11#include " entrypoint.h"
2- #include < Embedder.h>
3- #include " utilsclass.h"
2+ #include < embedder/src/embedder.h>
43#include < ehandle.h>
54#include " sdk/services.h"
6-
5+ #include " sdk/CRecipientFilters.h"
6+ #include " networkbasetypes.pb.h"
77#include < swiftly-ext/sdk.h>
8+ #include < swiftly-ext/memory.h>
89
9- void Hook_CCSPlayer_MovementServices_CheckJumpPre (void * services, void * movementData );
10+ dyno::ReturnAction Hook_CCSPlayer_MovementServices_CheckJumpPre (dyno::CallbackType cbType, dyno::IHook& hook );
1011
1112// ////////////////////////////////////////////////////////////
1213// /////////////// Core Variables //////////////
1314// //////////////////////////////////////////////////////////
1415
15- SH_DECL_HOOK5_void (IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0 , CPlayerSlot, ENetworkDisconnectionReason, const char *, uint64, const char *);
16+ SH_DECL_HOOK5_void (IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0 , CPlayerSlot, ENetworkDisconnectionReason, const char *, uint64, const char *);
1617SH_DECL_HOOK2 (IGameEventManager2, LoadEventsFromFile, SH_NOATTRIB, 0 , int , const char *, bool );
1718
1819int loadEventFromFileHookID = -1 ;
19- IServerGameClients * gameclients = nullptr ;
20+ IServerGameClients* gameclients = nullptr ;
2021IGameEventManager2* g_gameEventManager = nullptr ;
2122IGameEventSystem* g_pGameEventSystem = nullptr ;
2223IVEngineServer2* engine = nullptr ;
2324ICvar* icvar = nullptr ;
2425
2526UtilsExtension g_Ext;
26- CUtlVector<FuncHookBase*> g_vecHooks;
2727CREATE_GLOBALVARS ();
2828
29- FuncHook<decltype (Hook_CCSPlayer_MovementServices_CheckJumpPre)> TCCSPlayer_MovementServices_CheckJumpPre (Hook_CCSPlayer_MovementServices_CheckJumpPre, " CCSPlayer_MovementServices_CheckJumpPre" );
29+ FunctionHook CCSPlayer_MovementServices_CheckJumpPre (" CCSPlayer_MovementServices_CheckJumpPre" , dyno::CallbackType::Pre, Hook_CCSPlayer_MovementServices_CheckJumpPre, " pp" , ' v' );
30+ FunctionHook CCSPlayer_MovementServices_CheckJumpPost (" CCSPlayer_MovementServices_CheckJumpPre" , dyno::CallbackType::Post, Hook_CCSPlayer_MovementServices_CheckJumpPre, " pp" , ' v' );
3031
3132ConVar* autobunnyhoppingcvar = nullptr ;
3233
@@ -37,11 +38,8 @@ ConVar* autobunnyhoppingcvar = nullptr;
3738EXT_EXPOSE (g_Ext);
3839bool UtilsExtension::Load (std::string& error, SourceHook::ISourceHook* SHPtr, ISmmAPI* ismm, bool late)
3940{
40- SAVE_GLOBALVARS ();
41- if (!InitializeHooks ()) {
42- error = " Failed to initialize hooks." ;
43- return false ;
44- }
41+ g_SHPtr = SHPtr;
42+ g_SMAPI = ismm;
4543
4644 GET_IFACE_CURRENT (GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
4745 GET_IFACE_CURRENT (GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
@@ -59,18 +57,18 @@ bool UtilsExtension::Load(std::string& error, SourceHook::ISourceHook* SHPtr, IS
5957
6058int UtilsExtension::LoadEventsFromFile (const char * filePath, bool searchAll)
6159{
62- if (!g_gameEventManager) {
60+ if (!g_gameEventManager) {
6361 g_gameEventManager = META_IFACEPTR (IGameEventManager2);
6462 }
6563
6664 RETURN_META_VALUE (MRES_IGNORED, 0 );
6765}
6866
69- extern uint64_t bhop_state;
67+ uint64_t bhop_state = 0 ;
7068
71- void UtilsExtension::Hook_ClientDisconnect ( CPlayerSlot slot, ENetworkDisconnectionReason reason, const char * pszName, uint64 xuid, const char *pszNetworkID )
69+ void UtilsExtension::Hook_ClientDisconnect (CPlayerSlot slot, ENetworkDisconnectionReason reason, const char * pszName, uint64 xuid, const char * pszNetworkID )
7270{
73- if ((bhop_state & (1ULL << slot.Get ())) != 0 ) bhop_state &= ~(1ULL << slot.Get ());
71+ if ((bhop_state & (1ULL << slot.Get ())) != 0 ) bhop_state &= ~(1ULL << slot.Get ());
7472}
7573
7674ConVar* FetchCVar (std::string cvarname)
@@ -85,8 +83,10 @@ ConVar* FetchCVar(std::string cvarname)
8583 return icvar->GetConVar (cvarHandle);
8684}
8785
88- void Hook_CCSPlayer_MovementServices_CheckJumpPre (void * services, void * movementData )
86+ dyno::ReturnAction Hook_CCSPlayer_MovementServices_CheckJumpPre (dyno::CallbackType cbType, dyno::IHook& hook )
8987{
88+ void * services = hook.getArgument <void *>(0 );
89+
9090 if (autobunnyhoppingcvar == nullptr )
9191 autobunnyhoppingcvar = FetchCVar (" sv_autobunnyhopping" );
9292
@@ -96,25 +96,20 @@ void Hook_CCSPlayer_MovementServices_CheckJumpPre(void* services, void* movement
9696 {
9797 CHandle<CEntityInstance> controller = SDKGetProp<CHandle<CEntityInstance>>(((CPlayer_MovementServices*)services)->m_pPawn , " CBasePlayerPawn" , " m_hController" );
9898 int pid = controller.GetEntryIndex () - 1 ;
99- if ((bhop_state & (1ULL << pid)) != 0 ) {
100- autobunnyhopping = true ;
101-
102- TCCSPlayer_MovementServices_CheckJumpPre (services, movementData);
103-
104- autobunnyhopping = false ;
105- return ;
99+ if ((bhop_state & (1ULL << pid)) != 0 ) {
100+ autobunnyhopping = (cbType == dyno::CallbackType::Pre);
101+ return dyno::ReturnAction::Ignored;
106102 }
107103 }
108104
109- TCCSPlayer_MovementServices_CheckJumpPre (services, movementData) ;
105+ return dyno::ReturnAction::Ignored ;
110106}
111107
112108bool UtilsExtension::Unload (std::string& error)
113109{
114110 SH_REMOVE_HOOK_ID (loadEventFromFileHookID);
115111 SH_REMOVE_HOOK_MEMFUNC (IServerGameClients, ClientDisconnect, gameclients, this , &UtilsExtension::Hook_ClientDisconnect, true );
116112
117- UnloadHooks ();
118113 return true ;
119114}
120115
@@ -130,25 +125,73 @@ void UtilsExtension::AllPluginsLoaded()
130125
131126bool UtilsExtension::OnPluginLoad (std::string pluginName, void * pluginState, PluginKind_t kind, std::string& error)
132127{
133- EContext* state = (EContext*)pluginState;
128+ EContext* ctx = (EContext*)pluginState;
129+
130+ ADD_CLASS (" PlayerUtils" );
131+
132+ #ifndef _WIN32
133+ ADD_CLASS_FUNCTION (" PlayerUtils" , " SetBunnyhop" , [](FunctionContext* context, ClassData* data) -> void {
134+ int playerid = context->GetArgumentOr <int >(0 , -1 );
135+ bool state = context->GetArgumentOr <bool >(1 , false );
136+
137+ if (state == true ) bhop_state |= (1ULL << playerid);
138+ else bhop_state &= ~(1ULL << playerid);
139+
140+ INetworkMessageInternal* netmsg = g_pNetworkMessages->FindNetworkMessagePartial (" SetConVar" );
141+ auto msg = netmsg->AllocateMessage ()->ToPB <CNETMsg_SetConVar>();
142+ CMsg_CVars_CVar* cvar = msg->mutable_convars ()->add_cvars ();
143+ cvar->set_name (" sv_autobunnyhopping" );
144+ cvar->set_value (state == true ? " true" : " false" );
134145
135- BeginClass<PlayerUtils>(" PlayerUtils" , state)
136- .addConstructor <std::string>()
137- .addFunction (" SetBunnyhop" , &PlayerUtils::SetBunnyhop)
138- .addFunction (" GetBunnyhop" , &PlayerUtils::GetBunnyhop)
139- .addFunction (" IsListeningToGameEvent" , &PlayerUtils::IsListeningToGameEvent)
140- .endClass ();
146+ CSingleRecipientFilter filter (playerid);
147+ g_pGameEventSystem->PostEventAbstract (-1 , false , &filter, netmsg, msg, 0 );
141148
142- GetGlobalNamespace (state).addConstant (" playerutils" , PlayerUtils (pluginName));
149+ delete msg;
150+ });
151+ #else
152+ ADD_CLASS_FUNCTION (" PlayerUtils" , " SetBunnyhop" , [](FunctionContext* context, ClassData* data) -> void {
153+ int playerid = context->GetArgumentOr <int >(0 , -1 );
154+ bool state = context->GetArgumentOr <bool >(1 , false );
155+
156+ if (state == true ) bhop_state |= (1ULL << playerid);
157+ else bhop_state &= ~(1ULL << playerid);
158+
159+ INetworkMessageInternal* netmsg = g_pNetworkMessages->FindNetworkMessagePartial (" SetConVar" );
160+ auto msg = netmsg->AllocateMessage ()->ToPB <CNETMsg_SetConVar>();
161+ CMsg_CVars_CVar* cvar = msg->mutable_convars ()->add_cvars ();
162+ cvar->set_name (" sv_autobunnyhopping" );
163+ cvar->set_value (state == true ? " true" : " false" );
164+
165+ CSingleRecipientFilter filter (playerid);
166+ g_pGameEventSystem->PostEventAbstract (-1 , false , &filter, netmsg, msg, 0 );
167+ });
168+ #endif
169+
170+ ADD_CLASS_FUNCTION (" PlayerUtils" , " IsListeningToGameEvent" , [](FunctionContext* context, ClassData* data) -> void {
171+ int playerid = context->GetArgumentOr <int >(0 , -1 );
172+ std::string game_event = context->GetArgumentOr <std::string>(1 , " " );
173+
174+ void * getListener = GetSignature (" LegacyGameEventListener" );
175+ if (!getListener) return context->SetReturn (false );
176+
177+ IGameEventListener2* playerListener = reinterpret_cast <IGameEventListener2 * (*)(int )>(getListener)(playerid);
178+ if (!playerListener) return context->SetReturn (false );
179+
180+ return context->SetReturn (g_gameEventManager->FindListener (playerListener, game_event.c_str ()));
181+ });
182+
183+ ADD_CLASS_FUNCTION (" PlayerUtils" , " GetBunnyhop" , [](FunctionContext* context, ClassData* data) -> void {
184+ int playerid = context->GetArgumentOr <int >(0 , -1 );
185+ context->SetReturn (((bhop_state & (1ULL << playerid)) != 0 ));
186+ });
187+
188+ ADD_VARIABLE (" _G" , " playerutils" , MAKE_CLASS_INSTANCE_CTX (ctx, " PlayerUtils" , {}));
143189
144190 return true ;
145191}
146192
147193bool UtilsExtension::OnPluginUnload (std::string pluginName, void * pluginState, PluginKind_t kind, std::string& error)
148194{
149- EContext* state = (EContext*)pluginState;
150-
151- GetGlobalNamespace (state).addConstant (" playerutils" , nullptr );
152195 return true ;
153196}
154197
0 commit comments