From 4680f8cecc945fac8dfb86d531f5573a5c6c0162 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 21 May 2022 12:42:28 +0200 Subject: [PATCH] Reduce CPU time on dedicated server Additional functions and statements found during performance profiling. Swapped 'Community_Frame()' C3 patch in favor of using shipped ConVar instead. --- r5dev/common/opcodes.cpp | 12 ++++++++++-- r5dev/common/opcodes.h | 12 +++++++++--- r5dev/tier1/IConVar.cpp | 2 ++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/r5dev/common/opcodes.cpp b/r5dev/common/opcodes.cpp index e3fb2bb0..954aac2f 100644 --- a/r5dev/common/opcodes.cpp +++ b/r5dev/common/opcodes.cpp @@ -313,8 +313,16 @@ void Dedicated_Init() //------------------------------------------------------------------------- // RUNTIME: COMMUNITIES //------------------------------------------------------------------------- - Community_Frame.Offset(0x0).Patch({ 0xC3 }); // FUN --> RET | Return early to prevent 'Community_Frame()' from being ran every frame on the server (CLIENT ONLY). - //GetEngineClientThread.Offset(0x0).Patch({ 0xB8, 0x00, 0x00, 0x00, 0x00, 0xC3 }); // FUN --> RET | Return nullptr for mp_gamemode thread assignment during registration callback. + { + //GetEngineClientThread.Offset(0x0).Patch({ 0xB8, 0x00, 0x00, 0x00, 0x00, 0xC3 }); // FUN --> RET | Return nullptr for mp_gamemode thread assignment during registration callback. + } + + //------------------------------------------------------------------------- + // RUNTIME: MATCHMAKING + //------------------------------------------------------------------------- + { + MatchMaking_Frame.Patch({ 0xB8, 0x00, 0x00, 0x00, 0x00, 0xC3 }); // FUN --> RET | Return early for 'MatchMaking_Frame()'. + } { CWin32Surface_initStaticData.Patch({ 0xC3 }); // FUN --> RET | Prevent 'CWin32Surface::initStaticData()' from being ran in CInit. diff --git a/r5dev/common/opcodes.h b/r5dev/common/opcodes.h index de6a7281..164a329c 100644 --- a/r5dev/common/opcodes.h +++ b/r5dev/common/opcodes.h @@ -74,7 +74,7 @@ inline CMemory UpdateMaterialSystemConfig; inline CMemory HandleConfigFile; inline CMemory ResetPreviousGameState; inline CMemory LoadPlayerConfig; -inline CMemory Community_Frame; +inline CMemory MatchMaking_Frame; inline CMemory GetEngineClientThread; inline CMemory CWin32Surface_initStaticData; #if !defined (GAMEDLL_S0) || !defined (GAMEDLL_S1) @@ -209,13 +209,19 @@ class VOpcodes : public IDetour #elif defined (GAMEDLL_S3) LoadPlayerConfig = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x89\x4C\x24\x08\x48\x81\xEC\x00\x00\x00\x00\x48\x83\x3D\x00\x00\x00\x00\x00"), "xxxxxxx????xxx?????"); #endif - Community_Frame = g_mGameDll.FindPatternSIMD(reinterpret_cast("\xE8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x8B\x0D\x00\x00\x00\x00\x48\x85\xC9\x0F\x84\x00\x00\x00\x00\x48\x8B\x01"), "x????x????xxx????xxxxx????xxx").FollowNearCallSelf(); - #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) GetEngineClientThread = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x48\x83\xEC\x20\x65\x48\x8B\x04\x25\x00\x00\x00\x00\x48\x8B\xD9\xB9\x00\x00\x00\x00\x48\x8B\x10\x8B\x04\x11\x39\x05\x00\x00\x00\x00\x7F\x15"), "xxxxxxxxxxx????xxxx????xxxxxxxx????xx"); #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) GetEngineClientThread = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x48\x83\xEC\x20\x65\x48\x8B\x04\x25\x00\x00\x00\x00\x48\x8B\xD9\xB9\x00\x00\x00\x00\x48\x8B\x10\x8B\x04\x11\x39\x05\x00\x00\x00\x00\x7F\x21"), "xxxxxxxxxxx????xxxx????xxxxxxxx????xx"); #endif +#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) + MatchMaking_Frame = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x55\x56\x41\x54\x41\x55\x48\x8D\xAC\x24\x00\x00\x00\x00"), "xxxxxxxxxxx????"); +#elif defined (GAMEDLL_S2) + MatchMaking_Frame = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x74\x24\x00\x55\x41\x54\x41\x57\x48\x8D\xAC\x24\x00\x00\x00\x00"), "xxxx?xxxxxxxxx????"); +#elif defined (GAMEDLL_S3) + MatchMaking_Frame = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x8B\xC4\x55\x48\x8D\xA8\x00\x00\x00\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x89\x78\x18"), "xxxxxxx????xxx????xxxx"); +#endif + CWin32Surface_initStaticData = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x48\x83\xEC\x28\xE8\x00\x00\x00\x00\x48\x8D\x0D\x00\x00\x00\x00\x48\x83\xC4\x28\xE9\x00\x00\x00\x00\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x33\xC9"), "xxxxx????xxx????xxxxx????xxxxxxxxx"); // 48 83 EC 28 E8 ? ? ? ? 48 8D 0D ? ? ? ? 48 83 C4 28 E9 ? ? ? ? CC CC CC CC CC CC CC 33 C9 diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index 79a1b0b3..286245c6 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -194,8 +194,10 @@ void ConVar::PurgeShipped(void) const { "bink_materials_enabled", "communities_enabled", + "community_frame_run", "ime_enabled", "origin_igo_mutes_sound_enabled", + "twitch_shouldQuery", "voice_enabled", };