From 81fd8e011fff75278af576297f44bc3ca5fa1db4 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Sun, 7 Feb 2021 14:25:04 +0000 Subject: [PATCH] DEV9: Apply settings if configuration was performed during emulation --- pcsx2/DEV9/DEV9.cpp | 75 ++++++++++++++++++++++++++++++++++++++ pcsx2/DEV9/DEV9.h | 1 + pcsx2/DEV9/Linux/Linux.cpp | 5 +++ pcsx2/DEV9/Win32/Win32.cpp | 5 +++ 4 files changed, 86 insertions(+) diff --git a/pcsx2/DEV9/DEV9.cpp b/pcsx2/DEV9/DEV9.cpp index 85dec091a1..4835ab89fe 100644 --- a/pcsx2/DEV9/DEV9.cpp +++ b/pcsx2/DEV9/DEV9.cpp @@ -97,6 +97,8 @@ int mapping; std::string s_strIniPath = "inis"; std::string s_strLogPath = "logs"; +bool isRunning = false; + s32 DEV9init() { DevCon.WriteLn("DEV9init"); @@ -222,6 +224,7 @@ s32 DEV9open(void* pDsp) if (config.ethEnable) InitNet(); + isRunning = true; return 0; } @@ -231,6 +234,7 @@ void DEV9close() dev9.ata->Close(); TermNet(); + isRunning = false; } int DEV9irqHandler(void) @@ -1079,3 +1083,74 @@ void DEV9setLogDir(const char* dir) // Get the path to the log directory. s_strLogPath = (dir == NULL) ? "logs" : dir; } + +void ApplyConfigIfRunning(Config oldConfig) +{ + if (!isRunning) + return; + + //Eth + if (config.ethEnable) + { + if (oldConfig.ethEnable) + { + //Reload Net if adapter changed + if (strcmp(oldConfig.Eth, config.Eth) != 0) + { + TermNet(); + InitNet(); + } + } + else + InitNet(); + } + else if (oldConfig.ethEnable) + TermNet(); + + //Hdd + //Hdd Validate Path +#ifdef _WIN32 + ghc::filesystem::path hddPath(std::wstring(config.Hdd)); +#else + ghc::filesystem::path hddPath(config.Hdd); +#endif + + if (hddPath.empty()) + config.hddEnable = false; + + if (hddPath.is_relative()) + { + //GHC uses UTF8 on all platforms + ghc::filesystem::path path(GetSettingsFolder().ToUTF8().data()); + hddPath = path / hddPath; + } + + //Hdd Compare with old config + if (config.hddEnable) + { + if (oldConfig.hddEnable) + { + //ATA::Open/Close dosn't set any regs + //So we can close/open to apply settings +#ifdef _WIN32 + if (wcscmp(config.Hdd, oldConfig.Hdd)) +#else + if (strcmp(config.Hdd, oldConfig.Hdd)) +#endif + { + dev9.ata->Close(); + if (dev9.ata->Open(hddPath) != 0) + config.hddEnable = false; + } + + if (config.HddSize != oldConfig.HddSize) + { + dev9.ata->Close(); + if (dev9.ata->Open(hddPath) != 0) + config.hddEnable = false; + } + } + } + else if (oldConfig.hddEnable) + dev9.ata->Close(); +} diff --git a/pcsx2/DEV9/DEV9.h b/pcsx2/DEV9/DEV9.h index 85cc5b78aa..e4398ec88f 100644 --- a/pcsx2/DEV9/DEV9.h +++ b/pcsx2/DEV9/DEV9.h @@ -723,6 +723,7 @@ u32 DEV9read32(u32 addr); void DEV9write8(u32 addr, u8 value); void DEV9write16(u32 addr, u16 value); void DEV9write32(u32 addr, u32 value); +void ApplyConfigIfRunning(Config oldConfig); #ifdef _WIN32 #pragma warning(error : 4013) diff --git a/pcsx2/DEV9/Linux/Linux.cpp b/pcsx2/DEV9/Linux/Linux.cpp index 3709cbb451..943c326233 100644 --- a/pcsx2/DEV9/Linux/Linux.cpp +++ b/pcsx2/DEV9/Linux/Linux.cpp @@ -186,6 +186,8 @@ void OnOk() void DEV9configure() { ScopedCoreThreadPause paused_core; + Config oldConfig = config; + gtk_init(NULL, NULL); GError* error = NULL; if (builder == nullptr) @@ -217,5 +219,8 @@ void DEV9configure() break; } gtk_widget_hide(GTK_WIDGET(dlg)); + + ApplyConfigIfRunning(oldConfig); + paused_core.AllowResume(); } diff --git a/pcsx2/DEV9/Win32/Win32.cpp b/pcsx2/DEV9/Win32/Win32.cpp index 60a094c64a..f7e1a43d3f 100644 --- a/pcsx2/DEV9/Win32/Win32.cpp +++ b/pcsx2/DEV9/Win32/Win32.cpp @@ -358,11 +358,16 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) void DEV9configure() { ScopedCoreThreadPause paused_core; + Config oldConfig = config; + DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIG), GetActiveWindow(), (DLGPROC)ConfigureDlgProc); //SysMessage("Nothing to Configure"); + + ApplyConfigIfRunning(oldConfig); + paused_core.AllowResume(); }