From 5b5effa96449ae11ed5faf66cca12a3e96143ee0 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 7 Jan 2024 11:45:03 +0100 Subject: [PATCH] DataCache: rework datacache invalid data handling This is a more reliable solution as pretty much all code patch in CMDLCache checks the ptr for NULL, but none of them do for 0xDEADFEEDDEADFEED (probably a debug only thing that somehow made it into this build). Patched out so the engine could deal with it properly. Anything interesting already gets logged from the SDK so we won't miss out on anything patching this out. --- src/resource/patch/r5apex.patch | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/resource/patch/r5apex.patch b/src/resource/patch/r5apex.patch index f416006b..ed57e30c 100644 --- a/src/resource/patch/r5apex.patch +++ b/src/resource/patch/r5apex.patch @@ -44,17 +44,14 @@ // screen. This satisfies the required memory size to render all 120 player models (active players on server). 0xE6530: "mov r8d, 200000h" -// This patch prevents a crash in 'CMDLCache::GetStudioHardwareForLODRange()' when attempting to dereference -// an invalid studiocache handle (0xDEADFEEDDEADFEED). An inline assembly patch was easier to implement than -// rebuilding the function. -0x1E6EFD: "jmp 0x000000014129518A" // Jump to codecave. -// NOTE: stored in RCX as past this code block, this register was only written to before any reads!!! -0x129458A: "mov rcx, 0xDEADFEEDDEADFEED" // Store 'DC_INVALID_HANDLE' immediate in register. -0x1294594: "cmp rax, rcx" // Compare RAX (studiocache pointer) to 'DC_INVALID_HANDLE'. -0x1294597: "je 0x00000001401E7B0E" // If pointer equals, jump and skip all studiocache dereference operations. -0x129459D: "mov rax, qword ptr ds:[rax+0x8]" // Recovered instructions overwritten by long jump to codecave. -0x12945A1: "inc ebx" // Recovered instructions overwritten by long jump to codecave. -0x12945A3: "jmp 0x00000001401E7B03" // Jump back to original code; use studiocache pointer. +// This patch assigns the model and anim cache pointers to NULL instead of 0xDEADFEEDDEADFEED, +// if the asset failed to load. The 0xDEADFEEDDEADFEED (DC_INVALID_HANDLE) assignment was most +// likely done to catch errors in the asset loading system, since the pointer test won't fail +// while the pointer is invalid, this cause a hard crash. We however don't want this as this +// would cause issues loading BSP's with missing assets (the SDK handles the errors properly +// and also logs what was failed to load). +0x1E3CB6: "xor rax, rax" // NULL RAX instead of mov'ing '0xDEADFEEDDEADFEED' to cache ptr in 'Pak_UpdateModelAsset()' +0x1E3EE2: "xor rax, rax" // NULL RAX instead of mov'ing '0xDEADFEEDDEADFEED' to cache ptr in 'Pak_UpdateAnimRigAsset()' ///////////////////////////// /////////////////////////////