Skip to content

Commit

Permalink
[Sonic Frontiers] Disable Decelerate Collision: hook rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperbx committed Oct 8, 2024
1 parent 5ce7a3f commit bd92a5f
Showing 1 changed file with 7 additions and 56 deletions.
63 changes: 7 additions & 56 deletions Source/Sonic Frontiers/Physics/Disable Decelerate Collision.hmm
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,16 @@ Patch "Disable Decelerate Collision" in "Physics" by "Hyper" does
/*
Disables the collision flag that kills all horizontal velocity when jumping.

Example usage;
Examples;
- The bridge in Kronos above the river.
- The cliffsides in Ares.
*/
//
static int Seek = 0;
//
{
fixed (int* pSeek = &Seek)
{
WriteAsmHook
(
$@"
mov r14, qword ptr [rsp + 0x48 + 0xFFFFFFFFFFFFFFD8]
mov rdi, qword ptr [rsp + 0x48 + 0xFFFFFFFFFFFFFFE0]
mov rsi, qword ptr [rsp + 0x48 + 0xFFFFFFFFFFFFFFE8]
push rbx
push rcx
push rdx
push r11
push r15
mov rdx, {(long)pSeek}
mov rbx, rax
mov rbx, [rbx] ; dereference pointer to collision info map [int64, int32]
test rbx, rbx ; check if null
jz exit
mov ecx, dword ptr [rbx + 8] ; store vertex count
imul ecx, 4 ; multiply vertex count by 4 to get an appropriate iteration size
mov rbx, [rbx] ; dereference pointer to collision info
iterate:
cmp dword ptr [rdx], ecx ; iterate through vertices to set info for each
jge exit
mov r15d, dword ptr [rdx] ; store current iteration
mov r11, rbx
add r11, r15 ; add offset to address
mov r15d, dword ptr [r11] ; store current collision info for modification
and r15d, 0xFFFFFDFF ; clear 9th bit
mov dword ptr [r11], r15d ; store modified collision info in original array
add dword ptr [rdx], 4 ; increment by 4 (32-bit integers)
jmp iterate
exit:
mov dword ptr [rdx], 0 ; reset incrementation
pop r15
pop r11
pop rdx
pop rcx
pop rbx
",

/* 0x140A9FBF3 */
ScanSignature
(
"\x4C\x8B\x74\x24\x20\x48\x8B\x7C\x24\x28\x48\x8B\x74\x24\x30\x48\x8B\x00",
"xxxxxxxxxxxxxxxxxx"
),

HookBehavior.Replace
);
}
}
// v1.41: 0x14089A44F
var sig = ScanSignature("\x89\x41\x34\x8B\x42\x38\x89\x41\x38\x8B\x42\x3C\x89\x41\x3C\x0F\xB6\x42\x40\x88\x41\x40\x48\x8B\xC1", "xxxxxxxxxxxxxxxxxxxxxxxxx");

if (sig == 0)
return;

WriteAsmHook("and eax, 0xFFFFFDFF", sig, HookBehavior.After);
}

0 comments on commit bd92a5f

Please sign in to comment.