Refactored Allow All Vehicles (#2604)

* Refactored Allow All Vehicles to use the current seat the ped is in to fetch the animation info that the car is currently using.
* Update gtav-classes tag hash.
* Removed GROUP_SMG from the allow all weapons false scenario.
This commit is contained in:
gir489
2023-12-19 11:15:52 -05:00
committed by GitHub
parent 8e8919ec56
commit e544e02e55
5 changed files with 36 additions and 35 deletions

View File

@ -4,6 +4,7 @@
#include <vehicle/CVehicleModelInfo.hpp>
#include <vehicle/CVehicleSeatMetadataMgr.hpp>
#include <vehicle/CVehicleDriveByMetadataMgr.hpp>
#include <vehicle/CGetPedSeatReturnClass.hpp>
#include "gta/weapons.hpp"
@ -11,50 +12,49 @@ namespace big
{
void looped::vehicle_allow_all_weapons()
{
CVehicle* vehicle_ptr = (CVehicle*)g_pointers->m_gta.m_handle_to_ptr(self::veh);
if (vehicle_ptr == nullptr)
if (self::veh == 0 || g_local_player == nullptr)
return;
rage::atArray<Hash> one_handed_groups =
g_pointers->m_gta.m_driveby_metadata_mgr->m_drive_by_weapon_groups->m_drive_by_default->m_driveby_default_one_handed_weapon_group_names;
auto seat_info = g_pointers->m_gta.m_get_ped_seat(g_local_player->m_seat_info, g_local_player);
if (seat_info == nullptr)
return;
if (g.vehicle.unlimited_weapons == false)
{
if (one_handed_groups.size() != 1)
if (seat_info->anim_info)
{
rage::atArray<Hash> one_handed_groups;
one_handed_groups.append(GROUP_PISTOL);
g_pointers->m_gta.m_driveby_metadata_mgr->m_drive_by_weapon_groups->m_drive_by_default->m_driveby_default_one_handed_weapon_group_names = one_handed_groups;
for (auto drive_by_anim_info : seat_info->anim_info->m_drive_by_anim_infos)
{
if (drive_by_anim_info->m_weapon_groups->m_groups.size() == 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL))
{
drive_by_anim_info->m_weapon_groups->m_groups.clear();
drive_by_anim_info->m_weapon_groups->m_groups.append({GROUP_PISTOL});
}
}
}
return;
}
CVehicleModelInfo* vehicle_model_info = static_cast<CVehicleModelInfo*>(vehicle_ptr->m_model_info);
if (seat_info->anim_info == nullptr) //Should only occur in the R-88 and similar formula cars, so assume the user is in the driver's seat. Fix later, if other edge cases occur.
{
seat_info->anim_info = g_pointers->m_gta.m_vehicle_layout_metadata_mgr->m_drive_by_seat_defaults->m_driveby_standard_front_left;
}
auto num_seats = vehicle_model_info->m_vehicle_layout->m_max_seats;
auto seat_info = vehicle_model_info->m_vehicle_layout->m_layout_metadata->m_seat_info;
auto defaults = g_pointers->m_gta.m_vehicle_layout_metadata_mgr->m_drive_by_seat_defaults;
if (seat_info->m_front_left->m_drive_by_info != defaults->m_driveby_standard_front_left)
seat_info->m_front_left->m_drive_by_info = defaults->m_driveby_standard_front_left;
if (num_seats > 1 && seat_info->m_front_right->m_drive_by_info != defaults->m_driveby_standard_front_right)
seat_info->m_front_right->m_drive_by_info = defaults->m_driveby_standard_front_right;
if (num_seats > 2 && seat_info->m_rear_left->m_drive_by_info != defaults->m_driveby_standard_rear_left)
seat_info->m_rear_left->m_drive_by_info = defaults->m_driveby_standard_rear_left;
if (num_seats > 3 && seat_info->m_rear_right->m_drive_by_info != defaults->m_driveby_standard_rear_right)
seat_info->m_rear_right->m_drive_by_info = defaults->m_driveby_standard_rear_right;
for (auto drive_by_anim_info : seat_info->anim_info->m_drive_by_anim_infos)
{
if (drive_by_anim_info->m_weapon_groups->m_groups.size() != 7 && drive_by_anim_info->m_weapon_groups->m_groups.contains(GROUP_PISTOL))
{
drive_by_anim_info->m_weapon_groups->m_groups.clear();
drive_by_anim_info->m_weapon_groups->m_groups.append({GROUP_PISTOL, GROUP_MG, GROUP_RIFLE, GROUP_SHOTGUN, GROUP_HEAVY, GROUP_SNIPER, GROUP_SMG});
}
}
CVehicleModelInfo* vehicle_model_info = static_cast<CVehicleModelInfo*>(g_local_player->m_vehicle->m_model_info);
vehicle_model_info->set_vehicle_model_flag(CVehicleModelInfoFlags::DRIVER_NO_DRIVE_BY, false);
if (PAD::IS_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_AIM))
{
PAD::DISABLE_CONTROL_ACTION(0, (int)ControllerInputs::INPUT_VEH_FLY_MOUSE_CONTROL_OVERRIDE, 1);
}
if (g_pointers->m_gta.m_driveby_metadata_mgr->m_drive_by_weapon_groups->m_drive_by_default
->m_driveby_default_one_handed_weapon_group_names.size() == 1)
{
one_handed_groups.append({GROUP_MG, GROUP_RIFLE, GROUP_SHOTGUN, GROUP_HEAVY, GROUP_SNIPER, GROUP_SMG});
g_pointers->m_gta.m_driveby_metadata_mgr->m_drive_by_weapon_groups->m_drive_by_default->m_driveby_default_one_handed_weapon_group_names = one_handed_groups;
}
}
}