From 4312d9d15cbb51b24e8ac9b35b81cca51b9ab673 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Thu, 21 Dec 2023 10:17:45 -0500 Subject: [PATCH] Weapon events refactor. (#2622) * Removed legacy REMOVE_ALL_WEAPONS_EVENT network event check. Added GIVE_WEAPON_EVENT check to prevent people giving us weapons. --- src/hooks/protections/received_event.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/hooks/protections/received_event.cpp b/src/hooks/protections/received_event.cpp index 3b2d58e1..0ebd6cf1 100644 --- a/src/hooks/protections/received_event.cpp +++ b/src/hooks/protections/received_event.cpp @@ -570,8 +570,8 @@ namespace big } case eNetworkEvents::REMOVE_WEAPON_EVENT: { - int net_id = buffer->Read(13); - uint32_t hash = buffer->Read(32); + std::int16_t net_id = buffer->Read(13); + Hash hash = buffer->Read(32); if (hash == RAGE_JOAAT("WEAPON_UNARMED")) { @@ -582,8 +582,9 @@ namespace big if (g_local_player && g_local_player->m_net_object && g_local_player->m_net_object->m_object_id == net_id) { + weapon_item weapon = g_gta_data_service->weapon_by_hash(hash); g_notification_service->push_warning("PROTECTIONS"_T.data(), - std::vformat("REMOVE_WEAPON_ATTEMPT"_T, std::make_format_args(source_player->get_name()))); + std::format("{} {} {}.", source_player->get_name(), "REMOVE_WEAPON_ATTEMPT_MESSAGE"_T, weapon.m_display_name)); g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); return; } @@ -591,14 +592,16 @@ namespace big buffer->Seek(0); break; } - case eNetworkEvents::REMOVE_ALL_WEAPONS_EVENT: + case eNetworkEvents::GIVE_WEAPON_EVENT: { - int net_id = buffer->Read(13); + std::int16_t net_id = buffer->Read(13); + Hash hash = buffer->Read(32); if (g_local_player && g_local_player->m_net_object && g_local_player->m_net_object->m_object_id == net_id) { + weapon_item weapon = g_gta_data_service->weapon_by_hash(hash); g_notification_service->push_warning("PROTECTIONS"_T.data(), - std::vformat("REMOVE_ALL_WEAPONS_ATTEMPT"_T, std::make_format_args(source_player->get_name()))); + std::format("{} {} {}.", source_player->get_name(), "GIVE_WEAPON_ATTEMPT_MESSAGE"_T, weapon.m_display_name)); g_pointers->m_gta.m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); return; }