diff --git a/build.bat b/build.bat index 458e343..5591577 100644 --- a/build.bat +++ b/build.bat @@ -4,6 +4,9 @@ setlocal EnableDelayedExpansion set CONFIG=%1 if "%CONFIG%"=="" set CONFIG=Release +if "%CONFIG:~0,1%"=="/" set CONFIG=%CONFIG:~1% +if "%CONFIG:~0,1%"=="-" set CONFIG=%CONFIG:~1% + if defined VCINSTALLDIR goto :env_ready set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" if not exist "%VSWHERE%" set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" diff --git a/include/debug.inc b/include/debug.inc new file mode 100644 index 0000000..2dd1e47 --- /dev/null +++ b/include/debug.inc @@ -0,0 +1,33 @@ +IFDEF DEBUG + +EXTERNDEF Logger_LogInfo :PROC +EXTERNDEF Logger_LogWarn :PROC +EXTERNDEF Logger_LogError :PROC + +LOG_DBG MACRO sym + lea rcx, sym + call Logger_LogInfo +ENDM + +LOG_WARN MACRO sym + lea rcx, sym + call Logger_LogWarn +ENDM + +LOG_ERR MACRO sym + lea rcx, sym + call Logger_LogError +ENDM + +ELSE ; Release - all macros are empty + +LOG_DBG MACRO sym +ENDM + +LOG_WARN MACRO sym +ENDM + +LOG_ERR MACRO sym +ENDM + +ENDIF \ No newline at end of file diff --git a/include/master.inc b/include/master.inc index 4e3c4cf..69c05a2 100644 --- a/include/master.inc +++ b/include/master.inc @@ -1,4 +1,5 @@ INCLUDE include\enums.inc INCLUDE include\macros.inc INCLUDE include\structs.inc -INCLUDE include\externs.inc \ No newline at end of file +INCLUDE include\externs.inc +INCLUDE include\debug.inc \ No newline at end of file diff --git a/logger.asm b/logger.asm index e2fbb43..ddaaa71 100644 --- a/logger.asm +++ b/logger.asm @@ -1,5 +1,7 @@ INCLUDE include\master.inc +IFDEF DEBUG + EXTRN printf :PROC EXTRN GetLocalTime :PROC EXTRN GetModuleFileNameA :PROC @@ -27,7 +29,6 @@ szFmtInfo DB "[INFO] [%02d:%02d:%02d.%03d] %s", 0Ah, 0 szFmtWarn DB "[WARN] [%02d:%02d:%02d.%03d] %s", 0Ah, 0 szFmtError DB "[ERROR] [%02d:%02d:%02d.%03d] %s", 0Ah, 0 szFmtFatal DB "[FATAL] [%02d:%02d:%02d.%03d] %s", 0Ah, 0 -szLogPath DB "C:\raider_debug.txt", 0 .data? @@ -40,7 +41,7 @@ Logger_hFile QWORD ? ; GetModuleFileNameA(NULL,...)) and appending "raider_debug.txt", ; then opens that file with CREATE_ALWAYS. Using the EXE directory ; -; Frame: 0 pushes + sub 148h = 328; 328 mod 16 = 8; RSP = 0 +; Frame: 0 pushes + sub 148h = 328; 328 mod 16 = 8; RSP = 0 ; [rsp+000..+01F] shadow (32) ; [rsp+020..+027] CreateFileA 5th arg: dwCreationDisposition ; [rsp+028..+02F] CreateFileA 6th arg: dwFlagsAndAttributes @@ -129,7 +130,7 @@ Logger_Shutdown ENDP ; Logger__Print (internal) ; Writes a timestamped log line to the console (printf) and, -; if the file handle is valid, also to C:\raider_debug.txt with +; if the file handle is valid, also to raider_debug.txt with ; an immediate FlushFileBuffers so no data is lost on crash. ; ; In: RCX = format string* (one of szFmtInfo/Warn/Error/Fatal) @@ -153,11 +154,11 @@ Logger__Print PROC mov QWORD PTR [rsp+40h], rdx ; save msg* mov QWORD PTR [rsp+48h], rcx ; save fmt* - ; ---- GetLocalTime ---- + ; GetLocalTime lea rcx, [rsp+30h] call GetLocalTime - ; ---- Console: printf(fmt, H, M, S, ms, msg) ---- + ; Console: printf(fmt, H, M, S, ms, msg) mov rcx, QWORD PTR [rsp+48h] movzx edx, WORD PTR [rsp+30h + ST_wHour] movzx r8d, WORD PTR [rsp+30h + ST_wMinute] @@ -168,7 +169,7 @@ Logger__Print PROC mov QWORD PTR [rsp+28h], rax ; 6th arg: msg* call printf - ; ---- File: skip if handle invalid ---- + ; File: skip if handle invalid mov rcx, QWORD PTR [Logger_hFile] test rcx, rcx jz @@skip_file @@ -251,7 +252,7 @@ Logger_LogFatal ENDP ; Logger_LogInfoFmt(RCX=fmt*, RDX/R8/R9/stack=args) ; Console-only printf passthrough (variadic - can't redirect to file). -; Frame: 0 pushes + sub 28h; RSP = 0 +; Frame: 0 pushes + sub 28h; RSP = 0 Logger_LogInfoFmt PROC sub rsp, 28h call printf @@ -259,4 +260,38 @@ Logger_LogInfoFmt PROC ret Logger_LogInfoFmt ENDP +ELSE ; Release build - all logger functions are single-instruction stubs + +.code + +Logger_Initialize PROC + ret +Logger_Initialize ENDP + +Logger_Shutdown PROC + ret +Logger_Shutdown ENDP + +Logger_LogInfo PROC + ret +Logger_LogInfo ENDP + +Logger_LogWarn PROC + ret +Logger_LogWarn ENDP + +Logger_LogError PROC + ret +Logger_LogError ENDP + +Logger_LogFatal PROC + ret +Logger_LogFatal ENDP + +Logger_LogInfoFmt PROC + ret +Logger_LogInfoFmt ENDP + +ENDIF + END \ No newline at end of file diff --git a/native.asm b/native.asm index 3f42fb7..ba800a9 100644 --- a/native.asm +++ b/native.asm @@ -14,6 +14,15 @@ szNatErr_InitHost DB "[NATIVE] OnlineBeaconHost::InitHost not found", 0 szNatErr_ProcessEvent DB "[NATIVE] ProcessEvent vtable resolve failed (null engine)", 0 szNatOk DB "[NATIVE] InitializeAll complete", 0 +IFDEF DEBUG +szNatDbg_Start DB "[NATIVE] InitializeAll starting", 0 +szNatDbg_FNameToString DB "[NATIVE] FNameToString found", 0 +szNatDbg_GObjects DB "[NATIVE] GObjects found", 0 +szNatDbg_Malloc DB "[NATIVE] FMemory::Malloc found", 0 +szNatDbg_TickFlush DB "[NATIVE] NetDriver::TickFlush found", 0 +szNatDbg_ProcessEvent DB "[NATIVE] ProcessEvent resolved", 0 +ENDIF + .code ; Native_InitializeAll() @@ -22,9 +31,11 @@ szNatOk DB "[NATIVE] InitializeAll complete", 0 Native_InitializeAll PROC push rbp push rbx - sub rsp, 40 ; shadow space; RSP = 0 mod 16 at all CALLs + sub rsp, 40 ; shadow space; RSP ≡ 0 mod 16 at all CALLs - xor ecx, ecx ; lpModuleName = NULL -> returns base of .exe + LOG_DBG szNatDbg_Start + + xor ecx, ecx ; lpModuleName = NULL → returns base of .exe call GetModuleHandleA mov QWORD PTR [Imagebase], rax @@ -35,7 +46,10 @@ Native_InitializeAll PROC call Utils_FindPattern mov QWORD PTR [FNameToString], rax test rax, rax - jnz @@ok_FNameToString + jz @@err_FNameToString + LOG_DBG szNatDbg_FNameToString + jmp @@ok_FNameToString +@@err_FNameToString: lea rcx, szNatErr_FNameToString call Logger_LogError @@ok_FNameToString: @@ -47,7 +61,10 @@ Native_InitializeAll PROC call Utils_FindPattern mov QWORD PTR [GObjects], rax test rax, rax - jnz @@ok_GObjects + jz @@err_GObjects + LOG_DBG szNatDbg_GObjects + jmp @@ok_GObjects +@@err_GObjects: lea rcx, szNatErr_GObjects call Logger_LogError @@ok_GObjects: @@ -59,7 +76,10 @@ Native_InitializeAll PROC call Utils_FindPattern mov QWORD PTR [FMemory_Malloc], rax test rax, rax - jnz @@ok_Malloc + jz @@err_Malloc + LOG_DBG szNatDbg_Malloc + jmp @@ok_Malloc +@@err_Malloc: lea rcx, szNatErr_Malloc call Logger_LogError @@ok_Malloc: @@ -95,7 +115,10 @@ Native_InitializeAll PROC call Utils_FindPattern mov QWORD PTR [Native_NetDriver_TickFlush], rax test rax, rax - jnz @@ok_TickFlush + jz @@err_TickFlush + LOG_DBG szNatDbg_TickFlush + jmp @@ok_TickFlush +@@err_TickFlush: lea rcx, szNatErr_TickFlush call Logger_LogError @@ok_TickFlush: @@ -127,7 +150,7 @@ Native_InitializeAll PROC xor r8d, r8d call Utils_FindPattern mov QWORD PTR [Native_OnlineBeacon_PauseBeaconRequests], rax - ; Also store in the host-specific slot - same function pointer + ; Also store in the host-specific slot — same function pointer mov QWORD PTR [Native_OnlineBeaconHost_PauseBeaconRequests], rax ; OnlineBeacon::NotifyAcceptingConnection (direct) @@ -273,6 +296,7 @@ Native_InitializeAll PROC mov rax, QWORD PTR [rax] ; load vtable pointer from engine object mov rax, QWORD PTR [rax + 200h] ; slot 0x40 (64 * 8 = 0x200) mov QWORD PTR [ProcessEvent], rax + LOG_DBG szNatDbg_ProcessEvent jmp @@pe_done @@err_PE: @@ -280,6 +304,7 @@ Native_InitializeAll PROC call Logger_LogError @@pe_done: + lea rcx, szNatOk call Logger_LogInfo diff --git a/raider.asm b/raider.asm index f10bbbb..eb77928 100644 --- a/raider.asm +++ b/raider.asm @@ -10,6 +10,18 @@ szInitHooks DB "Initializing hooks!", 0 szFailNetDebug DB "Failed to find NetDebug", 0 szBaseAddrFmt DB "[INFO] Base Address: 0x%I64X", 0Ah, 0 +IFDEF DEBUG +szDbgUFHooks DB "[DEBUG] UFunctionHooks initialized", 0 +szDbgDetourBegin DB "[DEBUG] Detour transaction started", 0 +szDbgAtchTickFlush DB "[DEBUG] Attached Hooks_TickFlush", 0 +szDbgAtchSpawnPA DB "[DEBUG] Attached Hooks_LocalPlayerSpawnPlayActor", 0 +szDbgAtchNetDebug DB "[DEBUG] Attached Hooks_NetDebug", 0 +szDbgAtchProcEvent DB "[DEBUG] Attached Hooks_ProcessEventHook", 0 +szDbgAtchViewPt DB "[DEBUG] Attached Hooks_GetPlayerViewPoint", 0 +szDbgDetourCommit DB "[DEBUG] Detours transaction committed", 0 +szDbgConsoleCreated DB "[DEBUG] SDK console created", 0 +ENDIF + .data @@ -45,8 +57,10 @@ Main PROC call Native_InitializeAll call UFunctionHooks_Initialize + LOG_DBG szDbgUFHooks call DetourTransactionBegin + LOG_DBG szDbgDetourBegin call GetCurrentThread mov rcx, rax @@ -55,10 +69,12 @@ Main PROC lea rcx, Native_NetDriver_TickFlush lea rdx, Hooks_TickFlush call DetourAttach + LOG_DBG szDbgAtchTickFlush lea rcx, Native_LocalPlayer_SpawnPlayActor lea rdx, Hooks_LocalPlayerSpawnPlayActor call DetourAttach + LOG_DBG szDbgAtchSpawnPA lea rcx, Pat_NetDebug xor edx, edx ; bRelative = false @@ -80,6 +96,7 @@ Main PROC lea rcx, QWORD PTR [rbp - 8] lea rdx, Hooks_NetDebug call DetourAttach + LOG_DBG szDbgAtchNetDebug lea rcx, ProcessEvent lea rdx, Hooks_ProcessEventHook @@ -88,14 +105,17 @@ Main PROC lea rcx, Native_PlayerController_GetPlayerViewPoint lea rdx, Hooks_GetPlayerViewPoint call DetourAttach + LOG_DBG szDbgAtchViewPt call DetourTransactionCommit + LOG_DBG szDbgDetourCommit lea rcx, szBaseAddrFmt mov rdx, QWORD PTR [Imagebase] call printf call SDK_CreateConsole + LOG_DBG szDbgConsoleCreated xor eax, eax ; return 0 (DWORD thread exit code) diff --git a/ufunctionhooks.asm b/ufunctionhooks.asm index 4f9cc30..a6443a0 100644 --- a/ufunctionhooks.asm +++ b/ufunctionhooks.asm @@ -96,8 +96,11 @@ szFn_OnRep_DeathInfo DB "Function FortniteGame.FortPlayerStateAth szHookCount DB "[UFHOOKS] Registered %d UFunction hooks", 0Ah, 0 -.code +IFDEF DEBUG +szUFDbg_Start DB "[UFHOOKS] Starting UFunction hook registration", 0 +ENDIF +.code PEHOOK_CheatScript PROC xor al, al ; return 0 @@ -1314,6 +1317,7 @@ UFunctionHooks_Initialize PROC push r12 sub rsp, 40 ; 5 pushes: RSP=8; sub40 -> 0 + LOG_DBG szUFDbg_Start ; Set public pointers to internal storage lea rax, _ToHook_Storage mov QWORD PTR [UFunctionHooks_ToHook_Data], rax