From ca11b4355b33a3eb66997e23b83434a9753ccc14 Mon Sep 17 00:00:00 2001 From: Jenny White Date: Sat, 28 Apr 2018 23:35:42 +0300 Subject: [PATCH] WIP hooks refactor --- include/common.hpp | 2 +- include/hooks/CMakeLists.txt | 9 +- include/hooks/CreateMove.hpp | 13 --- include/hooks/HookedMethods.hpp | 151 ++++++++++++++++++++++++++++++++ include/hooks/PaintTraverse.hpp | 15 ---- include/hooks/hookedmethods.hpp | 73 --------------- include/hooks/others.hpp | 63 ------------- src/hooks/sdl.cpp | 2 +- 8 files changed, 154 insertions(+), 174 deletions(-) delete mode 100755 include/hooks/CreateMove.hpp create mode 100644 include/hooks/HookedMethods.hpp delete mode 100755 include/hooks/PaintTraverse.hpp delete mode 100644 include/hooks/hookedmethods.hpp delete mode 100755 include/hooks/others.hpp diff --git a/include/common.hpp b/include/common.hpp index 0df4b0f6..d76b439c 100755 --- a/include/common.hpp +++ b/include/common.hpp @@ -94,7 +94,7 @@ #include "textfile.hpp" #include "ipc.hpp" #include "tfmm.hpp" -#include "hooks/hookedmethods.hpp" +#include "hooks/HookedMethods.hpp" #include "classinfo/classinfo.hpp" #include "votelogger.hpp" #include "crits.hpp" diff --git a/include/hooks/CMakeLists.txt b/include/hooks/CMakeLists.txt index cb48678f..2151284f 100644 --- a/include/hooks/CMakeLists.txt +++ b/include/hooks/CMakeLists.txt @@ -1,11 +1,4 @@ target_sources(cathook PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/CreateMove.hpp" - "${CMAKE_CURRENT_LIST_DIR}/hookedmethods.hpp" - "${CMAKE_CURRENT_LIST_DIR}/others.hpp") - -if(EnableVisuals) - target_sources(cathook PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/PaintTraverse.hpp") -endif() + "${CMAKE_CURRENT_LIST_DIR}/HookedMethods.hpp") target_include_directories(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}") \ No newline at end of file diff --git a/include/hooks/CreateMove.hpp b/include/hooks/CreateMove.hpp deleted file mode 100755 index b5a13f77..00000000 --- a/include/hooks/CreateMove.hpp +++ /dev/null @@ -1,13 +0,0 @@ -/* - * CreateMove.h - * - * Created on: Jan 8, 2017 - * Author: nullifiedcat - */ - -#pragma once - -class CUserCmd; - -extern bool *bSendPackets; -bool CreateMove_hook(void *, float, CUserCmd *); diff --git a/include/hooks/HookedMethods.hpp b/include/hooks/HookedMethods.hpp new file mode 100644 index 00000000..2e3193e9 --- /dev/null +++ b/include/hooks/HookedMethods.hpp @@ -0,0 +1,151 @@ + +/* + Created by Jenny White on 28.04.18. + Copyright (c) 2018 nullworks. All rights reserved. +*/ + + +#pragma once + +#include "common.hpp" + +extern bool *bSendPackets; +extern CatVar no_zoom; +extern CatVar clean_screenshots; +extern CatVar disable_visuals; +extern CatVar disconnect_reason; +#if ENABLE_VISUALS +extern int spectator_target; +#endif + +#if ENABLE_VISUALS +union SDL_Event; +#endif + +namespace types +{ +// ClientMode +using CreateMove = bool(*)(void *, float, CUserCmd *); +using LevelInit = void(*)(void *, const char *); +using LevelShutdown = void(*)(void *); +// ClientMode + 4 +using FireGameEvent = void(*)(void *_this, IGameEvent *event); +// IBaseClient +using DispatchUserMessage = bool(*)(void *, int, bf_read &); +// IInput +using GetUserCmd = CUserCmd *(*)(IInput *, int); + +using CanPacket = bool(*)(void *); +using IN_KeyEvent = int(*)(void *, int, int, const char *); +using SendNetMsg = bool(*)(void *, INetMessage &, bool, bool); +using Shutdown = void(*)(void *, const char *); +using BeginFrame = void(*)(IStudioRender *); +using CanInspect = bool(*)(IClientEntity *); +using GetClientName = const char *(*)(CBaseClientState *); +using ProcessSetConVar = bool(*)(CBaseClientState *, NET_SetConVar *); +using ProcessGetCvarValue = bool(*)(CBaseClientState *, SVC_GetCvarValue *); +// ISteamFriends +using GetFriendPersonaName = const char *(*)(ISteamFriends *, CSteamID); + +#if ENABLE_VISUALS +// ClientMode +using OverrideView = void(*)(void *, CViewSetup *); +// IEngineVGui +using Paint = void(*)(IEngineVGui *, PaintMode_t); +//IVModelRender +using DrawModelExecute = void(*)(IVModelRender *, const DrawModelState_t &, + const ModelRenderInfo_t &, matrix3x4_t *); +// IBaseClient +using FrameStageNotify = void(*)(void *, int); + +using PaintTraverse = void(*)(void *, unsigned int, bool, bool); +// SDL +using SDL_GL_SwapWindow = void(*)(SDL_Window *window); +using SDL_PollEvent = int(*)(SDL_Event *event); +// Manual +using RandomInt = int(*)(void *, int, int); +#endif +} + +namespace methods +{ +bool CreateMove(void *, float, CUserCmd *); +void PaintTraverse(void *, unsigned int, bool, bool); +const char *GetClientName(CBaseClientState *_this); +bool ProcessSetConVar(CBaseClientState *_this, NET_SetConVar *msg); +bool ProcessGetCvarValue(CBaseClientState *_this, SVC_GetCvarValue *msg); +const char *GetFriendPersonaName(ISteamFriends *_this, CSteamID steamID); +void FireGameEvent(void *_this, IGameEvent *event); +CUserCmd *GetUserCmd(IInput *, int); +void DrawModelExecute(IVModelRender *_this, const DrawModelState_t &state, + const ModelRenderInfo_t &info, matrix3x4_t *matrix); +bool CanPacket(void *); +int IN_KeyEvent(void *, int, int, const char *); +bool SendNetMsg(void *, INetMessage &, bool, bool); +void Shutdown(void *, const char *); +void OverrideView(void *, CViewSetup *); +bool DispatchUserMessage(void *, int, bf_read &); +void FrameStageNotify(void *, int); +void LevelInit(void *, const char *); +void LevelShutdown(void *); +int RandomInt(void *, int, int); +int SDL_PollEvent(SDL_Event *event); +void SDL_GL_SwapWindow(SDL_Window *window); +void Paint(IEngineVGui *_this, PaintMode_t mode); + +} + + + +// typedef void(*CInput__CreateMove_t)(void*, int, float, bool); +// void CInput__CreateMove_hook(void*, int sequence_number, float +// input_sample_frametime, bool active); + + +#if ENABLE_VISUALS + +/* SDL HOOKS */ +union SDL_Event; +class SDL_Window; + +extern SDL_Window *sdl_current_window; + + + +void DoSDLHooking(); +void DoSDLUnhooking(); +#endif + + +// TODO! +#if 0 + +#if ENABLE_NULL_GRAPHICS +typedef ITexture *(*FindTexture_t)(void *, const char *, const char *, bool, + int); +typedef IMaterial *(*FindMaterialEx_t)(void *, const char *, const char *, int, + bool, const char *); +typedef IMaterial *(*FindMaterial_t)(void *, const char *, const char *, bool, + const char *); + +/* 70 */ void ReloadTextures_null_hook(void *this_); +/* 71 */ void ReloadMaterials_null_hook(void *this_, const char *pSubString); +/* 73 */ IMaterial *FindMaterial_null_hook(void *this_, + char const *pMaterialName, + const char *pTextureGroupName, + bool complain, + const char *pComplainPrefix); +/* 81 */ ITexture *FindTexture_null_hook(void *this_, char const *pTextureName, + const char *pTextureGroupName, + bool complain, + int nAdditionalCreationFlags); +/* 121 */ void ReloadFilesInList_null_hook(void *this_, + IFileList *pFilesToReload); +/* 123 */ IMaterial *FindMaterialEx_null_hook(void *this_, + char const *pMaterialName, + const char *pTextureGroupName, + int nContext, bool complain, + const char *pComplainPrefix); +#endif + +#endif \ No newline at end of file diff --git a/include/hooks/PaintTraverse.hpp b/include/hooks/PaintTraverse.hpp deleted file mode 100755 index 147ab016..00000000 --- a/include/hooks/PaintTraverse.hpp +++ /dev/null @@ -1,15 +0,0 @@ -/* - * PaintTraverse.h - * - * Created on: Jan 8, 2017 - * Author: nullifiedcat - */ - -#pragma once - -class CatVar; - -extern CatVar no_zoom; -extern CatVar clean_screenshots; -extern CatVar disable_visuals; -void PaintTraverse_hook(void *, unsigned int, bool, bool); diff --git a/include/hooks/hookedmethods.hpp b/include/hooks/hookedmethods.hpp deleted file mode 100644 index 15513884..00000000 --- a/include/hooks/hookedmethods.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * hooks.h - * - * Created on: Jan 8, 2017 - * Author: nullifiedcat - */ - -#pragma once - -#include "common.hpp" - -typedef bool (*CreateMove_t)(void *, float, CUserCmd *); -typedef void (*PaintTraverse_t)(void *, unsigned int, bool, bool); -typedef bool (*CanPacket_t)(void *); -typedef int (*IN_KeyEvent_t)(void *, int, int, const char *); -typedef bool (*SendNetMsg_t)(void *, INetMessage &, bool, bool); -typedef void (*Shutdown_t)(void *, const char *); -typedef void (*OverrideView_t)(void *, CViewSetup *); -typedef bool (*DispatchUserMessage_t)(void *, int, bf_read &); -typedef void (*FrameStageNotify_t)(void *, int); -typedef void (*LevelInit_t)(void *, const char *); -typedef void (*LevelShutdown_t)(void *); - -typedef void (*BeginFrame_t)(IStudioRender *); -typedef bool (*CanInspect_t)(IClientEntity *); -typedef void (*DrawModelExecute_t)(IVModelRender *, const DrawModelState_t &, - const ModelRenderInfo_t &, matrix3x4_t *); -typedef CUserCmd *(*GetUserCmd_t)(IInput *, int); -typedef const char *(*GetClientName_t)(CBaseClientState *); -typedef bool (*ProcessSetConVar_t)(CBaseClientState *, NET_SetConVar *); -typedef bool (*ProcessGetCvarValue_t)(CBaseClientState *, SVC_GetCvarValue *); -typedef void (*Paint_t)(IEngineVGui *, PaintMode_t); - -typedef int (*RandomInt_t)(void *, int, int); - -const char *GetClientName_hook(CBaseClientState *_this); -bool ProcessSetConVar_hook(CBaseClientState *_this, NET_SetConVar *msg); -bool ProcessGetCvarValue_hook(CBaseClientState *_this, SVC_GetCvarValue *msg); -// typedef void(*CInput__CreateMove_t)(void*, int, float, bool); -// void CInput__CreateMove_hook(void*, int sequence_number, float -// input_sample_frametime, bool active); -typedef const char *(*GetFriendPersonaName_t)(ISteamFriends *, CSteamID); -const char *GetFriendPersonaName_hook(ISteamFriends *_this, CSteamID steamID); - -typedef void (*FireGameEvent_t)(void *_this, IGameEvent *event); -void FireGameEvent_hook(void *_this, IGameEvent *event); - -CUserCmd *GetUserCmd_hook(IInput *, int); -void DrawModelExecute_hook(IVModelRender *_this, const DrawModelState_t &state, - const ModelRenderInfo_t &info, matrix3x4_t *matrix); - -#if ENABLE_VISUALS -void Paint_hook(IEngineVGui *_this, PaintMode_t mode); - -/* SDL HOOKS */ -union SDL_Event; -class SDL_Window; - -extern SDL_Window *sdl_current_window; - -typedef int (*SDL_PollEvent_t)(SDL_Event *event); -typedef void (*SDL_GL_SwapWindow_t)(SDL_Window *window); - -int SDL_PollEvent_hook(SDL_Event *event); -void SDL_GL_SwapWindow_hook(SDL_Window *window); - -void DoSDLHooking(); -void DoSDLUnhooking(); -#endif - -#include "CreateMove.hpp" -#include "PaintTraverse.hpp" -#include "others.hpp" diff --git a/include/hooks/others.hpp b/include/hooks/others.hpp deleted file mode 100755 index 4f284fc4..00000000 --- a/include/hooks/others.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * others.h - * - * Created on: Jan 8, 2017 - * Author: nullifiedcat - */ - -#pragma once - -#include "config.h" - -class INetMessage; -class CViewSetup; -class bf_read; -class SDL_Window; -class CatVar; - -extern CatVar disconnect_reason; -#if ENABLE_VISUALS -extern int spectator_target; -#endif - -bool CanPacket_hook(void *); -int IN_KeyEvent_hook(void *, int, int, const char *); -bool SendNetMsg_hook(void *, INetMessage &, bool, bool); -void Shutdown_hook(void *, const char *); -void OverrideView_hook(void *, CViewSetup *); -bool DispatchUserMessage_hook(void *, int, bf_read &); -void FrameStageNotify_hook(void *, int); -void LevelInit_hook(void *, const char *); -void LevelShutdown_hook(void *); -int RandomInt_hook(void *, int, int); - -#if ENABLE_NULL_GRAPHICS -typedef ITexture *(*FindTexture_t)(void *, const char *, const char *, bool, - int); -typedef IMaterial *(*FindMaterialEx_t)(void *, const char *, const char *, int, - bool, const char *); -typedef IMaterial *(*FindMaterial_t)(void *, const char *, const char *, bool, - const char *); - -/* 70 */ void ReloadTextures_null_hook(void *this_); -/* 71 */ void ReloadMaterials_null_hook(void *this_, const char *pSubString); -/* 73 */ IMaterial *FindMaterial_null_hook(void *this_, - char const *pMaterialName, - const char *pTextureGroupName, - bool complain, - const char *pComplainPrefix); -/* 81 */ ITexture *FindTexture_null_hook(void *this_, char const *pTextureName, - const char *pTextureGroupName, - bool complain, - int nAdditionalCreationFlags); -/* 121 */ void ReloadFilesInList_null_hook(void *this_, - IFileList *pFilesToReload); -/* 123 */ IMaterial *FindMaterialEx_null_hook(void *this_, - char const *pMaterialName, - const char *pTextureGroupName, - int nContext, bool complain, - const char *pComplainPrefix); -#endif - -// extern unsigned int* swapwindow_ptr; -// extern unsigned int swapwindow_orig; diff --git a/src/hooks/sdl.cpp b/src/hooks/sdl.cpp index 092e7ec6..382aedd6 100755 --- a/src/hooks/sdl.cpp +++ b/src/hooks/sdl.cpp @@ -7,7 +7,7 @@ #include "common.hpp" -#include "hooks/hookedmethods.hpp" +#include "hooks/HookedMethods.hpp" #include "hack.hpp" #include