Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions xlive/Blam/Engine/camera/first_person_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "observer.h"

#include "cache/cache_files.h"
#include "game/game.h"
#include "game/game_globals.h"
#include "game/players.h"
#include "game/player_control.h"
Expand Down Expand Up @@ -114,9 +115,19 @@ static void __cdecl first_person_camera_update(int8* camera, s_director_update*
// New method to override the crosshair offset using carto profiles
if (true)
{
s_saved_game_cartographer_player_profile* player_profile = cartographer_player_profile_get_by_user_index(director_update->user_index);
result->crosshair_position.x = 0.f;
result->crosshair_position.y = player_profile->crosshair_offset;
s_game_variant* variant = get_game_variant();

if (game_is_multiplayer() && variant && variant->cartographer_settings.flags.test(_cartographer_variant_force_default_cross_hair_offset))
{
result->crosshair_position = k_observer_default_cross_hair_position;
}
else
{
s_saved_game_cartographer_player_profile* player_profile = cartographer_player_profile_get_by_user_index(director_update->user_index);

result->crosshair_position.x = k_observer_default_cross_hair_position.x;
result->crosshair_position.y = player_profile->crosshair_offset;
}
}
// Original method of setting the crosshair position
else
Expand Down
8 changes: 8 additions & 0 deletions xlive/Blam/Engine/camera/following_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "camera_track_definition.h"
#include "director.h"
#include "observer.h"
#include "game/game.h"
#include "game/game_globals.h"
#include "game/player_control.h"
#include "saved_games/cartographer_player_profile/cartographer_player_profile.h"
Expand Down Expand Up @@ -151,6 +152,13 @@ void __cdecl following_camera_player_control_get_camera_info(int32 user_index, s
real32 following_camera_get_default_camera_field_of_view()
{
s_saved_game_cartographer_player_profile* player_profile = cartographer_player_profile_get_by_user_index(updating_user_index);
s_game_variant* variant = get_game_variant();

if (game_is_multiplayer() && variant && variant->cartographer_settings.flags.test(_cartographer_variant_force_default_fov))
{
return DEGREES_TO_RADIANS(78.f);
}

return DEGREES_TO_RADIANS(player_profile->vehicle_field_of_view);
}

Expand Down
18 changes: 14 additions & 4 deletions xlive/Blam/Engine/camera/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "cutscene/cinematics.h"
#include "effects/player_effects.h"
#include "game/game.h"
#include "game/game_time.h"
#include "game/players.h"
#include "interface/first_person_weapons.h"
Expand All @@ -14,7 +15,6 @@
#include "scenario/scenario.h"
#include "shell/shell.h"

#include "H2MOD/Modules/CustomVariantSettings/CustomVariantSettings.h"

/* constants */

Expand Down Expand Up @@ -132,14 +132,24 @@ void observer_set_suggested_field_of_view(real32 fov)
if (fov <= 0 || fov > 110) return;

float final_fov_rad;
if (currentVariantSettings.forced_fov == 0)

if (game_is_multiplayer())
{
final_fov_rad = DEGREES_TO_RADIANS(fov);
s_game_variant* variant = get_game_variant();
if (variant && variant->cartographer_settings.flags.test(_cartographer_variant_force_default_fov))
{
final_fov_rad = DEGREES_TO_RADIANS(78.f);
}
else
{
final_fov_rad = DEGREES_TO_RADIANS(fov);
}
}
else
{
final_fov_rad = DEGREES_TO_RADIANS(currentVariantSettings.forced_fov);
final_fov_rad = DEGREES_TO_RADIANS(fov);
}

*Memory::GetAddress<float*>(0x413780, 0x3B5300) = final_fov_rad;
return;
}
Expand Down
2 changes: 2 additions & 0 deletions xlive/Blam/Engine/camera/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/* constants */

constexpr real_point2d k_observer_default_cross_hair_position{ {0.f, 0.138f} };
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a constant instead of constexpr

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constantexpr in this context is the same as constant.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's duplicated in 2 TUs right now, keep it as a constant assigned in the cpp file and have it as an extern in the header


enum
{
k_observer_command_values = 6
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/cseries/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct s_async_completion
bool unk_1;
bool unk_2;
bool unk_3;
int32 unk_4;
int32 creation_result;
char file_path[2048];
real32 unk_808;
};
Expand Down
23 changes: 23 additions & 0 deletions xlive/Blam/Engine/cseries/cseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ static_assert(sizeof(real64) == 8);
typedef long datum;
static_assert(sizeof(datum) == 4);

// 32-bit file storage identifier
typedef int32 enumerated_file_index;
static_assert(sizeof(enumerated_file_index) == 4);

// 32-bit character that's specified as a utf32 string
struct utf32
{
Expand Down Expand Up @@ -92,6 +96,12 @@ extern bool g_catch_exceptions;
#define VALID_INDEX(index, count) ((index) >= 0 && (index) < (count))
#define VALID_COUNT(index, count) ((index) >= 0 && (index) <= (count))

#define ENUMERATED_INDEX_IS_DEFAULT_SAVE(enumerated_file_index) (((enumerated_file_index) & 0x200000) != 0)
#define ENUMERATED_INDEX_GET_TYPE(enumerated_file_index) (e_saved_game_file_type)(((enumerated_file_index) & 0xF) >> 0)
#define ENUMERATED_INDEX_GET_ABS_INDEX(enumerated_file_index) (((enumerated_file_index) & 0x1FFF00) >> 8)
#define ENUMERATED_INDEX_GET_MEMORY_UNIT(enumerated_file_index) (((enumerated_file_index) & 0xF0) >> 4)
#define ENUMERATED_INDEX_GET_SALT(enumerated_file_index) (((enumerated_file_index) & 0x7FC000 ) >> 14)

// TODO remove padding macros
// Explanation:
// Harder to debug memory with it since types dont show up in the watch view
Expand Down Expand Up @@ -247,3 +257,16 @@ int32 csstrncmp(const char* s1, const char* s2, size_t size);

// Convert string to lowercase
char* csstrnlwr(char* s, size_t size);

constexpr uint32 bits_required_for(uint64 max_value)
{
// minimum of 1 bit for 1 and 0

uint32 bits = 1;
while (max_value > 1)
{
max_value >>= 1;
++bits;
}
return bits;
}
16 changes: 16 additions & 0 deletions xlive/Blam/Engine/filesys/pc_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ bool __cdecl pc_file_system_get_drive_letter_for_type(e_pc_file_system_type type
return INVOKE(0x8F1FE, 0, pc_file_system_get_drive_letter_for_type, type, buffer);
}

char* pc_file_system_get_saved_games_location(char* out_path, int16 buffer_size)
{
// invoking by type to remove unused parameter
return INVOKE_TYPE(0x3E43E, 0, char* (__cdecl*)(int32, char*, int16), 0, out_path, buffer_size);
}

int32 __cdecl pc_file_system_delete_save_directory(CHAR* flat_file_path, wchar_t* save_file_name)
{
return INVOKE(0x9CB52, 0, pc_file_system_delete_save_directory, flat_file_path, save_file_name);
}

bool __cdecl pc_file_system_check_disk_free_space(uint32 size)
{
return INVOKE(0x3E705, 0, pc_file_system_check_disk_free_space, size);
}

void pc_file_system_apply_hooks()
{
//DETOUR_ATTACH(p_pc_file_system_create_directory_hierarchy, Memory::GetAddress<t_pc_file_system_create_directory_hierarchy>(0x8EF9E), pc_file_system_create_directory_hierarchy);
Expand Down
3 changes: 3 additions & 0 deletions xlive/Blam/Engine/filesys/pc_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ s_pc_file_type_save_path_info* pc_file_system_get_save_path_info(e_pc_file_syste

void file_seek_and_read(FILE* file_handle, uint32 file_offset, uint32 read_size, uint32 read_count, void* out_buffer);
bool __cdecl pc_file_system_get_drive_letter_for_type(e_pc_file_system_type type, wchar_t* buffer);
char* __cdecl pc_file_system_get_saved_games_location(char* out_path, int16 buffer_size);
int32 __cdecl pc_file_system_delete_save_directory(CHAR* flat_file_path, wchar_t* save_file_name);
bool __cdecl pc_file_system_check_disk_free_space(uint32 size);

void pc_file_system_apply_hooks();
8 changes: 8 additions & 0 deletions xlive/Blam/Engine/filesys/pc_saved_game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "stdafx.h"
#include "pc_saved_game.h"

int32 pc_saved_game_get_next_available_save_location(char* flat_path, wchar_t* full_display_name, int32 unk_1, int32 unk_2,
wchar_t* wide_path, int32 wide_path_size)
{
return INVOKE(0x9C8D7, 0, pc_saved_game_get_next_available_save_location, flat_path, full_display_name, unk_1, unk_2, wide_path, wide_path_size);
}
4 changes: 3 additions & 1 deletion xlive/Blam/Engine/filesys/pc_saved_game.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once

#define k_max_save_game_fs_slot 32768
#define save_game_max_name 128
#define save_game_max_name 128

int32 __cdecl pc_saved_game_get_next_available_save_location(char* flat_path, wchar_t* full_display_name, int32 unk_1, int32 unk_2, wchar_t* wide_path, int32 wide_path_size);
7 changes: 6 additions & 1 deletion xlive/Blam/Engine/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ bool game_in_editor(void)
return false;
}

bool game_is_finished()
{
return get_main_game_globals()->game_is_finished;
}

bool game_is_campaign(void)
{
return game_options_get()->game_mode == _game_mode_campaign;
Expand Down Expand Up @@ -509,7 +514,7 @@ static void game_info_initialize_for_new_map(const s_game_options* options)

if (game_is_multiplayer() || game_globals->options.game_variant.variant_game_engine_index)
{
game_engine_variant_cleanup(&game_globals->options.game_variant.flags);
game_variant_cleanup(&game_globals->options.game_variant);
}
random_math_set_seed(game_globals->options.random_seed);
game_globals->game_is_lost = false;
Expand Down
1 change: 1 addition & 0 deletions xlive/Blam/Engine/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ s_game_options* game_options_get(void);
s_game_variant* current_game_variant(void);
e_game_mode game_mode_get(void);
bool game_in_editor(void);
bool game_is_finished();
int16 game_get_active_structure_bsp_index();
bool game_is_campaign(void);
bool game_is_multiplayer(void);
Expand Down
1 change: 1 addition & 0 deletions xlive/Blam/Engine/game/game_allegiance.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum e_game_team : int16
_game_team_neutral = 8,

k_game_multiplayer_team_count = 8,
k_game_simulation_team_count = 9,

// SP
_game_team_default = 0,
Expand Down
51 changes: 45 additions & 6 deletions xlive/Blam/Engine/game/game_engine.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
#include "stdafx.h"
#include "game_engine.h"

#include "game_engine_default.h"
#include "game_engine_headhunter.h"
#include "saved_games/game_variant.h"
#include "saved_games/player_profile.h"

/* public code */

void game_engine_apply_patches()
{
// todo: server offset
PatchCall(Memory::GetAddress(0x1B1E38, 0x197E62), game_engine_get_simulation_protocol);
if (Memory::g_memory_is_dedicated_server)
{
PatchCall(Memory::GetAddress(0, 0x197DF1), game_engine_get_simulation_protocol);
}

game_engine_list_set(_game_engine_type_headhunter, get_global_headhunter_engine_instance());
//game_engine_list_set(_game_engine_type_headhunter, get_game_mode_engines()[_game_engine_type_koth]);
}

c_game_engine* current_game_engine(void)
{
return get_game_mode_engines()[game_engine_globals_get()->game_engine_index];
s_game_engine_globals* game_engine_globals = game_engine_globals_get();

ASSERT(game_engine_globals);

c_game_engine* engine = get_game_mode_engines()[game_engine_globals->game_engine_index];

return engine;
}

s_game_engine_globals* game_engine_globals_get(void)
Expand All @@ -23,6 +47,21 @@ c_game_engine** get_game_mode_engines()
return Memory::GetAddress<c_game_engine**>(0x4D8548, 0x4F3CE4);
}

void game_engine_list_set(e_game_engine_type type, c_game_engine* engine)
{
Memory::GetAddress<c_game_engine**>(0x4D8548, 0x4F3CE4)[type] = engine;
}

e_network_game_simulation_protocol game_engine_get_simulation_protocol(s_game_variant* variant)
{
e_network_game_simulation_protocol result = _network_game_simulation_protocol_synchronous;

if (IN_RANGE(variant->variant_game_engine_index, _game_engine_type_ctf, k_game_engine_playable_types))
result = _network_game_simulation_protocol_distributed;

return result;
}

c_game_engine* get_slayer_engine()
{
return get_game_mode_engines()[_game_engine_type_slayer];
Expand All @@ -40,11 +79,6 @@ bool __cdecl game_engine_get_change_colors(s_player_profile* player_profile, e_g
return INVOKE(0x6E5C3, 0x6D1BF, game_engine_get_change_colors, player_profile, team_index, change_colors);
}

bool __cdecl game_engine_variant_cleanup(uint16* flags)
{
return INVOKE(0x5B720, 0x3D380, game_engine_variant_cleanup, flags);
}

void __cdecl game_engine_player_activated(datum player_index)
{
INVOKE(0x6A29E, 0x69CB6, game_engine_player_activated, player_index);
Expand Down Expand Up @@ -73,3 +107,8 @@ void __cdecl game_engine_render(void)
INVOKE(0x6A60F, 0x0, game_engine_render);
return;
}

void __cdecl game_engine_adjust_score(int32 player_index, int32 amount)
{
INVOKE(0x70E13, 0x6F914, game_engine_adjust_score, player_index, amount);
}
Loading