-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc221b4
commit 1870130
Showing
11 changed files
with
404 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <common.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct MsbBlockHeader { | ||
/* 0x00 */ char name[4]; | ||
/* 0x04 */ int sectionLength; | ||
/* 0x08 */ unsigned short field_0x08; | ||
/* 0x0A */ unsigned char field_0x0A[0x10 - 0x0A]; | ||
/* 0x10 */ int numEntries; | ||
}; | ||
|
||
struct MsbBlock { | ||
/* 0x00 */ int *ptr; | ||
/* 0x04 */ char name[4]; | ||
/* 0x08 */ int sectionLength; | ||
/* 0x0C */ u16 field_0x0C; | ||
}; | ||
|
||
#pragma push | ||
#pragma pack(2) | ||
|
||
struct MsbHeader { | ||
/* 0x00 */ unsigned char field_0x00[0x0C - 0x00]; | ||
/* 0x0C */ unsigned char version; | ||
/* 0x0E */ unsigned short sectionCount; | ||
/* 0x10 */ unsigned char field_0x10[0x12 - 0x10]; | ||
/* 0x12 */ int fileLength; | ||
}; | ||
|
||
#pragma pop | ||
|
||
struct MsbInfo { | ||
/* 0x00 */ struct MsbHeader *header; | ||
/* 0x04 */ int fileLength; | ||
/* 0x08 */ unsigned char version; | ||
/* 0x0A */ unsigned short sectionCount; | ||
/* 0x0C */ struct MsbBlock *sectionInfos; | ||
}; | ||
|
||
void LMSi_AnalyzeMessageHeader(struct MsbInfo *info); | ||
void LMSi_AnalyzeMessageBlocks(struct MsbInfo *info); | ||
void LMSi_AnalyzeMessageBinary(struct MsbInfo *info, const char *type); | ||
int LMSi_SearchBlockByName(struct MsbInfo *info, const char *name); | ||
int LMSi_GetHashTableIndexFromLabel(const char *label, int tableSize); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <common.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct MsbfInfo; | ||
|
||
struct MsbFlowInfo { | ||
/* 0x00 */ char type; | ||
/* 0x01 */ char subType; | ||
/* 0x04 */ short params1n2; | ||
/* 0x08 */ short next; | ||
/* 0x0A */ short param3; | ||
/* 0x0C */ short param4; | ||
/* 0x0E */ short param5; | ||
}; | ||
|
||
// Func names are made up | ||
|
||
struct MsbfInfo *LMS_InitFlow(void *data); | ||
void LMS_CloseFlow(struct MsbfInfo *info); | ||
int LMS_GetFlow(struct MsbfInfo *info, int index); | ||
int LMS_GetEntrypoint(struct MsbfInfo *info, const char *label); | ||
struct MsbFlowInfo *LMS_GetFlowElement(struct MsbfInfo *info, int index); | ||
const unsigned short *LMS_GetBranchPoints(struct MsbfInfo *info, int index); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <common.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void LMS_SetMemFuncs(void *(*alloc)(size_t size), void (*free)(void *ptr)); | ||
|
||
// internal | ||
void *LMSi_Malloc(size_t size); | ||
void LMSi_Free(void *ptr); | ||
int LMSi_MemCmp(const char *p1, const char *p2, int n); | ||
void LMSi_MemCopy(char *p1, const char *p2, int n); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <common.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
struct MsbtInfo; | ||
|
||
struct MsbtAttrInfo { | ||
char c_0x00; | ||
char c_0x01; | ||
}; | ||
|
||
struct MsbtInfo *LMS_InitMessage(void *data); | ||
void LMS_CloseMessage(struct MsbtInfo *info); | ||
int LMS_GetTextIndexByLabel(struct MsbtInfo *info, const char *label); | ||
const char *LMS_GetText(struct MsbtInfo *info, int index); | ||
const char *LMS_GetTextByLabel(struct MsbtInfo *info, const char *label); | ||
const char *LMS_GetLabelByTextIndex(struct MsbtInfo *info, int index); | ||
struct MsbtAttrInfo *LMS_GetAttribute(struct MsbtInfo *info, int index); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <libms/commonlib.h> | ||
#include <libms/libms.h> | ||
|
||
void LMSi_AnalyzeMessageHeader(struct MsbInfo *info) { | ||
info->version = info->header->version; | ||
info->sectionCount = info->header->sectionCount; | ||
if (info->sectionCount == 0) { | ||
info->sectionInfos = NULL; | ||
} else { | ||
info->sectionInfos = (struct MsbBlock *)LMSi_Malloc(sizeof(struct MsbBlock) * info->sectionCount); | ||
} | ||
info->fileLength = info->header->fileLength; | ||
} | ||
|
||
inline static struct MsbBlockHeader* GetBlockHeader(struct MsbInfo *info, int offset) { | ||
return (struct MsbBlockHeader*)(offset + (unsigned int)info->header); | ||
} | ||
|
||
void LMSi_AnalyzeMessageBlocks(struct MsbInfo *info) { | ||
// TODO regswap | ||
int i; | ||
int offset = ROUND_UP(sizeof(struct MsbHeader), 0x20); // file header | ||
for (i = 0; i < info->sectionCount; i++) { | ||
struct MsbBlock *section = &info->sectionInfos[i]; | ||
section->ptr = &GetBlockHeader(info, offset)->numEntries; | ||
section->name[0] = GetBlockHeader(info, offset)->name[0]; | ||
section->name[1] = GetBlockHeader(info, offset)->name[1]; | ||
section->name[2] = GetBlockHeader(info, offset)->name[2]; | ||
section->name[3] = GetBlockHeader(info, offset)->name[3]; | ||
section->sectionLength = GetBlockHeader(info, offset)->sectionLength; | ||
section->field_0x0C = GetBlockHeader(info, offset)->field_0x08; | ||
offset = offset + 0x10; // section header | ||
offset = offset + section->sectionLength; // section | ||
offset = ROUND_UP(offset, 0x10); // align | ||
} | ||
} | ||
|
||
void LMSi_AnalyzeMessageBinary(struct MsbInfo *info, const char *type) { | ||
LMSi_AnalyzeMessageHeader(info); | ||
LMSi_AnalyzeMessageBlocks(info); | ||
} | ||
|
||
int LMSi_SearchBlockByName(struct MsbInfo *info, const char *name) { | ||
for (unsigned short i = 0; i < info->sectionCount; i++) { | ||
if (LMSi_MemCmp(info->sectionInfos[i].name, name, 4)) { | ||
return i; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
int LMSi_GetHashTableIndexFromLabel(const char *label, int tableSize) { | ||
unsigned int hash = 0; | ||
int c; | ||
while (1) { | ||
c = *label; | ||
if (c == '\0') { | ||
break; | ||
} | ||
hash = hash * 0x492 + c; | ||
label++; | ||
} | ||
return hash % tableSize; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <libms/commonlib.h> | ||
#include <libms/flowfile.h> | ||
#include <libms/libms.h> | ||
|
||
|
||
struct MsbfInfo { | ||
/* 0x00 */ struct MsbInfo base; | ||
/* 0x10 */ int flw3Index; | ||
/* 0x14 */ int fen1Index; | ||
/* 0x18 */ int ref1Index; | ||
}; | ||
|
||
struct MsbfInfo *LMS_InitFlow(void *data) { | ||
struct MsbfInfo *info = (struct MsbfInfo *)LMSi_Malloc(sizeof(struct MsbfInfo)); | ||
info->base.header = (struct MsbHeader *)data; | ||
LMSi_AnalyzeMessageBinary(&info->base, "MsgStdBn"); | ||
info->flw3Index = LMSi_SearchBlockByName(&info->base, "LBL1"); | ||
info->fen1Index = LMSi_SearchBlockByName(&info->base, "TXT2"); | ||
info->ref1Index = LMSi_SearchBlockByName(&info->base, "ATR1"); | ||
return info; | ||
} | ||
|
||
void LMS_CloseFlow(struct MsbfInfo *info) { | ||
if (info->base.sectionInfos != nullptr) { | ||
LMSi_Free(info->base.sectionInfos); | ||
} | ||
LMSi_Free(info); | ||
} | ||
|
||
int LMS_GetFlow(struct MsbfInfo *info, int index) { | ||
// TODO | ||
} | ||
|
||
int LMS_GetEntrypoint(struct MsbfInfo *info, const char *label) { | ||
// TODO | ||
} | ||
|
||
struct MsbFlowInfo *LMS_GetFlowElement(struct MsbfInfo *info, int index) { | ||
// TODO | ||
} | ||
|
||
const unsigned short *LMS_GetBranchPoints(struct MsbfInfo *info, int index) { | ||
// TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <libms/libms.h> | ||
|
||
static void *(*MSB_ALLOC_FUNC)(size_t size); | ||
static void (*MSB_FREE_FUNC)(void *arg); | ||
|
||
void LMS_SetMemFuncs(void *(*alloc)(size_t size), void (*free)(void *ptr)) { | ||
MSB_ALLOC_FUNC = alloc; | ||
MSB_FREE_FUNC = free; | ||
} | ||
|
||
// internal | ||
void *LMSi_Malloc(size_t size) { | ||
return (MSB_ALLOC_FUNC)(size); | ||
} | ||
|
||
void LMSi_Free(void *ptr) { | ||
return (MSB_FREE_FUNC)(ptr); | ||
} | ||
|
||
int LMSi_MemCmp(const char *p1, const char *p2, int n) { | ||
for (int i = 0; i < n; i++) { | ||
if (p1[i] != p2[i]) { | ||
return 0; | ||
} | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
void LMSi_MemCopy(char *p1, const char *p2, int n) { | ||
// TODO register usage too optimal | ||
for (int i = 0; i < n; i++) { | ||
*p1 = *p2; | ||
p1++; | ||
p2++; | ||
} | ||
} |
Oops, something went wrong.