From e5d75893d375e77b169f9b24cc3f505c06ad17fb Mon Sep 17 00:00:00 2001 From: BenCat07 Date: Fri, 3 Jan 2020 20:15:42 +0100 Subject: [PATCH] Hide SDL window for catbots entirely due to mesa having problems with Xvfb we should stop using Xvfb and instead just use the normal display again, but this time hide the window --- include/copypasted/CSignature.h | 2 ++ include/core/sharedobj.hpp | 1 + src/copypasted/CSignature.cpp | 5 +++++ src/core/sharedobj.cpp | 7 +++++++ src/hooks/nographics.cpp | 37 ++++++++++++++++++++++++++++----- 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/copypasted/CSignature.h b/include/copypasted/CSignature.h index c94227bf..a6bdeffa 100644 --- a/include/copypasted/CSignature.h +++ b/include/copypasted/CSignature.h @@ -30,6 +30,7 @@ enum SharedObjects engine, steamapi, vstd, + launcher, // Whatever you do, keep this one last entry_count }; @@ -43,6 +44,7 @@ public: static uintptr_t GetSignature(const char *chPattern, sharedobj::SharedObject &obj, int idx); static uintptr_t GetClientSignature(const char *chPattern); static uintptr_t GetEngineSignature(const char *chPattern); + static uintptr_t GetLauncherSignature(const char *chaPattern); static uintptr_t GetSteamAPISignature(const char *chPattern); static uintptr_t GetVstdSignature(const char *chPattern); }; diff --git a/include/core/sharedobj.hpp b/include/core/sharedobj.hpp index 12106f42..09785c88 100644 --- a/include/core/sharedobj.hpp +++ b/include/core/sharedobj.hpp @@ -42,6 +42,7 @@ SharedObject &serverbrowser(); SharedObject &steamclient(); SharedObject &client(); SharedObject &engine(); +SharedObject &launcher(); SharedObject &steamapi(); SharedObject &vstdlib(); SharedObject &tier0(); diff --git a/src/copypasted/CSignature.cpp b/src/copypasted/CSignature.cpp index f0c74722..56139e87 100644 --- a/src/copypasted/CSignature.cpp +++ b/src/copypasted/CSignature.cpp @@ -212,6 +212,11 @@ uintptr_t CSignature::GetEngineSignature(const char *chPattern) return GetSignature(chPattern, sharedobj::engine(), CSignature_space::engine); } //=================================================================================== +uintptr_t CSignature::GetLauncherSignature(const char *chPattern) +{ + return GetSignature(chPattern, sharedobj::launcher(), CSignature_space::launcher); +} +//=================================================================================== uintptr_t CSignature::GetSteamAPISignature(const char *chPattern) { return GetSignature(chPattern, sharedobj::steamapi(), CSignature_space::steamapi); diff --git a/src/core/sharedobj.cpp b/src/core/sharedobj.cpp index e55abca8..f4952cfb 100644 --- a/src/core/sharedobj.cpp +++ b/src/core/sharedobj.cpp @@ -99,6 +99,7 @@ void LoadEarlyObjects() try { engine().Load(); + launcher().Load(); filesystem_stdio().Load(); tier0().Load(); materialsystem().Load(); @@ -146,6 +147,7 @@ void UnloadAllSharedObjects() studiorender().Unload(); libsdl().Unload(); #endif + launcher().Unload(); engine().Unload(); filesystem_stdio().Unload(); tier0().Unload(); @@ -172,6 +174,11 @@ SharedObject &engine() static SharedObject obj("engine.so", true); return obj; } +SharedObject &launcher() +{ + static SharedObject obj("launcher.so", true); + return obj; +} SharedObject &vstdlib() { static SharedObject obj("libvstdlib.so", true); diff --git a/src/hooks/nographics.cpp b/src/hooks/nographics.cpp index 622156bf..3d4744d6 100755 --- a/src/hooks/nographics.cpp +++ b/src/hooks/nographics.cpp @@ -271,17 +271,44 @@ static void UnHookFs() if (g_IBaseClient) g_IBaseClient->InvalidateMdlCache(); } + #if ENABLE_TEXTMODE static InitRoutineEarly nullify_textmode([]() { - ReduceRamUsage(); - static auto addr1 = e8call_direct(gSignatures.GetEngineSignature("E8 ? ? ? ? 8B 93 ? ? ? ? 85 D2 0F 84")) + 0x18; - static auto addr2 = sharedobj::materialsystem().Pointer(0x3EC08); + // SDL_CreateWindow has a "flag" parameter. We simply give it HIDDEN as a flag + static auto addr1 = gSignatures.GetLauncherSignature("C7 43 ? ? ? ? ? C7 44 24 ? ? ? ? ? C7 44 24") + 0xb; + // All of these are needed so tf2 doesn't just unhide the window + static auto addr2 = gSignatures.GetLauncherSignature("E8 ? ? ? ? C6 43 25 01 83 C4 5C"); + static auto addr3 = gSignatures.GetLauncherSignature("E8 ? ? ? ? 8B 43 14 89 04 24 E8 ? ? ? ? C6 43 25 01 83 C4 1C"); + static auto addr4 = gSignatures.GetLauncherSignature("89 14 24 E8 ? ? ? ? 8B 45 B4") + 0x3; - static BytePatch patch1(addr1, { 0x81, 0xC4, 0x6C, 0x20, 0x00, 0x00, 0x5B, 0x5E, 0x5F, 0x5D, 0xC3 }); - static BytePatch patch2(addr2, { 0x83, 0xC4, 0x50, 0x5B, 0x5E, 0x5D, 0xC3 }); + // 0x8 = SDL_HIDDEN + static BytePatch patch1(addr1, { 0x8 }); + + // all are the same size so use same patch for all + std::vector patch_arr = { 0x90, 0x90, 0x90, 0x90, 0x90 }; + + static BytePatch patch2(addr2, patch_arr); + static BytePatch patch3(addr3, patch_arr); + static BytePatch patch4(addr4, patch_arr); patch1.Patch(); patch2.Patch(); + patch3.Patch(); + patch4.Patch(); + + ReduceRamUsage(); + // CVideoMode_Common::Init SetupStartupGraphic + static auto addr5 = e8call_direct(gSignatures.GetEngineSignature("E8 ? ? ? ? 8B 93 ? ? ? ? 85 D2 0F 84")) + 0x18; + // make materials illegal + static auto addr6 = sharedobj::materialsystem().Pointer(0x3EC08); + + // Make SetupStartupGraphic instantly return + static BytePatch patch5(addr5, { 0x81, 0xC4, 0x6C, 0x20, 0x00, 0x00, 0x5B, 0x5E, 0x5F, 0x5D, 0xC3 }); + // materials are gone :crab: + static BytePatch patch6(addr6, { 0x83, 0xC4, 0x50, 0x5B, 0x5E, 0x5D, 0xC3 }); + + patch5.Patch(); + patch6.Patch(); }); #endif