diff --git a/soh/soh/Enhancements/randomizer/context.cpp b/soh/soh/Enhancements/randomizer/context.cpp index 945f62a57..b76dafb95 100644 --- a/soh/soh/Enhancements/randomizer/context.cpp +++ b/soh/soh/Enhancements/randomizer/context.cpp @@ -127,6 +127,20 @@ ItemLocation* Context::GetItemLocation(size_t locKey) { return &itemLocationTable[static_cast(locKey)]; } +ItemOverride& Context::GetItemOverride(RandomizerCheck locKey) { + if (!overrides.contains(locKey)) { + overrides.emplace(locKey, ItemOverride()); + } + return overrides.at(locKey); +} + +ItemOverride& Context::GetItemOverride(size_t locKey) { + if (!overrides.contains(static_cast(locKey))) { + overrides.emplace(static_cast(locKey), ItemOverride()); + } + return overrides.at(static_cast(locKey)); +} + void Context::PlaceItemInLocation(const RandomizerCheck locKey, const RandomizerGet item, const bool applyEffectImmediately, const bool setHidden) { const auto loc = GetItemLocation(locKey); diff --git a/soh/soh/Enhancements/randomizer/context.h b/soh/soh/Enhancements/randomizer/context.h index 4cbe26383..63e64cb7d 100644 --- a/soh/soh/Enhancements/randomizer/context.h +++ b/soh/soh/Enhancements/randomizer/context.h @@ -37,6 +37,8 @@ class Context { RandomizerArea hintedArea = RA_NONE); ItemLocation* GetItemLocation(RandomizerCheck locKey); ItemLocation* GetItemLocation(size_t locKey); + ItemOverride& GetItemOverride(RandomizerCheck locKey); + ItemOverride& GetItemOverride(size_t locKey); void PlaceItemInLocation(RandomizerCheck locKey, RandomizerGet item, bool applyEffectImmediately = false, bool setHidden = false); std::vector allLocations; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index bb1e6e871..449e50574 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -2355,6 +2355,9 @@ extern "C" GetItemEntry ItemTable_Retrieve(int16_t getItemID) { } extern "C" GetItemEntry ItemTable_RetrieveEntry(s16 tableID, s16 getItemID) { + if (tableID == MOD_RANDOMIZER) { + return Rando::StaticData::RetrieveItem(static_cast(getItemID)).GetGIEntry_Copy(); + } return ItemTableManager::Instance->RetrieveItemEntry(tableID, getItemID); } diff --git a/soh/soh/SaveManager.cpp b/soh/soh/SaveManager.cpp index e050c5fb8..d6f573e65 100644 --- a/soh/soh/SaveManager.cpp +++ b/soh/soh/SaveManager.cpp @@ -331,13 +331,12 @@ void SaveManager::LoadRandomizerVersion3() { RandomizerGet rg = RG_NONE; SaveManager::Instance->LoadData("fakeRgID", rg, RG_NONE); if (rg != RG_NONE) { - randoContext->overrides[static_cast(i)] = - Rando::ItemOverride(static_cast(i), rg); + randoContext->overrides.emplace(static_cast(i), Rando::ItemOverride(static_cast(i), rg)); SaveManager::Instance->LoadStruct("trickName", [&]() { SaveManager::Instance->LoadData( - "english", randoContext->overrides[static_cast(i)].GetTrickName().english); + "english", randoContext->GetItemOverride(i).GetTrickName().english); SaveManager::Instance->LoadData( - "french", randoContext->overrides[static_cast(i)].GetTrickName().french); + "french", randoContext->GetItemOverride(i).GetTrickName().french); }); } uint16_t price = 0; @@ -437,10 +436,10 @@ void SaveManager::SaveRandomizer(SaveContext* saveContext, int sectionID, bool f SaveManager::Instance->SaveStruct("", [&]() { SaveManager::Instance->SaveData("rgID", randoContext->GetItemLocation(i)->GetPlacedRandomizerGet()); if (randoContext->GetItemLocation(i)->GetPlacedRandomizerGet() == RG_ICE_TRAP) { - SaveManager::Instance->SaveData("fakeRgID", randoContext->overrides[static_cast(i)].LooksLike()); + SaveManager::Instance->SaveData("fakeRgID", randoContext->GetItemOverride(i).LooksLike()); SaveManager::Instance->SaveStruct("trickName", [&]() { - SaveManager::Instance->SaveData("english", randoContext->overrides[static_cast(i)].GetTrickName().GetEnglish()); - SaveManager::Instance->SaveData("french", randoContext->overrides[static_cast(i)].GetTrickName().GetFrench()); + SaveManager::Instance->SaveData("english", randoContext->GetItemOverride(i).GetTrickName().GetEnglish()); + SaveManager::Instance->SaveData("french", randoContext->GetItemOverride(i).GetTrickName().GetFrench()); // TODO: German (trick names don't have german translations yet) }); } diff --git a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index b6998d2b4..3a8da0b39 100644 --- a/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/soh/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1336,7 +1336,8 @@ void FileChoose_GenerateRandoSeed(GameState* thisx) { memcpy(Save_GetSaveMetaInfo(this->buttonIndex)->playerName, CVarGetInteger("gLinkDefaultName", 0) ? &linkName : &emptyName, 8); return; - } else { + } + if (!generating) { Randomizer_GenerateSeed(); } }