From 43afdae9e7fc5212b4743bbefea0dc8d61d7b6e5 Mon Sep 17 00:00:00 2001 From: gir489 <100792176+gir489returns@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:29:49 -0400 Subject: [PATCH] Fixed mission cars not being properly cleaned up. (#3434) --- .../protections/received_clone_remove.cpp | 83 ++++++++++--------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/hooks/protections/received_clone_remove.cpp b/src/hooks/protections/received_clone_remove.cpp index a57b88bb..d588000a 100644 --- a/src/hooks/protections/received_clone_remove.cpp +++ b/src/hooks/protections/received_clone_remove.cpp @@ -1,41 +1,44 @@ -#include "hooking/hooking.hpp" -#include "util/notify.hpp" - -namespace big -{ - void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token) - { - if (!dst || !dst->m_player_info || !dst->m_player_info->m_ped || !dst->m_player_info->m_ped->m_net_object - || dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) [[unlikely]] - { - notify::crash_blocked(src, "player ped removal"); - return; - } - - if (g_local_player && g_local_player->m_vehicle && g_local_player->m_vehicle->m_net_object - && object_id == g_local_player->m_vehicle->m_net_object->m_object_id) [[unlikely]] - { - if (auto plyr = g_player_service->get_by_id(src->m_player_id)) - { - g.reactions.delete_vehicle.process(plyr); - } - return; - } - - if (auto object = g_pointers->m_gta.m_get_net_object(*g_pointers->m_gta.m_network_object_mgr, object_id, true)) [[likely]] - { - if (object->m_object_type == (int)eNetObjType::NET_OBJ_TYPE_PLAYER && object->m_owner_id != src->m_player_id) [[unlikely]] - { - std::string target = ""; - - if (auto tgt = g_player_service->get_by_id(object->m_owner_id)) - target = tgt->get_name(); - - LOGF(stream::net_sync, WARNING, "Rejecting clone remove from {}, who is trying to delete {}'s player ped", src->get_name(), target); - return; - } - } - - g_hooking->get_original()(mgr, src, dst, object_id, ownership_token); - } +#include "hooking/hooking.hpp" +#include "util/notify.hpp" + +namespace big +{ + void hooks::received_clone_remove(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, int16_t object_id, uint32_t ownership_token) + { + if (!dst || !dst->m_player_info || !dst->m_player_info->m_ped || !dst->m_player_info->m_ped->m_net_object + || dst->m_player_info->m_ped->m_net_object->m_object_id == object_id) [[unlikely]] + { + notify::crash_blocked(src, "player ped removal"); + return; + } + + if (g_local_player && g_local_player->m_vehicle && g_local_player->m_vehicle->m_net_object + && object_id == g_local_player->m_vehicle->m_net_object->m_object_id) [[unlikely]] + { + if (!NETWORK::NETWORK_IS_ACTIVITY_SESSION()) //If we're in Freemode. + { + if (auto plyr = g_player_service->get_by_id(src->m_player_id)) + { + g.reactions.delete_vehicle.process(plyr); + } + return; + } + } + + if (auto object = g_pointers->m_gta.m_get_net_object(*g_pointers->m_gta.m_network_object_mgr, object_id, true)) [[likely]] + { + if (object->m_object_type == (int)eNetObjType::NET_OBJ_TYPE_PLAYER && object->m_owner_id != src->m_player_id) [[unlikely]] + { + std::string target = ""; + + if (auto tgt = g_player_service->get_by_id(object->m_owner_id)) + target = tgt->get_name(); + + LOGF(stream::net_sync, WARNING, "Rejecting clone remove from {}, who is trying to delete {}'s player ped", src->get_name(), target); + return; + } + } + + g_hooking->get_original()(mgr, src, dst, object_id, ownership_token); + } } \ No newline at end of file