From 26686402c38440cdd01079e7cfab3e4145245c0e Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 21 Feb 2024 07:48:42 +0100 Subject: [PATCH] proper fix for weapon info damage crash (#2740) --- cmake/gtav-classes.cmake | 2 +- src/gta/weapon_info_manager.hpp | 9 +++++++++ src/gta_pointers.hpp | 3 +++ src/hooks/protections/received_event.cpp | 18 ++++++++++++++++-- src/pointers.cpp | 9 +++++++++ 5 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/gta/weapon_info_manager.hpp diff --git a/cmake/gtav-classes.cmake b/cmake/gtav-classes.cmake index e3fa9f1d..de8a6723 100644 --- a/cmake/gtav-classes.cmake +++ b/cmake/gtav-classes.cmake @@ -3,7 +3,7 @@ include(FetchContent) FetchContent_Declare( gtav_classes GIT_REPOSITORY https://github.com/Yimura/GTAV-Classes.git - GIT_TAG e8d8bdd2b3152253f6e1fde48720e4caeab19f83 + GIT_TAG 09a586011a296cf8ce3ffb9c15db7ce474ea4363 GIT_PROGRESS TRUE CONFIGURE_COMMAND "" BUILD_COMMAND "" diff --git a/src/gta/weapon_info_manager.hpp b/src/gta/weapon_info_manager.hpp new file mode 100644 index 00000000..224b7866 --- /dev/null +++ b/src/gta/weapon_info_manager.hpp @@ -0,0 +1,9 @@ +#pragma once + +// https://github.com/Parik27/V.Rainbomizer/blob/0c70868626411a1d30483339003b9985b0ff1c98/lib/CItemInfo.hh#L62 +class CWeaponInfoManager +{ +public: + char field_0x0[16][4]; + rage::atArray m_item_infos; +}; \ No newline at end of file diff --git a/src/gta_pointers.hpp b/src/gta_pointers.hpp index e6aec9f4..9f3f7e97 100644 --- a/src/gta_pointers.hpp +++ b/src/gta_pointers.hpp @@ -16,6 +16,7 @@ class CVehicleDriveByMetadataMgr; class CBlipList; class TimecycleKeyframeData; class CTrainConfig; +class CWeaponInfoManager; namespace rage { @@ -362,6 +363,8 @@ namespace big functions::get_ped_seat m_get_ped_seat; functions::received_clone_remove m_received_clone_remove; + + CWeaponInfoManager* m_weapon_info_manager; }; #pragma pack(pop) static_assert(sizeof(gta_pointers) % 8 == 0, "Pointers are not properly aligned"); diff --git a/src/hooks/protections/received_event.cpp b/src/hooks/protections/received_event.cpp index 131d0e25..0207afaa 100644 --- a/src/hooks/protections/received_event.cpp +++ b/src/hooks/protections/received_event.cpp @@ -1,6 +1,7 @@ #include "fiber_pool.hpp" #include "gta/enums.hpp" #include "gta/net_game_event.hpp" +#include "gta/weapon_info_manager.hpp" #include "hooking/hooking.hpp" #include "script/scriptIdBase.hpp" #include "util/math.hpp" @@ -25,6 +26,19 @@ namespace big id.m_instance_id = buffer.Read(8); } + static bool is_valid_weapon(rage::joaat_t hash) + { + for (const auto& info : g_pointers->m_gta.m_weapon_info_manager->m_item_infos) + { + if (info && info->m_name == hash && info->GetClassId() == RAGE_JOAAT("cweaponinfo")) + { + return true; + } + } + + return false; + } + // Returns true if bad event bool scan_weapon_damage_event(rage::netEventMgr* event_manager, CNetGamePlayer* player, CNetGamePlayer* target_player, int event_index, int event_handled_bitset, rage::datBitBuffer* buffer) { @@ -72,9 +86,9 @@ namespace big damageType = buffer->Read(2); weaponType = buffer->Read(32); - const auto is_crash_weapon = weaponType == RAGE_JOAAT("AMMO_BALL"); - if (is_crash_weapon) + if (!is_valid_weapon(weaponType)) { + notify::crash_blocked(player, "invalid weapon type"); g_pointers->m_gta.m_send_event_ack(event_manager, player, target_player, event_index, event_handled_bitset); return true; } diff --git a/src/pointers.cpp b/src/pointers.cpp index 7f783bfe..6e09bb24 100644 --- a/src/pointers.cpp +++ b/src/pointers.cpp @@ -1763,6 +1763,15 @@ namespace big { g_pointers->m_gta.m_received_clone_remove = ptr.as(); } + }, + // CWeaponInfoManager + { + "CWIM", + "0F B7 15 ? ? ? ? ? 33 D2 2B D3 78 ? ? 8B 1D", + [](memory::handle ptr) + { + g_pointers->m_gta.m_weapon_info_manager = ptr.add(3).rip().sub(72).as(); + } } >(); // don't leave a trailing comma at the end