Skip to content

Commit f20e27f

Browse files
committed
Update schema system
1 parent cb36b56 commit f20e27f

File tree

5 files changed

+83
-87
lines changed

5 files changed

+83
-87
lines changed

AMBuildScript

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class MMSPluginConfig(object):
157157
'-fPIC',
158158
]
159159

160-
cxx.cxxflags += ['-std=c++17']
160+
cxx.cxxflags += ['-std=c++20']
161161
if (cxx.version >= 'gcc-4.0') or cxx.family == 'clang':
162162
cxx.cflags += ['-fvisibility=hidden']
163163
cxx.cxxflags += ['-fvisibility-inlines-hidden']
@@ -204,7 +204,7 @@ class MMSPluginConfig(object):
204204
cxx.cflags += [
205205
'/W3',
206206
'/Zi',
207-
'/std:c++17',
207+
'/std:c++20',
208208
]
209209
cxx.cxxflags += ['/TP']
210210

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
help='Plugin alias')
2626
parser.options.add_argument('--hl2sdk-root', type=str, dest='hl2sdk_root', default=None,
2727
help='Root search folder for HL2SDKs')
28-
parser.options.add_argument('--hl2sdk-manifests', type=str, dest='hl2sdk_manifests', default=None,
28+
parser.options.add_argument('--hl2sdk-manifests', type=str, dest='hl2sdk_manifests', default='hl2sdk-manifests/',
2929
help='HL2SDK manifests source tree folder')
3030
parser.options.add_argument('--mms_path', type=str, dest='mms_path', default=None,
3131
help='Metamod:Source source tree folder')

cs2_sdk/schema.cpp

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* =============================================================================
33
* CS2Fixes
4-
* Copyright (C) 2023 Source2ZE
4+
* Copyright (C) 2023-2025 Source2ZE
55
* =============================================================================
66
*
77
* This program is free software; you can redistribute it and/or modify it under
@@ -19,116 +19,113 @@
1919

2020
#include "schema.h"
2121

22-
#include "schemasystem/schemasystem.h"
23-
#include "tier1/utlmap.h"
24-
#include "tier0/memdbgon.h"
25-
#include "../utils/plat.h"
2622
#include "entity/cbaseentity.h"
23+
#include "../utils/plat.h"
24+
#include "schemasystem/schemasystem.h"
2725

28-
extern CSchemaSystem *g_pSchemaSystem2;
29-
extern CGlobalVars *gpGlobals;
30-
31-
using SchemaKeyValueMap_t = CUtlMap<uint32_t, SchemaKey>;
32-
using SchemaTableMap_t = CUtlMap<uint32_t, SchemaKeyValueMap_t*>;
26+
#include "tier0/memdbgon.h"
3327

28+
using SchemaKeyValueMap_t = std::map<uint32_t, SchemaKey>;
29+
using SchemaTableMap_t = std::map<uint32_t, SchemaKeyValueMap_t>;
3430

3531
static bool IsFieldNetworked(SchemaClassFieldData_t& field)
3632
{
37-
for (int i = 0; i < field.m_nStaticMetadataCount; i++)
38-
{
39-
static auto networkEnabled = hash_32_fnv1a_const("MNetworkEnable");
40-
if (networkEnabled == hash_32_fnv1a_const(field.m_pStaticMetadata[i].m_pszName))
41-
return true;
42-
}
43-
44-
return false;
45-
}
33+
for (int i = 0; i < field.m_nStaticMetadataCount; i++)
34+
{
35+
static auto networkEnabled = hash_32_fnv1a_const("MNetworkEnable");
36+
if (networkEnabled == hash_32_fnv1a_const(field.m_pStaticMetadata[i].m_pszName))
37+
return true;
38+
}
39+
40+
return false;
41+
}
4642

47-
static bool InitSchemaFieldsForClass(SchemaTableMap_t *tableMap, const char* className, uint32_t classKey)
43+
static bool InitSchemaFieldsForClass(SchemaTableMap_t& tableMap, const char* className, uint32_t classKey)
4844
{
49-
CSchemaSystemTypeScope* pType = g_pSchemaSystem2->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
45+
CSchemaSystemTypeScope* pType = g_pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
5046

51-
if (!pType)
52-
return false;
47+
if (!pType)
48+
return false;
5349

54-
SchemaClassInfoData_t *pClassInfo = pType->FindDeclaredClass(className).Get();
50+
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
5551

56-
if (!pClassInfo)
57-
{
58-
SchemaKeyValueMap_t *map = new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
59-
tableMap->Insert(classKey, map);
52+
if (!pClassInfo)
53+
{
54+
SchemaKeyValueMap_t map;
55+
tableMap.insert(std::make_pair(classKey, map));
6056

61-
Warning("InitSchemaFieldsForClass(): '%s' was not found!\n", className);
62-
return false;
63-
}
57+
Warning("InitSchemaFieldsForClass(): '%s' was not found!\n", className);
58+
return false;
59+
}
6460

65-
short fieldsSize = pClassInfo->m_nFieldCount;
66-
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
61+
short fieldsSize = pClassInfo->m_nFieldCount;
62+
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
6763

68-
SchemaKeyValueMap_t *keyValueMap = new SchemaKeyValueMap_t(0, 0, DefLessFunc(uint32_t));
69-
keyValueMap->EnsureCapacity(fieldsSize);
70-
tableMap->Insert(classKey, keyValueMap);
64+
SchemaKeyValueMap_t &keyValueMap = tableMap.insert(std::make_pair(classKey, SchemaKeyValueMap_t())).first->second;
7165

72-
for (int i = 0; i < fieldsSize; ++i)
73-
{
74-
SchemaClassFieldData_t& field = pFields[i];
66+
for (int i = 0; i < fieldsSize; ++i)
67+
{
68+
SchemaClassFieldData_t& field = pFields[i];
7569

7670
#ifdef _DEBUG
77-
Message("%s::%s found at -> 0x%X - %llx\n", className, field.m_name, field.m_single_inheritance_offset, &field);
71+
Message("%s::%s found at -> 0x%X - %llx\n", className, field.m_pszName, field.m_nSingleInheritanceOffset, &field);
7872
#endif
7973

80-
keyValueMap->Insert(hash_32_fnv1a_const(field.m_pszName), {field.m_nSingleInheritanceOffset, IsFieldNetworked(field)});
81-
}
74+
std::pair<uint32_t, SchemaKey> keyValuePair;
75+
keyValuePair.first = hash_32_fnv1a_const(field.m_pszName);
76+
keyValuePair.second.offset = field.m_nSingleInheritanceOffset;
77+
keyValuePair.second.networked = IsFieldNetworked(field);
78+
79+
keyValueMap.insert(keyValuePair);
80+
}
8281

83-
return true;
82+
return true;
8483
}
8584

8685
int16_t schema::FindChainOffset(const char* className)
8786
{
88-
CSchemaSystemTypeScope* pType = g_pSchemaSystem2->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
87+
CSchemaSystemTypeScope* pType = g_pSchemaSystem->FindTypeScopeForModule(MODULE_PREFIX "server" MODULE_EXT);
8988

90-
if (!pType)
91-
return false;
89+
if (!pType)
90+
return false;
9291

93-
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
92+
SchemaClassInfoData_t* pClassInfo = pType->FindDeclaredClass(className).Get();
9493

95-
do
96-
{
97-
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
98-
short fieldsSize = pClassInfo->m_nFieldCount;
99-
for (int i = 0; i < fieldsSize; ++i)
100-
{
101-
SchemaClassFieldData_t& field = pFields[i];
94+
do
95+
{
96+
SchemaClassFieldData_t* pFields = pClassInfo->m_pFields;
97+
short fieldsSize = pClassInfo->m_nFieldCount;
98+
for (int i = 0; i < fieldsSize; ++i)
99+
{
100+
SchemaClassFieldData_t& field = pFields[i];
102101

103-
if (V_strcmp(field.m_pszName, "__m_pChainEntity") == 0)
104-
{
105-
return field.m_nSingleInheritanceOffset;
106-
}
107-
}
108-
} while ((pClassInfo = pClassInfo->m_pBaseClasses ? pClassInfo->m_pBaseClasses->m_pClass : nullptr) != nullptr);
102+
if (V_strcmp(field.m_pszName, "__m_pChainEntity") == 0)
103+
return field.m_nSingleInheritanceOffset;
104+
}
105+
} while ((pClassInfo = pClassInfo->m_pBaseClasses ? pClassInfo->m_pBaseClasses->m_pClass : nullptr) != nullptr);
109106

110-
return 0;
107+
return 0;
111108
}
112109

113110
SchemaKey schema::GetOffset(const char* className, uint32_t classKey, const char* memberName, uint32_t memberKey)
114111
{
115-
static SchemaTableMap_t schemaTableMap(0, 0, DefLessFunc(uint32_t));
116-
int16_t tableMapIndex = schemaTableMap.Find(classKey);
117-
if (!schemaTableMap.IsValidIndex(tableMapIndex))
118-
{
119-
if (InitSchemaFieldsForClass(&schemaTableMap, className, classKey))
120-
return GetOffset(className, classKey, memberName, memberKey);
121-
122-
return { 0, 0 };
123-
}
124-
125-
SchemaKeyValueMap_t *tableMap = schemaTableMap[tableMapIndex];
126-
int16_t memberIndex = tableMap->Find(memberKey);
127-
if (!tableMap->IsValidIndex(memberIndex))
128-
{
129-
Warning("schema::GetOffset(): '%s' was not found in '%s'!\n", memberName, className);
130-
return { 0, 0 };
131-
}
132-
133-
return tableMap->Element(memberIndex);
112+
static SchemaTableMap_t schemaTableMap;
113+
114+
if (!schemaTableMap.contains(classKey))
115+
{
116+
if (InitSchemaFieldsForClass(schemaTableMap, className, classKey))
117+
return GetOffset(className, classKey, memberName, memberKey);
118+
119+
return {0, 0};
120+
}
121+
122+
SchemaKeyValueMap_t tableMap = schemaTableMap[classKey];
123+
124+
if (!tableMap.contains(memberKey))
125+
{
126+
Warning("schema::GetOffset(): '%s' was not found in '%s'!\n", memberName, className);
127+
return {0, 0};
128+
}
129+
130+
return tableMap[memberKey];
134131
}

serverlistplayersfix.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ CSteamGameServerAPIContext g_steamAPI;
4747
IServerGameDLL* server = NULL;
4848
IVEngineServer* engine = NULL;
4949
IServerGameClients* gameclients = NULL;
50-
CSchemaSystem* g_pSchemaSystem2 = nullptr;
5150
CGameEntitySystem* g_pEntitySystem = nullptr;
5251

5352
CGameEntitySystem* GameEntitySystem()
@@ -71,7 +70,7 @@ bool ServerListPlayersFix::Load(PluginId id, ISmmAPI *ismm, char *error, size_t
7170
GET_V_IFACE_ANY(GetServerFactory, server, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
7271
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
7372
GET_V_IFACE_ANY(GetServerFactory, gameclients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
74-
GET_V_IFACE_CURRENT(GetEngineFactory, g_pSchemaSystem2, CSchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
73+
GET_V_IFACE_CURRENT(GetEngineFactory, g_pSchemaSystem, ISchemaSystem, SCHEMASYSTEM_INTERFACE_VERSION);
7574
GET_V_IFACE_ANY(GetEngineFactory, g_pNetworkServerService, INetworkServerService, NETWORKSERVERSERVICE_INTERFACE_VERSION);
7675
GET_V_IFACE_CURRENT(GetEngineFactory, g_pGameResourceServiceServer, IGameResourceService, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
7776

@@ -173,7 +172,7 @@ const char *ServerListPlayersFix::GetLicense()
173172

174173
const char *ServerListPlayersFix::GetVersion()
175174
{
176-
return "1.0.1";
175+
return "1.0.2";
177176
}
178177

179178
const char *ServerListPlayersFix::GetDate()

0 commit comments

Comments
 (0)