From c4783eae37f1fe371355e0b419246fc25089482d Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Thu, 7 Oct 2021 19:30:33 +0000 Subject: [PATCH] shavit_misc_staticprestrafe -> shavit_core_staticprestrafe --- addons/sourcemod/scripting/shavit-core.sp | 58 ++++++++++++++++++++++ addons/sourcemod/scripting/shavit-misc.sp | 60 ----------------------- 2 files changed, 58 insertions(+), 60 deletions(-) diff --git a/addons/sourcemod/scripting/shavit-core.sp b/addons/sourcemod/scripting/shavit-core.sp index ed910093..b760edbc 100644 --- a/addons/sourcemod/scripting/shavit-core.sp +++ b/addons/sourcemod/scripting/shavit-core.sp @@ -43,6 +43,7 @@ EngineVersion gEV_Type = Engine_Unknown; bool gB_Protobuf = false; // hook stuff +DynamicHook gH_GetPlayerMaxSpeed = null; DynamicHook gH_AcceptInput; // used for hooking player_speedmod's AcceptInput Handle gH_PhysicsCheckForEntityUntouch; @@ -120,6 +121,7 @@ Convar gCV_VelocityTeleport = null; Convar gCV_DefaultStyle = null; Convar gCV_NoChatSound = null; Convar gCV_SimplerLadders = null; +Convar gCV_StaticPrestrafe = null; Convar gCV_UseOffsets = null; Convar gCV_TimeInMessages; Convar gCV_DebugOffsets = null; @@ -384,6 +386,7 @@ public void OnPluginStart() gCV_NoChatSound = new Convar("shavit_core_nochatsound", "0", "Disables click sound for chat messages.", 0, true, 0.0, true, 1.0); gCV_SimplerLadders = new Convar("shavit_core_simplerladders", "1", "Allows using all keys on limited styles (such as sideways) after touching ladders\nTouching the ground enables the restriction again.", 0, true, 0.0, true, 1.0); gCV_UseOffsets = new Convar("shavit_core_useoffsets", "1", "Calculates more accurate times by subtracting/adding tick offsets from the time the server uses to register that a player has left or entered a trigger", 0, true, 0.0, true, 1.0); + gCV_StaticPrestrafe = new Convar("shavit_core_staticprestrafe", "1", "Force prestrafe for every pistol.\n250 is the default value and some styles will have 260.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0); gCV_TimeInMessages = new Convar("shavit_core_timeinmessages", "0", "Whether to prefix SayText2 messages with the time.", 0, true, 0.0, true, 1.0); gCV_DebugOffsets = new Convar("shavit_core_debugoffsets", "0", "Print offset upon leaving or entering a zone?", 0, true, 0.0, true, 1.0); gCV_DisableSvCheats = new Convar("shavit_core_disable_sv_cheats", "1", "Force sv_cheats to 0.", 0, true, 0.0, true, 1.0); @@ -496,6 +499,18 @@ void LoadDHooks() } gH_PhysicsCheckForEntityUntouch = EndPrepSDKCall(); + if (gEV_Type != Engine_TF2) + { + int iOffset; + + if ((iOffset = GameConfGetOffset(gamedataConf, "CCSPlayer::GetPlayerMaxSpeed")) == -1) + { + SetFailState("Couldn't get the offset for \"CCSPlayer::GetPlayerMaxSpeed\" - make sure your gamedata is updated!"); + } + + gH_GetPlayerMaxSpeed = new DynamicHook(iOffset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity); + } + delete CreateInterface; delete gamedataConf; @@ -2605,6 +2620,11 @@ public void OnClientPutInServer(int client) SDKHook(client, SDKHook_PreThinkPost, PreThinkPost); SDKHook(client, SDKHook_PostThinkPost, PostThinkPost); + if (gEV_Type != Engine_TF2) + { + gH_GetPlayerMaxSpeed.HookEntity(Hook_Post, client, CCSPlayer__GetPlayerMaxSpeed); + } + int iSteamID = GetSteamAccountID(client); if(iSteamID == 0) @@ -3440,10 +3460,48 @@ public void Shavit_OnLeaveZone(int client, int type, int track, int id, int enti } } +public MRESReturn CCSPlayer__GetPlayerMaxSpeed(int pThis, DHookReturn hReturn) +{ + if (!gCV_StaticPrestrafe.BoolValue || !IsValidClient(pThis, true)) + { + return MRES_Ignored; + } + + hReturn.Value = GetStyleSettingFloat(gA_Timers[pThis].bsStyle, "runspeed"); + + return MRES_Override; +} + +void TF2_MaxSpeedStuff(int client) +{ + float maxspeed; + + if (GetEntityFlags(client) & FL_ONGROUND) + { + maxspeed = GetStyleSettingFloat(gA_Timers[client].bsStyle, "runspeed"); + } + else + { + // This is used to stop CTFGameMovement::PreventBunnyJumping from destroying + // player velocity when doing uncrouch stuff. Kind of poopy. + float fSpeed[3]; + GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed); + maxspeed = GetVectorLength(fSpeed); + } + + // not the best method, but only one i found for tf2 + SetEntPropFloat(client, Prop_Send, "m_flMaxspeed", maxspeed); +} + public void PreThinkPost(int client) { if(IsPlayerAlive(client)) { + if (gEV_Type == Engine_TF2) + { + TF2_MaxSpeedStuff(client); + } + if(!gB_Zones || !Shavit_InsideZone(client, Zone_Airaccelerate, -1)) { sv_airaccelerate.FloatValue = GetStyleSettingFloat(gA_Timers[client].bsStyle, "airaccelerate"); diff --git a/addons/sourcemod/scripting/shavit-misc.sp b/addons/sourcemod/scripting/shavit-misc.sp index f12f76b1..f1713ec8 100644 --- a/addons/sourcemod/scripting/shavit-misc.sp +++ b/addons/sourcemod/scripting/shavit-misc.sp @@ -117,7 +117,6 @@ Convar gCV_Scoreboard = null; Convar gCV_WeaponCommands = null; Convar gCV_WeaponsSpawnGood = null; Convar gCV_PlayerOpacity = null; -Convar gCV_StaticPrestrafe = null; Convar gCV_NoclipMe = null; Convar gCV_AdvertisementInterval = null; Convar gCV_Checkpoints = null; @@ -161,7 +160,6 @@ Handle gH_Forwards_OnCheckpointMenuMade = null; Handle gH_Forwards_OnCheckpointMenuSelect = null; // dhooks -Handle gH_GetPlayerMaxSpeed = null; DynamicHook gH_UpdateStepSound = null; DynamicHook gH_IsSpawnPointValid = null; DynamicDetour gH_CalcPlayerScore = null; @@ -326,7 +324,6 @@ public void OnPluginStart() gCV_WeaponCommands = new Convar("shavit_misc_weaponcommands", "2", "Enable sm_usp, sm_glock and sm_knife?\n0 - Disabled\n1 - Enabled\n2 - Also give infinite reserved ammo.\n3 - Also give infinite clip ammo.", 0, true, 0.0, true, 3.0); gCV_WeaponsSpawnGood = new Convar("shavit_misc_weaponsspawngood", "3", "Bitflag for making glocks spawn on burst-fire and USPs spawn with a silencer on.\n0 - Disabled\n1 - Spawn USPs with a silencer.\n2 - Spawn glocks on burst-fire mode.\n3 - Spawn both USPs and glocks GOOD.", 0, true, 0.0, true, 3.0); gCV_PlayerOpacity = new Convar("shavit_misc_playeropacity", "69", "Player opacity (alpha) to set on spawn.\n-1 - Disabled\nValue can go up to 255. 0 for invisibility.", 0, true, -1.0, true, 255.0); - gCV_StaticPrestrafe = new Convar("shavit_misc_staticprestrafe", "1", "Force prestrafe for every pistol.\n250 is the default value and some styles will have 260.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0); gCV_NoclipMe = new Convar("shavit_misc_noclipme", "1", "Allow +noclip, sm_p and all the noclip commands?\n0 - Disabled\n1 - Enabled\n2 - requires 'admin_noclipme' override or ADMFLAG_CHEATS flag.", 0, true, 0.0, true, 2.0); gCV_AdvertisementInterval = new Convar("shavit_misc_advertisementinterval", "600.0", "Interval between each chat advertisement.\nConfiguration file for those is configs/shavit-advertisements.cfg.\nSet to 0.0 to disable.\nRequires server restart for changes to take effect.", 0, true, 0.0); gCV_Checkpoints = new Convar("shavit_misc_checkpoints", "1", "Allow players to save and teleport to checkpoints.", 0, true, 0.0, true, 1.0); @@ -410,15 +407,6 @@ void LoadDHooks() LogError("Couldn't get the address for \"CTFGameRules::CalcPlayerScore\" - make sure your gamedata is updated!"); } } - else - { - if ((iOffset = GameConfGetOffset(hGameData, "CCSPlayer::GetPlayerMaxSpeed")) == -1) - { - SetFailState("Couldn't get the offset for \"CCSPlayer::GetPlayerMaxSpeed\" - make sure your gamedata is updated!"); - } - - gH_GetPlayerMaxSpeed = DHookCreate(iOffset, HookType_Entity, ReturnType_Float, ThisPointer_CBaseEntity, CCSPlayer__GetPlayerMaxSpeed); - } if ((iOffset = GameConfGetOffset(hGameData, "CBasePlayer::UpdateStepSound")) != -1) { @@ -1063,18 +1051,6 @@ public Action Command_Radio(int client, const char[] command, int args) return Plugin_Continue; } -public MRESReturn CCSPlayer__GetPlayerMaxSpeed(int pThis, DHookReturn hReturn) -{ - if(!gCV_StaticPrestrafe.BoolValue || !IsValidClient(pThis, true)) - { - return MRES_Ignored; - } - - hReturn.Value = Shavit_GetStyleSettingFloat(gI_Style[pThis], "runspeed"); - - return MRES_Override; -} - // Remove flags from replay bots that cause CBasePlayer::UpdateStepSound to return without playing a footstep. public MRESReturn Hook_UpdateStepSound_Pre(int pThis, DHookParam hParams) { @@ -1517,18 +1493,6 @@ public void OnClientPutInServer(int client) return; } - if(gEV_Type == Engine_TF2) - { - SDKHook(client, SDKHook_PreThinkPost, TF2_OnPreThink); - } - else - { - if(gH_GetPlayerMaxSpeed != null) - { - DHookEntity(gH_GetPlayerMaxSpeed, true, client); - } - } - if(!AreClientCookiesCached(client)) { gI_Style[client] = Shavit_GetBhopStyle(client); @@ -1821,30 +1785,6 @@ public Action OnSetTransmit(int entity, int client) return Plugin_Continue; } -public void TF2_OnPreThink(int client) -{ - if(IsPlayerAlive(client)) - { - float maxspeed; - - if (GetEntityFlags(client) & FL_ONGROUND) - { - maxspeed = Shavit_GetStyleSettingFloat(gI_Style[client], "runspeed"); - } - else - { - // This is used to stop CTFGameMovement::PreventBunnyJumping from destroying - // player velocity when doing uncrouch stuff. Kind of poopy. - float fSpeed[3]; - GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed); - maxspeed = GetVectorLength(fSpeed); - } - - // not the best method, but only one i found for tf2 - SetEntPropFloat(client, Prop_Send, "m_flMaxspeed", maxspeed); - } -} - public Action OnClientSayCommand(int client, const char[] command, const char[] sArgs) { if (!IsValidClient(client))