mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-08 18:13:02 -04:00
sky character blob and stage edit registration
This commit is contained in:
@@ -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<s8>(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<s8>(key & 0xFF);
|
||||
for (const auto& bytes : additions) {
|
||||
StageActorHandle handle{};
|
||||
svc_mng.stage->add_actor(mod_ctx, stage, room, layer, bytes.data(), bytes.size(), &handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,4 +27,5 @@ extern ServiceManager svc_mng;
|
||||
ModResult initialize(const ServiceManager& services);
|
||||
|
||||
void setupRandomizerFile();
|
||||
void registerStageEdits();
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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);
|
||||
@@ -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++;
|
||||
|
||||
Reference in New Issue
Block a user