From 39ecd9632bb69d1c95ab299f0b65b5566811925a Mon Sep 17 00:00:00 2001 From: nanocat Date: Fri, 16 Jan 2026 21:24:12 +0100 Subject: [PATCH 1/9] materialsystem bytepatches never actually ran --- TextmodeTF2/src/BytePatches/BytePatches.h | 10 ++++++++-- TextmodeTF2/src/Core/Core.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index ad9b49e..7705da8 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -58,6 +58,12 @@ class CBytePatches // Mod_LoadTexinfo // forces mat_loadtextures 0 logic to skip material loading BytePatch("engine.dll", "0F 84 ? ? ? ? 48 63 7E 44", 0x0, "90 E9"), + + // These SHOULD fix d3device failure + // CVideoMode_Common::CreateGameWindow + BytePatch("engine.dll", "48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20 41 56 48 83 EC 50 4C 8B F1 41 0F B6 F1 48 8D 0D ? ? ? ?", 0x0, "B0 01 C3"), + // CGame::CreateGameWindow + BytePatch("engine.dll", "40 55 53 56 57 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B F1 C6 45 D0 00 B9 40 00", 0x0, "B0 01 C3"), }}, {"materialsystem", { @@ -71,7 +77,7 @@ class CBytePatches // CMaterialSystem::FindMaterial // returns NULL for every material lookup - BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), + // BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), }}, {"client", { @@ -146,4 +152,4 @@ class CBytePatches }; }; -ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); \ No newline at end of file +ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index e9e2971..529753f 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -141,7 +141,7 @@ int CCore::LoadMatSys() return LOAD_WAIT; I::MaterialSystem->SetInStubMode(true); - + U::BytePatches.Initialize("materialsystem"); static std::vector vMatSystemHooks { "IMaterialSystem_CreateRenderTargetTexture", "IMaterialSystem_CreateNamedRenderTargetTextureEx", From 7f6c1918ceef7dc8db9bea2c3c812d45355c24b3 Mon Sep 17 00:00:00 2001 From: nanocat Date: Fri, 16 Jan 2026 21:26:17 +0100 Subject: [PATCH 2/9] same with datacache? --- TextmodeTF2/src/Core/Core.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 529753f..310b802 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -195,6 +195,8 @@ int CCore::LoadMDLCache() if (!G::IMDLCache) return LOAD_WAIT; + U::BytePatches.Initialize("datacache"); + if (!U::Hooks.Initialize("IMDLCache_ProcessDataIntoCache")) return LOAD_FAIL; @@ -285,4 +287,4 @@ void CCore::Unload() file << ssFailStream.str(); file.close(); return; -} \ No newline at end of file +} From f70e8f9e9f3b4df2136a834981fd3f14c1d9dbc8 Mon Sep 17 00:00:00 2001 From: nanocat Date: Sat, 17 Jan 2026 09:42:18 +0100 Subject: [PATCH 3/9] more bytepatches --- TextmodeTF2/src/BytePatches/BytePatches.h | 57 ++++++++++++++++++++- TextmodeTF2/src/Core/Core.cpp | 44 +++++++++++++++- TextmodeTF2/src/Core/Core.h | 4 +- TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp | 4 +- 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index 7705da8..f7d7d4a 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -148,7 +148,62 @@ class CBytePatches { // CDataCacheSection::Unlock CRASHFIX! BytePatch("datacache.dll", "48 89 5C 24 18 48 89 7C 24 20 41 56 48 83 EC 20 F6 81 E0 00 00 00 04", 0x41, "90 90 90 90 90"), - }} + }}, + {"studiorender", + { + // CStudioRender::DrawModelArray + BytePatch("studiorender.dll", "40 53 48 83 EC 20 48 8D 05 ? ? ? ? 48 8B D9", 0x0, "C3"), + + // CStudioRenderContext::AddShadows + BytePatch("studiorender.dll", "40 53 56 57 41 55 41 57 48 83 EC 30 48 8B 0D ? ? ? ?", 0x0, "C3"), + + // CStudioRenderContext (model rendering setup) + BytePatch("studiorender.dll", "4C 89 4C 24 20 48 89 4C 24 08 56 41 54 41 55 41 56 41 57 48 83 EC 70", 0x0, "C3"), + + // CStudioRenderContext (another model rendering path) + BytePatch("studiorender.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 44 89 4C 24 20 57 41 56 41 57 48 83 EC 40", 0x0, "C3"), + + // Disables bone setup only needed for drawing + BytePatch("studiorender.dll", "4C 89 44 24 18 48 89 54 24 10 48 89 4C 24 08 55 56 57 41 54 41 55 41 56 41 57 48 81 EC D0 00 00", 0x0, "31 C0 C3"), + }}, + {"vguimatsurface", + { + // PaintTraverse + BytePatch("vguimatsurface.dll", "40 57 48 83 EC 30 80 A1 ? ? ? ? 9F 48 8B F9", 0x0, "C3"), + + // DrawPrintText + BytePatch("vguimatsurface.dll", "44 89 4C 24 20 48 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00", 0x0, "C3"), + + // AddGlyphToCache + BytePatch("vguimatsurface.dll", "4C 89 4C 24 20 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC E0 00 00 00", 0x0, "31 C0 C3"), + + // FlushText + BytePatch("vguimatsurface.dll", "40 53 48 83 EC 30 83 B9 A8 03 01 00 00 48 8B D9", 0x0, "C3"), + }}, + // if something will start to crash i blame this at the first + {"shaderapidx9", + { + // Present + BytePatch("shaderapidx9.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57", 0x0, "C3"), + + // CreateTextures + BytePatch("shaderapidx9.dll", "44 89 4C 24 20 44 89 44 24 18 48 89 54 24 10 55", 0x0, "31 C0 C3"), + + // ModifyTexture + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 57 48 83 EC 50 48 8B 05", 0x0, "C3"), + + // CreateTextureHandles + BytePatch("shaderapidx9.dll", "4C 8B DC 56 41 55 48 81 EC 98 00 00 00 48 8B 05", 0x0, "C3"), + + // TexLock + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 6B 18 56 57 41 54 41", 0x0, "31 C0 C3"), + + // TexUnlock + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 73 18 57 48 83 EC 50", 0x0, "C3"), + + // CrashFix + BytePatch("shaderapidx9.dll", "40 53 55 57 41 56 41 57 48 83 EC 50 48 8B 81", 0x0, "C3"), + }}, }; }; diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 310b802..9e84089 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -203,6 +203,28 @@ int CCore::LoadMDLCache() return m_bMDLCacheLoaded = true; } +int CCore::LoadStudioRender() +{ + if (!GetModuleHandleA("studiorender.dll")) + return LOAD_WAIT; + + if (!U::BytePatches.Initialize("studiorender")) + return LOAD_WAIT; + + return m_bStudioRenderLoaded = true; +} + +int CCore::LoadVGuiMatSurface() +{ + if (!GetModuleHandleA("vguimatsurface.dll")) + return LOAD_WAIT; + + if (!U::BytePatches.Initialize("vguimatsurface")) + return LOAD_WAIT; + + return m_bVGuiMatSurfaceLoaded = true; +} + void CCore::Load() { G::CurrentPath = std::filesystem::current_path().string() + "\\TextmodeTF2"; @@ -239,7 +261,8 @@ void CCore::Load() m_bTimeout = GetModuleHandleA("filesystem_stdio.dll") && GetModuleHandleA("engine.dll") && GetModuleHandleA("materialsystem.dll") && - GetModuleHandleA("client.dll"); + GetModuleHandleA("client.dll") && + GetModuleHandleA("studiorender.dll"); int iFilesystem = m_bFilesystemLoaded ? 1 : LoadFilesystem(); CHECK(iFilesystem, "Failed to load file system") @@ -255,8 +278,25 @@ void CCore::Load() int iMDLCache = m_bMDLCacheLoaded ? 1 : LoadMDLCache(); CHECK(iMDLCache, "Failed to load MDL cache") + + int iStudioRender = m_bStudioRenderLoaded ? 1 : LoadStudioRender(); + CHECK(iStudioRender, "Failed to load Studio Render") + + int iVGuiMatSurface = m_bVGuiMatSurfaceLoaded ? 1 : LoadVGuiMatSurface(); + CHECK(iVGuiMatSurface, "Failed to load VGUI Mat Surface") + + if (!m_bShaderAPILoaded) + { + if (GetModuleHandleA("shaderapidx9.dll")) + { + if (U::BytePatches.Initialize("shaderapidx9")) + m_bShaderAPILoaded = true; + } + else if (m_bTimeout) + m_bShaderAPILoaded = true; + } } - while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded); + while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded || !m_bStudioRenderLoaded || !m_bShaderAPILoaded || !m_bVGuiMatSurfaceLoaded); SDK::Output("TextmodeTF2", std::format("Loaded in {} seconds", SDK::PlatFloatTime()).c_str()); } diff --git a/TextmodeTF2/src/Core/Core.h b/TextmodeTF2/src/Core/Core.h index 7441cee..bf4e4c5 100644 --- a/TextmodeTF2/src/Core/Core.h +++ b/TextmodeTF2/src/Core/Core.h @@ -17,7 +17,7 @@ class CCore bool m_bUnload = false; bool m_bTimeout = false; private: - bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false; + bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false, m_bStudioRenderLoaded = false, m_bShaderAPILoaded = false, m_bVGuiMatSurfaceLoaded = false; int LoadFilesystem(); int LoadEngine(); @@ -25,6 +25,8 @@ class CCore int LoadClient(); int LoadParticles(); int LoadMDLCache(); + int LoadStudioRender(); + int LoadVGuiMatSurface(); std::stringstream ssFailStream; }; diff --git a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp index 65d0921..facc3cd 100644 --- a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp +++ b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp @@ -180,13 +180,13 @@ static LONG APIENTRY ExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) try { std::ofstream file; - file.open(G::CurrentPath + "\\crash_log.txt", std::ios_base::app); + file.open("crash_log.txt", std::ios_base::app); file << ssErrorStream.str() + "\n\n\n"; file.close(); ssErrorStream << "\n"; ssErrorStream << "Ctrl + C to copy. \n"; - ssErrorStream << "Logged to TextmodeTF2\\crash_log.txt. "; + ssErrorStream << "Logged to crash_log.txt. "; } catch (...) {} From a2b165249e243dabaad8a608fd41955346995cc4 Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 04:19:50 +0100 Subject: [PATCH 4/9] Revert "more bytepatches" This reverts commit f70e8f9e9f3b4df2136a834981fd3f14c1d9dbc8. --- TextmodeTF2/src/BytePatches/BytePatches.h | 57 +-------------------- TextmodeTF2/src/Core/Core.cpp | 44 +--------------- TextmodeTF2/src/Core/Core.h | 4 +- TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp | 4 +- 4 files changed, 6 insertions(+), 103 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index f7d7d4a..7705da8 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -148,62 +148,7 @@ class CBytePatches { // CDataCacheSection::Unlock CRASHFIX! BytePatch("datacache.dll", "48 89 5C 24 18 48 89 7C 24 20 41 56 48 83 EC 20 F6 81 E0 00 00 00 04", 0x41, "90 90 90 90 90"), - }}, - {"studiorender", - { - // CStudioRender::DrawModelArray - BytePatch("studiorender.dll", "40 53 48 83 EC 20 48 8D 05 ? ? ? ? 48 8B D9", 0x0, "C3"), - - // CStudioRenderContext::AddShadows - BytePatch("studiorender.dll", "40 53 56 57 41 55 41 57 48 83 EC 30 48 8B 0D ? ? ? ?", 0x0, "C3"), - - // CStudioRenderContext (model rendering setup) - BytePatch("studiorender.dll", "4C 89 4C 24 20 48 89 4C 24 08 56 41 54 41 55 41 56 41 57 48 83 EC 70", 0x0, "C3"), - - // CStudioRenderContext (another model rendering path) - BytePatch("studiorender.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 44 89 4C 24 20 57 41 56 41 57 48 83 EC 40", 0x0, "C3"), - - // Disables bone setup only needed for drawing - BytePatch("studiorender.dll", "4C 89 44 24 18 48 89 54 24 10 48 89 4C 24 08 55 56 57 41 54 41 55 41 56 41 57 48 81 EC D0 00 00", 0x0, "31 C0 C3"), - }}, - {"vguimatsurface", - { - // PaintTraverse - BytePatch("vguimatsurface.dll", "40 57 48 83 EC 30 80 A1 ? ? ? ? 9F 48 8B F9", 0x0, "C3"), - - // DrawPrintText - BytePatch("vguimatsurface.dll", "44 89 4C 24 20 48 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00", 0x0, "C3"), - - // AddGlyphToCache - BytePatch("vguimatsurface.dll", "4C 89 4C 24 20 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC E0 00 00 00", 0x0, "31 C0 C3"), - - // FlushText - BytePatch("vguimatsurface.dll", "40 53 48 83 EC 30 83 B9 A8 03 01 00 00 48 8B D9", 0x0, "C3"), - }}, - // if something will start to crash i blame this at the first - {"shaderapidx9", - { - // Present - BytePatch("shaderapidx9.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57", 0x0, "C3"), - - // CreateTextures - BytePatch("shaderapidx9.dll", "44 89 4C 24 20 44 89 44 24 18 48 89 54 24 10 55", 0x0, "31 C0 C3"), - - // ModifyTexture - BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 57 48 83 EC 50 48 8B 05", 0x0, "C3"), - - // CreateTextureHandles - BytePatch("shaderapidx9.dll", "4C 8B DC 56 41 55 48 81 EC 98 00 00 00 48 8B 05", 0x0, "C3"), - - // TexLock - BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 6B 18 56 57 41 54 41", 0x0, "31 C0 C3"), - - // TexUnlock - BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 73 18 57 48 83 EC 50", 0x0, "C3"), - - // CrashFix - BytePatch("shaderapidx9.dll", "40 53 55 57 41 56 41 57 48 83 EC 50 48 8B 81", 0x0, "C3"), - }}, + }} }; }; diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 9e84089..310b802 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -203,28 +203,6 @@ int CCore::LoadMDLCache() return m_bMDLCacheLoaded = true; } -int CCore::LoadStudioRender() -{ - if (!GetModuleHandleA("studiorender.dll")) - return LOAD_WAIT; - - if (!U::BytePatches.Initialize("studiorender")) - return LOAD_WAIT; - - return m_bStudioRenderLoaded = true; -} - -int CCore::LoadVGuiMatSurface() -{ - if (!GetModuleHandleA("vguimatsurface.dll")) - return LOAD_WAIT; - - if (!U::BytePatches.Initialize("vguimatsurface")) - return LOAD_WAIT; - - return m_bVGuiMatSurfaceLoaded = true; -} - void CCore::Load() { G::CurrentPath = std::filesystem::current_path().string() + "\\TextmodeTF2"; @@ -261,8 +239,7 @@ void CCore::Load() m_bTimeout = GetModuleHandleA("filesystem_stdio.dll") && GetModuleHandleA("engine.dll") && GetModuleHandleA("materialsystem.dll") && - GetModuleHandleA("client.dll") && - GetModuleHandleA("studiorender.dll"); + GetModuleHandleA("client.dll"); int iFilesystem = m_bFilesystemLoaded ? 1 : LoadFilesystem(); CHECK(iFilesystem, "Failed to load file system") @@ -278,25 +255,8 @@ void CCore::Load() int iMDLCache = m_bMDLCacheLoaded ? 1 : LoadMDLCache(); CHECK(iMDLCache, "Failed to load MDL cache") - - int iStudioRender = m_bStudioRenderLoaded ? 1 : LoadStudioRender(); - CHECK(iStudioRender, "Failed to load Studio Render") - - int iVGuiMatSurface = m_bVGuiMatSurfaceLoaded ? 1 : LoadVGuiMatSurface(); - CHECK(iVGuiMatSurface, "Failed to load VGUI Mat Surface") - - if (!m_bShaderAPILoaded) - { - if (GetModuleHandleA("shaderapidx9.dll")) - { - if (U::BytePatches.Initialize("shaderapidx9")) - m_bShaderAPILoaded = true; - } - else if (m_bTimeout) - m_bShaderAPILoaded = true; - } } - while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded || !m_bStudioRenderLoaded || !m_bShaderAPILoaded || !m_bVGuiMatSurfaceLoaded); + while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded); SDK::Output("TextmodeTF2", std::format("Loaded in {} seconds", SDK::PlatFloatTime()).c_str()); } diff --git a/TextmodeTF2/src/Core/Core.h b/TextmodeTF2/src/Core/Core.h index bf4e4c5..7441cee 100644 --- a/TextmodeTF2/src/Core/Core.h +++ b/TextmodeTF2/src/Core/Core.h @@ -17,7 +17,7 @@ class CCore bool m_bUnload = false; bool m_bTimeout = false; private: - bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false, m_bStudioRenderLoaded = false, m_bShaderAPILoaded = false, m_bVGuiMatSurfaceLoaded = false; + bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false; int LoadFilesystem(); int LoadEngine(); @@ -25,8 +25,6 @@ class CCore int LoadClient(); int LoadParticles(); int LoadMDLCache(); - int LoadStudioRender(); - int LoadVGuiMatSurface(); std::stringstream ssFailStream; }; diff --git a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp index facc3cd..65d0921 100644 --- a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp +++ b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp @@ -180,13 +180,13 @@ static LONG APIENTRY ExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) try { std::ofstream file; - file.open("crash_log.txt", std::ios_base::app); + file.open(G::CurrentPath + "\\crash_log.txt", std::ios_base::app); file << ssErrorStream.str() + "\n\n\n"; file.close(); ssErrorStream << "\n"; ssErrorStream << "Ctrl + C to copy. \n"; - ssErrorStream << "Logged to crash_log.txt. "; + ssErrorStream << "Logged to TextmodeTF2\\crash_log.txt. "; } catch (...) {} From a10d58f53e8df480c39933a10e304c1838c2a1c6 Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 04:23:44 +0100 Subject: [PATCH 5/9] Revert "same with datacache?" This reverts commit 7f6c1918ceef7dc8db9bea2c3c812d45355c24b3. --- TextmodeTF2/src/Core/Core.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 310b802..529753f 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -195,8 +195,6 @@ int CCore::LoadMDLCache() if (!G::IMDLCache) return LOAD_WAIT; - U::BytePatches.Initialize("datacache"); - if (!U::Hooks.Initialize("IMDLCache_ProcessDataIntoCache")) return LOAD_FAIL; @@ -287,4 +285,4 @@ void CCore::Unload() file << ssFailStream.str(); file.close(); return; -} +} \ No newline at end of file From 6d1af14f4ff1c2714511225fe25b9629154947d2 Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 04:23:50 +0100 Subject: [PATCH 6/9] Revert "materialsystem bytepatches never actually ran" This reverts commit 39ecd9632bb69d1c95ab299f0b65b5566811925a. --- TextmodeTF2/src/BytePatches/BytePatches.h | 10 ++-------- TextmodeTF2/src/Core/Core.cpp | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index 7705da8..ad9b49e 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -58,12 +58,6 @@ class CBytePatches // Mod_LoadTexinfo // forces mat_loadtextures 0 logic to skip material loading BytePatch("engine.dll", "0F 84 ? ? ? ? 48 63 7E 44", 0x0, "90 E9"), - - // These SHOULD fix d3device failure - // CVideoMode_Common::CreateGameWindow - BytePatch("engine.dll", "48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20 41 56 48 83 EC 50 4C 8B F1 41 0F B6 F1 48 8D 0D ? ? ? ?", 0x0, "B0 01 C3"), - // CGame::CreateGameWindow - BytePatch("engine.dll", "40 55 53 56 57 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B F1 C6 45 D0 00 B9 40 00", 0x0, "B0 01 C3"), }}, {"materialsystem", { @@ -77,7 +71,7 @@ class CBytePatches // CMaterialSystem::FindMaterial // returns NULL for every material lookup - // BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), + BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), }}, {"client", { @@ -152,4 +146,4 @@ class CBytePatches }; }; -ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); +ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); \ No newline at end of file diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 529753f..e9e2971 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -141,7 +141,7 @@ int CCore::LoadMatSys() return LOAD_WAIT; I::MaterialSystem->SetInStubMode(true); - U::BytePatches.Initialize("materialsystem"); + static std::vector vMatSystemHooks { "IMaterialSystem_CreateRenderTargetTexture", "IMaterialSystem_CreateNamedRenderTargetTextureEx", From a15e51cfdb175f1abb37fc434dd96bd92d8ce23e Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 07:15:24 +0100 Subject: [PATCH 7/9] Reapply "materialsystem bytepatches never actually ran" This reverts commit 6d1af14f4ff1c2714511225fe25b9629154947d2. --- TextmodeTF2/src/BytePatches/BytePatches.h | 10 ++++++++-- TextmodeTF2/src/Core/Core.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index ad9b49e..7705da8 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -58,6 +58,12 @@ class CBytePatches // Mod_LoadTexinfo // forces mat_loadtextures 0 logic to skip material loading BytePatch("engine.dll", "0F 84 ? ? ? ? 48 63 7E 44", 0x0, "90 E9"), + + // These SHOULD fix d3device failure + // CVideoMode_Common::CreateGameWindow + BytePatch("engine.dll", "48 89 5C 24 10 48 89 74 24 18 48 89 7C 24 20 41 56 48 83 EC 50 4C 8B F1 41 0F B6 F1 48 8D 0D ? ? ? ?", 0x0, "B0 01 C3"), + // CGame::CreateGameWindow + BytePatch("engine.dll", "40 55 53 56 57 41 57 48 8D AC 24 ? ? ? ? 48 81 EC ? ? ? ? 48 8B F1 C6 45 D0 00 B9 40 00", 0x0, "B0 01 C3"), }}, {"materialsystem", { @@ -71,7 +77,7 @@ class CBytePatches // CMaterialSystem::FindMaterial // returns NULL for every material lookup - BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), + // BytePatch("materialsystem.dll", "48 8B F9 48 8B CA 49 8B D8 FF 10 4C 8B C0 48 8D 15 ? ? ? ? 48 8D 4C 24 20", 0x0, "31 C0 C3"), }}, {"client", { @@ -146,4 +152,4 @@ class CBytePatches }; }; -ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); \ No newline at end of file +ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U); diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index e9e2971..529753f 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -141,7 +141,7 @@ int CCore::LoadMatSys() return LOAD_WAIT; I::MaterialSystem->SetInStubMode(true); - + U::BytePatches.Initialize("materialsystem"); static std::vector vMatSystemHooks { "IMaterialSystem_CreateRenderTargetTexture", "IMaterialSystem_CreateNamedRenderTargetTextureEx", From e8fb2405311b5cb4d7455297a8ff5cf7e5e2ebbd Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 07:15:26 +0100 Subject: [PATCH 8/9] Reapply "same with datacache?" This reverts commit a10d58f53e8df480c39933a10e304c1838c2a1c6. --- TextmodeTF2/src/Core/Core.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 529753f..310b802 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -195,6 +195,8 @@ int CCore::LoadMDLCache() if (!G::IMDLCache) return LOAD_WAIT; + U::BytePatches.Initialize("datacache"); + if (!U::Hooks.Initialize("IMDLCache_ProcessDataIntoCache")) return LOAD_FAIL; @@ -285,4 +287,4 @@ void CCore::Unload() file << ssFailStream.str(); file.close(); return; -} \ No newline at end of file +} From 537b6ab54fe808d1fe14f5b42775e61c7eff5239 Mon Sep 17 00:00:00 2001 From: nanocat Date: Sun, 18 Jan 2026 07:15:28 +0100 Subject: [PATCH 9/9] Reapply "more bytepatches" This reverts commit a2b165249e243dabaad8a608fd41955346995cc4. --- TextmodeTF2/src/BytePatches/BytePatches.h | 57 ++++++++++++++++++++- TextmodeTF2/src/Core/Core.cpp | 44 +++++++++++++++- TextmodeTF2/src/Core/Core.h | 4 +- TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp | 4 +- 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/TextmodeTF2/src/BytePatches/BytePatches.h b/TextmodeTF2/src/BytePatches/BytePatches.h index 7705da8..f7d7d4a 100644 --- a/TextmodeTF2/src/BytePatches/BytePatches.h +++ b/TextmodeTF2/src/BytePatches/BytePatches.h @@ -148,7 +148,62 @@ class CBytePatches { // CDataCacheSection::Unlock CRASHFIX! BytePatch("datacache.dll", "48 89 5C 24 18 48 89 7C 24 20 41 56 48 83 EC 20 F6 81 E0 00 00 00 04", 0x41, "90 90 90 90 90"), - }} + }}, + {"studiorender", + { + // CStudioRender::DrawModelArray + BytePatch("studiorender.dll", "40 53 48 83 EC 20 48 8D 05 ? ? ? ? 48 8B D9", 0x0, "C3"), + + // CStudioRenderContext::AddShadows + BytePatch("studiorender.dll", "40 53 56 57 41 55 41 57 48 83 EC 30 48 8B 0D ? ? ? ?", 0x0, "C3"), + + // CStudioRenderContext (model rendering setup) + BytePatch("studiorender.dll", "4C 89 4C 24 20 48 89 4C 24 08 56 41 54 41 55 41 56 41 57 48 83 EC 70", 0x0, "C3"), + + // CStudioRenderContext (another model rendering path) + BytePatch("studiorender.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 44 89 4C 24 20 57 41 56 41 57 48 83 EC 40", 0x0, "C3"), + + // Disables bone setup only needed for drawing + BytePatch("studiorender.dll", "4C 89 44 24 18 48 89 54 24 10 48 89 4C 24 08 55 56 57 41 54 41 55 41 56 41 57 48 81 EC D0 00 00", 0x0, "31 C0 C3"), + }}, + {"vguimatsurface", + { + // PaintTraverse + BytePatch("vguimatsurface.dll", "40 57 48 83 EC 30 80 A1 ? ? ? ? 9F 48 8B F9", 0x0, "C3"), + + // DrawPrintText + BytePatch("vguimatsurface.dll", "44 89 4C 24 20 48 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC C0 00 00 00", 0x0, "C3"), + + // AddGlyphToCache + BytePatch("vguimatsurface.dll", "4C 89 4C 24 20 89 54 24 10 55 56 57 41 54 41 55 41 56 41 57 48 81 EC E0 00 00 00", 0x0, "31 C0 C3"), + + // FlushText + BytePatch("vguimatsurface.dll", "40 53 48 83 EC 30 83 B9 A8 03 01 00 00 48 8B D9", 0x0, "C3"), + }}, + // if something will start to crash i blame this at the first + {"shaderapidx9", + { + // Present + BytePatch("shaderapidx9.dll", "48 89 5C 24 08 48 89 6C 24 10 48 89 74 24 18 57", 0x0, "C3"), + + // CreateTextures + BytePatch("shaderapidx9.dll", "44 89 4C 24 20 44 89 44 24 18 48 89 54 24 10 55", 0x0, "31 C0 C3"), + + // ModifyTexture + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 57 48 83 EC 50 48 8B 05", 0x0, "C3"), + + // CreateTextureHandles + BytePatch("shaderapidx9.dll", "4C 8B DC 56 41 55 48 81 EC 98 00 00 00 48 8B 05", 0x0, "C3"), + + // TexLock + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 6B 18 56 57 41 54 41", 0x0, "31 C0 C3"), + + // TexUnlock + BytePatch("shaderapidx9.dll", "4C 8B DC 49 89 5B 10 49 89 73 18 57 48 83 EC 50", 0x0, "C3"), + + // CrashFix + BytePatch("shaderapidx9.dll", "40 53 55 57 41 56 41 57 48 83 EC 50 48 8B 81", 0x0, "C3"), + }}, }; }; diff --git a/TextmodeTF2/src/Core/Core.cpp b/TextmodeTF2/src/Core/Core.cpp index 310b802..9e84089 100644 --- a/TextmodeTF2/src/Core/Core.cpp +++ b/TextmodeTF2/src/Core/Core.cpp @@ -203,6 +203,28 @@ int CCore::LoadMDLCache() return m_bMDLCacheLoaded = true; } +int CCore::LoadStudioRender() +{ + if (!GetModuleHandleA("studiorender.dll")) + return LOAD_WAIT; + + if (!U::BytePatches.Initialize("studiorender")) + return LOAD_WAIT; + + return m_bStudioRenderLoaded = true; +} + +int CCore::LoadVGuiMatSurface() +{ + if (!GetModuleHandleA("vguimatsurface.dll")) + return LOAD_WAIT; + + if (!U::BytePatches.Initialize("vguimatsurface")) + return LOAD_WAIT; + + return m_bVGuiMatSurfaceLoaded = true; +} + void CCore::Load() { G::CurrentPath = std::filesystem::current_path().string() + "\\TextmodeTF2"; @@ -239,7 +261,8 @@ void CCore::Load() m_bTimeout = GetModuleHandleA("filesystem_stdio.dll") && GetModuleHandleA("engine.dll") && GetModuleHandleA("materialsystem.dll") && - GetModuleHandleA("client.dll"); + GetModuleHandleA("client.dll") && + GetModuleHandleA("studiorender.dll"); int iFilesystem = m_bFilesystemLoaded ? 1 : LoadFilesystem(); CHECK(iFilesystem, "Failed to load file system") @@ -255,8 +278,25 @@ void CCore::Load() int iMDLCache = m_bMDLCacheLoaded ? 1 : LoadMDLCache(); CHECK(iMDLCache, "Failed to load MDL cache") + + int iStudioRender = m_bStudioRenderLoaded ? 1 : LoadStudioRender(); + CHECK(iStudioRender, "Failed to load Studio Render") + + int iVGuiMatSurface = m_bVGuiMatSurfaceLoaded ? 1 : LoadVGuiMatSurface(); + CHECK(iVGuiMatSurface, "Failed to load VGUI Mat Surface") + + if (!m_bShaderAPILoaded) + { + if (GetModuleHandleA("shaderapidx9.dll")) + { + if (U::BytePatches.Initialize("shaderapidx9")) + m_bShaderAPILoaded = true; + } + else if (m_bTimeout) + m_bShaderAPILoaded = true; + } } - while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded); + while (!m_bFilesystemLoaded || !m_bEngineLoaded || !m_bMatSysLoaded || !m_bClientLoaded || !m_bParticlesLoaded || !m_bMDLCacheLoaded || !m_bStudioRenderLoaded || !m_bShaderAPILoaded || !m_bVGuiMatSurfaceLoaded); SDK::Output("TextmodeTF2", std::format("Loaded in {} seconds", SDK::PlatFloatTime()).c_str()); } diff --git a/TextmodeTF2/src/Core/Core.h b/TextmodeTF2/src/Core/Core.h index 7441cee..bf4e4c5 100644 --- a/TextmodeTF2/src/Core/Core.h +++ b/TextmodeTF2/src/Core/Core.h @@ -17,7 +17,7 @@ class CCore bool m_bUnload = false; bool m_bTimeout = false; private: - bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false; + bool m_bFilesystemLoaded = false, m_bEngineLoaded = false, m_bMatSysLoaded = false, m_bClientLoaded = false, m_bParticlesLoaded = false, m_bMDLCacheLoaded = false, m_bStudioRenderLoaded = false, m_bShaderAPILoaded = false, m_bVGuiMatSurfaceLoaded = false; int LoadFilesystem(); int LoadEngine(); @@ -25,6 +25,8 @@ class CCore int LoadClient(); int LoadParticles(); int LoadMDLCache(); + int LoadStudioRender(); + int LoadVGuiMatSurface(); std::stringstream ssFailStream; }; diff --git a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp index 65d0921..facc3cd 100644 --- a/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp +++ b/TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp @@ -180,13 +180,13 @@ static LONG APIENTRY ExceptionFilter(PEXCEPTION_POINTERS ExceptionInfo) try { std::ofstream file; - file.open(G::CurrentPath + "\\crash_log.txt", std::ios_base::app); + file.open("crash_log.txt", std::ios_base::app); file << ssErrorStream.str() + "\n\n\n"; file.close(); ssErrorStream << "\n"; ssErrorStream << "Ctrl + C to copy. \n"; - ssErrorStream << "Logged to TextmodeTF2\\crash_log.txt. "; + ssErrorStream << "Logged to crash_log.txt. "; } catch (...) {}