From f996c7777c2a051b10623a0260b826b3ff9ad5af Mon Sep 17 00:00:00 2001 From: Jenny White Date: Sun, 29 Apr 2018 10:43:11 +0300 Subject: [PATCH] sdl_hooks, (compiles) --- include/MiscTemporary.hpp | 18 ++-- include/chatlog.hpp | 2 + include/visual/CMakeLists.txt | 3 +- include/visual/SDLHooks.hpp | 18 ++++ src/MiscTemporary.cpp | 7 +- src/hack.cpp | 7 +- src/hooks/CMakeLists.txt | 2 - src/hooks/CreateMove.cpp | 126 ++++++++++++------------- src/hooks/DispatchUserMessage.cpp | 4 +- src/hooks/GetFriendPersonaName.cpp | 106 +++++++++++++++++++-- src/hooks/PaintTraverse.cpp | 19 ---- src/hooks/SendNetMsg.cpp | 15 ++- src/hooks/Shutdown.cpp | 2 + src/hooks/others.cpp | 107 +-------------------- src/hooks/sdl.cpp | 94 ------------------ src/hooks/visual/SDL_GL_SwapWindow.cpp | 11 ++- src/visual/CMakeLists.txt | 3 +- src/visual/EffectChams.cpp | 1 + src/visual/EffectGlow.cpp | 1 + src/visual/SDLHooks.cpp | 33 +++++++ src/visual/drawex.cpp | 7 +- src/visual/drawmgr.cpp | 1 + 22 files changed, 271 insertions(+), 316 deletions(-) create mode 100644 include/visual/SDLHooks.hpp delete mode 100644 src/hooks/PaintTraverse.cpp delete mode 100755 src/hooks/sdl.cpp create mode 100644 src/visual/SDLHooks.cpp diff --git a/include/MiscTemporary.hpp b/include/MiscTemporary.hpp index 72b152fd..f36c6301 100644 --- a/include/MiscTemporary.hpp +++ b/include/MiscTemporary.hpp @@ -14,12 +14,16 @@ extern CatVar no_zoom; extern CatVar clean_screenshots; extern CatVar disable_visuals; extern CatVar disconnect_reason; - +extern CatVar crypt_chat; +extern CatVar minigun_jump; +extern CatVar nolerp; +extern CatVar joinclass; +extern CatVar jointeam; +extern CatVar fakelag_amount; +extern CatVar serverlag_amount; +extern CatVar debug_projectiles; +extern CatVar semiauto; +extern CatVar engine_pred; #if ENABLE_VISUALS extern int spectator_target; -#endif - -extern SDL_Window *sdl_current_window; - -void DoSDLHooking(); -void DoSDLUnhooking(); \ No newline at end of file +#endif \ No newline at end of file diff --git a/include/chatlog.hpp b/include/chatlog.hpp index 3ef6295d..d39c7e8d 100755 --- a/include/chatlog.hpp +++ b/include/chatlog.hpp @@ -7,6 +7,8 @@ #pragma once +#include + namespace chatlog { diff --git a/include/visual/CMakeLists.txt b/include/visual/CMakeLists.txt index ef6ce432..33ff88bf 100644 --- a/include/visual/CMakeLists.txt +++ b/include/visual/CMakeLists.txt @@ -6,7 +6,8 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/drawmgr.hpp" "${CMAKE_CURRENT_LIST_DIR}/EffectChams.hpp" "${CMAKE_CURRENT_LIST_DIR}/EffectGlow.hpp" - "${CMAKE_CURRENT_LIST_DIR}/fidgetspinner.hpp") + "${CMAKE_CURRENT_LIST_DIR}/fidgetspinner.hpp" + "${CMAKE_CURRENT_LIST_DIR}/SDLHooks.hpp") if(EnableGUI) add_subdirectory(menu) diff --git a/include/visual/SDLHooks.hpp b/include/visual/SDLHooks.hpp new file mode 100644 index 00000000..662fdc08 --- /dev/null +++ b/include/visual/SDLHooks.hpp @@ -0,0 +1,18 @@ +/* + Created by Jenny White on 29.04.18. + Copyright (c) 2018 nullworks. All rights reserved. +*/ + +#pragma once + +struct SDL_Window; + +namespace sdl_hooks +{ + +extern SDL_Window *window; + +void applySdlHooks(); +void cleanSdlHooks(); + +} \ No newline at end of file diff --git a/src/MiscTemporary.cpp b/src/MiscTemporary.cpp index d8ab9f7c..a794fc5b 100644 --- a/src/MiscTemporary.cpp +++ b/src/MiscTemporary.cpp @@ -26,4 +26,9 @@ CatVar serverlag_amount( CatVar semiauto(CV_INT, "semiauto", "0", "Semiauto"); CatVar servercrash(CV_SWITCH, "servercrash", "0", "crash servers", "Crash servers by spamming signon net messages"); -bool *bSendPackets; \ No newline at end of file +bool *bSendPackets; + + +CatVar crypt_chat( + CV_SWITCH, "chat_crypto", "1", "Crypto chat", + "Start message with !! and it will be only visible to cathook users"); \ No newline at end of file diff --git a/src/hack.cpp b/src/hack.cpp index bd96633d..2cba698a 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -5,6 +5,7 @@ * Author: nullifiedcat */ +#include #include "hack.hpp" #include "common.hpp" @@ -312,7 +313,7 @@ free(logname);*/ hooks::clientmode4.Apply(); hooks::client.Set(g_IBaseClient); - hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage); + hooks::client.HookMethod(HOOK_ARGS(DispatchUserMessage)); #if ENABLE_VISUALS hooks::client.HookMethod(HOOK_ARGS(FrameStageNotify)); hooks::client.HookMethod(HOOK_ARGS(IN_KeyEvent)); @@ -403,7 +404,7 @@ free(logname);*/ } logging::Info("SSE enabled.."); #endif - DoSDLHooking(); + sdl_hooks::applySdlHooks(); logging::Info("SDL hooking done"); g_IGameEventManager->AddListener(&adv_event_listener, false); @@ -453,7 +454,7 @@ void hack::Shutdown() hack::shutdown = true; playerlist::Save(); #if ENABLE_VISUALS - DoSDLUnhooking(); + sdl_hooks::cleanSdlHooks(); #endif logging::Info("Unregistering convars.."); ConVar_Unregister(); diff --git a/src/hooks/CMakeLists.txt b/src/hooks/CMakeLists.txt index 8be467e8..143562dc 100644 --- a/src/hooks/CMakeLists.txt +++ b/src/hooks/CMakeLists.txt @@ -10,8 +10,6 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/nographics.cpp" "${CMAKE_CURRENT_LIST_DIR}/others.cpp" "${CMAKE_CURRENT_LIST_DIR}/Paint.cpp" - "${CMAKE_CURRENT_LIST_DIR}/PaintTraverse.cpp" - "${CMAKE_CURRENT_LIST_DIR}/sdl.cpp" "${CMAKE_CURRENT_LIST_DIR}/SendNetMsg.cpp" "${CMAKE_CURRENT_LIST_DIR}/Shutdown.cpp") diff --git a/src/hooks/CreateMove.cpp b/src/hooks/CreateMove.cpp index 179afc12..d496cb88 100644 --- a/src/hooks/CreateMove.cpp +++ b/src/hooks/CreateMove.cpp @@ -7,11 +7,73 @@ #include "common.hpp" #include "hack.hpp" +#include "MiscTemporary.hpp" #include #include "HookedMethods.hpp" + +class CMoveData; +namespace engine_prediction +{ + +void RunEnginePrediction(IClientEntity *ent, CUserCmd *ucmd) +{ + if (!ent) + return; + + typedef void (*SetupMoveFn)(IPrediction *, IClientEntity *, CUserCmd *, + class IMoveHelper *, CMoveData *); + typedef void (*FinishMoveFn)(IPrediction *, IClientEntity *, CUserCmd *, + CMoveData *); + + void **predictionVtable = *((void ***) g_IPrediction); + SetupMoveFn oSetupMove = + (SetupMoveFn) (*(unsigned *) (predictionVtable + 19)); + FinishMoveFn oFinishMove = + (FinishMoveFn) (*(unsigned *) (predictionVtable + 20)); + + // CMoveData *pMoveData = (CMoveData*)(sharedobj::client->lmap->l_addr + + // 0x1F69C0C); CMoveData movedata {}; + char object[165]; + CMoveData *pMoveData = (CMoveData *) object; + + float frameTime = g_GlobalVars->frametime; + float curTime = g_GlobalVars->curtime; + + CUserCmd defaultCmd; + if (ucmd == NULL) + { + ucmd = &defaultCmd; + } + + NET_VAR(ent, 4188, CUserCmd *) = ucmd; + + g_GlobalVars->curtime = + g_GlobalVars->interval_per_tick * NET_INT(ent, netvar.nTickBase); + g_GlobalVars->frametime = g_GlobalVars->interval_per_tick; + + *g_PredictionRandomSeed = + MD5_PseudoRandom(g_pUserCmd->command_number) & 0x7FFFFFFF; + g_IGameMovement->StartTrackPredictionErrors( + reinterpret_cast(ent)); + oSetupMove(g_IPrediction, ent, ucmd, NULL, pMoveData); + g_IGameMovement->ProcessMovement(reinterpret_cast(ent), + pMoveData); + oFinishMove(g_IPrediction, ent, ucmd, pMoveData); + g_IGameMovement->FinishTrackPredictionErrors( + reinterpret_cast(ent)); + + NET_VAR(ent, 4188, CUserCmd *) = nullptr; + + g_GlobalVars->frametime = frameTime; + g_GlobalVars->curtime = curTime; + + return; +} +} + namespace hooked_methods { @@ -440,64 +502,6 @@ DEFINE_HOOKED_METHOD(CreateMove, bool, void *this_, float input_sample_time, } } -class CMoveData; -namespace engine_prediction -{ - -void RunEnginePrediction(IClientEntity *ent, CUserCmd *ucmd) -{ - if (!ent) - return; - - typedef void (*SetupMoveFn)(IPrediction *, IClientEntity *, CUserCmd *, - class IMoveHelper *, CMoveData *); - typedef void (*FinishMoveFn)(IPrediction *, IClientEntity *, CUserCmd *, - CMoveData *); - - void **predictionVtable = *((void ***) g_IPrediction); - SetupMoveFn oSetupMove = - (SetupMoveFn)(*(unsigned *) (predictionVtable + 19)); - FinishMoveFn oFinishMove = - (FinishMoveFn)(*(unsigned *) (predictionVtable + 20)); - - // CMoveData *pMoveData = (CMoveData*)(sharedobj::client->lmap->l_addr + - // 0x1F69C0C); CMoveData movedata {}; - char object[165]; - CMoveData *pMoveData = (CMoveData *) object; - - float frameTime = g_GlobalVars->frametime; - float curTime = g_GlobalVars->curtime; - - CUserCmd defaultCmd; - if (ucmd == NULL) - { - ucmd = &defaultCmd; - } - - NET_VAR(ent, 4188, CUserCmd *) = ucmd; - - g_GlobalVars->curtime = - g_GlobalVars->interval_per_tick * NET_INT(ent, netvar.nTickBase); - g_GlobalVars->frametime = g_GlobalVars->interval_per_tick; - - *g_PredictionRandomSeed = - MD5_PseudoRandom(g_pUserCmd->command_number) & 0x7FFFFFFF; - g_IGameMovement->StartTrackPredictionErrors( - reinterpret_cast(ent)); - oSetupMove(g_IPrediction, ent, ucmd, NULL, pMoveData); - g_IGameMovement->ProcessMovement(reinterpret_cast(ent), - pMoveData); - oFinishMove(g_IPrediction, ent, ucmd, pMoveData); - g_IGameMovement->FinishTrackPredictionErrors( - reinterpret_cast(ent)); - - NET_VAR(ent, 4188, CUserCmd *) = nullptr; - - g_GlobalVars->frametime = frameTime; - g_GlobalVars->curtime = curTime; - - return; -} /*float o_curtime; float o_frametime; @@ -523,9 +527,3 @@ void End() { g_GlobalVars->curtime = o_curtime; g_GlobalVars->frametime = o_frametime; }*/ -} - -bool CreateMove_hook(void *thisptr, float inputSample, CUserCmd *cmd) -{ - -} diff --git a/src/hooks/DispatchUserMessage.cpp b/src/hooks/DispatchUserMessage.cpp index 69b1873d..c150fb95 100644 --- a/src/hooks/DispatchUserMessage.cpp +++ b/src/hooks/DispatchUserMessage.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "HookedMethods.hpp" static bool retrun = false; @@ -20,9 +21,6 @@ static CatVar chat_filter(CV_STRING, "chat_censor", "", "Censor words", "said, seperate with commas"); static CatVar chat_filter_enabled(CV_SWITCH, "chat_censor_enabled", "0", "Enable censor", "Censor Words in chat"); -static CatVar crypt_chat( - CV_SWITCH, "chat_crypto", "1", "Crypto chat", - "Start message with !! and it will be only visible to cathook users"); std::string clear = ""; std::string lastfilter{}; std::string lastname{}; diff --git a/src/hooks/GetFriendPersonaName.cpp b/src/hooks/GetFriendPersonaName.cpp index 31e5a4b2..baac83e3 100644 --- a/src/hooks/GetFriendPersonaName.cpp +++ b/src/hooks/GetFriendPersonaName.cpp @@ -5,16 +5,110 @@ #include "HookedMethods.hpp" +static CatVar ipc_name(CV_STRING, "name_ipc", "", "IPC Name"); + +CatEnum namesteal_enum({ "OFF", "PASSIVE", "ACTIVE" }); +CatVar namesteal(namesteal_enum, "name_stealer", "0", "Name Stealer", + "Attemt to steal your teammates names. Usefull for avoiding " + "kicks\nPassive only changes when the name stolen is no " + "longer the best name to use\nActive Attemps to change the " + "name whenever possible"); + +static std::string stolen_name; + +// Func to get a new entity to steal name from and returns true if a target has +// been found +bool StolenName() +{ + + // Array to store potential namestealer targets with a bookkeeper to tell + // how full it is + int potential_targets[32]; + int potential_targets_length = 0; + + // Go through entities looking for potential targets + for (int i = 1; i < HIGHEST_ENTITY; i++) + { + CachedEntity *ent = ENTITY(i); + + // Check if ent is a good target + if (!ent) + continue; + if (ent == LOCAL_E) + continue; + if (!ent->m_Type == ENTITY_PLAYER) + continue; + if (ent->m_bEnemy) + continue; + + // Check if name is current one + player_info_s info; + if (g_IEngine->GetPlayerInfo(ent->m_IDX, &info)) + { + + // If our name is the same as current, than change it + if (std::string(info.name) == stolen_name) + { + // Since we found the ent we stole our name from and it is still + // good, if user settings are passive, then we return true and + // dont alter our name + if ((int) namesteal == 1) + { + return true; + // Otherwise we continue to change our name to something + // else + } + else + continue; + } + + // a ent without a name is no ent we need, contine for a different + // one + } + else + continue; + + // Save the ent to our array + potential_targets[potential_targets_length] = i; + potential_targets_length++; + + // With our maximum amount of players reached, dont search for anymore + if (potential_targets_length >= 32) + break; + } + + // Checks to prevent crashes + if (potential_targets_length == 0) + return false; + + // Get random number that we can use with our array + int target_random_num = + floor(RandFloatRange(0, potential_targets_length - 0.1F)); + + // Get a idx from our random array position + int new_target = potential_targets[target_random_num]; + + // Grab username of user + player_info_s info; + if (g_IEngine->GetPlayerInfo(new_target, &info)) + { + + // If our name is the same as current, than change it and return true + stolen_name = std::string(info.name); + return true; + } + + // Didnt get playerinfo + return false; +} + + namespace hooked_methods { DEFINE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *this_, CSteamID steam_id) { - static const GetFriendPersonaName_t original = - (GetFriendPersonaName_t) hooks::steamfriends.GetMethod( - offsets::GetFriendPersonaName()); - #if ENABLE_IPC if (ipc::peer) { @@ -29,7 +123,7 @@ DEFINE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *this_, #endif // Check User settings if namesteal is allowed - if (namesteal && steamID == g_ISteamUser->GetSteamID()) + if (namesteal && steam_id == g_ISteamUser->GetSteamID()) { // We dont want to steal names while not in-game as there are no targets @@ -49,7 +143,7 @@ DEFINE_HOOKED_METHOD(GetFriendPersonaName, const char *, ISteamFriends *this_, } if ((strlen(force_name.GetString()) > 1) && - steamID == g_ISteamUser->GetSteamID()) + steam_id == g_ISteamUser->GetSteamID()) { return force_name_newlined; diff --git a/src/hooks/PaintTraverse.cpp b/src/hooks/PaintTraverse.cpp deleted file mode 100644 index 4cc0a47f..00000000 --- a/src/hooks/PaintTraverse.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * PaintTraverse.cpp - * - * Created on: Jan 8, 2017 - * Author: nullifiedcat - */ - -#include "common.hpp" - -#if ENABLE_GUI -#include "GUI.h" -#endif - - - -void PaintTraverse_hook(void *_this, unsigned int vp, bool fr, bool ar) -{ - -} diff --git a/src/hooks/SendNetMsg.cpp b/src/hooks/SendNetMsg.cpp index 6bc3ef19..54ffaf05 100644 --- a/src/hooks/SendNetMsg.cpp +++ b/src/hooks/SendNetMsg.cpp @@ -4,12 +4,21 @@ */ #include +#include #include "HookedMethods.hpp" +static CatVar newlines_msg(CV_INT, "chat_newlines", "0", "Prefix newlines", + "Add # newlines before each your message", 0, 24); + + +static CatVar log_sent(CV_SWITCH, "debug_log_sent_messages", "0", + "Log sent messages"); +static CatVar airstuck(CV_KEY, "airstuck", "0", "Airstuck", ""); + namespace hooked_methods { -DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &message, +DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &msg, bool force_reliable, bool voice) { size_t say_idx, say_team_idx; @@ -47,7 +56,7 @@ DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &message, str = str.substr(16, str.length() - 17); // if (queue_messages && !chat_stack::CanSend()) { stringcmd.m_szCommand = str.c_str(); - return original(_this, stringcmd, bForceReliable, bVoice); + return original::SendNetMsg(this_, stringcmd, force_reliable, voice); //} } } @@ -92,6 +101,6 @@ DEFINE_HOOKED_METHOD(SendNetMsg, bool, INetChannel *this_, INetMessage &message, logging::Info("%i bytes => %s", buffer.GetNumBytesWritten(), bytes.c_str()); } - return original::SendNetMsg(this_, message, force_reliable, voice); + return original::SendNetMsg(this_, msg, force_reliable, voice); } } \ No newline at end of file diff --git a/src/hooks/Shutdown.cpp b/src/hooks/Shutdown.cpp index b442bd58..6e88f445 100644 --- a/src/hooks/Shutdown.cpp +++ b/src/hooks/Shutdown.cpp @@ -5,6 +5,8 @@ #include "HookedMethods.hpp" +static CatVar die_if_vac(CV_SWITCH, "die_if_vac", "0", "Die if VAC banned"); + namespace hooked_methods { diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index 1f4c4b17..8952533c 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -12,6 +12,7 @@ #include "chatlog.hpp" #include "netmessage.hpp" #include +#include #if ENABLE_VISUALS @@ -52,8 +53,6 @@ CatCommand spectate("spectate", "Spectate", [](const CCommand &args) { #endif -static CatVar log_sent(CV_SWITCH, "debug_log_sent_messages", "0", - "Log sent messages"); static CatCommand plus_use_action_slot_item_server( "+cat_use_action_slot_item_server", "use_action_slot_item_server", []() { @@ -69,117 +68,17 @@ static CatCommand minus_use_action_slot_item_server( g_IEngine->ServerCmdKeyValues(kv); }); -static CatVar newlines_msg(CV_INT, "chat_newlines", "0", "Prefix newlines", - "Add # newlines before each your message", 0, 24); // TODO replace \\n with \n // TODO name \\n = \n // static CatVar queue_messages(CV_SWITCH, "chat_queue", "0", "Queue messages", // "Use this if you want to use spam/killsay and still be able to chat normally // (without having your msgs eaten by valve cooldown)"); -static CatVar airstuck(CV_KEY, "airstuck", "0", "Airstuck", ""); static CatVar server_crash_key(CV_KEY, "crash_server", "0", "Server crash key", "hold key and wait..."); -static CatVar die_if_vac(CV_SWITCH, "die_if_vac", "0", "Die if VAC banned"); - - -CatEnum namesteal_enum({ "OFF", "PASSIVE", "ACTIVE" }); -CatVar namesteal(namesteal_enum, "name_stealer", "0", "Name Stealer", - "Attemt to steal your teammates names. Usefull for avoiding " - "kicks\nPassive only changes when the name stolen is no " - "longer the best name to use\nActive Attemps to change the " - "name whenever possible"); - -static std::string stolen_name; - -// Func to get a new entity to steal name from and returns true if a target has -// been found -bool StolenName() -{ - - // Array to store potential namestealer targets with a bookkeeper to tell - // how full it is - int potential_targets[32]; - int potential_targets_length = 0; - - // Go through entities looking for potential targets - for (int i = 1; i < HIGHEST_ENTITY; i++) - { - CachedEntity *ent = ENTITY(i); - - // Check if ent is a good target - if (!ent) - continue; - if (ent == LOCAL_E) - continue; - if (!ent->m_Type == ENTITY_PLAYER) - continue; - if (ent->m_bEnemy) - continue; - - // Check if name is current one - player_info_s info; - if (g_IEngine->GetPlayerInfo(ent->m_IDX, &info)) - { - - // If our name is the same as current, than change it - if (std::string(info.name) == stolen_name) - { - // Since we found the ent we stole our name from and it is still - // good, if user settings are passive, then we return true and - // dont alter our name - if ((int) namesteal == 1) - { - return true; - // Otherwise we continue to change our name to something - // else - } - else - continue; - } - - // a ent without a name is no ent we need, contine for a different - // one - } - else - continue; - - // Save the ent to our array - potential_targets[potential_targets_length] = i; - potential_targets_length++; - - // With our maximum amount of players reached, dont search for anymore - if (potential_targets_length >= 32) - break; - } - - // Checks to prevent crashes - if (potential_targets_length == 0) - return false; - - // Get random number that we can use with our array - int target_random_num = - floor(RandFloatRange(0, potential_targets_length - 0.1F)); - - // Get a idx from our random array position - int new_target = potential_targets[target_random_num]; - - // Grab username of user - player_info_s info; - if (g_IEngine->GetPlayerInfo(new_target, &info)) - { - - // If our name is the same as current, than change it and return true - stolen_name = std::string(info.name); - return true; - } - - // Didnt get playerinfo - return false; -} - -static CatVar ipc_name(CV_STRING, "name_ipc", "", "IPC Name"); + + diff --git a/src/hooks/sdl.cpp b/src/hooks/sdl.cpp deleted file mode 100755 index 99125261..00000000 --- a/src/hooks/sdl.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * sdl.cpp - * - * Created on: May 19, 2017 - * Author: nullifiedcat - */ - -#include "common.hpp" - -#include "hooks/HookedMethods.hpp" -#include "hack.hpp" - -#include -#include -#include -#include -#include -#include -#include - -SDL_Window *sdl_current_window{ nullptr }; -SDL_GL_SwapWindow_t *SDL_GL_SwapWindow_loc{ nullptr }; -SDL_GL_SwapWindow_t SDL_GL_SwapWindow_o{ nullptr }; - -SDL_PollEvent_t *SDL_PollEvent_loc{ nullptr }; -SDL_PollEvent_t SDL_PollEvent_o{ nullptr }; - -typedef uint32_t (*SDL_GetWindowFlags_t)(SDL_Window *window); - -SDL_GetWindowFlags_t *SDL_GetWindowFlags_loc{ nullptr }; -SDL_GetWindowFlags_t SDL_GetWindowFlags_o{ nullptr }; - -uint32_t SDL_GetWindowFlags_hook(SDL_Window *window) -{ - uint32_t flags = SDL_GetWindowFlags_o(window); - flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_HIDDEN); - flags |= SDL_WINDOW_SHOWN; - return flags; -} - -void SDL_GL_SwapWindow_hook(SDL_Window *window) -{ - -} - -int SDL_PollEvent_hook(SDL_Event *event) -{ - int ret = SDL_PollEvent_o(event); - if (ret) - { - logging::Info("event %x %x", event->type, event->common.type); - if (event->type == SDL_WINDOWEVENT) - { - switch (event->window.event) - { - case SDL_WINDOWEVENT_HIDDEN: - logging::Info("Window hidden"); - return 0; - case SDL_WINDOWEVENT_MINIMIZED: - logging::Info("Window minimized"); - return 0; - } - } - } - return ret; -} - -void DoSDLHooking() -{ - SDL_GL_SwapWindow_loc = reinterpret_cast( - sharedobj::libsdl().Pointer(0xFD648)); - - SDL_GL_SwapWindow_o = *SDL_GL_SwapWindow_loc; - *SDL_GL_SwapWindow_loc = SDL_GL_SwapWindow_hook; - - // SDL_GetWindowFlags_loc = - // reinterpret_cast(sharedobj::libsdl().Pointer(0xFD588)); - - // SDL_GetWindowFlags_o = *SDL_GetWindowFlags_loc; - // *SDL_GetWindowFlags_loc = SDL_GetWindowFlags_hook; - - // SDL_PollEvent_loc = - // reinterpret_cast(sharedobj::libsdl().Pointer(0xFCF64)); - - // SDL_PollEvent_o = *SDL_PollEvent_loc; - // *SDL_PollEvent_loc = SDL_PollEvent_hook; -} - -void DoSDLUnhooking() -{ - *SDL_GL_SwapWindow_loc = SDL_GL_SwapWindow_o; - // *SDL_GetWindowFlags_loc = SDL_GetWindowFlags_o; - // *SDL_PollEvent_loc = SDL_PollEvent_o; -} diff --git a/src/hooks/visual/SDL_GL_SwapWindow.cpp b/src/hooks/visual/SDL_GL_SwapWindow.cpp index 96c41227..985c4011 100644 --- a/src/hooks/visual/SDL_GL_SwapWindow.cpp +++ b/src/hooks/visual/SDL_GL_SwapWindow.cpp @@ -3,6 +3,9 @@ Copyright (c) 2018 nullworks. All rights reserved. */ +#include +#include +#include #include "HookedMethods.hpp" namespace hooked_methods @@ -24,8 +27,8 @@ DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window) GetWindowWMInfo(window, &wminfo); init_wminfo = true; } - if (!sdl_current_window) - sdl_current_window = window; + if (!sdl_hooks::window) + sdl_hooks::window = window; static bool init{ false }; @@ -44,13 +47,11 @@ DEFINE_HOOKED_METHOD(SDL_GL_SwapWindow, void, SDL_Window *window) { PROF_SECTION(SWAPWINDOW_tf2); SDL_GL_MakeCurrent(window, tf2_sdl); - SDL_GL_SwapWindow_o(window); + original::SDL_GL_SwapWindow(window); // glXMakeContextCurrent(wminfo.info.x11.display, // wminfo.info.x11.window, // wminfo.info.x11.window, tf2); // glXSwapBuffers(wminfo.info.x11.display, wminfo.info.x11.window); } - - return original::SDL_GL_SwapWindow(window); } } \ No newline at end of file diff --git a/src/visual/CMakeLists.txt b/src/visual/CMakeLists.txt index 580c2e88..8ede8cc0 100644 --- a/src/visual/CMakeLists.txt +++ b/src/visual/CMakeLists.txt @@ -6,7 +6,8 @@ target_sources(cathook PRIVATE "${CMAKE_CURRENT_LIST_DIR}/drawmgr.cpp" "${CMAKE_CURRENT_LIST_DIR}/EffectChams.cpp" "${CMAKE_CURRENT_LIST_DIR}/EffectGlow.cpp" - "${CMAKE_CURRENT_LIST_DIR}/fidgetspinner.cpp") + "${CMAKE_CURRENT_LIST_DIR}/fidgetspinner.cpp" + "${CMAKE_CURRENT_LIST_DIR}/SDLHooks.cpp") if(EnableGUI) add_subdirectory(menu) diff --git a/src/visual/EffectChams.cpp b/src/visual/EffectChams.cpp index 365e529c..0ca807bd 100644 --- a/src/visual/EffectChams.cpp +++ b/src/visual/EffectChams.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "common.hpp" // static CatVar chams_experimental(CV_SWITCH, "chams_effect", "0", diff --git a/src/visual/EffectGlow.cpp b/src/visual/EffectGlow.cpp index 1f7c3538..4cf7cc04 100755 --- a/src/visual/EffectGlow.cpp +++ b/src/visual/EffectGlow.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "common.hpp" IMaterialSystem *materials = nullptr; diff --git a/src/visual/SDLHooks.cpp b/src/visual/SDLHooks.cpp new file mode 100644 index 00000000..31696d31 --- /dev/null +++ b/src/visual/SDLHooks.cpp @@ -0,0 +1,33 @@ +/* + Created by Jenny White on 29.04.18. + Copyright (c) 2018 nullworks. All rights reserved. +*/ + +#include "SDLHooks.hpp" +#include "HookedMethods.hpp" + +namespace sdl_hooks +{ + +SDL_Window *window{ nullptr }; + +namespace pointers +{ +hooked_methods::types::SDL_GL_SwapWindow *SDL_GL_SwapWindow{ nullptr }; +} + + +void applySdlHooks() +{ + pointers::SDL_GL_SwapWindow = reinterpret_cast(sharedobj::libsdl().Pointer(0xFD648)); + + hooked_methods::original::SDL_GL_SwapWindow = *pointers::SDL_GL_SwapWindow; + *pointers::SDL_GL_SwapWindow = hooked_methods::methods::SDL_GL_SwapWindow; +} + +void cleanSdlHooks() +{ + *pointers::SDL_GL_SwapWindow = hooked_methods::original::SDL_GL_SwapWindow; +} + +} \ No newline at end of file diff --git a/src/visual/drawex.cpp b/src/visual/drawex.cpp index 7b5ccfde..cd36e0cc 100755 --- a/src/visual/drawex.cpp +++ b/src/visual/drawex.cpp @@ -12,6 +12,7 @@ #include #include +#include #if EXTERNAL_DRAWING extern "C" { @@ -77,7 +78,7 @@ void initialize() } xoverlay_show(); #else - context = SDL_GL_CreateContext(sdl_current_window); + context = SDL_GL_CreateContext(sdl_hooks::window); glClearColor(1.0, 0.0, 0.0, 0.5); glewExperimental = GL_TRUE; glewInit(); @@ -159,7 +160,7 @@ void draw_begin() #if EXTERNAL_DRAWING xoverlay_draw_begin(); #else - SDL_GL_MakeCurrent(sdl_current_window, context); + SDL_GL_MakeCurrent(sdl_hooks::window, context); #endif glez_begin(); } @@ -168,7 +169,7 @@ void draw_end() { PROF_SECTION(DRAWEX_draw_end); glez_end(); - SDL_GL_MakeCurrent(sdl_current_window, nullptr); + SDL_GL_MakeCurrent(sdl_hooks::window, nullptr); #if EXTERNAL_DRAWING xoverlay_draw_end(); #endif diff --git a/src/visual/drawmgr.cpp b/src/visual/drawmgr.cpp index 0bdaeb2b..dbbec05d 100644 --- a/src/visual/drawmgr.cpp +++ b/src/visual/drawmgr.cpp @@ -5,6 +5,7 @@ * Author: nullifiedcat */ +#include #include "common.hpp" #include "visual/drawing.hpp" #include "hack.hpp"