Skip to content

Commit

Permalink
fix dead camera referencing "de-allocated" stack for the node position
Browse files Browse the repository at this point in the history
  • Loading branch information
nukeulater committed Dec 30, 2023
1 parent 1894f71 commit 12e9379
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
34 changes: 33 additions & 1 deletion xlive/Blam/Engine/camera/dead_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,40 @@
#include "Blam/Engine/objects/objects.h"
#include "Util/Hooks/Hook.h"

real_point3d* __cdecl object_try_and_get_interpolated_position(datum object_index, int16 node_index, real_point3d* out_pos)
{
real_matrix4x3 out_mat = *object_try_get_node_matrix_interpolated(object_index, node_index, &out_mat);
*out_pos = out_mat.position;
return out_pos;
}

__declspec(naked) void object_try_get_node_position_interpolated_intermediate()
{
#define current_stack_offset (2Ch + 4h + 4h)
__asm
{
// grab the out position mem address at 0x0C
mov eax, [esp + 4 + current_stack_offset + 0Ch]
add eax, 4 // go to position offset
push eax
// grab the rest of the parameters
mov eax, [esp + 4 + 4 + 4]
push eax // node index
mov eax, [esp + 4 + 4 + 4]
push eax // object index
call object_try_and_get_interpolated_position
add esp, 4 * 3
// copy ptr of the data in esi
mov esi, [esp + 4 + current_stack_offset + 0Ch]
retn
}
#undef current_stack_offset (0Ch)
}

void apply_dead_camera_patches()
{
// Patch call inside dead_camera update to try and get interpolated node matrix from the current target_datum
PatchCall(Memory::GetAddress(0xCDBAE), object_try_get_node_matrix_interpolated);
PatchCall(Memory::GetAddress(0xCDBAE), object_try_get_node_position_interpolated_intermediate);
// nop the rest of the unneeded instructions
NopFill(Memory::GetAddress(0xCDBB3), 22);
}
7 changes: 3 additions & 4 deletions xlive/Blam/Engine/objects/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,11 @@ real_matrix4x3* object_get_node_matrix(datum object_index, int16 node_index)
return &nodes[node_index];
}

real_matrix4x3* object_try_get_node_matrix_interpolated(datum object_index, int16 node_index)
real_matrix4x3* object_try_get_node_matrix_interpolated(datum object_index, int16 node_index, real_matrix4x3* out_mat)
{
real_matrix4x3 result;
if (halo_interpolator_interpolate_object_node_matrix(object_index, node_index, &result))
if (halo_interpolator_interpolate_object_node_matrix(object_index, node_index, out_mat))
{
return &result;
return out_mat;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/objects/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void object_get_origin_interpolated(datum object_index, real_point3d* point_out)

real_matrix4x3* object_get_node_matrix(datum object_datum, int16 node_index);

real_matrix4x3* object_try_get_node_matrix_interpolated(datum object_index, int16 node_index);
real_matrix4x3* object_try_get_node_matrix_interpolated(datum object_index, int16 node_index, real_matrix4x3* out_mat);

real_matrix4x3* object_get_node_matrices(datum object_datum, int32* out_node_count);

Expand Down

0 comments on commit 12e9379

Please sign in to comment.