From 9fc6f83e8c1af184af0c8c7d9d6a1941dae2bf63 Mon Sep 17 00:00:00 2001 From: KiD Fearless Date: Tue, 7 Apr 2020 13:35:03 -0600 Subject: [PATCH 1/4] Fix SQL Syntax error in MySQL 8.0 --- addons/sourcemod/scripting/shavit-stats.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index 88aab204..a7a89723 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -433,7 +433,7 @@ Action OpenStatsMenu(int client, int steamid) "JOIN (SELECT COUNT(*) maps FROM (SELECT map FROM %smapzones WHERE track = 0 AND type = 0 GROUP BY map) s) b " ... "JOIN (SELECT COUNT(*) wrs FROM %splayertimes a JOIN (SELECT MIN(time) time, map FROM %splayertimes WHERE style = 0 AND track = 0 GROUP by map, style, track) b ON a.time = b.time AND a.map = b.map AND track = 0 AND style = 0 WHERE auth = %d) c " ... "JOIN (SELECT name, ip, lastlogin, FORMAT(points, 2) points FROM %susers WHERE auth = %d) d " ... - "JOIN (SELECT COUNT(*) rank FROM %susers u1 JOIN (SELECT points FROM %susers WHERE auth = %d) u2 WHERE u1.points >= u2.points) e " ... + "JOIN (SELECT COUNT(*) rank FROM %susers as u1 JOIN (SELECT points FROM %susers WHERE auth = %d) u2 WHERE u1.points >= u2.points) e " ... "LIMIT 1;", gS_MySQLPrefix, steamid, gS_MySQLPrefix, gS_MySQLPrefix, gS_MySQLPrefix, steamid, gS_MySQLPrefix, steamid, gS_MySQLPrefix, gS_MySQLPrefix, steamid); } From db5ee570f090c957ed7f50e3e30d9ef067c26792 Mon Sep 17 00:00:00 2001 From: deadw1nter Date: Wed, 8 Apr 2020 04:12:32 +0800 Subject: [PATCH 2/4] Prerun should only record when you are in start zone (#885) * Make clearpreframe optional --- addons/sourcemod/scripting/shavit-replay.sp | 33 +++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index a8860d8b..7386299d 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -118,6 +118,7 @@ bool gB_Button[MAXPLAYERS+1]; int gI_PlayerFrames[MAXPLAYERS+1]; int gI_PlayerPrerunFrames[MAXPLAYERS+1]; int gI_PlayerTimerStartFrames[MAXPLAYERS+1]; +bool gB_ClearFrame[MAXPLAYERS+1]; ArrayList gA_PlayerFrames[MAXPLAYERS+1]; int gI_Track[MAXPLAYERS+1]; float gF_LastInteraction[MAXPLAYERS+1]; @@ -154,6 +155,7 @@ Convar gCV_BotWeapon = null; Convar gCV_PlaybackCanStop = null; Convar gCV_PlaybackCooldown = null; Convar gCV_PlaybackPreRunTime = null; +Convar gCV_ClearPreRun = null; // timer settings int gI_Styles = 0; @@ -290,6 +292,7 @@ public void OnPluginStart() gCV_PlaybackCanStop = new Convar("shavit_replay_pbcanstop", "1", "Allow players to stop playback if they requested it?", 0, true, 0.0, true, 1.0); gCV_PlaybackCooldown = new Convar("shavit_replay_pbcooldown", "10.0", "Cooldown in seconds to apply for players between each playback they request/stop.\nDoes not apply to RCON admins.", 0, true, 0.0); gCV_PlaybackPreRunTime = new Convar("shavit_replay_preruntime", "1.0", "Time (in seconds) to record before a player leaves start zone. (The value should NOT be too high)", 0, true, 0.0); + gCV_ClearPreRun = new Convar("shavit_replay_clearprefrunframe", "0.0", "Clear prerun frame when entering start zone?", 0, true, 0.0, true, 1.0); gCV_CentralBot.AddChangeHook(OnConVarChanged); @@ -1601,11 +1604,23 @@ public Action Shavit_OnStart(int client) { gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length - RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale); gI_PlayerTimerStartFrames[client] = gA_PlayerFrames[client].Length; - - if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale)) + + if(!gB_ClearFrame[client]) { - gA_PlayerFrames[client].Erase(0); - gI_PlayerFrames[client]--; + if(gCV_ClearPreRun.BoolValue) + { + ClearFrames(client); + } + gB_ClearFrame[client] = true; + } + + else + { + if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale)) + { + gA_PlayerFrames[client].Erase(0); + gI_PlayerFrames[client]--; + } } return Plugin_Continue; @@ -1616,6 +1631,14 @@ public void Shavit_OnStop(int client) ClearFrames(client); } +public void Shavit_OnLeaveZone(int client, int type, int track, int id, int entity) +{ + if(type == Zone_Start) + { + gB_ClearFrame[client] = false; + } +} + public void Shavit_OnFinish(int client, int style, float time, int jumps, int strafes, float sync, int track) { if(Shavit_IsPracticeMode(client)) @@ -1625,8 +1648,6 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st if(!gCV_Enabled.BoolValue || (gCV_TimeLimit.FloatValue > 0.0 && time > gCV_TimeLimit.FloatValue)) { - ClearFrames(client); - return; } From 38461223675cd5d25ab5ba5f4b2c9d4ae892fade Mon Sep 17 00:00:00 2001 From: KiD Fearless Date: Tue, 7 Apr 2020 14:16:59 -0600 Subject: [PATCH 3/4] Change language of prerun convar --- addons/sourcemod/scripting/shavit-replay.sp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 7386299d..b5555e8e 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -292,7 +292,7 @@ public void OnPluginStart() gCV_PlaybackCanStop = new Convar("shavit_replay_pbcanstop", "1", "Allow players to stop playback if they requested it?", 0, true, 0.0, true, 1.0); gCV_PlaybackCooldown = new Convar("shavit_replay_pbcooldown", "10.0", "Cooldown in seconds to apply for players between each playback they request/stop.\nDoes not apply to RCON admins.", 0, true, 0.0); gCV_PlaybackPreRunTime = new Convar("shavit_replay_preruntime", "1.0", "Time (in seconds) to record before a player leaves start zone. (The value should NOT be too high)", 0, true, 0.0); - gCV_ClearPreRun = new Convar("shavit_replay_clearprefrunframe", "0.0", "Clear prerun frame when entering start zone?", 0, true, 0.0, true, 1.0); + gCV_ClearPreRun = new Convar("shavit_replay_prerun_always", "1", "Record prerun frames outside the start zone?", 0, true, 0.0, true, 1.0); gCV_CentralBot.AddChangeHook(OnConVarChanged); @@ -1607,7 +1607,7 @@ public Action Shavit_OnStart(int client) if(!gB_ClearFrame[client]) { - if(gCV_ClearPreRun.BoolValue) + if(!gCV_ClearPreRun.BoolValue) { ClearFrames(client); } From 91f83e2c2afc9eb8171a7dced5932c9704c1b27e Mon Sep 17 00:00:00 2001 From: deadw1nter Date: Fri, 10 Apr 2020 23:57:21 +0800 Subject: [PATCH 4/4] Clean up prerun code + Add prerun countdown to hud (#886) * remove timer preframe variables * Prerun should only record when you are in start zone * Make clearpreframe optional * add prerun countdown to hud --- addons/sourcemod/scripting/include/shavit.inc | 15 +------- addons/sourcemod/scripting/shavit-hud.sp | 13 +++++-- addons/sourcemod/scripting/shavit-misc.sp | 7 +--- addons/sourcemod/scripting/shavit-replay.sp | 37 +++++++++---------- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index e249a292..c8529ce7 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -239,7 +239,6 @@ enum struct cp_cache_t int iClassname; ArrayList aFrames; int iPreFrames; - int iTimerPreFrames; bool bSegmented; int iSerial; bool bPractice; @@ -1731,25 +1730,15 @@ native void Shavit_SetCurrentCheckpoint(int client, int index); */ native int Shavit_GetPlayerPreFrame(int client); -/* - * Gets player's timer frame - * - * @param client Client index - * - * @return Timer start frame - */ - native int Shavit_GetPlayerTimerframe(int client); - /* * Sets player's preeframe length * * @param client Client index - * @param PreFrame PreFrame length - * @param timerPreFrame Timer start frame length + * @param preframe preframe length * * @noreturn */ -native void Shavit_SetPlayerPreFrame(int client, int PreFrame, int timereframe); +native void Shavit_SetPlayerPreFrame(int client, int preframe); // same as Shavit_PrintToChat() but loops through the whole server // code stolen from the base halflife.inc file diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index cdeef640..55b00c9f 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -124,6 +124,7 @@ Convar gCV_GradientStepSize = null; Convar gCV_TicksPerUpdate = null; Convar gCV_SpectatorList = null; Convar gCV_UseHUDFix = null; +Convar gCV_PrerunCountDown = null; // timer settings stylestrings_t gS_StyleStrings[STYLE_LIMIT]; @@ -197,6 +198,7 @@ public void OnPluginStart() gCV_TicksPerUpdate = new Convar("shavit_hud_ticksperupdate", "5", "How often (in ticks) should the HUD update?\nPlay around with this value until you find the best for your server.\nThe maximum value is your tickrate.", 0, true, 1.0, true, (1.0 / GetTickInterval())); gCV_SpectatorList = new Convar("shavit_hud_speclist", "1", "Who to show in the specators list?\n0 - everyone\n1 - all admins (admin_speclisthide override to bypass)\n2 - players you can target", 0, true, 0.0, true, 2.0); gCV_UseHUDFix = new Convar("shavit_hud_csgofix", "1", "Apply the csgo color fix to the center hud?\nThis will add a dollar sign and block sourcemod hooks to hint message", 0, true, 0.0, true, 1.0); + gCV_PrerunCountDown = new Convar("shavit_hud_prerun_countdown", "1", "Display prerun countdown to the replay hud?", 0, true, 0.0, true, 1.0); Convar.AutoExecConfig(); @@ -987,7 +989,7 @@ int AddHUDToBuffer_Source2013(int client, huddata_t data, char[] buffer, int max char sTime[32]; FormatSeconds(data.fTime, sTime, 32, false); - if(data.fTime < 0.0) + if(data.fTime < 0.0 && gCV_PrerunCountDown.BoolValue) { Format(sTime, 32, "-%s", sTime); } @@ -995,7 +997,7 @@ int AddHUDToBuffer_Source2013(int client, huddata_t data, char[] buffer, int max char sWR[32]; FormatSeconds(data.fWR, sWR, 32, false); - FormatEx(sLine, 128, "%s / %s\n(%.1f%)", sTime, sWR, ((data.fTime <= 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); + FormatEx(sLine, 128, "%s / %s\n(%.1f%)", sTime, sWR, ((data.fTime < 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); AddHUDLine(buffer, maxlen, sLine, iLines); iLines++; } @@ -1168,10 +1170,15 @@ int AddHUDToBuffer_CSGO(int client, huddata_t data, char[] buffer, int maxlen) char sTime[32]; FormatSeconds(data.fTime, sTime, 32, false); + if(data.fTime < 0.0 && gCV_PrerunCountDown.BoolValue) + { + Format(sTime, 32, "-%s", sTime); + } + char sWR[32]; FormatSeconds(data.fWR, sWR, 32, false); - FormatEx(sLine, 128, "%s / %s (%.1f%%)", sTime, sWR, ((data.fTime / data.fWR) * 100)); + FormatEx(sLine, 128, "%s / %s (%.1f%%)", sTime, sWR, ((data.fTime < 0.0 ? 0.0 : data.fTime / data.fWR) * 100)); AddHUDLine(buffer, maxlen, sLine, iLines); iLines++; } diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index fa91bfc0..c63cd40b 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -64,7 +64,6 @@ enum struct persistent_data_t int iClassname; ArrayList aFrames; int iPreFrames; - int iTimerPreFrames; bool bPractice; } @@ -1136,7 +1135,6 @@ void PersistData(int client) { aData.aFrames = Shavit_GetReplayData(client); aData.iPreFrames = Shavit_GetPlayerPreFrame(client); - aData.iTimerPreFrames = Shavit_GetPlayerTimerframe(client); } aData.fDisconnectTime = GetEngineTime(); @@ -1257,7 +1255,7 @@ public Action Timer_LoadPersistentData(Handle Timer, any data) if(gB_Replay && aData.aFrames != null) { Shavit_SetReplayData(client, aData.aFrames); - Shavit_SetPlayerPreFrame(client, aData.iPreFrames, aData.iTimerPreFrames); + Shavit_SetPlayerPreFrame(client, aData.iPreFrames); } if(aData.bPractice) @@ -2350,7 +2348,6 @@ bool SaveCheckpoint(int client, int index, bool overflow = false) { cpcache.aFrames = Shavit_GetReplayData(target); cpcache.iPreFrames = Shavit_GetPlayerPreFrame(target); - cpcache.iTimerPreFrames = Shavit_GetPlayerTimerframe(target); } cpcache.bSegmented = true; @@ -2563,7 +2560,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage) else { Shavit_SetReplayData(client, cpcache.aFrames); - Shavit_SetPlayerPreFrame(client, cpcache.iPreFrames, cpcache.iTimerPreFrames); + Shavit_SetPlayerPreFrame(client, cpcache.iPreFrames); } } diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index b5555e8e..bcd75930 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -156,6 +156,7 @@ Convar gCV_PlaybackCanStop = null; Convar gCV_PlaybackCooldown = null; Convar gCV_PlaybackPreRunTime = null; Convar gCV_ClearPreRun = null; +ConVar gCV_PrerunCountdown = null; // timer settings int gI_Styles = 0; @@ -209,7 +210,6 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_Replay_DeleteMap", Native_Replay_DeleteMap); CreateNative("Shavit_SetReplayData", Native_SetReplayData); CreateNative("Shavit_GetPlayerPreFrame", Native_GetPreFrame); - CreateNative("Shavit_GetPlayerTimerframe", Native_GetTimerFrame); CreateNative("Shavit_SetPlayerPreFrame", Native_SetPreFrame); // registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins @@ -250,6 +250,7 @@ public void OnPluginStart() FindConVar((gEV_Type != Engine_TF2)? "bot_quota":"tf_bot_quota").Flags &= ~FCVAR_NOTIFY; FindConVar("bot_stop").Flags &= ~FCVAR_CHEAT; + gCV_PrerunCountdown = FindConVar("shavit_hud_prerun_countdown"); for(int i = 0; i < sizeof(gS_ForcedCvars); i++) { @@ -701,6 +702,13 @@ public int Native_GetReplayTime(Handle handler, int numParams) return view_as(GetReplayLength(Track_Main, track)); } + if(gCV_PrerunCountdown.BoolValue) + { + if(gI_ReplayTick[style] < gA_FrameCache[style][track].iPreFrames) + { + return view_as(float(gI_ReplayTick[style] - gA_FrameCache[style][track].iPreFrames) / gF_Tickrate * gA_StyleSettings[style].fTimescale); + } + } return view_as(float(gI_TimerTick[style]) / gF_Tickrate * gA_StyleSettings[style].fTimescale); } @@ -767,19 +775,9 @@ public int Native_GetPreFrame(Handle handler, int numParams) return gI_PlayerPrerunFrames[GetNativeCell(1)]; } -public int Native_GetTimerFrame(Handle handler, int numParams) -{ - return gI_PlayerTimerStartFrames[GetNativeCell(1)]; -} - public int Native_SetPreFrame(Handle handler, int numParams) { - int client = GetNativeCell(1); - int preframes = GetNativeCell(2); - int timerframes = GetNativeCell(3); - - gI_PlayerPrerunFrames[client] = preframes; - gI_PlayerTimerStartFrames[client] = timerframes; + gI_PlayerPrerunFrames[GetNativeCell(1)] = GetNativeCell(2); } public Action Cron(Handle Timer) @@ -1221,7 +1219,7 @@ bool LoadReplay(int style, int track, const char[] path) return false; } -bool SaveReplay(int style, int track, float time, int steamid, char[] name, int preframes, ArrayList playerrecording, int timerstartframe) +bool SaveReplay(int style, int track, float time, int steamid, char[] name, int preframes, ArrayList playerrecording) { char sTrack[4]; FormatEx(sTrack, 4, "_%d", track); @@ -1240,7 +1238,7 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int fFile.WriteString(gS_Map, true); fFile.WriteInt8(style); fFile.WriteInt8(track); - fFile.WriteInt32(preframes < 0 ? timerstartframe : timerstartframe - preframes); + fFile.WriteInt32(preframes); int iSize = playerrecording.Length; fFile.WriteInt32(iSize); @@ -1252,7 +1250,7 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int int iFramesWritten = 0; gA_Frames[style][track].Clear(); - for(int i = (preframes < 0 ? 0 : preframes); i < iSize; i++) + for(int i = 0; i < iSize; i++) { playerrecording.GetArray(i, aFrameData, CELLS_PER_FRAME); gA_Frames[style][track].PushArray(aFrameData); @@ -1272,11 +1270,11 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int delete fFile; - gA_FrameCache[style][track].iFrameCount = iSize - (preframes < 0 ? 0 : preframes); + gA_FrameCache[style][track].iFrameCount = iSize; gA_FrameCache[style][track].fTime = time; gA_FrameCache[style][track].bNewFormat = true; strcopy(gA_FrameCache[style][track].sReplayName, MAX_NAME_LENGTH, name); - gA_FrameCache[style][track].iPreFrames = preframes < 0 ? timerstartframe : (timerstartframe - preframes); + gA_FrameCache[style][track].iPreFrames = preframes; return true; } @@ -1602,8 +1600,7 @@ public void DeleteFrames(int client) public Action Shavit_OnStart(int client) { - gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length - RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale); - gI_PlayerTimerStartFrames[client] = gA_PlayerFrames[client].Length; + gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length; if(!gB_ClearFrame[client]) { @@ -1682,7 +1679,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st GetClientName(client, sName, MAX_NAME_LENGTH); ReplaceString(sName, MAX_NAME_LENGTH, "#", "?"); - SaveReplay(style, track, time, iSteamID, sName, gI_PlayerPrerunFrames[client], gA_PlayerFrames[client], gI_PlayerTimerStartFrames[client]); + SaveReplay(style, track, time, iSteamID, sName, gI_PlayerPrerunFrames[client], gA_PlayerFrames[client]); if(ReplayEnabled(style)) {