From 563ad264cdf8e50f4bd388b7482e74fd667a035a Mon Sep 17 00:00:00 2001 From: Yimura Date: Mon, 12 Sep 2022 22:55:23 +0100 Subject: [PATCH] refactor: Cleaned up Received Clone Sync hook (#445) --- .../hooks/protections/received_clone_sync.cpp | 72 +++++++------------ 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/BigBaseV2/src/hooks/protections/received_clone_sync.cpp b/BigBaseV2/src/hooks/protections/received_clone_sync.cpp index 44d7b99a..e16c78fe 100644 --- a/BigBaseV2/src/hooks/protections/received_clone_sync.cpp +++ b/BigBaseV2/src/hooks/protections/received_clone_sync.cpp @@ -1,49 +1,26 @@ #include "hooking.hpp" #include "core/globals.hpp" -#include "natives.hpp" #include "network/netObject.hpp" #include "base/CBaseModelInfo.hpp" #include "vehicle/CVehicleModelInfo.hpp" #include "base/CObject.hpp" +#include "util/model_info.hpp" -namespace big { - - /* Return types of this hook: +namespace big +{ + enum SyncResponse : int64_t + { + NoSyncTreeFound = 1, // No sync tree found + PlayerIsNotInOurRoamingBubble = 1, // Player is not in our roaming bubble + WrongOwner = 2, // Wrong owner + ObjectIsBeingReassinged = 2, // Object is being reassigned + CantApplyData_NoNetworkObject = 4, // Can't apply data - no network object + CantApplyData = 6, // Can't apply data + CantApplyData_NoGameObject = 6, // Can't apply data - no game object + CantApplyData_NetworkClosed = 7, // Can't apply data - network closed + SuccessfullSync = 8 + }; - case 1: - LOG(INFO) << "Player is not in our roaming bubble"; - break; - case 2: - LOG(INFO) << "Wrong owner"; - break; - case 4: - LOG(INFO) << "Can't apply data - no network object"; - break; - case 6: - LOG(INFO) << "Can't apply data - no game object"; - break; - case 7: - LOG(INFO) << "Can't apply data - network closed"; - break; - case 8: - LOG(INFO) << "Succesfull sync"; - break; - */ - - const CVehicleModelInfo* get_model_data(rage::joaat_t hash) { - auto modelTble = g_pointers->m_model_table; - for (auto i = modelTble->m_lookup_table[hash % modelTble->m_lookup_key]; i; i = i->m_next) - { - if (i->m_hash == hash) - { - if (const auto model = modelTble->m_data[i->m_idx]; model) - { - return reinterpret_cast(model); - } - } - } - return nullptr; - } int64_t hooks::received_clone_sync(CNetworkObjectMgr* mgr, CNetGamePlayer* src, CNetGamePlayer* dst, eObjType sync_type, uint16_t obj_id, rage::datBitBuffer* buffer, uint16_t unk, uint32_t timestamp) { if (auto sync_tree = g_pointers->m_get_sync_tree_for_type(mgr, sync_type); sync_tree && *g_pointers->m_is_session_started) { @@ -66,30 +43,29 @@ namespace big { if (g->notifications.mismatch_sync_type.notify) g_notification_service->push_warning(fmt::format("Mismatch Sync from {}", src->get_name()), fmt::format("Type {} in sync tree {}", sync_type, tree_name)); - return 2; + return SyncResponse::WrongOwner; } else if (auto game_obj = net_obj->GetGameObject(); game_obj) { if (auto model_info = game_obj->m_model_info) { - if (!STREAMING::IS_MODEL_VALID(model_info->m_model_hash)) + const auto model = model_info::get_model(model_info->m_model_hash); + if (!model || model_info->m_model_type != model->m_model_type) { - return 2; + return SyncResponse::WrongOwner; } - else if (reinterpret_cast(model_info)->m_vehicle_type != get_model_data(model_info->m_model_hash)->m_vehicle_type) + + if (model->m_model_type == eModelType::Vehicle && + reinterpret_cast(model_info)->m_vehicle_type != reinterpret_cast(model)->m_vehicle_type) { - return 2; - } - else if (model_info->m_model_type != get_model_data(model_info->m_model_hash)->m_model_type) - { - return 2; + return SyncResponse::WrongOwner; } } } } else if (sync_type != eObjType::pedObjType) //We don't want to not sync a player, so we ensure it's not a ped { - return 2; + return SyncResponse::WrongOwner; } } return g_hooking->m_received_clone_sync_hook.get_original()(mgr, src, dst, sync_type, obj_id, buffer, unk, timestamp);