Skip to content

Commit 263b18a

Browse files
committed
fix: edge-cases with MaxClients zero
For whatever reason, the first load into a map with a forward slash `/` in the path causes `engine->GetMaxClients()` to return 0, and the same for *every* load with a backslash `\` in the path. Fixes #324
1 parent fb145b2 commit 263b18a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Modules/Engine.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ float Engine::GetIPT() { // IntervalPerTick
110110
}
111111
return 1.0f / sar.game->Tickrate();
112112
}
113+
int Engine::GetMaxClients() {
114+
if (this->GetMaxClientsOrig() == 0) {
115+
return server->gpGlobals->maxClients;
116+
}
117+
return this->GetMaxClientsOrig();
118+
}
113119
int Engine::GetTick() {
114120
return (this->GetMaxClients() < 2 || engine->demoplayer->IsPlaying()) ? *this->tickcount : TIME_TO_TICKS(*this->net_time);
115121
}
@@ -978,7 +984,7 @@ bool Engine::Init() {
978984
this->GetLocalPlayer = this->engineClient->Original<_GetLocalPlayer>(Offsets::GetLocalPlayer);
979985
this->GetViewAngles = this->engineClient->Original<_GetViewAngles>(Offsets::GetViewAngles);
980986
this->SetViewAngles = this->engineClient->Original<_SetViewAngles>(Offsets::SetViewAngles);
981-
this->GetMaxClients = this->engineClient->Original<_GetMaxClients>(Offsets::GetMaxClients);
987+
this->GetMaxClientsOrig = this->engineClient->Original<_GetMaxClients>(Offsets::GetMaxClients);
982988
this->GetGameDirectory = this->engineClient->Original<_GetGameDirectory>(Offsets::GetGameDirectory);
983989
this->GetSaveDirName = this->engineClient->Original<_GetSaveDirName>(Offsets::GetSaveDirName);
984990
this->DebugDrawPhysCollide = this->engineClient->Original<_DebugDrawPhysCollide>(Offsets::DebugDrawPhysCollide);

src/Modules/Engine.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Engine : public Module {
6767
_GetLocalPlayer GetLocalPlayer = nullptr;
6868
_GetViewAngles GetViewAngles = nullptr;
6969
_SetViewAngles SetViewAngles = nullptr;
70-
_GetMaxClients GetMaxClients = nullptr;
70+
_GetMaxClients GetMaxClientsOrig = nullptr;
7171
_GetGameDirectory GetGameDirectory = nullptr;
7272
_GetSaveDirName GetSaveDirName = nullptr;
7373
_GetActiveSplitScreenPlayerSlot GetActiveSplitScreenPlayerSlot = nullptr;
@@ -125,6 +125,7 @@ class Engine : public Module {
125125
public:
126126
void ExecuteCommand(const char *cmd, bool immediately = false);
127127
float GetIPT();
128+
int GetMaxClients();
128129
int GetTick();
129130
float ToTime(int tick);
130131
int GetLocalPlayerIndex();

0 commit comments

Comments
 (0)