From 91585c2fd11095837234b56d38c15afd507feb1e Mon Sep 17 00:00:00 2001 From: kidfearless Date: Mon, 30 Nov 2020 09:33:36 -0700 Subject: [PATCH 01/22] Update version to signify dev builds --- addons/sourcemod/scripting/include/shavit.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 35fb43b6..185baa17 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -23,7 +23,7 @@ #endif #define _shavit_included -#define SHAVIT_VERSION "2.6.0" +#define SHAVIT_VERSION "2.6.0.DEV" #define STYLE_LIMIT 256 #define MAX_ZONES 64 #define MAX_NAME_LENGTH_SQL 32 From 41c048603554f71cd9f42b94ca6245fd03d3aba9 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:34:39 +0000 Subject: [PATCH 02/22] Allow !goto/!tpto from start/end zone (#963) * allow !goto/!tpto from start/end zones * also remove translation phrase for TeleportInZone --- addons/sourcemod/scripting/shavit-misc.sp | 7 ------- addons/sourcemod/translations/shavit-misc.phrases.txt | 5 ----- 2 files changed, 12 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 6687c3e5..0b3f4793 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -1607,13 +1607,6 @@ bool Teleport(int client, int targetserial) int iTarget = GetClientFromSerial(targetserial); - if(Shavit_InsideZone(client, Zone_Start, -1) || Shavit_InsideZone(client, Zone_End, -1)) - { - Shavit_PrintToChat(client, "%T", "TeleportInZone", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText, gS_ChatStrings.sVariable, gS_ChatStrings.sText); - - return false; - } - if(iTarget == 0) { Shavit_PrintToChat(client, "%T", "TeleportInvalidTarget", client); diff --git a/addons/sourcemod/translations/shavit-misc.phrases.txt b/addons/sourcemod/translations/shavit-misc.phrases.txt index a40f8ed2..2255173d 100644 --- a/addons/sourcemod/translations/shavit-misc.phrases.txt +++ b/addons/sourcemod/translations/shavit-misc.phrases.txt @@ -76,11 +76,6 @@ { "en" "You can teleport only if you are alive." } - "TeleportInZone" - { - "#format" "{1:s},{2:s},{3:s},{4:s}" - "en" "You {1}cannot teleport{2} inside the {3}start/end zones{4}." - } "TeleportInvalidTarget" { "en" "Invalid target." From f69f761685912bab628e5e272ec4a650b2bc38f8 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:35:40 +0000 Subject: [PATCH 03/22] only print the stage time message once per stage (#965) * only print the stage time message once per stage * show stage message every time when segmenting * add missing Shavit_OnStageMessage forward include --- addons/sourcemod/scripting/include/shavit.inc | 11 +++++++++++ addons/sourcemod/scripting/shavit-zones.sp | 14 +++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 185baa17..f86b6ff1 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -734,6 +734,17 @@ forward void Shavit_OnEnterZone(int client, int type, int track, int id, int ent */ forward void Shavit_OnLeaveZone(int client, int type, int track, int id, int entity, int data); +/** + * Called when a player leaves a zone. + * + * @param client Client index. + * @param stageNumber Stage number. + * @param message The stage time message that will be printed. + * @param maxlen The buffer size of message. + * @return Plugin_Handled to block the timer from printing msg to the client. Plugin_Continue to let the timer print msg. + */ +forward Action Shavit_OnStageMessage(int client, int stageNumber, char[] message, int maxlen); + /** * Called when a player gets the worst record in the server for the style. * Note: Will be only called for ranked styles. diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index 3f3717bc..575a53a9 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -127,6 +127,7 @@ float gV_ZoneCenter[MAX_ZONES][3]; int gI_StageZoneID[MAX_ZONES]; int gI_EntityZone[4096]; bool gB_ZonesCreated = false; +int gI_LastStage[MAXPLAYERS+1]; char gS_BeamSprite[PLATFORM_MAX_PATH]; int gI_BeamSprite = -1; @@ -2741,6 +2742,8 @@ public void SQL_CreateTable_Callback(Database db, DBResultSet results, const cha public void Shavit_OnRestart(int client, int track) { + gI_LastStage[client] = 0; + if(gCV_TeleportToStart.BoolValue) { int iIndex = -1; @@ -2999,18 +3002,23 @@ public void StartTouchPost(int entity, int other) case Zone_Stage: { - if(status != Timer_Stopped && Shavit_GetClientTrack(other) == gA_ZoneCache[gI_EntityZone[entity]].iZoneTrack) + int num = gA_ZoneCache[gI_EntityZone[entity]].iZoneData; + char special[sizeof(stylestrings_t::sSpecialString)]; + Shavit_GetStyleStrings(Shavit_GetBhopStyle(other), sSpecialString, special, sizeof(special)); + + if(status != Timer_Stopped && Shavit_GetClientTrack(other) == gA_ZoneCache[gI_EntityZone[entity]].iZoneTrack && (num > gI_LastStage[other] || StrContains(special, "segments") != -1)) { + gI_LastStage[other] = num; char sTime[32]; FormatSeconds(Shavit_GetClientTime(other), sTime, 32, true); char sMessage[255]; - FormatEx(sMessage, 255, "%T", "ZoneStageEnter", other, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, gA_ZoneCache[gI_EntityZone[entity]].iZoneData, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, sTime, gS_ChatStrings.sText); + FormatEx(sMessage, 255, "%T", "ZoneStageEnter", other, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, num, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, sTime, gS_ChatStrings.sText); Action aResult = Plugin_Continue; Call_StartForward(gH_Forwards_StageMessage); Call_PushCell(other); - Call_PushCell(gA_ZoneCache[gI_EntityZone[entity]].iZoneData); + Call_PushCell(num); Call_PushStringEx(sMessage, 255, SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); Call_PushCell(255); Call_Finish(aResult); From 3d670a7812adbe216cfd1d7011e1602011fb3791 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:36:05 +0000 Subject: [PATCH 04/22] allow !resume when not on the ground (#966) * allow !resume when not on the ground * block !pause if moving / velocity != 0.0 --- addons/sourcemod/scripting/include/shavit.inc | 3 +- addons/sourcemod/scripting/shavit-core.sp | 28 ++++++++++++++----- .../translations/shavit-core.phrases.txt | 5 ++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index f86b6ff1..e1a546fe 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -71,7 +71,8 @@ enum CPR_ByConVar = (1 << 0), CPR_NoTimer = (1 << 1), CPR_InStartZone = (1 << 2), - CPR_NotOnGround = (1 << 3) + CPR_NotOnGround = (1 << 3), + CPR_Moving = (1 << 4) }; enum diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index fe5ad31b..6fc93bbd 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -674,13 +674,6 @@ public Action Command_TogglePause(int client, int args) return Plugin_Handled; } - if((iFlags & CPR_NotOnGround) > 0) - { - Shavit_PrintToChat(client, "%T", "PauseNotOnGround", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText); - - return Plugin_Handled; - } - if(gA_Timers[client].bPaused) { TeleportEntity(client, gF_PauseOrigin[client], gF_PauseAngles[client], gF_PauseVelocity[client]); @@ -691,6 +684,20 @@ public Action Command_TogglePause(int client, int args) else { + if((iFlags & CPR_NotOnGround) > 0) + { + Shavit_PrintToChat(client, "%T", "PauseNotOnGround", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText); + + return Plugin_Handled; + } + + if((iFlags & CPR_Moving) > 0) + { + Shavit_PrintToChat(client, "%T", "PauseMoving", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText); + + return Plugin_Handled; + } + GetClientAbsOrigin(client, gF_PauseOrigin[client]); GetClientEyeAngles(client, gF_PauseAngles[client]); GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", gF_PauseVelocity[client]); @@ -1526,6 +1533,13 @@ public int Native_CanPause(Handle handler, int numParams) iFlags |= CPR_NotOnGround; } + float vel[3]; + GetEntPropVector(client, Prop_Data, "m_vecVelocity", vel); + if (vel[0] != 0.0 || vel[1] != 0.0 || vel[2] != 0.0) + { + iFlags |= CPR_Moving; + } + return iFlags; } diff --git a/addons/sourcemod/translations/shavit-core.phrases.txt b/addons/sourcemod/translations/shavit-core.phrases.txt index 0c4767a4..fa7109f5 100644 --- a/addons/sourcemod/translations/shavit-core.phrases.txt +++ b/addons/sourcemod/translations/shavit-core.phrases.txt @@ -100,6 +100,11 @@ "#format" "{1:s},{2:s},{3:s},{4:s},{5:s}" "en" "{1}You {2}cannot{3} pause in the {4}start zone{5}." } + "PauseMoving" + { + "#format" "{1:s},{2:s}" + "en" "You {1}are not{2} allowed to pause while moving." + } "TimerUnpaused" { "#format" "{1:s},{2:s}" From 080c64f8b98dced2f80d54406950a3a9b8c89ed6 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:37:11 +0000 Subject: [PATCH 05/22] fix ApplyFlags for the replay bot (#977) --- 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 3e12e7ac..a0a888b5 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -1839,14 +1839,14 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st void ApplyFlags(int &flags1, int flags2, int flag) { - if((flags2 & flag) > 0) + if((flags2 & flag) != 0) { flags1 |= flag; } else { - flags2 &= ~flag; + flags1 &= ~flag; } } From a1e60b39fab4435e0c53f38a3a4cde6f5a830149 Mon Sep 17 00:00:00 2001 From: Joe <55846624+rtldg@users.noreply.github.com> Date: Mon, 30 Nov 2020 16:40:45 +0000 Subject: [PATCH 06/22] Multiple bonuses (#982) * cleanup GetTrackName() * a few more changes to change mod_zone_bonus & add Track_Bonus_Last * fix undefined symbol sTrack * fixup !bwr for multiple bonuses * fix GetTrackName() after I broke it * add bonus number param to help text of sm_bwr * fix !wr after I broke it adding !bwr [bonus number] * ignore checkpoint zones for now because nothing is ready for them * update points for bonus #2 through #8 at same time so instead of something like `9 (track count) * 22 (style count)` queries, it'll do `3 (main, bonus1, rest of bonuses) * 22 (style count)` queries and the rest of the bonuses on the recalc all in the same query --- addons/sourcemod/scripting/include/shavit.inc | 11 ++++ addons/sourcemod/scripting/shavit-core.sp | 48 +++++++++----- addons/sourcemod/scripting/shavit-hud.sp | 14 ---- addons/sourcemod/scripting/shavit-misc.sp | 22 ++----- addons/sourcemod/scripting/shavit-rankings.sp | 38 ++++------- addons/sourcemod/scripting/shavit-replay.sp | 16 +---- addons/sourcemod/scripting/shavit-stats.sp | 14 ---- addons/sourcemod/scripting/shavit-wr.sp | 66 +++++++++++-------- addons/sourcemod/scripting/shavit-zones.sp | 30 ++++----- .../translations/shavit-common.phrases.txt | 7 +- 10 files changed, 117 insertions(+), 149 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index e1a546fe..79f5c647 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -114,6 +114,7 @@ enum { Track_Main, Track_Bonus, + Track_Bonus_Last = 8, TRACKS_SIZE }; @@ -452,6 +453,16 @@ stock bool GuessBestMapName(ArrayList maps, const char[] input, char[] output, i return false; } +stock void GetTrackName(int client, int track, char[] output, int size) +{ + if (track == Track_Main) + FormatEx(output, size, "%T", "Track_Main", client, track); + else if (track >= Track_Bonus) + FormatEx(output, size, "%T", "Track_Bonus", client, track); + else //if (track < Track_Main) + FormatEx(output, size, "%T", "Track_Unknown", client); +} + /** * Called before shavit-core processes the client's usercmd. * Before this is called, safety checks (fake/dead clients) happen. diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 6fc93bbd..5357c069 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -563,7 +563,21 @@ public Action Command_StartTimer(int client, int args) if(StrContains(sCommand, "sm_b", false) == 0) { - track = Track_Bonus; + if (args < 1) + { + track = Shavit_GetClientTrack(client); + } + else + { + char arg[6]; + GetCmdArg(1, arg, sizeof(arg)); + track = StringToInt(arg); + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } } if(gCV_AllowTimerWithoutZone.BoolValue || (gB_Zones && (Shavit_ZoneExists(Zone_Start, track) || gB_KZMap))) @@ -609,7 +623,21 @@ public Action Command_TeleportEnd(int client, int args) if(StrContains(sCommand, "sm_b", false) == 0) { - track = Track_Bonus; + if (args < 1) + { + track = Shavit_GetClientTrack(client); + } + else + { + char arg[6]; + GetCmdArg(1, arg, sizeof(arg)); + track = StringToInt(arg); + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } } if(gB_Zones && (Shavit_ZoneExists(Zone_End, track) || gB_KZMap)) @@ -1126,7 +1154,7 @@ public Action Command_Style(int client, int args) char sWR[8]; strcopy(sWR, 8, "WR"); - if(gA_Timers[client].iTrack == Track_Bonus) + if(gA_Timers[client].iTrack >= Track_Bonus) { strcopy(sWR, 8, "BWR"); } @@ -3528,17 +3556,3 @@ void UpdateStyleSettings(int client) SetEntityGravity(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier)); } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 043c6752..035cb95c 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -1923,20 +1923,6 @@ public int Native_GetHUDSettings(Handle handler, int numParams) return gI_HUDSettings[client]; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - void PrintCSGOHUDText(int client, const char[] format, any ...) { char buff[MAX_HINT_SIZE]; diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 0b3f4793..9326c976 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -968,11 +968,15 @@ void UpdateClanTag(int client) } int track = Shavit_GetClientTrack(client); - char sTrack[3]; + char sTrack[4]; if(track != Track_Main) { - GetTrackName(client, track, sTrack, 3); + sTrack[0] = 'B'; + if (track > Track_Bonus) + { + FormatEx(sTrack, sizeof(sTrack), "B%d", track); + } } char sRank[8]; @@ -2854,20 +2858,6 @@ public Action Shavit_OnStart(int client) return Plugin_Continue; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - public void Shavit_OnWorldRecord(int client, int style, float time, int jumps, int strafes, float sync, int track) { char sUpperCase[64]; diff --git a/addons/sourcemod/scripting/shavit-rankings.sp b/addons/sourcemod/scripting/shavit-rankings.sp index af42a75a..f4c19a93 100644 --- a/addons/sourcemod/scripting/shavit-rankings.sp +++ b/addons/sourcemod/scripting/shavit-rankings.sp @@ -86,8 +86,6 @@ Handle gH_Forwards_OnRankAssigned = null; chatstrings_t gS_ChatStrings; int gI_Styles = 0; stylesettings_t gA_StyleSettings[STYLE_LIMIT]; -char gS_StyleNames[STYLE_LIMIT][64]; -char gS_TrackNames[TRACKS_SIZE][32]; public Plugin myinfo = { @@ -159,11 +157,6 @@ public void OnPluginStart() Shavit_OnChatConfigLoaded(); } - for(int i = 0; i < TRACKS_SIZE; i++) - { - GetTrackName(LANG_SERVER, i, gS_TrackNames[i], 32); - } - SQL_DBConnect(); } @@ -187,7 +180,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < gI_Styles; i++) { Shavit_GetStyleSettings(i, gA_StyleSettings[i]); - Shavit_GetStyleStrings(i, sStyleName, gS_StyleNames[i], 64); } } @@ -645,7 +637,7 @@ void RecalculateAll(const char[] map) LogError("DEBUG: 5 (RecalculateAll)"); #endif - for(int i = 0; i < TRACKS_SIZE; i++) + for(int i = 0; i < 3; i++) { for(int j = 0; j < gI_Styles; j++) { @@ -654,7 +646,7 @@ void RecalculateAll(const char[] map) continue; } - RecalculateMap(map, i, j); + RecalculateMap(map, i, j, (i > Track_Bonus)); } } } @@ -664,15 +656,23 @@ public void Shavit_OnFinish_Post(int client, int style, float time, int jumps, i RecalculateMap(gS_Map, track, style); } -void RecalculateMap(const char[] map, const int track, const int style) +void RecalculateMap(const char[] map, const int track, const int style, bool restOfTheBonuses=false) { #if defined DEBUG PrintToServer("Recalculating points. (%s, %d, %d)", map, track, style); #endif char sQuery[256]; - FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, %d, time, '%s', %.1f, %.3f) WHERE style = %d AND track = %d AND map = '%s';", + if (restOfTheBonuses) + { + FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, track, time, '%s', %.1f, %.3f) WHERE style = %d AND track > 1 AND map = '%s';", + gS_MySQLPrefix, style, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, map); + } + else + { + FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, %d, time, '%s', %.1f, %.3f) WHERE style = %d AND track = %d AND map = '%s';", gS_MySQLPrefix, style, track, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, track, map); + } gH_SQL.Query(SQL_Recalculate_Callback, sQuery, 0, DBPrio_High); @@ -872,20 +872,6 @@ public void SQL_UpdateTop100_Callback(Database db, DBResultSet results, const ch gH_Top100Menu.ExitButton = true; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - public int Native_GetMapTier(Handle handler, int numParams) { int tier = 0; diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index a0a888b5..17ccf399 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -718,7 +718,7 @@ public any Native_GetReplayTime(Handle handler, int numParams) int style = GetNativeCell(1); int track = GetNativeCell(2); - if(style < 0 || track < 0) + if(style < 0 || track < 0 || track >= TRACKS_SIZE) { return ThrowNativeError(200, "Style/Track out of range"); } @@ -2782,20 +2782,6 @@ int GetSpectatorTarget(int client) return target; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - float GetReplayLength(int style, int track) { if(gA_FrameCache[style][track].iFrameCount == 0) diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index a7a89723..de49daa4 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -935,17 +935,3 @@ public int Native_GetWRCount(Handle handler, int numParams) { return gI_WRAmount[GetNativeCell(1)]; } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index 704bf4ed..170aa79e 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -144,9 +144,9 @@ public void OnPluginStart() RegConsoleCmd("sm_wr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_wr [map]"); RegConsoleCmd("sm_worldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_worldrecord [map]"); - RegConsoleCmd("sm_bwr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bwr [map]"); - RegConsoleCmd("sm_bworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bworldrecord [map]"); - RegConsoleCmd("sm_bonusworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bonusworldrecord [map]"); + RegConsoleCmd("sm_bwr", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bwr [map] [bonus number]"); + RegConsoleCmd("sm_bworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bworldrecord [map] [bonus number]"); + RegConsoleCmd("sm_bonusworldrecord", Command_WorldRecord, "View the leaderboard of a map. Usage: sm_bonusworldrecord [map] [bonus number]"); RegConsoleCmd("sm_recent", Command_RecentRecords, "View the recent #1 times set."); RegConsoleCmd("sm_recentrecords", Command_RecentRecords, "View the recent #1 times set."); @@ -1315,14 +1315,46 @@ public Action Command_WorldRecord(int client, int args) return Plugin_Handled; } - if(args == 0) + char sCommand[16]; + GetCmdArg(0, sCommand, 16); + + int track = Track_Main; + bool havemap = false; + + if(StrContains(sCommand, "sm_b", false) == 0) + { + if (args >= 1) + { + char arg[6]; + GetCmdArg((args > 1) ? 2 : 1, arg, sizeof(arg)); + track = StringToInt(arg); + + // if the track doesn't fit in the bonus track range then assume it's a map name + if (args > 1 || (track < Track_Bonus || track > Track_Bonus_Last)) + { + havemap = true; + } + } + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + track = Track_Bonus; + } + } + + else + { + havemap = (args >= 1); + } + + if(!havemap) { strcopy(gA_WRCache[client].sClientMap, 128, gS_Map); } else { - GetCmdArgString(gA_WRCache[client].sClientMap, 128); + GetCmdArg(1, gA_WRCache[client].sClientMap, 128); if (!GuessBestMapName(gA_ValidMaps, gA_WRCache[client].sClientMap, gA_WRCache[client].sClientMap, 128)) { Shavit_PrintToChat(client, "%t", "Map was not found", gA_WRCache[client].sClientMap); @@ -1330,16 +1362,6 @@ public Action Command_WorldRecord(int client, int args) } } - char sCommand[16]; - GetCmdArg(0, sCommand, 16); - - int track = Track_Main; - - if(StrContains(sCommand, "sm_b", false) == 0) - { - track = Track_Bonus; - } - return ShowWRStyleMenu(client, track); } @@ -2265,17 +2287,3 @@ int GetRankForTime(int style, float time, int track) return (iRecords + 1); } - -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index 575a53a9..44e82db9 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -802,6 +802,11 @@ public void Frame_HookTrigger(any data) return; } + if (StrContains(sName, "checkpoint") != -1) + { + return; // TODO + } + int zone = -1; int track = Track_Main; @@ -817,7 +822,16 @@ public void Frame_HookTrigger(any data) if(StrContains(sName, "bonus") != -1) { - track = Track_Bonus; + // Parse out the X in mod_zone_bonus_X_start and mod_zone_bonus_X_end + char sections[8][8]; + ExplodeString(sName, "_", sections, 8, 8, false); + track = StringToInt(sections[3]); // 0 on failure to parse. 0 is less than Track_Bonus + + if (track < Track_Bonus || track > Track_Bonus_Last) + { + // Just ignore because there's either too many bonuses or X can be 0 and nobody told me + return; + } } if(zone != -1) @@ -2197,20 +2211,6 @@ public Action OnClientSayCommand(int client, const char[] command, const char[] return Plugin_Continue; } -void GetTrackName(int client, int track, char[] output, int size) -{ - if(track < 0 || track >= TRACKS_SIZE) - { - FormatEx(output, size, "%T", "Track_Unknown", client); - - return; - } - - static char sTrack[16]; - FormatEx(sTrack, 16, "Track_%d", track); - FormatEx(output, size, "%T", sTrack, client); -} - void UpdateTeleportZone(int client) { float vTeleport[3]; diff --git a/addons/sourcemod/translations/shavit-common.phrases.txt b/addons/sourcemod/translations/shavit-common.phrases.txt index 99849345..d849a1ff 100644 --- a/addons/sourcemod/translations/shavit-common.phrases.txt +++ b/addons/sourcemod/translations/shavit-common.phrases.txt @@ -9,13 +9,14 @@ { "en" "UNKNOWN TRACK" } - "Track_0" + "Track_Main" { "en" "Main" } - "Track_1" + "Track_Bonus" { - "en" "Bonus" + "#format" "{1:d}" + "en" "Bonus #{1}" } // ---------- Commands ---------- // "NoCommandAccess" From db27bdce14cbcdb6e316e361f715f16d9c6d30a5 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Tue, 1 Dec 2020 08:43:06 -0700 Subject: [PATCH 07/22] Added Shavit_GetStyleSetting, deprecated Shavit_GetStyleSettings --- addons/sourcemod/scripting/include/shavit.inc | 19 ++++++- addons/sourcemod/scripting/shavit-core.sp | 49 ++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 79f5c647..246e74ea 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -1533,6 +1533,19 @@ native void Shavit_OpenStatsMenu(int client, int steamid); */ native int Shavit_GetWRCount(int client); +/* + * Gets a value from the style config for the given style + * e.g. Shavit_GetStyleSetting(Shavit_GetBhopStyle(client), "TAS", sBuffer, 2); + * + * @param style Style index. + * @param key Style key to retreive. + * @param value Value buffer to store the return value in. + * @param maxlength Max length of the value buffer, cannot exceed 256. + * + * @return True if key was found, false otherwise. + */ +native bool Shavit_GetStyleSetting(int style, const char[] key, char[] value, int maxlength); + /** * Saves the style settings on `any` references. * @@ -1541,6 +1554,7 @@ native int Shavit_GetWRCount(int client); * @param size Size of the StyleSettings buffer, e.g sizeof(stylesettings_t) * @return SP_ERROR_NONE on success, anything else on failure. */ +#pragma deprecated Use different natives or Shavit_GetStyleSetting instead. native int Shavit_GetStyleSettings(int style, any[] StyleSettings, int size = sizeof(stylesettings_t)); /** @@ -1913,7 +1927,7 @@ native int Shavit_GetPlayerPreFrame(int client); * * @return Timer preframe count */ - native int Shavit_GetPlayerTimerFrame(int client); +native int Shavit_GetPlayerTimerFrame(int client); /* * Sets player's preframe length. @@ -1934,7 +1948,7 @@ native void Shavit_SetPlayerPreFrame(int client, int PreFrame); * * @noreturn */ - native void Shavit_SetPlayerTimerFrame(int client, int TimerPreFrame); +native void Shavit_SetPlayerTimerFrame(int client, int TimerPreFrame); // same as Shavit_PrintToChat() but loops through the whole server // code stolen from the base halflife.inc file @@ -2010,6 +2024,7 @@ public void __pl_shavit_SetNTVOptional() MarkNativeAsOptional("Shavit_GetStageZone"); MarkNativeAsOptional("Shavit_GetStrafeCount"); MarkNativeAsOptional("Shavit_GetStyleCount"); + MarkNativeAsOptional("Shavit_GetStyleSetting"); MarkNativeAsOptional("Shavit_GetStyleSettings"); MarkNativeAsOptional("Shavit_GetStyleStrings"); MarkNativeAsOptional("Shavit_GetSync"); diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 5357c069..fed2d44c 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -159,6 +159,8 @@ int gI_Styles = 0; int gI_OrderedStyles[STYLE_LIMIT]; stylestrings_t gS_StyleStrings[STYLE_LIMIT]; stylesettings_t gA_StyleSettings[STYLE_LIMIT]; +StringMap gSM_StyleKeys[STYLE_LIMIT]; +int gI_CurrentParserIndex = 0; // chat settings chatstrings_t gS_ChatStrings; @@ -207,6 +209,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_GetPerfectJumps", Native_GetPerfectJumps); CreateNative("Shavit_GetStrafeCount", Native_GetStrafeCount); CreateNative("Shavit_GetStyleCount", Native_GetStyleCount); + CreateNative("Shavit_GetStyleSetting", Native_GetStyleSetting); CreateNative("Shavit_GetStyleSettings", Native_GetStyleSettings); CreateNative("Shavit_GetStyleStrings", Native_GetStyleStrings); CreateNative("Shavit_GetSync", Native_GetSync); @@ -2028,6 +2031,22 @@ public int Native_SetClientTimescale(Handle handler, int numParams) } } +public int Native_GetStyleSetting(Handle handler, int numParams) +{ + int style = GetNativeCell(1); + + char sKey[256]; + GetNativeString(2, sKey, 256); + + int maxlength = GetNativeCell(4); + + char sValue[256]; + bool ret = gSM_StyleKeys[style].GetString(sKey, sValue, maxlength); + + SetNativeString(3, sValue, maxlength); + return ret; +} + int GetTimerStatus(int client) { if(!gA_Timers[client].bEnabled) @@ -2300,6 +2319,12 @@ bool LoadStyles() char sPath[PLATFORM_MAX_PATH]; BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-styles.cfg"); + SMCParser parser = new SMCParser(); + parser.OnEnterSection = OnStyleEnterSection; + parser.OnKeyValue = OnStyleKeyValue; + parser.ParseFile(sPath); + delete parser; + KeyValues kv = new KeyValues("shavit-styles"); if(!kv.ImportFromFile(sPath) || !kv.GotoFirstSubKey()) @@ -2312,7 +2337,7 @@ bool LoadStyles() int i = 0; do - { + { kv.GetString("name", gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName), ""); kv.GetString("shortname", gS_StyleStrings[i].sShortName, sizeof(stylestrings_t::sShortName), ""); kv.GetString("htmlcolor", gS_StyleStrings[i].sHTMLColor, sizeof(stylestrings_t::sHTMLColor), ""); @@ -2434,6 +2459,28 @@ bool LoadStyles() return true; } +public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_quotes) +{ + // styles key + if(!IsCharNumeric(name[0])) + { + return SMCParse_Continue; + } + + // Technically can lead to a small memory leak if a style is removed mid game. + // TODO: replace hard coded values with SMCParser logic. + gI_CurrentParserIndex = StringToInt(name); + delete gSM_StyleKeys[gI_CurrentParserIndex]; + gSM_StyleKeys[gI_CurrentParserIndex] = new StringMap(); + + return SMCParse_Continue; +} + +public SMCResult OnStyleKeyValue(SMCParser smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes) +{ + gSM_StyleKeys[gI_CurrentParserIndex].SetString(key, value); +} + public int SortAscending_StyleOrder(int index1, int index2, const int[] array, any hndl) { int iOrder1 = gA_StyleSettings[index1].iOrdering; From 69efd6c5e8b720938c01313c7c3e306b83b8b223 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 06:49:15 -0700 Subject: [PATCH 08/22] use smcparser for style loading --- addons/sourcemod/scripting/shavit-core.sp | 295 +++++++++++++--------- 1 file changed, 170 insertions(+), 125 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index fed2d44c..da6596e4 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -2316,6 +2316,11 @@ public void SQL_InsertUser_Callback(Database db, DBResultSet results, const char bool LoadStyles() { + for(int i = 0; i < STYLE_LIMIT; i++) + { + delete gSM_StyleKeys[i]; + } + char sPath[PLATFORM_MAX_PATH]; BuildPath(Path_SM, sPath, PLATFORM_MAX_PATH, "configs/shavit-styles.cfg"); @@ -2325,129 +2330,6 @@ bool LoadStyles() parser.ParseFile(sPath); delete parser; - KeyValues kv = new KeyValues("shavit-styles"); - - if(!kv.ImportFromFile(sPath) || !kv.GotoFirstSubKey()) - { - delete kv; - - return false; - } - - int i = 0; - - do - { - kv.GetString("name", gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName), ""); - kv.GetString("shortname", gS_StyleStrings[i].sShortName, sizeof(stylestrings_t::sShortName), ""); - kv.GetString("htmlcolor", gS_StyleStrings[i].sHTMLColor, sizeof(stylestrings_t::sHTMLColor), ""); - kv.GetString("command", gS_StyleStrings[i].sChangeCommand, sizeof(stylestrings_t::sChangeCommand), ""); - kv.GetString("clantag", gS_StyleStrings[i].sClanTag, sizeof(stylestrings_t::sClanTag), ""); - kv.GetString("specialstring", gS_StyleStrings[i].sSpecialString, sizeof(stylestrings_t::sSpecialString), ""); - kv.GetString("permission", gS_StyleStrings[i].sStylePermission, sizeof(stylestrings_t::sStylePermission), ""); - - gA_StyleSettings[i].bAutobhop = view_as(kv.GetNum("autobhop", 1)); - gA_StyleSettings[i].bEasybhop = view_as(kv.GetNum("easybhop", 1)); - gA_StyleSettings[i].iPrespeed = view_as(kv.GetNum("prespeed", 0)); - gA_StyleSettings[i].fVelocityLimit = kv.GetFloat("velocity_limit", 0.0); - gA_StyleSettings[i].fAiraccelerate = kv.GetFloat("airaccelerate", 1000.0); - gA_StyleSettings[i].bEnableBunnyhopping = view_as(kv.GetNum("bunnyhopping", 1)); - gA_StyleSettings[i].fRunspeed = kv.GetFloat("runspeed", 260.00); - gA_StyleSettings[i].fGravityMultiplier = kv.GetFloat("gravity", 1.0); - gA_StyleSettings[i].fSpeedMultiplier = kv.GetFloat("speed", 1.0); - gA_StyleSettings[i].fTimescale = view_as(kv.GetNum("halftime", 0))? 0.5:kv.GetFloat("timescale", 1.0); // backwards compat for old halftime settig - gA_StyleSettings[i].fVelocity = kv.GetFloat("velocity", 1.0); - gA_StyleSettings[i].fBonusVelocity = kv.GetFloat("bonus_velocity", 0.0); - gA_StyleSettings[i].fMinVelocity = kv.GetFloat("min_velocity", 0.0); - gA_StyleSettings[i].fJumpMultiplier = kv.GetFloat("jump_multiplier", 0.0); - gA_StyleSettings[i].fJumpBonus = kv.GetFloat("jump_bonus", 0.0); - gA_StyleSettings[i].bBlockW = view_as(kv.GetNum("block_w", 0)); - gA_StyleSettings[i].bBlockA = view_as(kv.GetNum("block_a", 0)); - gA_StyleSettings[i].bBlockS = view_as(kv.GetNum("block_s", 0)); - gA_StyleSettings[i].bBlockD = view_as(kv.GetNum("block_d", 0)); - gA_StyleSettings[i].bBlockUse = view_as(kv.GetNum("block_use", 0)); - gA_StyleSettings[i].iForceHSW = kv.GetNum("force_hsw", 0); - gA_StyleSettings[i].iBlockPLeft = kv.GetNum("block_pleft", 0); - gA_StyleSettings[i].iBlockPRight = kv.GetNum("block_pright", 0); - gA_StyleSettings[i].iBlockPStrafe = kv.GetNum("block_pstrafe", 0); - gA_StyleSettings[i].bUnranked = view_as(kv.GetNum("unranked", 0)); - gA_StyleSettings[i].bNoReplay = view_as(kv.GetNum("noreplay", 0)); - gA_StyleSettings[i].bSync = view_as(kv.GetNum("sync", 1)); - gA_StyleSettings[i].bStrafeCountW = view_as(kv.GetNum("strafe_count_w", false)); - gA_StyleSettings[i].bStrafeCountA = view_as(kv.GetNum("strafe_count_a", true)); - gA_StyleSettings[i].bStrafeCountS = view_as(kv.GetNum("strafe_count_s", false)); - gA_StyleSettings[i].bStrafeCountD = view_as(kv.GetNum("strafe_count_d", true)); - gA_StyleSettings[i].fRankingMultiplier = kv.GetFloat("rankingmultiplier", 1.00); - gA_StyleSettings[i].iSpecial = kv.GetNum("special", 0); - gA_StyleSettings[i].iOrdering = kv.GetNum("ordering", i); - gA_StyleSettings[i].bInaccessible = view_as(kv.GetNum("inaccessible", false)); - gA_StyleSettings[i].iEnabled = kv.GetNum("enabled", 1); - gA_StyleSettings[i].bKZCheckpoints = view_as(kv.GetNum("kzcheckpoints", 0)); - gA_StyleSettings[i].bForceKeysOnGround = view_as(kv.GetNum("force_groundkeys", 0)); - - // if this style is disabled, we will force certain settings - if(gA_StyleSettings[i].iEnabled <= 0) - { - gA_StyleSettings[i].bNoReplay = true; - gA_StyleSettings[i].fRankingMultiplier = 0.0; - gA_StyleSettings[i].bInaccessible = true; - } - - if(!gB_Registered && strlen(gS_StyleStrings[i].sChangeCommand) > 0 && !gA_StyleSettings[i].bInaccessible) - { - char sStyleCommands[32][32]; - int iCommands = ExplodeString(gS_StyleStrings[i].sChangeCommand, ";", sStyleCommands, 32, 32, false); - - char sDescription[128]; - FormatEx(sDescription, 128, "Change style to %s.", gS_StyleStrings[i].sStyleName); - - for(int x = 0; x < iCommands; x++) - { - TrimString(sStyleCommands[x]); - StripQuotes(sStyleCommands[x]); - - char sCommand[32]; - FormatEx(sCommand, 32, "sm_%s", sStyleCommands[x]); - - gSM_StyleCommands.SetValue(sCommand, i); - - RegConsoleCmd(sCommand, Command_StyleChange, sDescription); - } - } - - if(StrContains(gS_StyleStrings[i].sStylePermission, ";") != -1) - { - char sText[2][32]; - int iCount = ExplodeString(gS_StyleStrings[i].sStylePermission, ";", sText, 2, 32); - - AdminFlag flag = Admin_Reservation; - - if(FindFlagByChar(sText[0][0], flag)) - { - gI_StyleFlag[i] = FlagToBit(flag); - } - - strcopy(gS_StyleOverride[i], 32, (iCount >= 2)? sText[1]:""); - } - - else if(strlen(gS_StyleStrings[i].sStylePermission) > 0) - { - AdminFlag flag = Admin_Reservation; - - if(FindFlagByChar(gS_StyleStrings[i].sStylePermission[0], flag)) - { - gI_StyleFlag[i] = FlagToBit(flag); - } - } - - gI_OrderedStyles[i] = i++; - } - - while(kv.GotoNextKey()); - - delete kv; - - gI_Styles = i; gB_Registered = true; SortCustom1D(gI_OrderedStyles, gI_Styles, SortAscending_StyleOrder); @@ -2467,12 +2349,175 @@ public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_ return SMCParse_Continue; } - // Technically can lead to a small memory leak if a style is removed mid game. - // TODO: replace hard coded values with SMCParser logic. gI_CurrentParserIndex = StringToInt(name); + + if(gI_Styles <= gI_CurrentParserIndex) + { + gI_Styles = gI_CurrentParserIndex + 1; + } + delete gSM_StyleKeys[gI_CurrentParserIndex]; gSM_StyleKeys[gI_CurrentParserIndex] = new StringMap(); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("name", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("shortname", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("htmlcolor", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("command", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("clantag", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("specialstring", ""); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("permission", ""); + + gS_StyleStrings[gI_CurrentParserIndex].sStyleName = ""; + gS_StyleStrings[gI_CurrentParserIndex].sShortName = ""; + gS_StyleStrings[gI_CurrentParserIndex].sHTMLColor = ""; + gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand = ""; + gS_StyleStrings[gI_CurrentParserIndex].sClanTag = ""; + gS_StyleStrings[gI_CurrentParserIndex].sSpecialString = ""; + gS_StyleStrings[gI_CurrentParserIndex].sStylePermission = ""; + + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("autobhop", 1); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("easybhop", 1); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("prespeed", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("velocity_limit", 0.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("airaccelerate", 1000.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("bunnyhopping", 1); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("runspeed", 260.00); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("gravity", 1.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("speed", 1.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("halftime", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("timescale", 1.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("velocity", 1.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("bonus_velocity", 0.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("min_velocity", 0.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("jump_multiplier", 0.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("jump_bonus", 0.0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_w", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_a", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_s", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_d", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_use", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("force_hsw", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pleft", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pright", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pstrafe", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("unranked", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("noreplay", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("sync", 1); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_w", false); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_a", true); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_s", false); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_d", true); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("rankingmultiplier", 1.00); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("special", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("ordering", gI_CurrentParserIndex); + + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("inaccessible", false); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("enabled", 1); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("kzcheckpoints", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("force_groundkeys", 0); + + gA_StyleSettings[gI_CurrentParserIndex].bAutobhop = true; + gA_StyleSettings[gI_CurrentParserIndex].bEasybhop = true; + gA_StyleSettings[gI_CurrentParserIndex].iPrespeed = 0; + gA_StyleSettings[gI_CurrentParserIndex].fVelocityLimit = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].fAiraccelerate = 1000.0; + gA_StyleSettings[gI_CurrentParserIndex].bEnableBunnyhopping = true; + gA_StyleSettings[gI_CurrentParserIndex].fRunspeed = 260.00; + gA_StyleSettings[gI_CurrentParserIndex].fGravityMultiplier = 1.0; + gA_StyleSettings[gI_CurrentParserIndex].fSpeedMultiplier = 1.0; + gA_StyleSettings[gI_CurrentParserIndex].fTimescale = 1.0; + gA_StyleSettings[gI_CurrentParserIndex].fVelocity = 1.0; + gA_StyleSettings[gI_CurrentParserIndex].fBonusVelocity = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].fMinVelocity = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].fJumpMultiplier = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].fJumpBonus = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].bBlockW = false; + gA_StyleSettings[gI_CurrentParserIndex].bBlockA = false; + gA_StyleSettings[gI_CurrentParserIndex].bBlockS = false; + gA_StyleSettings[gI_CurrentParserIndex].bBlockD = false; + gA_StyleSettings[gI_CurrentParserIndex].bBlockUse = false; + gA_StyleSettings[gI_CurrentParserIndex].iForceHSW = 0; + gA_StyleSettings[gI_CurrentParserIndex].iBlockPLeft = 0; + gA_StyleSettings[gI_CurrentParserIndex].iBlockPRight = 0; + gA_StyleSettings[gI_CurrentParserIndex].iBlockPStrafe = 0; + gA_StyleSettings[gI_CurrentParserIndex].bUnranked = false; + gA_StyleSettings[gI_CurrentParserIndex].bNoReplay = false; + gA_StyleSettings[gI_CurrentParserIndex].bSync = true; + gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountW = false; + gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountA = true; + gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountS = false; + gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountD = true; + gA_StyleSettings[gI_CurrentParserIndex].fRankingMultiplier = 1.00; + gA_StyleSettings[gI_CurrentParserIndex].iSpecial = 0; + gA_StyleSettings[gI_CurrentParserIndex].iOrdering = gI_CurrentParserIndex; + gA_StyleSettings[gI_CurrentParserIndex].bInaccessible = false; + gA_StyleSettings[gI_CurrentParserIndex].iEnabled = 1; + gA_StyleSettings[gI_CurrentParserIndex].bKZCheckpoints = false; + gA_StyleSettings[gI_CurrentParserIndex].bForceKeysOnGround = false; + + // if this style is disabled, we will force certain settings + if(gA_StyleSettings[gI_CurrentParserIndex].iEnabled <= 0) + { + gA_StyleSettings[gI_CurrentParserIndex].bNoReplay = true; + gA_StyleSettings[gI_CurrentParserIndex].fRankingMultiplier = 0.0; + gA_StyleSettings[gI_CurrentParserIndex].bInaccessible = true; + + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("noreplay", true); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("rankingmultiplier", 0); + gSM_StyleKeys[gI_CurrentParserIndex].SetValue("inaccessible", true); + } + + if(!gB_Registered && strlen(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand) > 0 && !gA_StyleSettings[gI_CurrentParserIndex].bInaccessible) + { + char sStyleCommands[32][32]; + int iCommands = ExplodeString(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand, ";", sStyleCommands, 32, 32, false); + + char sDescription[128]; + FormatEx(sDescription, 128, "Change style to %s.", gS_StyleStrings[gI_CurrentParserIndex].sStyleName); + + for(int x = 0; x < iCommands; x++) + { + TrimString(sStyleCommands[x]); + StripQuotes(sStyleCommands[x]); + + char sCommand[32]; + FormatEx(sCommand, 32, "sm_%s", sStyleCommands[x]); + + gSM_StyleCommands.SetValue(sCommand, gI_CurrentParserIndex); + + RegConsoleCmd(sCommand, Command_StyleChange, sDescription); + } + } + + if(StrContains(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission, ";") != -1) + { + char sText[2][32]; + int iCount = ExplodeString(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission, ";", sText, 2, 32); + + AdminFlag flag = Admin_Reservation; + + if(FindFlagByChar(sText[0][0], flag)) + { + gI_StyleFlag[gI_CurrentParserIndex] = FlagToBit(flag); + } + + strcopy(gS_StyleOverride[gI_CurrentParserIndex], 32, (iCount >= 2)? sText[1]:""); + } + + else if(strlen(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission) > 0) + { + AdminFlag flag = Admin_Reservation; + + if(FindFlagByChar(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission[0], flag)) + { + gI_StyleFlag[gI_CurrentParserIndex] = FlagToBit(flag); + } + } + + gI_OrderedStyles[gI_CurrentParserIndex] = gI_CurrentParserIndex; + + + return SMCParse_Continue; } From 2f48ddb85a66e304cdece7a449354df896280932 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:01:06 -0700 Subject: [PATCH 09/22] Removed shavit_getstylesettings from shavit-hud --- addons/sourcemod/scripting/shavit-hud.sp | 32 +++++++++++++++++------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 035cb95c..5fc4e09b 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -133,7 +133,6 @@ Convar gCV_EnableDynamicTimeDifference = null; // timer settings stylestrings_t gS_StyleStrings[STYLE_LIMIT]; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; chatstrings_t gS_ChatStrings; public Plugin myinfo = @@ -365,7 +364,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < styles; i++) { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); Shavit_GetStyleStrings(i, sStyleName, gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName)); Shavit_GetStyleStrings(i, sHTMLColor, gS_StyleStrings[i].sHTMLColor, sizeof(stylestrings_t::sHTMLColor)); } @@ -1162,7 +1160,9 @@ int AddHUDToBuffer_Source2013(int client, huddata_t data, char[] buffer, int max AddHUDLine(buffer, maxlen, sLine, iLines); iLines++; - if(gA_StyleSettings[data.iStyle].fVelocityLimit > 0.0 && Shavit_InsideZone(data.iTarget, Zone_CustomSpeedLimit, -1)) + char limit[16]; + Shavit_GetStyleSetting(data.iStyle, "velocity_limit", limit, 16); + if(StringToFloat(limit) > 0.0 && Shavit_InsideZone(data.iTarget, Zone_CustomSpeedLimit, -1)) { if(gI_ZoneSpeedLimit[data.iTarget] == 0) { @@ -1445,9 +1445,12 @@ void UpdateMainHUD(int client) fReplayTime = Shavit_GetReplayTime(iReplayStyle, iReplayTrack); fReplayLength = Shavit_GetReplayLength(iReplayStyle, iReplayTrack); - if(gA_StyleSettings[iReplayStyle].fSpeedMultiplier != 1.0) + char sSpeed[16]; + Shavit_GetStyleSetting(iReplayStyle, "speed", sSpeed, 16); + float fSpeed2 = StringToFloat(sSpeed); + if(fSpeed2 != 1.0) { - fSpeedHUD /= gA_StyleSettings[iReplayStyle].fSpeedMultiplier; + fSpeedHUD /= fSpeed2; } } } @@ -1523,8 +1526,10 @@ void UpdateKeyOverlay(int client, Panel panel, bool &draw) } char sPanelLine[128]; + char autobhop[4]; + Shavit_GetStyleSetting(style, "autobhop", autobhop, 4); - if(gB_BhopStats && !gA_StyleSettings[style].bAutobhop) + if(gB_BhopStats && !StringToInt(autobhop)) { FormatEx(sPanelLine, 64, " %d%s%d\n", gI_ScrollCount[target], (gI_ScrollCount[target] > 9)? " ":" ", gI_LastScrollCount[target]); } @@ -1580,7 +1585,10 @@ void UpdateCenterKeys(int client) style = 0; } - if(gB_BhopStats && !gA_StyleSettings[style].bAutobhop) + char autobhop[4]; + Shavit_GetStyleSetting(style, "autobhop", autobhop, 4); + + if(gB_BhopStats && !StringToInt(autobhop)) { Format(sCenterText, 64, "%s\n  %d %d", sCenterText, gI_ScrollCount[target], gI_LastScrollCount[target]); } @@ -1771,11 +1779,17 @@ void UpdateKeyHint(int client) { int style = Shavit_GetBhopStyle(target); - if((gI_HUDSettings[client] & HUD_SYNC) > 0 && Shavit_GetTimerStatus(target) == Timer_Running && gA_StyleSettings[style].bSync && !IsFakeClient(target) && (!gB_Zones || !Shavit_InsideZone(target, Zone_Start, -1))) + char sync[4]; + Shavit_GetStyleSetting(style, "sync", sync, 4); + + char autobhop[4]; + Shavit_GetStyleSetting(style, "autobhop", autobhop, 4); + + if((gI_HUDSettings[client] & HUD_SYNC) > 0 && Shavit_GetTimerStatus(target) == Timer_Running && StringToInt(sync) && !IsFakeClient(target) && (!gB_Zones || !Shavit_InsideZone(target, Zone_Start, -1))) { Format(sMessage, 256, "%s%s%T: %.01f", sMessage, (strlen(sMessage) > 0)? "\n\n":"", "HudSync", client, Shavit_GetSync(target)); - if(!gA_StyleSettings[style].bAutobhop && (gI_HUD2Settings[client] & HUD2_PERFS) == 0) + if(!StringToInt(autobhop) && (gI_HUD2Settings[client] & HUD2_PERFS) == 0) { Format(sMessage, 256, "%s\n%T: %.1f", sMessage, "HudPerfs", client, Shavit_GetPerfectJumps(target)); } From 98af2b4a51fba4228cb2d394257de273530db01c Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:12:04 -0700 Subject: [PATCH 10/22] Removed shavit_getstylesettings from shavit-replay --- addons/sourcemod/scripting/shavit-replay.sp | 28 +++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 17ccf399..6facc866 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -162,7 +162,6 @@ Convar gCV_DynamicTimeCheap = null; // timer settings int gI_Styles = 0; stylestrings_t gS_StyleStrings[STYLE_LIMIT]; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; // chat settings chatstrings_t gS_ChatStrings; @@ -736,7 +735,10 @@ public any Native_GetReplayTime(Handle handler, int numParams) return GetReplayLength(Track_Main, track); } - return float(gI_ReplayTick[style] - gA_FrameCache[style][track].iPreFrames) / gF_Tickrate * gA_StyleSettings[style].fTimescale; + char sSpeed[16]; + Shavit_GetStyleSetting(style, "speed", sSpeed, 16); + + return float(gI_ReplayTick[style] - gA_FrameCache[style][track].iPreFrames) / gF_Tickrate * StringToFloat(sSpeed); } public int Native_HijackAngles(Handle handler, int numParams) @@ -1036,7 +1038,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < styles; i++) { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); Shavit_GetStyleStrings(i, sClanTag, gS_StyleStrings[i].sClanTag, sizeof(stylestrings_t::sClanTag)); Shavit_GetStyleStrings(i, sStyleName, gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName)); Shavit_GetStyleStrings(i, sShortName, gS_StyleStrings[i].sShortName, sizeof(stylestrings_t::sShortName)); @@ -1714,7 +1715,11 @@ 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); + char sSpeed[16]; + Shavit_GetStyleSetting(Shavit_GetBhopStyle(client), "speed", sSpeed, 16); + float fSpeed = StringToFloat(sSpeed); + + gI_PlayerPrerunFrames[client] = gA_PlayerFrames[client].Length - RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / fSpeed); if(gI_PlayerPrerunFrames[client] < 0) { gI_PlayerPrerunFrames[client] = 0; @@ -1732,7 +1737,8 @@ public Action Shavit_OnStart(int client) else { - if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / gA_StyleSettings[Shavit_GetBhopStyle(client)].fTimescale)) + + if(gA_PlayerFrames[client].Length >= RoundToFloor(gCV_PlaybackPreRunTime.FloatValue * gF_Tickrate / fSpeed)) { gA_PlayerFrames[client].Erase(0); gI_PlayerFrames[client]--; @@ -2162,7 +2168,11 @@ public Action Timer_StartReplay(Handle Timer, any data) bool ReplayEnabled(any style) { - return (!gA_StyleSettings[style].bUnranked && !gA_StyleSettings[style].bNoReplay); + char unranked[4]; + char noreplay[4]; + Shavit_GetStyleSetting(style, "unranked", unranked, 4); + Shavit_GetStyleSetting(style, "noreplay", noreplay, 4); + return (!StringToInt(unranked) && !StringToInt(noreplay)); } public void Player_Event(Event event, const char[] name, bool dontBroadcast) @@ -2795,7 +2805,11 @@ float GetReplayLength(int style, int track) return gA_FrameCache[style][track].fTime; } - return Shavit_GetWorldRecord(style, track) * gA_StyleSettings[style].fTimescale; + char speed[16]; + Shavit_GetStyleSetting(style, "speed", speed, 16); + + + return Shavit_GetWorldRecord(style, track) * StringToFloat(speed); } void GetReplayName(int style, int track, char[] buffer, int length) From ec85dae24f9da02c0ee1d563e6f95fee4cfa2b93 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:17:14 -0700 Subject: [PATCH 11/22] Removed shavit_getstylesettings from shavit-rankings --- addons/sourcemod/scripting/shavit-rankings.sp | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-rankings.sp b/addons/sourcemod/scripting/shavit-rankings.sp index f4c19a93..d9a2bfb0 100644 --- a/addons/sourcemod/scripting/shavit-rankings.sp +++ b/addons/sourcemod/scripting/shavit-rankings.sp @@ -85,7 +85,6 @@ Handle gH_Forwards_OnRankAssigned = null; // Timer settings. chatstrings_t gS_ChatStrings; int gI_Styles = 0; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; public Plugin myinfo = { @@ -176,11 +175,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) { gI_Styles = Shavit_GetStyleCount(); } - - for(int i = 0; i < gI_Styles; i++) - { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); - } } public void OnLibraryAdded(const char[] name) @@ -583,14 +577,21 @@ public Action Command_RecalcAll(int client, int args) { char sQuery[192]; - if(gA_StyleSettings[i].bUnranked || gA_StyleSettings[i].fRankingMultiplier == 0.0) + char unranked[4]; + Shavit_GetStyleSetting(i, "unranked", unranked, 16); + + char multiplier[16]; + Shavit_GetStyleSetting(i, "rankingmultiplier", multiplier, 16); + float fMultiplier = StringToFloat(multiplier); + + if(StringToInt(unranked) || fMultiplier == 0.0) { FormatEx(sQuery, 192, "UPDATE %splayertimes SET points = 0 WHERE style = %d;", gS_MySQLPrefix, i); } else { - FormatEx(sQuery, 192, "UPDATE %splayertimes SET points = GetRecordPoints(%d, track, time, map, %.1f, %.3f) WHERE style = %d;", gS_MySQLPrefix, i, gCV_PointsPerTier.FloatValue, gA_StyleSettings[i].fRankingMultiplier, i); + FormatEx(sQuery, 192, "UPDATE %splayertimes SET points = GetRecordPoints(%d, track, time, map, %.1f, %.3f) WHERE style = %d;", gS_MySQLPrefix, i, gCV_PointsPerTier.FloatValue, fMultiplier, i); } trans.AddQuery(sQuery); @@ -641,7 +642,9 @@ void RecalculateAll(const char[] map) { for(int j = 0; j < gI_Styles; j++) { - if(gA_StyleSettings[j].bUnranked) + char unranked[4]; + Shavit_GetStyleSetting(j, "unranked", unranked, 4); + if(StringToInt(unranked)) { continue; } @@ -663,15 +666,17 @@ void RecalculateMap(const char[] map, const int track, const int style, bool res #endif char sQuery[256]; + char multiplier[16]; + Shavit_GetStyleSetting(style, "rankingmultiplier", multiplier, 16); if (restOfTheBonuses) { FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, track, time, '%s', %.1f, %.3f) WHERE style = %d AND track > 1 AND map = '%s';", - gS_MySQLPrefix, style, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, map); + gS_MySQLPrefix, style, map, gCV_PointsPerTier.FloatValue, StringToFloat(multiplier), style, map); } else { FormatEx(sQuery, 256, "UPDATE %splayertimes SET points = GetRecordPoints(%d, %d, time, '%s', %.1f, %.3f) WHERE style = %d AND track = %d AND map = '%s';", - gS_MySQLPrefix, style, track, map, gCV_PointsPerTier.FloatValue, gA_StyleSettings[style].fRankingMultiplier, style, track, map); + gS_MySQLPrefix, style, track, map, gCV_PointsPerTier.FloatValue, StringToFloat(multiplier), style, track, map); } gH_SQL.Query(SQL_Recalculate_Callback, sQuery, 0, DBPrio_High); From 1011629ec4294b9b1f7fe6bc9ab98ca9e07338a9 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:36:24 -0700 Subject: [PATCH 12/22] Add helper natives for Shavit_GetStyleSetting --- addons/sourcemod/scripting/include/shavit.inc | 39 +++++++++++++++++ addons/sourcemod/scripting/shavit-core.sp | 43 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 246e74ea..645ad915 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -1546,6 +1546,42 @@ native int Shavit_GetWRCount(int client); */ native bool Shavit_GetStyleSetting(int style, const char[] key, char[] value, int maxlength); + +/* + * Gets an int value from the style config for the given style. Returns 0 if key is not found. + * e.g. Shavit_GetStyleSettingInt(Shavit_GetBhopStyle(client), "TAS"); + * + * @param style Style index. + * @param key Style key to retreive. + * + * @return Integer value if found, 0 if key is missing. + */ +native int Shavit_GetStyleSettingInt(int style, const char[] key); + + +/* + * Gets a float value from the style config for the given style. Returns 0.0 if key is not found + * e.g. Shavit_GetStyleSettingFloat(Shavit_GetBhopStyle(client), "speed"); + * + * @param style Style index. + * @param key Style key to retreive. + * + * @return Float value if found, 0.0 if key is missing. + */ +native float Shavit_GetStyleSettingFloat(int style, const char[] key); + + +/* + * Checks if the given key exists for that style + * e.g. Shavit_HasStyleSetting(Shavit_GetBhopStyle(client), "tas"); + * + * @param style Style index. + * @param key Style key to retreive. + * + * @return True if found. + */ +native bool Shavit_HasStyleSetting(int style, const char[] key); + /** * Saves the style settings on `any` references. * @@ -2025,6 +2061,9 @@ public void __pl_shavit_SetNTVOptional() MarkNativeAsOptional("Shavit_GetStrafeCount"); MarkNativeAsOptional("Shavit_GetStyleCount"); MarkNativeAsOptional("Shavit_GetStyleSetting"); + MarkNativeAsOptional("Shavit_GetStyleSettingInt"); + MarkNativeAsOptional("Shavit_GetStyleSettingFloat"); + MarkNativeAsOptional("Shavit_HasStyleSetting"); MarkNativeAsOptional("Shavit_GetStyleSettings"); MarkNativeAsOptional("Shavit_GetStyleStrings"); MarkNativeAsOptional("Shavit_GetSync"); diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index da6596e4..c6fb8763 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -210,6 +210,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_GetStrafeCount", Native_GetStrafeCount); CreateNative("Shavit_GetStyleCount", Native_GetStyleCount); CreateNative("Shavit_GetStyleSetting", Native_GetStyleSetting); + CreateNative("Shavit_GetStyleSettingInt", Native_GetStyleSettingInt); + CreateNative("Shavit_GetStyleSettingFloat", Native_GetStyleSettingFloat); + CreateNative("Shavit_HasStyleSetting", Native_HasStyleSetting); CreateNative("Shavit_GetStyleSettings", Native_GetStyleSettings); CreateNative("Shavit_GetStyleStrings", Native_GetStyleStrings); CreateNative("Shavit_GetSync", Native_GetSync); @@ -2047,6 +2050,46 @@ public int Native_GetStyleSetting(Handle handler, int numParams) return ret; } +public int Native_GetStyleSettingInt(Handle handler, int numParams) +{ + int style = GetNativeCell(1); + + char sKey[256]; + GetNativeString(2, sKey, 256); + + char sValue[16]; + gSM_StyleKeys[style].GetString(sKey, sValue, 16); + + return StringToInt(sValue); +} + +public any Native_GetStyleSettingFloat(Handle handler, int numParams) +{ + int style = GetNativeCell(1); + + char sKey[256]; + GetNativeString(2, sKey, 256); + + char sValue[16]; + gSM_StyleKeys[style].GetString(sKey, sValue, 16); + + return StringToFloat(sValue); +} + +public any Native_HasStyleSetting(Handle handler, int numParams) +{ + // TODO: replace with sm 1.11 StringMap.ContainsKey + int style = GetNativeCell(1); + + char sKey[256]; + GetNativeString(2, sKey, 256); + + char sValue[1]; + gSM_StyleKeys[style].GetString(sKey, sValue, 1); + + return gSM_StyleKeys[style].GetString(sKey, sValue, 1); +} + int GetTimerStatus(int client) { if(!gA_Timers[client].bEnabled) From 1835573a703e2f5c64e319fa6c19c9f6ba983c5b Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:39:09 -0700 Subject: [PATCH 13/22] Removed shavit_getstylesettings from shavit-stats --- addons/sourcemod/scripting/shavit-stats.sp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-stats.sp b/addons/sourcemod/scripting/shavit-stats.sp index de49daa4..7c691c99 100644 --- a/addons/sourcemod/scripting/shavit-stats.sp +++ b/addons/sourcemod/scripting/shavit-stats.sp @@ -61,7 +61,6 @@ Convar gCV_MVPRankOnes_Main = null; // timer settings int gI_Styles = 0; stylestrings_t gS_StyleStrings[STYLE_LIMIT]; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; // chat settings chatstrings_t gS_ChatStrings; @@ -157,7 +156,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < styles; i++) { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); Shavit_GetStyleStrings(i, sStyleName, gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName)); Shavit_GetStyleStrings(i, sShortName, gS_StyleStrings[i].sShortName, sizeof(stylestrings_t::sShortName)); } @@ -323,7 +321,7 @@ public Action Command_MapsDoneLeft(int client, int args) { int iStyle = styles[i]; - if(gA_StyleSettings[iStyle].bUnranked || gA_StyleSettings[iStyle].iEnabled == -1) + if(Shavit_GetStyleSettingInt(iStyle, "unranked") || Shavit_GetStyleSettingInt(iStyle, "enabled") == -1) { continue; } @@ -539,7 +537,7 @@ public void OpenStatsMenuCallback(Database db, DBResultSet results, const char[] { int iStyle = styles[i]; - if(gA_StyleSettings[iStyle].bUnranked || gA_StyleSettings[iStyle].iEnabled <= 0) + if(Shavit_GetStyleSettingInt(iStyle, "unranked") || Shavit_GetStyleSettingInt(iStyle, "enabled") <= 0) { continue; } From 3cd45238bc8d6904c1c253406c7e4e0335fda79d Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:45:27 -0700 Subject: [PATCH 14/22] Removed shavit_getstylesettings from shavit-misc --- addons/sourcemod/scripting/shavit-misc.sp | 32 +++++++++++------------ 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index 9326c976..f7c0879e 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -168,7 +168,6 @@ bool gB_Zones = false; // timer settings stylestrings_t gS_StyleStrings[STYLE_LIMIT]; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; // chat settings chatstrings_t gS_ChatStrings; @@ -439,7 +438,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < styles; i++) { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); Shavit_GetStyleStrings(i, sStyleName, gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName)); Shavit_GetStyleStrings(i, sClanTag, gS_StyleStrings[i].sClanTag, sizeof(stylestrings_t::sClanTag)); Shavit_GetStyleStrings(i, sSpecialString, gS_StyleStrings[i].sSpecialString, sizeof(stylestrings_t::sSpecialString)); @@ -762,7 +760,7 @@ public MRESReturn CCSPlayer__GetPlayerMaxSpeed(int pThis, Handle hReturn) return MRES_Ignored; } - DHookSetReturn(hReturn, view_as(gA_StyleSettings[gI_Style[pThis]].fRunspeed)); + DHookSetReturn(hReturn, Shavit_GetStyleSettingFloat(gI_Style[pThis], "runspeed")); return MRES_Override; } @@ -808,7 +806,7 @@ public Action Timer_PersistKZCP(Handle Timer) for(int i = 1; i <= MaxClients; i++) { if(!gB_ClosedKZCP[i] && - gA_StyleSettings[gI_Style[i]].bKZCheckpoints + Shavit_GetStyleSettingInt(gI_Style[i], "kzcheckpoints") && GetClientMenu(i) == MenuSource_None && IsClientInGame(i) && IsPlayerAlive(i)) { @@ -1056,7 +1054,7 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float int iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity"); // prespeed - if(!bNoclip && gA_StyleSettings[gI_Style[client]].iPrespeed == 0 && bInStart) + if(!bNoclip && Shavit_GetStyleSettingInt(gI_Style[client], "prespeed") == 0 && bInStart) { if((gCV_PreSpeed.IntValue == 2 || gCV_PreSpeed.IntValue == 3) && gI_GroundEntity[client] == -1 && iGroundEntity != -1 && (buttons & IN_JUMP) > 0) { @@ -1073,7 +1071,7 @@ public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float float fSpeed[3]; GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed); - float fLimit = (gA_StyleSettings[gI_Style[client]].fRunspeed + gCV_PrestrafeLimit.FloatValue); + float fLimit = (Shavit_GetStyleSettingFloat(gI_Style[client], "runspeed") + gCV_PrestrafeLimit.FloatValue); // if trying to jump, add a very low limit to stop prespeeding in an elegant way // otherwise, make sure nothing weird is happening (such as sliding at ridiculous speeds, at zone enter) @@ -1419,7 +1417,7 @@ public void OnPreThink(int client) if(IsPlayerAlive(client)) { // not the best method, but only one i found for tf2 - SetEntPropFloat(client, Prop_Send, "m_flMaxspeed", gA_StyleSettings[gI_Style[client]].fRunspeed); + SetEntPropFloat(client, Prop_Send, "m_flMaxspeed", Shavit_GetStyleSettingFloat(gI_Style[client], "runspeed")); } } @@ -1710,7 +1708,7 @@ public Action Command_Checkpoints(int client, int args) return Plugin_Handled; } - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { gB_ClosedKZCP[client] = false; } @@ -1808,7 +1806,7 @@ public Action Command_Tele(int client, int args) public Action OpenCheckpointsMenu(int client) { - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { OpenKZCPMenu(client); } @@ -1869,7 +1867,7 @@ public int MenuHandler_KZCheckpoints(Menu menu, MenuAction action, int param1, i { if(action == MenuAction_Select) { - if(CanSegment(param1) || !gA_StyleSettings[gI_Style[param1]].bKZCheckpoints) + if(CanSegment(param1) || !Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { return 0; } @@ -2220,7 +2218,7 @@ bool SaveCheckpoint(int client, int index, bool overflow = false) return false; } - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { if((iFlags & FL_ONGROUND) == 0 || client != target) { @@ -2436,7 +2434,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage) timer_snapshot_t snapshot; CopyArray(cpcache.aSnapshot, snapshot, sizeof(timer_snapshot_t)); - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints != gA_StyleSettings[snapshot.bsStyle].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints") != Shavit_GetStyleSettingInt(snapshot.bsStyle, "kzcheckpoints")) { Shavit_PrintToChat(client, "%T", "CommandTeleCPInvalid", client); @@ -2507,7 +2505,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage) CopyArray(cpcache.fAngles, ang, 3); // this is basically the same as normal checkpoints except much less data is used - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { TeleportEntity(client, pos, ang, view_as({ 0.0, 0.0, 0.0 })); @@ -2839,7 +2837,7 @@ public Action Command_Specs(int client, int args) public Action Shavit_OnStart(int client) { - if(gA_StyleSettings[gI_Style[client]].iPrespeed == 0 && GetEntityMoveType(client) == MOVETYPE_NOCLIP) + if(Shavit_GetStyleSettingInt(gI_Style[client], "prespeed") == 0 && GetEntityMoveType(client) == MOVETYPE_NOCLIP) { return Plugin_Stop; } @@ -2850,7 +2848,7 @@ public Action Shavit_OnStart(int client) SetEntPropString(client, Prop_Data, "m_iClassname", "player"); } - if(gA_StyleSettings[gI_Style[client]].bKZCheckpoints) + if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) { ResetCheckpoints(client); } @@ -2896,7 +2894,7 @@ public void Shavit_OnRestart(int client, int track) } if(!gB_ClosedKZCP[client] && - gA_StyleSettings[gI_Style[client]].bKZCheckpoints && + Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints") && GetClientMenu(client, null) == MenuSource_None && IsPlayerAlive(client) && GetClientTeam(client) >= 2) { @@ -3023,7 +3021,7 @@ public void Player_Spawn(Event event, const char[] name, bool dontBroadcast) // refreshes kz cp menu if there is nothing open if(!gB_ClosedKZCP[client] && - gA_StyleSettings[gI_Style[client]].bKZCheckpoints && + Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints") && GetClientMenu(client, null) == MenuSource_None && IsPlayerAlive(client) && GetClientTeam(client) >= 2) { From 200ffd16f8c58d85a0911fe7fdaf291c917e7fce Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:48:57 -0700 Subject: [PATCH 15/22] Removed shavit_getstylesettings from shavit-wr --- addons/sourcemod/scripting/shavit-wr.sp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index 170aa79e..e93c5b98 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -83,7 +83,6 @@ Convar gCV_RecentLimit = null; // timer settings int gI_Styles = 0; stylestrings_t gS_StyleStrings[STYLE_LIMIT]; -stylesettings_t gA_StyleSettings[STYLE_LIMIT]; // chat settings chatstrings_t gS_ChatStrings; @@ -373,7 +372,6 @@ public void Shavit_OnStyleConfigLoaded(int styles) for(int i = 0; i < styles; i++) { - Shavit_GetStyleSettings(i, gA_StyleSettings[i]); Shavit_GetStyleStrings(i, sStyleName, gS_StyleStrings[i].sStyleName, sizeof(stylestrings_t::sStyleName)); Shavit_GetStyleStrings(i, sShortName, gS_StyleStrings[i].sShortName, sizeof(stylestrings_t::sShortName)); } @@ -532,7 +530,7 @@ public void SQL_UpdateWRCache_Callback(Database db, DBResultSet results, const c int iStyle = results.FetchInt(1); int iTrack = results.FetchInt(2); - if(iStyle >= gI_Styles || iStyle < 0 || gA_StyleSettings[iStyle].bUnranked) + if(iStyle >= gI_Styles || iStyle < 0 || Shavit_GetStyleSettingInt(iStyle, "unranked")) { continue; } @@ -778,7 +776,7 @@ void DeleteSubmenu(int client) { int iStyle = styles[i]; - if(gA_StyleSettings[iStyle].iEnabled == -1) + if(Shavit_GetStyleSettingInt(iStyle, "enabled") == -1) { continue; } @@ -851,7 +849,7 @@ public int MenuHandler_DeleteAll_First(Menu menu, MenuAction action, int param1, { int iStyle = styles[i]; - if(gA_StyleSettings[iStyle].iEnabled == -1) + if(Shavit_GetStyleSettingInt(iStyle, "enabled") == -1) { continue; } @@ -1379,7 +1377,7 @@ Action ShowWRStyleMenu(int client, int track) { int iStyle = styles[i]; - if(gA_StyleSettings[iStyle].bUnranked || gA_StyleSettings[iStyle].iEnabled == -1) + if(Shavit_GetStyleSettingInt(iStyle, "unranked") || Shavit_GetStyleSettingInt(iStyle, "enabled") == -1) { continue; } @@ -1670,8 +1668,7 @@ public void SQL_RR_Callback(Database db, DBResultSet results, const char[] error FormatSeconds(fTime, sTime, 16); int iStyle = results.FetchInt(4); - - if(iStyle >= gI_Styles || iStyle < 0 || gA_StyleSettings[iStyle].bUnranked) + if(iStyle >= gI_Styles || iStyle < 0 || Shavit_GetStyleSettingInt(iStyle, "unranked")) { continue; } @@ -1792,7 +1789,7 @@ public void SQL_SubMenu_Callback(Database db, DBResultSet results, const char[] int iJumps = results.FetchInt(2); float fPerfs = results.FetchFloat(9); - if(gA_StyleSettings[iStyle].bAutobhop) + if(Shavit_GetStyleSettingInt(iStyle, "autobhop")) { FormatEx(sDisplay, 128, "%T: %d", "WRJumps", client, iJumps); } @@ -2001,7 +1998,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st bool bIncrementCompletions = true; int iOverwrite = 0; - if(gA_StyleSettings[style].bUnranked || Shavit_IsPracticeMode(client)) + if(Shavit_GetStyleSettingInt(iStyle, "unranked") || Shavit_IsPracticeMode(client)) { iOverwrite = 0; // ugly way of not writing to database bIncrementCompletions = false; @@ -2127,7 +2124,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st gI_PlayerCompletion[client][style][track]++; - if(iOverwrite == 0 && !gA_StyleSettings[style].bUnranked) + if(iOverwrite == 0 && !Shavit_GetStyleSettingInt(iStyle, "unranked")) { FormatEx(sMessage, 255, "%s[%s]%s %T", gS_ChatStrings.sVariable, sTrack, gS_ChatStrings.sText, "WorseTime", client, gS_ChatStrings.sStyle, gS_StyleStrings[style].sStyleName, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, sTime, gS_ChatStrings.sText, jumps, strafes, sSync, gS_ChatStrings.sText, sDifference); @@ -2233,7 +2230,7 @@ public void SQL_UpdateLeaderboards_Callback(Database db, DBResultSet results, co int style = results.FetchInt(0); int track = results.FetchInt(1); - if(style >= gI_Styles || gA_StyleSettings[style].bUnranked || track >= TRACKS_SIZE) + if(style >= gI_Styles || Shavit_GetStyleSettingInt(iStyle, "unranked") || track >= TRACKS_SIZE) { continue; } @@ -2243,7 +2240,7 @@ public void SQL_UpdateLeaderboards_Callback(Database db, DBResultSet results, co for(int i = 0; i < gI_Styles; i++) { - if(i >= gI_Styles || gA_StyleSettings[i].bUnranked) + if(i >= gI_Styles || Shavit_GetStyleSettingInt(i, "unranked")) { continue; } From 7c5298f721b48a170d12e82616ad6b6919fe0e69 Mon Sep 17 00:00:00 2001 From: kidfearless Date: Fri, 4 Dec 2020 07:51:23 -0700 Subject: [PATCH 16/22] fixup compile errors --- addons/sourcemod/scripting/shavit-misc.sp | 2 +- addons/sourcemod/scripting/shavit-wr.sp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index f7c0879e..2bc15639 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -1867,7 +1867,7 @@ public int MenuHandler_KZCheckpoints(Menu menu, MenuAction action, int param1, i { if(action == MenuAction_Select) { - if(CanSegment(param1) || !Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints")) + if(CanSegment(param1) || !Shavit_GetStyleSettingInt(gI_Style[param1], "kzcheckpoints")) { return 0; } diff --git a/addons/sourcemod/scripting/shavit-wr.sp b/addons/sourcemod/scripting/shavit-wr.sp index e93c5b98..4aa0d0cb 100644 --- a/addons/sourcemod/scripting/shavit-wr.sp +++ b/addons/sourcemod/scripting/shavit-wr.sp @@ -1998,7 +1998,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st bool bIncrementCompletions = true; int iOverwrite = 0; - if(Shavit_GetStyleSettingInt(iStyle, "unranked") || Shavit_IsPracticeMode(client)) + if(Shavit_GetStyleSettingInt(style, "unranked") || Shavit_IsPracticeMode(client)) { iOverwrite = 0; // ugly way of not writing to database bIncrementCompletions = false; @@ -2124,7 +2124,7 @@ public void Shavit_OnFinish(int client, int style, float time, int jumps, int st gI_PlayerCompletion[client][style][track]++; - if(iOverwrite == 0 && !Shavit_GetStyleSettingInt(iStyle, "unranked")) + if(iOverwrite == 0 && !Shavit_GetStyleSettingInt(style, "unranked")) { FormatEx(sMessage, 255, "%s[%s]%s %T", gS_ChatStrings.sVariable, sTrack, gS_ChatStrings.sText, "WorseTime", client, gS_ChatStrings.sStyle, gS_StyleStrings[style].sStyleName, gS_ChatStrings.sText, gS_ChatStrings.sVariable2, sTime, gS_ChatStrings.sText, jumps, strafes, sSync, gS_ChatStrings.sText, sDifference); @@ -2230,7 +2230,7 @@ public void SQL_UpdateLeaderboards_Callback(Database db, DBResultSet results, co int style = results.FetchInt(0); int track = results.FetchInt(1); - if(style >= gI_Styles || Shavit_GetStyleSettingInt(iStyle, "unranked") || track >= TRACKS_SIZE) + if(style >= gI_Styles || Shavit_GetStyleSettingInt(style, "unranked") || track >= TRACKS_SIZE) { continue; } From b2da978f73436d0adec846a244dc5ac5058b98ce Mon Sep 17 00:00:00 2001 From: kidfearless Date: Mon, 14 Dec 2020 15:02:59 -0700 Subject: [PATCH 17/22] re-work shavit-core to use GetStyleSetting stocks. Log error when using Shavit_GetStyleSettings. --- addons/sourcemod/scripting/include/shavit.inc | 13 + addons/sourcemod/scripting/shavit-core.sp | 401 +++++++++++------- 2 files changed, 254 insertions(+), 160 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index 645ad915..dc818cbf 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -152,6 +152,7 @@ enum struct stylestrings_t char sStylePermission[64]; } +//TODO:REMOVE IN 3.0 enum struct stylesettings_t { bool bAutobhop; @@ -1559,6 +1560,18 @@ native bool Shavit_GetStyleSetting(int style, const char[] key, char[] value, in native int Shavit_GetStyleSettingInt(int style, const char[] key); +/* + * Gets the bool value from the style config for the given style. Returns false if key is not found. + * e.g. if(Shavit_GetStyleSettingBool(Shavit_GetBhopStyle(client), "TAS")) + * + * @param style Style index. + * @param key Style key to retreive. + * + * @return bool value if found, false if key is missing. + */ +native bool Shavit_GetStyleSettingBool(int style, const char[] key); + + /* * Gets a float value from the style config for the given style. Returns 0.0 if key is not found * e.g. Shavit_GetStyleSettingFloat(Shavit_GetBhopStyle(client), "speed"); diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index c6fb8763..96115201 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -211,6 +211,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("Shavit_GetStyleCount", Native_GetStyleCount); CreateNative("Shavit_GetStyleSetting", Native_GetStyleSetting); CreateNative("Shavit_GetStyleSettingInt", Native_GetStyleSettingInt); + CreateNative("Shavit_GetStyleSettingBool", Native_GetStyleSettingBool); CreateNative("Shavit_GetStyleSettingFloat", Native_GetStyleSettingFloat); CreateNative("Shavit_HasStyleSetting", Native_HasStyleSetting); CreateNative("Shavit_GetStyleSettings", Native_GetStyleSettings); @@ -1127,8 +1128,8 @@ public Action Command_Style(int client, int args) // this logic will prevent the style from showing in !style menu if it's specifically inaccessible // or just completely disabled - if((gA_StyleSettings[iStyle].bInaccessible && gA_StyleSettings[iStyle].iEnabled == 1) || - gA_StyleSettings[iStyle].iEnabled == -1) + if((GetStyleSettingBool(iStyle, "inaccessible") && GetStyleSettingInt(iStyle, "enabled") == 1) || + GetStyleSettingInt(iStyle, "enabled") == -1) { continue; } @@ -1138,7 +1139,7 @@ public Action Command_Style(int client, int args) char sDisplay[64]; - if(gA_StyleSettings[iStyle].bUnranked) + if(GetStyleSettingBool(iStyle, "unranked")) { FormatEx(sDisplay, 64, "%T %s", "StyleUnranked", client, gS_StyleStrings[iStyle].sStyleName); } @@ -1285,13 +1286,13 @@ void ChangeClientStyle(int client, int style, bool manual) Shavit_PrintToChat(client, "%T", "StyleSelection", client, gS_ChatStrings.sStyle, gS_StyleStrings[style].sStyleName, gS_ChatStrings.sText); } - if(gA_StyleSettings[style].bUnranked) + if(GetStyleSettingBool(style, "unranked")) { Shavit_PrintToChat(client, "%T", "UnrankedWarning", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText); } - int aa_old = RoundToZero(gA_StyleSettings[gA_Timers[client].iStyle].fAiraccelerate); - int aa_new = RoundToZero(gA_StyleSettings[style].fAiraccelerate); + int aa_old = RoundToZero(GetStyleSettingFloat(gA_Timers[client].iStyle, "airaccelerate")); + int aa_new = RoundToZero(GetStyleSettingFloat(style, "airaccelerate")); if(aa_old != aa_new) { @@ -1342,7 +1343,7 @@ void DoJump(int client) } // TF2 doesn't use stamina - if(gEV_Type != Engine_TF2 && (gA_StyleSettings[gA_Timers[client].iStyle].bEasybhop) || Shavit_InsideZone(client, Zone_Easybhop, gA_Timers[client].iTrack)) + if(gEV_Type != Engine_TF2 && (GetStyleSettingBool(gA_Timers[client].iStyle, "easybhop")) || Shavit_InsideZone(client, Zone_Easybhop, gA_Timers[client].iTrack)) { SetEntPropFloat(client, Prop_Send, "m_flStamina", 0.0); } @@ -1359,14 +1360,19 @@ void VelocityChanges(int data) return; } - if(gA_Timers[client].fTimescale != -1.0) - { - SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", view_as(gA_Timers[client].fTimescale)); - } + int style = gA_Timers[client].iStyle; - else + if(GetStyleSettingBool(style, "force_timescale")) { - SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", view_as(gA_StyleSettings[gA_Timers[client].iStyle].fSpeedMultiplier)); + if(gA_Timers[client].fTimescale != -1.0) + { + SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", gA_Timers[client].fTimescale); + } + + else if(GetStyleSettingFloat(style, "speed") != 1.0) + { + SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetStyleSettingFloat(style, "speed")); + } } float fAbsVelocity[3]; @@ -1376,9 +1382,9 @@ void VelocityChanges(int data) if(fSpeed != 0.0) { - float fVelocityMultiplier = view_as(gA_StyleSettings[gA_Timers[client].iStyle].fVelocity); - float fVelocityBonus = view_as(gA_StyleSettings[gA_Timers[client].iStyle].fBonusVelocity); - float fMin = view_as(gA_StyleSettings[gA_Timers[client].iStyle].fMinVelocity); + float fVelocityMultiplier = GetStyleSettingFloat(style, "velocity"); + float fVelocityBonus = GetStyleSettingFloat(style, "bonus_velocity"); + float fMin = GetStyleSettingFloat(style, "min_velocity"); if(fVelocityMultiplier != 0.0) { @@ -1401,8 +1407,8 @@ void VelocityChanges(int data) } } - float fJumpMultiplier = gA_StyleSettings[gA_Timers[client].iStyle].fJumpMultiplier; - float fJumpBonus = gA_StyleSettings[gA_Timers[client].iStyle].fJumpBonus; + float fJumpMultiplier = GetStyleSettingFloat(style, "jump_multiplier"); + float fJumpBonus = GetStyleSettingFloat(style, "jump_bonus"); if(fJumpMultiplier != 0.0) { @@ -1495,7 +1501,7 @@ public int Native_HasStyleAccess(Handle handler, int numParams) { int style = GetNativeCell(2); - if(gA_StyleSettings[style].bInaccessible || gA_StyleSettings[style].iEnabled <= 0) + if(GetStyleSettingBool(style, "inaccessible") || GetStyleSettingInt(style, "enabled") <= 0) { return false; } @@ -1675,7 +1681,8 @@ public int Native_FinishMap(Handle handler, int numParams) Call_PushCell(gA_Timers[client].fTimer); Call_PushCell(gA_Timers[client].iJumps); Call_PushCell(gA_Timers[client].iStrafes); - Call_PushCell((gA_StyleSettings[gA_Timers[client].iStyle].bSync)? (gA_Timers[client].iGoodGains == 0)? 0.0:(gA_Timers[client].iGoodGains / float(gA_Timers[client].iTotalMeasures) * 100.0):-1.0); + //gross + Call_PushCell((GetStyleSettingBool(gA_Timers[client].iStyle, "sync"))? (gA_Timers[client].iGoodGains == 0)? 0.0:(gA_Timers[client].iGoodGains / float(gA_Timers[client].iTotalMeasures) * 100.0):-1.0); Call_PushCell(track = gA_Timers[client].iTrack); perfs = (gA_Timers[client].iMeasuredJumps == 0)? 100.0:(gA_Timers[client].iPerfectJumps / float(gA_Timers[client].iMeasuredJumps) * 100.0); } @@ -1686,7 +1693,8 @@ public int Native_FinishMap(Handle handler, int numParams) Call_PushCell(snapshot.fCurrentTime); Call_PushCell(snapshot.iJumps); Call_PushCell(snapshot.iStrafes); - Call_PushCell((gA_StyleSettings[snapshot.bsStyle].bSync)? (snapshot.iGoodGains == 0)? 0.0:(snapshot.iGoodGains / float(snapshot.iTotalMeasures) * 100.0):-1.0); + // gross + Call_PushCell((GetStyleSettingBool(snapshot.bsStyle, "sync"))? (snapshot.iGoodGains == 0)? 0.0:(snapshot.iGoodGains / float(snapshot.iTotalMeasures) * 100.0):-1.0); Call_PushCell(track = snapshot.iTimerTrack); perfs = (snapshot.iMeasuredJumps == 0)? 100.0:(snapshot.iPerfectJumps / float(snapshot.iMeasuredJumps) * 100.0); } @@ -1845,7 +1853,7 @@ public int Native_GetSync(Handle handler, int numParams) { int client = GetNativeCell(1); - return view_as((gA_StyleSettings[gA_Timers[client].iStyle].bSync)? (gA_Timers[client].iGoodGains == 0)? 0.0:(gA_Timers[client].iGoodGains / float(gA_Timers[client].iTotalMeasures) * 100.0):-1.0); + return view_as((GetStyleSettingBool(gA_Timers[client].iStyle, "sync")? (gA_Timers[client].iGoodGains == 0)? 0.0:(gA_Timers[client].iGoodGains / float(gA_Timers[client].iTotalMeasures) * 100.0):-1.0)); } public int Native_GetStyleCount(Handle handler, int numParams) @@ -1855,11 +1863,14 @@ public int Native_GetStyleCount(Handle handler, int numParams) public int Native_GetStyleSettings(Handle handler, int numParams) { + LogError("Shavit_GetStyleSettings is deprecated and will be removed in 3.0. Use Shavit_GetStyleSetting instead"); + if(GetNativeCell(3) != sizeof(stylesettings_t)) { return ThrowNativeError(200, "stylesettings_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins", GetNativeCell(3), sizeof(stylesettings_t)); } + return SetNativeArray(2, gA_StyleSettings[GetNativeCell(1)], sizeof(stylesettings_t)); } @@ -2057,12 +2068,31 @@ public int Native_GetStyleSettingInt(Handle handler, int numParams) char sKey[256]; GetNativeString(2, sKey, 256); - char sValue[16]; - gSM_StyleKeys[style].GetString(sKey, sValue, 16); + return GetStyleSettingInt(style, sKey); +} +int GetStyleSettingInt(int style, char[] key) +{ + char sValue[16]; + gSM_StyleKeys[style].GetString(key, sValue, 16); return StringToInt(sValue); } +public int Native_GetStyleSettingBool(Handle handler, int numParams) +{ + int style = GetNativeCell(1); + + char sKey[256]; + GetNativeString(2, sKey, 256); + + return GetStyleSettingBool(style, sKey); +} + +bool GetStyleSettingBool(int style, char[] key) +{ + return GetStyleSettingInt(style, key) != 0; +} + public any Native_GetStyleSettingFloat(Handle handler, int numParams) { int style = GetNativeCell(1); @@ -2070,9 +2100,13 @@ public any Native_GetStyleSettingFloat(Handle handler, int numParams) char sKey[256]; GetNativeString(2, sKey, 256); - char sValue[16]; - gSM_StyleKeys[style].GetString(sKey, sValue, 16); + return GetStyleSettingFloat(style, sKey); +} +float GetStyleSettingFloat(int style, char[] key) +{ + char sValue[16]; + gSM_StyleKeys[style].GetString(key, sValue, 16); return StringToFloat(sValue); } @@ -2084,10 +2118,15 @@ public any Native_HasStyleSetting(Handle handler, int numParams) char sKey[256]; GetNativeString(2, sKey, 256); - char sValue[1]; - gSM_StyleKeys[style].GetString(sKey, sValue, 1); + return HasStyleSetting(style, sKey); +} - return gSM_StyleKeys[style].GetString(sKey, sValue, 1); +bool HasStyleSetting(int style, char[] key) +{ + char sValue[1]; + gSM_StyleKeys[style].GetString(key, sValue, 1); + + return gSM_StyleKeys[style].GetString(key, sValue, 1); } int GetTimerStatus(int client) @@ -2116,8 +2155,8 @@ void StartTimer(int client, int track) GetEntPropVector(client, Prop_Data, "m_vecVelocity", fSpeed); if(!gCV_NoZAxisSpeed.BoolValue || - gA_StyleSettings[gA_Timers[client].iStyle].iPrespeed == 1 || - (fSpeed[2] == 0.0 && (gA_StyleSettings[gA_Timers[client].iStyle].iPrespeed == 2 || SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)) <= 290.0))) + GetStyleSettingInt(gA_Timers[client].iStyle, "prespeed") == 1 || + (fSpeed[2] == 0.0 && (GetStyleSettingInt(gA_Timers[client].iStyle, "prespeed") == 2 || SquareRoot(Pow(fSpeed[0], 2.0) + Pow(fSpeed[1], 2.0)) <= 290.0))) { Action result = Plugin_Continue; Call_StartForward(gH_Forwards_Start); @@ -2159,10 +2198,10 @@ void StartTimer(int client, int track) else { - SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", view_as(gA_StyleSettings[gA_Timers[client].iStyle].fSpeedMultiplier)); + SetEntPropFloat(client, Prop_Data, "m_flLaggedMovementValue", GetStyleSettingFloat(gA_Timers[client].iStyle, "speed")); } - SetEntityGravity(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier)); + SetEntityGravity(client, GetStyleSettingFloat(gA_Timers[client].iStyle, "gravity")); } else if(result == Plugin_Handled || result == Plugin_Stop) @@ -2369,10 +2408,80 @@ bool LoadStyles() SMCParser parser = new SMCParser(); parser.OnEnterSection = OnStyleEnterSection; + parser.OnLeaveSection = OnStyleLeaveSection; parser.OnKeyValue = OnStyleKeyValue; parser.ParseFile(sPath); delete parser; + + // TODO: REMOVE IN 3.0 + // These are being left in as a backwards compatibility for the forwards using the style settings struct. + // Forwards seem to be fairly safe but will eventually be deprecated in favor of removing enum struct api usage. + KeyValues kv = new KeyValues("shavit-styles"); + + if(!kv.ImportFromFile(sPath) || !kv.GotoFirstSubKey()) + { + delete kv; + + return false; + } + + int i = 0; + + do + { + gA_StyleSettings[i].bAutobhop = view_as(kv.GetNum("autobhop", 1)); + gA_StyleSettings[i].bEasybhop = view_as(kv.GetNum("easybhop", 1)); + gA_StyleSettings[i].iPrespeed = view_as(kv.GetNum("prespeed", 0)); + gA_StyleSettings[i].fVelocityLimit = kv.GetFloat("velocity_limit", 0.0); + gA_StyleSettings[i].fAiraccelerate = kv.GetFloat("airaccelerate", 1000.0); + gA_StyleSettings[i].bEnableBunnyhopping = view_as(kv.GetNum("bunnyhopping", 1)); + gA_StyleSettings[i].fRunspeed = kv.GetFloat("runspeed", 260.00); + gA_StyleSettings[i].fGravityMultiplier = kv.GetFloat("gravity", 1.0); + gA_StyleSettings[i].fSpeedMultiplier = kv.GetFloat("speed", 1.0); + gA_StyleSettings[i].fTimescale = view_as(kv.GetNum("halftime", 0))? 0.5:kv.GetFloat("timescale", 1.0); // backwards compat for old halftime settig + gA_StyleSettings[i].fVelocity = kv.GetFloat("velocity", 1.0); + gA_StyleSettings[i].fBonusVelocity = kv.GetFloat("bonus_velocity", 0.0); + gA_StyleSettings[i].fMinVelocity = kv.GetFloat("min_velocity", 0.0); + gA_StyleSettings[i].fJumpMultiplier = kv.GetFloat("jump_multiplier", 0.0); + gA_StyleSettings[i].fJumpBonus = kv.GetFloat("jump_bonus", 0.0); + gA_StyleSettings[i].bBlockW = view_as(kv.GetNum("block_w", 0)); + gA_StyleSettings[i].bBlockA = view_as(kv.GetNum("block_a", 0)); + gA_StyleSettings[i].bBlockS = view_as(kv.GetNum("block_s", 0)); + gA_StyleSettings[i].bBlockD = view_as(kv.GetNum("block_d", 0)); + gA_StyleSettings[i].bBlockUse = view_as(kv.GetNum("block_use", 0)); + gA_StyleSettings[i].iForceHSW = kv.GetNum("force_hsw", 0); + gA_StyleSettings[i].iBlockPLeft = kv.GetNum("block_pleft", 0); + gA_StyleSettings[i].iBlockPRight = kv.GetNum("block_pright", 0); + gA_StyleSettings[i].iBlockPStrafe = kv.GetNum("block_pstrafe", 0); + gA_StyleSettings[i].bUnranked = view_as(kv.GetNum("unranked", 0)); + gA_StyleSettings[i].bNoReplay = view_as(kv.GetNum("noreplay", 0)); + gA_StyleSettings[i].bSync = view_as(kv.GetNum("sync", 1)); + gA_StyleSettings[i].bStrafeCountW = view_as(kv.GetNum("strafe_count_w", false)); + gA_StyleSettings[i].bStrafeCountA = view_as(kv.GetNum("strafe_count_a", true)); + gA_StyleSettings[i].bStrafeCountS = view_as(kv.GetNum("strafe_count_s", false)); + gA_StyleSettings[i].bStrafeCountD = view_as(kv.GetNum("strafe_count_d", true)); + gA_StyleSettings[i].fRankingMultiplier = kv.GetFloat("rankingmultiplier", 1.00); + gA_StyleSettings[i].iSpecial = kv.GetNum("special", 0); + gA_StyleSettings[i].iOrdering = kv.GetNum("ordering", i); + gA_StyleSettings[i].bInaccessible = view_as(kv.GetNum("inaccessible", false)); + gA_StyleSettings[i].iEnabled = kv.GetNum("enabled", 1); + gA_StyleSettings[i].bKZCheckpoints = view_as(kv.GetNum("kzcheckpoints", 0)); + gA_StyleSettings[i].bForceKeysOnGround = view_as(kv.GetNum("force_groundkeys", 0)); + + // if this style is disabled, we will force certain settings + if(gA_StyleSettings[i].iEnabled <= 0) + { + gA_StyleSettings[i].bNoReplay = true; + gA_StyleSettings[i].fRankingMultiplier = 0.0; + gA_StyleSettings[i].bInaccessible = true; + } + } + + while(kv.GotoNextKey()); + + delete kv; + gB_Registered = true; SortCustom1D(gI_OrderedStyles, gI_Styles, SortAscending_StyleOrder); @@ -2418,96 +2527,68 @@ public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_ gS_StyleStrings[gI_CurrentParserIndex].sSpecialString = ""; gS_StyleStrings[gI_CurrentParserIndex].sStylePermission = ""; - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("autobhop", 1); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("easybhop", 1); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("prespeed", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("velocity_limit", 0.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("airaccelerate", 1000.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("bunnyhopping", 1); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("runspeed", 260.00); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("gravity", 1.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("speed", 1.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("halftime", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("timescale", 1.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("velocity", 1.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("bonus_velocity", 0.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("min_velocity", 0.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("jump_multiplier", 0.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("jump_bonus", 0.0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_w", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_a", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_s", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_d", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_use", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("force_hsw", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pleft", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pright", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("block_pstrafe", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("unranked", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("noreplay", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("sync", 1); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_w", false); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_a", true); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_s", false); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("strafe_count_d", true); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("rankingmultiplier", 1.00); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("special", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("ordering", gI_CurrentParserIndex); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("autobhop", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("easybhop", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("prespeed", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("velocity_limit", "0.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("airaccelerate", "1000.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("bunnyhopping", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("runspeed", "260.00"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("gravity", "1.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("speed", "1.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("halftime", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("timescale", "1.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("velocity", "1.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("bonus_velocity", "0.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("min_velocity", "0.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("jump_multiplier", "0.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("jump_bonus", "0.0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_w", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_a", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_s", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_d", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_use", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("force_hsw", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_pleft", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_pright", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("block_pstrafe", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("unranked", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("noreplay", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("sync", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("strafe_count_w", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("strafe_count_a", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("strafe_count_s", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("strafe_count_d", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("rankingmultiplier", "1.00"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("special", "0"); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("inaccessible", false); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("enabled", 1); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("kzcheckpoints", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("force_groundkeys", 0); + char sOrder[4]; + IntToString(gI_CurrentParserIndex, sOrder, 4); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("ordering", sOrder); - gA_StyleSettings[gI_CurrentParserIndex].bAutobhop = true; - gA_StyleSettings[gI_CurrentParserIndex].bEasybhop = true; - gA_StyleSettings[gI_CurrentParserIndex].iPrespeed = 0; - gA_StyleSettings[gI_CurrentParserIndex].fVelocityLimit = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].fAiraccelerate = 1000.0; - gA_StyleSettings[gI_CurrentParserIndex].bEnableBunnyhopping = true; - gA_StyleSettings[gI_CurrentParserIndex].fRunspeed = 260.00; - gA_StyleSettings[gI_CurrentParserIndex].fGravityMultiplier = 1.0; - gA_StyleSettings[gI_CurrentParserIndex].fSpeedMultiplier = 1.0; - gA_StyleSettings[gI_CurrentParserIndex].fTimescale = 1.0; - gA_StyleSettings[gI_CurrentParserIndex].fVelocity = 1.0; - gA_StyleSettings[gI_CurrentParserIndex].fBonusVelocity = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].fMinVelocity = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].fJumpMultiplier = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].fJumpBonus = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].bBlockW = false; - gA_StyleSettings[gI_CurrentParserIndex].bBlockA = false; - gA_StyleSettings[gI_CurrentParserIndex].bBlockS = false; - gA_StyleSettings[gI_CurrentParserIndex].bBlockD = false; - gA_StyleSettings[gI_CurrentParserIndex].bBlockUse = false; - gA_StyleSettings[gI_CurrentParserIndex].iForceHSW = 0; - gA_StyleSettings[gI_CurrentParserIndex].iBlockPLeft = 0; - gA_StyleSettings[gI_CurrentParserIndex].iBlockPRight = 0; - gA_StyleSettings[gI_CurrentParserIndex].iBlockPStrafe = 0; - gA_StyleSettings[gI_CurrentParserIndex].bUnranked = false; - gA_StyleSettings[gI_CurrentParserIndex].bNoReplay = false; - gA_StyleSettings[gI_CurrentParserIndex].bSync = true; - gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountW = false; - gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountA = true; - gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountS = false; - gA_StyleSettings[gI_CurrentParserIndex].bStrafeCountD = true; - gA_StyleSettings[gI_CurrentParserIndex].fRankingMultiplier = 1.00; - gA_StyleSettings[gI_CurrentParserIndex].iSpecial = 0; - gA_StyleSettings[gI_CurrentParserIndex].iOrdering = gI_CurrentParserIndex; - gA_StyleSettings[gI_CurrentParserIndex].bInaccessible = false; - gA_StyleSettings[gI_CurrentParserIndex].iEnabled = 1; - gA_StyleSettings[gI_CurrentParserIndex].bKZCheckpoints = false; - gA_StyleSettings[gI_CurrentParserIndex].bForceKeysOnGround = false; + gSM_StyleKeys[gI_CurrentParserIndex].SetString("inaccessible", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("enabled", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("kzcheckpoints", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("force_groundkeys", "0"); + gI_OrderedStyles[gI_CurrentParserIndex] = gI_CurrentParserIndex; + + return SMCParse_Continue; +} + +public SMCResult OnStyleLeaveSection(SMCParser smc) +{ // if this style is disabled, we will force certain settings - if(gA_StyleSettings[gI_CurrentParserIndex].iEnabled <= 0) + if(GetStyleSettingInt(gI_CurrentParserIndex, "enabled") <= 0) { - gA_StyleSettings[gI_CurrentParserIndex].bNoReplay = true; - gA_StyleSettings[gI_CurrentParserIndex].fRankingMultiplier = 0.0; - gA_StyleSettings[gI_CurrentParserIndex].bInaccessible = true; - - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("noreplay", true); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("rankingmultiplier", 0); - gSM_StyleKeys[gI_CurrentParserIndex].SetValue("inaccessible", true); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("noreplay", "1"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("rankingmultiplier", "0"); + gSM_StyleKeys[gI_CurrentParserIndex].SetString("inaccessible", "1"); + } + + if(GetStyleSettingBool(gI_CurrentParserIndex, "halftime")) + { + gSM_StyleKeys[gI_CurrentParserIndex].SetString("timescale", "0.5"); } if(!gB_Registered && strlen(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand) > 0 && !gA_StyleSettings[gI_CurrentParserIndex].bInaccessible) @@ -2556,12 +2637,6 @@ public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_ gI_StyleFlag[gI_CurrentParserIndex] = FlagToBit(flag); } } - - gI_OrderedStyles[gI_CurrentParserIndex] = gI_CurrentParserIndex; - - - - return SMCParse_Continue; } public SMCResult OnStyleKeyValue(SMCParser smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes) @@ -2571,8 +2646,8 @@ public SMCResult OnStyleKeyValue(SMCParser smc, const char[] key, const char[] v public int SortAscending_StyleOrder(int index1, int index2, const int[] array, any hndl) { - int iOrder1 = gA_StyleSettings[index1].iOrdering; - int iOrder2 = gA_StyleSettings[index2].iOrdering; + int iOrder1 = GetStyleSettingInt(index1, "ordering"); + int iOrder2 = GetStyleSettingInt(index2, "ordering"); if(iOrder1 < iOrder2) { @@ -3045,7 +3120,7 @@ public void Shavit_OnLeaveZone(int client, int type, int track, int id, int enti { if(type == Zone_Airaccelerate) { - UpdateAiraccelerate(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fAiraccelerate)); + UpdateAiraccelerate(client, GetStyleSettingFloat(gA_Timers[client].iStyle, "airaccelerate")); } } @@ -3055,7 +3130,7 @@ public void PreThinkPost(int client) { if(!gB_Zones || !Shavit_InsideZone(client, Zone_Airaccelerate, -1)) { - sv_airaccelerate.FloatValue = view_as(gA_StyleSettings[gA_Timers[client].iStyle].fAiraccelerate); + sv_airaccelerate.FloatValue = GetStyleSettingFloat(gA_Timers[client].iStyle, "airaccelerate"); } else @@ -3065,16 +3140,16 @@ public void PreThinkPost(int client) if(sv_enablebunnyhopping != null) { - sv_enablebunnyhopping.BoolValue = view_as(gA_StyleSettings[gA_Timers[client].iStyle].bEnableBunnyhopping); + sv_enablebunnyhopping.BoolValue = GetStyleSettingBool(gA_Timers[client].iStyle, "bunnyhopping"); } MoveType mtMoveType = GetEntityMoveType(client); - if(view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier) != 1.0 && + if(GetStyleSettingFloat(gA_Timers[client].iStyle, "gravity") != 1.0 && (mtMoveType == MOVETYPE_WALK || mtMoveType == MOVETYPE_ISOMETRIC) && (gA_Timers[client].iMoveType == MOVETYPE_LADDER || GetEntityGravity(client) == 1.0)) { - SetEntityGravity(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier)); + SetEntityGravity(client, GetStyleSettingFloat(gA_Timers[client].iStyle, "gravity")); } gA_Timers[client].iMoveType = mtMoveType; @@ -3149,7 +3224,7 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams) else { - time = frametime * view_as(gA_StyleSettings[gA_Timers[client].iStyle].fTimescale); + time = frametime * GetStyleSettingFloat(gA_Timers[client].iStyle, "timescale"); } gA_Timers[client].iZoneIncrement++; @@ -3173,7 +3248,9 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams) Call_PushCell(client); Call_PushArray(snapshot, sizeof(timer_snapshot_t)); Call_PushCellRef(time); + //TODO:REMOVE IN 3.0 Call_PushArray(gA_StyleSettings[gA_Timers[client].iStyle], sizeof(stylesettings_t)); + // Call_PushArray(NULL_VECTOR, sizeof(NULL_VECTOR)); Call_Finish(); gA_Timers[client].fTimer += time; @@ -3181,6 +3258,8 @@ public MRESReturn DHook_ProcessMovementPost(Handle hParams) Call_StartForward(gH_Forwards_OnTimerIncrementPost); Call_PushCell(client); Call_PushCell(time); + //TODO:REMOVE IN 3.0 + // Call_PushArray(NULL_VECTOR, sizeof(NULL_VECTOR)); Call_PushArray(gA_StyleSettings[gA_Timers[client].iStyle], sizeof(stylesettings_t)); Call_Finish(); @@ -3291,7 +3370,9 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 Call_PushCell(GetTimerStatus(client)); Call_PushCell(gA_Timers[client].iTrack); Call_PushCell(gA_Timers[client].iStyle); + //TODO:REMOVE IN 3.0 Call_PushArray(gA_StyleSettings[gA_Timers[client].iStyle], sizeof(stylesettings_t)); + // Call_PushArray(NULL_VECTOR, sizeof(NULL_VECTOR)); Call_PushArrayEx(mouse, 2, SM_PARAM_COPYBACK); Call_Finish(result); @@ -3306,13 +3387,13 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 if(gA_Timers[client].bEnabled && !gA_Timers[client].bPaused) { // +left/right block - if(!gB_Zones || (!bInStart && ((gA_StyleSettings[gA_Timers[client].iStyle].iBlockPLeft > 0 && - (buttons & IN_LEFT) > 0) || (gA_StyleSettings[gA_Timers[client].iStyle].iBlockPRight > 0 && (buttons & IN_RIGHT) > 0)))) + if(!gB_Zones || (!bInStart && ((GetStyleSettingInt(gA_Timers[client].iStyle, "block_pleft") > 0 && + (buttons & IN_LEFT) > 0) || (GetStyleSettingInt(gA_Timers[client].iStyle, "block_pright") > 0 && (buttons & IN_RIGHT) > 0)))) { vel[0] = 0.0; vel[1] = 0.0; - if(gA_StyleSettings[gA_Timers[client].iStyle].iBlockPRight >= 2) + if(GetStyleSettingInt(gA_Timers[client].iStyle, "block_pright") >= 2) { char sCheatDetected[64]; FormatEx(sCheatDetected, 64, "%T", "LeftRightCheat", client); @@ -3321,13 +3402,13 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 } // +strafe block - if(gA_StyleSettings[gA_Timers[client].iStyle].iBlockPStrafe > 0 && + if(GetStyleSettingInt(gA_Timers[client].iStyle, "block_pstrafe") > 0 && ((vel[0] > 0.0 && (buttons & IN_FORWARD) == 0) || (vel[0] < 0.0 && (buttons & IN_BACK) == 0) || (vel[1] > 0.0 && (buttons & IN_MOVERIGHT) == 0) || (vel[1] < 0.0 && (buttons & IN_MOVELEFT) == 0))) { if(gA_Timers[client].fStrafeWarning < gA_Timers[client].fTimer) { - if(gA_StyleSettings[gA_Timers[client].iStyle].iBlockPStrafe >= 2) + if(GetStyleSettingInt(gA_Timers[client].iStyle, "block_pstrafe") >= 2) { char sCheatDetected[64]; FormatEx(sCheatDetected, 64, "%T", "Inconsistencies", client); @@ -3356,26 +3437,26 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 int iPButtons = buttons; - if(gA_StyleSettings[gA_Timers[client].iStyle].bStrafeCountW && !gA_StyleSettings[gA_Timers[client].iStyle].bBlockW && + if(GetStyleSettingBool(gA_Timers[client].iStyle, "strafe_count_w") && !GetStyleSettingBool(gA_Timers[client].iStyle, "block_w") && (gA_Timers[client].iLastButtons & IN_FORWARD) == 0 && (buttons & IN_FORWARD) > 0) { gA_Timers[client].iStrafes++; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bStrafeCountA && !gA_StyleSettings[gA_Timers[client].iStyle].bBlockA && (gA_Timers[client].iLastButtons & IN_MOVELEFT) == 0 && - (buttons & IN_MOVELEFT) > 0 && (gA_StyleSettings[gA_Timers[client].iStyle].iForceHSW > 0 || ((buttons & IN_FORWARD) == 0 && (buttons & IN_BACK) == 0))) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "strafe_count_a") && !GetStyleSettingBool(gA_Timers[client].iStyle, "block_a") && (gA_Timers[client].iLastButtons & IN_MOVELEFT) == 0 && + (buttons & IN_MOVELEFT) > 0 && (GetStyleSettingInt(gA_Timers[client].iStyle, "force_hsw") > 0 || ((buttons & IN_FORWARD) == 0 && (buttons & IN_BACK) == 0))) { gA_Timers[client].iStrafes++; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bStrafeCountS && !gA_StyleSettings[gA_Timers[client].iStyle].bBlockS && + if(GetStyleSettingBool(gA_Timers[client].iStyle, "strafe_count_s") && !GetStyleSettingBool(gA_Timers[client].iStyle, "block_s") && (gA_Timers[client].iLastButtons & IN_BACK) == 0 && (buttons & IN_BACK) > 0) { gA_Timers[client].iStrafes++; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bStrafeCountD && !gA_StyleSettings[gA_Timers[client].iStyle].bBlockD && (gA_Timers[client].iLastButtons & IN_MOVERIGHT) == 0 && - (buttons & IN_MOVERIGHT) > 0 && (gA_StyleSettings[gA_Timers[client].iStyle].iForceHSW > 0 || ((buttons & IN_FORWARD) == 0 && (buttons & IN_BACK) == 0))) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "strafe_count_d") && !GetStyleSettingBool(gA_Timers[client].iStyle, "block_d") && (gA_Timers[client].iLastButtons & IN_MOVERIGHT) == 0 && + (buttons & IN_MOVERIGHT) > 0 && (GetStyleSettingInt(gA_Timers[client].iStyle, "force_hsw") > 0 || ((buttons & IN_FORWARD) == 0 && (buttons & IN_BACK) == 0))) { gA_Timers[client].iStrafes++; } @@ -3396,32 +3477,32 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 if(!gA_Timers[client].bCanUseAllKeys && mtMoveType != MOVETYPE_NOCLIP && mtMoveType != MOVETYPE_LADDER && !Shavit_InsideZone(client, Zone_Freestyle, -1)) { // block E - if(gA_StyleSettings[gA_Timers[client].iStyle].bBlockUse && (buttons & IN_USE) > 0) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "block_use") && (buttons & IN_USE) > 0) { buttons &= ~IN_USE; } - if(iGroundEntity == -1 || gA_StyleSettings[gA_Timers[client].iStyle].bForceKeysOnGround) + if(iGroundEntity == -1 || GetStyleSettingBool(gA_Timers[client].iStyle, "force_groundkeys")) { - if(gA_StyleSettings[gA_Timers[client].iStyle].bBlockW && ((buttons & IN_FORWARD) > 0 || vel[0] > 0.0)) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "block_w") && ((buttons & IN_FORWARD) > 0 || vel[0] > 0.0)) { vel[0] = 0.0; buttons &= ~IN_FORWARD; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bBlockA && ((buttons & IN_MOVELEFT) > 0 || vel[1] < 0.0)) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "block_a") && ((buttons & IN_MOVELEFT) > 0 || vel[1] < 0.0)) { vel[1] = 0.0; buttons &= ~IN_MOVELEFT; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bBlockS && ((buttons & IN_BACK) > 0 || vel[0] < 0.0)) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "block_s") && ((buttons & IN_BACK) > 0 || vel[0] < 0.0)) { vel[0] = 0.0; buttons &= ~IN_BACK; } - if(gA_StyleSettings[gA_Timers[client].iStyle].bBlockD && ((buttons & IN_MOVERIGHT) > 0 || vel[1] > 0.0)) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "block_d") && ((buttons & IN_MOVERIGHT) > 0 || vel[1] > 0.0)) { vel[1] = 0.0; buttons &= ~IN_MOVERIGHT; @@ -3431,9 +3512,9 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 // Theory about blocking non-HSW strafes while playing HSW: // Block S and W without A or D. // Block A and D without S or W. - if(gA_StyleSettings[gA_Timers[client].iStyle].iForceHSW > 0) + if(GetStyleSettingInt(gA_Timers[client].iStyle, "force_hsw") > 0) { - bool bSHSW = (gA_StyleSettings[gA_Timers[client].iStyle].iForceHSW == 2) && !bInStart; // don't decide on the first valid input until out of start zone! + bool bSHSW = (GetStyleSettingInt(gA_Timers[client].iStyle, "force_hsw") == 2) && !bInStart; // don't decide on the first valid input until out of start zone! int iCombination = -1; bool bForward = ((buttons & IN_FORWARD) > 0 && vel[0] >= 100.0); @@ -3509,7 +3590,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 bool bInWater = (GetEntProp(client, Prop_Send, "m_nWaterLevel") >= 2); // enable duck-jumping/bhop in tf2 - if(gEV_Type == Engine_TF2 && gA_StyleSettings[gA_Timers[client].iStyle].bEnableBunnyhopping && (buttons & IN_JUMP) > 0 && iGroundEntity != -1) + if(gEV_Type == Engine_TF2 && GetStyleSettingBool(gA_Timers[client].iStyle, "bunnyhopping") && (buttons & IN_JUMP) > 0 && iGroundEntity != -1) { float fSpeed[3]; GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed); @@ -3518,7 +3599,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 SetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed); } - if(gA_StyleSettings[gA_Timers[client].iStyle].bAutobhop && gA_Timers[client].bAuto && (buttons & IN_JUMP) > 0 && mtMoveType == MOVETYPE_WALK && !bInWater) + if(GetStyleSettingBool(gA_Timers[client].iStyle, "autobhop") && gA_Timers[client].bAuto && (buttons & IN_JUMP) > 0 && mtMoveType == MOVETYPE_WALK && !bInWater) { int iOldButtons = GetEntProp(client, Prop_Data, "m_nOldButtons"); SetEntProp(client, Prop_Data, "m_nOldButtons", (iOldButtons & ~IN_JUMP)); @@ -3547,16 +3628,16 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 } } - if(bInStart && gCV_BlockPreJump.BoolValue && gA_StyleSettings[gA_Timers[client].iStyle].iPrespeed == 0 && (vel[2] > 0 || (buttons & IN_JUMP) > 0)) + if(bInStart && gCV_BlockPreJump.BoolValue && GetStyleSettingInt(gA_Timers[client].iStyle, "prespeed") == 0 && (vel[2] > 0 || (buttons & IN_JUMP) > 0)) { vel[2] = 0.0; buttons &= ~IN_JUMP; } // velocity limit - if(iGroundEntity != -1 && view_as(gA_StyleSettings[gA_Timers[client].iStyle].fVelocityLimit > 0.0)) + if(iGroundEntity != -1 && GetStyleSettingFloat(gA_Timers[client].iStyle, "velocity_limit") > 0.0) { - float fSpeedLimit = view_as(gA_StyleSettings[gA_Timers[client].iStyle].fVelocityLimit); + float fSpeedLimit = GetStyleSettingFloat(gA_Timers[client].iStyle, "velocity_limit"); if(gB_Zones && Shavit_InsideZone(client, Zone_CustomSpeedLimit, -1)) { @@ -3679,15 +3760,15 @@ void UpdateStyleSettings(int client) { if(sv_autobunnyhopping != null) { - sv_autobunnyhopping.ReplicateToClient(client, (gA_StyleSettings[gA_Timers[client].iStyle].bAutobhop && gA_Timers[client].bAuto)? "1":"0"); + sv_autobunnyhopping.ReplicateToClient(client, (GetStyleSettingBool(gA_Timers[client].iStyle, "autobhop") && gA_Timers[client].bAuto)? "1":"0"); } if(sv_enablebunnyhopping != null) { - sv_enablebunnyhopping.ReplicateToClient(client, (gA_StyleSettings[gA_Timers[client].iStyle].bEnableBunnyhopping)? "1":"0"); + sv_enablebunnyhopping.ReplicateToClient(client, (GetStyleSettingBool(gA_Timers[client].iStyle, "bunnyhopping"))? "1":"0"); } - UpdateAiraccelerate(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fAiraccelerate)); + UpdateAiraccelerate(client, GetStyleSettingFloat(gA_Timers[client].iStyle, "airaccelerate")); - SetEntityGravity(client, view_as(gA_StyleSettings[gA_Timers[client].iStyle].fGravityMultiplier)); + SetEntityGravity(client, GetStyleSettingFloat(gA_Timers[client].iStyle, "gravity")); } From f997d4e54468d930da356031dd22f64d26f8b44d Mon Sep 17 00:00:00 2001 From: kidfearless Date: Mon, 14 Dec 2020 15:12:22 -0700 Subject: [PATCH 18/22] implement force_timescale in configs --- addons/sourcemod/configs/shavit-styles.cfg | 1 + addons/sourcemod/scripting/shavit-core.sp | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/addons/sourcemod/configs/shavit-styles.cfg b/addons/sourcemod/configs/shavit-styles.cfg index cc503778..d8cb0da4 100644 --- a/addons/sourcemod/configs/shavit-styles.cfg +++ b/addons/sourcemod/configs/shavit-styles.cfg @@ -31,6 +31,7 @@ "gravity" "1.0" // Gravity setting, 1.0 for default. Standard for low gravity styles is 0.6. "speed" "1.0" // Speed multiplier, 1.0 for default. Standard for slowmo styles is 0.5. "timescale" "1.0" // Timing will scale with this setting. + "force_timescale" "0" // Force the timescale every jump? Default is 0 for normal timescales. "velocity" "1.0" // % of horizontal velocity to keep per jump. a value 0.9 will make the player lose 10% of their velocity per jump. Likewise, values above 1 will result in speed gains. "bonus_velocity" "0.0" // Bonus velocity to gain per jump. If set to e.g. 100.0, the player will gain 100 bonus velocity per jump. "min_velocity" "0.0" // Minimum amount of horizontal velocity to keep per jump. If set to 600.0, the player can't have less than 600 velocity per jump. diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 96115201..60a2fca8 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -2591,6 +2591,20 @@ public SMCResult OnStyleLeaveSection(SMCParser smc) gSM_StyleKeys[gI_CurrentParserIndex].SetString("timescale", "0.5"); } + // Setting it here so that we can reference the timescale setting. + if(!HasStyleSetting(gI_CurrentParserIndex, "force_timescale")) + { + if(GetStyleSettingFloat(gI_CurrentParserIndex, "timescale") == 1.0) + { + gSM_StyleKeys[gI_CurrentParserIndex].SetString("force_timescale", "0"); + } + + else + { + gSM_StyleKeys[gI_CurrentParserIndex].SetString("force_timescale", "1"); + } + } + if(!gB_Registered && strlen(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand) > 0 && !gA_StyleSettings[gI_CurrentParserIndex].bInaccessible) { char sStyleCommands[32][32]; From dc57d481f808ae6a96904b02f00b4e0bc98b575d Mon Sep 17 00:00:00 2001 From: KiD Fearless Date: Tue, 29 Dec 2020 11:12:31 -0700 Subject: [PATCH 19/22] Change Shavit_GetStyleStrings to use style keys --- addons/sourcemod/scripting/shavit-core.sp | 96 ++++++++++++++++------- 1 file changed, 69 insertions(+), 27 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index 60a2fca8..536ab6cb 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -157,7 +157,6 @@ ConVar sv_enablebunnyhopping = null; bool gB_Registered = false; int gI_Styles = 0; int gI_OrderedStyles[STYLE_LIMIT]; -stylestrings_t gS_StyleStrings[STYLE_LIMIT]; stylesettings_t gA_StyleSettings[STYLE_LIMIT]; StringMap gSM_StyleKeys[STYLE_LIMIT]; int gI_CurrentParserIndex = 0; @@ -1141,7 +1140,9 @@ public Action Command_Style(int client, int args) if(GetStyleSettingBool(iStyle, "unranked")) { - FormatEx(sDisplay, 64, "%T %s", "StyleUnranked", client, gS_StyleStrings[iStyle].sStyleName); + char sName[64]; + gSM_StyleKeys[iStyle].GetString("name", sName, 64); + FormatEx(sDisplay, 64, "%T %s", "StyleUnranked", client, sName); } else @@ -1166,12 +1167,14 @@ public Action Command_Style(int client, int args) strcopy(sWR, 8, "BWR"); } - FormatEx(sDisplay, 64, "%s - %s: %s", gS_StyleStrings[iStyle].sStyleName, sWR, sTime); + char sName[64]; + gSM_StyleKeys[iStyle].GetString("name", sName, 64); + FormatEx(sDisplay, 64, "%s - %s: %s", sName, sWR, sTime); } else { - strcopy(sDisplay, 64, gS_StyleStrings[iStyle].sStyleName); + gSM_StyleKeys[iStyle].GetString("name", sDisplay, 64); } } @@ -1283,7 +1286,10 @@ void ChangeClientStyle(int client, int style, bool manual) return; } - Shavit_PrintToChat(client, "%T", "StyleSelection", client, gS_ChatStrings.sStyle, gS_StyleStrings[style].sStyleName, gS_ChatStrings.sText); + char sName[64]; + gSM_StyleKeys[style].GetString("name", sName, 64); + + Shavit_PrintToChat(client, "%T", "StyleSelection", client, gS_ChatStrings.sStyle, sName, gS_ChatStrings.sText); } if(GetStyleSettingBool(style, "unranked")) @@ -1879,16 +1885,52 @@ public int Native_GetStyleStrings(Handle handler, int numParams) int style = GetNativeCell(1); int type = GetNativeCell(2); int size = GetNativeCell(4); + char sValue[128]; switch(type) { - case sStyleName: return SetNativeString(3, gS_StyleStrings[style].sStyleName, size); - case sShortName: return SetNativeString(3, gS_StyleStrings[style].sShortName, size); - case sHTMLColor: return SetNativeString(3, gS_StyleStrings[style].sHTMLColor, size); - case sChangeCommand: return SetNativeString(3, gS_StyleStrings[style].sChangeCommand, size); - case sClanTag: return SetNativeString(3, gS_StyleStrings[style].sClanTag, size); - case sSpecialString: return SetNativeString(3, gS_StyleStrings[style].sSpecialString, size); - case sStylePermission: return SetNativeString(3, gS_StyleStrings[style].sStylePermission, size); + case sStyleName: + { + gSM_StyleKeys[style].GetString("name", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sShortName: + { + gSM_StyleKeys[style].GetString("shortname", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sHTMLColor: + { + gSM_StyleKeys[style].GetString("htmlcolor", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sChangeCommand: + { + gSM_StyleKeys[style].GetString("command", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sClanTag: + { + gSM_StyleKeys[style].GetString("clantag", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sSpecialString: + { + gSM_StyleKeys[style].GetString("specialstring", sValue, size); + + return SetNativeString(3, sValue, size); + } + case sStylePermission: + { + gSM_StyleKeys[style].GetString("permission", sValue, size); + + return SetNativeString(3, sValue, size); + } } return -1; @@ -2519,14 +2561,6 @@ public SMCResult OnStyleEnterSection(SMCParser smc, const char[] name, bool opt_ gSM_StyleKeys[gI_CurrentParserIndex].SetString("specialstring", ""); gSM_StyleKeys[gI_CurrentParserIndex].SetString("permission", ""); - gS_StyleStrings[gI_CurrentParserIndex].sStyleName = ""; - gS_StyleStrings[gI_CurrentParserIndex].sShortName = ""; - gS_StyleStrings[gI_CurrentParserIndex].sHTMLColor = ""; - gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand = ""; - gS_StyleStrings[gI_CurrentParserIndex].sClanTag = ""; - gS_StyleStrings[gI_CurrentParserIndex].sSpecialString = ""; - gS_StyleStrings[gI_CurrentParserIndex].sStylePermission = ""; - gSM_StyleKeys[gI_CurrentParserIndex].SetString("autobhop", "1"); gSM_StyleKeys[gI_CurrentParserIndex].SetString("easybhop", "1"); gSM_StyleKeys[gI_CurrentParserIndex].SetString("prespeed", "0"); @@ -2605,13 +2639,18 @@ public SMCResult OnStyleLeaveSection(SMCParser smc) } } - if(!gB_Registered && strlen(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand) > 0 && !gA_StyleSettings[gI_CurrentParserIndex].bInaccessible) + char sStyleCommand[128]; + gSM_StyleKeys[gI_CurrentParserIndex].GetString("command", sStyleCommand, 128); + char sName[64]; + gSM_StyleKeys[gI_CurrentParserIndex].GetString("name", sName, 64); + + if(!gB_Registered && strlen(sStyleCommand) > 0 && !gA_StyleSettings[gI_CurrentParserIndex].bInaccessible) { char sStyleCommands[32][32]; - int iCommands = ExplodeString(gS_StyleStrings[gI_CurrentParserIndex].sChangeCommand, ";", sStyleCommands, 32, 32, false); + int iCommands = ExplodeString(sStyleCommand, ";", sStyleCommands, 32, 32, false); char sDescription[128]; - FormatEx(sDescription, 128, "Change style to %s.", gS_StyleStrings[gI_CurrentParserIndex].sStyleName); + FormatEx(sDescription, 128, "Change style to %s.", sName); for(int x = 0; x < iCommands; x++) { @@ -2627,10 +2666,13 @@ public SMCResult OnStyleLeaveSection(SMCParser smc) } } - if(StrContains(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission, ";") != -1) + char sPermission[64]; + gSM_StyleKeys[gI_CurrentParserIndex].GetString("permission", sPermission, 64); + + if(StrContains(sPermission, ";") != -1) { char sText[2][32]; - int iCount = ExplodeString(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission, ";", sText, 2, 32); + int iCount = ExplodeString(sPermission, ";", sText, 2, 32); AdminFlag flag = Admin_Reservation; @@ -2642,11 +2684,11 @@ public SMCResult OnStyleLeaveSection(SMCParser smc) strcopy(gS_StyleOverride[gI_CurrentParserIndex], 32, (iCount >= 2)? sText[1]:""); } - else if(strlen(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission) > 0) + else if(strlen(sPermission) > 0) { AdminFlag flag = Admin_Reservation; - if(FindFlagByChar(gS_StyleStrings[gI_CurrentParserIndex].sStylePermission[0], flag)) + if(FindFlagByChar(sPermission[0], flag)) { gI_StyleFlag[gI_CurrentParserIndex] = FlagToBit(flag); } From 976fc90d87972bb379be743e74f2592926fd774b Mon Sep 17 00:00:00 2001 From: KiD Fearless Date: Wed, 6 Jan 2021 13:47:19 -0700 Subject: [PATCH 20/22] Speculatory exploit fix --- addons/sourcemod/scripting/shavit-zones.sp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index 44e82db9..921991f6 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -3093,6 +3093,31 @@ public void TouchPost(int entity, int other) Shavit_StartTimer(other, Track_Main); } } + case Zone_Respawn: + { + CS_RespawnPlayer(other); + } + + case Zone_Teleport: + { + TeleportEntity(other, gV_Destinations[gI_EntityZone[entity]], NULL_VECTOR, NULL_VECTOR); + } + + case Zone_Slay: + { + Shavit_StopTimer(other); + ForcePlayerSuicide(other); + Shavit_PrintToChat(other, "%T", "ZoneSlayEnter", other, gS_ChatStrings.sWarning, gS_ChatStrings.sVariable2, gS_ChatStrings.sWarning); + } + + case Zone_Stop: + { + if(Shavit_GetTimerStatus(other) != Timer_Stopped) + { + Shavit_StopTimer(other); + Shavit_PrintToChat(other, "%T", "ZoneStopEnter", other, gS_ChatStrings.sWarning, gS_ChatStrings.sVariable2, gS_ChatStrings.sWarning); + } + } } } From f2e1ad9706c33faf4b0eac09c095aae7fcfabdd9 Mon Sep 17 00:00:00 2001 From: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com> Date: Fri, 8 Jan 2021 16:24:59 +0300 Subject: [PATCH 21/22] Delete frames from cpcache on entry deletion (#1001) * Delete frames from cpcache on entry deletion * Handle few more cases * One more case --- addons/sourcemod/scripting/shavit-misc.sp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index a86cf3a9..03ce61ee 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -1149,7 +1149,7 @@ public void OnClientPutInServer(int client) } else { - gA_Checkpoints[client].Clear(); + ResetCheckpoints(client); } gB_SaveStates[client] = false; @@ -1352,6 +1352,11 @@ void ResetCheckpoints(int client) { if(gA_Checkpoints[client]) { + for(int i = 0; i < gA_Checkpoints[client].Length; i++) + { + delete view_as(gA_Checkpoints[client].Get(i, cp_cache_t::aFrames)); + } + gA_Checkpoints[client].Clear(); } @@ -2410,6 +2415,7 @@ bool SaveCheckpoint(int client, int index, bool overflow = false) if(gA_Checkpoints[client].Length >= iMaxCPs) { + delete view_as(gA_Checkpoints[client].Get(0, cp_cache_t::aFrames)); gA_Checkpoints[client].Erase(0); gI_CurrentCheckpoint[client] = gA_Checkpoints[client].Length; } @@ -2612,6 +2618,7 @@ bool DeleteCheckpoint(int client, int index) return false; } + delete view_as(gA_Checkpoints[client].Get(index, cp_cache_t::aFrames)); gA_Checkpoints[client].Erase(index); return true; From 655474025456111c4a8dd9c00f246720e0d88033 Mon Sep 17 00:00:00 2001 From: Nairda <38843773+Nairdaa@users.noreply.github.com> Date: Mon, 25 Jan 2021 03:46:03 +0100 Subject: [PATCH 22/22] useless pr, but KiD asked for it (#1007) * useless pr, but KiD asked for it added braces * yesn't updated to match the solid very good yes coding style also, added extra two empty lines at the bottom just in case anything breaks --- addons/sourcemod/scripting/shavit-hud.sp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index 5fc4e09b..3ffd5140 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -1312,9 +1312,20 @@ int AddHUDToBuffer_CSGO(int client, huddata_t data, char[] buffer, int maxlen) { int iColor = 0xFF0000; // red, worse than both pb and wr - if(data.iTimerStatus == Timer_Paused) iColor = 0xA9C5E8; // blue sky - else if(data.fTime < data.fWR || data.fWR == 0.0) iColor = GetGradient(0x00FF00, 0x96172C, RoundToZero((data.fTime / data.fWR) * 100)); - else if(data.fPB != 0.0 && data.fTime < data.fPB) iColor = 0xFFA500; // orange + if(data.iTimerStatus == Timer_Paused) + { + iColor = 0xA9C5E8; // blue sky + } + + else if(data.fTime < data.fWR || data.fWR == 0.0) + { + iColor = GetGradient(0x00FF00, 0x96172C, RoundToZero((data.fTime / data.fWR) * 100)); + } + + else if(data.fPB != 0.0 && data.fTime < data.fPB) + { + iColor = 0xFFA500; // orange + } char sTime[32]; FormatSeconds(data.fTime, sTime, 32, false); @@ -1979,4 +1990,5 @@ void TrimPlayerName(const char[] name, char[] outname, int len) if(count > gCV_SpecNameSymbolLength.IntValue) Format(outname, len, "%s...", outname); -} \ No newline at end of file +} +