Custom teleport added euler angles and added persist outfit (#1743)

* Addressed #1694: Added Euler angles to telelocation JSON object.
* Added Persist Outfits to resolve #1669
This commit is contained in:
gir489
2023-07-18 04:16:26 -04:00
committed by GitHub
parent d1a8022eb7
commit 1d78388519
10 changed files with 294 additions and 90 deletions

View File

@ -7,9 +7,10 @@ namespace big
{
std::string name;
float x, y, z;
float yaw = 0.0f, pitch = 0.0f, roll = 0.0f;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(telelocation, name, x, y, z);
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(telelocation, name, x, y, z, yaw, pitch, roll);
class custom_teleport_service
{

View File

@ -0,0 +1,115 @@
#include "util/outfit.hpp"
#include "outfit_service.hpp"
#include "natives.hpp"
namespace big
{
void outfit_service::apply_outfit(nlohmann::json j, bool set_parachute)
{
bool was_components_set = false;
for (auto& item : j["components"].items())
{
std::stringstream ss(item.key());
int id = 0;
ss >> id;
if (!set_parachute && id == 5)
continue;
int drawable_id = item.value()["drawable_id"];
int texture_id = item.value()["texture_id"];
if (PED::GET_PED_DRAWABLE_VARIATION(self::ped, id) != drawable_id || PED::GET_PED_TEXTURE_VARIATION(self::ped, id) != texture_id)
{
was_components_set = true;
PED::SET_PED_COMPONENT_VARIATION(self::ped, id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(self::ped, id));
if (PED::GET_PED_DRAWABLE_VARIATION(self::ped, id) != drawable_id || PED::GET_PED_TEXTURE_VARIATION(self::ped, id) != texture_id) //Run it again Tony to make sure it actually changed.
was_components_set = false;
}
}
for (auto& item : j["props"].items())
{
std::stringstream ss(item.key());
int id = 0;
ss >> id;
int drawable_id = item.value()["drawable_id"];
int texture_id = item.value()["texture_id"];
if (drawable_id == -1 && PED::GET_PED_PROP_INDEX(self::ped, id, 1) != -1)
PED::CLEAR_PED_PROP(self::ped, id, 1);
else if (PED::GET_PED_PROP_INDEX(self::ped, id, 1) != drawable_id || PED::GET_PED_PROP_TEXTURE_INDEX(self::ped, id) != texture_id)
{
was_components_set = true;
PED::SET_PED_PROP_INDEX(self::ped, id, drawable_id, texture_id, NETWORK::NETWORK_IS_GAME_IN_PROGRESS(), 1);
if (id == 0)
{
//Prevent player ped from taking helmet off.
PED::SET_PED_HELMET_PROP_INDEX(self::ped, drawable_id, 0);
PED::SET_PED_HELMET_TEXTURE_INDEX(self::ped, texture_id);
PED::SET_PED_CONFIG_FLAG(self::ped, 34, true);
if (!PED::IS_PED_ON_ANY_BIKE(self::ped))
PED::SET_PED_CONFIG_FLAG(self::ped, 36, true);
}
}
}
if (j.contains("blend_data") && was_components_set)
{
head_blend_data blend_data = j["blend_data"];
PED::SET_PED_HEAD_BLEND_DATA(self::ped, blend_data.shape_first_id, blend_data.shape_second_id,
blend_data.shape_third_id, blend_data.skin_first_id, blend_data.skin_second_id, blend_data.skin_third_id,
blend_data.shape_mix, blend_data.skin_mix, blend_data.third_mix, blend_data.is_parent);
}
}
void outfit_service::save_outfit(std::string filename)
{
outfit::components_t components;
outfit::props_t props;
for (auto& item : components.items)
{
item.drawable_id = PED::GET_PED_DRAWABLE_VARIATION(self::ped, item.id);
item.drawable_id_max = PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(self::ped, item.id) - 1;
item.texture_id = PED::GET_PED_TEXTURE_VARIATION(self::ped, item.id);
item.texture_id_max = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(self::ped, item.id, item.drawable_id) - 1;
}
for (auto& item : props.items)
{
item.drawable_id = PED::GET_PED_PROP_INDEX(self::ped, item.id, 1);
item.drawable_id_max = PED::GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS(self::ped, item.id) - 1;
item.texture_id = PED::GET_PED_PROP_TEXTURE_INDEX(self::ped, item.id);
item.texture_id_max = PED::GET_NUMBER_OF_PED_PROP_TEXTURE_VARIATIONS(self::ped, item.id, item.drawable_id) - 1;
}
nlohmann::json j;
nlohmann::json j_components;
nlohmann::json j_props;
for (auto& item : components.items)
{
nlohmann::json tmp;
tmp["drawable_id"] = item.drawable_id;
tmp["texture_id"] = item.texture_id;
j_components[std::to_string(item.id)] = tmp;
}
for (auto& item : props.items)
{
nlohmann::json tmp;
tmp["drawable_id"] = item.drawable_id;
tmp["texture_id"] = item.texture_id;
j_props[std::to_string(item.id)] = tmp;
}
head_blend_data blend_data{};
PED::GET_PED_HEAD_BLEND_DATA(self::ped, (Any*)&blend_data);
j["components"] = j_components;
j["props"] = j_props;
j["blend_data"] = blend_data;
static folder saved_outfit_path = g_file_manager.get_project_folder("saved_outfits");
std::ofstream o(saved_outfit_path.get_file(filename).get_path());
o << std::setw(4) << j << std::endl;
}
}

View File

@ -0,0 +1,30 @@
#pragma once
namespace big
{
class outfit_service
{
public:
struct head_blend_data
{
public:
alignas(8) int shape_first_id = -1;
alignas(8) int shape_second_id = -1;
alignas(8) int shape_third_id = -1;
alignas(8) int skin_first_id = -1;
alignas(8) int skin_second_id = -1;
alignas(8) int skin_third_id = -1;
alignas(8) float shape_mix = FLT_MAX;
alignas(8) float skin_mix = FLT_MAX;
alignas(8) float third_mix = FLT_MAX;
alignas(8) BOOL is_parent = FALSE;
NLOHMANN_DEFINE_TYPE_INTRUSIVE(head_blend_data, shape_first_id, shape_second_id, shape_third_id, skin_first_id, skin_second_id, skin_third_id, shape_mix, skin_mix, third_mix, is_parent);
};
static_assert(sizeof(head_blend_data) == 0x50, "head_blend_data is not sized properly.");
static void apply_outfit(nlohmann::json, bool);
static void save_outfit(std::string);
};
}