-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathgamesystem.cpp
102 lines (82 loc) · 3.23 KB
/
gamesystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* =============================================================================
* CS2Fixes
* Copyright (C) 2023-2025 Source2ZE
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gamesystem.h"
#include "addresses.h"
#include "adminsystem.h"
#include "common.h"
#include "entities.h"
#include "gameconfig.h"
#include "idlemanager.h"
#include "leader.h"
#include "playermanager.h"
#include "tier0/vprof.h"
#include "zombiereborn.h"
#include "tier0/memdbgon.h"
extern CGlobalVars* gpGlobals;
extern CGameConfig* g_GameConfig;
CBaseGameSystemFactory** CBaseGameSystemFactory::sm_pFirst = nullptr;
CGameSystem g_GameSystem;
IGameSystemFactory* CGameSystem::sm_Factory = nullptr;
// This mess is needed to get the pointer to sm_pFirst so we can insert game systems
bool InitGameSystems()
{
// This signature directly points to the instruction referencing sm_pFirst, and the opcode is 3 bytes so we skip those
uint8* ptr = (uint8*)g_GameConfig->ResolveSignature("IGameSystem_InitAllSystems_pFirst") + 3;
if (!ptr)
{
Panic("Failed to InitGameSystems, see warnings above.\n");
return false;
}
// Grab the offset as 4 bytes
uint32 offset = *(uint32*)ptr;
// Go to the next instruction, which is the starting point of the relative jump
ptr += 4;
// Now grab our pointer
CBaseGameSystemFactory::sm_pFirst = (CBaseGameSystemFactory**)(ptr + offset);
// And insert the game system(s)
CGameSystem::sm_Factory = new CGameSystemStaticFactory<CGameSystem>("CS2Fixes_GameSystem", &g_GameSystem);
return true;
}
extern std::string g_sBurnParticle;
GS_EVENT_MEMBER(CGameSystem, BuildGameSessionManifest)
{
Message("CGameSystem::BuildGameSessionManifest\n");
IEntityResourceManifest* pResourceManifest = msg->m_pResourceManifest;
// This takes any resource type, model or not
// Any resource adding MUST be done here, the resource manifest is not long-lived
// pResourceManifest->AddResource("characters/models/my_character_model.vmdl");
ZR_Precache(pResourceManifest);
PrecacheBeaconParticle(pResourceManifest);
Leader_Precache(pResourceManifest);
pResourceManifest->AddResource(g_sBurnParticle.c_str());
}
// Called every frame before entities think
GS_EVENT_MEMBER(CGameSystem, ServerPreEntityThink)
{
VPROF_BUDGET("CGameSystem::ServerPreEntityThink", "CS2FixesPerFrame")
g_playerManager->FlashLightThink();
g_pIdleSystem->UpdateIdleTimes();
EntityHandler_OnGameFramePre(gpGlobals->m_bInSimulation, gpGlobals->tickcount);
}
// Called every frame after entities think
GS_EVENT_MEMBER(CGameSystem, ServerPostEntityThink)
{
VPROF_BUDGET("CGameSystem::ServerPostEntityThink", "CS2FixesPerFrame")
g_playerManager->UpdatePlayerStates();
}