diff --git a/config/eur/arm9/symbols.txt b/config/eur/arm9/symbols.txt index ac98082e..273b726b 100644 --- a/config/eur/arm9/symbols.txt +++ b/config/eur/arm9/symbols.txt @@ -1821,10 +1821,10 @@ _ZN18UnkStruct_027E0C6813func_020370e8Eissi kind:function(arm,size=0x70) addr:0x _ZN18UnkStruct_027E0C6813func_02037158EP21UnkSubClass1_02256FF8 kind:function(arm,size=0x20) addr:0x2037158 _ZN18UnkStruct_027E0C6813func_02037178EP21UnkSubClass1_02256FF8 kind:function(arm,size=0x38) addr:0x2037178 _ZN18UnkStruct_027E0C68D2Ev kind:function(arm,size=0x4) addr:0x20371b0 -_Z13func_020371b4P11BMGFileInfo kind:function(thumb,size=0x14) addr:0x20371b4 -_Z13func_020371c8P11BMGFileInfoPjs kind:function(thumb,size=0x90) addr:0x20371c8 -_Z13func_02037258P11BMGFileInfoi kind:function(arm,size=0x34) addr:0x2037258 -_Z13func_0203728cP11BMGFileInfoi kind:function(arm,size=0x64) addr:0x203728c +_ZN11BMGFileInfo13func_020371b4Ev kind:function(thumb,size=0x14) addr:0x20371b4 +_ZN11BMGFileInfo13func_020371c8EPjs kind:function(thumb,size=0x90) addr:0x20371c8 +_ZN11BMGFileInfo13func_02037258Et kind:function(arm,size=0x34) addr:0x2037258 +_ZN11BMGFileInfo13func_0203728cEi kind:function(arm,size=0x64) addr:0x203728c _ZN9BMGGroups13func_020372f0E12BMGFileIndexs kind:function(thumb,size=0xc4) addr:0x20372f0 _ZN9BMGGroups13func_020373b4Es kind:function(thumb,size=0x38) addr:0x20373b4 _ZN9BMGGroups13func_020373ecEi kind:function(arm,size=0x60) addr:0x20373ec diff --git a/config/usa/arm9/symbols.txt b/config/usa/arm9/symbols.txt index 125495a0..de3d48e3 100644 --- a/config/usa/arm9/symbols.txt +++ b/config/usa/arm9/symbols.txt @@ -1821,10 +1821,10 @@ _ZN18UnkStruct_027E0C6813func_020370e8Eissi kind:function(arm,size=0x70) addr:0x _ZN18UnkStruct_027E0C6813func_02037158EP21UnkSubClass1_02256FF8 kind:function(arm,size=0x20) addr:0x2037114 _ZN18UnkStruct_027E0C6813func_02037178EP21UnkSubClass1_02256FF8 kind:function(arm,size=0x38) addr:0x2037134 _ZN18UnkStruct_027E0C68D2Ev kind:function(arm,size=0x4) addr:0x203716c -_Z13func_020371b4P11BMGFileInfo kind:function(thumb,size=0x14) addr:0x2037170 -_Z13func_020371c8P11BMGFileInfoPjs kind:function(thumb,size=0x90) addr:0x2037184 -_Z13func_02037258P11BMGFileInfoi kind:function(arm,size=0x34) addr:0x2037214 -_Z13func_0203728cP11BMGFileInfoi kind:function(arm,size=0x64) addr:0x2037248 +_ZN11BMGFileInfo13func_020371b4Ev kind:function(thumb,size=0x14) addr:0x2037170 +_ZN11BMGFileInfo13func_020371c8EPjs kind:function(thumb,size=0x90) addr:0x2037184 +_ZN11BMGFileInfo13func_02037258Et kind:function(arm,size=0x34) addr:0x2037214 +_ZN11BMGFileInfo13func_0203728cEi kind:function(arm,size=0x64) addr:0x2037248 _ZN9BMGGroups13func_020372f0E12BMGFileIndexs kind:function(thumb,size=0xc4) addr:0x20372ac _ZN9BMGGroups13func_020373b4Es kind:function(thumb,size=0x38) addr:0x2037370 _ZN9BMGGroups13func_020373ecEi kind:function(arm,size=0x60) addr:0x20373a8 diff --git a/include/Message/BMG.hpp b/include/Message/BMG.hpp index 53a418ea..1fd03974 100644 --- a/include/Message/BMG.hpp +++ b/include/Message/BMG.hpp @@ -6,26 +6,26 @@ #define BMG_MAGIC "MESGbmg1" #define BMG_TAG(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a)) -#define BMG_GET_INF1(pGroups, flags) (func_02037258(&(pGroups)->entries[(flags) >> 0x10], (flags) & 0xFFFF)) +#define BMG_GET_INF1(pGroups, flags) ((pGroups)->entries[(flags) >> 0x10].func_02037258((flags) & 0xFFFF)) #define BMG_GET_MSG_OFFSET(pGroups, flags) (BMG_GET_INF1((pGroups), (flags))->offset) #define BMG_GET_MSG_ADDR(pGroups, flags) ((u32)(pGroups)->entries[(flags) >> 0x10].pDAT1 + (BMG_GET_MSG_OFFSET((pGroups), (flags)) & ~1)) -typedef enum BMGTag { +enum BMGTag { /* "INF1" */ BMG_TAG_INF1 = BMG_TAG('I', 'N', 'F', '1'), /* "FLW1" */ BMG_TAG_FLW1 = BMG_TAG('F', 'L', 'W', '1'), /* "FLI1" */ BMG_TAG_FLI1 = BMG_TAG('F', 'L', 'I', '1'), /* "DAT1" */ BMG_TAG_DAT1 = BMG_TAG('D', 'A', 'T', '1'), /* "MID1" */ BMG_TAG_MID1 = BMG_TAG('M', 'I', 'D', '1'), /* "MID1" */ BMG_TAG_STR1 = BMG_TAG('S', 'T', 'R', '1'), -} BMGTag; +}; -typedef enum BMGEncoding { +enum BMGEncoding { /* 1 */ BMG_ENCODING_CP1252 = 1, /* 2 */ BMG_ENCODING_UTF16_BE, /* 3 */ BMG_ENCODING_SHIFT_JIS, /* 4 */ BMG_ENCODING_UTF8, /* 5 */ BMG_ENCODING_MAX -} BMGEncoding; +}; typedef enum BMGFileIndex { /* 0 */ BMG_FILE_INDEX_SYSTEM, @@ -65,120 +65,140 @@ typedef enum BMGFileIndex { /* 34 */ BMG_FILE_INDEX_MAX } BMGFileIndex; -typedef struct SectionBase { - /* 0x00 */ u32 tag; // "INF1", "DAT1", ... - /* 0x04 */ u32 size; // the size of the section -} SectionBase; // size = 0x8 +struct SectionBase { + /* 00 */ u32 tag; // "INF1", "DAT1", ... + /* 04 */ u32 size; // the size of the section + /* 08 */ +}; -typedef struct BMGHeader { - /* 0x00 */ char magic[8]; // always "MESGbmg1" - /* 0x08 */ u32 fileSize; // the size of the BMG file - /* 0x0C */ u32 numSections; // the number of sections (INF1, DAT1, ...) - /* 0x10 */ u8 encoding; // see `BMGEncoding` - /* 0x11 */ u8 unk_11[0xF]; // alignment padding? -} BMGHeader; // size = 0x20 +struct BMGHeader { + /* 00 */ char magic[8]; // always "MESGbmg1" + /* 08 */ u32 fileSize; // the size of the BMG file + /* 0c */ u32 numSections; // the number of sections (INF1, DAT1, ...) + /* 10 */ u8 encoding; // see `BMGEncoding` + /* 11 */ u8 unk_11[0xF]; // alignment padding? + /* 20 */ +}; -typedef struct EntryINF1 { - /* 0x00 */ u32 offset; // relative to the end of the DAT1 header - /* 0x04 */ u8 mUnk_04; // flags/attributes? (+0x04 to +0x06) - /* 0x05 */ u8 mUnk_05; - /* 0x06 */ u8 mUnk_06; - /* 0x07 */ u8 mUnk_07; -} EntryINF1; // size = 0x8 +struct EntryINF1 { + /* 00 */ u32 offset; // relative to the end of the DAT1 header + /* 04 */ u8 mUnk_04; // flags/attributes? (+0x04 to +0x06) + /* 05 */ u8 mUnk_05; + /* 06 */ u8 mUnk_06; + /* 07 */ u8 mUnk_07; + /* 08 */ +}; -typedef struct SectionINF1 { - /* 0x00 */ SectionBase base; - /* 0x08 */ u16 numEntries; - /* 0x0A */ u16 entrySize; - /* 0x0C */ u16 groupId; - /* 0x0E */ u8 colorId; - /* 0x0F */ u8 unk_0F[0x1]; // alignment padding? - /* 0x10 */ EntryINF1* entries; -} SectionINF1; +struct SectionINF1 { + /* 00 */ SectionBase base; + /* 08 */ u16 numEntries; + /* 0a */ u16 entrySize; + /* 0c */ u16 groupId; + /* 0e */ u8 colorId; + /* 0f */ u8 mUnk_0F[0x1]; // alignment padding? + /* 10 */ EntryINF1* entries; + /* 14 */ +}; -typedef enum InstrType { +enum InstrType { /* 1 */ FLW1_TYPE_SHOW_MSG = 1, /* 2 */ FLW1_TYPE_BRANCH = 2, /* 3 */ FLW1_TYPE_EVENT = 3, -} InstrType; + /* 4 */ +}; -typedef struct InstrShowMsg { - /* 0x01 */ u8 bmgFileIndex; // index into sBMGFiles - /* 0x02 */ u16 msgIndex; // index of INF1 entry - /* 0x04 */ s16 nextIndex; // index of FLW1 entry, 0xFFFF stops the conversation - /* 0x06 */ s16 nextBMGFileIndex; // index into sBMGFiles -} InstrShowMsg; // size = 0x8 +struct InstrShowMsg { + /* 01 */ u8 bmgFileIndex; // index into sBMGFiles + /* 02 */ u16 msgIndex; // index of INF1 entry + /* 04 */ s16 nextIndex; // index of FLW1 entry, 0xFFFF stops the conversation + /* 06 */ s16 nextBMGFileIndex; // index into sBMGFiles + /* 08 */ +}; -typedef struct InstrBranch { - /* 0x01 */ u8 mUnk_01; - /* 0x02 */ u16 funcIndex; // index of the query function to run - /* 0x04 */ u16 funcArg; // the argument to use in the function - /* 0x06 */ u16 flwEntry; // the index of the second section table to be used next in the conversation. -} InstrBranch; // size = 0x8 +struct InstrBranch { + /* 01 */ u8 mUnk_01; + /* 02 */ u16 funcIndex; // index of the query function to run + /* 04 */ u16 funcArg; // the argument to use in the function + /* 06 */ u16 flwEntry; // the index of the second section table to be used next in the conversation. + /* 08 */ +}; -typedef struct InstrEvent { - /* 0x01 */ u8 funcIndex; // index of the query function to run - /* 0x02 */ u16 flwEntry; // the index of the second section table to be used next in the conversation. - /* 0x04 */ u32 funcArg; // the argument to use in the function -} InstrEvent; // size = 0x8 +struct InstrEvent { + /* 01 */ u8 funcIndex; // index of the query function to run + /* 02 */ u16 flwEntry; // the index of the second section table to be used next in the conversation. + /* 04 */ u32 funcArg; // the argument to use in the function + /* 08 */ +}; -typedef struct FLW1Instr { - /* 0x00 */ u8 type; // see InstrType - /* 0x01 */ union { +struct FLW1Instr { + /* 00 */ u8 type; // see InstrType + /* 01 */ union { InstrShowMsg showMsg; InstrBranch branch; InstrEvent event; }; -} FLW1Instr; // size = 0x8 + /* 09 */ +}; -typedef struct SectionFLW1 { - /* 0x00 */ SectionBase base; - /* 0x04 */ u16 numInstructions; - /* 0x08 */ u16 numLabels; - /* 0x0C */ u32 mUnk_0c; // always zero? - /* 0x10 */ FLW1Instr* instructions; - /* 0x14 */ s16* flwEntries; - /* 0x18 */ s8* bmgFileIndices; -} SectionFLW1; +struct SectionFLW1 { + /* 00 */ SectionBase base; + /* 04 */ u16 numInstructions; + /* 08 */ u16 numLabels; + /* 0c */ u32 mUnk_0c; // always zero? + /* 10 */ FLW1Instr* instructions; + /* 14 */ s16* flwEntries; + /* 18 */ s8* bmgFileIndices; + /* 1c */ +}; -typedef struct EntryFLI1 { - /* 0x00 */ u32 msgFlowID; - /* 0x04 */ u32 msgFlowNodeIndex; -} EntryFLI1; // size = 0x8 +struct EntryFLI1 { + /* 00 */ u32 msgFlowID; + /* 04 */ u32 msgFlowNodeIndex; + /* 08 */ +}; -typedef struct SectionFLI1 { - /* 0x00 */ SectionBase base; - /* 0x04 */ u16 numEntries; - /* 0x08 */ u16 entrySize; - /* 0x0C */ u32 mUnk_0c; // always zero? - /* 0x10 */ EntryFLI1* entries; -} SectionFLI1; +struct SectionFLI1 { + /* 00 */ SectionBase base; + /* 04 */ u16 numEntries; + /* 08 */ u16 entrySize; + /* 0c */ u32 mUnk_0c; // always zero? + /* 10 */ EntryFLI1* entries; + /* 14 */ +}; -typedef struct EntryDAT1 { - /* 0x00 */ char* text; -} EntryDAT1; +struct EntryDAT1 { + /* 00 */ char* text; + /* 04 */ +}; -typedef struct SectionDAT1 { - /* 0x00 */ SectionBase base; - /* 0x08 */ EntryDAT1* entries; -} SectionDAT1; +struct SectionDAT1 { + /* 00 */ SectionBase base; + /* 08 */ EntryDAT1* entries; + /* 0c */ +}; -typedef struct BMGFileInfo { - /* 0x00 */ BMGHeader* pHeader; // pointer to the file's header - /* 0x04 */ SectionINF1* pINF1; // pointer to the data informations (INF -> informations) - /* 0x08 */ SectionFLW1* pFLW1; // pointer to the message flow data (FLW -> flow) - /* 0x0C */ SectionFLI1* pFLI1; // pointer to the message flow index table (FLI -> flow index table) - /* 0x10 */ SectionDAT1* pDAT1; // pointer to the data (DAT -> data) - /* 0x14 */ BMGHeader* mUnk_14; // same as pHeader (?) - /* 0x18 */ s16 mUnk_18; // stores `func_020372f0`->param_3 value (currently undetermined purpose) - /* 0x1A */ s16 groupId; // stores the group id -} BMGFileInfo; // size = 0x1C +struct BMGFileInfo { + /* 00 */ BMGHeader* pHeader; // pointer to the file's header + /* 04 */ SectionINF1* pINF1; // pointer to the data informations (INF -> informations) + /* 08 */ SectionFLW1* pFLW1; // pointer to the message flow data (FLW -> flow) + /* 0c */ SectionFLI1* pFLI1; // pointer to the message flow index table (FLI -> flow index table) + /* 10 */ SectionDAT1* pDAT1; // pointer to the data (DAT -> data) + /* 14 */ BMGHeader* mUnk_14; // same as pHeader (?) + /* 18 */ s16 mUnk_18; // stores `func_020372f0`->param_3 value (currently undetermined purpose) + /* 1a */ s16 groupId; // stores the group id + /* 1c */ + + void func_020371b4(); + u16 func_020371c8(u32* pFile, s16 unk_18); + EntryINF1* func_02037258(u16 param_2); + u16 func_0203728c(unk32 param_2); +}; class BMGGroups : public SysObject { public: - /* 0x00 */ BMGFileInfo* entries; // accessed with `groupId` - /* 0x04 */ s32 numEntries; - /* 0x08 */ + /* 00 */ BMGFileInfo* entries; // accessed with `groupId` + /* 04 */ s32 numEntries; + /* 08 */ BMGGroups(); ~BMGGroups(); @@ -186,5 +206,3 @@ public: void func_020373b4(s16 unk_18); u32 func_020373ec(unk32 param_2); }; - -extern EntryINF1* func_02037258(BMGFileInfo* pFileInfo, unk32 param_2); diff --git a/src/Main/Message/BMG.cpp b/src/Main/Message/BMG.cpp index edf2f9f5..15fab32a 100644 --- a/src/Main/Message/BMG.cpp +++ b/src/Main/Message/BMG.cpp @@ -48,28 +48,30 @@ static char* sBMGFileNames[BMG_FILE_INDEX_MAX] = { "kaitei_F", // BMG_FILE_INDEX_KAITEI_F }; -THUMB void func_020371b4(BMGFileInfo* pFileInfo) { - pFileInfo->pHeader = NULL; - pFileInfo->pINF1 = NULL; - pFileInfo->pFLW1 = NULL; - pFileInfo->pFLI1 = NULL; - pFileInfo->pDAT1 = NULL; - pFileInfo->mUnk_14 = NULL; - pFileInfo->mUnk_18 = 0; +THUMB void BMGFileInfo::func_020371b4() { + this->pHeader = NULL; + this->pINF1 = NULL; + this->pFLW1 = NULL; + this->pFLI1 = NULL; + this->pDAT1 = NULL; + this->mUnk_14 = NULL; + this->mUnk_18 = 0; } -THUMB u16 func_020371c8(BMGFileInfo* pFileInfo, u32* pFile, s16 unk_18) { +// non-matching (equivalent) +THUMB u16 BMGFileInfo::func_020371c8(u32* pFile, s16 unk_18) { SectionBase* pSection; u16 groupId; u32 i; + BMGHeader* pHeader = (BMGHeader*)pFile; groupId = -1; - pFileInfo->mUnk_14 = (BMGHeader*)pFile; - pFileInfo->pHeader = (BMGHeader*)pFile; - pFileInfo->mUnk_18 = unk_18; + this->mUnk_14 = pHeader; + this->mUnk_18 = unk_18; + this->pHeader = pHeader; pSection = (SectionBase*)((u8*)pFile + sizeof(BMGHeader)); - for (i = 0; i < pFileInfo->pHeader->numSections; i++) { + for (i = 0; i < this->mUnk_14->numSections; i++) { switch (pSection->tag) { case BMG_TAG_MID1: // unused @@ -78,18 +80,18 @@ THUMB u16 func_020371c8(BMGFileInfo* pFileInfo, u32* pFile, s16 unk_18) { // unused break; case BMG_TAG_INF1: - pFileInfo->pINF1 = (SectionINF1*)pSection; - groupId = pFileInfo->pINF1->groupId; + this->pINF1 = (SectionINF1*)pSection; + groupId = this->pINF1->groupId; break; case BMG_TAG_DAT1: //! TODO: fake? - pFileInfo->pDAT1 = (SectionDAT1*)(pSection + 1); + this->pDAT1 = (SectionDAT1*)(pSection + 1); break; case BMG_TAG_FLW1: - pFileInfo->pFLW1 = (SectionFLW1*)pSection; + this->pFLW1 = (SectionFLW1*)pSection; break; case BMG_TAG_FLI1: - pFileInfo->pFLI1 = (SectionFLI1*)pSection; + this->pFLI1 = (SectionFLI1*)pSection; break; } @@ -99,35 +101,49 @@ THUMB u16 func_020371c8(BMGFileInfo* pFileInfo, u32* pFile, s16 unk_18) { return groupId; } -ARM EntryINF1* func_02037258(BMGFileInfo* pFileInfo, unk32 param_2) { - SectionINF1* pINF1 = pFileInfo->pINF1; +ARM EntryINF1* BMGFileInfo::func_02037258(u16 param_2) { + if (this->pINF1 != NULL) { + if (param_2 < this->pINF1->numEntries) { + return (EntryINF1*)((u32)&this->pINF1->entries + this->pINF1->entrySize * param_2); + } - if (pINF1 == NULL) { return NULL; } - if (param_2 < pINF1->numEntries) { - return &pINF1->entries[pINF1->entrySize * param_2]; - } - return NULL; } -ARM u16 func_0203728c(BMGFileInfo* pFileInfo, unk32 param_2) { +// non-matching +ARM u16 BMGFileInfo::func_0203728c(unk32 param_2) { SectionFLI1* pFLI1; - u16 i; + EntryFLI1* entry; + u32 i; + u16 j; - pFLI1 = pFileInfo->pFLI1; + pFLI1 = this->pFLI1; if (pFLI1 == NULL) { return -1; } - for (i = 0; i < pFLI1->numEntries; i++) { - if (param_2 == pFLI1->entries[i * 2].msgFlowID) { - return pFLI1->entries[i].msgFlowNodeIndex; + i = 0; + do { + entry = &pFLI1->entries[i]; + + if (param_2 > entry->msgFlowID) { + return entry->msgFlowNodeIndex; } - } + + // i++; + j = i + 1; + i = j & 0xFFFF; + } while (j < pFLI1->numEntries); + + // for (i = 0; (u16)i < pFLI1->numEntries; i++) { + // if (param_2 == pFLI1->entries[i].msgFlowID) { + // return pFLI1->entries[i].msgFlowNodeIndex; + // } + // } return -1; } @@ -161,10 +177,10 @@ THUMB void BMGGroups::func_020372f0(BMGFileIndex eIndex, s16 unk_18) { // initialize file info bmgFile.groupId = 0; - func_020371b4(&bmgFile); + bmgFile.func_020371b4(); // assign sections and set the file info in the groups entries - groupId = func_020371c8(&bmgFile, pFile, unk_18); + groupId = bmgFile.func_020371c8(pFile, unk_18); this->entries[groupId] = bmgFile; this->entries[groupId].groupId = groupId; } @@ -175,7 +191,7 @@ THUMB void BMGGroups::func_020373b4(s16 unk_18) { for (i = 0; i < this->numEntries; i++) { if (this->entries[i].mUnk_18 == unk_18) { func_0202d590(this->entries[i].mUnk_14); - func_020371b4(&this->entries[i]); + this->entries[i].func_020371b4(); } } } @@ -188,7 +204,7 @@ ARM u32 BMGGroups::func_020373ec(unk32 param_2) { dVar1 = -1; for (i = 0; i < this->numEntries; i++) { - uVar2 = func_0203728c(&this->entries[i], param_2); + uVar2 = this->entries[i].func_0203728c(param_2); if (uVar2 != dVar1) { return uVar2 | i << 0x10; diff --git a/src/Main/Message/MessageManager.cpp b/src/Main/Message/MessageManager.cpp index 923c21b3..7a1e0726 100644 --- a/src/Main/Message/MessageManager.cpp +++ b/src/Main/Message/MessageManager.cpp @@ -432,7 +432,7 @@ ARM UnkStruct_02038aa0* UnkStruct_027E0C68::func_02036da8(u32 param_2, s16* para int iStack_34; int iStack_30; - pEVar1 = func_02037258(&this->pGroups->entries[param_2 >> 0x10], param_2 & 0xFFFF); + pEVar1 = this->pGroups->entries[param_2 >> 0x10].func_02037258(param_2 & 0xFFFF); if (pEVar1 == NULL) { return NULL; @@ -458,7 +458,7 @@ ARM UnkStruct_02038aa0* UnkStruct_027E0C68::func_02036da8(u32 param_2, s16* para // pSVar4->vfunc_50(pEVar1, BMG_GET_MSG_ADDR(pBVar5, param_2), (s16*)&iStack_38, 1); BMGFileInfo* entry = &(pBVar5)->entries[(param_2) >> 0x10]; // pSVar4->vfunc_50(pEVar1, - // ((u32)entry->pDAT1 + (((func_02037258(entry, (((param_2))) & 0xFFFF))->offset) & ~1)), + // ((u32)entry->pDAT1 + (((entry.func_02037258((((param_2))) & 0xFFFF))->offset) & ~1)), // // BMG_GET_MSG_ADDR(pBVar5, param_2), // (s16*)&iStack_38, 1); @@ -501,7 +501,7 @@ ARM UnkStruct_020397f8* UnkStruct_027E0C68::func_02036f68(u32 param_2, u8* param int iVar4; UnkStruct_020397f8 *pSVar5; - pEVar1 = func_02037258(&this->pGroups->entries[param_2 >> 0x10], param_2 & 0xffff); + pEVar1 = this->pGroups->entries[param_2 >> 0x10].func_02037258(param_2 & 0xffff); if (pEVar1 == NULL) { return NULL;