From 21929ee421773e98a6c5635a38b05030705a9680 Mon Sep 17 00:00:00 2001 From: lonelybud <139460769+lonelybud@users.noreply.github.com> Date: Thu, 25 Jul 2024 00:57:06 +0530 Subject: [PATCH] fix #3406 & refactor bounds check (#3419) * Revert "change DragInt to SliderInt (#3378)" This reverts outfit changes from commit c8dd29075c947f68b14b1a4beb6984538669aab7. * Revert "Redesigned outfit editor (#3376)" This reverts commit 5c6f7ae8c5a034f2a3f6f6df1ad0da9a870962bb. * fix components text and draw should not be -1 --- src/util/outfit.hpp | 12 ++++----- src/views/self/view_outfit_editor.cpp | 36 +++++++++------------------ src/views/self/view_outfit_slots.cpp | 8 +++--- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/src/util/outfit.hpp b/src/util/outfit.hpp index afedd0a9..119981a4 100644 --- a/src/util/outfit.hpp +++ b/src/util/outfit.hpp @@ -38,20 +38,20 @@ namespace big::outfit {7, "OUTFIT_WRIST"_T.data()}}; }; - inline void check_bounds_drawable(outfit_t* item) + inline void check_bounds_drawable(outfit_t* item, const int lower) { if(item->drawable_id > item->drawable_id_max) item->drawable_id = item->drawable_id_max; - if(item->drawable_id < 0) - item->drawable_id = 0; + if(item->drawable_id < lower) + item->drawable_id = lower; } - inline void check_bounds_texture(outfit_t* item) + inline void check_bounds_texture(outfit_t* item, const int lower) { if(item->texture_id > item->texture_id_max) item->texture_id = item->texture_id_max; - if(item->texture_id < 0) - item->texture_id = 0; + if(item->texture_id < lower) + item->texture_id = lower; } // usually each update increases 1// diff --git a/src/views/self/view_outfit_editor.cpp b/src/views/self/view_outfit_editor.cpp index d6d92a22..a599e6e4 100644 --- a/src/views/self/view_outfit_editor.cpp +++ b/src/views/self/view_outfit_editor.cpp @@ -106,17 +106,14 @@ namespace big for (auto& item : components.items) { ImGui::SetNextItemWidth(120); - if (item.drawable_id_max <= 0) - ImGui::BeginDisabled(); - if (ImGui::SliderInt(std::format("{} [0,{}]##1", item.label, item.drawable_id_max).c_str(), &item.drawable_id, 0, item.drawable_id_max)) + if (ImGui::InputInt(std::format("{} [0,{}]##1", item.label, item.drawable_id_max).c_str(), &item.drawable_id)) { - //outfit::check_bounds_drawable(&item); // The game does this on its own, but seems to crash if we call OOB values to fast. (-1 is not a valid scenario) + outfit::check_bounds_drawable(&item, 0); // The game does this on it's own but seems to crash if we call OOB values to fast. + g_fiber_pool->queue_job([item] { PED::SET_PED_COMPONENT_VARIATION(self::ped, item.id, item.drawable_id, 0, PED::GET_PED_PALETTE_VARIATION(self::ped, item.id)); }); } - if (item.drawable_id_max <= 0) - ImGui::EndDisabled(); } ImGui::EndGroup(); @@ -126,17 +123,14 @@ namespace big for (auto& item : components.items) { ImGui::SetNextItemWidth(120); - if (item.texture_id_max <= 0) - ImGui::BeginDisabled(); - if (ImGui::SliderInt(std::format("{} {} [0,{}]##2", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id, 0, item.texture_id_max)) + if (ImGui::InputInt(std::format("{} {} [0,{}]##2", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id)) { - //outfit::check_bounds_drawable(&item); // The game does this on its own, but seems to crash if we call OOB values to fast. (-1 is not a valid scenario) + outfit::check_bounds_texture(&item, 0); // The game does this on it's own but seems to crash if we call OOB values to fast. + g_fiber_pool->queue_job([item] { PED::SET_PED_COMPONENT_VARIATION(self::ped, item.id, item.drawable_id, item.texture_id, PED::GET_PED_PALETTE_VARIATION(self::ped, item.id)); }); } - if (item.texture_id_max <= 0) - ImGui::EndDisabled(); } ImGui::EndGroup(); @@ -146,11 +140,10 @@ namespace big for (auto& item : props.items) { ImGui::SetNextItemWidth(120); - if (item.drawable_id_max <= 0) - ImGui::BeginDisabled(); - if (ImGui::SliderInt(std::format("{} [0,{}]##3", item.label, item.drawable_id_max).c_str(), &item.drawable_id, -1, item.drawable_id_max)) + if (ImGui::InputInt(std::format("{} [0,{}]##3", item.label, item.drawable_id_max).c_str(), &item.drawable_id)) { - //outfit::check_bounds_drawable(&item); // The game does this on its own, but seems to crash if we call OOB values to fast. (-1 is only used here as a magic number to signal the removal of the prop.) + outfit::check_bounds_drawable(&item, -1); // The game does this on it's own but seems to crash if we call OOB values to fast. + g_fiber_pool->queue_job([item] { if (item.drawable_id == -1) PED::CLEAR_PED_PROP(self::ped, item.id, 1); @@ -158,8 +151,6 @@ namespace big PED::SET_PED_PROP_INDEX(self::ped, item.id, item.drawable_id, 0, TRUE, 1); }); } - if (item.drawable_id_max <= 0) - ImGui::EndDisabled(); } ImGui::EndGroup(); @@ -169,17 +160,14 @@ namespace big for (auto& item : props.items) { ImGui::SetNextItemWidth(120); - if (item.texture_id_max <= 0) - ImGui::BeginDisabled(); - if (ImGui::SliderInt(std::format("{} {} [0,{}]##4", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id, 0, item.texture_id_max)) + if (ImGui::InputInt(std::format("{} {} [0,{}]##4", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), &item.texture_id)) { - //outfit::check_bounds_drawable(&item); // The game does this on its own, but seems to crash if we call OOB values to fast. (-1 is not a valid scenario) + outfit::check_bounds_texture(&item, -1); // The game does this on it's own but seems to crash if we call OOB values to fast. + g_fiber_pool->queue_job([item] { PED::SET_PED_PROP_INDEX(self::ped, item.id, item.drawable_id, item.texture_id, TRUE, 1); }); } - if (item.texture_id_max <= 0) - ImGui::EndDisabled(); } ImGui::EndGroup(); diff --git a/src/views/self/view_outfit_slots.cpp b/src/views/self/view_outfit_slots.cpp index c7db6701..543827cb 100644 --- a/src/views/self/view_outfit_slots.cpp +++ b/src/views/self/view_outfit_slots.cpp @@ -88,7 +88,7 @@ namespace big for (auto& item : components.items) { ImGui::SetNextItemWidth(120); - ImGui::SliderInt(std::format("{} [0,{}]##1", item.label, item.drawable_id_max).c_str(), outfit::get_component_drawable_id_address(slot, item.id), 0, item.drawable_id_max); + ImGui::InputInt(std::format("{} [0,{}]##1", item.label, item.drawable_id_max).c_str(), outfit::get_component_drawable_id_address(slot, item.id)); } ImGui::EndGroup(); @@ -98,7 +98,7 @@ namespace big for (auto& item : components.items) { ImGui::SetNextItemWidth(120); - ImGui::SliderInt(std::format("{} {} [0,{}]##2", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_component_texture_id_address(slot, item.id), 0, item.texture_id_max); + ImGui::InputInt(std::format("{} {} [0,{}]##2", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_component_texture_id_address(slot, item.id)); } ImGui::EndGroup(); @@ -108,7 +108,7 @@ namespace big for (auto& item : props.items) { ImGui::SetNextItemWidth(120); - ImGui::SliderInt(std::format("{} [0,{}]##3", item.label, item.drawable_id_max).c_str(), outfit::get_prop_drawable_id_address(slot, item.id), 0, item.drawable_id_max); + ImGui::InputInt(std::format("{} [0,{}]##3", item.label, item.drawable_id_max).c_str(), outfit::get_prop_drawable_id_address(slot, item.id)); } ImGui::EndGroup(); @@ -118,7 +118,7 @@ namespace big for (auto& item : props.items) { ImGui::SetNextItemWidth(120); - ImGui::SliderInt(std::format("{} {} [0,{}]##4", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_prop_texture_id_address(slot, item.id), 0, item.texture_id_max); + ImGui::InputInt(std::format("{} {} [0,{}]##4", item.label, "OUTFIT_TEX"_T, item.texture_id_max).c_str(), outfit::get_prop_texture_id_address(slot, item.id)); } ImGui::EndGroup(); }