Add CCommonHostState to SDK

The previous 'interval_per_tick' global belongs to the 'g_pCommonHostState' singleton.
This commit is contained in:
Kawe Mazidjatari 2023-09-17 16:44:18 +02:00
parent b723cb35cc
commit 71d0332dca
5 changed files with 101 additions and 5 deletions

View File

@ -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
{

View File

@ -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;

View File

@ -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

View File

@ -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<uintptr_t>(g_pCommonHostState));
LogVarAdr("g_bAbortServerSet", reinterpret_cast<uintptr_t>(g_bAbortServerSet));
LogVarAdr("interval_per_tick", reinterpret_cast<uintptr_t>(interval_per_tick));
LogVarAdr("host_abortserver", reinterpret_cast<uintptr_t>(host_abortserver));
LogVarAdr("host_initialized", reinterpret_cast<uintptr_t>(host_initialized));
LogVarAdr("host_frametime_unbounded", reinterpret_cast<uintptr_t>(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<float*>();
g_pCommonHostState = g_GameDll.FindPatternSIMD("48 83 EC 28 84 C9 75 0B")
.FindPatternSelf("48 8B 15").ResolveRelativeAddressSelf(0x3, 0x7).RCast<CCommonHostState*>();
#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<bool*>();
host_abortserver = p_Host_Error.FindPattern("48 8D 0D", CMemory::Direction::DOWN, 512, 3).ResolveRelativeAddress(3, 7).RCast<jmp_buf*>();

View File

@ -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