From 51e3b6e132908143902ee9d01703f1f12388abdb Mon Sep 17 00:00:00 2001 From: Aure7138 <100095051+Aure7138@users.noreply.github.com> Date: Thu, 6 Apr 2023 02:25:20 +0800 Subject: [PATCH] refactor: all weapons in vehicle (#1197) --- src/backend/looped/vehicle/unlimited_weapons.cpp | 10 ---------- src/hooking.cpp | 2 ++ src/hooking.hpp | 2 ++ src/hooks/misc/allow_weapons_in_vehicle.cpp | 15 +++++++++++++++ src/pointers.cpp | 4 ++-- src/pointers.hpp | 2 +- 6 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 src/hooks/misc/allow_weapons_in_vehicle.cpp diff --git a/src/backend/looped/vehicle/unlimited_weapons.cpp b/src/backend/looped/vehicle/unlimited_weapons.cpp index 4206656e..3e25092d 100644 --- a/src/backend/looped/vehicle/unlimited_weapons.cpp +++ b/src/backend/looped/vehicle/unlimited_weapons.cpp @@ -7,20 +7,10 @@ namespace big { using looped_command::looped_command; - virtual void on_enable() override - { - g_pointers->m_allow_weapons_in_vehicle->apply(); - } - virtual void on_tick() override { } - - virtual void on_disable() override - { - g_pointers->m_allow_weapons_in_vehicle->restore(); - } }; veh_unlimited_weapons g_veh_unlimited_weapons("vehallweapons", "Allow Weapons In Vehicle", "Allows you to use all weapons in vehicle", g.vehicle.unlimited_weapons); } diff --git a/src/hooking.cpp b/src/hooking.cpp index 860b934d..62222d48 100644 --- a/src/hooking.cpp +++ b/src/hooking.cpp @@ -123,6 +123,8 @@ namespace big detour_hook_helper::add("FPFM", g_pointers->m_fipackfile_mount); + detour_hook_helper::add("AWIV", g_pointers->m_allow_weapons_in_vehicle); + g_hooking = this; } diff --git a/src/hooking.hpp b/src/hooking.hpp index 7f27fcdc..1dbfde2a 100644 --- a/src/hooking.hpp +++ b/src/hooking.hpp @@ -165,6 +165,8 @@ namespace big static void write_vehicle_proximity_migration_data_node(rage::netObject* veh, CVehicleProximityMigrationDataNode* node); static bool fipackfile_mount(rage::fiPackfile* this_, const char* mount_point); + + static bool allow_weapons_in_vehicle(int64_t unk, int weaponinfo_group); }; class minhook_keepalive diff --git a/src/hooks/misc/allow_weapons_in_vehicle.cpp b/src/hooks/misc/allow_weapons_in_vehicle.cpp new file mode 100644 index 00000000..b1aa1cbb --- /dev/null +++ b/src/hooks/misc/allow_weapons_in_vehicle.cpp @@ -0,0 +1,15 @@ +#include "hooking.hpp" + +namespace big +{ + bool hooks::allow_weapons_in_vehicle(int64_t unk, int weaponinfo_group) + { + if (g.vehicle.unlimited_weapons) + { + if (weaponinfo_group == RAGE_JOAAT("GROUP_THROWN")) //Because the thrower can be used without bypassing, we let the game decide the return value, since this function has multiple xrefs, it may be necessary to return 0 at some point + return g_hooking->get_original()(unk, weaponinfo_group); + return true; + } + return g_hooking->get_original()(unk, weaponinfo_group); + } +} \ No newline at end of file diff --git a/src/pointers.cpp b/src/pointers.cpp index c6b20eb1..982e11ce 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -737,8 +737,8 @@ namespace big }); // Allow Weapons In Vehicle - main_batch.add("AWIV", "49 3B C9 7C F0 ? ? C3", [this](memory::handle ptr) { - m_allow_weapons_in_vehicle = memory::byte_patch::make(ptr.add(5).as(), 0x01B0).get(); //In order for the second xref loop not to stop + main_batch.add("AWIV", "49 8B 40 08 39 10", [this](memory::handle ptr) { + m_allow_weapons_in_vehicle = ptr.sub(23).as(); }); // Crash Trigger diff --git a/src/pointers.hpp b/src/pointers.hpp index 19de0c59..499d45f5 100644 --- a/src/pointers.hpp +++ b/src/pointers.hpp @@ -255,7 +255,7 @@ namespace big bool* m_refresh_audio_input{}; memory::byte_patch* m_disable_collision{}; - memory::byte_patch* m_allow_weapons_in_vehicle{}; + PVOID m_allow_weapons_in_vehicle{}; PVOID m_taskjump_constructor{};