From 67ddabd231921186cb4ff435e94872ff3fb0221e Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Wed, 23 Jun 2010 01:15:09 +0000 Subject: [PATCH] Fix patch application, which I broke in r3273. :) DevNote: Adding SysForwardDefs.h, which I'm going to use for forward declaring a bunch of PCSX2 classes and other simple dependency-free include content. This is the SysCore version of AppForwardDefs, and hopefully helps minimize header file hell. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@3276 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/GameDatabase.cpp | 8 +++---- pcsx2/GameDatabase.h | 24 ++++++++++----------- pcsx2/Patch.cpp | 23 +++++++++----------- pcsx2/Patch.h | 25 +++++++++++----------- pcsx2/SysForwardDefs.h | 25 ++++++++++++++++++++++ pcsx2/System.h | 9 ++------ pcsx2/gui/AppCoreThread.cpp | 2 +- pcsx2/windows/VCprojects/pcsx2_2008.vcproj | 4 ++++ 8 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 pcsx2/SysForwardDefs.h diff --git a/pcsx2/GameDatabase.cpp b/pcsx2/GameDatabase.cpp index ba1832adbc..e08672710d 100644 --- a/pcsx2/GameDatabase.cpp +++ b/pcsx2/GameDatabase.cpp @@ -51,8 +51,8 @@ void BaseGameDatabaseImpl::updateGame(const Game_Data& game) } // Searches the current game's data to see if the given key exists -bool Game_Data::keyExists(const wxChar* key) { - KeyPairArray::iterator it( kList.begin() ); +bool Game_Data::keyExists(const wxChar* key) const { + KeyPairArray::const_iterator it( kList.begin() ); for ( ; it != kList.end(); ++it) { if (it[0].CompareKey(key)) { return true; @@ -73,8 +73,8 @@ void Game_Data::deleteKey(const wxChar* key) { } // Gets a string representation of the 'value' for the given key -wxString Game_Data::getString(const wxChar* key) { - KeyPairArray::iterator it( kList.begin() ); +wxString Game_Data::getString(const wxChar* key) const { + KeyPairArray::const_iterator it( kList.begin() ); for ( ; it != kList.end(); ++it) { if (it[0].CompareKey(key)) { return it[0].value; diff --git a/pcsx2/GameDatabase.h b/pcsx2/GameDatabase.h index 375c9b6f2d..5d40acf319 100644 --- a/pcsx2/GameDatabase.h +++ b/pcsx2/GameDatabase.h @@ -95,9 +95,9 @@ struct Game_Data kList.clear(); } - bool keyExists(const wxChar* key); + bool keyExists(const wxChar* key) const; void deleteKey(const wxChar* key); - wxString getString(const wxChar* key); + wxString getString(const wxChar* key) const; void writeString(const wxString& key, const wxString& value); void writeBool(const wxString& key, bool value); @@ -105,46 +105,46 @@ struct Game_Data return !id.IsEmpty(); } - bool sectionExists(const wxChar* key, const wxString& value) { + bool sectionExists(const wxChar* key, const wxString& value) const { return keyExists(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", value.c_str())); } - wxString getSection(const wxChar* key, const wxString& value) { + wxString getSection(const wxChar* key, const wxString& value) const { return getString(wxsFormat(L"[%s%s%s]", key, value.IsEmpty() ? L"" : L" = ", value.c_str())); } // Gets an integer representation of the 'value' for the given key - int getInt(const wxChar* key) { + int getInt(const wxChar* key) const { return wxStrtoul(getString(key), NULL, 0); } // Gets a u8 representation of the 'value' for the given key - u8 getU8(const wxChar* key) { + u8 getU8(const wxChar* key) const { return (u8)wxAtoi(getString(key)); } // Gets a bool representation of the 'value' for the given key - bool getBool(const wxChar* key) { + bool getBool(const wxChar* key) const { return !!wxAtoi(getString(key)); } - bool keyExists(const char* key) { + bool keyExists(const char* key) const { return keyExists(fromUTF8(key)); } - wxString getString(const char* key) { + wxString getString(const char* key) const { return getString(fromUTF8(key)); } - int getInt(const char* key) { + int getInt(const char* key) const { return getInt(fromUTF8(key)); } - u8 getU8(const char* key) { + u8 getU8(const char* key) const { return getU8(fromUTF8(key)); } - bool getBool(const char* key) { + bool getBool(const char* key) const { return getBool(fromUTF8(key)); } }; diff --git a/pcsx2/Patch.cpp b/pcsx2/Patch.cpp index 397602b0b2..bf00f86140 100644 --- a/pcsx2/Patch.cpp +++ b/pcsx2/Patch.cpp @@ -131,27 +131,24 @@ void TrimPatches(wxString& s) // This routine loads patches from the game database // Returns number of patches loaded -int InitPatches(const wxString& name) +int InitPatches(const wxString& crc, const Game_Data& game) { bool patchFound = false; wxString patch; patchnumber = 0; - if (IGameDatabase* GameDB = AppHost_GetGameDatabase() ) + if (game.IsOk()) { - Game_Data game; - if (GameDB->findGame(game,name)) { - if (game.sectionExists(L"patches", name)) { - patch = game.getSection(L"patches", name); - patchFound = true; - } - else if (game.keyExists(L"[patches]")) { - patch = game.getString(L"[patches]"); - patchFound = true; - } + if (game.sectionExists(L"patches", crc)) { + patch = game.getSection(L"patches", crc); + patchFound = true; + } + else if (game.keyExists(L"[patches]")) { + patch = game.getString(L"[patches]"); + patchFound = true; } } - + if (patchFound) { Console.WriteLn(Color_Green, "Patch found in the Database!"); TrimPatches(patch); diff --git a/pcsx2/Patch.h b/pcsx2/Patch.h index c75a368fe2..a4db00831d 100644 --- a/pcsx2/Patch.h +++ b/pcsx2/Patch.h @@ -12,10 +12,11 @@ * You should have received a copy of the GNU General Public License along with PCSX2. * If not, see . */ -#ifndef __PATCH_H__ -#define __PATCH_H__ + +#pragma once #include "Pcsx2Defs.h" +#include "SysForwardDefs.h" #define MAX_PATCH 512 #define MAX_CHEAT 1024 @@ -56,16 +57,14 @@ namespace PatchFunc PATCHTABLEFUNC cheat; } -int InitCheats(const wxString& name); -void inifile_command(bool isCheat, const wxString& cmd); -void inifile_trim(wxString& buffer); +extern int InitCheats(const wxString& name); +extern void inifile_command(bool isCheat, const wxString& cmd); +extern void inifile_trim(wxString& buffer); -int InitPatches(const wxString& name); -int AddPatch(int Mode, int Place, int Address, int Size, u64 data); -void ResetPatch(void); -void ApplyPatch(int place = 1); -void ApplyCheat(int place = 1); -void _ApplyPatch(IniPatch *p); - -#endif /* __PATCH_H__ */ +extern int InitPatches(const wxString& name, const Game_Data& game); +extern int AddPatch(int Mode, int Place, int Address, int Size, u64 data); +extern void ResetPatch(void); +extern void ApplyPatch(int place = 1); +extern void ApplyCheat(int place = 1); +extern void _ApplyPatch(IniPatch *p); diff --git a/pcsx2/SysForwardDefs.h b/pcsx2/SysForwardDefs.h new file mode 100644 index 0000000000..b2ddb35f97 --- /dev/null +++ b/pcsx2/SysForwardDefs.h @@ -0,0 +1,25 @@ +/* PCSX2 - PS2 Emulator for PCs + * Copyright (C) 2002-2010 PCSX2 Dev Team + * + * PCSX2 is free software: you can redistribute it and/or modify it under the terms + * of the GNU Lesser General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with PCSX2. + * If not, see . + */ + +#pragma once + +static const int PCSX2_VersionHi = 0; +static const int PCSX2_VersionMid = 9; +static const int PCSX2_VersionLo = 7; + +class SysCoreThread; +class CpuInitializerSet; + +struct Game_Data; diff --git a/pcsx2/System.h b/pcsx2/System.h index acfd943468..91a9ab055e 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -15,17 +15,12 @@ #pragma once +#include "SysForwardDefs.h" + #include "Utilities/SafeArray.h" #include "Utilities/Threading.h" // to use threading stuff, include the Threading namespace in your file. #include "CDVD/CDVDaccess.h" -static const int PCSX2_VersionHi = 0; -static const int PCSX2_VersionMid = 9; -static const int PCSX2_VersionLo = 7; - -class SysCoreThread; -class CpuInitializerSet; - typedef SafeArray VmStateBuffer; // -------------------------------------------------------------------------------------- diff --git a/pcsx2/gui/AppCoreThread.cpp b/pcsx2/gui/AppCoreThread.cpp index ce3b23a2b6..3b5589f9e0 100644 --- a/pcsx2/gui/AppCoreThread.cpp +++ b/pcsx2/gui/AppCoreThread.cpp @@ -266,7 +266,7 @@ void AppCoreThread::ApplySettings( const Pcsx2Config& src ) } if (EmuConfig.EnablePatches) { - if (int patches = InitPatches(gameCRC)) { + if (int patches = InitPatches(gameCRC, game)) { gamePatch.Printf(L" [%d Patches]", patches); } if (int fixes = loadGameSettings(fixup, GameDB)) { diff --git a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj index 9a43bb4cc5..11731ee54a 100644 --- a/pcsx2/windows/VCprojects/pcsx2_2008.vcproj +++ b/pcsx2/windows/VCprojects/pcsx2_2008.vcproj @@ -475,6 +475,10 @@ RelativePath="..\..\Stats.h" > + +