From ace7aa4acbe6c724650b9093eff1ed19bf3cd087 Mon Sep 17 00:00:00 2001 From: otavepto <153766569+otavepto@users.noreply.github.com> Date: Wed, 3 Jan 2024 01:56:26 +0200 Subject: [PATCH] added a new debug option "ResumeByDebugger" for the Windows version of the client loader --- CHANGELOG.md | 3 ++ post_build/README.experimental_steamclient.md | 6 +++- .../win/ColdClientLoader.cpp | 29 +++++++++++++++++-- .../win/ColdClientLoader.ini | 23 ++++++++------- 4 files changed, 48 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a98a630..39671078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* added a new option to the Windows version of the client loader to aid in debugging. +the option is called `ResumeByDebugger`, and setting it to `1` will prevent the loader from +auto resuming the main app thread, giving you a chance to attach your debugger. * make the script `generate_emu_config` generate an empty `DLC.txt` if the app has no DLCs * windows build: sign each file after build with a self-signed generated certificate + note in the release readme regarding false-positives * windows build: note in readme about Windows SDK diff --git a/post_build/README.experimental_steamclient.md b/post_build/README.experimental_steamclient.md index ac97ad2d..acb413c6 100644 --- a/post_build/README.experimental_steamclient.md +++ b/post_build/README.experimental_steamclient.md @@ -24,7 +24,11 @@ You do not need to create a `steam_interfaces.txt` file for the `steamclient` ve * `ExeCommandLine` additional args to pass to the exe, example: `-dx11 -windowed` Optionally you can specify a different location for `steamclient(64).dll`: * `SteamClientDll`: path to `steamclient.dll`, either full path or relative to this `.ini` file - * `SteamClientDll`: path to `steamclient(64).dll`, either full path or relative to this `.ini` file + * `SteamClientDll`: path to `steamclient(64).dll`, either full path or relative to this `.ini` file + * For debug **build** only: + * `ResumeByDebugger`: setting this to `1` or 'y' or `true` will prevent the loader from calling `ResumeThread` on the main thread after spawning the .exe, and it will display a mesage with the process ID (PID) so you attach your debugger on it. + Note that you have to resume the main thread from the debugger after attaching, also the entry breakpoint may not be set automatically, but you can do that manually. + **Note** that any arguments passed to `steamclient_loader.exe` via command line will be passed to the target `.exe`. Example: `steamclient_loader.exe` `-dx11` diff --git a/tools/steamclient_loader/win/ColdClientLoader.cpp b/tools/steamclient_loader/win/ColdClientLoader.cpp index 3c5b3c71..feee2a6a 100644 --- a/tools/steamclient_loader/win/ColdClientLoader.cpp +++ b/tools/steamclient_loader/win/ColdClientLoader.cpp @@ -10,6 +10,7 @@ #include #include #include +#include bool IsNotRelativePathOrRemoveFileName(WCHAR* output, bool Remove) { @@ -166,8 +167,32 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance return 1; } - // run and wait - ResumeThread(processInfo.hThread); + bool run_exe = true; +#ifndef EMU_RELEASE_BUILD + { + std::wstring dbg_file(50, L'\0'); + auto res_dbg_len = GetPrivateProfileStringW(L"Debug", L"ResumeByDebugger", L"", &dbg_file[0], dbg_file.size(), CurrentDirectory); + if (dbg_file[0]) { + dbg_file = dbg_file.substr(0, res_dbg_len); + } else { + dbg_file.clear(); + } + for (auto &c : dbg_file) { + c = (wchar_t)std::tolower((int)c); + } + if (dbg_file == L"1" || dbg_file == L"y" || dbg_file == L"yes" || dbg_file == L"true") { + run_exe = false; + std::string msg = "Attach a debugger now to PID " + std::to_string(processInfo.dwProcessId) + " and resume its main thread"; + MessageBoxA(NULL, msg.c_str(), "ColdClientLoader", MB_OK); + } + } +#endif + + // run + if (run_exe) { + ResumeThread(processInfo.hThread); + } + // wait WaitForSingleObject(processInfo.hThread, INFINITE); CloseHandle(processInfo.hThread); diff --git a/tools/steamclient_loader/win/ColdClientLoader.ini b/tools/steamclient_loader/win/ColdClientLoader.ini index bc65aa24..02d9fa5a 100644 --- a/tools/steamclient_loader/win/ColdClientLoader.ini +++ b/tools/steamclient_loader/win/ColdClientLoader.ini @@ -1,10 +1,13 @@ -#My own modified version of ColdClientLoader originally by Rat431 -[SteamClient] -Exe=game.exe -ExeRunDir=. -ExeCommandLine= -#IMPORTANT: -AppId= - -SteamClientDll=steamclient.dll -SteamClient64Dll=steamclient64.dll +#My own modified version of ColdClientLoader originally by Rat431 +[SteamClient] +Exe=game.exe +ExeRunDir=. +ExeCommandLine= +#IMPORTANT: +AppId= + +SteamClientDll=steamclient.dll +SteamClient64Dll=steamclient64.dll + +[Debug] +ResumeByDebugger=0