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 4e83f3f25f
commit 5e58512a1e
5 changed files with 36 additions and 35 deletions

View File

@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
gtav_classes
GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git
GIT_TAG 6366aa82b65d04b5d3c581d15428da1cd92afea8
GIT_TAG eab95fba6d19ceeee0442158b6f5de6824ff7349
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""

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;
}
}
}

View File

@ -9,6 +9,7 @@ class CVehicleGadgetDataNode;
class CGameScriptHandlerNetComponent;
class CDoorBreakEvent;
class GenericPool;
class CGetPedSeatReturnClass;
enum eVehicleGadgetType : uint32_t;
enum class PedBones : uint16_t;
@ -198,5 +199,5 @@ namespace big::functions
using remove_player_from_sender_list = bool (*)(void* list, uint64_t* rockstar_id);
using get_ped_bone = bool (*)(CPed* ped_ptr, rage::fvector4& output, PedBones bone);
using get_ped_seat = CGetPedSeatReturnClass*(*)(PVOID seat_info, CPed* ped);
}

View File

@ -358,7 +358,7 @@ namespace big
bool* m_is_social_club_overlay_active;
functions::get_ped_bone m_get_ped_bone;
functions::get_ped_seat m_get_ped_seat;
};
#pragma pack(pop)
static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned");

View File

@ -1742,13 +1742,13 @@ namespace big
g_pointers->m_gta.m_nullsub = ptr.as<void(*)()>();
}
},
// Get Ped Bone
// Get Ped Seat
{
"GPB",
"48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 60 48 8B 01 41 8B E8 48 8B F2",
"GPS",
"E8 ? ? ? ? 48 85 DB 74 66",
[](memory::handle ptr)
{
g_pointers->m_gta.m_get_ped_bone = ptr.as<functions::get_ped_bone>();
g_pointers->m_gta.m_get_ped_seat = ptr.add(1).rip().as<functions::get_ped_seat>();
}
}
>(); // don't leave a trailing comma at the end