From 5e58512a1e31e6eb5df9617f0817ac7eadece8cb Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:15:52 -0500 Subject: [PATCH] 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. --- scripts/gtav-classes.cmake | 2 +- .../looped/vehicle/allow_all_weapons.cpp | 56 +++++++++---------- src/function_types.hpp | 3 +- src/gta_pointers.hpp | 2 +- src/pointers.cpp | 8 +-- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/scripts/gtav-classes.cmake b/scripts/gtav-classes.cmake index 69201f11..ab9a7def 100644 --- a/scripts/gtav-classes.cmake +++ b/scripts/gtav-classes.cmake @@ -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 "" diff --git a/src/backend/looped/vehicle/allow_all_weapons.cpp b/src/backend/looped/vehicle/allow_all_weapons.cpp index a97557ed..f3a57e03 100644 --- a/src/backend/looped/vehicle/allow_all_weapons.cpp +++ b/src/backend/looped/vehicle/allow_all_weapons.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #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 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 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(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(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; - } } } \ No newline at end of file diff --git a/src/function_types.hpp b/src/function_types.hpp index 1e053435..039d96a4 100644 --- a/src/function_types.hpp +++ b/src/function_types.hpp @@ -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); } diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index 0c53b7fa..d34aef5c 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -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"); diff --git a/src/pointers.cpp b/src/pointers.cpp index c3d360dc..5b0efbc2 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1742,13 +1742,13 @@ namespace big g_pointers->m_gta.m_nullsub = ptr.as(); } }, - // 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(); + g_pointers->m_gta.m_get_ped_seat = ptr.add(1).rip().as(); } } >(); // don't leave a trailing comma at the end