Skip to content

Commit

Permalink
Merge pull request pnill#455 from Berthalamew/objects
Browse files Browse the repository at this point in the history
fix update issues
  • Loading branch information
nukeulater authored Oct 19, 2023
2 parents e391509 + a079a48 commit d8183b5
Show file tree
Hide file tree
Showing 22 changed files with 248 additions and 215 deletions.
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/Networking/Session/NetworkSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ unsigned long long NetworkSession::GetPlayerId(int playerIdx)

int NetworkSession::GetPlayerTeam(int playerIdx)
{
return GetPlayerInformation(playerIdx)->properties[0].player_team;
return GetPlayerInformation(playerIdx)->properties[0].team_index;
}

int NetworkSession::GetPeerIndexFromId(unsigned long long xuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ bool __stdcall c_simulation_object_entity_definition__object_setup_placement_dat
object_placement_data_new(placement_data, object_creation_data->object_definition_index, NONE, 0);
placement_data->object_placement_flags |= 0x12u;
placement_data->emblem_info = object_creation_data->emblem_info;
if (TEST_FLAG(*flags, 1))
if (TEST_BIT(*flags, 1))
{
placement_data->position = state_data->position;
*flags &= ~FLAG(1);
}
if (TEST_FLAG(*flags, 2))
if (TEST_BIT(*flags, 2))
{
placement_data->forward = state_data->forward;
placement_data->up = state_data->up;
*flags &= ~FLAG(2);
}
if (TEST_FLAG(*flags, 3))
if (TEST_BIT(*flags, 3))
{
placement_data->scale = state_data->scale;
*flags &= ~FLAG(3);
}
if (TEST_FLAG(*flags, 4))
if (TEST_BIT(*flags, 4))
{
placement_data->translational_velocity = state_data->translational_velocity;
*flags &= ~FLAG(4);
}
if (TEST_FLAG(*flags, 5))
if (TEST_BIT(*flags, 5))
{
placement_data->angular_velocity = state_data->angular_velocity;
*flags &= ~FLAG(5);
Expand Down
3 changes: 2 additions & 1 deletion xlive/Blam/Engine/cseries/cseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ static_assert(sizeof(datum) == 4);

/// Use this for setting up enum bitfields
#define FLAG(bit)( 1<<(bit) )
#define TEST_FLAG(flags, bit)( ((flags) & FLAG(bit)) != 0 )
#define TEST_BIT(flags, bit)( ((flags) & FLAG(bit)) != 0 )
#define TEST_FLAG(flags, flag)( ((flags) & (flag)) != 0 )
#define SET_FLAG(flags, bit, value)( (value) ? ((flags) |= FLAG(bit)) : ((flags) &= ~FLAG(bit)) )
#define SWAP_FLAG(flags, bit) ( (flags) ^=FLAG(bit) )
#define FLAG_RANGE(first_bit, last_bit) ( (FLAG( (last_bit)+1 - (first_bit) )-1) << (first_bit) )
Expand Down
5 changes: 5 additions & 0 deletions xlive/Blam/Engine/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ bool game_in_progress(void)
return get_main_game_globals() && get_main_game_globals()->game_in_progress;
}

bool game_is_authoritative(void)
{
return game_options_get()->simulation_type != _game_simulation_distributed_client;
}

void game_options_setup_default_players(int player_count, s_game_options* game_options)
{
typedef void(__cdecl* cache_file_map_clear_all_failures_t)(int, s_game_options*);
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 @@ -40,6 +40,7 @@ bool game_is_multiplayer(void);
bool game_is_ui_shell(void);
bool game_in_progress(void);
bool game_is_predicted(void);
bool game_is_authoritative(void);

// Setup default player data in the game options structure
void game_options_setup_default_players(int player_count, s_game_options* game_options);
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/game/game_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "game_engine.h"

s_game_engine_globals* s_game_engine_globals::get()
s_game_engine_globals* game_engine_globals_get(void)
{
return *Memory::GetAddress<s_game_engine_globals**>(0x4BF8F8, 0x4EA028);
}
Expand Down
14 changes: 8 additions & 6 deletions xlive/Blam/Engine/game/game_engine.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once
#include "Blam/Engine/game/game_statborg.h"
#include "game_statborg.h"
#include "Blam/Engine/Networking/Session/NetworkSession.h"

#define k_maximum_game_engine_event_responses_per_type 128

enum e_valid_multiplayer_games : short
Expand Down Expand Up @@ -80,7 +82,7 @@ struct s_game_engine_globals
short team_flags;
WORD field_6;
WORD field_8;
WORD flags_A;
uint16 team_bitmask;
WORD field_C;
short field_E;
WORD field_10;
Expand All @@ -92,18 +94,16 @@ struct s_game_engine_globals
short field_6C;
DWORD field_70;
DWORD gap_74[28];
float unk_local_player_hud_field[4];
real32 unk_local_player_hud_field[k_number_of_users];
byte field_F4;
byte pad_F5[4];
byte gapF9[523];
c_game_statborg game_statborg;
s_game_engine_global_player_info player_info[16];
s_game_engine_global_player_info player_info[k_maximum_players];
DWORD ticks;
BYTE gap71C[1336];
DWORD game_engine_index;
BYTE gapC58[132];

static s_game_engine_globals* get();
};
CHECK_STRUCT_SIZE(s_game_engine_globals, 0xCDC);

Expand Down Expand Up @@ -164,4 +164,6 @@ struct s_multiplayer_event_response_definition
};
TAG_BLOCK_SIZE_ASSERT(s_multiplayer_event_response_definition, 0xA8);

s_game_engine_globals* game_engine_globals_get(void);

bool __cdecl game_engine_get_change_colors(s_player_profile* player_profile, e_game_team team_index, real_color_rgb* change_colors);
157 changes: 144 additions & 13 deletions xlive/Blam/Engine/game/players.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
#include "stdafx.h"
#include "players.h"

#include "Blam/Engine/game/game.h"
#include "Blam/Engine/game/game_engine.h"
#include "Blam/Engine/game/game_engine_util.h"
#include "Blam/Engine/game/game_globals.h"
#include "Blam/Engine/saved_games/game_variant.h"
#include "Blam/Engine/scenario/scenario.h"

#include "H2MOD/Modules/Shell/Config.h"

/*
- TO NOTE:
- This functions work only after the game has started (game life cycle is in_game or after map has been loaded).
- If you need to do something in the pregame lobby, use the functions available in Network Session (H2MOD/Modules/Networking/NetworkSession)
- If you need to do something in the pregame lobby, use the functions available in Network Session (Blam/Networking/Session)
*/

s_data_array* s_player::GetArray()
Expand Down Expand Up @@ -32,7 +41,7 @@ e_game_team s_player::GetTeam(int playerIndex)
{
return (e_game_team)NONE;
}
return (e_game_team)GetPlayer(playerIndex)->properties[0].player_team;
return (e_game_team)GetPlayer(playerIndex)->properties[0].team_index;
}

void s_player::SetTeam(int playerIndex, e_game_team team)
Expand All @@ -41,7 +50,7 @@ void s_player::SetTeam(int playerIndex, e_game_team team)
{
return;
}
GetPlayer(playerIndex)->properties[0].player_team = (byte)team;
GetPlayer(playerIndex)->properties[0].team_index = (int8)team;
}

void s_player::SetUnitBipedType(int playerIndex, e_character_type bipedType)
Expand All @@ -53,15 +62,6 @@ void s_player::SetUnitBipedType(int playerIndex, e_character_type bipedType)
GetPlayer(playerIndex)->properties[0].profile_traits.profile.player_character_type = bipedType;
}

void s_player::SetUnitBipedType(int playerIndex, byte representationIndex)
{
if (!IndexValid(playerIndex))
{
return;
}
GetPlayer(playerIndex)->properties[0].profile_traits.profile.player_character_type = (e_character_type)representationIndex;
}

void s_player::SetBipedSpeed(int playerIndex, float speed)
{
if (!IndexValid(playerIndex))
Expand Down Expand Up @@ -109,7 +109,7 @@ bool PlayerIterator::get_next_active_player()

while (m_current_player)
{
if (!TEST_FLAG(m_current_player->flags, _player_left_game_bit))
if (!TEST_BIT(m_current_player->flags, _player_left_game_bit))
break;

m_current_player = get_next_datum();
Expand Down Expand Up @@ -157,3 +157,134 @@ uint32 player_appearance_required_bits()
{
return 39;
}

void __cdecl player_validate_configuration(datum player_index, s_player_properties* configuration_data)
{
// Campaign verification
if (game_is_campaign())
{
scenario* scnr = get_global_scenario();
uint32 block_size = scnr->player_starting_locations.size;
if (block_size > 0)
{
// Go through every player starting location and check if there's a campaign player type set
// Set the appropriate data in the player to the values of the tagblock
bool found = false;
for (uint32 i = 0; i < block_size; ++i)
{
scenario_player* player_starting_location = scnr->player_starting_locations[i];
if (player_starting_location->campaign_player_type != NONE)
{
configuration_data->team_index = _game_team_player;
configuration_data->profile_traits.profile.player_character_type = (e_character_type)player_starting_location->campaign_player_type;
found = true;
break;
}
}

// If a campaign_player_type type wasn't found in any of the starting locations set default values
if (!found)
{
configuration_data->team_index = _game_team_player;
configuration_data->profile_traits.profile.player_character_type = character_type_masterchief;
}
}
else
{
configuration_data->team_index = _game_team_player;
configuration_data->profile_traits.profile.player_character_type = character_type_masterchief;
}
}
// Multiplayer verification
else if (game_is_multiplayer())
{
// Don't allow dervish since he's not loaded properly in shared
if (configuration_data->profile_traits.profile.player_character_type == character_type_dervish)
{
configuration_data->profile_traits.profile.player_character_type = character_type_elite;
}


if (H2Config_spooky_boy && !Memory::IsDedicatedServer())
{
configuration_data->profile_traits.profile.player_character_type = character_type_skeleton;
for (uint32 i = 0; i < k_number_of_users; i++)
{
network_session_interface_set_local_user_character_type(i, character_type_skeleton);
}
*Memory::GetAddress<e_character_type*>(0x51A67C) = character_type_skeleton;
}
}

// General character verification
e_character_type character = configuration_data->profile_traits.profile.player_character_type;
if (character != NONE)
{
if (character >= character_type_masterchief)
{
s_game_globals* globals = scenario_get_game_globals();
if (character > (e_character_type)globals->player_representation.size - 1)
{
character = (e_character_type)(globals->player_representation.size - 1);
}
}
else
{
character = character_type_masterchief;
}
configuration_data->profile_traits.profile.player_character_type = character;
}

// Skill verification
int8 player_displayed_skill = configuration_data->player_displayed_skill;
if (player_displayed_skill != NONE)
{
if (player_displayed_skill < 0)
player_displayed_skill = 0;
configuration_data->player_displayed_skill = player_displayed_skill;
}
int8 player_overall_skill = configuration_data->player_overall_skill;
if (player_overall_skill != NONE)
{
if (player_overall_skill < 0)
{
player_overall_skill = 0;
}
configuration_data->player_overall_skill = player_overall_skill;
}

// Handicap verification
e_handicap player_handicap_level = configuration_data->player_handicap_level;
if (player_handicap_level >= _handicap_none)
{
if (player_handicap_level > _handicap_severe)
{
player_handicap_level = _handicap_severe;
}
}
else
{
player_handicap_level = _handicap_none;
}
configuration_data->player_handicap_level = player_handicap_level;

// User role verification
int8 bungie_user_role = configuration_data->bungie_user_role;
if (bungie_user_role < 0 || bungie_user_role > 7)
{
configuration_data->bungie_user_role = 0;
}

if (current_game_engine())
{
if (TEST_BIT(get_game_variant()->game_engine_flags, _game_engine_teams_bit))
{
if (configuration_data->team_index != NONE && !TEST_BIT(game_engine_globals_get()->team_bitmask, configuration_data->team_index))
{
configuration_data->team_index = NONE;
}
}
}

return;
}
34 changes: 19 additions & 15 deletions xlive/Blam/Engine/game/players.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ enum e_player_color : byte
player_color_tan
};

enum e_character_type : byte
enum e_character_type : int8
{
character_type_masterchief = 0,
character_type_dervish = 1,
character_type_spartan = 2,
character_type_elite = 3,

// cartographer added characters
character_type_skeleton = 4,
character_type_flood = 5,
character_type_lmao = 6
};

enum e_handicap : byte
enum e_handicap : uint8
{
handicap_none = 0,
handicap_minor = 1,
handicap_moderate = 2,
handicap_severe = 3
_handicap_none = 0,
_handicap_minor = 1,
_handicap_moderate = 2,
_handicap_severe = 3
};

enum e_player_flags : int
Expand Down Expand Up @@ -92,14 +94,14 @@ struct s_player_properties
wchar_t clan_name[16];
s_clan_identifiers clan_identifiers;

byte player_team;
int8 team_index;
e_handicap player_handicap_level;
byte player_displayed_skill;
byte player_overall_skill;
char player_is_griefer;
char bungie_user_role;
char achievement_flags;
byte unk2;
int8 player_displayed_skill;
int8 player_overall_skill;
int8 player_is_griefer;
int8 bungie_user_role;
int8 achievement_flags;
int8 unk2;
};
CHECK_STRUCT_SIZE(s_player_properties, 132);

Expand Down Expand Up @@ -165,7 +167,6 @@ struct s_player
static e_game_team GetTeam(int playerIndex);
static void SetTeam(int playerIndex, e_game_team team);
static void SetUnitBipedType(int playerIndex, e_character_type bipedType);
static void SetUnitBipedType(int playerIndex, byte representationIndex);
static void SetBipedSpeed(int playerIndex, float speed);
static const wchar_t* GetName(int playerIndex);
static datum GetPlayerUnitDatumIndex(int playerIndex);
Expand Down Expand Up @@ -247,4 +248,7 @@ datum __cdecl player_index_from_user_index(int32 user_index);
bool __cdecl players_user_is_active(int32 user_index);

// gets required bits for player_appearance
uint32 player_appearance_required_bits(void);
uint32 player_appearance_required_bits(void);

// Validate player configuration
void __cdecl player_validate_configuration(datum player_index, s_player_properties* configuration_data);
Loading

0 comments on commit d8183b5

Please sign in to comment.