From 5e3c08ce230ad9fb2aeee1cea431afca8907530f Mon Sep 17 00:00:00 2001 From: Aure7138 <100095051+Aure7138@users.noreply.github.com> Date: Wed, 22 Feb 2023 17:23:47 +0800 Subject: [PATCH] feat(protection): model mismatch (#1014) --- src/hooks/protections/can_apply_data.cpp | 18 +++++++++++++++++- src/util/model_info.hpp | 13 +++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/hooks/protections/can_apply_data.cpp b/src/hooks/protections/can_apply_data.cpp index 0d144e27..1d1c0778 100644 --- a/src/hooks/protections/can_apply_data.cpp +++ b/src/hooks/protections/can_apply_data.cpp @@ -552,6 +552,8 @@ namespace big inline bool is_crash_ped(uint32_t model) { + if (!model_info::is_model_of_type(model, eModelType::Ped, eModelType::OnlineOnlyPed)) + return true; for (auto iterator : crash_peds) if (iterator == model) return true; @@ -560,6 +562,8 @@ namespace big inline bool is_crash_vehicle(uint32_t model) { + if (!model_info::is_model_of_type(model, eModelType::Vehicle, eModelType::Unk133)) + return true; for (auto iterator : crash_vehicles) if (iterator == model) return true; @@ -568,6 +572,8 @@ namespace big inline bool is_crash_object(uint32_t model) { + if (!model_info::is_model_of_type(model, eModelType::Object, eModelType::Time, eModelType::Weapon, eModelType::Destructable, eModelType::WorldObject, eModelType::Sprinkler, eModelType::Unk65, eModelType::Plant, eModelType::LOD, eModelType::Unk132, eModelType::Building)) + return true; for (auto iterator : crash_objects) if (iterator == model) return true; @@ -614,6 +620,16 @@ namespace big switch (node_hash) { + case (RAGE_JOAAT("CVehicleCreationDataNode")): + { + const auto creation_node = (CVehicleCreationDataNode*)(node); + if (is_crash_vehicle(creation_node->m_model)) + { + notify::crash_blocked(sender, "invalid vehicle model"); + return true; + } + break; + } case RAGE_JOAAT("CDoorCreationDataNode"): { const auto creation_node = (CDoorCreationDataNode*)(node); @@ -627,7 +643,7 @@ namespace big case RAGE_JOAAT("CPickupCreationDataNode"): { const auto creation_node = (CPickupCreationDataNode*)(node); - if (is_crash_object(creation_node->m_custom_model)) + if (creation_node->m_custom_model && is_crash_object(creation_node->m_custom_model)) { notify::crash_blocked(sender, "invalid pickup model"); return true; diff --git a/src/util/model_info.hpp b/src/util/model_info.hpp index e7742bf0..c9362dea 100644 --- a/src/util/model_info.hpp +++ b/src/util/model_info.hpp @@ -55,11 +55,16 @@ namespace big return nullptr; } - static bool is_model_of_type(const rage::joaat_t hash, const eModelType type) + template + static bool is_model_of_type(const rage::joaat_t hash, const T arg, const Args... args) { - if (const auto model = model_info::get_model(hash); model && model->m_model_type == type) - return true; - return false; + bool of_type = false; + if (const auto model = model_info::get_model(hash)) + { + of_type = model->m_model_type == arg; + ([&of_type, &model](eModelType type) { of_type |= model->m_model_type == type; }(args), ...); + } + return of_type; } }; } \ No newline at end of file