diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2024-09-20 14:24:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-20 14:24:56 +0200 |
commit | a4b09bc42d5f79ef86697c893efc9e3b7d966502 (patch) | |
tree | d4c7b2b8cc04361ddf7b9c942e5f9462bb55e0b9 /primedev/core/tier0.cpp | |
parent | a9d2ce8a692f7890f4e4bfc21458332890605a5f (diff) | |
parent | 6737a344c012c0f7fd19cd593949dd3dbe5a0cb7 (diff) | |
download | NorthstarLauncher-a4b09bc42d5f79ef86697c893efc9e3b7d966502.tar.gz NorthstarLauncher-a4b09bc42d5f79ef86697c893efc9e3b7d966502.zip |
Merge branch 'main' into feat/overhaul-mod-loading-locations
Diffstat (limited to 'primedev/core/tier0.cpp')
-rw-r--r-- | primedev/core/tier0.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/primedev/core/tier0.cpp b/primedev/core/tier0.cpp index dd5ac245..639b3bf8 100644 --- a/primedev/core/tier0.cpp +++ b/primedev/core/tier0.cpp @@ -18,11 +18,40 @@ void TryCreateGlobalMemAlloc() g_pMemAllocSingleton = CreateGlobalMemAlloc(); // if it already exists, this returns the preexisting IMemAlloc instance } +HRESULT WINAPI _SetThreadDescription(HANDLE hThread, PCWSTR lpThreadDescription) +{ + // need to grab it dynamically as this function was only introduced at some point in Windows 10 + static decltype(&SetThreadDescription) _SetThreadDescription = + CModule("KernelBase.dll").GetExportedFunction("SetThreadDescription").RCast<decltype(&SetThreadDescription)>(); + + if (_SetThreadDescription) + return _SetThreadDescription(hThread, lpThreadDescription); + + return ERROR_OLD_WIN_VERSION; +} + +static void(__fastcall* o_pThreadSetDebugName)(HANDLE threadHandle, const char* name) = nullptr; +static void __fastcall h_ThreadSetDebugName(HANDLE threadHandle, const char* name) +{ + if (threadHandle == 0) + threadHandle = GetCurrentThread(); + + // TODO: This "method" of "charset conversion" from string to wstring is abhorrent. Change it to a proper one + // as soon as Northstar has some helper function to do proper charset conversions. + auto tmp = std::string(name); + _SetThreadDescription(threadHandle, std::wstring(tmp.begin(), tmp.end()).c_str()); + + o_pThreadSetDebugName(threadHandle, name); +} + ON_DLL_LOAD("tier0.dll", Tier0GameFuncs, (CModule module)) { // shouldn't be necessary, but do this just in case TryCreateGlobalMemAlloc(); + o_pThreadSetDebugName = module.GetExportedFunction("ThreadSetDebugName").RCast<decltype(o_pThreadSetDebugName)>(); + HookAttach(&(PVOID&)o_pThreadSetDebugName, (PVOID)h_ThreadSetDebugName); + // setup tier0 funcs CommandLine = module.GetExportedFunction("CommandLine").RCast<CommandLineType>(); Plat_FloatTime = module.GetExportedFunction("Plat_FloatTime").RCast<Plat_FloatTimeType>(); |