Skip to content

Commit 65007b1

Browse files
committed
feat(scripting/player): GetBunnyhop & SetBunnyhop
1 parent 23c84f6 commit 65007b1

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed

src/player/Player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ class Player
114114

115115
CPlayerBitVec m_selfMutes[64] = {};
116116

117+
bool bunnyhopState = false;
118+
117119
private:
118120
int slot;
119121
bool isFakeClient = false;

src/player/PlayerManager.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#include "PlayerManager.h"
2+
#include "../hooks/FuncHook.h"
3+
4+
void Hook_CCSPlayer_MovementServices_CheckJumpPre(CCSPlayer_MovementServices *services, void *movementData);
5+
6+
FuncHook<decltype(Hook_CCSPlayer_MovementServices_CheckJumpPre)> TCCSPlayer_MovementServices_CheckJumpPre(Hook_CCSPlayer_MovementServices_CheckJumpPre, "CCSPlayer_MovementServices_CheckJumpPre");
27

38
PlayerManager::PlayerManager() {}
49
PlayerManager::~PlayerManager() {}
@@ -62,4 +67,34 @@ Player *PlayerManager::FindPlayerBySteamID(uint64 steamid)
6267
return player;
6368
}
6469
return nullptr;
70+
}
71+
72+
ConVar *FetchCVar(std::string cvarname);
73+
ConVar *autobunnyhoppingcvar = nullptr;
74+
75+
void Hook_CCSPlayer_MovementServices_CheckJumpPre(CCSPlayer_MovementServices *services, void *movementData)
76+
{
77+
if (autobunnyhoppingcvar == nullptr)
78+
autobunnyhoppingcvar = FetchCVar("sv_autobunnyhopping");
79+
80+
bool &autobunnyhopping = *reinterpret_cast<bool *>(&autobunnyhoppingcvar->values);
81+
82+
if (!autobunnyhopping)
83+
{
84+
Player *player = g_playerManager->GetPlayer(((CPlayer_MovementServices *)services)->m_pPawn->m_hController().GetEntryIndex() - 1);
85+
if (player)
86+
{
87+
if (player->bunnyhopState)
88+
{
89+
autobunnyhopping = true;
90+
91+
TCCSPlayer_MovementServices_CheckJumpPre(services, movementData);
92+
93+
autobunnyhopping = false;
94+
return;
95+
}
96+
}
97+
}
98+
99+
TCCSPlayer_MovementServices_CheckJumpPre(services, movementData);
65100
}

src/plugins/core/scripting.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ class PluginPlayer
593593

594594
void SetVoiceFlags(int flags);
595595
int GetVoiceFlags();
596+
597+
void SetBunnyhop(bool state);
598+
bool GetBunnyhop();
596599
};
597600

598601
//////////////////////////////////////////////////////////////

src/plugins/core/scripting/player.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,23 @@ uint32_t PluginPlayer::GetConnectedTime()
460460
PluginWeaponManager PluginPlayer::GetWeaponManager()
461461
{
462462
return PluginWeaponManager(playerId);
463+
}
464+
465+
void PluginPlayer::SetBunnyhop(bool state)
466+
{
467+
Player *self = g_playerManager->GetPlayer(this->playerId);
468+
if (!self)
469+
return;
470+
471+
self->SetClientConvar("sv_autobunnyhopping", state ? "true" : "false");
472+
self->bunnyhopState = state;
473+
}
474+
475+
bool PluginPlayer::GetBunnyhop()
476+
{
477+
Player *self = g_playerManager->GetPlayer(this->playerId);
478+
if (!self)
479+
return false;
480+
481+
return self->bunnyhopState;
463482
}

src/plugins/lua/scripting/player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "core.h"
22
#include "../../../player/PlayerManager.h"
33

4-
54
std::map<int, std::pair<uint64_t, PluginPlayer *>> playerObjectCache;
65

76
PluginPlayer *scripting_GetPlayer(int playerid, lua_State *state)
@@ -75,6 +74,8 @@ void SetupLuaPlayer(LuaPlugin *plugin, lua_State *state)
7574
.addFunction("SetVoiceFlags", &PluginPlayer::SetVoiceFlags)
7675
.addFunction("GetConnectedTime", &PluginPlayer::GetConnectedTime)
7776
.addFunction("GetWeaponManager", &PluginPlayer::GetWeaponManager)
77+
.addFunction("SetBunnyhop", &PluginPlayer::SetBunnyhop)
78+
.addFunction("GetBunnyhop", &PluginPlayer::GetBunnyhop)
7879
.endClass()
7980
.addFunction("GetPlayer", scripting_GetPlayer);
8081
}

src/sdk/entity/services.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
class CBaseEntity;
99
class CCSPlayerPawn;
10+
class CBasePlayerPawn;
11+
12+
class CPlayerPawnComponent
13+
{
14+
public:
15+
virtual ~CPlayerPawnComponent() = 0;
16+
17+
private:
18+
[[maybe_unused]] uint8_t __pad0008[0x28]; // 0x8
19+
public:
20+
CBasePlayerPawn *m_pPawn; // 0x30
21+
};
1022

1123
struct CSPerRoundStats_t
1224
{
@@ -33,7 +45,7 @@ class CCSPlayerController_ActionTrackingServices
3345
SCHEMA_FIELD_OFFSET(CSMatchStats_t, m_matchStats, 0)
3446
};
3547

36-
class CPlayer_MovementServices
48+
class CPlayer_MovementServices : public CPlayerPawnComponent
3749
{
3850
public:
3951
DECLARE_SCHEMA_CLASS_BASE(CPlayer_MovementServices, false)
@@ -109,7 +121,7 @@ class CCSPlayer_ItemServices
109121
class WeaponPurchaseCount_t
110122
{
111123
private:
112-
virtual void unk01(){};
124+
virtual void unk01() {};
113125
uint64_t unk1 = 0; // 0x8
114126
uint64_t unk2 = 0; // 0x10
115127
uint64_t unk3 = 0; // 0x18
@@ -138,14 +150,6 @@ class CCSPlayer_ActionTrackingServices
138150
SCHEMA_FIELD_OFFSET(WeaponPurchaseTracker_t, m_weaponPurchasesThisRound, 0)
139151
};
140152

141-
class CPlayerPawnComponent
142-
{
143-
public:
144-
DECLARE_SCHEMA_CLASS_BASE(CPlayerPawnComponent, false)
145-
146-
SCHEMA_FIELD_OFFSET(CCSPlayerPawn *, __m_pChainEntity, 0)
147-
};
148-
149153
class CPlayer_WeaponServices : public CPlayerPawnComponent
150154
{
151155
public:

src/signatures/Signatures.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CCSPlayerPawnBase;
1616
class CTakeDamageInfo;
1717
class IRecipientFilter;
1818
class CEntityIndex;
19+
class CCSPlayer_MovementServices;
1920

2021
struct EmitSound_t;
2122
struct SndOpEventGuid_t;
@@ -37,6 +38,7 @@ typedef void (*CBasePlayerController_SetPawn)(CBasePlayerController *, CCSPlayer
3738
typedef void (*CCSPlayerPawnBase_PostThink)(CCSPlayerPawnBase *);
3839
typedef void (*CBaseEntity_TakeDamageOld)(Z_CBaseEntity *, CTakeDamageInfo *);
3940
typedef void (*CBaseEntity_EmitSoundParams)(Z_CBaseEntity *, const char *, int, float, float);
41+
typedef void (*CCSPlayer_MovementServices_CheckJumpPre)(CCSPlayer_MovementServices *, void *);
4042
typedef SndOpEventGuid_t (*CBaseEntity_EmitSoundFilter)(IRecipientFilter &filter, CEntityIndex ent, const EmitSound_t &params);
4143

4244
class Signatures

0 commit comments

Comments
 (0)