diff --git a/Core/Console.cpp b/Core/Console.cpp index d648890b..4ef40726 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -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(); - Instance->Initialize(GetROMPath(), nullptr, ipsFilename); - Console::Resume(); -} - -void Console::LoadROM(string filepath, stringstream *filestream, int32_t archiveFileIndex) -{ - Console::Pause(); - Instance->Initialize(filepath, filestream, "", archiveFileIndex); + Instance->Initialize(filepath, filestream, ipsFile, archiveFileIndex); Console::Resume(); } diff --git a/Core/Console.h b/Core/Console.h index a26eb64e..c8a4d87e 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -67,9 +67,8 @@ class Console static void LoadState(istream &loadStream); 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 void ApplyIpsPatch(string ipsFilename); static string GetROMPath(); static string GetRomName(); static uint32_t GetCrc32(); diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index ee5f7b52..affb0e50 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -12,6 +12,7 @@ std::unordered_map MessageManager::_enResources = { { "Error", u8"Error" }, { "GameInfo", u8"Game Info" }, { "GameLoaded", u8"Game loaded" }, + { "IPS", u8"IPS" }, { "Movies", u8"Movies" }, { "NetPlay", u8"Net Play" }, { "Region", u8"Region" }, @@ -20,6 +21,7 @@ std::unordered_map MessageManager::_enResources = { { "SoundRecorder", u8"Sound Recorder" }, { "Test", u8"Test" }, + { "ApplyingIps", u8"Applying patch: %1" }, { "CheatApplied", u8"1 cheat applied." }, { "CheatsApplied", u8"%1 cheats applied." }, { "ConnectedToServer", u8"Connected to server." }, @@ -73,6 +75,7 @@ std::unordered_map MessageManager::_frResources = { { "Error", u8"Erreur" }, { "GameInfo", u8"Info sur le ROM" }, { "GameLoaded", u8"Jeu chargé" }, + { "IPS", u8"IPS" }, { "Movies", u8"Films" }, { "NetPlay", u8"Jeu en ligne" }, { "Region", u8"Région" }, @@ -81,6 +84,7 @@ std::unordered_map MessageManager::_frResources = { { "SoundRecorder", u8"Enregistreur audio" }, { "Test", u8"Test" }, + { "ApplyingIps", u8"Fichier IPS appliqué : %1" }, { "CheatApplied", u8"%1 code activé." }, { "CheatsApplied", u8"%1 codes activés." }, { "ConnectedToServer", u8"Connecté avec succès au serveur." }, @@ -134,6 +138,7 @@ std::unordered_map MessageManager::_jaResources = { { "Error", u8"エラー" }, { "GameInfo", u8"ゲーム情報" }, { "GameLoaded", u8"ゲーム開始" }, + { "IPS", u8"IPS" }, { "Movies", u8"動画" }, { "NetPlay", u8"ネットプレー" }, { "Region", u8"地域" }, @@ -142,6 +147,7 @@ std::unordered_map MessageManager::_jaResources = { { "SoundRecorder", u8"サウンドレコーダー" }, { "Test", u8"テスト" }, + { "ApplyingIps", u8"パッチファイルを適用しました: %1" }, { "CheatApplied", u8"チートコード%1個を有効にしました。" }, { "CheatsApplied", u8"チートコード%1個を有効にしました。" }, { "ConnectedToServer", u8"サーバに接続しました。" }, @@ -195,6 +201,7 @@ std::unordered_map MessageManager::_ruResources = { { "Error", u8"Ошибка" }, { "GameInfo", u8"Информация об игре" }, { "GameLoaded", u8"Игра загружена" }, + { "IPS", u8"IPS" }, { "Movies", u8"Записи" }, { "NetPlay", u8"Игра по сети" }, { "Region", u8"Регион" }, @@ -203,6 +210,7 @@ std::unordered_map MessageManager::_ruResources = { { "SoundRecorder", u8"Запись звука" }, { "Test", u8"Тест" }, + { "ApplyingIps", u8"Applying patch: %1" }, { "CheatApplied", u8"1 Чит применён." }, { "CheatsApplied", u8"Читов применено %1" }, { "ConnectedToServer", u8"Подключение к серверу." }, @@ -256,6 +264,7 @@ std::unordered_map MessageManager::_esResources = { { "Error", u8"Error" }, { "GameInfo", u8"Info del Juego" }, { "GameLoaded", u8"Juego Cargado" }, + { "IPS", u8"IPS" }, { "Movies", u8"Videos" }, { "NetPlay", u8"Juego Online" }, { "Region", u8"Región" }, @@ -264,6 +273,7 @@ std::unordered_map MessageManager::_esResources = { { "SoundRecorder", u8"Grabadora de Sonido" }, { "Test", u8"Test" }, + { "ApplyingIps", u8"Applying patch: %1" }, { "CheatApplied", u8"1 truco aplicado." }, { "CheatsApplied", u8"%1 trucos aplicados." }, { "ConnectedToServer", u8"Conectado al servidor." }, diff --git a/Core/RomLoader.cpp b/Core/RomLoader.cpp index eac248d3..4dfb0fd7 100644 --- a/Core/RomLoader.cpp +++ b/Core/RomLoader.cpp @@ -97,6 +97,7 @@ bool RomLoader::LoadFromMemory(uint8_t* buffer, size_t length, string romName) if(!_ipsFilename.empty()) { //Apply IPS patch + MessageManager::DisplayMessage("IPS", "ApplyingIps", FolderUtilities::GetFilename(_ipsFilename, true)); fileData = IpsPatcher::PatchBuffer(_ipsFilename, fileData); } diff --git a/GUI.NET/Dependencies/Font.24.spritefont b/GUI.NET/Dependencies/Font.24.spritefont index 6743e0e9..468f9fb5 100644 Binary files a/GUI.NET/Dependencies/Font.24.spritefont and b/GUI.NET/Dependencies/Font.24.spritefont differ diff --git a/GUI.NET/Forms/frmMain.cs b/GUI.NET/Forms/frmMain.cs index 04649c7e..c9f42558 100644 --- a/GUI.NET/Forms/frmMain.cs +++ b/GUI.NET/Forms/frmMain.cs @@ -26,7 +26,8 @@ namespace Mesen.GUI.Forms private Thread _emuThread; private frmDebugger _debugger; private frmLogWindow _logWindow; - private string _romToLoad = null; + private string _currentRomPath = null; + private int _currentRomArchiveIndex = -1; private string _currentGame = null; private bool _customSize = false; private FormWindowState _originalWindowState; @@ -454,55 +455,47 @@ namespace Mesen.GUI.Forms } } - private void LoadIpsFile(string filename) + private void LoadIpsFile(string ipsFile) { - string ipsFile = filename; - string romFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); - - if(File.Exists(romFile+".nes") || File.Exists(romFile+".zip") || File.Exists(romFile+".fds")) { - string ext = string.Empty; - if(File.Exists(romFile+".nes")) - 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); + 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); } - } 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)) { string romName; if(frmSelectRom.SelectRom(filename, ref archiveFileIndex, out romName)) { + _currentRomArchiveIndex = archiveFileIndex; if(archiveFileIndex >= 0) { Interlocked.Increment(ref _romLoadCounter); ctrlNsfPlayer.Visible = false; 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(() => { 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); } - string ipsFile = Path.Combine(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)) + ".ips"; - if(File.Exists(ipsFile)) { - InteropEmu.ApplyIpsPatch(ipsFile); - } - ConfigManager.Config.AddRecentFile(filename, romName, archiveFileIndex); UpdateRecentFiles(); })); @@ -650,7 +638,7 @@ namespace Mesen.GUI.Forms ToolStripMenuItem tsmi = new ToolStripMenuItem(); tsmi.Text = recentItem.RomName; 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); } @@ -1296,7 +1284,7 @@ namespace Mesen.GUI.Forms if(ofd.ShowDialog() == DialogResult.OK) { if(MD5Helper.GetMD5Hash(ofd.FileName).ToLowerInvariant() == "ca30b50f880eb660a320674ed365ef7a") { File.Copy(ofd.FileName, Path.Combine(ConfigManager.HomeFolder, "FdsBios.bin")); - LoadROM(_romToLoad); + LoadROM(_currentRomPath, ConfigManager.Config.PreferenceInfo.AutoLoadIpsPatches); } else { MesenMsgBox.Show("InvalidFdsBios", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index bf59f9ae..62b473f6 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -25,8 +25,7 @@ namespace Mesen.GUI [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 ApplyIpsPatch([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(UTF8Marshaler))]string filename); + [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 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); diff --git a/InteropDLL/ConsoleWrapper.cpp b/InteropDLL/ConsoleWrapper.cpp index 96c701e3..47f480b0 100644 --- a/InteropDLL/ConsoleWrapper.cpp +++ b/InteropDLL/ConsoleWrapper.cpp @@ -86,8 +86,7 @@ namespace InteropEmu { DllExport bool __stdcall IsRunning() { return Console::IsRunning(); } - DllExport void __stdcall LoadROM(char* filename, int32_t archiveFileIndex) { Console::LoadROM(filename, nullptr, archiveFileIndex); } - DllExport void __stdcall ApplyIpsPatch(char* filename) { Console::ApplyIpsPatch(filename); } + DllExport void __stdcall LoadROM(char* filename, int32_t archiveFileIndex, char* ipsFile) { Console::LoadROM(filename, nullptr, archiveFileIndex, ipsFile); } DllExport void __stdcall AddKnowGameFolder(char* folder) { FolderUtilities::AddKnowGameFolder(folder); } DllExport const char* __stdcall GetArchiveRomList(char* filename) {