Skip to content
Permalink
Browse files

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
  • Loading branch information
BenCat07 committed Jan 3, 2020
1 parent d28f5e9 commit e5d75893d375e77b169f9b24cc3f505c06ad17fb
@@ -30,6 +30,7 @@ enum SharedObjects
engine,
steamapi,
vstd,
launcher,
// Whatever you do, keep this one last
entry_count
};
@@ -43,6 +44,7 @@ class CSignature
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);
};
@@ -42,6 +42,7 @@ SharedObject &serverbrowser();
SharedObject &steamclient();
SharedObject &client();
SharedObject &engine();
SharedObject &launcher();
SharedObject &steamapi();
SharedObject &vstdlib();
SharedObject &tier0();
@@ -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);
@@ -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);
@@ -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;

// 0x8 = SDL_HIDDEN
static BytePatch patch1(addr1, { 0x8 });

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 });
// all are the same size so use same patch for all
std::vector<unsigned char> 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

0 comments on commit e5d7589

Please sign in to comment.
You can’t perform that action at this time.