Skip to content

Commit d93f698

Browse files
BotoXKyleSanderson
authored andcommitted
cstrike: Fix wrong timeleft calculation (#1072)
* Fix wrong timeleft calculation * reorder function calls
1 parent 2075848 commit d93f698

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

extensions/cstrike/extension.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ IGameConfig *g_pGameConf = NULL;
5151
IGameEventManager2 *gameevents = NULL;
5252
bool hooked_everything = false;
5353
int g_msgHintText = -1;
54+
CGlobalVars *gpGlobals;
5455

5556
SMEXT_LINK(&g_CStrike);
5657

@@ -107,6 +108,7 @@ bool CStrike::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool
107108
{
108109
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
109110
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
111+
gpGlobals = ismm->GetCGlobals();
110112

111113
return true;
112114
}

extensions/cstrike/extension.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class CStrike :
166166
extern IBinTools *g_pBinTools;
167167
extern IGameConfig *g_pGameConf;
168168
extern ISDKTools *g_pSDKTools;
169+
extern CGlobalVars *gpGlobals;
169170
extern int g_msgHintText;
170171
extern bool g_pIgnoreTerminateDetour;
171172
extern bool g_pIgnoreCSWeaponDropDetour;

extensions/cstrike/timeleft.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,19 @@ void TimeLeftEvents::FireGameEvent(IGameEvent *event)
5858
if (get_new_timeleft_offset || !round_end_found)
5959
{
6060
get_new_timeleft_offset = false;
61-
timersys->NotifyOfGameStart();
61+
62+
float flGameStartTime = gpGlobals->curtime;
63+
uintptr_t gamerules = (uintptr_t)g_pSDKTools->GetGameRules();
64+
if (gamerules)
65+
{
66+
sm_sendprop_info_t info;
67+
if (gamehelpers->FindSendPropInfo("CCSGameRulesProxy", "m_flGameStartTime", &info))
68+
{
69+
flGameStartTime = *(float *)(gamerules + info.actual_offset);
70+
}
71+
}
72+
73+
timersys->NotifyOfGameStart(flGameStartTime - gpGlobals->curtime);
6274
timersys->MapTimeLeftChanged();
6375
}
6476
round_end_found = false;

0 commit comments

Comments
 (0)