IPS: Fixed "Autoload IPS patches" option (IPS files were always loaded) + fixed and simplified IPS loading logic

This commit is contained in:
Souryo 2016-08-20 22:07:56 -04:00
parent b63e7c4e35
commit d57a9f413a
8 changed files with 43 additions and 54 deletions

View File

@ -104,17 +104,10 @@ void Console::Initialize(string romFilename, stringstream *filestream, string ip
} }
} }
void Console::ApplyIpsPatch(string ipsFilename) void Console::LoadROM(string filepath, stringstream *filestream, int32_t archiveFileIndex, string ipsFile)
{ {
Console::Pause(); Console::Pause();
Instance->Initialize(GetROMPath(), nullptr, ipsFilename); Instance->Initialize(filepath, filestream, ipsFile, archiveFileIndex);
Console::Resume();
}
void Console::LoadROM(string filepath, stringstream *filestream, int32_t archiveFileIndex)
{
Console::Pause();
Instance->Initialize(filepath, filestream, "", archiveFileIndex);
Console::Resume(); Console::Resume();
} }

View File

@ -67,9 +67,8 @@ class Console
static void LoadState(istream &loadStream); static void LoadState(istream &loadStream);
static void LoadState(uint8_t *buffer, uint32_t bufferSize); static void LoadState(uint8_t *buffer, uint32_t bufferSize);
static void LoadROM(string filepath, stringstream *filestream = nullptr, int32_t archiveFileIndex = -1); static void LoadROM(string filepath, stringstream *filestream = nullptr, int32_t archiveFileIndex = -1, string ipsFile = "");
static bool LoadROM(string romName, uint32_t crc32Hash); static bool LoadROM(string romName, uint32_t crc32Hash);
static void ApplyIpsPatch(string ipsFilename);
static string GetROMPath(); static string GetROMPath();
static string GetRomName(); static string GetRomName();
static uint32_t GetCrc32(); static uint32_t GetCrc32();

View File

@ -12,6 +12,7 @@ std::unordered_map<string, string> MessageManager::_enResources = {
{ "Error", u8"Error" }, { "Error", u8"Error" },
{ "GameInfo", u8"Game Info" }, { "GameInfo", u8"Game Info" },
{ "GameLoaded", u8"Game loaded" }, { "GameLoaded", u8"Game loaded" },
{ "IPS", u8"IPS" },
{ "Movies", u8"Movies" }, { "Movies", u8"Movies" },
{ "NetPlay", u8"Net Play" }, { "NetPlay", u8"Net Play" },
{ "Region", u8"Region" }, { "Region", u8"Region" },
@ -20,6 +21,7 @@ std::unordered_map<string, string> MessageManager::_enResources = {
{ "SoundRecorder", u8"Sound Recorder" }, { "SoundRecorder", u8"Sound Recorder" },
{ "Test", u8"Test" }, { "Test", u8"Test" },
{ "ApplyingIps", u8"Applying patch: %1" },
{ "CheatApplied", u8"1 cheat applied." }, { "CheatApplied", u8"1 cheat applied." },
{ "CheatsApplied", u8"%1 cheats applied." }, { "CheatsApplied", u8"%1 cheats applied." },
{ "ConnectedToServer", u8"Connected to server." }, { "ConnectedToServer", u8"Connected to server." },
@ -73,6 +75,7 @@ std::unordered_map<string, string> MessageManager::_frResources = {
{ "Error", u8"Erreur" }, { "Error", u8"Erreur" },
{ "GameInfo", u8"Info sur le ROM" }, { "GameInfo", u8"Info sur le ROM" },
{ "GameLoaded", u8"Jeu chargé" }, { "GameLoaded", u8"Jeu chargé" },
{ "IPS", u8"IPS" },
{ "Movies", u8"Films" }, { "Movies", u8"Films" },
{ "NetPlay", u8"Jeu en ligne" }, { "NetPlay", u8"Jeu en ligne" },
{ "Region", u8"Région" }, { "Region", u8"Région" },
@ -81,6 +84,7 @@ std::unordered_map<string, string> MessageManager::_frResources = {
{ "SoundRecorder", u8"Enregistreur audio" }, { "SoundRecorder", u8"Enregistreur audio" },
{ "Test", u8"Test" }, { "Test", u8"Test" },
{ "ApplyingIps", u8"Fichier IPS appliqué : %1" },
{ "CheatApplied", u8"%1 code activé." }, { "CheatApplied", u8"%1 code activé." },
{ "CheatsApplied", u8"%1 codes activés." }, { "CheatsApplied", u8"%1 codes activés." },
{ "ConnectedToServer", u8"Connecté avec succès au serveur." }, { "ConnectedToServer", u8"Connecté avec succès au serveur." },
@ -134,6 +138,7 @@ std::unordered_map<string, string> MessageManager::_jaResources = {
{ "Error", u8"エラー" }, { "Error", u8"エラー" },
{ "GameInfo", u8"ゲーム情報" }, { "GameInfo", u8"ゲーム情報" },
{ "GameLoaded", u8"ゲーム開始" }, { "GameLoaded", u8"ゲーム開始" },
{ "IPS", u8"IPS" },
{ "Movies", u8"動画" }, { "Movies", u8"動画" },
{ "NetPlay", u8"ネットプレー" }, { "NetPlay", u8"ネットプレー" },
{ "Region", u8"地域" }, { "Region", u8"地域" },
@ -142,6 +147,7 @@ std::unordered_map<string, string> MessageManager::_jaResources = {
{ "SoundRecorder", u8"サウンドレコーダー" }, { "SoundRecorder", u8"サウンドレコーダー" },
{ "Test", u8"テスト" }, { "Test", u8"テスト" },
{ "ApplyingIps", u8"パッチファイルを適用しました: %1" },
{ "CheatApplied", u8"チートコード%1個を有効にしました。" }, { "CheatApplied", u8"チートコード%1個を有効にしました。" },
{ "CheatsApplied", u8"チートコード%1個を有効にしました。" }, { "CheatsApplied", u8"チートコード%1個を有効にしました。" },
{ "ConnectedToServer", u8"サーバに接続しました。" }, { "ConnectedToServer", u8"サーバに接続しました。" },
@ -195,6 +201,7 @@ std::unordered_map<string, string> MessageManager::_ruResources = {
{ "Error", u8"Ошибка" }, { "Error", u8"Ошибка" },
{ "GameInfo", u8"Информация об игре" }, { "GameInfo", u8"Информация об игре" },
{ "GameLoaded", u8"Игра загружена" }, { "GameLoaded", u8"Игра загружена" },
{ "IPS", u8"IPS" },
{ "Movies", u8"Записи" }, { "Movies", u8"Записи" },
{ "NetPlay", u8"Игра по сети" }, { "NetPlay", u8"Игра по сети" },
{ "Region", u8"Регион" }, { "Region", u8"Регион" },
@ -203,6 +210,7 @@ std::unordered_map<string, string> MessageManager::_ruResources = {
{ "SoundRecorder", u8"Запись звука" }, { "SoundRecorder", u8"Запись звука" },
{ "Test", u8"Тест" }, { "Test", u8"Тест" },
{ "ApplyingIps", u8"Applying patch: %1" },
{ "CheatApplied", u8"1 Чит применён." }, { "CheatApplied", u8"1 Чит применён." },
{ "CheatsApplied", u8"Читов применено %1" }, { "CheatsApplied", u8"Читов применено %1" },
{ "ConnectedToServer", u8"Подключение к серверу." }, { "ConnectedToServer", u8"Подключение к серверу." },
@ -256,6 +264,7 @@ std::unordered_map<string, string> MessageManager::_esResources = {
{ "Error", u8"Error" }, { "Error", u8"Error" },
{ "GameInfo", u8"Info del Juego" }, { "GameInfo", u8"Info del Juego" },
{ "GameLoaded", u8"Juego Cargado" }, { "GameLoaded", u8"Juego Cargado" },
{ "IPS", u8"IPS" },
{ "Movies", u8"Videos" }, { "Movies", u8"Videos" },
{ "NetPlay", u8"Juego Online" }, { "NetPlay", u8"Juego Online" },
{ "Region", u8"Región" }, { "Region", u8"Región" },
@ -264,6 +273,7 @@ std::unordered_map<string, string> MessageManager::_esResources = {
{ "SoundRecorder", u8"Grabadora de Sonido" }, { "SoundRecorder", u8"Grabadora de Sonido" },
{ "Test", u8"Test" }, { "Test", u8"Test" },
{ "ApplyingIps", u8"Applying patch: %1" },
{ "CheatApplied", u8"1 truco aplicado." }, { "CheatApplied", u8"1 truco aplicado." },
{ "CheatsApplied", u8"%1 trucos aplicados." }, { "CheatsApplied", u8"%1 trucos aplicados." },
{ "ConnectedToServer", u8"Conectado al servidor." }, { "ConnectedToServer", u8"Conectado al servidor." },

View File

@ -97,6 +97,7 @@ bool RomLoader::LoadFromMemory(uint8_t* buffer, size_t length, string romName)
if(!_ipsFilename.empty()) { if(!_ipsFilename.empty()) {
//Apply IPS patch //Apply IPS patch
MessageManager::DisplayMessage("IPS", "ApplyingIps", FolderUtilities::GetFilename(_ipsFilename, true));
fileData = IpsPatcher::PatchBuffer(_ipsFilename, fileData); fileData = IpsPatcher::PatchBuffer(_ipsFilename, fileData);
} }

View File

@ -26,7 +26,8 @@ namespace Mesen.GUI.Forms
private Thread _emuThread; private Thread _emuThread;
private frmDebugger _debugger; private frmDebugger _debugger;
private frmLogWindow _logWindow; private frmLogWindow _logWindow;
private string _romToLoad = null; private string _currentRomPath = null;
private int _currentRomArchiveIndex = -1;
private string _currentGame = null; private string _currentGame = null;
private bool _customSize = false; private bool _customSize = false;
private FormWindowState _originalWindowState; private FormWindowState _originalWindowState;
@ -454,55 +455,47 @@ namespace Mesen.GUI.Forms
} }
} }
private void LoadIpsFile(string filename) private void LoadIpsFile(string ipsFile)
{ {
string ipsFile = filename; if(_emuThread == null) {
string romFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) {
OpenFileDialog ofd = new OpenFileDialog();
if(File.Exists(romFile+".nes") || File.Exists(romFile+".zip") || File.Exists(romFile+".fds")) { ofd.Filter = ResourceHelper.GetMessage("FilterRom");
string ext = string.Empty; if(ConfigManager.Config.RecentFiles.Count > 0) {
if(File.Exists(romFile+".nes")) ofd.InitialDirectory = Path.GetDirectoryName(ConfigManager.Config.RecentFiles[0].Path);
ext = ".nes";
if(File.Exists(romFile+".zip"))
ext = ".zip";
if(File.Exists(romFile+".fds"))
ext = ".fds";
LoadROM(romFile + ext);
InteropEmu.ApplyIpsPatch(ipsFile);
} else {
if(_emuThread == null) {
if(MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) {
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = ResourceHelper.GetMessage("FilterRom");
if(ConfigManager.Config.RecentFiles.Count > 0) {
ofd.InitialDirectory = Path.GetDirectoryName(ConfigManager.Config.RecentFiles[0].Path);
}
if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
LoadROM(ofd.FileName);
}
InteropEmu.ApplyIpsPatch(ipsFile);
} }
} else if(MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) {
InteropEmu.ApplyIpsPatch(ipsFile); if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
LoadROM(ofd.FileName, true, -1, ipsFile);
}
} }
} else if(MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK) {
LoadROM(_currentRomPath, true, _currentRomArchiveIndex, ipsFile);
} }
} }
private void LoadROM(string filename, bool autoLoadIps = false, int archiveFileIndex = -1) private void LoadROM(string filename, bool autoLoadIps = false, int archiveFileIndex = -1, string ipsFileToApply = null)
{ {
_romToLoad = filename; _currentRomPath = filename;
_currentRomArchiveIndex = -1;
if(File.Exists(filename)) { if(File.Exists(filename)) {
string romName; string romName;
if(frmSelectRom.SelectRom(filename, ref archiveFileIndex, out romName)) { if(frmSelectRom.SelectRom(filename, ref archiveFileIndex, out romName)) {
_currentRomArchiveIndex = archiveFileIndex;
if(archiveFileIndex >= 0) { if(archiveFileIndex >= 0) {
Interlocked.Increment(ref _romLoadCounter); Interlocked.Increment(ref _romLoadCounter);
ctrlNsfPlayer.Visible = false; ctrlNsfPlayer.Visible = false;
ctrlLoading.Visible = true; ctrlLoading.Visible = true;
} }
string ipsFile = ipsFileToApply ?? Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)) + ".ips";
if(!File.Exists(ipsFile)) {
autoLoadIps = false;
}
Task loadRomTask = new Task(() => { Task loadRomTask = new Task(() => {
lock(_loadRomLock) { lock(_loadRomLock) {
InteropEmu.LoadROM(filename, archiveFileIndex); InteropEmu.LoadROM(filename, archiveFileIndex, autoLoadIps ? ipsFile : string.Empty);
} }
}); });
@ -512,11 +505,6 @@ namespace Mesen.GUI.Forms
Interlocked.Decrement(ref _romLoadCounter); Interlocked.Decrement(ref _romLoadCounter);
} }
string ipsFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)) + ".ips";
if(File.Exists(ipsFile)) {
InteropEmu.ApplyIpsPatch(ipsFile);
}
ConfigManager.Config.AddRecentFile(filename, romName, archiveFileIndex); ConfigManager.Config.AddRecentFile(filename, romName, archiveFileIndex);
UpdateRecentFiles(); UpdateRecentFiles();
})); }));
@ -650,7 +638,7 @@ namespace Mesen.GUI.Forms
ToolStripMenuItem tsmi = new ToolStripMenuItem(); ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = recentItem.RomName; tsmi.Text = recentItem.RomName;
tsmi.Click += (object sender, EventArgs args) => { tsmi.Click += (object sender, EventArgs args) => {
LoadROM(recentItem.Path, false, recentItem.ArchiveFileIndex); LoadROM(recentItem.Path, ConfigManager.Config.PreferenceInfo.AutoLoadIpsPatches, recentItem.ArchiveFileIndex);
}; };
mnuRecentFiles.DropDownItems.Add(tsmi); mnuRecentFiles.DropDownItems.Add(tsmi);
} }
@ -1296,7 +1284,7 @@ namespace Mesen.GUI.Forms
if(ofd.ShowDialog() == DialogResult.OK) { if(ofd.ShowDialog() == DialogResult.OK) {
if(MD5Helper.GetMD5Hash(ofd.FileName).ToLowerInvariant() == "ca30b50f880eb660a320674ed365ef7a") { if(MD5Helper.GetMD5Hash(ofd.FileName).ToLowerInvariant() == "ca30b50f880eb660a320674ed365ef7a") {
File.Copy(ofd.FileName, Path.Combine(ConfigManager.HomeFolder, "FdsBios.bin")); File.Copy(ofd.FileName, Path.Combine(ConfigManager.HomeFolder, "FdsBios.bin"));
LoadROM(_romToLoad); LoadROM(_currentRomPath, ConfigManager.Config.PreferenceInfo.AutoLoadIpsPatches);
} else { } else {
MesenMsgBox.Show("InvalidFdsBios", MessageBoxButtons.OK, MessageBoxIcon.Error); MesenMsgBox.Show("InvalidFdsBios", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }

View File

@ -25,8 +25,7 @@ namespace Mesen.GUI
[DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool IsRunning(); [DllImport(DLLPath)] [return: MarshalAs(UnmanagedType.I1)] public static extern bool IsRunning();
[DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename, Int32 archiveFileIndex = -1); [DllImport(DLLPath)] public static extern void LoadROM([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename, Int32 archiveFileIndex, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UTF8Marshaler))]string ipsFile);
[DllImport(DLLPath)] public static extern void ApplyIpsPatch([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename);
[DllImport(DLLPath)] public static extern void AddKnowGameFolder([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string folder); [DllImport(DLLPath)] public static extern void AddKnowGameFolder([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string folder);
[DllImport(DLLPath, EntryPoint = "GetArchiveRomList")] private static extern IntPtr GetArchiveRomListWrapper([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename); [DllImport(DLLPath, EntryPoint = "GetArchiveRomList")] private static extern IntPtr GetArchiveRomListWrapper([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename);

View File

@ -86,8 +86,7 @@ namespace InteropEmu {
DllExport bool __stdcall IsRunning() { return Console::IsRunning(); } DllExport bool __stdcall IsRunning() { return Console::IsRunning(); }
DllExport void __stdcall LoadROM(char* filename, int32_t archiveFileIndex) { Console::LoadROM(filename, nullptr, archiveFileIndex); } DllExport void __stdcall LoadROM(char* filename, int32_t archiveFileIndex, char* ipsFile) { Console::LoadROM(filename, nullptr, archiveFileIndex, ipsFile); }
DllExport void __stdcall ApplyIpsPatch(char* filename) { Console::ApplyIpsPatch(filename); }
DllExport void __stdcall AddKnowGameFolder(char* folder) { FolderUtilities::AddKnowGameFolder(folder); } DllExport void __stdcall AddKnowGameFolder(char* folder) { FolderUtilities::AddKnowGameFolder(folder); }
DllExport const char* __stdcall GetArchiveRomList(char* filename) { DllExport const char* __stdcall GetArchiveRomList(char* filename) {