Skip to content

Commit

Permalink
Merge pull request pnill#465 from Berthalamew/development
Browse files Browse the repository at this point in the history
update player grenade code
  • Loading branch information
nukeulater authored Nov 6, 2023
2 parents d39306c + 23d20ea commit 84e6bc6
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);
47 changes: 12 additions & 35 deletions xlive/Blam/Engine/game/players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<entity_set_unk_flags_t>(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<unit_add_grenade_to_inventory_send_t>(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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion xlive/Blam/Engine/game/players.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions xlive/Blam/Engine/objects/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ enum e_game_team : short
_game_team_none = -1
};

enum e_grenades : BYTE
{
Fragmentation,
Plasma
};

enum e_weapon_index : WORD
{
Primary = 0xFF00,
Expand Down
9 changes: 8 additions & 1 deletion xlive/Blam/Engine/units/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions xlive/H2MOD/Variants/GunGame/GunGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 2 additions & 0 deletions xlive/Project_Cartographer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
<ClCompile Include="Blam\Engine\scenario\scenario.cpp" />
<ClCompile Include="Blam\Engine\scenario\scenario_kill_trigger_volumes.cpp" />
<ClCompile Include="Blam\Engine\shell\windows\crash_report_window\crash_report_window.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_action.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_entities.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_interface.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_internal.cpp" />
Expand Down Expand Up @@ -762,6 +763,7 @@
<ClInclude Include="Blam\Engine\scenario\scenario_interpolators.h" />
<ClInclude Include="Blam\Engine\scenario\scenario_kill_trigger_volumes.h" />
<ClInclude Include="Blam\Engine\shell\windows\crash_report_window\crash_report_window.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_action.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_damage.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_device_machines.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_entities.h" />
Expand Down
6 changes: 2 additions & 4 deletions xlive/Project_Cartographer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<ClCompile Include="H2MOD\Modules\Tweaks\Tweaks.cpp" />
<ClCompile Include="H2MOD\Modules\Updater\Updater.cpp" />
<ClCompile Include="H2MOD\Utils\Utils.cpp" />
<ClCompile Include="H2MOD\Variants\FireFight\FireFight.cpp" />
<ClCompile Include="H2MOD\Variants\GunGame\GunGame.cpp" />
<ClCompile Include="H2MOD\Variants\H2X\H2X.cpp" />
<ClCompile Include="H2MOD\Variants\Infection\Infection.cpp" />
Expand Down Expand Up @@ -120,7 +119,6 @@
<ClCompile Include="H2MOD\Modules\CustomMenu\c_screen_widget.cpp" />
<ClCompile Include="H2MOD\Modules\CustomMenu\c_virtual_keyboard_menu.cpp" />
<ClCompile Include="H2MOD\Modules\CustomMenu\Accounts\c_account_create_menu.cpp" />
<ClCompile Include="H2MOD\Variants\FireFight\DeviceShop\DeviceShop.cpp" />
<ClCompile Include="H2MOD\GUI\ImGui_Integration\Console\CommandHandler.cpp" />
<ClCompile Include="H2MOD\GUI\ImGui_Integration\Console\ImGui_ConsoleImpl.cpp" />
<ClCompile Include="H2MOD\GUI\ImGui_Integration\Console\CommandCollection.cpp" />
Expand Down Expand Up @@ -220,6 +218,7 @@
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_internal.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_units.cpp" />
<ClCompile Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_main.cpp" />
<ClCompile Include="Blam\Engine\Simulation\game_interface\simulation_game_action.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="3rdparty\discord\discord_register.h" />
Expand Down Expand Up @@ -376,7 +375,6 @@
<ClInclude Include="H2MOD\Modules\Tweaks\Tweaks.h" />
<ClInclude Include="H2MOD\Modules\Updater\Updater.h" />
<ClInclude Include="H2MOD\Utils\Utils.h" />
<ClInclude Include="H2MOD\Variants\FireFight\FireFight.h" />
<ClInclude Include="H2MOD\Variants\GunGame\GunGame.h" />
<ClInclude Include="H2MOD\Variants\H2X\H2X.h" />
<ClInclude Include="H2MOD\Variants\Infection\Infection.h" />
Expand Down Expand Up @@ -505,7 +503,6 @@
<ClInclude Include="H2MOD\Modules\CustomMenu\c_virtual_keyboard_menu.h" />
<ClInclude Include="H2MOD\Modules\CustomMenu\Accounts\c_account_create_menu.h" />
<ClInclude Include="Blam\Engine\game\cheats.h" />
<ClInclude Include="H2MOD\Variants\FireFight\DeviceShop\DeviceShop.h" />
<ClInclude Include="H2MOD\GUI\ImGui_Integration\Console\CommandHandler.h" />
<ClInclude Include="H2MOD\GUI\ImGui_Integration\Console\CommandsUtil.h" />
<ClInclude Include="H2MOD\GUI\ImGui_Integration\Console\ComVar.h" />
Expand Down Expand Up @@ -675,6 +672,7 @@
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_interface.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_internal.h" />
<ClInclude Include="Blam\Engine\rasterizer\dx9\rasterizer_dx9_main.h" />
<ClInclude Include="Blam\Engine\Simulation\game_interface\simulation_game_action.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resources\Resource.rc" />
Expand Down

0 comments on commit 84e6bc6

Please sign in to comment.