From 80b5a685f118b77fc0e2e9909001c4980e58f939 Mon Sep 17 00:00:00 2001 From: spacy51 Date: Thu, 16 Oct 2008 15:29:53 +0000 Subject: [PATCH] ADDED support for .ips .ups .ppf files to the GUI. --- src/win32/Commands.cpp | 2 +- src/win32/MainWnd.cpp | 37 +++++++++++++++++++++++++----------- src/win32/MainWnd.h | 5 ++++- src/win32/MainWndOptions.cpp | 6 +++--- src/win32/VBA.cpp | 6 +++--- src/win32/VBA.h | 2 +- src/win32/VBA.rc | 2 +- src/win32/resource.h | 2 +- 8 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/win32/Commands.cpp b/src/win32/Commands.cpp index f7b2e3e6..4bb7cf1e 100644 --- a/src/win32/Commands.cpp +++ b/src/win32/Commands.cpp @@ -138,7 +138,7 @@ struct { { "OptionsEmulatorSaveEEPROMSensor", ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR }, { "OptionsEmulatorSaveFlash64K", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K }, { "OptionsEmulatorSaveFlash128K", ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M }, - { "OptionsEmulatorAutoIPSPatch", ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH }, + { "OptionsEmulatorAutoApplyPatchFiles", ID_OPTIONS_EMULATOR_AUTOMATICALLYAPPLYPATCHFILES }, { "OptionsEmulatorAGBPrint", ID_OPTIONS_EMULATOR_AGBPRINT }, { "OptionsEmulatorRTC", ID_OPTIONS_EMULATOR_REALTIMECLOCK }, { "OptionsEmulatorRewindInterval", ID_OPTIONS_EMULATOR_REWINDINTERVAL }, diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index 38ae1658..c04eff39 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -69,6 +69,12 @@ MainWnd::~MainWnd() { } +bool MainWnd::fileExists( LPCTSTR lpFileName ) +{ + // check if file exists + return GetFileAttributes( lpFileName ) != INVALID_FILE_ATTRIBUTES; +} + BEGIN_MESSAGE_MAP(MainWnd, CWnd) //{{AFX_MSG_MAP(MainWnd) @@ -173,8 +179,8 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SYNCHRONIZE, OnUpdateOptionsEmulatorSynchronize) ON_COMMAND(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnOptionsEmulatorSpeeduptoggle) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_SPEEDUPTOGGLE, OnUpdateOptionsEmulatorSpeeduptoggle) - ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnOptionsEmulatorAutomaticallyipspatch) - ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH, OnUpdateOptionsEmulatorAutomaticallyipspatch) + ON_COMMAND(ID_OPTIONS_EMULATOR_AUTOMATICALLYAPPLYPATCHFILES, OnOptionsEmulatorAutomaticallyApplyPatchFiles) + ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AUTOMATICALLYAPPLYPATCHFILES, OnUpdateOptionsEmulatorAutomaticallyipspatch) ON_COMMAND(ID_OPTIONS_EMULATOR_AGBPRINT, OnOptionsEmulatorAgbprint) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_AGBPRINT, OnUpdateOptionsEmulatorAgbprint) ON_COMMAND(ID_OPTIONS_EMULATOR_REALTIMECLOCK, OnOptionsEmulatorRealtimeclock) @@ -455,8 +461,19 @@ bool MainWnd::FileRun() gbCheatRemoveAll(); } - CString ipsname; - ipsname.Format("%s.ips", theApp.filename); + CString patchName; + patchName.Format("%s.ips", theApp.filename); + if( !fileExists( patchName ) ) { + patchName.Format("%s.ups", theApp.filename); + if( !fileExists( patchName ) ) { + patchName.Format("%s.ppf", theApp.filename); + if( !fileExists( patchName ) ) { + // don't use any patches + patchName.Empty(); + } + } + } + if(!theApp.dir.GetLength()) { int index = theApp.filename.ReverseFind('\\'); @@ -495,9 +512,9 @@ bool MainWnd::FileRun() theApp.romSize = gbRomSize; - if(theApp.autoIPS) { + if(theApp.autoPatch && !patchName.IsEmpty()) { int size = gbRomSize; - utilApplyIPS(ipsname, &gbRom, &size); + utilApplyIPS(patchName, &gbRom, &size); if(size != gbRomSize) { extern bool gbUpdateSizes(); gbUpdateSizes(); @@ -562,9 +579,9 @@ bool MainWnd::FileRun() } */ - if(theApp.autoIPS) { + if(theApp.autoPatch && !patchName.IsEmpty()) { int size = 0x2000000; - utilApplyIPS(ipsname, &rom, &size); + utilApplyIPS(patchName, &rom, &size); if(size != 0x2000000) { CPUReset(); } @@ -1151,9 +1168,7 @@ void MainWnd::screenCapture(int captureNumber) captureNumber, ext); - // check if file exists - DWORD dwAttr = GetFileAttributes( buffer ); - if( dwAttr != INVALID_FILE_ATTRIBUTES ) { + if( fileExists( buffer ) ) { // screenshot file already exists screenCapture(++captureNumber); // this will recursively use the first non-existent screenshot number diff --git a/src/win32/MainWnd.h b/src/win32/MainWnd.h index 2838860f..59aa1074 100644 --- a/src/win32/MainWnd.h +++ b/src/win32/MainWnd.h @@ -49,6 +49,9 @@ public: void winSaveCheatList(const char *name); void winSaveCheatListDefault(); +private: + bool fileExists( LPCTSTR lpFileName ); + DECLARE_MESSAGE_MAP() @@ -176,7 +179,7 @@ protected: afx_msg void OnUpdateOptionsEmulatorSynchronize(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorSpeeduptoggle(); afx_msg void OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI* pCmdUI); - afx_msg void OnOptionsEmulatorAutomaticallyipspatch(); + afx_msg void OnOptionsEmulatorAutomaticallyApplyPatchFiles(); afx_msg void OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI* pCmdUI); afx_msg void OnOptionsEmulatorAgbprint(); afx_msg void OnUpdateOptionsEmulatorAgbprint(CCmdUI* pCmdUI); diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index 810d1fa8..8397183d 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -536,14 +536,14 @@ void MainWnd::OnUpdateOptionsEmulatorSpeeduptoggle(CCmdUI* pCmdUI) pCmdUI->SetCheck(theApp.speedupToggle); } -void MainWnd::OnOptionsEmulatorAutomaticallyipspatch() +void MainWnd::OnOptionsEmulatorAutomaticallyApplyPatchFiles() { - theApp.autoIPS = !theApp.autoIPS; + theApp.autoPatch = !theApp.autoPatch; } void MainWnd::OnUpdateOptionsEmulatorAutomaticallyipspatch(CCmdUI* pCmdUI) { - pCmdUI->SetCheck(theApp.autoIPS); + pCmdUI->SetCheck(theApp.autoPatch); } void MainWnd::OnOptionsEmulatorAgbprint() diff --git a/src/win32/VBA.cpp b/src/win32/VBA.cpp index 6fe7fd0c..31fd78d5 100644 --- a/src/win32/VBA.cpp +++ b/src/win32/VBA.cpp @@ -257,7 +257,7 @@ VBA::VBA() autoSaveLoadCheatList = false; winout = NULL; removeIntros = false; - autoIPS = true; + autoPatch = true; winGbBorderOn = 0; winFlashSize = 0x20000; winRtcEnable = false; @@ -1635,7 +1635,7 @@ void VBA::loadSettings() recentFreeze = regQueryDwordValue("recentFreeze", false) ? true : false; - autoIPS = regQueryDwordValue("autoIPS", true) ? true : false; + autoPatch = regQueryDwordValue("autoPatch", 1) == 1 ? true : false; cpuDisableSfx = regQueryDwordValue("disableSfx", 0) ? true : false; @@ -2616,7 +2616,7 @@ void VBA::saveSettings() regSetDwordValue("recentFreeze", recentFreeze); - regSetDwordValue("autoIPS", autoIPS); + regSetDwordValue("autoPatch", autoPatch ? 1 : 0); regSetDwordValue("disableSfx", cpuDisableSfx); diff --git a/src/win32/VBA.h b/src/win32/VBA.h index 1e25cb4c..a5f9592c 100644 --- a/src/win32/VBA.h +++ b/src/win32/VBA.h @@ -124,7 +124,7 @@ class VBA : public CWinApp bool autoSaveLoadCheatList; FILE *winout; bool removeIntros; - bool autoIPS; + bool autoPatch; int winGbBorderOn; int winFlashSize; bool winRtcEnable; diff --git a/src/win32/VBA.rc b/src/win32/VBA.rc index 8c82ede4..11f5e885 100644 --- a/src/win32/VBA.rc +++ b/src/win32/VBA.rc @@ -1859,7 +1859,7 @@ BEGIN MENUITEM "&Below Normal", ID_OPTIONS_PRIORITY_BELOWNORMAL END MENUITEM "&Remove intros (GBA)", ID_OPTIONS_EMULATOR_REMOVEINTROSGBA - MENUITEM "Automatic IPS patching", ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH + MENUITEM "Auto-apply IPS/UPS/PPF", ID_OPTIONS_EMULATOR_AUTOMATICALLYAPPLYPATCHFILES MENUITEM "AGB Print", ID_OPTIONS_EMULATOR_AGBPRINT MENUITEM "Real Time Clock", ID_OPTIONS_EMULATOR_REALTIMECLOCK MENUITEM "&Game Overrides...", ID_OPTIONS_EMULATOR_GAMEOVERRIDES diff --git a/src/win32/resource.h b/src/win32/resource.h index ed0c12e3..b226a6d9 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -718,7 +718,7 @@ #define ID_OPTIONS_EMULATOR_SAVETYPE_EEPROMSENSOR 40173 #define ID_OPTIONS_EMULATOR_SAVETYPE_FLASH512K 40174 #define ID_OPTIONS_EMULATOR_SAVETYPE_FLASH1M 40175 -#define ID_OPTIONS_EMULATOR_AUTOMATICALLYIPSPATCH 40176 +#define ID_OPTIONS_EMULATOR_AUTOMATICALLYAPPLYPATCHFILES 40176 #define ID_TOOLS_RECORD_STARTAVIRECORDING 40178 #define ID_TOOLS_RECORD_STOPAVIRECORDING 40179 #define ID_OPTIONS_FILTER_BILINEAR 40186