Skip to content

Commit

Permalink
Added trg print detouring
Browse files Browse the repository at this point in the history
  • Loading branch information
krystalgamer committed Nov 10, 2023
1 parent 96c9ee2 commit f5b8eb0
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion texture_loader/loader.c
Expand Up @@ -17,7 +17,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID reserverd){

if(fdwReason == DLL_PROCESS_ATTACH){

#if DEBUG
#ifdef _DEBUG
AllocateConsole();
#endif

Expand Down
15 changes: 15 additions & 0 deletions texture_loader/log.c
Expand Up @@ -18,6 +18,21 @@ void DebugPrintf(const char* format, ...) {
printf(output_string);
}

void DebugPrintfWithNewLine(const char* format, ...) {

static char output_string[1024];
memset(output_string, 0, sizeof(output_string));

va_list args;
va_start(args, format);

vsnprintf(output_string, sizeof(output_string), format, args);

OutputDebugStringA(output_string);
printf(output_string);
puts("");
}

void DebugPuts(const char* str) {
OutputDebugStringA(str);
puts(str);
Expand Down
1 change: 1 addition & 0 deletions texture_loader/log.h
Expand Up @@ -2,6 +2,7 @@
#define LOG_H

void DebugPrintf(const char* format, ...);
void DebugPrintfWithNewLine(const char* format, ...);
void DebugPuts(const char* str);

#endif LOG_H
4 changes: 4 additions & 0 deletions texture_loader/new_ep.c
Expand Up @@ -142,6 +142,10 @@ static BOOL ApplyMyPatches(const Settings *settings){
DO_OR_QUIT(UnlockEverything());
}

#ifdef _DEBUG
TestingGround();
#endif

return TRUE;
}

Expand Down
41 changes: 41 additions & 0 deletions texture_loader/patches.c
Expand Up @@ -425,3 +425,44 @@ BOOL UnlockEverything() {
DebugPuts("Unlocking everything");
return ActivateCheat(1) == 1;
}


/************************************************
Testing ground
************************************************/


__declspec(naked) void MyPrinterDetour() {
__asm {
mov eax, [esp]
cmp eax, 0x004E0210
jl LeavePrinter
cmp eax, 0x004E2BAE
jg LeavePrinter
mov eax, [esp+4]
cmp eax, 0x0053B000
jl LeavePrinter
cmp eax, 0x002E0C000
jg LeavePrinter
jmp DebugPrintfWithNewLine

LeavePrinter:
ret
}
}

BOOL TestingGround() {
DebugPuts("TESTING GROUND");

unsigned char jmpAndRet[6] = {
0x68, 0x00, 0x00, 0x00, 0x00,
0xc3
};

*(DWORD*)&jmpAndRet[1] = (DWORD)&MyPrinterDetour;
SetMemory(0x004015B0, sizeof(jmpAndRet), jmpAndRet, "Replacing printf_if_false with mine to print ExecuteCommandList calls");

return TRUE;
}
1 change: 1 addition & 0 deletions texture_loader/patches.h
Expand Up @@ -12,5 +12,6 @@ BOOL TextureLoader();
BOOL ModOptions();
BOOL FixBugs();
BOOL UnlockEverything();
BOOL TestingGround();

#endif

0 comments on commit f5b8eb0

Please sign in to comment.