From 4af9c7f258318849f86c56a8c36da399217fb33c Mon Sep 17 00:00:00 2001 From: maybegreat48 <96936658+maybegreat48@users.noreply.github.com> Date: Fri, 10 Mar 2023 22:41:46 +0000 Subject: [PATCH] fix(Toxic): fix typo (#1062) --- src/hooks/protections/can_apply_data.cpp | 4 +- ..._vehicle_proximity_migration_data_node.cpp | 2 +- src/util/entity.hpp | 38 +++++++++++++------ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/hooks/protections/can_apply_data.cpp b/src/hooks/protections/can_apply_data.cpp index d1fc09f8..59349ef3 100644 --- a/src/hooks/protections/can_apply_data.cpp +++ b/src/hooks/protections/can_apply_data.cpp @@ -668,7 +668,7 @@ namespace big } case RAGE_JOAAT("CVehicleProximityMigrationDataNode"): { - if (g_local_player && g_local_player->m_net_object) + if (object && g_local_player && g_local_player->m_net_object) { const auto migration_node = (CVehicleProximityMigrationDataNode*)(node); if (is_in_vehicle(g_local_player, g_local_player->m_vehicle) && g_local_player->m_vehicle->m_net_object @@ -687,6 +687,8 @@ namespace big } } } + + break; } } } diff --git a/src/hooks/toxic/write_vehicle_proximity_migration_data_node.cpp b/src/hooks/toxic/write_vehicle_proximity_migration_data_node.cpp index 4d970c9c..ef44015d 100644 --- a/src/hooks/toxic/write_vehicle_proximity_migration_data_node.cpp +++ b/src/hooks/toxic/write_vehicle_proximity_migration_data_node.cpp @@ -13,7 +13,7 @@ namespace big g_hooking->get_original()(veh, node); - if (vehicle->m_net_object->m_object_id = g.m_tp_veh_net_id) + if (vehicle->m_net_object->m_object_id == g.m_tp_veh_net_id) { node->m_has_occupants[0] = true; node->m_occupants[0] = g.m_tp_player_net_id; diff --git a/src/util/entity.hpp b/src/util/entity.hpp index 12c176db..33bd9119 100644 --- a/src/util/entity.hpp +++ b/src/util/entity.hpp @@ -72,22 +72,36 @@ namespace big::entity inline bool take_control_of(Entity ent, int timeout = 300) { - auto ptr = g_pointers->m_handle_to_ptr(ent); - if (ptr) + if (auto hnd = g_pointers->m_handle_to_ptr(ent)) { - if (!*g_pointers->m_is_session_started || network_has_control_of_entity(ptr->m_net_object)) - return true; - for (int i = 0; !network_has_control_of_entity(ptr->m_net_object) && i < timeout; i++) + if (!*g_pointers->m_is_session_started || !hnd->m_net_object || network_has_control_of_entity(hnd->m_net_object)) { - g_pointers->m_request_control(ptr->m_net_object); - if (timeout != 0) - script::get_current()->yield(); + return true; } - if (!network_has_control_of_entity(ptr->m_net_object)) - return false; - int netHandle = NETWORK::NETWORK_GET_NETWORK_ID_FROM_ENTITY(ent); - NETWORK::SET_NETWORK_ID_CAN_MIGRATE(netHandle, true); } + else + { + return false; + } + + for (int i = 0; i < timeout; i++) + { + auto hnd = g_pointers->m_handle_to_ptr(ent); + + if (!hnd || !hnd->m_net_object) + return false; + + g_pointers->m_request_control(hnd->m_net_object); + if (timeout != 0) + script::get_current()->yield(); + } + + auto hnd = g_pointers->m_handle_to_ptr(ent); + if (!hnd || !hnd->m_net_object || !network_has_control_of_entity(hnd->m_net_object)) + return false; + + int netHandle = NETWORK::NETWORK_GET_NETWORK_ID_FROM_ENTITY(ent); + NETWORK::SET_NETWORK_ID_CAN_MIGRATE(netHandle, true); return true; }