Skip to content

Commit

Permalink
Allow jumping while ducking (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikusch authored Jan 12, 2021
1 parent e9f65f8 commit f9ad637
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ added by the plugin.

* SourceMod 1.10
* [DHooks with Detour Support](https://forums.alliedmods.net/showpost.php?p=2588686&postcount=589)
* [MemoryPatch](https://github.com/Kenzzer/MemoryPatch) (compile only)

## ConVars

* `sv_enablebunnyhopping ( def. "1" )` - Allow player speed to exceed maximum running speed
* `sv_autobunnyhopping ( def. "1" )` - Players automatically re-jump while holding jump button
* `sv_duckbunnyhopping ( def. "1" )` - Allow jumping while ducked

It is recommended to set `sv_airaccelerate` to at least `150` if you intend to use this plugin.
30 changes: 30 additions & 0 deletions addons/sourcemod/gamedata/tf-bhop.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@
"linux" "@_ZNK9CTFPlayer10CanAirDashEv"
"windows" "\x2A\x2A\x2A\x2A\x2A\x2A\x57\x8B\xF9\xF7\x87\x84\x1A\x00\x00\x00\x00\x04\x00"
}
"CTFGameMovement::CheckJumpButton"
{
"library" "server"
"linux" "@_ZN15CTFGameMovement15CheckJumpButtonEv"
"windows" "\x55\x8B\xEC\x83\xEC\x0C\x57\x8B\xF9\x8B\x47\x04\x80\xB8\x54\x0A\x00\x00\x00"
}
}
"Addresses"
{
"MemoryPatch_AllowDuckJump"
{
"linux"
{
"signature" "CTFGameMovement::CheckJumpButton"
"offset" "204" // CTFGameMovement::CheckJumpButton+CC
}
"windows"
{
"signature" "CTFGameMovement::CheckJumpButton"
"offset" "499" // CTFGameMovement::CheckJumpButton+1F3
}
}
}
"Functions"
{
Expand All @@ -27,5 +49,13 @@
"this" "ignore"
}
}
"Keys"
{
"MemoryPatch_AllowDuckJump"
{
"linux" "\xEB" // jz short -> jmp short
"windows" "\xEB" // jz short -> jmp short
}
}
}
}
34 changes: 32 additions & 2 deletions addons/sourcemod/scripting/tf-bhop.sp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <sourcemod>
#include <dhooks>
#include <memorypatch>

#pragma semicolon 1
#pragma newdecls required
Expand All @@ -31,9 +32,11 @@ enum

ConVar sv_enablebunnyhopping;
ConVar sv_autobunnyhopping;
ConVar sv_duckbunnyhopping;

DynamicDetour g_DHookPreventBunnyJumping;
Handle g_SDKCallCanAirDash;
MemoryPatch g_MemoryPatchAllowDuck;

bool g_InJumpRelease[MAXPLAYERS + 1];

Expand All @@ -42,14 +45,16 @@ public Plugin myinfo =
name = "Team Fortress 2 Bunnyhop",
author = "Mikusch",
description = "Simply TF2 bunnyhopping plugin",
version = "v1.0",
version = "v1.1",
url = "https://github.com/Mikusch/tf-bhop"
}

public void OnPluginStart()
{
sv_enablebunnyhopping = CreateConVar("sv_enablebunnyhopping", "1", "Allow player speed to exceed maximum running speed", FCVAR_REPLICATED, true, 0.0, true, 1.0);
sv_autobunnyhopping = CreateConVar("sv_autobunnyhopping", "1", "Players automatically re-jump while holding jump button", FCVAR_REPLICATED, true, 0.0, true, 1.0);
sv_duckbunnyhopping = CreateConVar("sv_duckbunnyhopping", "1", "Allow jumping while ducked", FCVAR_REPLICATED, true, 0.0, true, 1.0);
sv_duckbunnyhopping.AddChangeHook(ConVarChanged_DuckBunnyhopping);

GameData gamedata = new GameData("tf-bhop");
if (gamedata == null)
Expand All @@ -74,9 +79,21 @@ public void OnPluginStart()
SetFailState("Failed to find signature for function CTFPlayer::CanAirDash");
}

MemoryPatch.SetGameData(gamedata);

g_MemoryPatchAllowDuck = new MemoryPatch("MemoryPatch_AllowDuckJump");
if (g_MemoryPatchAllowDuck != null)
g_MemoryPatchAllowDuck.Enable();

delete gamedata;
}

public void OnPluginEnd()
{
if (g_MemoryPatchAllowDuck != null)
g_MemoryPatchAllowDuck.Disable();
}

public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
if (sv_autobunnyhopping.BoolValue)
Expand All @@ -94,7 +111,6 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
else if (!g_InJumpRelease[client] && GetWaterLevel(client) < WL_Waist)
{
buttons &= ~IN_JUMP;
SetEntityFlags(client, flags & ~FL_DUCKING);
}
}
else if (CanAirDash(client))
Expand All @@ -109,6 +125,20 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
}
}

public void ConVarChanged_DuckBunnyhopping(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (convar.BoolValue)
{
if (g_MemoryPatchAllowDuck != null)
g_MemoryPatchAllowDuck.Enable();
}
else
{
if (g_MemoryPatchAllowDuck != null)
g_MemoryPatchAllowDuck.Disable();
}
}

public MRESReturn DHookCallback_PreventBunnyJumpingPre()
{
return sv_enablebunnyhopping.BoolValue ? MRES_Supercede : MRES_Ignored;
Expand Down

0 comments on commit f9ad637

Please sign in to comment.