From 8b89c1d2b556b3f3dd473297a0a3e95f0341feaa Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 26 Mar 2023 16:47:47 +0200 Subject: [PATCH] Init concommand/convars a bit earlier Init in 'CEngineAPI::Init'. --- r5dev/engine/sys_dll2.cpp | 16 +++++++++++----- r5dev/engine/sys_dll2.h | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/r5dev/engine/sys_dll2.cpp b/r5dev/engine/sys_dll2.cpp index 384f1747..ffc5e5b5 100644 --- a/r5dev/engine/sys_dll2.cpp +++ b/r5dev/engine/sys_dll2.cpp @@ -77,16 +77,20 @@ static void InitVPKSystem() } } +InitReturnVal_t CEngineAPI::VInit(CEngineAPI* pEngineAPI) +{ + ConCommand::InitShipped(); + ConCommand::PurgeShipped(); + ConVar::InitShipped(); + ConVar::PurgeShipped(); + return CEngineAPI_Init(pEngineAPI); +} + //----------------------------------------------------------------------------- // Initialization, shutdown of a mod. //----------------------------------------------------------------------------- bool CEngineAPI::VModInit(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir) { - ConCommand::InitShipped(); - ConCommand::PurgeShipped(); - ConVar::InitShipped(); - ConVar::PurgeShipped(); - // Register new Pak Assets here! //RTech_RegisterAsset(0, 1, "", nullptr, nullptr, nullptr, CMemory(0x1660AD0A8).RCast(), 8, 8, 8, 0, 0xFFFFFFC); @@ -153,12 +157,14 @@ void CEngineAPI::VSetStartupInfo(CEngineAPI* pEngineAPI, StartupInfo_t* pStartup /////////////////////////////////////////////////////////////////////////////// void VSys_Dll2::Attach() const { + DetourAttach(&CEngineAPI_Init, &CEngineAPI::VInit); DetourAttach(&CEngineAPI_ModInit, &CEngineAPI::VModInit); DetourAttach(&v_CEngineAPI_SetStartupInfo, &CEngineAPI::VSetStartupInfo); } void VSys_Dll2::Detach() const { + DetourDetach(&CEngineAPI_Init, &CEngineAPI::VInit); DetourDetach(&CEngineAPI_ModInit, &CEngineAPI::VModInit); DetourDetach(&v_CEngineAPI_SetStartupInfo, &CEngineAPI::VSetStartupInfo); } \ No newline at end of file diff --git a/r5dev/engine/sys_dll2.h b/r5dev/engine/sys_dll2.h index 6d6e9dcd..fbca1d85 100644 --- a/r5dev/engine/sys_dll2.h +++ b/r5dev/engine/sys_dll2.h @@ -30,7 +30,7 @@ public: // Reset the map we're on virtual void SetMap(const char* pMapName) = 0; - + static InitReturnVal_t VInit(CEngineAPI* thisp); static bool VModInit(CEngineAPI* pEngineAPI, const char* pModName, const char* pGameDir); static void VSetStartupInfo(CEngineAPI* pEngineAPI, StartupInfo_t* pStartupInfo); //private: @@ -39,6 +39,12 @@ public: StartupInfo_t m_StartupInfo; }; +inline CMemory p_CEngineAPI_Init; +inline auto CEngineAPI_Init = p_CEngineAPI_Init.RCast(); + +inline CMemory p_CEngineAPI_Shutdown; +inline auto CEngineAPI_Shutdown = p_CEngineAPI_Shutdown.RCast(); + inline CMemory p_CEngineAPI_Connect; inline auto CEngineAPI_Connect = p_CEngineAPI_Connect.RCast(); @@ -67,6 +73,8 @@ class VSys_Dll2 : public IDetour { virtual void GetAdr(void) const { + LogFunAdr("CEngineAPI::Init", p_CEngineAPI_Init.GetPtr()); + LogFunAdr("CEngineAPI::Shutdown", p_CEngineAPI_Shutdown.GetPtr()); LogFunAdr("CEngineAPI::Connect", p_CEngineAPI_Connect.GetPtr()); LogFunAdr("CEngineAPI::ModInit", p_CEngineAPI_ModInit.GetPtr()); LogFunAdr("CEngineAPI::MainLoop", p_CEngineAPI_MainLoop.GetPtr()); @@ -82,12 +90,15 @@ class VSys_Dll2 : public IDetour } virtual void GetFun(void) const { + p_CEngineAPI_Init = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B F1 48 8D 3D ?? ?? ?? ?? 33 DB 48 8D 15 ?? ?? ?? ??"); p_CEngineAPI_Connect = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? 48 85 C0 48 89 15"); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) + p_CEngineAPI_Shutdown = g_GameDll.FindPatternSIMD("41 54 41 56 48 83 EC 38 48 8B 0D ?? ?? ?? ??"); p_CEngineAPI_ModInit = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 41 54 41 55 41 56 41 57 48 81 EC ?? ?? ?? ?? 4D 8B F0"); p_CEngineAPI_MainLoop = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 48 81 EC ?? ?? ?? ?? 45 33 C9"); p_PakFile_Init = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 44 88 44 24 ?? 56 57 41 54 41 56 41 57 48 83 EC 20"); #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) + p_CEngineAPI_Shutdown = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 0D ?? ?? ?? ?? 33 D2 48 8B 01 FF 90 ?? ?? ?? ?? B1 01"); p_CEngineAPI_ModInit = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 4C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ?? ?? ?? ?? 4D 8B F8"); p_CEngineAPI_MainLoop = g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ?? 84 C0 B9 ?? ?? ?? ??").FollowNearCallSelf(); p_PakFile_Init = g_GameDll.FindPatternSIMD("44 88 44 24 ?? 53 55 56 57"); @@ -95,6 +106,8 @@ class VSys_Dll2 : public IDetour p_CEngineAPI_SetStartupInfo = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? ?? 48 81 EC ?? ?? ?? ?? 80 3D ?? ?? ?? ?? ?? 48 8B DA"); p_ResetMTVFTaskItem = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 15 ?? ?? ?? ?? 48 85 D2 0F 84 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? 48 8B 01 FF 90 ?? ?? ?? ?? 33 C9 E8 ?? ?? ?? ?? 0F 28 05 ?? ?? ?? ?? 0F 28 0D ?? ?? ?? ?? 0F 11 05 ?? ?? ?? ?? 0F 28 05 ?? ?? ?? ?? 0F 11 0D ?? ?? ?? ?? 0F 28 0D ?? ?? ?? ?? 0F 11 05 ?? ?? ?? ?? 0F 11 0D ?? ?? ?? ?? 48 C7 05 ?? ?? ?? ?? ?? ?? ?? ?? FF 15 ?? ?? ?? ??"); + CEngineAPI_Init = p_CEngineAPI_Init.RCast(); + CEngineAPI_Shutdown = p_CEngineAPI_Shutdown.RCast(); CEngineAPI_Connect = p_CEngineAPI_Connect.RCast(); /*48 83 EC 28 48 8B 05 ?? ?? ?? ?? 48 8D 0D ?? ?? ?? ?? 48 85 C0 48 89 15 ?? ?? ?? ??*/ CEngineAPI_ModInit = p_CEngineAPI_ModInit.RCast(); /*48 89 5C 24 ?? 48 89 4C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 81 EC ?? ?? ?? ?? 4D 8B F8*/ CEngineAPI_MainLoop = p_CEngineAPI_MainLoop.RCast(); /*E8 ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ?? 84 C0 B9 ?? ?? ?? ??*/