From ed8966054c07ba5a9becfa14e67894fb715e7d7e Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 09:15:05 -0500 Subject: [PATCH 1/5] Persist item tracker notes --- libultraship/libultraship/Hooks.h | 1 + .../randomizer/randomizer_item_tracker.cpp | 11 ++++++++++- soh/soh/SaveManager.cpp | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/Hooks.h b/libultraship/libultraship/Hooks.h index 5f29a831c..f9cd8b4ba 100644 --- a/libultraship/libultraship/Hooks.h +++ b/libultraship/libultraship/Hooks.h @@ -31,4 +31,5 @@ namespace Ship { DEFINE_HOOK(LoadTexture, void(const char* path, uint8_t** texture)); DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(ExitGame, void()); + DEFINE_HOOK(LoadFile, void(uint32_t fileNum)); } diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 8cede9a66..f39e1d944 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -485,6 +485,8 @@ void DrawSong(ItemTrackerItem item) { SetLastItemHoverText(SohUtils::GetQuestItemName(item.id)); } +static ImVector itemTrackerNotes; + void DrawNotes(bool resizeable = false) { ImGui::BeginGroup(); int iconSize = CVar_GetS32("gItemTrackerIconSize", 36); @@ -510,12 +512,15 @@ void DrawNotes(bool resizeable = false) { (void*)itemTrackerNotes); } }; - static ImVector itemTrackerNotes; if (itemTrackerNotes.empty()) { itemTrackerNotes.push_back(0); } ImVec2 size = resizeable ? ImVec2(-FLT_MIN, ImGui::GetContentRegionAvail().y) : ImVec2(((iconSize + iconSpacing) * 6) - 8, 200); ItemTrackerNotes::TrackerNotesInputTextMultiline("##ItemTrackerNotes", &itemTrackerNotes, size, ImGuiInputTextFlags_AllowTabInput); + if (ImGui::IsItemDeactivatedAfterEdit() && IsValidSaveFile()) { + CVar_SetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str()); + SohImGui::needs_save = true; + } ImGui::EndGroup(); } @@ -925,4 +930,8 @@ void InitItemTracker() { Ship::RegisterHook([](OSContPad* cont_pad) { buttonsPressed = cont_pad; }); + Ship::RegisterHook([](uint32_t fileNum) { + const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), ""); + strcpy(itemTrackerNotes.Data, initialTrackerNotes); + }); } diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 8d8e7cd77..7050813b6 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -5,6 +5,7 @@ #include "functions.h" #include "macros.h" #include "Cvar.h" +#include "Hooks.h" #define NOGDI // avoid various windows defines that conflict with things in z64.h #include "spdlog/spdlog.h" @@ -1570,6 +1571,7 @@ extern "C" void Save_SaveGlobal(void) { extern "C" void Save_LoadFile(void) { SaveManager::Instance->LoadFile(gSaveContext.fileNum); + Ship::ExecuteHooks(gSaveContext.fileNum); } extern "C" void Save_AddLoadFunction(char* name, int version, SaveManager::LoadFunc func) { From 90bf5988eec51e459d32fd55a2f72fe82a24ba8b Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 09:30:53 -0500 Subject: [PATCH 2/5] Adjust Hooks include --- soh/soh/SaveManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 16aa0fff0..8de0b0f18 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -4,7 +4,7 @@ #include "z64.h" #include "functions.h" #include "macros.h" -#include "Hooks.h" +#include #include #define NOGDI // avoid various windows defines that conflict with things in z64.h From b92b1eaee6f046f5f06d07020e344eb1f26ec703 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 09:33:54 -0500 Subject: [PATCH 3/5] Use SohImGui::RequestCvarSaveOnNextTick --- soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 2bcb73e87..36b5593ea 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -518,7 +518,7 @@ void DrawNotes(bool resizeable = false) { ItemTrackerNotes::TrackerNotesInputTextMultiline("##ItemTrackerNotes", &itemTrackerNotes, size, ImGuiInputTextFlags_AllowTabInput); if (ImGui::IsItemDeactivatedAfterEdit() && IsValidSaveFile()) { CVar_SetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), std::string(std::begin(itemTrackerNotes), std::end(itemTrackerNotes)).c_str()); - SohImGui::needs_save = true; + SohImGui::RequestCvarSaveOnNextTick(); } ImGui::EndGroup(); } From 72660e2cfd8abd858417efa36ad7116b3a9b93ae Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 15:28:59 -0500 Subject: [PATCH 4/5] Fix for beans obtainability --- soh/soh/Enhancements/randomizer/randomizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 083e231d9..0187d5486 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -1360,7 +1360,7 @@ ItemObtainability Randomizer::GetItemObtainabilityFromRandomizerGet(RandomizerGe return INV_CONTENT(ITEM_LENS) == ITEM_NONE ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_MAGIC_BEAN: case RG_MAGIC_BEAN_PACK: - return BEANS_BOUGHT < 10 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; + return AMMO(ITEM_BEAN) < 10 ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_MEGATON_HAMMER: return INV_CONTENT(ITEM_HAMMER) == ITEM_NONE ? CAN_OBTAIN : CANT_OBTAIN_ALREADY_HAVE; case RG_FIRE_ARROWS: From 77a5d03019c59196587f656b7ee069ae0a033566 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Sat, 3 Sep 2022 15:46:33 -0500 Subject: [PATCH 5/5] Hook into file delete and clear notes --- libultraship/libultraship/Hooks.h | 1 + soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp | 6 +++++- soh/soh/SaveManager.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libultraship/libultraship/Hooks.h b/libultraship/libultraship/Hooks.h index f9cd8b4ba..fd6c049bc 100644 --- a/libultraship/libultraship/Hooks.h +++ b/libultraship/libultraship/Hooks.h @@ -32,4 +32,5 @@ namespace Ship { DEFINE_HOOK(GfxInit, void()); DEFINE_HOOK(ExitGame, void()); DEFINE_HOOK(LoadFile, void(uint32_t fileNum)); + DEFINE_HOOK(DeleteFile, void(uint32_t fileNum)); } diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 36b5593ea..5b52047ab 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -930,7 +930,11 @@ void InitItemTracker() { buttonsPressed = cont_pad; }); Ship::RegisterHook([](uint32_t fileNum) { - const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(gSaveContext.fileNum)).c_str(), ""); + const char* initialTrackerNotes = CVar_GetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), ""); strcpy(itemTrackerNotes.Data, initialTrackerNotes); }); + Ship::RegisterHook([](uint32_t fileNum) { + CVar_SetString(("gItemTrackerNotes" + std::to_string(fileNum)).c_str(), ""); + SohImGui::RequestCvarSaveOnNextTick(); + }); } diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index 8de0b0f18..3305f1d70 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -1592,6 +1592,7 @@ extern "C" void Save_CopyFile(int from, int to) { extern "C" void Save_DeleteFile(int fileNum) { SaveManager::Instance->DeleteZeldaFile(fileNum); + Ship::ExecuteHooks(fileNum); } extern "C" bool Save_Exist(int fileNum) {