From 5c772b06e387f00d1712fc47cadbba9784c8c9e4 Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Wed, 7 Apr 2021 17:21:53 +0000 Subject: [PATCH] hopefully fix checkpoint timescale stuff --- addons/sourcemod/scripting/include/shavit.inc | 1 + addons/sourcemod/scripting/shavit-core.sp | 76 +++++++------------ addons/sourcemod/scripting/shavit-misc.sp | 3 + 3 files changed, 31 insertions(+), 49 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index dacd2299..612f25bd 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -228,6 +228,7 @@ enum struct timer_snapshot_t float fDistanceOffset[2]; float fAvgVelocity; float fMaxVelocity; + float fTimescale; } enum struct cp_cache_t diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index e9e56f3f..e000983e 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -1675,23 +1675,7 @@ public int Native_FinishMap(Handle handler, int numParams) } timer_snapshot_t snapshot; - snapshot.bTimerEnabled = gA_Timers[client].bEnabled; - snapshot.bClientPaused = gA_Timers[client].bPaused; - snapshot.iJumps = gA_Timers[client].iJumps; - snapshot.bsStyle = gA_Timers[client].iStyle; - snapshot.iStrafes = gA_Timers[client].iStrafes; - snapshot.iTotalMeasures = gA_Timers[client].iTotalMeasures; - snapshot.iGoodGains = gA_Timers[client].iGoodGains; - snapshot.fServerTime = GetEngineTime(); - snapshot.fCurrentTime = gA_Timers[client].fTimer; - snapshot.iSHSWCombination = gA_Timers[client].iSHSWCombination; - snapshot.iTimerTrack = gA_Timers[client].iTrack; - snapshot.iMeasuredJumps = gA_Timers[client].iMeasuredJumps; - snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps; - snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; - snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; - snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity; - snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity; + BuildSnapshot(client, snapshot); Action result = Plugin_Continue; Call_StartForward(gH_Forwards_FinishPre); @@ -2037,23 +2021,7 @@ public int Native_SaveSnapshot(Handle handler, int numParams) int client = GetNativeCell(1); timer_snapshot_t snapshot; - snapshot.bTimerEnabled = gA_Timers[client].bEnabled; - snapshot.bClientPaused = gA_Timers[client].bPaused; - snapshot.iJumps = gA_Timers[client].iJumps; - snapshot.bsStyle = gA_Timers[client].iStyle; - snapshot.iStrafes = gA_Timers[client].iStrafes; - snapshot.iTotalMeasures = gA_Timers[client].iTotalMeasures; - snapshot.iGoodGains = gA_Timers[client].iGoodGains; - snapshot.fServerTime = GetEngineTime(); - snapshot.fCurrentTime = gA_Timers[client].fTimer; - snapshot.iSHSWCombination = gA_Timers[client].iSHSWCombination; - snapshot.iTimerTrack = gA_Timers[client].iTrack; - snapshot.iMeasuredJumps = gA_Timers[client].iMeasuredJumps; - snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps; - snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; - snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; - snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity; - snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity; + BuildSnapshot(client, snapshot); return SetNativeArray(2, snapshot, sizeof(timer_snapshot_t)); } @@ -2064,6 +2032,7 @@ public int Native_LoadSnapshot(Handle handler, int numParams) return ThrowNativeError(200, "timer_snapshot_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins", GetNativeCell(3), sizeof(timer_snapshot_t)); } + int client = GetNativeCell(1); timer_snapshot_t snapshot; @@ -2102,6 +2071,7 @@ public int Native_LoadSnapshot(Handle handler, int numParams) gA_Timers[client].fDistanceOffset = snapshot.fDistanceOffset; gA_Timers[client].fAvgVelocity = snapshot.fAvgVelocity; gA_Timers[client].fMaxVelocity = snapshot.fMaxVelocity; + gA_Timers[client].fTimescale = snapshot.fTimescale; return 0; } @@ -3494,21 +3464,7 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams) gA_Timers[client].iZoneIncrement++; timer_snapshot_t snapshot; - snapshot.bTimerEnabled = gA_Timers[client].bEnabled; - snapshot.bClientPaused = gA_Timers[client].bPaused; - snapshot.iJumps = gA_Timers[client].iJumps; - snapshot.bsStyle = gA_Timers[client].iStyle; - snapshot.iStrafes = gA_Timers[client].iStrafes; - snapshot.iTotalMeasures = gA_Timers[client].iTotalMeasures; - snapshot.iGoodGains = gA_Timers[client].iGoodGains; - snapshot.fServerTime = GetEngineTime(); - snapshot.fCurrentTime = gA_Timers[client].fTimer; - snapshot.iSHSWCombination = gA_Timers[client].iSHSWCombination; - snapshot.iTimerTrack = gA_Timers[client].iTrack; - snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; - snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; - snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity; - snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity; + BuildSnapshot(client, snapshot); Call_StartForward(gH_Forwards_OnTimerIncrement); Call_PushCell(client); @@ -3599,6 +3555,28 @@ bool TREnumTrigger(int entity, int client) { return true; } +void BuildSnapshot(int client, timer_snapshot_t snapshot) +{ + snapshot.bTimerEnabled = gA_Timers[client].bEnabled; + snapshot.bClientPaused = gA_Timers[client].bPaused; + snapshot.iJumps = gA_Timers[client].iJumps; + snapshot.bsStyle = gA_Timers[client].iStyle; + snapshot.iStrafes = gA_Timers[client].iStrafes; + snapshot.iTotalMeasures = gA_Timers[client].iTotalMeasures; + snapshot.iGoodGains = gA_Timers[client].iGoodGains; + snapshot.fServerTime = GetEngineTime(); + snapshot.fCurrentTime = gA_Timers[client].fTimer; + snapshot.iSHSWCombination = gA_Timers[client].iSHSWCombination; + snapshot.iTimerTrack = gA_Timers[client].iTrack; + snapshot.iMeasuredJumps = gA_Timers[client].iMeasuredJumps; + snapshot.iPerfectJumps = gA_Timers[client].iPerfectJumps; + snapshot.fTimeOffset = gA_Timers[client].fTimeOffset; + snapshot.fDistanceOffset = gA_Timers[client].fDistanceOffset; + snapshot.fAvgVelocity = gA_Timers[client].fAvgVelocity; + snapshot.fMaxVelocity = gA_Timers[client].fMaxVelocity; + snapshot.fTimescale = gA_Timers[client].fTimescale; +} + public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2]) { if(IsFakeClient(client)) diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 11dacc4b..86ee9770 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -2380,6 +2380,9 @@ void SaveCheckpointCache(int target, cp_cache_t cpcache, bool isPersistentData) snapshot.fServerTime = GetEngineTime(); snapshot.iSHSWCombination = -1; snapshot.iTimerTrack = Shavit_GetReplayBotTrack(target); + snapshot.fTimescale = Shavit_GetStyleSettingFloat(snapshot.bsStyle, "timescale"); + cpcache.fSpeed = snapshot.fTimescale; + ScaleVector(cpcache.fVelocity, 1 / cpcache.fSpeed); } else {