Skip to content
Permalink
Browse files

cstrike: Fix wrong timeleft calculation (#1072)

* Fix wrong timeleft calculation

* reorder function calls
  • Loading branch information...
BotoX authored and KyleSanderson committed Sep 2, 2019
1 parent 2075848 commit d93f6984cc8486bc51c9d53e86c04687a55c3a60
Showing with 16 additions and 1 deletion.
  1. +2 −0 extensions/cstrike/extension.cpp
  2. +1 −0 extensions/cstrike/extension.h
  3. +13 −1 extensions/cstrike/timeleft.cpp
@@ -51,6 +51,7 @@ IGameConfig *g_pGameConf = NULL;
IGameEventManager2 *gameevents = NULL;
bool hooked_everything = false;
int g_msgHintText = -1;
CGlobalVars *gpGlobals;

SMEXT_LINK(&g_CStrike);

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

return true;
}
@@ -166,6 +166,7 @@ class CStrike :
extern IBinTools *g_pBinTools;
extern IGameConfig *g_pGameConf;
extern ISDKTools *g_pSDKTools;
extern CGlobalVars *gpGlobals;
extern int g_msgHintText;
extern bool g_pIgnoreTerminateDetour;
extern bool g_pIgnoreCSWeaponDropDetour;
@@ -58,7 +58,19 @@ void TimeLeftEvents::FireGameEvent(IGameEvent *event)
if (get_new_timeleft_offset || !round_end_found)
{
get_new_timeleft_offset = false;
timersys->NotifyOfGameStart();

float flGameStartTime = gpGlobals->curtime;
uintptr_t gamerules = (uintptr_t)g_pSDKTools->GetGameRules();
if (gamerules)
{
sm_sendprop_info_t info;
if (gamehelpers->FindSendPropInfo("CCSGameRulesProxy", "m_flGameStartTime", &info))
{
flGameStartTime = *(float *)(gamerules + info.actual_offset);
}
}

timersys->NotifyOfGameStart(flGameStartTime - gpGlobals->curtime);
timersys->MapTimeLeftChanged();
}
round_end_found = false;

0 comments on commit d93f698

Please sign in to comment.
You can’t perform that action at this time.