From 27ca4ae6e64d88dcd0aa8607b9bd9c460141089b Mon Sep 17 00:00:00 2001 From: TheGreenBandit <106003542+TheGreenBandit@users.noreply.github.com> Date: Tue, 18 Oct 2022 15:08:05 -0400 Subject: [PATCH] feat(PersistCar): Added Invisible, Invincible and Collision options (#474) Co-authored-by: tupoy_ya Co-authored-by: Evangelos Paterakis Co-authored-by: navmodder <30207948+navmodder@users.noreply.github.com> --- BigBaseV2/src/core/data/model_attachment.hpp | 25 ++++++++---- BigBaseV2/src/function_types.hpp | 1 + BigBaseV2/src/pointers.cpp | 6 +++ BigBaseV2/src/pointers.hpp | 1 + .../services/vehicle/persist_car_service.cpp | 40 ++++++++++++++++++- .../services/vehicle/persist_car_service.hpp | 6 ++- 6 files changed, 67 insertions(+), 12 deletions(-) diff --git a/BigBaseV2/src/core/data/model_attachment.hpp b/BigBaseV2/src/core/data/model_attachment.hpp index 2859c330..c7e13eca 100644 --- a/BigBaseV2/src/core/data/model_attachment.hpp +++ b/BigBaseV2/src/core/data/model_attachment.hpp @@ -9,19 +9,28 @@ namespace big Hash model_hash; Vector3 position; Vector3 rotation; - }; + bool has_collision; + bool is_visible; + bool is_invincible; + + }; + static void to_json(nlohmann::json& j, const model_attachment& attachment) { - static void to_json(nlohmann::json& j, const model_attachment& attachment) - { j = nlohmann::json{ {"model_hash", attachment.model_hash}, {"position_x", attachment.position.x}, {"position_y", attachment.position.y}, {"position_z", attachment.position.z}, - {"rotation_x", attachment.rotation.x}, {"rotation_y", attachment.rotation.y}, {"rotation_z", attachment.rotation.z} }; - } + {"rotation_x", attachment.rotation.x}, {"rotation_y", attachment.rotation.y}, {"rotation_z", attachment.rotation.z}, + {"has_collision", attachment.has_collision}, + {"is_visible", attachment.is_visible}, + {"is_invincible", attachment.is_invincible} - static void from_json(const nlohmann::json& j, model_attachment& attachment) - { + }; + }; + static void from_json(const nlohmann::json& j, model_attachment& attachment) { j.at("model_hash").get_to(attachment.model_hash); j.at("position_x").get_to(attachment.position.x); j.at("position_y").get_to(attachment.position.y); j.at("position_z").get_to(attachment.position.z); j.at("rotation_x").get_to(attachment.rotation.x); j.at("rotation_y").get_to(attachment.rotation.y); j.at("rotation_z").get_to(attachment.rotation.z); + j.at("has_collision").get_to(attachment.has_collision); + j.at("is_visible").get_to(attachment.is_visible); + j.at("is_invincible").get_to(attachment.is_invincible); } -}; +}; \ No newline at end of file diff --git a/BigBaseV2/src/function_types.hpp b/BigBaseV2/src/function_types.hpp index 4a132c89..92255b45 100644 --- a/BigBaseV2/src/function_types.hpp +++ b/BigBaseV2/src/function_types.hpp @@ -19,6 +19,7 @@ namespace big::functions using increment_stat_event = bool(*)(uint64_t net_event_struct, int64_t sender, int64_t a3); using ptr_to_handle = Entity(*)(void* entity); + using get_script_handle_t = uint64_t(*)(int64_t); using get_gameplay_cam_coords = Vector3(*)(); diff --git a/BigBaseV2/src/pointers.cpp b/BigBaseV2/src/pointers.cpp index 4a1e4eca..0251ec9f 100644 --- a/BigBaseV2/src/pointers.cpp +++ b/BigBaseV2/src/pointers.cpp @@ -221,6 +221,12 @@ namespace big m_ptr_to_handle = ptr.sub(0x15).as(); }); + // Get Script Handle + main_batch.add("GSH", "83 F9 FF 74 31 4C 8B 0D", [this](memory::handle ptr) + { + m_get_script_handle = ptr.as(); + }); + // Blame Explode main_batch.add("BE", "0F 85 ? ? ? ? 48 8B 05 ? ? ? ? 48 8B 48 08 E8", [this](memory::handle ptr) { diff --git a/BigBaseV2/src/pointers.hpp b/BigBaseV2/src/pointers.hpp index 74f7c505..ce56f65c 100644 --- a/BigBaseV2/src/pointers.hpp +++ b/BigBaseV2/src/pointers.hpp @@ -27,6 +27,7 @@ namespace big rage::CReplayInterface** m_replay_interface{}; functions::ptr_to_handle m_ptr_to_handle{}; + functions::get_script_handle_t m_get_script_handle{}; rage::scrNativeRegistrationTable* m_native_registration_table{}; functions::get_native_handler m_get_native_handler{}; functions::fix_vectors m_fix_vectors{}; diff --git a/BigBaseV2/src/services/vehicle/persist_car_service.cpp b/BigBaseV2/src/services/vehicle/persist_car_service.cpp index 6af2f5fe..d2614e2e 100644 --- a/BigBaseV2/src/services/vehicle/persist_car_service.cpp +++ b/BigBaseV2/src/services/vehicle/persist_car_service.cpp @@ -1,9 +1,11 @@ #include "persist_car_service.hpp" #include "util/vehicle.hpp" #include "util/world_model.hpp" +#include "util/misc.hpp" +#include "vehicle/CVehicle.hpp" +#include "base/CObject.hpp" #include "pointers.hpp" - namespace big { void persist_car_service::save_vehicle(Vehicle vehicle, std::string_view file_name) @@ -106,6 +108,10 @@ namespace big attachment.position.x, attachment.position.y, attachment.position.z, attachment.rotation.x, attachment.rotation.y, attachment.rotation.z, false, false, false, false, 0, true, 0); + + ENTITY::SET_ENTITY_VISIBLE(object, attachment.is_visible, 0); + ENTITY::SET_ENTITY_COLLISION(object, attachment.has_collision, true); + ENTITY::SET_ENTITY_INVINCIBLE(object, attachment.is_invincible); } } @@ -119,6 +125,7 @@ namespace big 0, attachment.position.x, attachment.position.y, attachment.position.z, attachment.rotation.x, attachment.rotation.y, attachment.rotation.z, + false, false, false, false, 0, true, 0); VEHICLE::SET_VEHICLE_IS_CONSIDERED_BY_PLAYER(vehicle_to_attach, false); @@ -146,6 +153,24 @@ namespace big VEHICLE::SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(vehicle, primary_custom_color[0], primary_custom_color[1], primary_custom_color[2]); } + if (!vehicle_json[is_visible_key].is_null()) + { + bool is_visible = vehicle_json[is_visible_key]; + ENTITY::SET_ENTITY_VISIBLE(vehicle, is_visible, 0); + } + + if (!vehicle_json[has_collision_key].is_null()) + { + bool has_collision = vehicle_json[has_collision_key]; + ENTITY::SET_ENTITY_COLLISION(vehicle, has_collision, true); + } + + if (!vehicle_json[is_invincible_key].is_null()) + { + bool is_invincible = vehicle_json[is_invincible_key]; + ENTITY::SET_ENTITY_INVINCIBLE(vehicle, is_invincible); + } + if (!vehicle_json[custom_secondary_color_key].is_null()) { std::vector secondary_custom_color = vehicle_json[custom_secondary_color_key]; @@ -266,13 +291,17 @@ namespace big const auto object_rotation = ENTITY::GET_ENTITY_ROTATION(object, 0); const auto vehicle_rotation = ENTITY::GET_ENTITY_ROTATION(vehicle, 0); + bool has_collision = ENTITY::GET_ENTITY_COLLISION_DISABLED(object); + bool is_visible = ENTITY::IS_ENTITY_VISIBLE(object); + CObject* cobject = (CObject*)g_pointers->m_get_script_handle(vehicle); + bool is_invincible = misc::has_bit_set(&(int&)cobject->m_damage_bits, 8); Vector3 rotation; rotation.x = (object_rotation.x - vehicle_rotation.x); rotation.y = (object_rotation.y - vehicle_rotation.y); rotation.z = (object_rotation.z - vehicle_rotation.z); - model_attachment attachment = { ENTITY::GET_ENTITY_MODEL(object), location, rotation }; + model_attachment attachment = { ENTITY::GET_ENTITY_MODEL(object), location, rotation, !has_collision, is_visible, is_invincible }; return attachment; } @@ -389,6 +418,13 @@ namespace big VEHICLE::GET_VEHICLE_EXTRA_COLOURS(vehicle, &pearlescent_color, &wheel_color); vehicle_json[pearlescent_color_key] = pearlescent_color; + bool has_collision = ENTITY::GET_ENTITY_COLLISION_DISABLED(vehicle); + bool is_visible = ENTITY::IS_ENTITY_VISIBLE(vehicle); + CVehicle* cvehicle = (CVehicle*)g_pointers->m_get_script_handle(vehicle); + bool is_invincible = misc::has_bit_set(&(int&)cvehicle->m_damage_bits, 8); + vehicle_json[has_collision_key] = !has_collision; + vehicle_json[is_visible_key] = is_visible; + vehicle_json[is_invincible_key] = is_invincible; vehicle_json[wheel_color_key] = wheel_color; std::map vehicle_extras; diff --git a/BigBaseV2/src/services/vehicle/persist_car_service.hpp b/BigBaseV2/src/services/vehicle/persist_car_service.hpp index 4b1c5a79..d9ce7e6e 100644 --- a/BigBaseV2/src/services/vehicle/persist_car_service.hpp +++ b/BigBaseV2/src/services/vehicle/persist_car_service.hpp @@ -11,7 +11,6 @@ namespace big static std::vector list_files(); static Vehicle clone_ped_car(Ped ped, Vehicle vehicle); - static void save_vehicle(Vehicle vehicle, std::string_view file_name); static Vehicle load_vehicle(std::string_view file_name); @@ -20,6 +19,9 @@ namespace big static constexpr auto model_attachments_key = "model_attachments"; static constexpr auto vehicle_attachments_key = "vehicle_attachments"; + static constexpr auto is_invincible_key = "is_invincible"; + static constexpr auto is_visible_key = "is_visible"; + static constexpr auto has_collision_key = "has_collision"; static constexpr auto vehicle_model_hash_key = "vehicle_model_hash"; @@ -77,4 +79,4 @@ namespace big static big::folder check_vehicle_folder(); }; -} +} \ No newline at end of file