Skip to content

Commit 8812801

Browse files
committed
make schema system works
1 parent ca5a9e0 commit 8812801

6 files changed

Lines changed: 64 additions & 17 deletions

File tree

gamedata/cs2fixes.games.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@
131131
"windows" "\x48\x89\x5C\x24\x08\x57\x48\x83\xEC\x2A\xF3\x0F\x10\x81\x04\x04\x00\x00"
132132
"linux" "\x55\x48\x89\xE5\x41\x57\x41\x56\x41\x55\x41\x54\x53\x48\x89\xFB\x48\x81\xEC\x2A\x2A\x2A\x2A\x0F\x2E\x87\x2A\x2A\x2A\x2A\x7A\x2A\x75\x2A\x48\x81\xC4\x2A\x2A\x2A\x2A\x5B\x41\x5C\x41\x5D\x41\x5E\x41\x5F\x5D\xC3\x0F\x1F\x40\x2A\x31\xC9\x31\xF6\x31\xFF\xF3\x0F\x11\x85\x2A\x2A\x2A\x2A\x66\x89\x8D\x2A\x2A\x2A\x2A\xBA\x2A\x2A\x2A\x2A\xB9\x2A\x2A\x2A\x2A\x66\x0F\xEF\xC9\x48\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x48\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x48\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x48\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x0F\x29\x8D\x2A\x2A\x2A\x2A\x48\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\xC7\x85\x2A\x2A\x2A\x2A\x2A\x2A\x2A\xE8\x2A\x2A\x2A\x2A\xF3\x0F\x10\x85\x2A\x2A\x2A\x2A\x85\xC0\x41\x89\xC4\x0F\x8E\x2A\x2A\x2A\x2A\x48\x63\x8D\x2A\x2A\x2A\x2A\x48\x63\xD0\x31\xF6\xF3\x0F\x11\x85\x2A\x2A\x2A\x2A\x48\xC1\xE2\x2A\x48\x8B\xBD\x2A\x2A\x2A\x2A\x48\xC1\xE1\x2A\x81\xBD\x2A\x2A\x2A\x2A\x2A\x2A\x2A\x40\x0F\x96\xC6\xE8\x2A\x2A\x2A\x2A\x8B\x95\x2A\x2A\x2A\x2A\xF3\x0F\x10\x85\x2A\x2A\x2A\x2A\x48\x89\x85\x2A\x2A\x2A\x2A\x81\xFA\x2A\x2A\x2A\x2A\x0F\x87"
133133
}
134+
"NetworkStateChanged"
135+
{
136+
"library" "server"
137+
"windows" "\x4C\x8B\xC2\x48\x8B\xD1\x48\x8B\x09"
138+
"linux" "\x48\x8B\x07\x48\x85\xC0\x74\x2A\x48\x8B\x50\x10"
139+
}
140+
134141
// "Game System %s is defined twice!\n"
135142
// Note that this signature points to the instruction with sm_pFirst which is the first qword referenced in the function.
136143
"IGameSystem_InitAllSystems_pFirst"
@@ -394,6 +401,11 @@
394401
}
395402
"Offsets"
396403
{
404+
"CBaseEntity::StateChanged"
405+
{
406+
"windows" "25"
407+
"linux" "26"
408+
}
397409
"CBaseEntity::Precache"
398410
{
399411
"windows" "4"

src/addresses.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ bool addresses::Initialize(CGameConfig* g_GameConfig)
5858
RESOLVE_SIG(g_GameConfig, "CBasePlayerController_SetPawn", addresses::CBasePlayerController_SetPawn);
5959
RESOLVE_SIG(g_GameConfig, "CBaseModelEntity_SetModel", addresses::CBaseModelEntity_SetModel);
6060
RESOLVE_SIG(g_GameConfig, "UTIL_Remove", addresses::UTIL_Remove);
61+
RESOLVE_SIG(g_GameConfig, "NetworkStateChanged", addresses::NetworkStateChanged);
6162
RESOLVE_SIG(g_GameConfig, "CEntitySystem_AddEntityIOEvent", addresses::CEntitySystem_AddEntityIOEvent);
6263
RESOLVE_SIG(g_GameConfig, "CEntityInstance_AcceptInput", addresses::CEntityInstance_AcceptInput);
6364
RESOLVE_SIG(g_GameConfig, "CGameEntitySystem_FindEntityByClassName", addresses::CGameEntitySystem_FindEntityByClassName);

src/addresses.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class INetworkStringTable;
5858
class CCSPlayer_WeaponServices;
5959
class CBasePlayerWeapon;
6060
class CSpawnGroupMgrGameSystem;
61-
61+
class CNetworkStateChangedInfo;
6262
struct EmitSound_t;
6363
struct SndOpEventGuid_t;
6464

@@ -85,7 +85,7 @@ namespace addresses
8585
inline void(FASTCALL* CBaseModelEntity_SetModel)(CBaseModelEntity* pModel, const char* szModel);
8686
inline void(FASTCALL* UTIL_Remove)(CEntityInstance*);
8787

88-
88+
inline void(FASTCALL* NetworkStateChanged)(void* chainEntity, CNetworkStateChangedInfo& info);
8989

9090
inline void(FASTCALL* CEntitySystem_AddEntityIOEvent)(CEntitySystem* pEntitySystem, CEntityInstance* pTarget, const char* pszInput,
9191
CEntityInstance* pActivator, CEntityInstance* pCaller, variant_t* value, float flDelay, int outputID);

src/cs2_sdk/schema.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* =============================================================================
33
* CS2Fixes
44
* Copyright (C) 2023-2025 Source2ZE
@@ -131,14 +131,17 @@ SchemaKey schema::GetOffset(const char* className, uint32_t classKey, const char
131131
return tableMap->Element(memberIndex);
132132
}
133133

134-
void EntityNetworkStateChanged(uintptr_t entityInstance, uint nOffset)
134+
void NetworkStateChanged(uintptr_t chainEntity, uint32_t offset, uint32_t nArrayIndex, uint32_t nPathIndex)
135135
{
136-
reinterpret_cast<CEntityInstance*>(entityInstance)->NetworkStateChanged(nOffset);
136+
CNetworkStateChangedInfo info(offset, nArrayIndex, nPathIndex);
137+
138+
addresses::NetworkStateChanged(reinterpret_cast<void*>(chainEntity), info);
137139
}
138140

139-
void ChainNetworkStateChanged(uintptr_t networkVarChainer, uint nLocalOffset)
141+
void SetStateChanged(uintptr_t pEntity, uint32_t offset, uint32_t nArrayIndex, uint32_t nPathIndex)
140142
{
141-
CEntityInstance* pEntity = *reinterpret_cast<CEntityInstance**>(networkVarChainer);
142-
if (pEntity && (pEntity->m_pEntity->m_flags & EF_IS_CONSTRUCTION_IN_PROGRESS) == 0)
143-
pEntity->NetworkStateChanged(nLocalOffset, -1, *reinterpret_cast<ChangeAccessorFieldPathIndex_t*>(networkVarChainer + 32));
143+
CNetworkStateChangedInfo info(offset, nArrayIndex, nPathIndex);
144+
145+
static auto fnOffset = g_GameConfig->GetOffset("CBaseEntity::StateChanged");
146+
CALL_VIRTUAL(void, fnOffset, (void*)pEntity, &info);
144147
}

src/cs2_sdk/schema.h

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* =============================================================================
33
* CS2Fixes
44
* Copyright (C) 2023-2025 Source2ZE
@@ -37,14 +37,44 @@
3737
#include "virtual.h"
3838
#undef schema
3939

40+
class CBaseEntity;
41+
4042
struct SchemaKey
4143
{
4244
int32 offset;
4345
bool networked;
4446
};
4547

46-
void EntityNetworkStateChanged(uintptr_t entityInstance, uint nOffset);
47-
void ChainNetworkStateChanged(uintptr_t networkVarChainer, uint nLocalOffset);
48+
struct CNetworkStateChangedInfo
49+
{
50+
CNetworkStateChangedInfo() = delete;
51+
52+
CNetworkStateChangedInfo(uint32_t nOffset, uint32_t nArrayIndex, uint32_t nPathIndex)
53+
{
54+
m_vecOffsetData.EnsureCount(1);
55+
m_vecOffsetData[0] = nOffset;
56+
57+
unk_30 = -1;
58+
59+
unk_3c = 0;
60+
61+
m_nArrayIndex = nArrayIndex;
62+
m_nPathIndex = nPathIndex;
63+
}
64+
65+
private:
66+
int m_nSize; // 0x0
67+
CUtlVector<uint32_t> m_vecOffsetData; // 0x8
68+
char* m_pszFieldName{}; // 0x20
69+
char* m_pszFileName{}; // 0x28
70+
uint32_t unk_30 = -1; // 0x30
71+
uint32_t m_nArrayIndex{}; // 0x34
72+
uint32_t m_nPathIndex{}; // 0x38
73+
uint16_t unk_3c{}; // 0x3c
74+
}; // Size: 0x3e
75+
76+
void NetworkStateChanged(uintptr_t chainEntity, uint32_t offset, uint32_t nArrayIndex = -1, uint32_t nPathIndex = -1);
77+
void SetStateChanged(uintptr_t pEntity, uint32_t offset, uint32_t nArrayIndex = -1, uint32_t nPathIndex = -1);
4878

4979
constexpr uint32_t val_32_const = 0x811c9dc5;
5080
constexpr uint32_t prime_32_const = 0x1000193;
@@ -96,16 +126,17 @@ inline constexpr uint64_t hash_64_fnv1a_const(const char* const str, const uint6
96126
if (m_chain != 0 && m_key.networked) \
97127
{ \
98128
DevMsg("Found chain offset %d for %s::%s\n", m_chain, ThisClassName, #varName); \
99-
ChainNetworkStateChanged((uintptr_t)(pThisClass) + m_chain, m_key.offset + extra_offset); \
129+
::NetworkStateChanged((uintptr_t)(pThisClass) + m_chain, m_key.offset + extra_offset); \
100130
} \
101131
else if (m_key.networked) \
102132
{ \
103133
/* WIP: Works fine for most props, but inlined classes in the middle of a class will \
104134
need to have their this pointer corrected by the offset .*/ \
105135
if (!IsStruct) \
106-
EntityNetworkStateChanged((uintptr_t)pThisClass, m_key.offset + extra_offset); \
107-
else \
108-
CALL_VIRTUAL(void, 1, pThisClass, m_key.offset + extra_offset, 0xFFFFFFFF, 0xFFFFFFFF); \
136+
::SetStateChanged((uintptr_t)pThisClass, m_key.offset + extra_offset); \
137+
/* Crash here if no VTable */ \
138+
/*else \
139+
CALL_VIRTUAL(void, 1, pThisClass, m_key.offset + extra_offset, 0xFFFFFFFF, 0xFFFFFFFF);*/ \
109140
} \
110141
*reinterpret_cast<std::add_pointer_t<type>>((uintptr_t)(pThisClass) + m_key.offset + extra_offset) = val; \
111142
} \

src/utils/virtual.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* =============================================================================
33
* CS2Fixes
44
* Copyright (C) 2023-2025 Source2ZE

0 commit comments

Comments
 (0)