From 6303ca8b6b5967b15314b4f2fbf25ab289d7ffb1 Mon Sep 17 00:00:00 2001 From: Jenny White Date: Sun, 29 Apr 2018 08:31:25 +0300 Subject: [PATCH] HOOK_ARGS --- include/hooks.hpp | 5 ++++ include/hooks/HookedMethods.hpp | 3 +++ include/offsets.hpp | 4 ++++ src/hack.cpp | 41 +++++++++++++-------------------- src/ipc.cpp | 2 +- 5 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/hooks.hpp b/include/hooks.hpp index cf7a95e4..286aa2b1 100755 --- a/include/hooks.hpp +++ b/include/hooks.hpp @@ -37,6 +37,11 @@ public: ~VMTHook(); void Set(ptr_t inst, uint32_t offset = 0); void Release(); + template + inline void HookMethod(T func, uint32_t idx, T *backup) + { + HookMethod(ptr_t(func), idx, (ptr_t *)(backup)); + } void HookMethod(ptr_t func, uint32_t idx, ptr_t *backup); void *GetMethod(uint32_t idx) const; void Apply(); diff --git a/include/hooks/HookedMethods.hpp b/include/hooks/HookedMethods.hpp index c56efaaa..21ad0440 100644 --- a/include/hooks/HookedMethods.hpp +++ b/include/hooks/HookedMethods.hpp @@ -23,6 +23,9 @@ struct SDL_Window; types::name original::name{ nullptr }; \ rtype name(__VA_ARGS__) +#define HOOK_ARGS(name) \ + hooked_methods::methods::name, offsets::name(), &hooked_methods::original::name + namespace hooked_methods { // ClientMode diff --git a/include/offsets.hpp b/include/offsets.hpp index 8f78a6b7..36d86047 100755 --- a/include/offsets.hpp +++ b/include/offsets.hpp @@ -164,4 +164,8 @@ struct offsets { return PlatformOffset(2, undefined, undefined); } + static constexpr uint32_t Paint() + { + return PlatformOffset(14, undefined, undefined); + } }; diff --git a/src/hack.cpp b/src/hack.cpp index 6b3781ee..d45ff24a 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -290,8 +290,8 @@ free(logname);*/ g_pPlayerResource = new TFPlayerResource(); #if ENABLE_VISUALS hooks::panel.Set(g_IPanel); - hooks::panel.HookMethod((void *) PaintTraverse_hook, - offsets::PaintTraverse()); + hooks::panel.HookMethod(hooked_methods::methods::PaintTraverse, + offsets::PaintTraverse(), &hooked_methods::original::PaintTraverse); hooks::panel.Apply(); #endif uintptr_t *clientMode = 0; @@ -304,32 +304,27 @@ free(logname);*/ usleep(10000); } hooks::clientmode.Set((void *) clientMode); - hooks::clientmode.HookMethod((void *) CreateMove_hook, - offsets::CreateMove()); + hooks::clientmode.HookMethod(HOOK_ARGS(CreateMove)); #if ENABLE_VISUALS - hooks::clientmode.HookMethod((void *) OverrideView_hook, - offsets::OverrideView()); + hooks::clientmode.HookMethod(HOOK_ARGS(OverrideView)); #endif - hooks::clientmode.HookMethod((void *) LevelInit_hook, offsets::LevelInit()); - hooks::clientmode.HookMethod((void *) LevelShutdown_hook, - offsets::LevelShutdown()); + hooks::clientmode.HookMethod(HOOK_ARGS(LevelInit)); + hooks::clientmode.HookMethod(HOOK_ARGS(LevelShutdown)); hooks::clientmode.Apply(); + hooks::clientmode4.Set((void *) (clientMode), 4); - hooks::clientmode4.HookMethod((void *) FireGameEvent_hook, - offsets::FireGameEvent()); + hooks::clientmode4.HookMethod(HOOK_ARGS(FireGameEvent)); hooks::clientmode4.Apply(); hooks::client.Set(g_IBaseClient); #if ENABLE_VISUALS - hooks::client.HookMethod((void *) FrameStageNotify_hook, - offsets::FrameStageNotify()); + hooks::client.HookMethod(HOOK_ARGS(FrameStageNotify)); #endif - hooks::client.HookMethod((void *) DispatchUserMessage_hook, - offsets::DispatchUserMessage()); + hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage); #if ENABLE_VISUALS hooks::vstd.Set((void *) g_pUniformStream); - hooks::vstd.HookMethod((void *) RandomInt_hook, offsets::RandomInt()); + hooks::vstd.HookMethod(HOOK_ARGS(RandomInt)); hooks::vstd.Apply(); #endif @@ -356,28 +351,24 @@ free(logname);*/ } #endif #if ENABLE_VISUALS - hooks::client.HookMethod((void *) IN_KeyEvent_hook, offsets::IN_KeyEvent()); + hooks::client.HookMethod(HOOK_ARGS(IN_KeyEvent)); #endif hooks::client.Apply(); hooks::input.Set(g_IInput); - hooks::input.HookMethod((void *) GetUserCmd_hook, offsets::GetUserCmd()); + hooks::input.HookMethod(HOOK_ARGS(GetUserCmd)); hooks::input.Apply(); #ifndef HOOK_DME_DISABLED #if ENABLE_VISUALS hooks::modelrender.Set(g_IVModelRender); - hooks::modelrender.HookMethod((void *) DrawModelExecute_hook, - offsets::DrawModelExecute()); + hooks::modelrender.HookMethod(HOOK_ARGS(DrawModelExecute)); hooks::modelrender.Apply(); hooks::enginevgui.Set(g_IEngineVGui); - hooks::enginevgui.HookMethod( - (void *) Paint_hook, - offsets::PlatformOffset(14, offsets::undefined, offsets::undefined)); + hooks::enginevgui.HookMethod(HOOK_ARGS(Paint)); hooks::enginevgui.Apply(); #endif #endif hooks::steamfriends.Set(g_ISteamFriends); - hooks::steamfriends.HookMethod((void *) GetFriendPersonaName_hook, - offsets::GetFriendPersonaName()); + hooks::steamfriends.HookMethod(HOOK_ARGS(GetFriendPersonaName)); hooks::steamfriends.Apply(); // logging::Info("After hacking: %s", g_ISteamFriends->GetPersonaName()); // Sadly, it doesn't work as expected :( diff --git a/src/ipc.cpp b/src/ipc.cpp index b5d02af7..c89abf2f 100755 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -261,7 +261,7 @@ void StoreClientData() user_data_s &data = peer->memory->peer_user_data[peer->client_id]; data.friendid = g_ISteamUser->GetSteamID().GetAccountID(); data.ts_injected = time_injected; - strncpy(data.name, GetFriendPersonaName_hook(g_ISteamFriends, + strncpy(data.name, hooked_methods::methods::GetFriendPersonaName(g_ISteamFriends, g_ISteamUser->GetSteamID()), sizeof(data.name)); }