diff --git a/libultraship/libultraship/Hooks.h b/libultraship/libultraship/Hooks.h index 5f29a831c..fd6c049bc 100644 --- a/libultraship/libultraship/Hooks.h +++ b/libultraship/libultraship/Hooks.h @@ -31,4 +31,6 @@ 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)); + DEFINE_HOOK(DeleteFile, void(uint32_t fileNum)); } diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 7d0171a6a..dc3699611 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -1553,7 +1553,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: diff --git a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp index 3696fa67f..cf9ccfdbd 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_item_tracker.cpp @@ -484,6 +484,8 @@ void DrawSong(ItemTrackerItem item) { UIWidgets::SetLastItemHoverText(SohUtils::GetQuestItemName(item.id)); } +static ImVector itemTrackerNotes; + void DrawNotes(bool resizeable = false) { ImGui::BeginGroup(); int iconSize = CVar_GetS32("gItemTrackerIconSize", 36); @@ -509,12 +511,12 @@ 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::RequestCvarSaveOnNextTick(); + } ImGui::EndGroup(); } @@ -921,7 +923,19 @@ void InitItemTracker() { trackerBgB, trackerBgA }; // Float value, 1 = 255 in rgb value. + // Crashes when the itemTrackerNotes is empty, so add an empty character to it + if (itemTrackerNotes.empty()) { + itemTrackerNotes.push_back(0); + } Ship::RegisterHook([](OSContPad* cont_pad) { buttonsPressed = cont_pad; }); + Ship::RegisterHook([](uint32_t fileNum) { + 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 c048d1056..3305f1d70 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -4,6 +4,7 @@ #include "z64.h" #include "functions.h" #include "macros.h" +#include #include #define NOGDI // avoid various windows defines that conflict with things in z64.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) { @@ -1590,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) {