From 0826a790058661450f91a5dfc95b3c2e438b5732 Mon Sep 17 00:00:00 2001 From: TerraFaster Date: Sun, 7 Aug 2022 17:04:50 +0300 Subject: [PATCH] Improve AutoCook feature UX --- .../src/user/cheat/world/AutoCook.cpp | 46 +++++++++++++++---- cheat-library/src/user/cheat/world/AutoCook.h | 6 +-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/cheat-library/src/user/cheat/world/AutoCook.cpp b/cheat-library/src/user/cheat/world/AutoCook.cpp index 12cab44..712de5d 100644 --- a/cheat-library/src/user/cheat/world/AutoCook.cpp +++ b/cheat-library/src/user/cheat/world/AutoCook.cpp @@ -14,7 +14,9 @@ namespace cheat::feature app::Component_1* Profirency = nullptr; } - static void PlayerModule_RequestPlayerCook(app::MoleMole_PlayerModule* __this, uint32_t recipeId, uint32_t avatarId, uint32_t qteQuality, uint32_t count, MethodInfo* method); + static std::map qualities{ {"Strange", 1}, {"Normal", 2}, {"Delicious", 3} }; + + static void PlayerModule_RequestPlayerCook(app::MoleMole_PlayerModule* __this, uint32_t recipeId, uint32_t avatarId, uint32_t qteQuality, uint32_t count, MethodInfo* method); static void PlayerModule_OnPlayerCookRsp(app::MoleMole_PlayerModule* __this, app::PlayerCookRsp* rsp, MethodInfo* method); static void CookingQtePageContext_UpdateProficiency(app::CookingQtePageContext* __this, MethodInfo* method); @@ -22,7 +24,7 @@ namespace cheat::feature NF(f_Enabled, "Standart Cooking", "AutoCook", false), NF(f_FastProficiency, "Fast Proficiency", "AutoCook", false), NF(f_CountField, "Count Item", "AutoCook", 1), - NF(f_QualityField, "Quality", "AutoCook", 1) + NF(f_QualityField, "Quality", "AutoCook", "Normal") { HookManager::install(app::MoleMole_PlayerModule_RequestPlayerCook, PlayerModule_RequestPlayerCook); HookManager::install(app::MoleMole_PlayerModule_OnPlayerCookRsp, PlayerModule_OnPlayerCookRsp); @@ -38,12 +40,24 @@ namespace cheat::feature void AutoCook::DrawMain() { ConfigWidget(f_Enabled, "Fast Cooking if the recipe has fast cooking open. \n" \ - "If fast cooking is closed, you in addition need to turn on Fast Proficiency."); + "If fast cooking is closed, you in addition need to turn on Fast Proficiency."); ConfigWidget(f_FastProficiency, "Quickly prepare an unstudied recipe to the maximum possible."); ConfigWidget("Count Item", f_CountField, 1, 1, 100, "How much to cook at a time.\n" \ "(For standard mode only.)"); - ConfigWidget("Quality Cooking", f_QualityField, 1, 1, 3, "Quality of the cook."); + if (ImGui::BeginCombo("Cooking Quality", f_QualityField.value().c_str())) + { + for (auto& [qualityName, quality] : qualities) + { + bool is_selected = (f_QualityField.value().c_str() == qualityName); + if (ImGui::Selectable(qualityName.c_str(), is_selected)) + f_QualityField.value() = qualityName; + + if (is_selected) + ImGui::SetItemDefaultFocus(); + } + ImGui::EndCombo(); + } } bool AutoCook::NeedStatusDraw() const @@ -53,7 +67,10 @@ namespace cheat::feature void AutoCook::DrawStatus() { - ImGui::Text("Auto Cooking [%s]", f_FastProficiency ? "Proficiency" : "Standart"); + if (f_FastProficiency) + ImGui::Text("Auto Cooking [Proficiency]"); + else + ImGui::Text("Auto Cooking [Standart, %s]", f_QualityField.value().c_str()); } AutoCook& AutoCook::GetInstance() @@ -82,9 +99,14 @@ namespace cheat::feature if (autoCook.f_Enabled || autoCook.f_FastProficiency) { autoCook.CookFoodMaxNum = app::MoleMole_Config_CookRecipeExcelConfig_CheckCookFoodMaxNum(recipeId, nullptr); - qteQuality = autoCook.f_QualityField; - if (!autoCook.f_FastProficiency && autoCook.f_Enabled){ + // To prevent possible crashes + if (!qualities.count(autoCook.f_QualityField.value())) + autoCook.f_QualityField.value() = "Normal"; + + qteQuality = qualities.find(autoCook.f_QualityField.value())->second; + + if (!autoCook.f_FastProficiency && autoCook.f_Enabled) { count = autoCook.f_CountField; if (autoCook.f_CountField > autoCook.CookFoodMaxNum) count = autoCook.CookFoodMaxNum; @@ -99,7 +121,7 @@ namespace cheat::feature auto RectTransform = app::GameObject_GetComponentByName(GameObject::Profirency, string_to_il2cppi("RectTransform"), nullptr); auto TransformChild = app::Transform_GetChild(reinterpret_cast(RectTransform), 0, nullptr); auto TextComponent = app::Component_1_GetComponent_1(reinterpret_cast(TransformChild), string_to_il2cppi("Text"), nullptr); - + if (TextComponent != nullptr) { auto Text_str = app::Text_get_text(reinterpret_cast(TextComponent), nullptr); auto ProficiencyStr = il2cppi_to_string(Text_str).erase(0, il2cppi_to_string(Text_str).find_first_of(" .")); @@ -127,7 +149,11 @@ namespace cheat::feature AutoCook& autoCook = AutoCook::GetInstance(); if (autoCook.f_Enabled || autoCook.f_FastProficiency) { - rsp->fields.qteQuality_ = autoCook.f_QualityField; + // To prevent possible crashes + if (!qualities.count(autoCook.f_QualityField.value())) + autoCook.f_QualityField.value() = "Normal"; + + rsp->fields.qteQuality_ = qualities.find(autoCook.f_QualityField.value())->second; rsp->fields.cookCount_ = autoCook.f_CountField; if (autoCook.f_FastProficiency) rsp->fields.cookCount_ = 1; @@ -137,7 +163,7 @@ namespace cheat::feature return CALL_ORIGIN(PlayerModule_OnPlayerCookRsp, __this, rsp, method); } - + static void CookingQtePageContext_UpdateProficiency(app::CookingQtePageContext* __this, MethodInfo* method) { AutoCook& autoCook = AutoCook::GetInstance(); if (autoCook.f_Enabled || autoCook.f_FastProficiency) diff --git a/cheat-library/src/user/cheat/world/AutoCook.h b/cheat-library/src/user/cheat/world/AutoCook.h index 1efaa6c..de11afb 100644 --- a/cheat-library/src/user/cheat/world/AutoCook.h +++ b/cheat-library/src/user/cheat/world/AutoCook.h @@ -12,10 +12,10 @@ namespace cheat::feature config::Field> f_FastProficiency; config::Field f_CountField; - config::Field f_QualityField; + config::Field f_QualityField; int CookFoodMaxNum; // Maximum quantity at a time - int CookCount; + int CookCount; static AutoCook& GetInstance(); @@ -26,7 +26,7 @@ namespace cheat::feature void DrawStatus() override; private: - + AutoCook(); }; }