From 1f28fd1ca538c1867f9adfd437591c6d312017c6 Mon Sep 17 00:00:00 2001 From: TakaRikka Date: Sat, 8 Aug 2026 05:38:42 -0700 Subject: [PATCH] sky character blob and stage edit registration --- mods/randomizer/src/session.cpp | 47 +++++++++++++++++++++++++ mods/randomizer/src/session.hpp | 1 + mods/randomizer/src/tools.cpp | 37 +++++++++++++++---- mods/randomizer/src/tools.h | 4 +++ mods/randomizer/src/ui/rando_config.cpp | 1 + 5 files changed, 84 insertions(+), 6 deletions(-) diff --git a/mods/randomizer/src/session.cpp b/mods/randomizer/src/session.cpp index 54bd41c92c..749fd32fad 100644 --- a/mods/randomizer/src/session.cpp +++ b/mods/randomizer/src/session.cpp @@ -6,6 +6,7 @@ #include "flags.h" #include "item_ids.h" #include "tools.h" +#include "stages.h" #include "d/d_com_inf_game.h" #include "d/d_item.h" @@ -97,4 +98,50 @@ void setupRandomizerFile() { randoData.mCreatingSave = false; } +void registerStageEdits() { + auto& ctx = randomizer_GetContext(); + auto stage_of = [](u32 key) -> const char* { + const u32 stage_id = key >> 16; + if (stage_id >= sizeof(allStages) / sizeof(allStages[0])) { + return nullptr; + } + return allStages[stage_id]; + }; + + for (const auto& [key, patches] : ctx.mObjectPatches) { + const char* stage = stage_of(key); + if (stage == nullptr) { + continue; + } + + const u8 room = (key >> 8) & 0xFF; + const s8 layer = static_cast(key & 0xFF); + for (const auto& [crc, bytes] : patches) { + StageActorHandle handle{}; + + ModResult res; + if (bytes.size() == RandomizerContext::OBJ_DELETE_SIZE) { + res = svc_mng.stage->delete_actor(mod_ctx, stage, room, layer, crc, &handle); + } else { + res = svc_mng.stage->patch_actor( + mod_ctx, stage, room, layer, crc, bytes.data(), bytes.size(), &handle); + } + } + } + + for (const auto& [key, additions] : ctx.mObjectAdditions) { + const char* stage = stage_of(key); + if (stage == nullptr) { + continue; + } + + const u8 room = (key >> 8) & 0xFF; + const s8 layer = static_cast(key & 0xFF); + for (const auto& bytes : additions) { + StageActorHandle handle{}; + svc_mng.stage->add_actor(mod_ctx, stage, room, layer, bytes.data(), bytes.size(), &handle); + } + } +} + } \ No newline at end of file diff --git a/mods/randomizer/src/session.hpp b/mods/randomizer/src/session.hpp index 266000d726..e033ebb961 100644 --- a/mods/randomizer/src/session.hpp +++ b/mods/randomizer/src/session.hpp @@ -27,4 +27,5 @@ extern ServiceManager svc_mng; ModResult initialize(const ServiceManager& services); void setupRandomizerFile(); +void registerStageEdits(); } \ No newline at end of file diff --git a/mods/randomizer/src/tools.cpp b/mods/randomizer/src/tools.cpp index ec6effdd06..3f8d575673 100644 --- a/mods/randomizer/src/tools.cpp +++ b/mods/randomizer/src/tools.cpp @@ -767,12 +767,37 @@ void setAllLetterRead() { dComIfGs_getSaveData()->getPlayer().getLetterInfo().mLetterReadFlags[0] |= 0xFFFF; } -u8 getAncientDocumentNum() { - // TODO - return 0; +constexpr const char* skyCharacterBlobName = "sky_characters"; +u8 g_skyCharacters = 0; + +void saveAncientDocumentNum() { + auto* ctx = randomizer::session::svc_mng.mod_ctx; + randomizer::session::svc_mng.save->set_blob(ctx, skyCharacterBlobName, &g_skyCharacters, sizeof(g_skyCharacters)); } -u8 getAreaKeyNum(int) { - // TODO - return 0; +void loadAncientDocumentNum() { + g_skyCharacters = 0; + size_t size = sizeof(g_skyCharacters); + auto* ctx = randomizer::session::svc_mng.mod_ctx; + randomizer::session::svc_mng.save->get_blob(ctx, skyCharacterBlobName, &g_skyCharacters, &size); +} + +u8 getAncientDocumentNum() { + return g_skyCharacters; +} + +void setAncientDocumentNum(u8 num) { + g_skyCharacters = num; + saveAncientDocumentNum(); +} + +u8 getAreaKeyNum(int i_stageNo) { + stage_stag_info_class* stagInfo = dComIfGp_getStageStagInfo(); + if (stagInfo != nullptr) { + if (i_stageNo == dStage_stagInfo_GetSaveTbl(stagInfo)) { + return dComIfGs_getKeyNum(); + } + } + + return dComIfGs_getSaveData()->getSave(i_stageNo).getBit().getKeyNum(); } \ No newline at end of file diff --git a/mods/randomizer/src/tools.h b/mods/randomizer/src/tools.h index 3119c3fcac..475fc01793 100644 --- a/mods/randomizer/src/tools.h +++ b/mods/randomizer/src/tools.h @@ -53,9 +53,13 @@ void onRegionFlag(int i_stageNo, int i_no); void setRegionBit(u8 i_region); void setAllLetterGet(); void setAllLetterRead(); +void setAncientDocumentNum(u8 num); u8 getAncientDocumentNum(); u8 getAreaKeyNum(int); +void saveAncientDocumentNum(); +void loadAncientDocumentNum(); + bool tracker_isEventBit(u16 flag); bool tracker_isStageSwitch(int stage, int flag); bool tracker_isStageItem(int stage, int flag); \ No newline at end of file diff --git a/mods/randomizer/src/ui/rando_config.cpp b/mods/randomizer/src/ui/rando_config.cpp index 76bb24b034..3ac9218e16 100644 --- a/mods/randomizer/src/ui/rando_config.cpp +++ b/mods/randomizer/src/ui/rando_config.cpp @@ -528,6 +528,7 @@ ModResult buildPlayTab(ModContext* ctx, UiWindowHandle, UiElementHandle leftPane std::string hash = entry.path().filename().string(); randomizer_GetContext() = RandomizerContext(); randomizer_GetContext().LoadFromHash(hash); + session::registerStageEdits(); break; } idx++;