format + 2 more hooks

This commit is contained in:
Jenny White 2018-04-29 08:41:38 +03:00
parent 6303ca8b6b
commit 9285fdc28e
30 changed files with 129 additions and 105 deletions

5
include/hooks.hpp Executable file → Normal file
View File

@ -37,10 +37,10 @@ public:
~VMTHook();
void Set(ptr_t inst, uint32_t offset = 0);
void Release();
template<typename T>
template <typename T>
inline void HookMethod(T func, uint32_t idx, T *backup)
{
HookMethod(ptr_t(func), idx, (ptr_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;
@ -69,4 +69,5 @@ extern VMTHook steamfriends;
extern VMTHook materialsystem;
extern VMTHook enginevgui;
extern VMTHook vstd;
extern VMTHook eventmanager2;
}

View File

@ -4,7 +4,6 @@
Copyright (c) 2018 nullworks. All rights reserved.
*/
#pragma once
#include "common.hpp"
@ -14,17 +13,27 @@ union SDL_Event;
struct SDL_Window;
#endif
#define DECLARE_HOOKED_METHOD(name, rtype, ...) \
namespace types { using name = rtype(*)(__VA_ARGS__); } \
namespace methods { rtype name(__VA_ARGS__); } \
namespace original { extern types::name name; }
#define DECLARE_HOOKED_METHOD(name, rtype, ...) \
namespace types \
{ \
using name = rtype (*)(__VA_ARGS__); \
} \
namespace methods \
{ \
rtype name(__VA_ARGS__); \
} \
namespace original \
{ \
extern types::name name; \
}
#define DEFINE_HOOKED_METHOD(name, rtype, ...) \
types::name original::name{ nullptr }; \
#define DEFINE_HOOKED_METHOD(name, rtype, ...) \
types::name original::name{ nullptr }; \
rtype name(__VA_ARGS__)
#define HOOK_ARGS(name) \
hooked_methods::methods::name, offsets::name(), &hooked_methods::original::name
#define HOOK_ARGS(name) \
hooked_methods::methods::name, offsets::name(), \
&hooked_methods::original::name
namespace hooked_methods
{
@ -36,40 +45,48 @@ DECLARE_HOOKED_METHOD(LevelShutdown, void, void *);
DECLARE_HOOKED_METHOD(FireGameEvent, void, void *, IGameEvent *);
// IBaseClient
DECLARE_HOOKED_METHOD(DispatchUserMessage, bool, void *, int, bf_read &);
DECLARE_HOOKED_METHOD(IN_KeyEvent, int, void *, int, ButtonCode_t, const char *);
DECLARE_HOOKED_METHOD(IN_KeyEvent, int, void *, int, ButtonCode_t,
const char *);
// IInput
DECLARE_HOOKED_METHOD(GetUserCmd, CUserCmd *, IInput *, int);
// INetChannel
DECLARE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *, INetMessage &, bool, bool);
DECLARE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *, INetMessage &, bool,
bool);
DECLARE_HOOKED_METHOD(CanPacket, bool, INetChannel *);
DECLARE_HOOKED_METHOD(Shutdown, void, INetChannel *, const char *);
// ISteamFriends
DECLARE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *, CSteamID);
DECLARE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *,
CSteamID);
// IEngineVGui
DECLARE_HOOKED_METHOD(Paint, void, IEngineVGui *, PaintMode_t);
// IGameEventManager2
DECLARE_HOOKED_METHOD(FireEvent, bool, IGameEventManager2 *, IGameEvent *,
bool);
DECLARE_HOOKED_METHOD(FireEventClientSide, bool, IGameEventManager2 *,
IGameEvent *);
#if ENABLE_VISUALS
// ClientMode
DECLARE_HOOKED_METHOD(OverrideView, void, void *, CViewSetup *);
// IVModelRender
DECLARE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *, const DrawModelState_t &,
const ModelRenderInfo_t &, matrix3x4_t *);
DECLARE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *,
const DrawModelState_t &, const ModelRenderInfo_t &,
matrix3x4_t *);
// IStudioRender
DECLARE_HOOKED_METHOD(BeginFrame, void, IStudioRender *);
// IBaseClient
DECLARE_HOOKED_METHOD(FrameStageNotify, void, void *, ClientFrameStage_t);
// vgui::IPanel
DECLARE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *, unsigned int, bool, bool);
DECLARE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *, unsigned int, bool,
bool);
// SDL
DECLARE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *);
DECLARE_HOOKED_METHOD(SDL_PollEvent, int, SDL_Event *);
// IUniformRandomStream
DECLARE_HOOKED_METHOD(RandomInt, int, IUniformRandomStream *, int, int);
#endif
}
// TODO
// wontfix.club
#if 0

View File

@ -6,7 +6,7 @@
#include "MiscTemporary.hpp"
CatVar minigun_jump(CV_SWITCH, "minigun_jump", "0", "TF2C minigun jump",
"Allows jumping while shooting with minigun");
"Allows jumping while shooting with minigun");
CatVar jointeam(CV_SWITCH, "fb_autoteam", "1",
"Joins player team automatically (NYI)");
@ -15,15 +15,14 @@ CatVar joinclass(CV_STRING, "fb_autoclass", "spy",
CatVar nolerp(CV_SWITCH, "nolerp", "0", "NoLerp mode (experimental)");
CatVar engine_pred(CV_SWITCH, "engine_prediction", "0",
"Engine Prediction");
CatVar engine_pred(CV_SWITCH, "engine_prediction", "0", "Engine Prediction");
CatVar debug_projectiles(CV_SWITCH, "debug_projectiles", "0",
"Debug Projectiles");
"Debug Projectiles");
CatVar fakelag_amount(CV_INT, "fakelag", "0", "Bad Fakelag");
CatVar serverlag_amount(
CV_INT, "serverlag", "0", "serverlag",
"Lag the server by spamming this many voicecommands per tick");
CV_INT, "serverlag", "0", "serverlag",
"Lag the server by spamming this many voicecommands per tick");
CatVar semiauto(CV_INT, "semiauto", "0", "Semiauto");
CatVar servercrash(CV_SWITCH, "servercrash", "0", "crash servers",
"Crash servers by spamming signon net messages");

View File

@ -288,12 +288,7 @@ free(logname);*/
InitNetVars();
g_pLocalPlayer = new LocalPlayer();
g_pPlayerResource = new TFPlayerResource();
#if ENABLE_VISUALS
hooks::panel.Set(g_IPanel);
hooks::panel.HookMethod(hooked_methods::methods::PaintTraverse,
offsets::PaintTraverse(), &hooked_methods::original::PaintTraverse);
hooks::panel.Apply();
#endif
uintptr_t *clientMode = 0;
// Bad way to get clientmode.
// FIXME [MP]?
@ -315,19 +310,47 @@ free(logname);*/
hooks::clientmode4.Set((void *) (clientMode), 4);
hooks::clientmode4.HookMethod(HOOK_ARGS(FireGameEvent));
hooks::clientmode4.Apply();
hooks::client.Set(g_IBaseClient);
hooks::client.Set(g_IBaseClient);
hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage);
#if ENABLE_VISUALS
hooks::client.HookMethod(HOOK_ARGS(FrameStageNotify));
hooks::client.HookMethod(HOOK_ARGS(IN_KeyEvent));
#endif
hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage);
hooks::client.Apply();
#if ENABLE_VISUALS
hooks::vstd.Set((void *) g_pUniformStream);
hooks::vstd.HookMethod(HOOK_ARGS(RandomInt));
hooks::vstd.Apply();
hooks::panel.Set(g_IPanel);
hooks::panel.HookMethod(hooked_methods::methods::PaintTraverse,
offsets::PaintTraverse(), &hooked_methods::original::PaintTraverse);
hooks::panel.Apply();
#endif
hooks::input.Set(g_IInput);
hooks::input.HookMethod(HOOK_ARGS(GetUserCmd));
hooks::input.Apply();
#if ENABLE_VISUALS
hooks::modelrender.Set(g_IVModelRender);
hooks::modelrender.HookMethod(HOOK_ARGS(DrawModelExecute));
hooks::modelrender.Apply();
#endif
hooks::enginevgui.Set(g_IEngineVGui);
hooks::enginevgui.HookMethod(HOOK_ARGS(Paint));
hooks::enginevgui.Apply();
hooks::eventmanager2.Set(g_IEventManager2);
hooks::eventmanager2.HookMethod(HOOK_ARGS(FireEvent));
hooks::eventmanager2.HookMethod(HOOK_ARGS(FireEventClientSide));
hooks::eventmanager2.Apply();
hooks::steamfriends.Set(g_ISteamFriends);
hooks::steamfriends.HookMethod(HOOK_ARGS(GetFriendPersonaName));
hooks::steamfriends.Apply();
#if ENABLE_NULL_GRAPHICS
g_IMaterialSystem->SetInStubMode(true);
IF_GAME(IsTF2())
@ -350,38 +373,6 @@ free(logname);*/
// hooks::materialsystem.HookMethod();
}
#endif
#if ENABLE_VISUALS
hooks::client.HookMethod(HOOK_ARGS(IN_KeyEvent));
#endif
hooks::client.Apply();
hooks::input.Set(g_IInput);
hooks::input.HookMethod(HOOK_ARGS(GetUserCmd));
hooks::input.Apply();
#ifndef HOOK_DME_DISABLED
#if ENABLE_VISUALS
hooks::modelrender.Set(g_IVModelRender);
hooks::modelrender.HookMethod(HOOK_ARGS(DrawModelExecute));
hooks::modelrender.Apply();
hooks::enginevgui.Set(g_IEngineVGui);
hooks::enginevgui.HookMethod(HOOK_ARGS(Paint));
hooks::enginevgui.Apply();
#endif
#endif
hooks::steamfriends.Set(g_ISteamFriends);
hooks::steamfriends.HookMethod(HOOK_ARGS(GetFriendPersonaName));
hooks::steamfriends.Apply();
// logging::Info("After hacking: %s", g_ISteamFriends->GetPersonaName());
// Sadly, it doesn't work as expected :(
/*hooks::hkBaseClientState = new hooks::VMTHook();
hooks::hkBaseClientState->Init((void*)g_IBaseClientState, 0);
hooks::hkBaseClientState->HookMethod((void*)GetClientName_hook,
hooks::offGetClientName); hooks::hkBaseClientState->Apply();*/
// hooks::hkBaseClientState8 = new hooks::VMTHook();
// hooks::hkBaseClientState8->Init((void*)g_IBaseClientState, 8);
// hooks::hkBaseClientState8->HookMethod((void*)ProcessSetConVar_hook,
// hooks::offProcessSetConVar);
// hooks::hkBaseClientState8->HookMethod((void*)ProcessGetCvarValue_hook,
// hooks::offProcessGetCvarValue); hooks::hkBaseClientState8->Apply();
// FIXME [MP]
hacks::shared::killsay::Init();

5
src/hacks/Killstreak.cpp Executable file → Normal file
View File

@ -137,11 +137,6 @@ bool FireEventClientSide(IGameEventManager2 *manager, IGameEvent *event)
void init()
{
hook.Set(g_IEventManager2, 0);
// hook.HookMethod(FireEvent_hook, offsets::FireEvent());
hook.HookMethod((void *) FireEventClientSide,
offsets::FireEventClientSide());
hook.Apply();
}
}
}

View File

@ -83,7 +83,7 @@ void VMTHook::HookMethod(ptr_t func, uint32_t idx, ptr_t *backup)
"Hooking method %d of vtable 0x%08x, replacing 0x%08x with 0x%08x", idx,
vtable_original, GetMethod(idx), func);
if (backup)
*backup = vtable_hooked[2 + idx];
*backup = vtable_hooked[2 + idx];
vtable_hooked[2 + idx] = func;
}
@ -109,4 +109,5 @@ VMTHook clientmode4{};
VMTHook materialsystem{};
VMTHook enginevgui{};
VMTHook vstd{};
VMTHook eventmanager2{};
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(CanPacket, bool, INetChannel *this_)
{
return original::CanPacket(this_);
}
}

View File

@ -15,11 +15,11 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, CUserCmd *cmd)
DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time,
CUserCmd *cmd)
{
return original::CreateMove(this_, input_sample_time, cmd);
}
}
class CMoveData;
@ -107,7 +107,6 @@ void End() {
}*/
}
bool CreateMove_hook(void *thisptr, float inputSample, CUserCmd *cmd)
{
uintptr_t **fp;

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void * this_, int type, bf_read &buffer)
DEFINE_HOOKED_METHOD(DispatchUserMessage, bool, void *this_, int type,
bf_read &buffer)
{
return original::DispatchUserMessage(this_, type, buffer);
}
}

16
src/hooks/FireEvent.cpp Normal file
View File

@ -0,0 +1,16 @@
/*
Created by Jenny White on 29.04.18.
Copyright (c) 2018 nullworks. All rights reserved.
*/
#include "HookedMethods.hpp"
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(FireEvent, bool, IGameEventManager2 *this_,
IGameEvent *event, bool no_broadcast)
{
return original::FireEvent(this_, event, no_broadcast);
}
}

View File

@ -0,0 +1,16 @@
/*
Created by Jenny White on 29.04.18.
Copyright (c) 2018 nullworks. All rights reserved.
*/
#include "HookedMethods.hpp"
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(FireEventClientSide, bool, IGameEventManager2 *this_,
IGameEvent *event)
{
return original::FireEventClientSide(this_, event);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(FireGameEvent, void, void *this_, IGameEvent *event)
{
return original::FireGameEvent(this_, event);
}
}

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *this_, CSteamID steam_id)
DEFINE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *this_,
CSteamID steam_id)
{
return original::GetFriendPersonaName(this_, steam_id);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(GetUserCmd, CUserCmd *, IInput *this_, int sequence_number)
{
return original::GetUserCmd(this_, sequence_number);
}
}

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(IN_KeyEvent, int, void *this_, int eventcode, ButtonCode_t keynum, const char *binding)
DEFINE_HOOKED_METHOD(IN_KeyEvent, int, void *this_, int eventcode,
ButtonCode_t keynum, const char *binding)
{
return original::IN_KeyEvent(this_, eventcode, keynum, binding);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(LevelInit, void, void *this_, const char *name)
{
return original::LevelInit(this_, name);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(LevelShutdown, void, void *this_)
{
return original::LevelShutdown(this_);
}
}

1
src/hooks/Paint.cpp Executable file → Normal file
View File

@ -16,7 +16,6 @@ DEFINE_HOOKED_METHOD(Paint, void, IEngineVGui *this_, PaintMode_t mode)
{
return original::Paint(this_, mode);
}
}
static CatVar cursor_fix_experimental(CV_SWITCH, "experimental_cursor_fix", "1",

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &message, bool force_reliable, bool voice)
DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &message,
bool force_reliable, bool voice)
{
return original::SendNetMsg(this_, message, force_reliable, voice);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(Shutdown, void, INetChannel *this_, const char *reason)
{
return original::Shutdown(this_, reason);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(BeginFrame, void, IStudioRender *this_)
{
return original::BeginFrame(this_);
}
}

View File

@ -8,10 +8,10 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *this_, const DrawModelState_t &state,
DEFINE_HOOKED_METHOD(DrawModelExecute, void, IVModelRender *this_,
const DrawModelState_t &state,
const ModelRenderInfo_t &info, matrix3x4_t *bone)
{
return original::DrawModelExecute(this_, state, info, bone);
}
}

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_, ClientFrameStage_t stage)
DEFINE_HOOKED_METHOD(FrameStageNotify, void, void *this_,
ClientFrameStage_t stage)
{
return original::FrameStageNotify(this_, stage);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(OverrideView, void, void *this_, CViewSetup *setup)
{
return original::OverrideView(this_, setup);
}
}

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_, unsigned int panel, bool force, bool allow_force)
DEFINE_HOOKED_METHOD(PaintTraverse, void, vgui::IPanel *this_,
unsigned int panel, bool force, bool allow_force)
{
return original::PaintTraverse(this_, panel, force, allow_force);
}
}

View File

@ -8,9 +8,9 @@
namespace hooked_methods
{
DEFINE_HOOKED_METHOD(RandomInt, int, IUniformRandomStream *this_, int min, int max)
DEFINE_HOOKED_METHOD(RandomInt, int, IUniformRandomStream *this_, int min,
int max)
{
return original::RandomInt(this_, min, max);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window)
{
return original::SDL_GL_SwapWindow(window);
}
}

View File

@ -12,5 +12,4 @@ DEFINE_HOOKED_METHOD(SDL_PollEvent, int, SDL_Event *event)
{
return original::SDL_PollEvent(event);
}
}

4
src/ipc.cpp Executable file → Normal file
View File

@ -261,8 +261,8 @@ 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, hooked_methods::methods::GetFriendPersonaName(g_ISteamFriends,
g_ISteamUser->GetSteamID()),
strncpy(data.name, hooked_methods::methods::GetFriendPersonaName(
g_ISteamFriends, g_ISteamUser->GetSteamID()),
sizeof(data.name));
}

View File

@ -46,8 +46,8 @@ re::CTFPartyClient::MutLocalGroupCriteria(re::CTFPartyClient *client)
{
typedef re::ITFGroupMatchCriteria *(*MutLocalGroupCriteria_t)(
re::CTFPartyClient *);
static uintptr_t addr = gSignatures.GetClientSignature(
"55 89 E5 8B 45 ? 8B 50 ? C6 80");
static uintptr_t addr =
gSignatures.GetClientSignature("55 89 E5 8B 45 ? 8B 50 ? C6 80");
static MutLocalGroupCriteria_t MutLocalGroupCriteria_fn =
MutLocalGroupCriteria_t(addr);