Skip to content

Commit 705de60

Browse files
committed
Add sm_bhop_enablebunnyhopping convar
Closes #19
1 parent aebec8a commit 705de60

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ It is similar to the bunnyhop found in newer Source engine games, such as Counte
1717

1818
## Dependencies
1919

20-
* SourceMod 1.11+
20+
* SourceMod 1.12+
2121
* [TF2Attributes](https://github.com/FlaminSarge/tf2attributes)
2222
* [Source Scramble](https://github.com/nosoop/SMExt-SourceScramble)
2323

2424
## Configuration
2525

2626
The plugin creates the following console variables:
2727

28-
* `sm_bhop_enabled ( def. "1" )` - When set, allows player speed to exceed maximum running speed.
28+
* `sm_bhop_enabled ( def. "1" )` - Whether to enable the plugin.
29+
* `sm_bhop_enablebunnyhopping ( def. "1" )` - When set, allows player speed to exceed maximum running speed.
2930
* `sm_bhop_autojump ( def. "1" )` - When set, players automatically re-jump while holding the jump button.
3031
* `sm_bhop_autojump_falldamage ( def. "0" )` - When set, players will take fall damage while auto-bunnyhopping.
3132
* `sm_bhop_duckjump ( def. "1" )` - When set, allows jumping while ducked.

addons/sourcemod/gamedata/tf-bhop.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/*
2-
* Copyright (C) 2021 Mikusch
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16-
*/
17-
181
"Games"
192
{
203
"tf"

addons/sourcemod/scripting/tf-bhop.sp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18+
#pragma semicolon 1
19+
#pragma newdecls required
20+
1821
#include <sourcemod>
1922
#include <sdktools>
2023
#include <sdkhooks>
@@ -23,10 +26,7 @@
2326
#include <tf2attributes>
2427
#include <sourcescramble>
2528

26-
#pragma semicolon 1
27-
#pragma newdecls required
28-
29-
#define PLUGIN_VERSION "1.8.2"
29+
#define PLUGIN_VERSION "1.9.0"
3030

3131
enum
3232
{
@@ -49,6 +49,7 @@ Cookie g_hCookieAutoJumpDisabled;
4949
Handle g_hSDKCallCanAirDash;
5050

5151
ConVar sm_bhop_enabled;
52+
ConVar sm_bhop_enablebunnyhopping;
5253
ConVar sm_bhop_autojump;
5354
ConVar sm_bhop_autojump_falldamage;
5455
ConVar sm_bhop_duckjump;
@@ -76,14 +77,17 @@ public void OnPluginStart()
7677

7778
g_hMemoryPatches = new ArrayList(sizeof(MemoryPatchData));
7879

79-
sm_bhop_enabled = CreateConVar("sm_bhop_enabled", "1", "When set, allows player speed to exceed maximum running speed.");
80+
CreateConVar("sm_bhop_version", PLUGIN_VERSION, "The plugin version.", FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY | FCVAR_DONTRECORD);
81+
sm_bhop_enabled = CreateConVar("sm_bhop_enabled", "1", "Whether to enable the plugin.");
8082
sm_bhop_enabled.AddChangeHook(OnConVarChanged_EnablePlugin);
83+
sm_bhop_enablebunnyhopping = CreateConVar("sm_bhop_enablebunnyhopping", "1", "When set, allows player speed to exceed maximum running speed.");
84+
sm_bhop_enablebunnyhopping.AddChangeHook(OnConVarChanged_EnableMemoryPatch);
8185
sm_bhop_autojump = CreateConVar("sm_bhop_autojump", "1", "When set, players automatically re-jump while holding the jump button.");
8286
sm_bhop_autojump_falldamage = CreateConVar("sm_bhop_autojump_falldamage", "0", "When set, players will take fall damage while auto-bunnyhopping.");
8387
sm_bhop_duckjump = CreateConVar("sm_bhop_duckjump", "1", "When set, allows jumping while ducked.");
8488
sm_bhop_duckjump.AddChangeHook(OnConVarChanged_EnableMemoryPatch);
8589

86-
g_hCookieAutoJumpDisabled = new Cookie("autobunnyhopping_disabled", "Do not automatically re-jump while holding jump button", CookieAccess_Protected);
90+
g_hCookieAutoJumpDisabled = new Cookie("bhop_autojump_disable", "Do not automatically re-jump while holding jump button", CookieAccess_Protected);
8791

8892
RegConsoleCmd("sm_bhop", ConCmd_ToggleAutoBunnyhopping, "Toggle auto-bunnyhopping preference");
8993

@@ -104,13 +108,13 @@ public void OnPluginStart()
104108
SetFailState("Failed to find signature for function 'CTFPlayer::CanAirDash'");
105109
}
106110

107-
char platform[64];
111+
char platform[16];
108112
if (gameconf.GetKeyValue("Platform", platform, sizeof(platform)))
109113
{
110114
if (StrEqual(platform, "linux"))
111-
CreateMemoryPatch(gameconf, "CTFGameMovement::PreventBunnyJumping::AllowBunnyJumping_Linux", sm_bhop_enabled);
115+
CreateMemoryPatch(gameconf, "CTFGameMovement::PreventBunnyJumping::AllowBunnyJumping_Linux", sm_bhop_enablebunnyhopping);
112116
else if (StrEqual(platform, "windows"))
113-
CreateMemoryPatch(gameconf, "CTFGameMovement::PreventBunnyJumping::AllowBunnyJumping_Windows", sm_bhop_enabled);
117+
CreateMemoryPatch(gameconf, "CTFGameMovement::PreventBunnyJumping::AllowBunnyJumping_Windows", sm_bhop_enablebunnyhopping);
114118
else
115119
SetFailState("Unknown or unsupported platform '%s'", platform);
116120
}
@@ -253,7 +257,7 @@ Action OnClientTakeDamage(int victim, int &attacker, int &inflictor, float &dama
253257

254258
bool HitTrigger(int entity)
255259
{
256-
char classname[16];
260+
char classname[13];
257261
if (GetEntityClassname(entity, classname, sizeof(classname)) && StrEqual(classname, "trigger_push"))
258262
{
259263
float pushDir[3];
@@ -320,7 +324,7 @@ bool CanBunnyhop(int client)
320324
{
321325
return !g_bDisabledAutoBhop[client]
322326
&& !g_bInJumpRelease[client]
323-
&& GetEntPropEnt(client, Prop_Send, "m_hVehicle") == -1
327+
&& GetEntPropEnt(client, Prop_Data, "m_hVehicle") == -1
324328
&& GetEntProp(client, Prop_Data, "m_nWaterLevel") < WL_Waist
325329
&& GetEntityMoveType(client) != MOVETYPE_NONE
326330
&& !TF2_IsPlayerInCondition(client, TFCond_HalloweenGhostMode)
@@ -329,10 +333,10 @@ bool CanBunnyhop(int client)
329333

330334
bool CanAirDash(int client)
331335
{
332-
return g_hSDKCallCanAirDash ? SDKCall(g_hSDKCallCanAirDash, client) : false;
336+
return SDKCall(g_hSDKCallCanAirDash, client);
333337
}
334338

335339
bool CanDeployParachute(int client)
336340
{
337-
return TF2Attrib_HookValueInt(0, "parachute_attribute", client) ? !TF2Attrib_HookValueInt(0, "parachute_disabled", client) : false;
341+
return TF2Attrib_HookValueInt(0, "parachute_attribute", client) != 0;
338342
}

0 commit comments

Comments
 (0)