curtime resets on mapchange, use net_time

This commit is contained in:
BotoX 2019-07-28 15:41:03 +02:00
parent 84e07e975e
commit 7b8d71d1fa
2 changed files with 17 additions and 4 deletions

View File

@ -97,6 +97,7 @@ IServer *iserver = NULL;
CGlobalVars *gpGlobals = NULL;
IHLTVDirector *hltvdirector = NULL;
IHLTVServer *hltv = NULL;
double *net_time = NULL;
uint8_t g_UserIDtoClientMap[USHRT_MAX + 1];
char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][32];
@ -142,7 +143,7 @@ struct CQueryCache
char name[MAX_PLAYER_NAME_LENGTH];
unsigned nameLen;
int32_t score;
float time;
double time;
} players[SM_MAXPLAYERS + 1];
struct CInfo
@ -720,7 +721,7 @@ bool Hook_ProcessConnectionlessPacket(netpacket_t * packet)
pos += player.nameLen + 1;
*(int32_t *)&response[pos] = player.score; // Score | long | Player's score (usually "frags" or "kills".)
pos += 4;
*(float *)&response[pos] = gpGlobals->curtime - player.time; // Duration | float | Time (in seconds) player has been connected to the server.
*(float *)&response[pos] = *net_time - player.time; // Duration | float | Time (in seconds) player has been connected to the server.
pos += 4;
}
@ -817,6 +818,12 @@ bool Connect::SDK_OnLoad(char *error, size_t maxlen, bool late)
return false;
}
if(!g_pGameConf->GetMemSig("net_time", (void **)&net_time) || !net_time)
{
snprintf(error, maxlen, "Failed to find net_time address.\n");
return false;
}
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
g_Detour_CBaseServer__ConnectClient = DETOUR_CREATE_MEMBER(CBaseServer__ConnectClient, "CBaseServer__ConnectClient");
@ -1066,7 +1073,7 @@ void Connect::SDK_OnAllLoaded()
INetChannelInfo *netinfo = (INetChannelInfo *)player.pClient->GetNetChannel();
if(netinfo)
player.time = netinfo->GetTimeConnected();
player.time = *net_time - netinfo->GetTimeConnected();
else
player.time = 0;
@ -1146,7 +1153,7 @@ void ConnectEvents::FireGameEvent(IGameEvent *event)
player.fake = true;
g_QueryCache.info.nFakeClients++;
}
player.time = gpGlobals->curtime;
player.time = *net_time;
player.score = 0;
player.nameLen = strlcpy(player.name, player.pClient->GetClientName(), sizeof(player.name));

View File

@ -90,6 +90,12 @@
"library" "engine"
"linux" "@hltv"
}
"net_time"
{
"library" "engine"
"linux" "@net_time"
}
}
"Offsets"