feat(PersistCar): Added Invisible, Invincible and Collision options (#474)

Co-authored-by: tupoy_ya <nikitachuvilov2@gmail.com>
Co-authored-by: Evangelos Paterakis <evan@geopjr.dev>
Co-authored-by: navmodder <30207948+navmodder@users.noreply.github.com>
This commit is contained in:
TheGreenBandit 2022-10-18 15:08:05 -04:00 committed by GitHub
parent 85a45ae6c9
commit 27ca4ae6e6
6 changed files with 67 additions and 12 deletions

View File

@ -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);
}
};
};

View File

@ -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(*)();

View File

@ -221,6 +221,12 @@ namespace big
m_ptr_to_handle = ptr.sub(0x15).as<decltype(m_ptr_to_handle)>();
});
// 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<functions::get_script_handle_t>();
});
// Blame Explode
main_batch.add("BE", "0F 85 ? ? ? ? 48 8B 05 ? ? ? ? 48 8B 48 08 E8", [this](memory::handle ptr)
{

View File

@ -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{};

View File

@ -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<int> 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<int, bool> vehicle_extras;

View File

@ -11,7 +11,6 @@ namespace big
static std::vector<std::string> 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();
};
}
}