From 25706073ffa7e6dcf97a33ef6cf758f24d300cc6 Mon Sep 17 00:00:00 2001 From: MelonSpeedruns Date: Wed, 1 Jun 2022 17:58:20 -0400 Subject: [PATCH] rando generation working, but lots of incorrect check strings --- soh/include/randomizer/item_location.cpp | 3 +-- soh/include/randomizer/menu.cpp | 10 ++++--- soh/include/randomizer/menu.hpp | 2 +- soh/include/randomizer/rando_main.cpp | 8 +++++- soh/include/randomizer/spoiler_log.cpp | 27 ++++++++++++------- soh/include/randomizer/spoiler_log.hpp | 2 +- soh/soh/Enhancements/randomizer.cpp | 4 ++- soh/soh/OTRGlobals.cpp | 4 +++ soh/soh/OTRGlobals.h | 3 ++- .../ovl_file_choose/z_file_choose.c | 4 +++ 10 files changed, 47 insertions(+), 20 deletions(-) diff --git a/soh/include/randomizer/item_location.cpp b/soh/include/randomizer/item_location.cpp index 08c068fe1..39491c12f 100644 --- a/soh/include/randomizer/item_location.cpp +++ b/soh/include/randomizer/item_location.cpp @@ -9,7 +9,6 @@ #include //Location definitions -static std::array locationTable; void LocationTable_Init() { locationTable[NONE] = ItemLocation::Base (0xFF, 0xFF, "Invalid Location", NONE, NONE, {}, SpoilerCollectionCheck::None()); @@ -911,8 +910,8 @@ void LocationTable_Init() { locationTable[DMC_UPPER_GROTTO_GOSSIP_STONE] = ItemLocation::HintStone(0x00, 0x3A, "DMC Upper Grotto Gossip Stone", {}); locationTable[GANONDORF_HINT] = ItemLocation::OtherHint(0x00, 0x00, "Ganondorf Hint", {}); - } + std::vector KF_ShopLocations = { KF_SHOP_ITEM_1, KF_SHOP_ITEM_2, diff --git a/soh/include/randomizer/menu.cpp b/soh/include/randomizer/menu.cpp index 7ffa2f45b..219cfd6fd 100644 --- a/soh/include/randomizer/menu.cpp +++ b/soh/include/randomizer/menu.cpp @@ -515,14 +515,14 @@ void PrintOptionDescription() { printf("\x1b[22;0H%s", description.data()); } -void GenerateRandomizer() { +std::string GenerateRandomizer() { // if a blank seed was entered, make a random one if (Settings::seed.empty()) { Settings::seed = std::to_string(rand()); } else if (Settings::seed.rfind("seed_testing_count", 0) == 0) { const int count = std::stoi(Settings::seed.substr(18), nullptr); Playthrough::Playthrough_Repeat(count); - return; + return ""; } int ret = Playthrough::Playthrough_Init(std::hash{}(Settings::seed)); @@ -531,10 +531,10 @@ void GenerateRandomizer() { printf("\n\nFailed to generate after 5 tries.\nPress B to go back to the menu.\nA different seed might be " "successful."); SPDLOG_INFO("\nRANDOMIZATION FAILED COMPLETELY. PLZ FIX\n"); - return; + return ""; } else { printf("\n\nError %d with fill.\nPress Select to exit or B to go back to the menu.\n", ret); - return; + return ""; } } @@ -545,6 +545,8 @@ void GenerateRandomizer() { } Settings::Keysanity.RestoreDelayedOption(); } + + return "./randomizer/" + Settings::seed + ".json"; } std::string GetInput(const char* hintText) { diff --git a/soh/include/randomizer/menu.hpp b/soh/include/randomizer/menu.hpp index bb5fd9d9f..dab6de2a1 100644 --- a/soh/include/randomizer/menu.hpp +++ b/soh/include/randomizer/menu.hpp @@ -43,7 +43,7 @@ void PrintResetToDefaultsMenu(); void PrintGenerateMenu(); void ClearDescription(); void PrintOptionDescription(); -void GenerateRandomizer(); +std::string GenerateRandomizer(); std::string GetInput(const char* hintText); extern void MenuInit(); diff --git a/soh/include/randomizer/rando_main.cpp b/soh/include/randomizer/rando_main.cpp index 2d7eb9ae5..7afc1deac 100644 --- a/soh/include/randomizer/rando_main.cpp +++ b/soh/include/randomizer/rando_main.cpp @@ -4,6 +4,9 @@ #include "item_location.hpp" #include "location_access.hpp" #include "rando_main.hpp" +#include +#include +#include #define TICKS_PER_SEC 268123480.0 @@ -11,5 +14,8 @@ void RandoMain::GenerateRando() { HintTable_Init(); ItemTable_Init(); LocationTable_Init(); - GenerateRandomizer(); + + std::string fileName = GenerateRandomizer(); + CVar_SetString("gSpoilerLog", fileName.c_str()); + Game::SaveSettings(); } \ No newline at end of file diff --git a/soh/include/randomizer/spoiler_log.cpp b/soh/include/randomizer/spoiler_log.cpp index 7b89971a7..e00a561ed 100644 --- a/soh/include/randomizer/spoiler_log.cpp +++ b/soh/include/randomizer/spoiler_log.cpp @@ -19,6 +19,11 @@ #include #include #include +#include +#include +#include + +using json = nlohmann::json; namespace { std::string placementtxt; @@ -572,19 +577,22 @@ static void WriteHints(tinyxml2::XMLDocument& spoilerLog) { spoilerLog.RootElement()->InsertEndChild(parentNode); } -static void WriteAllLocations(tinyxml2::XMLDocument& spoilerLog) { - auto parentNode = spoilerLog.NewElement("all-locations"); +static void WriteAllLocations() { + json jsonLocations; for (const uint32_t key : allLocations) { - if (!Location(key)->IsHidden()) { - WriteLocation(parentNode, key, true); - } + ItemLocation* location = Location(key); + jsonLocations["locations"][location->GetName()] = location->GetPlacedItemName().english; } - spoilerLog.RootElement()->InsertEndChild(parentNode); + std::string jsonString = jsonLocations.dump(); + + std::ofstream jsonFile("./randomizer/" + Settings::seed + ".json"); + jsonFile << std::setw(4) << jsonString << std::endl; + jsonFile.close(); } -bool SpoilerLog_Write() { +const char* SpoilerLog_Write() { auto spoilerLog = tinyxml2::XMLDocument(false); spoilerLog.InsertEndChild(spoilerLog.NewDeclaration()); @@ -613,10 +621,11 @@ bool SpoilerLog_Write() { WriteHints(spoilerLog); WriteShuffledEntrances(spoilerLog); - WriteAllLocations(spoilerLog); + WriteAllLocations(); auto e = spoilerLog.SaveFile(GetSpoilerLogPath()); - return e == tinyxml2::XML_SUCCESS; + + return Settings::seed.c_str(); } void PlacementLog_Msg(std::string_view msg) { diff --git a/soh/include/randomizer/spoiler_log.hpp b/soh/include/randomizer/spoiler_log.hpp index f355f94ba..bf463c45f 100644 --- a/soh/include/randomizer/spoiler_log.hpp +++ b/soh/include/randomizer/spoiler_log.hpp @@ -107,5 +107,5 @@ const RandomizerHash& GetRandomizerHash(); void WriteIngameSpoilerLog(); -bool SpoilerLog_Write(); +const char* SpoilerLog_Write(); const SpoilerData& GetSpoilerData(); \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer.cpp b/soh/soh/Enhancements/randomizer.cpp index 982a6b642..e96a0db8c 100644 --- a/soh/soh/Enhancements/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer.cpp @@ -88,6 +88,7 @@ Randomizer::~Randomizer() { std::unordered_map SpoilerfileCheckNameToEnum = { {"Links Pocket", RC_LINKS_POCKET}, + {"Link's Pocket", RC_LINKS_POCKET }, {"Queen Gohma", RC_QUEEN_GOHMA}, {"King Dodongo", RC_KING_DODONGO}, {"Barinade", RC_BARINADE}, @@ -1169,6 +1170,7 @@ std::string sanitize(std::string stringValue) { void Randomizer::ParseItemLocationsFile(const char* spoilerFileName) { // todo pull this in from cvar or something + std::ifstream spoilerFileStream(sanitize(spoilerFileName)); if (!spoilerFileStream) return; @@ -1211,7 +1213,7 @@ void Randomizer::ParseItemLocationsFile(const char* spoilerFileName) { success = true; } catch (const std::exception& e) { Audio_PlaySoundGeneral(NA_SE_SY_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - return; + return; } if (success) { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 1344bf18e..8df4165ee 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1029,6 +1029,10 @@ extern "C" s16 GetItemModelFromId(s16 itemId) { return OTRGlobals::Instance->gRandomizer->GetItemModelFromId(itemId); } +extern "C" void LoadItemLocations(const char* spoilerFileName) { + OTRGlobals::Instance->gRandomizer->LoadItemLocations(spoilerFileName); +} + extern "C" void ParseItemLocationsFile(const char* spoilerFileName) { OTRGlobals::Instance->gRandomizer->ParseItemLocationsFile(spoilerFileName); } diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index c93e1c5fe..24363029a 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -76,7 +76,8 @@ int AudioPlayer_GetDesiredBuffered(void); void AudioPlayer_Play(const uint8_t* buf, uint32_t len); void AudioMgr_CreateNextAudioBuffer(s16* samples, u32 num_samples); int Controller_ShouldRumble(size_t i); -void ParseItemLocationsFile(const char* spoilerfilename); +void LoadItemLocations(const char* spoilerFileName); +void ParseItemLocationsFile(const char* spoilerFileName); s16 GetItemModelFromId(s16 itemId); s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); 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 977c5ca92..f0f31b609 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 @@ -1511,6 +1511,7 @@ void FileChoose_FadeOut(GameState* thisx) { * Note: On Debug ROM, File 1 will go to Map Select. * Update function for `SM_LOAD_GAME` */ + void FileChoose_LoadGame(GameState* thisx) { FileChooseContext* this = (FileChooseContext*)thisx; u16 swordEquipMask; @@ -1533,6 +1534,9 @@ void FileChoose_LoadGame(GameState* thisx) { this->state.running = false; } + const char* fileLoc = CVar_GetString("gSpoilerLog", ""); + LoadItemLocations(fileLoc); + gSaveContext.respawn[0].entranceIndex = -1; gSaveContext.respawnFlag = 0; gSaveContext.seqId = (u8)NA_BGM_DISABLED;