diff --git a/src/util/outfit.hpp b/src/util/outfit.hpp index 41b46e00..875c3127 100644 --- a/src/util/outfit.hpp +++ b/src/util/outfit.hpp @@ -3,6 +3,45 @@ namespace big::outfit { + struct outfit_t + { + int id; + std::string label; + int drawable_id = 0; + int drawable_id_max = 0; + int texture_id = 0; + int texture_id_max = 0; + }; + + struct components_t + { + std::vector items = {{0, "OUTFIT_HEAD"_T.data()}, + {1, "OUTFIT_BERD"_T.data()}, + {2, "OUTFIT_HAIR"_T.data()}, + {3, "OUTFIT_UPPR"_T.data()}, + {4, "OUTFIT_LOWR"_T.data()}, + {5, "OUTFIT_HAND"_T.data()}, + {6, "OUTFIT_FEET"_T.data()}, + {7, "OUTFIT_TEEF"_T.data()}, + {8, "OUTFIT_ACCS"_T.data()}, + {9, "OUTFIT_TASK"_T.data()}, + {10, "OUTFIT_DECL"_T.data()}, + {11, "OUTFIT_JBIB"_T.data()}}; + }; + + struct props_t + { + std::vector items = {{0, "OUTFIT_HEAD"_T.data()}, + {1, "OUTFIT_GLASSES"_T.data()}, + {2, "OUTFIT_EARS"_T.data()}, + {3, "OUTFIT_UNK1"_T.data()}, + {4, "OUTFIT_UNK2"_T.data()}, + {5, "OUTFIT_UNK3"_T.data()}, + {6, "OUTFIT_WATCH"_T.data()}, + {7, "OUTFIT_WRIST"_T.data()}, + {8, "OUTFIT_UNK4"_T.data()}}; + }; + inline char* get_slot_name_address(int slot) { return script_global(2359296).at(0, 5568).at(681).at(2460).at(slot, 8).as(); diff --git a/src/util/ped.hpp b/src/util/ped.hpp index ae2baced..16c6b637 100644 --- a/src/util/ped.hpp +++ b/src/util/ped.hpp @@ -2,6 +2,7 @@ #include "entity.hpp" #include "natives.hpp" #include "pointers.hpp" +#include "outfit.hpp" namespace big::ped { @@ -95,4 +96,18 @@ namespace big::ped return ped; } + + inline void set_ped_random_component_variation(Ped ped) + { + auto range = [](int lower_bound, int upper_bound) -> int { + return std::rand() % (upper_bound - lower_bound + 1) + lower_bound; + }; + outfit::components_t components; + for (auto& item : components.items) + { + int drawable_id = range(0, PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(ped, item.id) - 1); + int texture_id = range(0, PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(ped, item.id, drawable_id) - 1); + PED::SET_PED_COMPONENT_VARIATION(ped, item.id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(ped, item.id)); + } + } } diff --git a/src/views/settings/view_outfit_editor.cpp b/src/views/settings/view_outfit_editor.cpp index 6852168d..02285422 100644 --- a/src/views/settings/view_outfit_editor.cpp +++ b/src/views/settings/view_outfit_editor.cpp @@ -1,50 +1,18 @@ #include "natives.hpp" #include "pointers.hpp" +#include "util/outfit.hpp" +#include "util/ped.hpp" #include "views/view.hpp" namespace big { - static int range(int lower_bound, int upper_bound) - { - return std::rand() % (upper_bound - lower_bound + 1) + lower_bound; - } - void view::outfit_editor() { - struct outfit_t - { - int id; - std::string label; - int drawable_id = 0; - int drawable_id_max = 0; - int texture_id = 0; - int texture_id_max = 0; - }; - - static std::vector components = {{0, "OUTFIT_HEAD"_T.data()}, - {1, "OUTFIT_BERD"_T.data()}, - {2, "OUTFIT_HAIR"_T.data()}, - {3, "OUTFIT_UPPR"_T.data()}, - {4, "OUTFIT_LOWR"_T.data()}, - {5, "OUTFIT_HAND"_T.data()}, - {6, "OUTFIT_FEET"_T.data()}, - {7, "OUTFIT_TEEF"_T.data()}, - {8, "OUTFIT_ACCS"_T.data()}, - {9, "OUTFIT_TASK"_T.data()}, - {10, "OUTFIT_DECL"_T.data()}, - {11, "OUTFIT_JBIB"_T.data()}}; - static std::vector props = {{0, "OUTFIT_HEAD"_T.data()}, - {1, "OUTFIT_GLASSES"_T.data()}, - {2, "OUTFIT_EARS"_T.data()}, - {3, "OUTFIT_UNK1"_T.data()}, - {4, "OUTFIT_UNK2"_T.data()}, - {5, "OUTFIT_UNK3"_T.data()}, - {6, "OUTFIT_WATCH"_T.data()}, - {7, "OUTFIT_WRIST"_T.data()}, - {8, "OUTFIT_UNK4"_T.data()}}; + static outfit::components_t components; + static outfit::props_t props; g_fiber_pool->queue_job([] { - for (auto& item : components) + 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; @@ -53,7 +21,7 @@ namespace big item.texture_id_max = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(self::ped, item.id, item.drawable_id) - 1; } - for (auto& item : props) + 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; @@ -64,12 +32,7 @@ namespace big }); components::button("OUTFIT_RANDOM_COMPONENT"_T, [] { - for (auto& item : components) - { - int drawable_id = range(0, PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(self::ped, item.id) - 1); - int texture_id = range(0, PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(self::ped, item.id, drawable_id) - 1); - PED::SET_PED_COMPONENT_VARIATION(self::ped, item.id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(self::ped, item.id)); - } + ped::set_ped_random_component_variation(self::ped); }); ImGui::SameLine(); @@ -90,9 +53,9 @@ namespace big components::button("EXPORT_TO_CLIPBOARD"_T, [] { std::stringstream ss; - for (auto& item : components) + for (auto& item : components.items) ss << item.id << " " << item.drawable_id << " " << item.texture_id << " "; - for (auto& item : props) + for (auto& item : props.items) ss << item.id << " " << item.drawable_id << " " << item.texture_id << " "; ImGui::SetClipboardText(ss.str().c_str()); g_notification_service->push("OUTFIT"_T.data(), "EXPORT_TO_CLIPBOARD"_T.data()); @@ -101,7 +64,7 @@ namespace big components::button("IMPORT_FROM_CLIPBOARD"_T, [] { std::stringstream ss(ImGui::GetClipboardText()); - for (auto& item : components) + for (auto& item : components.items) { int id = 0; int drawable_id = 0; @@ -111,7 +74,7 @@ namespace big ss >> texture_id; PED::SET_PED_COMPONENT_VARIATION(self::ped, id, drawable_id, texture_id, PED::GET_PED_PALETTE_VARIATION(self::ped, id)); } - for (auto& item : props) + for (auto& item : props.items) { int id = 0; int drawable_id = 0; @@ -127,7 +90,7 @@ namespace big }); ImGui::BeginGroup(); - for (auto& item : components) + for (auto& item : components.items) { ImGui::SetNextItemWidth(60); if (ImGui::InputInt(std::format("{} [0,{}]", item.label, item.drawable_id_max).c_str(), &item.drawable_id, 0)) @@ -142,7 +105,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : components) + for (auto& item : components.items) { ImGui::SetNextItemWidth(60); if (ImGui::InputInt(std::format("{} {} [0,{}]", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id, 0)) @@ -157,7 +120,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : props) + for (auto& item : props.items) { ImGui::SetNextItemWidth(60); if (ImGui::InputInt(std::format("{} [0,{}]", item.label, item.drawable_id_max).c_str(), &item.drawable_id, 0)) @@ -175,7 +138,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : props) + for (auto& item : props.items) { ImGui::SetNextItemWidth(60); if (ImGui::InputInt(std::format("{} {} [0,{}]", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id, 0)) @@ -206,7 +169,7 @@ namespace big nlohmann::json j_components; nlohmann::json j_props; - for (auto& item : components) + for (auto& item : components.items) { nlohmann::json tmp; tmp["drawable_id"] = item.drawable_id; @@ -214,7 +177,7 @@ namespace big j_components[std::to_string(item.id)] = tmp; } - for (auto& item : props) + for (auto& item : props.items) { nlohmann::json tmp; tmp["drawable_id"] = item.drawable_id; diff --git a/src/views/settings/view_outfit_slots.cpp b/src/views/settings/view_outfit_slots.cpp index 7fbf290a..6ec899a2 100644 --- a/src/views/settings/view_outfit_slots.cpp +++ b/src/views/settings/view_outfit_slots.cpp @@ -22,40 +22,11 @@ namespace big ImGui::SetNextItemWidth(300); ImGui::InputText("OUTFIT_NAME"_T.data(), outfit::get_slot_name_address(slot), 16); - struct outfit_t - { - int id; - std::string label; - int drawable_id = 0; - int drawable_id_max = 0; - int texture_id = 0; - int texture_id_max = 0; - }; - - static std::vector components = {{0, "OUTFIT_HEAD"_T.data()}, - {1, "OUTFIT_BERD"_T.data()}, - {2, "OUTFIT_HAIR"_T.data()}, - {3, "OUTFIT_UPPR"_T.data()}, - {4, "OUTFIT_LOWR"_T.data()}, - {5, "OUTFIT_HAND"_T.data()}, - {6, "OUTFIT_FEET"_T.data()}, - {7, "OUTFIT_TEEF"_T.data()}, - {8, "OUTFIT_ACCS"_T.data()}, - {9, "OUTFIT_TASK"_T.data()}, - {10, "OUTFIT_DECL"_T.data()}, - {11, "OUTFIT_JBIB"_T.data()}}; - static std::vector props = {{0, "OUTFIT_HEAD"_T.data()}, - {1, "OUTFIT_GLASSES"_T.data()}, - {2, "OUTFIT_EARS"_T.data()}, - {3, "OUTFIT_UNK1"_T.data()}, - {4, "OUTFIT_UNK2"_T.data()}, - {5, "OUTFIT_UNK3"_T.data()}, - {6, "OUTFIT_WATCH"_T.data()}, - {7, "OUTFIT_WRIST"_T.data()}, - {8, "OUTFIT_UNK4"_T.data()}}; + static outfit::components_t components; + static outfit::props_t props; g_fiber_pool->queue_job([] { - for (auto& item : components) + for (auto& item : components.items) { item.drawable_id = *outfit::get_component_drawable_id_address(slot, item.id); item.drawable_id_max = PED::GET_NUMBER_OF_PED_DRAWABLE_VARIATIONS(self::ped, item.id) - 1; @@ -64,7 +35,7 @@ namespace big item.texture_id_max = PED::GET_NUMBER_OF_PED_TEXTURE_VARIATIONS(self::ped, item.id, item.drawable_id) - 1; } - for (auto& item : props) + for (auto& item : props.items) { item.drawable_id = *outfit::get_prop_drawable_id_address(slot, item.id); item.drawable_id_max = PED::GET_NUMBER_OF_PED_PROP_DRAWABLE_VARIATIONS(self::ped, item.id) - 1; @@ -76,9 +47,9 @@ namespace big components::button("EXPORT_TO_CLIPBOARD"_T, [] { std::stringstream ss; - for (auto& item : components) + for (auto& item : components.items) ss << item.id << " " << item.drawable_id << " " << item.texture_id << " "; - for (auto& item : props) + for (auto& item : props.items) ss << item.id << " " << item.drawable_id << " " << item.texture_id << " "; ImGui::SetClipboardText(ss.str().c_str()); g_notification_service->push("OUTFIT"_T.data(), "EXPORT_TO_CLIPBOARD"_T.data()); @@ -87,7 +58,7 @@ namespace big components::button("IMPORT_FROM_CLIPBOARD"_T, [] { std::stringstream ss(ImGui::GetClipboardText()); - for (auto& item : components) + for (auto& item : components.items) { int id = 0; int drawable_id = 0; @@ -98,7 +69,7 @@ namespace big *outfit::get_component_drawable_id_address(slot, id) = drawable_id; *outfit::get_component_texture_id_address(slot, id) = texture_id; } - for (auto& item : props) + for (auto& item : props.items) { int id = 0; int drawable_id = 0; @@ -112,7 +83,7 @@ namespace big }); ImGui::BeginGroup(); - for (auto& item : components) + for (auto& item : components.items) { ImGui::SetNextItemWidth(60); ImGui::InputInt(std::format("{} [0,{}]", item.label, item.drawable_id_max).c_str(), outfit::get_component_drawable_id_address(slot, item.id), 0); @@ -122,7 +93,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : components) + for (auto& item : components.items) { ImGui::SetNextItemWidth(60); ImGui::InputInt(std::format("{} {} [0,{}]", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_component_texture_id_address(slot, item.id), 0); @@ -132,7 +103,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : props) + for (auto& item : props.items) { ImGui::SetNextItemWidth(60); ImGui::InputInt(std::format("{} [0,{}]", item.label, item.drawable_id_max).c_str(), outfit::get_prop_drawable_id_address(slot, item.id), 0); @@ -142,7 +113,7 @@ namespace big ImGui::SameLine(); ImGui::BeginGroup(); - for (auto& item : props) + for (auto& item : props.items) { ImGui::SetNextItemWidth(60); ImGui::InputInt(std::format("{} {} [0,{}]", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_prop_texture_id_address(slot, item.id), 0); diff --git a/src/views/world/view_spawn_ped.cpp b/src/views/world/view_spawn_ped.cpp index 6f64f4f0..71555023 100644 --- a/src/views/world/view_spawn_ped.cpp +++ b/src/views/world/view_spawn_ped.cpp @@ -134,7 +134,7 @@ namespace big PED::SET_PED_ID_RANGE(ped, 200.0f); PED::SET_PED_FIRING_PATTERN(ped, RAGE_JOAAT("FIRING_PATTERN_FULL_AUTO")); PED::SET_PED_SHOOT_RATE(ped, 150); - PED::SET_PED_RANDOM_COMPONENT_VARIATION(ped, 0); + ped::set_ped_random_component_variation(ped); if (is_bodyguard) { @@ -617,7 +617,7 @@ namespace big return; } - PED::SET_PED_RANDOM_COMPONENT_VARIATION(self::ped, 0); + ped::set_ped_random_component_variation(self::ped); } });