Improve AutoCook feature UX

This commit is contained in:
TerraFaster 2022-08-07 17:04:50 +03:00
parent 15f493c74d
commit 3db45e07f3
2 changed files with 39 additions and 13 deletions

View File

@ -14,7 +14,9 @@ namespace cheat::feature
app::Component_1* Profirency = nullptr; 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<std::string, int> 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 PlayerModule_OnPlayerCookRsp(app::MoleMole_PlayerModule* __this, app::PlayerCookRsp* rsp, MethodInfo* method);
static void CookingQtePageContext_UpdateProficiency(app::CookingQtePageContext* __this, 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_Enabled, "Standart Cooking", "AutoCook", false),
NF(f_FastProficiency, "Fast Proficiency", "AutoCook", false), NF(f_FastProficiency, "Fast Proficiency", "AutoCook", false),
NF(f_CountField, "Count Item", "AutoCook", 1), 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_RequestPlayerCook, PlayerModule_RequestPlayerCook);
HookManager::install(app::MoleMole_PlayerModule_OnPlayerCookRsp, PlayerModule_OnPlayerCookRsp); HookManager::install(app::MoleMole_PlayerModule_OnPlayerCookRsp, PlayerModule_OnPlayerCookRsp);
@ -38,12 +40,24 @@ namespace cheat::feature
void AutoCook::DrawMain() void AutoCook::DrawMain()
{ {
ConfigWidget(f_Enabled, "Fast Cooking if the recipe has fast cooking open. \n" \ 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(f_FastProficiency, "Quickly prepare an unstudied recipe to the maximum possible.");
ConfigWidget("Count Item", f_CountField, 1, 1, 100, ConfigWidget("Count Item", f_CountField, 1, 1, 100,
"How much to cook at a time.\n" \ "How much to cook at a time.\n" \
"(For standard mode only.)"); "(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 bool AutoCook::NeedStatusDraw() const
@ -53,7 +67,10 @@ namespace cheat::feature
void AutoCook::DrawStatus() 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() AutoCook& AutoCook::GetInstance()
@ -82,9 +99,14 @@ namespace cheat::feature
if (autoCook.f_Enabled || autoCook.f_FastProficiency) if (autoCook.f_Enabled || autoCook.f_FastProficiency)
{ {
autoCook.CookFoodMaxNum = app::MoleMole_Config_CookRecipeExcelConfig_CheckCookFoodMaxNum(recipeId, nullptr); 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; count = autoCook.f_CountField;
if (autoCook.f_CountField > autoCook.CookFoodMaxNum) if (autoCook.f_CountField > autoCook.CookFoodMaxNum)
count = 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 RectTransform = app::GameObject_GetComponentByName(GameObject::Profirency, string_to_il2cppi("RectTransform"), nullptr);
auto TransformChild = app::Transform_GetChild(reinterpret_cast<app::Transform*>(RectTransform), 0, nullptr); auto TransformChild = app::Transform_GetChild(reinterpret_cast<app::Transform*>(RectTransform), 0, nullptr);
auto TextComponent = app::Component_1_GetComponent_1(reinterpret_cast<app::Component_1*>(TransformChild), string_to_il2cppi("Text"), nullptr); auto TextComponent = app::Component_1_GetComponent_1(reinterpret_cast<app::Component_1*>(TransformChild), string_to_il2cppi("Text"), nullptr);
if (TextComponent != nullptr) { if (TextComponent != nullptr) {
auto Text_str = app::Text_get_text(reinterpret_cast<app::Text*>(TextComponent), nullptr); auto Text_str = app::Text_get_text(reinterpret_cast<app::Text*>(TextComponent), nullptr);
auto ProficiencyStr = il2cppi_to_string(Text_str).erase(0, il2cppi_to_string(Text_str).find_first_of(" .")); 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(); AutoCook& autoCook = AutoCook::GetInstance();
if (autoCook.f_Enabled || autoCook.f_FastProficiency) 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; rsp->fields.cookCount_ = autoCook.f_CountField;
if (autoCook.f_FastProficiency) if (autoCook.f_FastProficiency)
rsp->fields.cookCount_ = 1; rsp->fields.cookCount_ = 1;
@ -137,7 +163,7 @@ namespace cheat::feature
return CALL_ORIGIN(PlayerModule_OnPlayerCookRsp, __this, rsp, method); return CALL_ORIGIN(PlayerModule_OnPlayerCookRsp, __this, rsp, method);
} }
static void CookingQtePageContext_UpdateProficiency(app::CookingQtePageContext* __this, MethodInfo* method) { static void CookingQtePageContext_UpdateProficiency(app::CookingQtePageContext* __this, MethodInfo* method) {
AutoCook& autoCook = AutoCook::GetInstance(); AutoCook& autoCook = AutoCook::GetInstance();
if (autoCook.f_Enabled || autoCook.f_FastProficiency) if (autoCook.f_Enabled || autoCook.f_FastProficiency)

View File

@ -12,10 +12,10 @@ namespace cheat::feature
config::Field<config::Toggle<Hotkey>> f_FastProficiency; config::Field<config::Toggle<Hotkey>> f_FastProficiency;
config::Field<int> f_CountField; config::Field<int> f_CountField;
config::Field<int> f_QualityField; config::Field<std::string> f_QualityField;
int CookFoodMaxNum; // Maximum quantity at a time int CookFoodMaxNum; // Maximum quantity at a time
int CookCount; int CookCount;
static AutoCook& GetInstance(); static AutoCook& GetInstance();
@ -26,7 +26,7 @@ namespace cheat::feature
void DrawStatus() override; void DrawStatus() override;
private: private:
AutoCook(); AutoCook();
}; };
} }