From faac1232bea42951e03d86dcb9f22b402721a23c Mon Sep 17 00:00:00 2001 From: Amos <48657826+Mauler125@users.noreply.github.com> Date: Mon, 7 Mar 2022 13:15:45 +0100 Subject: [PATCH] Make run on S1 again --- r5dev/engine/sys_engine.cpp | 32 ++++++++++++----------- r5dev/engine/sys_engine.h | 45 ++++++++++++++------------------- r5dev/launcher/IApplication.cpp | 4 +++ r5dev/launcher/IApplication.h | 8 ++---- 4 files changed, 42 insertions(+), 47 deletions(-) diff --git a/r5dev/engine/sys_engine.cpp b/r5dev/engine/sys_engine.cpp index fc2cde48..6adcec85 100644 --- a/r5dev/engine/sys_engine.cpp +++ b/r5dev/engine/sys_engine.cpp @@ -6,6 +6,7 @@ CEngine* g_pEngine = reinterpret_cast(g_pEngineBuffer.GetPtr()); //----------------------------------------------------------------------------- // Purpose: Start initializing the engine. +// Output : Returns true on success, false on failure. //----------------------------------------------------------------------------- bool CEngine::Load(bool dedicated, const char* rootDir) { @@ -16,7 +17,7 @@ bool CEngine::Load(bool dedicated, const char* rootDir) //----------------------------------------------------------------------------- // Purpose: Start to shutdown the engine. //----------------------------------------------------------------------------- -void CEngine::Unload() +void CEngine::Unload(void) { static int index = 2; CallVFunc(index, this); @@ -27,22 +28,21 @@ void CEngine::Unload() //----------------------------------------------------------------------------- void CEngine::SetNextState(EngineState_t iNextState) { - // Rebuild function, vfunc index is 3 in season 3. - m_nNextDLLState() = iNextState; + m_nNextDLLState = iNextState; } //----------------------------------------------------------------------------- // Purpose: Get the dll engine state. //----------------------------------------------------------------------------- -EngineState_t CEngine::GetState() +EngineState_t CEngine::GetState(void) const { - return m_nDLLState(); // Rebuild function, vfunc index is 4 in season 3. + return m_nDLLState; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -void CEngine::Frame() +void CEngine::Frame(void) { static int index = 5; CallVFunc(index, this); @@ -51,25 +51,27 @@ void CEngine::Frame() //----------------------------------------------------------------------------- // Purpose: Get engine frame time. //----------------------------------------------------------------------------- -float CEngine::GetFrameTime() +float CEngine::GetFrameTime(void) const { - return m_flFrameTime(); // Rebuild function, vfunc index is 6 in season 3. + return m_flFrameTime; } //----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- -float CEngine::GetPreviousTime() // I'm not sure if this is right, should double check. +float CEngine::GetPreviousTime(void) // I'm not sure if this is right, should double check. { static int index = 7; return CallVFunc(index, this); } -// Yes that is the function, I have no clue how to implement it at this moment so its gonna reside here for now. It's vfunc index 8. -//__m128 __fastcall GetCurTime(CEngine *thisPtr) -//{ -// return _mm_cvtpd_ps((__m128d)(unsigned __int64)thisPtr->m_flCurrentTime); -//} +//----------------------------------------------------------------------------- +// Purpose: +//----------------------------------------------------------------------------- +__m128 __fastcall CEngine::GetCurTime(CEngine *thisPtr) const +{ + return _mm_cvtpd_ps(_mm_cvtepi32_pd(_mm_cvtsi64_si128(thisPtr->m_flCurrentTime))); +} //----------------------------------------------------------------------------- // Purpose: Set dll state. @@ -78,4 +80,4 @@ void CEngine::SetQuitting(EngineDllQuitting_t quitDllState) { static int index = 9; CallVFunc(index, this, quitDllState); -} \ No newline at end of file +} diff --git a/r5dev/engine/sys_engine.h b/r5dev/engine/sys_engine.h index f84bc324..3a1b179c 100644 --- a/r5dev/engine/sys_engine.h +++ b/r5dev/engine/sys_engine.h @@ -24,39 +24,32 @@ enum class EngineDllQuitting_t : int QUIT_RESTART = 0x2, }; - -// TODO: Check if all indexes match up between seasons. If not patternscan them. class CEngine { public: bool Load(bool dedicated, const char* rootDir); - void Unload(); + void Unload(void); void SetNextState(EngineState_t iNextState); - EngineState_t GetState(); - void Frame(); - float GetFrameTime(); - float GetPreviousTime(); + EngineState_t GetState(void) const; + void Frame(void); + float GetFrameTime(void) const; + float GetPreviousTime(void); + __m128 GetCurTime(CEngine* thisPtr) const; void SetQuitting(EngineDllQuitting_t quitDllState); - // __m128 __fastcall GetCurTime() - // Last functions in class table. - // sub_1401FE2A0 - // sub_1401FE2B0 - // sub_1401FE3B0 - -#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) - MEMBER_AT_OFFSET(EngineState_t, m_nDLLState, 0x8); - MEMBER_AT_OFFSET(EngineState_t, m_nNextDLLState, 0xC); - MEMBER_AT_OFFSET(std::int64_t, m_flCurrentTime, 0x10); - MEMBER_AT_OFFSET(std::int64_t, m_flPreviousTime, 0x18); - MEMBER_AT_OFFSET(int, m_flFrameTime, 0x20); -#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) // TODO: Verify offsets for other seasons. Should probably be the same as Season 2. - MEMBER_AT_OFFSET(EngineState_t, m_nDLLState, 0x8); - MEMBER_AT_OFFSET(EngineState_t, m_nNextDLLState, 0xC); - MEMBER_AT_OFFSET(std::int64_t, m_flCurrentTime, 0x10); // They are 8 bytes for some reason but floats? Kinda confusing. - MEMBER_AT_OFFSET(std::int64_t, m_flPreviousTime, 0x18); - MEMBER_AT_OFFSET(float, m_flFrameTime, 0x20); -#endif +private: + void* vtable; + EngineState_t m_nDLLState; + EngineState_t m_nNextDLLState; + int64_t m_flCurrentTime; + int64_t m_flPreviousTime; + int m_flFrameTime; + int field_24; + int m_flFilteredTime; + uint8_t gap2C[4]; + int64_t field_30; + char field_38; + char field_39; }; namespace diff --git a/r5dev/launcher/IApplication.cpp b/r5dev/launcher/IApplication.cpp index be7c3f8d..bff65836 100644 --- a/r5dev/launcher/IApplication.cpp +++ b/r5dev/launcher/IApplication.cpp @@ -22,6 +22,9 @@ int HModAppSystemGroup_Main(CModAppSystemGroup* modAppSystemGroup) int nRunResult = RUN_OK; HEbisuSDK_Init(); // Not here in retail. We init EbisuSDK here though. +#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) // !TODO: rebuild does not work for S1 (CModAppSystemGroup and CEngine member offsets do align with all other builds). + return CModAppSystemGroup_Main(modAppSystemGroup); +#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) if (modAppSystemGroup->m_bIsServerOnly()) // This will never be true anyway but we implement it for the sake of it. { if (g_pEngine->Load(true, g_pEngineParms->baseDirectory)) @@ -46,6 +49,7 @@ int HModAppSystemGroup_Main(CModAppSystemGroup* modAppSystemGroup) } return nRunResult; +#endif } //----------------------------------------------------------------------------- diff --git a/r5dev/launcher/IApplication.h b/r5dev/launcher/IApplication.h index a4e5fa48..2797fe47 100644 --- a/r5dev/launcher/IApplication.h +++ b/r5dev/launcher/IApplication.h @@ -22,11 +22,7 @@ enum class CModAppSystemGroup { public: -#if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) MEMBER_AT_OFFSET(bool, m_bIsServerOnly, 0xA8); -#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) // TODO: Verify offset in CModAppSystemGroup::Main for other seasons. Should probably be the same as Season 2. - MEMBER_AT_OFFSET(bool, m_bIsServerOnly, 0xA8); -#endif }; //------------------------------------------------------------------------- @@ -37,13 +33,13 @@ namespace /* ==== CAPPSYSTEMGROUP ================================================================================================================================================= */ #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) ADDRESS p_CModAppSystemGroup_Main = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x83\xEC\x28\x80\xB9\x00\x00\x00\x00\x00\x48\x8B\x15\x00\x00\x00\x00", "xxxxxx?????xxx????"); - void* (*CModAppSystemGroup_Main)(void* modAppSystemGroup, void* a2) = (void* (*)(void*, void*))p_CModAppSystemGroup_Main.GetPtr(); /*48 83 EC 28 80 B9 ?? ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ??*/ + int (*CModAppSystemGroup_Main)(CModAppSystemGroup* modAppSystemGroup) = (int (*)(CModAppSystemGroup*))p_CModAppSystemGroup_Main.GetPtr(); /*48 83 EC 28 80 B9 ?? ?? ?? ?? ?? 48 8B 15 ?? ?? ?? ??*/ ADDRESS p_CModAppSystemGroup_Create = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x8B\xC4\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x83\xEC\x60\x48\xC7\x40\x00\x00\x00\x00\x00\x48\x89\x58\x08", "xxxxxxxxxxxxxxxxxxx?????xxxx"); bool (*CModAppSystemGroup_Create)(void* modAppSystemGroup) = (bool(*)(void*))p_CModAppSystemGroup_Create.GetPtr(); /*48 8B C4 57 41 54 41 55 41 56 41 57 48 83 EC 60 48 C7 40 ?? ?? ?? ?? ?? 48 89 58 08*/ #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) ADDRESS p_CModAppSystemGroup_Main = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x40\x53\x48\x83\xEC\x20\x80\xB9\x00\x00\x00\x00\x00\xBB\x00\x00\x00\x00", "xxxxxxxx?????x????"); - int (*CModAppSystemGroup_Main)(void* modAppSystemGroup) = (int(*)(void*))p_CModAppSystemGroup_Main.GetPtr(); /*40 53 48 83 EC 20 80 B9 ?? ?? ?? ?? ?? BB ?? ?? ?? ??*/ + int (*CModAppSystemGroup_Main)(CModAppSystemGroup* modAppSystemGroup) = (int(*)(CModAppSystemGroup*))p_CModAppSystemGroup_Main.GetPtr(); /*40 53 48 83 EC 20 80 B9 ?? ?? ?? ?? ?? BB ?? ?? ?? ??*/ ADDRESS p_CModAppSystemGroup_Create = g_mGameDll.FindPatternSIMD((std::uint8_t*)"\x48\x8B\xC4\x55\x41\x54\x41\x55\x41\x56\x41\x57\x48\x8B\xEC\x48\x83\xEC\x60", "xxxxxxxxxxxxxxxxxxx"); bool (*CModAppSystemGroup_Create)(void* modAppSystemGroup) = (bool(*)(void*))p_CModAppSystemGroup_Create.GetPtr(); /*48 8B C4 55 41 54 41 55 41 56 41 57 48 8B EC 48 83 EC 60*/