From d2d33af875adccb47fb9680895102e1a31c27e6a Mon Sep 17 00:00:00 2001 From: Berthalamew <40469582+Berthalamew@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:10:17 -0500 Subject: [PATCH 1/2] update set_player_unit_grenade_count function - move simulation action functions to their own module - update e_unit_grenade_type enum --- .../game_interface/simulation_game_action.cpp | 14 ++++++ .../game_interface/simulation_game_action.h | 10 ++++ xlive/Blam/Engine/game/players.cpp | 47 +++++-------------- xlive/Blam/Engine/game/players.h | 2 +- xlive/Blam/Engine/objects/objects.h | 6 +-- .../CustomVariantSettings.cpp | 4 +- xlive/H2MOD/Variants/GunGame/GunGame.cpp | 18 +++---- xlive/Project_Cartographer.vcxproj | 2 + xlive/Project_Cartographer.vcxproj.filters | 6 +-- 9 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.cpp create mode 100644 xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.h diff --git a/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.cpp b/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.cpp new file mode 100644 index 000000000..7cbc7385e --- /dev/null +++ b/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.cpp @@ -0,0 +1,14 @@ +#include "stdafx.h" +#include "simulation_game_action.h" + +void __cdecl simulation_action_object_update(datum unit_index, uint32 update_mask) +{ + INVOKE(0x1B6685, 0x1B05B5, simulation_action_object_update, unit_index, update_mask); + return; +} + +void __cdecl simulation_action_pickup_equipment(datum unit_datum_index, datum grenade_tag_index) +{ + INVOKE(0x1B6F12, 0x1B0E42, simulation_action_pickup_equipment, unit_datum_index, grenade_tag_index); + return; +} \ No newline at end of file diff --git a/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.h b/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.h new file mode 100644 index 000000000..b9d569235 --- /dev/null +++ b/xlive/Blam/Engine/Simulation/game_interface/simulation_game_action.h @@ -0,0 +1,10 @@ +#pragma once + +enum e_simulation_action_update : uint32 +{ + _simulation_action_update_grenade_count_bit = 22 +}; + +void __cdecl simulation_action_object_update(datum unit_index, uint32 update_mask); + +void __cdecl simulation_action_pickup_equipment(datum unit_datum_index, datum grenade_tag_index); diff --git a/xlive/Blam/Engine/game/players.cpp b/xlive/Blam/Engine/game/players.cpp index c632c03f8..94062db41 100644 --- a/xlive/Blam/Engine/game/players.cpp +++ b/xlive/Blam/Engine/game/players.cpp @@ -5,6 +5,8 @@ #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/Simulation/game_interface/simulation_game_action.h" +#include "Blam/Engine/units/units.h" #include "Blam/Engine/saved_games/game_variant.h" #include "Blam/Engine/scenario/scenario.h" @@ -97,49 +99,24 @@ datum s_player::get_unit_index(datum player_index) return get(player_index)->unit_index; } -void s_player::set_player_unit_grenade_count(datum player_index, e_grenades type, int32 count, bool reset_equipment) +void s_player::set_player_unit_grenade_count(datum player_index, e_unit_grenade_type type, int8 count, bool reset_equipment) { int32 abs_player_index = DATUM_INDEX_TO_ABSOLUTE_INDEX(player_index); - - if (type > e_grenades::Plasma) - { - LOG_TRACE_GAME("set_player_unit_grenades_count() invalid arg: type"); - return; - } - - static const std::string grenadeEquipamentTagName[2] = - { - "objects\\weapons\\grenade\\frag_grenade\\frag_grenade", - "objects\\weapons\\grenade\\plasma_grenade\\plasma_grenade" - }; - datum unit_datum_index = s_player::get_unit_index(player_index); - //datum grenade_eqip_tag_datum_index = tags::find_tag(blam_tag::tag_group_type::equipment, grenadeEquipamentTagName[type]); + unit_datum* unit = (unit_datum*)object_try_and_get_and_verify_type(unit_datum_index, FLAG(_object_type_biped)); - char* unit_object = (char*)object_try_and_get_and_verify_type(unit_datum_index, FLAG(_object_type_biped)); - if (unit_object != NULL) + // send simulation update for grenades if we control the simulation + if (unit != NULL && !game_is_predicted()) { - // not sure what these flags are, but this is called when picking up grenades - typedef void(__cdecl* entity_set_unk_flags_t)(datum object_index, int32 flags); - auto p_simulation_action_object_update = Memory::GetAddress(0x1B6685, 0x1B05B5); - - typedef void(__cdecl* unit_add_grenade_to_inventory_send_t)(datum unit_datum_index, datum equipment_tag_index); - auto p_unit_add_grenade_to_inventory_send = Memory::GetAddress(0x1B6F12, 0x1B0E42); - - // send simulation update for grenades if we control the simulation - if (!game_is_predicted()) + // delete all weapons if required + if (reset_equipment) { - // delete all weapons if required - if (reset_equipment) - unit_delete_all_weapons(unit_datum_index); - - // set grenade count - *(int8*)(unit_object + 0x252 + type) = (int8)count; - - p_simulation_action_object_update(unit_datum_index, FLAG(22)); // flag 22 seems to be sync entity grenade count (TODO: list all of the update types) - //p_unit_add_grenade_to_inventory_send(unit_datum_index, grenade_eqip_tag_datum_index); + unit_delete_all_weapons(unit_datum_index); } + unit->grenade_counts[type] = count; + simulation_action_object_update(unit_datum_index, FLAG(_simulation_action_update_grenade_count_bit)); + LOG_TRACE_GAME("set_player_unit_grenade_count() - sending grenade simulation update, playerIndex={0}, peerIndex={1}", abs_player_index, NetworkSession::GetPeerIndex(abs_player_index)); } } diff --git a/xlive/Blam/Engine/game/players.h b/xlive/Blam/Engine/game/players.h index 5a5d94b08..279305503 100644 --- a/xlive/Blam/Engine/game/players.h +++ b/xlive/Blam/Engine/game/players.h @@ -170,7 +170,7 @@ struct s_player static e_game_team get_team(datum player_index); static void set_team(datum player_index, e_game_team team); static void set_unit_character_type(datum player_index, e_character_type character_type); - static void set_player_unit_grenade_count(datum player_index, e_grenades type, int32 count, bool reset_equipment); + static void set_player_unit_grenade_count(datum player_index, e_unit_grenade_type type, int8 count, bool reset_equipment); static void set_unit_speed(datum player_index, float speed); static const wchar_t* get_name(datum player_index); static datum get_unit_index(datum player_index); diff --git a/xlive/Blam/Engine/objects/objects.h b/xlive/Blam/Engine/objects/objects.h index afd103f85..3c16d3c7b 100644 --- a/xlive/Blam/Engine/objects/objects.h +++ b/xlive/Blam/Engine/objects/objects.h @@ -46,10 +46,10 @@ enum e_game_team : short _game_team_none = -1 }; -enum e_grenades : BYTE +enum e_unit_grenade_type : int8 { - Fragmentation, - Plasma + _unit_grenade_type_fragmentation = 0, + _unit_grenade_type_plasma = 1 }; enum e_weapon_index : WORD diff --git a/xlive/H2MOD/Modules/CustomVariantSettings/CustomVariantSettings.cpp b/xlive/H2MOD/Modules/CustomVariantSettings/CustomVariantSettings.cpp index a7f4c0b97..e557b7527 100644 --- a/xlive/H2MOD/Modules/CustomVariantSettings/CustomVariantSettings.cpp +++ b/xlive/H2MOD/Modules/CustomVariantSettings/CustomVariantSettings.cpp @@ -91,8 +91,8 @@ namespace CustomVariantSettings { if (currentVariantSettings.infiniteGrenades) { - s_player::set_player_unit_grenade_count(playerIndex, Fragmentation, 4, false); - s_player::set_player_unit_grenade_count(playerIndex, Plasma, 4, false); + s_player::set_player_unit_grenade_count(playerIndex, _unit_grenade_type_fragmentation, 4, false); + s_player::set_player_unit_grenade_count(playerIndex, _unit_grenade_type_plasma, 4, false); } } } diff --git a/xlive/H2MOD/Variants/GunGame/GunGame.cpp b/xlive/H2MOD/Variants/GunGame/GunGame.cpp index 86138a9af..2320f5092 100644 --- a/xlive/H2MOD/Variants/GunGame/GunGame.cpp +++ b/xlive/H2MOD/Variants/GunGame/GunGame.cpp @@ -197,8 +197,8 @@ void GunGame::OnPlayerDeath(ExecTime execTime, datum playerIdx) // to note after the original function executes, the controlled unit by this player is set to NONE if (!game_is_predicted()) { - s_player::set_player_unit_grenade_count(playerIdx, e_grenades::Fragmentation, 0, true); - s_player::set_player_unit_grenade_count(playerIdx, e_grenades::Plasma, 0, true); + s_player::set_player_unit_grenade_count(playerIdx, _unit_grenade_type_fragmentation, 0, true); + s_player::set_player_unit_grenade_count(playerIdx, _unit_grenade_type_plasma, 0, true); } break; @@ -254,11 +254,11 @@ void GunGame::OnPlayerSpawn(ExecTime execTime, datum playerIdx) } else if (level == 15) { LOG_TRACE_GAME(L"[H2Mod-GunGame]: {} - {} on frag grenade level!", __FUNCTIONW__, s_player::get_name(playerIdx)); - s_player::set_player_unit_grenade_count(playerIdx, e_grenades::Fragmentation, 99, true); + s_player::set_player_unit_grenade_count(playerIdx, _unit_grenade_type_fragmentation, 99, true); } else if (level == 16) { LOG_TRACE_GAME(L"[H2Mod-GunGame]: {} - {} on plasma grenade level!", __FUNCTIONW__, s_player::get_name(playerIdx)); - s_player::set_player_unit_grenade_count(playerIdx, e_grenades::Plasma, 99, true); + s_player::set_player_unit_grenade_count(playerIdx, _unit_grenade_type_plasma, 99, true); } } } @@ -306,20 +306,20 @@ bool GunGame::c_game_statborg__adjust_player_stat(ExecTime execTime, c_game_stat LOG_TRACE_GAME(L"[H2Mod-GunGame]: {} - {} on level {} giving them weapon...", __FUNCTIONW__, s_player::get_name(player_datum), level); datum LevelWeapon = GunGame::levelWeapon[level]; - s_player::set_player_unit_grenade_count(player_datum, e_grenades::Fragmentation, 0, true); - s_player::set_player_unit_grenade_count(player_datum, e_grenades::Plasma, 0, true); + s_player::set_player_unit_grenade_count(player_datum, _unit_grenade_type_fragmentation, 0, true); + s_player::set_player_unit_grenade_count(player_datum, _unit_grenade_type_plasma, 0, true); call_give_player_weapon(absPlayerIdx, LevelWeapon, 1); } else if (level == 15) { LOG_TRACE_GAME(L"[H2Mod-GunGame]: {} - {} Level 15 - Frag Grenades!", __FUNCTIONW__, s_player::get_name(player_datum)); - s_player::set_player_unit_grenade_count(player_datum, e_grenades::Fragmentation, 99, true); + s_player::set_player_unit_grenade_count(player_datum, _unit_grenade_type_fragmentation, 99, true); } else if (level == 16) { LOG_TRACE_GAME(L"[H2Mod-GunGame]: {} - {} Level 16 - Plasma Grenades!", __FUNCTIONW__, s_player::get_name(player_datum)); - s_player::set_player_unit_grenade_count(player_datum, e_grenades::Fragmentation, 0, true); - s_player::set_player_unit_grenade_count(player_datum, e_grenades::Plasma, 99, true); + s_player::set_player_unit_grenade_count(player_datum, _unit_grenade_type_fragmentation, 0, true); + s_player::set_player_unit_grenade_count(player_datum, _unit_grenade_type_plasma, 99, true); } } diff --git a/xlive/Project_Cartographer.vcxproj b/xlive/Project_Cartographer.vcxproj index a340e0216..984527f21 100644 --- a/xlive/Project_Cartographer.vcxproj +++ b/xlive/Project_Cartographer.vcxproj @@ -444,6 +444,7 @@ + @@ -762,6 +763,7 @@ + diff --git a/xlive/Project_Cartographer.vcxproj.filters b/xlive/Project_Cartographer.vcxproj.filters index 28702322a..3c64773db 100644 --- a/xlive/Project_Cartographer.vcxproj.filters +++ b/xlive/Project_Cartographer.vcxproj.filters @@ -43,7 +43,6 @@ - @@ -120,7 +119,6 @@ - @@ -220,6 +218,7 @@ + @@ -376,7 +375,6 @@ - @@ -505,7 +503,6 @@ - @@ -675,6 +672,7 @@ + From 23d20ea0444582c042ae7d3356f6c11ea66ce5de Mon Sep 17 00:00:00 2001 From: Berthalamew <40469582+Berthalamew@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:13:38 -0500 Subject: [PATCH 2/2] move e_unit_grenade_type --- xlive/Blam/Engine/objects/objects.h | 6 ------ xlive/Blam/Engine/units/units.h | 9 ++++++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/xlive/Blam/Engine/objects/objects.h b/xlive/Blam/Engine/objects/objects.h index 3c16d3c7b..40471cdcb 100644 --- a/xlive/Blam/Engine/objects/objects.h +++ b/xlive/Blam/Engine/objects/objects.h @@ -46,12 +46,6 @@ enum e_game_team : short _game_team_none = -1 }; -enum e_unit_grenade_type : int8 -{ - _unit_grenade_type_fragmentation = 0, - _unit_grenade_type_plasma = 1 -}; - enum e_weapon_index : WORD { Primary = 0xFF00, diff --git a/xlive/Blam/Engine/units/units.h b/xlive/Blam/Engine/units/units.h index 8e1c8bb4b..5763f2871 100644 --- a/xlive/Blam/Engine/units/units.h +++ b/xlive/Blam/Engine/units/units.h @@ -14,6 +14,13 @@ enum e_weapon_addition_method : int16 _weapon_addition_method_seven = 7, }; +enum e_unit_grenade_type : int8 +{ + _unit_grenade_type_fragmentation = 0, + _unit_grenade_type_plasma = 1, + k_unit_grenade_types_count +}; + enum e_unit_weapons { unit_weapons_primary_weapon, @@ -94,7 +101,7 @@ struct unit_datum datum item_index; int8 grenade_type; int8 current_grenade_index; - int8 grenade_counts[2]; + int8 grenade_counts[k_unit_grenade_types_count]; int8 zoom_level; int8 gap_255; int8 field_256;