diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ab8992b..42edb4aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,6 @@ set(VACBypass 0 CACHE BOOL "Textmode VAC bypass") set(Textmode 0 CACHE BOOL "Various textmode-only features for bots") set(EnableTextmodeStdin 0 CACHE BOOL "Textmode Stdin -> Console bridge (EXPERIMENTAL)") set(EnableWarnings 0 CACHE BOOL "Enable compile warnings") -set(EnableNullGraphics 0 CACHE BOOL "Enable experimental textmode hooks (CRASHES)") set(EnableOnlineFeatures 0 CACHE BOOL "Enable online features (WIP)") set(EnableIRC 1 CACHE BOOL "Enable IRC for messaging and ignore-cathook") diff --git a/include/config.h.in b/include/config.h.in index 60b0a958..2d2bc392 100755 --- a/include/config.h.in +++ b/include/config.h.in @@ -14,7 +14,6 @@ #define DATA_PATH "@DataPath@" #define ENABLE_VAC_BYPASS @VACBypass@ #define ENABLE_TEXTMODE_STDIN @EnableTextmodeStdin@ -#define ENABLE_NULL_GRAPHICS @EnableNullGraphics@ #define TEXTMODE @Textmode@ #define ENABLE_PROFILER @EnableProfiler@ #define ENABLE_ONLINE @EnableOnlineFeatures@ diff --git a/include/core/interfaces.hpp b/include/core/interfaces.hpp index d84435b3..a0496080 100644 --- a/include/core/interfaces.hpp +++ b/include/core/interfaces.hpp @@ -90,9 +90,7 @@ extern CGameRules *g_pGameRules; extern IEngineVGui *g_IEngineVGui; extern IUniformRandomStream *g_pUniformStream; extern int *g_PredictionRandomSeed; -#if ENABLE_NULL_GRAPHICS extern IFileSystem *g_IFileSystem; extern IMDLCache *g_IMDLCache; -#endif void CreateInterfaces(); diff --git a/include/hooks/HookedMethods.hpp b/include/hooks/HookedMethods.hpp index cdf72c3f..c4b88010 100644 --- a/include/hooks/HookedMethods.hpp +++ b/include/hooks/HookedMethods.hpp @@ -82,7 +82,6 @@ DECLARE_HOOKED_METHOD(RandomInt, int, IUniformRandomStream *, int, int); // wontfix.club #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, @@ -108,6 +107,5 @@ typedef IMaterial *(*FindMaterial_t)(void *, const char *, const char *, bool, const char *pTextureGroupName, int nContext, bool complain, const char *pComplainPrefix); -#endif #endif diff --git a/src/core/interfaces.cpp b/src/core/interfaces.cpp index 4617e5c8..f4266f65 100644 --- a/src/core/interfaces.cpp +++ b/src/core/interfaces.cpp @@ -52,10 +52,8 @@ CGameRules *g_pGameRules = nullptr; IEngineVGui *g_IEngineVGui = nullptr; IUniformRandomStream *g_pUniformStream = nullptr; int *g_PredictionRandomSeed = nullptr; -#if ENABLE_NULL_GRAPHICS IFileSystem *g_IFileSystem = nullptr; IMDLCache *g_IMDLCache = nullptr; -#endif template T *BruteforceInterface(std::string name, sharedobj::SharedObject &object, int start = 0) { @@ -132,7 +130,7 @@ void CreateInterfaces() // FIXME SIGNATURE g_ISteamFriends = g_ISteamClient->GetISteamFriends(su, sp, "SteamFriends002"); } - rg_GlobalVars = *reinterpret_cast(gSignatures.GetClientSignature("8B 15 ? ? ? ? F3 0F 10 88 D0 08 00 00") + 2); + rg_GlobalVars = *reinterpret_cast(gSignatures.GetClientSignature("8B 15 ? ? ? ? F3 0F 10 88 D0 08 00 00") + 2); g_IPrediction = BruteforceInterface("VClientPrediction", sharedobj::client()); g_IGameMovement = BruteforceInterface("GameMovement", sharedobj::client()); IF_GAME(IsTF2()) @@ -158,10 +156,8 @@ void CreateInterfaces() g_pGameRules = *reinterpret_cast(g_pGameRules_sig + 8); } g_IMaterialSystem = BruteforceInterface("VMaterialSystem", sharedobj::materialsystem()); -#if ENABLE_NULL_GRAPHICS - g_IFileSystem = BruteforceInterface("VFileSystem", sharedobj::filesystem_stdio()); - g_IMDLCache = BruteforceInterface("MDLCache", sharedobj::datacache()); -#endif + g_IFileSystem = BruteforceInterface("VFileSystem", sharedobj::filesystem_stdio()); + g_IMDLCache = BruteforceInterface("MDLCache", sharedobj::datacache()); #if ENABLE_VISUALS g_pUniformStream = **(IUniformRandomStream ***) (gSignatures.GetVstdSignature("A3 ? ? ? ? C3 89 F6") + 0x1); diff --git a/src/hack.cpp b/src/hack.cpp index 9090dfe6..6b51f87f 100644 --- a/src/hack.cpp +++ b/src/hack.cpp @@ -143,14 +143,10 @@ void critical_error_handler(int signum) ::raise(SIGABRT); } -#if ENABLE_NULL_GRAPHICS static bool blacklist_file(const char *filename) { const static char *blacklist[] = { ".vtx", ".vtf", ".pcf", ".mdl" }; - if (!filename || !std::strcmp(filename, "models/error.mdl") || - !std::strcmp(filename, "models/vgui/competitive_badge.mdl") || - !std::strcmp(filename, "models/vgui/12v12_badge.mdl") || - !std::strncmp(filename, "models/player/", 14)) + if (!filename || !std::strcmp(filename, "models/error.mdl") || !std::strcmp(filename, "models/vgui/competitive_badge.mdl") || !std::strcmp(filename, "models/vgui/12v12_badge.mdl") || !std::strncmp(filename, "models/player/", 14)) return false; std::size_t len = std::strlen(filename); @@ -164,33 +160,33 @@ static bool blacklist_file(const char *filename) return false; } -static bool (*FSorig_ReadFile)(void*, const char *, const char *, void *, int, int, void *); -static bool FSHook_ReadFile(void *this_, const char *pFileName, const char *pPath, - void *buf, int nMaxBytes, int nStartingByte, void *pfnAlloc) +static bool (*FSorig_ReadFile)(void *, const char *, const char *, void *, int, int, void *); +static bool FSHook_ReadFile(void *this_, const char *pFileName, const char *pPath, void *buf, int nMaxBytes, int nStartingByte, void *pfnAlloc) { - //fprintf(stderr, "ReadFile: %s\n", pFileName); + // fprintf(stderr, "ReadFile: %s\n", pFileName); if (blacklist_file(pFileName)) return false; return FSorig_ReadFile(this_, pFileName, pPath, buf, nMaxBytes, nStartingByte, pfnAlloc); } -#endif - +static hooks::VMTHook /*fs_hook,*/ fs_hook2; static void ReduceRamUsage() { -#if ENABLE_NULL_GRAPHICS - static hooks::VMTHook /*fs_hook,*/ fs_hook2; fs_hook2.Set(reinterpret_cast(g_IFileSystem), 4); fs_hook2.HookMethod(FSHook_ReadFile, 14, &FSorig_ReadFile); fs_hook2.Apply(); /* ERROR: Must be called from texture thread */ - //g_IMaterialSystem->ReloadTextures(); + // g_IMaterialSystem->ReloadTextures(); g_IBaseClient->InvalidateMdlCache(); -#endif } - +static void UnHookFs() +{ + fs_hook2.Release(); + g_IBaseClient->InvalidateMdlCache(); +} +static settings::Bool null_graphics("hack.nullgraphics", "false"); static void InitRandom() { int rand_seed; @@ -246,8 +242,13 @@ free(logname);*/ InitRandom(); sharedobj::LoadAllSharedObjects(); CreateInterfaces(); - ReduceRamUsage(); CDumper dumper; + null_graphics.installChangeCallback([](settings::VariableBase &, bool after) { + if (after) + ReduceRamUsage(); + else + UnHookFs(); + }); dumper.SaveDump(); logging::Info("Is TF2? %d", IsTF2()); logging::Info("Is TF2C? %d", IsTF2C()); diff --git a/src/hooks/HookTools.cpp b/src/hooks/HookTools.cpp index e1085442..a5a1d214 100644 --- a/src/hooks/HookTools.cpp +++ b/src/hooks/HookTools.cpp @@ -17,6 +17,16 @@ struct EventCallbackData }; static std::vector events[ec_types::EcTypesSize]; +CatCommand evt_print("debug_print_events", "Print EC events", []() { + for (int i = 0; i < int(ec_types::EcTypesSize); ++i) + { + logging::Info("%d events:", i); + + for (auto it = events[i].begin(); it != events[i].end(); ++it) + logging::Info("%s", it->event_name.c_str()); + logging::Info(""); + } +}); void Register(enum ec_types type, const EventFunction &function, const std::string &name, enum ec_priority priority) {