From 71d0332dcaccf84c67e473d0d61492ddf488f035 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 17 Sep 2023 16:44:18 +0200 Subject: [PATCH] Add CCommonHostState to SDK The previous 'interval_per_tick' global belongs to the 'g_pCommonHostState' singleton. --- r5dev/engine/client/clientstate.cpp | 2 +- r5dev/engine/gl_model_private.h | 39 ++++++++++++++++++++++++++++- r5dev/engine/host.cpp | 18 +++++++++++++ r5dev/engine/host.h | 32 ++++++++++++++++++++--- r5dev/public/bspfile.h | 15 +++++++++++ 5 files changed, 101 insertions(+), 5 deletions(-) diff --git a/r5dev/engine/client/clientstate.cpp b/r5dev/engine/client/clientstate.cpp index 35c528ac..4845d9f2 100644 --- a/r5dev/engine/client/clientstate.cpp +++ b/r5dev/engine/client/clientstate.cpp @@ -58,7 +58,7 @@ float CClientState::GetClientTime() const { if (m_bClockCorrectionEnabled) { - return (float)m_ClockDriftMgr.m_nSimulationTick * (*(float*)&interval_per_tick); // VERIFY DEREF + return (float)m_ClockDriftMgr.m_nSimulationTick * g_pCommonHostState->interval_per_tick; } else { diff --git a/r5dev/engine/gl_model_private.h b/r5dev/engine/gl_model_private.h index 5b1f7ac6..aba93d99 100644 --- a/r5dev/engine/gl_model_private.h +++ b/r5dev/engine/gl_model_private.h @@ -14,15 +14,52 @@ #include "common/qlimits.h" #include "datacache/imdlcache.h" #include "public/model_types.h" +#include "public/bspfile.h" #ifndef DEDICATED #include "game/client/enginesprite.h" #endif // !DEDICATED typedef int ModelFileNameHandle_t; // 4 bytes in r5, void* originally. +struct worldbrushdata_t +{ + char unk[64]; + Vector3D* vertpositions; + int numvertices; + char unk_4C[4]; + Vector3D* vertnormals; + int numvertnormals; + int numtexdata; + dtexdata_t* texdata; + char* surfacenames; + char unk_60[4]; + int nummeshes; + char unk_78[72]; + int nummaterialsorts; + char unk_C4[4]; + char* lmapTypes; + int* lmapSizes; + dlightmapheader_t* lmapHeaders; + char* rtlData; + char* rtlPageData; + int numRtlPages; + int numLightmapHeaders; + bool externalLightmaps; + int numlightprobeindices; + int* lightprobeindices; + int numlightprobes; + dlightprobe_t* lightprobes; + char* lightproberefs; + char* lightprobetrees; + char* lightprobeparentinfos; + char unk_130[16]; + char* worldlights; + int numworldlights; +}; + struct brushdata_t // !! UNCONFIRMED !! { - void* pShared; // worldbrushdata_t + worldbrushdata_t* pShared; // worldbrushdata_t int firstmodelsurface; int nummodelsurfaces; diff --git a/r5dev/engine/host.cpp b/r5dev/engine/host.cpp index b878cdeb..53abafbc 100644 --- a/r5dev/engine/host.cpp +++ b/r5dev/engine/host.cpp @@ -12,6 +12,24 @@ #include "vgui/vgui_debugpanel.h" #endif // !DEDICATED +CCommonHostState* g_pCommonHostState = nullptr; + +void CCommonHostState::SetWorldModel(model_t* pModel) +{ + if (worldmodel == pModel) + return; + + worldmodel = pModel; + if (pModel) + { + worldbrush = pModel->brush.pShared; + } + else + { + worldbrush = NULL; + } +} + /* ================== _Host_RunFrame diff --git a/r5dev/engine/host.h b/r5dev/engine/host.h index 68f7ab36..e0d721c7 100644 --- a/r5dev/engine/host.h +++ b/r5dev/engine/host.h @@ -1,4 +1,5 @@ #pragma once +#include "engine/gl_model_private.h" inline CMemory p_Host_RunFrame; inline void(*v_Host_RunFrame)(void* unused, float time); @@ -16,13 +17,37 @@ inline void(*v_Host_Error)(const char* error, ...); //inline void(*v_VCR_EnterPausedState)(void); inline bool* g_bAbortServerSet = nullptr; -inline float* interval_per_tick = nullptr; inline jmp_buf* host_abortserver = nullptr; inline bool* host_initialized = nullptr; inline float* host_frametime_unbounded = nullptr; inline float* host_frametime_stddeviation = nullptr; +class CCommonHostState +{ +public: + CCommonHostState() + : worldmodel(NULL) + , worldbrush(NULL) + , interval_per_tick(0.0f) + , max_splitscreen_players(1) + , max_splitscreen_players_clientdll(1) + {} + + // cl_entitites[0].model + model_t* worldmodel; + struct worldbrushdata_t* worldbrush; + // Tick interval for game + float interval_per_tick; + // 1, unless a game supports split screen, then probably 2 or 4 (4 is the max allowable) + int max_splitscreen_players; + // This is the # the client .dll thinks is the max, it might be > max_splitscreen_players in -tools mode, etc. + int max_splitscreen_players_clientdll; + void SetWorldModel(model_t* pModel); +}; + +extern CCommonHostState* g_pCommonHostState; + /////////////////////////////////////////////////////////////////////////////// class VHost : public IDetour { @@ -33,8 +58,8 @@ class VHost : public IDetour LogFunAdr("Host_ShouldRun", p_Host_ShouldRun.GetPtr()); LogFunAdr("Host_Error", p_Host_Error.GetPtr()); //LogFunAdr("VCR_EnterPausedState", p_VCR_EnterPausedState.GetPtr()); + LogVarAdr("g_CommonHostState", reinterpret_cast(g_pCommonHostState)); LogVarAdr("g_bAbortServerSet", reinterpret_cast(g_bAbortServerSet)); - LogVarAdr("interval_per_tick", reinterpret_cast(interval_per_tick)); LogVarAdr("host_abortserver", reinterpret_cast(host_abortserver)); LogVarAdr("host_initialized", reinterpret_cast(host_initialized)); LogVarAdr("host_frametime_unbounded", reinterpret_cast(host_frametime_unbounded)); @@ -60,7 +85,8 @@ class VHost : public IDetour } virtual void GetVar(void) const { - interval_per_tick = g_GameDll.FindPatternSIMD("4C 8B DC 4D 89 4B 20 55 56 41 54").FindPatternSelf("F3 0F 5E", CMemory::Direction::DOWN, 150).ResolveRelativeAddressSelf(0x4, 0x8).RCast(); + g_pCommonHostState = g_GameDll.FindPatternSIMD("48 83 EC 28 84 C9 75 0B") + .FindPatternSelf("48 8B 15").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) g_bAbortServerSet = p_Host_Error.FindPattern("40 38 3D", CMemory::Direction::DOWN, 512, 2).ResolveRelativeAddress(3, 7).RCast(); host_abortserver = p_Host_Error.FindPattern("48 8D 0D", CMemory::Direction::DOWN, 512, 3).ResolveRelativeAddress(3, 7).RCast(); diff --git a/r5dev/public/bspfile.h b/r5dev/public/bspfile.h index 2e4a1c32..a78170c3 100644 --- a/r5dev/public/bspfile.h +++ b/r5dev/public/bspfile.h @@ -331,6 +331,13 @@ struct dgamelump_t int filelen; }; +struct dlightmapheader_t +{ + char type; + short width; + short height; +}; + struct dlightprobe_t { short ambientSH[12]; // Ambient spherical harmonics coefficients @@ -340,4 +347,12 @@ struct dlightprobe_t char pad[4]; // Padding has been removed as of S14 }; +struct dtexdata_t +{ + int nameStringTableID; + int width; + int height; + int flags; +}; + #endif // BSPFILE_H