Skip to content

Commit

Permalink
Merge pull request pnill#469 from Berthalamew/objects
Browse files Browse the repository at this point in the history
add first person definitions + other misc additions
  • Loading branch information
nukeulater authored Nov 21, 2023
2 parents 1f5cd0b + 7553475 commit 7be9d66
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 65 deletions.
10 changes: 10 additions & 0 deletions xlive/Blam/Engine/cseries/cseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ static_assert(sizeof(real64) == 8);
typedef long datum;
static_assert(sizeof(datum) == 4);

#define SIZEOF_BITS(value) 8 * sizeof(value)
#define CHAR_BITS SIZEOF_BITS(int8)
#define SHORT_BITS SIZEOF_BITS(int16)
#define LONG_BITS SIZEOF_BITS(int32)

// Invokes a function
// ADDR_CLIENT: file offset in halo2.exe
// ADDR_SERVER: file offset in h2server.exe
Expand Down Expand Up @@ -100,6 +105,11 @@ static_assert(sizeof(datum) == 4);
#define SWAP_FLAG(flags, bit) ( (flags) ^=FLAG(bit) )
#define FLAG_RANGE(first_bit, last_bit) ( (FLAG( (last_bit)+1 - (first_bit) )-1) << (first_bit) )

#define BIT_VECTOR_SIZE_IN_LONGS(BIT_COUNT) (((BIT_COUNT) + (LONG_BITS - 1)) / LONG_BITS)
#define BIT_VECTOR_SIZE_IN_BYTES(BIT_COUNT) (4 * BIT_VECTOR_SIZE_IN_LONGS(BIT_COUNT))
#define BIT_VECTOR_TEST_FLAG(BIT_VECTOR, BIT) (TEST_BIT(BIT_VECTOR[BIT / LONG_BITS], (BIT & (LONG_BITS - 1))))
#define BIT_VECTOR_SET_FLAG(BIT_VECTOR, BIT, ENABLE) (SET_FLAG(BIT_VECTOR[BIT / LONG_BITS], (BIT & (LONG_BITS - 1)), ENABLE))

/// Creates a mask out of a count number of flags
#define MASK(count) ( (unsigned)(1 << (count)) - (unsigned)1 )

Expand Down
41 changes: 37 additions & 4 deletions xlive/Blam/Engine/interface/first_person_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,35 @@

bool show_first_person = true;

typedef bool(__cdecl* render_first_person_check_t)(e_skull_type skull_type);
s_first_person_weapon* first_person_weapon_get_global(void)
{
return *Memory::GetAddress<s_first_person_weapon**>(0x977104, 0x99FBC4);
}

s_first_person_weapon* first_person_weapons_get(uint32 user_index)
{
return &first_person_weapon_get_global()[user_index];
}

s_first_person_orientations* first_person_orientations_get_global(void)
{
return *Memory::GetAddress<s_first_person_orientations**>(0x977100, 0x99FBC0);
}

s_first_person_orientations* first_person_orientations_get(uint32 user_index, uint32 weapon_slot)
{
return &first_person_orientations_get_global()[(k_first_person_max_weapons * user_index) + weapon_slot];
}

s_first_person_model_data* first_person_model_data_get_global(void)
{
return Memory::GetAddress<s_first_person_model_data*>(0x4E8F48, 0x50EDF0);
}

s_first_person_model_data* first_person_model_data_get(uint32 user_index)
{
return &first_person_model_data_get_global()[user_index];
}

bool __cdecl render_first_person_check(e_skull_type skull_type)
{
Expand All @@ -16,11 +44,16 @@ bool __cdecl render_first_person_check(e_skull_type skull_type)
void toggle_first_person(bool state)
{
show_first_person = state;
return;
}

void first_person_weapons_apply_patches()
{
if (Memory::IsDedicatedServer()) { return; }
// Only patch if not a dedi
if (!Memory::IsDedicatedServer())
{
PatchCall(Memory::GetAddress(0x228579), render_first_person_check);
}

PatchCall(Memory::GetAddress<render_first_person_check_t>(0x228579), render_first_person_check);
}
return;
}
84 changes: 84 additions & 0 deletions xlive/Blam/Engine/interface/first_person_weapons.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,88 @@
#pragma once
#include "Blam/Engine/animations/animation_manager.h"
#include "Blam/Engine/math/matrix_math.h"

#define MAXIMUM_NODES_PER_FIRST_PERSON_MODEL 64
#define k_first_person_max_weapons 2

enum e_first_person_weapon_data_flags : uint32
{
_weapon_node_table_valid_bit = 1,
_arm_node_table_valid_bit = 2,
};

struct s_first_person_model_data
{
datum render_model_tag_index;
datum object_index;
uint32 flags;
real_matrix4x3 nodes[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
};

struct s_first_person_weapon_slot
{
e_first_person_weapon_data_flags flags;
datum weapon_index;
c_animation_manager base_animation_manager;
int8 gap_90[12]; // unused? maybe a real_point3d?
c_animation_channel move_animation_channel;
c_animation_channel jitter_animation_channel;
c_animation_id pitch_and_turn_animation_id;
c_animation_id overlay_animation_id;
c_animation_id ammo_animation_id;
real32 field_E4;
real32 field_E8;
int16 field_EC;
int16 maybe_framerate;
int16 field_F0;
int16 field_F2;
int32 weapon_node_remapping_table_count;
int32 hands_node_remapping_table_count;
int32 weapon_node_remapping_table[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
int32 hands_node_remapping_table[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
int16 child_node_index;
int16 alternate_parent_node_index;
int32 node_orientations_count;
int32 animation_graph_node_count;
real_matrix4x3 nodes[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
datum sound_source_index;
int16 field_1004;
int16 pad;
};
CHECK_STRUCT_SIZE(s_first_person_weapon_slot, 4112);

struct s_first_person_weapon
{
uint32 flags;
datum unit_index;
int32 character_type;
s_first_person_weapon_slot weapons[k_first_person_max_weapons];
c_interpolator_control rate_interpolator_control;
real_euler_angles2d pos;
real_euler_angles2d field_2038;
real_euler_angles2d turn;
real_euler_angles2d field_2048;
real_euler_angles2d player_facing;
real_euler_angles2d field_2058;
real_matrix4x3 identity_matrix;
int32 adjustment_matrix_index;
real_matrix4x3 matrix_2098;
};
CHECK_STRUCT_SIZE(s_first_person_weapon, 8396);

struct s_first_person_orientations
{
real_orientation weapon_orientations[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
real_orientation hand_orientations[MAXIMUM_NODES_PER_FIRST_PERSON_MODEL];
};
CHECK_STRUCT_SIZE(s_first_person_orientations, 4096);

s_first_person_weapon* first_person_weapon_get_global(void);
s_first_person_weapon* first_person_weapons_get(uint32 user_index);
s_first_person_orientations* first_person_orientations_get_global(void);
s_first_person_orientations* first_person_orientations_get(uint32 user_index, uint32 weapon_slot);
s_first_person_model_data* first_person_model_data_get_global(void);
s_first_person_model_data* first_person_model_data_get(uint32 user_index);

void toggle_first_person(bool state);
void first_person_weapons_apply_patches();
62 changes: 62 additions & 0 deletions xlive/Blam/Engine/memory/static_arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,65 @@ class c_flags
protected:
t_storage_type m_storage;
};

template<size_t k_maximum_count>
class c_static_flags_no_init
{
public:
void* clear(void)
{
return csmemset(this->m_flags, 0, NUMBEROF(m_flags));
}

void* clear_range(int32 count)
{
return csmemset(this->m_flags, 0, BIT_VECTOR_SIZE_IN_BYTES(count));
}

void* fill(int32 count, uint8 value)
{
return csmemset(this->m_flags, value, BIT_VECTOR_SIZE_IN_BYTES(count));
}

const int32* get_bits_direct(void) const
{
return m_flags;
}

int32* get_writeable_bits_direct(void)
{
return m_flags;
}

void set(int32 index, bool enable)
{
BIT_VECTOR_SET_FLAG(this->m_flags, index, enable);
return;
}

void* set_bits_direct_destructive(int32 count, uint8 value)
{
return csmemcpy(this->m_flags, value, BIT_VECTOR_SIZE_IN_BYTES(count));
}

bool test(int32 index)
{
return BIT_VECTOR_TEST_FLAG(this->m_flags, index);
}

protected:
int32 m_flags[k_maximum_count / LONG_BITS];
};

template<size_t k_maximum_count>
class c_static_flags : public c_static_flags_no_init<k_maximum_count>
{
public:
c_static_flags(void) = default;
c_static_flags(int32 count, uint8 value)
{
fill(count, value);
return;
}
~c_static_flags(void) = default;
};
12 changes: 6 additions & 6 deletions xlive/Blam/Engine/objects/object_early_movers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ struct s_early_mover_data
{
real_point3d origin;
real_point3d position;
real_vector3d vector0;
real_vector3d vector1;
real_vector3d vector2;
real_vector3d linear_velocity_copy;
real_vector3d linear_velocity;
real_vector3d angular_velocity_copy;
real_vector3d angular_velocity;
real_matrix4x3 matrix0;
real_matrix4x3 matrix1;
real_matrix4x3 matrix2;
real_matrix4x3 transform_copy;
real_matrix4x3 transform;
real_matrix4x3 inverse_transform;
bool some_bool;
bool another_bool;
};
Expand Down
5 changes: 3 additions & 2 deletions xlive/Blam/Engine/objects/object_placement.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ enum e_scenario_object_placement_flags : uint32
_scenario_object_placement_bit_7 = 7,
_scenario_object_placement_bit_8 = 8,
_scenario_object_placement_bit_9 = 9,
_scenario_object_placement_bit_10 = 10
_scenario_object_placement_bit_10 = 10,
k_scenario_object_placement_flags
};

struct object_placement_data
Expand All @@ -46,7 +47,7 @@ struct object_placement_data
e_bsp_policy placement_policy;
BYTE unk_15;
WORD unk_16;
c_flags<e_scenario_object_placement_flags, uint32, 11> flags;
c_flags<e_scenario_object_placement_flags, uint32, k_scenario_object_placement_flags> flags;
real_point3d position;
real_vector3d forward;
real_vector3d up;
Expand Down
Loading

0 comments on commit 7be9d66

Please sign in to comment.