Skip to content

Commit

Permalink
Fix targetname and classname locking (#1135)
Browse files Browse the repository at this point in the history
* Move resettargetname cvars to shavit-zones

* Prevent Touch function to proceed when it should be skipped
  • Loading branch information
GAMMACASE authored Mar 24, 2022
1 parent 3a6592c commit 8f07c1d
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 59 deletions.
50 changes: 31 additions & 19 deletions addons/sourcemod/configs/shavit-mapfixes.cfg
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
"Map fixes"
{
"bhop_apathy"
"bhop_strafecontrol"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_misc_resettargetname_main" "apathy"
"shavit_zones_extra_spawn_height" "1.0"
}
"bhop_tranquility"
{
"shavit_zones_prebuilt_visual_offset" "16"
}
"bhop_amaranthglow"
{
"shavit_zones_prebuilt_visual_offset" "16"
}
"bhop_crash_egypt"

"bhop_apathy"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_misc_resettargetname_main" "player"
"shavit_zones_resettargetname_main" "apathy"
}
"bhop_drop"
"bhop_crash_egypt"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_misc_resettargetname_main" "activator_boost"
"shavit_zones_resettargetname_main" "player"
}
"bhop_japan"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_misc_resetclassname_main" "beginner"
"shavit_zones_resetclassname_main" "beginner"
}
"bhop_shutdown"
"bhop_space"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_misc_resettargetname_main" "asdf"
"shavit_zones_resetclassname_main" "sadface"
}
"bhop_strafecontrol"
"bhop_shutdown"
{
"shavit_zones_extra_spawn_height" "1.0"
"shavit_zones_resettargetname_main" "asdf"
}
"bhop_tranquility"
"bhop_interloper"
{
"shavit_zones_prebuilt_visual_offset" "16"
"shavit_zones_resettargetname_main" "lol"
}

"bhop_solitude"
{
"shavit_misc_forcetargetnamereset" "1"
"shavit_zones_forcetargetnamereset" "1"
}
"bhop_drop"
{
"shavit_zones_forcetargetnamereset" "1"
"shavit_zones_resettargetname_main" "activator_boost"
}
"kz_bhop_kairo"
{
"shavit_zones_forcetargetnamereset" "1"
"shavit_zones_resettargetname_main" "tped"
"shavit_zones_resetclassname_main" "cp0filter"
}
}
36 changes: 0 additions & 36 deletions addons/sourcemod/scripting/shavit-misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ Convar gCV_AdvertisementInterval = null;
Convar gCV_RemoveRagdolls = null;
Convar gCV_ClanTag = null;
Convar gCV_DropAll = null;
Convar gCV_ForceTargetnameReset = null;
Convar gCV_ResetTargetnameMain = null;
Convar gCV_ResetTargetnameBonus = null;
Convar gCV_ResetClassnameMain = null;
Convar gCV_ResetClassnameBonus = null;
Convar gCV_JointeamHook = null;
Convar gCV_SpectatorList = null;
Convar gCV_HideChatCommands = null;
Expand Down Expand Up @@ -276,11 +271,6 @@ public void OnPluginStart()
gCV_RemoveRagdolls = new Convar("shavit_misc_removeragdolls", "1", "Remove ragdolls after death?\n0 - Disabled\n1 - Only remove replay bot ragdolls.\n2 - Remove all ragdolls.", 0, true, 0.0, true, 2.0);
gCV_ClanTag = new Convar("shavit_misc_clantag", "{tr}{styletag} :: {time}", "Custom clantag for players.\n0 - Disabled\n{styletag} - style tag.\n{style} - style name.\n{time} - formatted time.\n{tr} - first letter of track.\n{rank} - player rank.\n{cr} - player's chatrank from shavit-chat, trimmed, with no colors", 0);
gCV_DropAll = new Convar("shavit_misc_dropall", "1", "Allow all weapons to be dropped?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_ForceTargetnameReset = new Convar("shavit_misc_forcetargetnamereset", "0", "Reset the player's targetname upon timer start?\nRecommended to leave disabled. Enable via per-map configs when necessary.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_ResetTargetnameMain = new Convar("shavit_misc_resettargetname_main", "", "What targetname to use when resetting the player. You don't need to touch this");
gCV_ResetTargetnameBonus = new Convar("shavit_misc_resettargetname_bonus", "", "What targetname to use when resetting the player (on bonus tracks). You don't need to touch this");
gCV_ResetClassnameMain = new Convar("shavit_misc_resetclassname_main", "", "What classname to use when resetting the player. You don't need to touch this");
gCV_ResetClassnameBonus = new Convar("shavit_misc_resetclassname_bonus", "", "What classname to use when resetting the player (on bonus tracks). You don't need to touch this");
gCV_JointeamHook = new Convar("shavit_misc_jointeamhook", "1", "Hook `jointeam`?\n0 - Disabled\n1 - Enabled, players can instantly change teams.", 0, true, 0.0, true, 1.0);
gCV_SpectatorList = new Convar("shavit_misc_speclist", "1", "Who to show in !specs?\n0 - everyone\n1 - all admins (admin_speclisthide override to bypass)\n2 - players you can target", 0, true, 0.0, true, 2.0);
gCV_HideChatCommands = new Convar("shavit_misc_hidechatcmds", "1", "Hide commands from chat?\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
Expand Down Expand Up @@ -2144,32 +2134,6 @@ public Action Shavit_OnStart(int client)
SetClientEventsPaused(client, false);
}

if(gCV_ForceTargetnameReset.BoolValue)
{
char targetname[64];
char classname[64];

if (Shavit_GetClientTrack(client) == Track_Main)
{
gCV_ResetTargetnameMain.GetString(targetname, sizeof(targetname));
gCV_ResetClassnameMain.GetString(classname, sizeof(classname));
}
else
{
gCV_ResetTargetnameBonus.GetString(targetname, sizeof(targetname));
gCV_ResetClassnameBonus.GetString(classname, sizeof(classname));
}

DispatchKeyValue(client, "targetname", targetname);

if (!classname[0])
{
classname = "player";
}

SetEntPropString(client, Prop_Data, "m_iClassname", classname);
}

return Plugin_Continue;
}

Expand Down
59 changes: 55 additions & 4 deletions addons/sourcemod/scripting/shavit-zones.sp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ Convar gCV_BoxOffset = null;
Convar gCV_ExtraSpawnHeight = null;
Convar gCV_PrebuiltVisualOffset = null;

Convar gCV_ForceTargetnameReset = null;
Convar gCV_ResetTargetnameMain = null;
Convar gCV_ResetTargetnameBonus = null;
Convar gCV_ResetClassnameMain = null;
Convar gCV_ResetClassnameBonus = null;

// handles
Handle gH_DrawVisible = null;
Handle gH_DrawAllZones = null;
Expand Down Expand Up @@ -313,6 +319,12 @@ public void OnPluginStart()
gCV_ExtraSpawnHeight = new Convar("shavit_zones_extra_spawn_height", "0.0", "YOU DONT NEED TO TOUCH THIS USUALLY. FIX YOUR ACTUAL ZONES.\nUsed to fix some shit prebuilt zones that are in the ground like bhop_strafecontrol");
gCV_PrebuiltVisualOffset = new Convar("shavit_zones_prebuilt_visual_offset", "0", "YOU DONT NEED TO TOUCH THIS USUALLY.\nUsed to fix the VISUAL beam offset for prebuilt zones on a map.\nExample maps you'd want to use 16 on: bhop_tranquility and bhop_amaranthglow");

gCV_ForceTargetnameReset = new Convar("shavit_zones_forcetargetnamereset", "0", "Reset the player's targetname upon timer start?\nRecommended to leave disabled. Enable via per-map configs when necessary.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_ResetTargetnameMain = new Convar("shavit_zones_resettargetname_main", "", "What targetname to use when resetting the player.\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetTargetnameBonus = new Convar("shavit_zones_resettargetname_bonus", "", "What targetname to use when resetting the player (on bonus tracks).\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetClassnameMain = new Convar("shavit_zones_resetclassname_main", "", "What classname to use when resetting the player.\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");
gCV_ResetClassnameBonus = new Convar("shavit_zones_resetclassname_bonus", "", "What classname to use when resetting the player (on bonus tracks).\nWould be applied once player teleports to the start zone or on every start if shavit_zones_forcetargetnamereset cvar is set to 1.\nYou don't need to touch this");

gCV_Interval.AddChangeHook(OnConVarChanged);
gCV_UseCustomSprite.AddChangeHook(OnConVarChanged);
gCV_Offset.AddChangeHook(OnConVarChanged);
Expand Down Expand Up @@ -4007,6 +4019,40 @@ public void Shavit_OnDatabaseLoaded()
}
}

void ResetClientTargetNameAndClassName(int client, int track)
{
char targetname[64];
char classname[64];

if (track == Track_Main)
{
gCV_ResetTargetnameMain.GetString(targetname, sizeof(targetname));
gCV_ResetClassnameMain.GetString(classname, sizeof(classname));
}
else
{
gCV_ResetTargetnameBonus.GetString(targetname, sizeof(targetname));
gCV_ResetClassnameBonus.GetString(classname, sizeof(classname));
}

DispatchKeyValue(client, "targetname", targetname);

if (!classname[0])
{
classname = "player";
}

SetEntPropString(client, Prop_Data, "m_iClassname", classname);
}

public Action Shavit_OnStart(int client, int track)
{
if(gCV_ForceTargetnameReset.BoolValue)
{
ResetClientTargetNameAndClassName(client, track);
}
}

public void Shavit_OnRestart(int client, int track)
{
gI_LastStage[client] = 0;
Expand Down Expand Up @@ -4053,6 +4099,7 @@ public void Shavit_OnRestart(int client, int track)

if (!gB_HasSetStart[client][track] || gB_StartAnglesOnly[client][track])
{
ResetClientTargetNameAndClassName(client, track);
// normally StartTimer will happen on zone-touch BUT we have this here for zones that are in the air
Shavit_StartTimer(client, track);
}
Expand Down Expand Up @@ -4454,18 +4501,22 @@ public void TouchPost(int entity, int other)
// and be fired after which is the expected and desired effect.
// This also kills all ongoing events that were active on the client prior to the teleportation to start and also resets targetname and classname
// before the OnStartTouch from triggers in start zone are run, thus preventing the maps to be abusable if they don't have any reset triggers in place
if (curr_tick != tick_served[other])
if (gI_LatestTeleportTick[other] <= curr_tick <= gI_LatestTeleportTick[other] + 4)
{
if (gI_LatestTeleportTick[other] <= curr_tick <= gI_LatestTeleportTick[other] + 4)
if (curr_tick != tick_served[other])
{
ResetClientTargetNameAndClassName(other, gA_ZoneCache[gI_EntityZone[entity]].iZoneTrack);

PhysicsRemoveTouchedList(other);
ClearClientEvents(other);

tick_served[other] = curr_tick;

return;
}

return;
}
else if (curr_tick != tick_served[other])
{
tick_served[other] = 0;
}
}
Expand Down

0 comments on commit 8f07c1d

Please sign in to comment.