diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1f79f5f6..66a7b4af 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -122,6 +122,11 @@ toBeSorted/unk_flag_stuff.cpp: toBeSorted/bitwise_flag_helper.cpp: .text start:0x800BF200 end:0x800BF264 +toBeSorted/dungeonflag_manager.cpp: + .text start:0x800BF8D0 end:0x800BFBA0 + .sbss start:0x80575404 end:0x80575408 + .bss start:0x805A9C58 end:0x805A9C68 + toBeSorted/skipflag_manager.cpp: .text start:0x800BFBA0 end:0x800BFE00 .sbss start:0x80575408 end:0x8057540C diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index dfd2e61c..4fe4a163 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -2228,7 +2228,7 @@ fn_80054CF0 = .text:0x80054CF0; // type:function size:0x88 fn_80054D80 = .text:0x80054D80; // type:function size:0x98 fn_80054E20 = .text:0x80054E20; // type:function size:0x88 fn_80054EB0 = .text:0x80054EB0; // type:function size:0x4 -fn_80054EC0 = .text:0x80054EC0; // type:function size:0xC +__nw__FUl = .text:0x80054EC0; // type:function size:0xC fn_80054ED0 = .text:0x80054ED0; // type:function size:0xC __dl__FPv = .text:0x80054EE0; // type:function size:0x8 fn_80054EF0 = .text:0x80054EF0; // type:function size:0x8 @@ -4171,15 +4171,15 @@ fn_800BF820 = .text:0x800BF820; // type:function size:0x3C fn_800BF860 = .text:0x800BF860; // type:function size:0x10 fn_800BF870 = .text:0x800BF870; // type:function size:0x4 fn_800BF880 = .text:0x800BF880; // type:function size:0x4C -fn_800BF8D0 = .text:0x800BF8D0; // type:function size:0x54 -fn_800BF930 = .text:0x800BF930; // type:function size:0xC -fn_800BF940 = .text:0x800BF940; // type:function size:0x3C -fn_800BF980 = .text:0x800BF980; // type:function size:0x54 -fn_800BF9E0 = .text:0x800BF9E0; // type:function size:0xC -fn_800BF9F0 = .text:0x800BF9F0; // type:function size:0x6C -fn_800BFA60 = .text:0x800BFA60; // type:function size:0x60 -fn_800BFAC0 = .text:0x800BFAC0; // type:function size:0x50 -fn_800BFB10 = .text:0x800BFB10; // type:function size:0x8C +copyFromSave__18DungeonflagManagerFUs = .text:0x800BF8D0; // type:function size:0x54 +setCommitFlag__18DungeonflagManagerFUs = .text:0x800BF930; // type:function size:0xC +__ct__18DungeonflagManagerFv = .text:0x800BF940; // type:function size:0x3C +setupFlagStuff__18DungeonflagManagerFv = .text:0x800BF980; // type:function size:0x54 +copyFromSave__18DungeonflagManagerFs = .text:0x800BF9E0; // type:function size:0xC +setToValue__18DungeonflagManagerFUsUi = .text:0x800BF9F0; // type:function size:0x6C +setFlag__18DungeonflagManagerFUs = .text:0x800BFA60; // type:function size:0x60 +getDungeonFlag__18DungeonflagManagerFUs = .text:0x800BFAC0; // type:function size:0x50 +doCommit__18DungeonflagManagerFv = .text:0x800BFB10; // type:function size:0x8C copyFromSave__15SkipflagManagerFv = .text:0x800BFBA0; // type:function size:0x44 setCommitFlag__15SkipflagManagerFUs = .text:0x800BFBF0; // type:function size:0xC __ct__15SkipflagManagerFv = .text:0x800BFC00; // type:function size:0x2C @@ -39848,7 +39848,7 @@ sTBoxFlags__15TBoxFlagManager = .sbss:0x805753F4; // type:object size:0x4 sInstance__18EnemyDefeatManager = .sbss:0x805753F8; // type:object size:0x4 data:4byte lbl_805753FC = .sbss:0x805753FC; // type:object size:0x4 data:4byte lbl_80575400 = .sbss:0x80575400; // type:object size:0x4 data:4byte -lbl_80575404 = .sbss:0x80575404; // type:object size:0x4 data:4byte +sInstance__18DungeonflagManager = .sbss:0x80575404; // type:object size:0x4 data:4byte sInstance__15SkipflagManager = .sbss:0x80575408; // type:object size:0x4 data:4byte lbl_80575410 = .sbss:0x80575410; // type:object size:0x8 data:4byte lbl_80575418 = .sbss:0x80575418; // type:object size:0x8 @@ -48236,7 +48236,7 @@ lbl_805A78E0 = .bss:0x805A78E0; // type:object size:0x1F8 sEnemyDefeatFlags__18EnemyDefeatManager = .bss:0x805A7AD8; // type:object size:0x2000 lbl_805A9AD8 = .bss:0x805A9AD8; // type:object size:0x100 lbl_805A9BD8 = .bss:0x805A9BD8; // type:object size:0x80 -lbl_805A9C58 = .bss:0x805A9C58; // type:object size:0x10 +sDungeonFlags__18DungeonflagManager = .bss:0x805A9C58; // type:object size:0x10 sSkipFlags__15SkipflagManager = .bss:0x805A9C68; // type:object size:0x20 lbl_805A9C88 = .bss:0x805A9C88; // type:object size:0x10 data:4byte lbl_805A9C98 = .bss:0x805A9C98; // type:object size:0x208 diff --git a/configure.py b/configure.py index 87235f4a..0b18234e 100644 --- a/configure.py +++ b/configure.py @@ -274,6 +274,7 @@ config.libs = [ Object(Matching, "toBeSorted/sceneflag_manager.cpp"), Object(NonMatching, "toBeSorted/flag_space.cpp"), Object(NonMatching, "toBeSorted/misc_flag_managers.cpp"), + Object(NonMatching, "toBeSorted/dungeonflag_manager.cpp"), Object(Matching, "toBeSorted/skipflag_manager.cpp"), Object(Matching, "c/c_list.cpp"), Object(Matching, "c/c_tree.cpp"), diff --git a/src/toBeSorted/dungeonflag_manager.cpp b/src/toBeSorted/dungeonflag_manager.cpp new file mode 100644 index 00000000..527a54c5 --- /dev/null +++ b/src/toBeSorted/dungeonflag_manager.cpp @@ -0,0 +1,98 @@ +#include "toBeSorted/bitwise_flag_helper.h" +#include "toBeSorted/file_manager.h" +#include "toBeSorted/flag_space.h" +#include "toBeSorted/unk_flag_stuff.h" +#include + +// TODO move +extern "C" UnkFlagDefinition lbl_80511AF0[]; + +class DungeonflagManager { +public: + bool mShouldCommit; + u16 mFlagIndex; + UnkFlagStuff *mFlagStuff; + FlagSpace mFlagSpace; + + static u16 sDungeonFlags[8]; + static DungeonflagManager *sInstance; + + void copyFromSave(s16 flag); + void copyFromSave(u16 flagIndex); + void setCommitFlag(u16 flag); + DungeonflagManager(); + void setupFlagStuff(); + void setToValue(u16 flag, u32 value); + void setFlag(u16 flag); + u32 getDungeonFlag(u16 flag); + bool doCommit(); +}; + +/** 80575404 */ +DungeonflagManager *DungeonflagManager::sInstance = nullptr; +/** 805a9c58 */ +u16 DungeonflagManager::sDungeonFlags[8] = {}; + +/** 800bf9e0 */ +void DungeonflagManager::copyFromSave(u16 flagIndex) { + u16 *ptr = FileManager::sInstance->getDungeonFlagsConst(); + mFlagSpace.copyFromSaveFile(ptr + (flagIndex & 0x1fff) * 8, 0, 0x8); +} + +/** 800bf930 */ +void DungeonflagManager::setCommitFlag(u16 flag) { + mShouldCommit = true; +} + +/** 0x800bf940 */ +DungeonflagManager::DungeonflagManager() + : mShouldCommit(false), mFlagIndex(-1), mFlagStuff(nullptr), + mFlagSpace(sDungeonFlags, ARRAY_LENGTH(sDungeonFlags)) {} + +/** 800bf980 */ +void DungeonflagManager::setupFlagStuff() { + mFlagStuff = new UnkFlagStuff(0x11, lbl_80511AF0); + mShouldCommit = false; +} + +/** 800bf9e0 */ +void DungeonflagManager::copyFromSave(s16 flag) { + mFlagIndex = flag; + copyFromSave((u16)flag); +} + +/** 800bf9f0 */ +void DungeonflagManager::setToValue(u16 flag, u32 value) { + u16 *data = mFlagSpace.getFlagPtrChecked(); + mFlagStuff->setCounterOrFlag(flag, data, 8, value); + setCommitFlag(flag); +} + +/** 800bfa60 */ +void DungeonflagManager::setFlag(u16 flag) { + u16 *data = mFlagSpace.getFlagPtrChecked(); + mFlagStuff->setCounterOrFlag(flag, data, 8, 1); + setCommitFlag(flag); +} + +/** 800fbac0 */ +u32 DungeonflagManager::getDungeonFlag(u16 flag) { + u16 *data = mFlagSpace.getFlagPtrUnchecked(); + return mFlagStuff->getCounterOrFlag(flag, data, 8); +} + +/** 800fbb10 */ +bool DungeonflagManager::doCommit() { + FileManager *instance; + u16 idx = mFlagIndex; + if (idx == 0xFFFF) { + return false; + } else if (mShouldCommit) { + instance = FileManager::sInstance; + u16 *ptr = mFlagSpace.getFlagPtrUnchecked(); + instance->setDungeonFlags(ptr, (idx & 0x1fff) * 8, 0x08); + mShouldCommit = false; + return true; + } + return false; +}