Skip to content
Open

xd #3

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 64 additions & 3 deletions TextmodeTF2/src/BytePatches/BytePatches.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
{
Expand All @@ -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",
{
Expand Down Expand Up @@ -142,8 +148,63 @@ 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"),
}},
};
};

ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U);
ADD_FEATURE_CUSTOM(CBytePatches, BytePatches, U);
50 changes: 46 additions & 4 deletions TextmodeTF2/src/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ int CCore::LoadMatSys()
return LOAD_WAIT;

I::MaterialSystem->SetInStubMode(true);

U::BytePatches.Initialize("materialsystem");
static std::vector<const char*> vMatSystemHooks
{
"IMaterialSystem_CreateRenderTargetTexture", "IMaterialSystem_CreateNamedRenderTargetTextureEx",
Expand Down Expand Up @@ -195,12 +195,36 @@ int CCore::LoadMDLCache()
if (!G::IMDLCache)
return LOAD_WAIT;

U::BytePatches.Initialize("datacache");

if (!U::Hooks.Initialize("IMDLCache_ProcessDataIntoCache"))
return LOAD_FAIL;

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";
Expand Down Expand Up @@ -237,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")
Expand All @@ -253,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());
}
Expand Down Expand Up @@ -285,4 +327,4 @@ void CCore::Unload()
file << ssFailStream.str();
file.close();
return;
}
}
4 changes: 3 additions & 1 deletion TextmodeTF2/src/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ 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();
int LoadMatSys();
int LoadClient();
int LoadParticles();
int LoadMDLCache();
int LoadStudioRender();
int LoadVGuiMatSurface();

std::stringstream ssFailStream;
};
Expand Down
4 changes: 2 additions & 2 deletions TextmodeTF2/src/Utils/CrashLog/CrashLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (...) {}

Expand Down