diff --git a/r5dev/core/dllmain.cpp b/r5dev/core/dllmain.cpp index da05d31b..f38db715 100644 --- a/r5dev/core/dllmain.cpp +++ b/r5dev/core/dllmain.cpp @@ -79,6 +79,15 @@ void SDK_Init() { Tier0_Init(); + // Allow skipping this check, as the popcnt instruction can be emulated. + // this allows CPU's like the 'Intel Pentium E5400' to run the dedicated + // server still. + if (!CommandLine()->CheckParm("-nocputest")) + { + // Check CPU as early as possible; error out if CPU isn't supported. + CheckCPU(); + } + if (!CommandLine()->CheckParm("-launcher")) { CommandLine()->AppendParametersFromFile(SDK_DEFAULT_CFG); @@ -147,7 +156,6 @@ void SDK_Shutdown() BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved) { - CheckCPU(); // Check CPU as early as possible; error out if CPU isn't supported. MathLib_Init(); // Initialize Mathlib. NOTE_UNUSED(lpReserved); diff --git a/r5dev/launcher/launcher.cpp b/r5dev/launcher/launcher.cpp index 0aa38bfc..ef8c41e4 100644 --- a/r5dev/launcher/launcher.cpp +++ b/r5dev/launcher/launcher.cpp @@ -12,6 +12,19 @@ #include "launcher/launcher.h" #include +static void CheckCPU() +{ + // Allow skipping this check, as the popcnt instruction can be emulated. + // this allows CPU's like the 'Intel Pentium E5400' to run the dedicated + // server still. + if (!CommandLine()->CheckParm("-nocputest")) + { + // Run the game's implementation of CheckCPU + // for SSE 3, SSSE 3 and POPCNT. + v_CheckCPU(); + } +} + int LauncherMain(HINSTANCE hInstance) { // Flush buffers every 5 seconds for every logger. @@ -81,6 +94,8 @@ LONG WINAPI TopLevelExceptionFilter(EXCEPTION_POINTERS* pExceptionPointers) void VLauncher::Attach(void) const { + DetourAttach((LPVOID*)&v_CheckCPU, &CheckCPU); + DetourAttach((LPVOID*)&v_LauncherMain, &LauncherMain); DetourAttach((LPVOID*)&v_TopLevelExceptionFilter, &TopLevelExceptionFilter); #if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) @@ -89,6 +104,8 @@ void VLauncher::Attach(void) const } void VLauncher::Detach(void) const { + DetourDetach((LPVOID*)&v_CheckCPU, &CheckCPU); + DetourDetach((LPVOID*)&v_LauncherMain, &LauncherMain); DetourDetach((LPVOID*)&v_TopLevelExceptionFilter, &TopLevelExceptionFilter); #if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) diff --git a/r5dev/launcher/launcher.h b/r5dev/launcher/launcher.h index 5037b532..5a3d6365 100644 --- a/r5dev/launcher/launcher.h +++ b/r5dev/launcher/launcher.h @@ -1,6 +1,9 @@ #ifndef LAUNCHER_H #define LAUNCHER_H +inline CMemory p_CheckCPU; +inline void(*v_CheckCPU)(void); + inline CMemory p_LauncherMain; inline int(*v_LauncherMain)(HINSTANCE hInstance); @@ -19,6 +22,7 @@ class VLauncher : public IDetour { virtual void GetAdr(void) const { + LogFunAdr("CheckCPU", p_CheckCPU.GetPtr()); LogFunAdr("LauncherMain", p_LauncherMain.GetPtr()); LogFunAdr("TopLevelExceptionFilter", p_TopLevelExceptionFilter.GetPtr()); #if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) @@ -27,6 +31,9 @@ class VLauncher : public IDetour } virtual void GetFun(void) const { + p_CheckCPU = g_GameDll.FindPatternSIMD("40 53 48 81 EC ?? ?? ?? ?? 33 C9"); + v_CheckCPU = p_CheckCPU.RCast(); + p_LauncherMain = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 8B C8 E8 ?? ?? ?? ?? CC").FollowNearCallSelf(); v_LauncherMain = p_LauncherMain.RCast();