From 06a7bf4c8c36af699b9882623d2642baf0269bf3 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 19 Jun 2020 16:57:44 -0400 Subject: msgdata.c through DecryptMessageDirect --- arm9/src/msgdata.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 arm9/src/msgdata.c (limited to 'arm9/src/msgdata.c') diff --git a/arm9/src/msgdata.c b/arm9/src/msgdata.c new file mode 100644 index 00000000..b3a1c027 --- /dev/null +++ b/arm9/src/msgdata.c @@ -0,0 +1,59 @@ +#include "global.h" +#include "filesystem.h" +#include "msg_data.h" +#include "heap.h" + +#pragma thumb on + +void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id); +void FreeMsgDataRawData(void * data); +void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct UnkStruct_200A394_4 * param); +void DecryptMessageDirect(struct UnkStruct_200A394 * r3, u32 r5, u16 * r4); + +void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id) +{ + return AllocAndReadWholeNarcMemberByIdPair(narc_id, file_id, heap_id); +} + +void FreeMsgDataRawData(void * data) +{ + FreeToHeap(data); +} + +inline static void Decrypt1(struct UnkStruct_200A394_4 * arg0, u32 arg1, u32 seed) +{ + seed = seed * 765 * (arg1 + 1) & 0xffff; + seed |= seed << 16; + arg0->unk0 ^= seed; + arg0->unk4 ^= seed; +} + +inline static void Decrypt2(u16 * arg0, u32 count, u32 arg2) +{ + u16 seed = (arg2 + 1) * 596947; + + while (count-- > 0) + { + *arg0 ^= seed; + seed += 18749; + arg0++; + } +} + +void DecryptMessageDirect(struct UnkStruct_200A394 * r3, u32 r5, u16 * r4) +{ + struct UnkStruct_200A394_4 sp0; + + if (r5 < r3->unk0) + { + sp0 = r3->unk4[r5]; + Decrypt1(&sp0, r5, r3->unk2); + + CopyEncryptedMessage16(r4, (const u16 *)((u8 *)r3 + sp0.unk0), &sp0); + Decrypt2(r4, sp0.unk4, r5); + } + else + { + GF_ASSERT(0); + } +} -- cgit v1.2.3 From 669fafdcf6929def1bdc82805f57daa0b75c245e Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 19 Jun 2020 19:32:35 -0400 Subject: through FUN_0200A76C --- arm9/src/msgdata.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 185 insertions(+), 8 deletions(-) (limited to 'arm9/src/msgdata.c') diff --git a/arm9/src/msgdata.c b/arm9/src/msgdata.c index b3a1c027..007cb471 100644 --- a/arm9/src/msgdata.c +++ b/arm9/src/msgdata.c @@ -2,6 +2,8 @@ #include "filesystem.h" #include "msg_data.h" #include "heap.h" +#include "MI_memory.h" +#include "string16.h" #pragma thumb on @@ -9,6 +11,13 @@ void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id); void FreeMsgDataRawData(void * data); void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct UnkStruct_200A394_4 * param); void DecryptMessageDirect(struct UnkStruct_200A394 * r3, u32 r5, u16 * r4); +void DecryptMessageViaNewNarcHandle(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest); +void FUN_0200A4D4(struct UnkStruct_200A394 * r5, u32 r4, struct String * dest); +struct String * FUN_0200A584(struct UnkStruct_200A394 * r5, u32 r4, u32 heap_id); +void FUN_0200A648(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String * dest); +void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest); +struct String * FUN_0200A738(NarcId narc_id, u32 group, u32 num, u32 heap_id); +struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id); void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id) { @@ -30,30 +39,198 @@ inline static void Decrypt1(struct UnkStruct_200A394_4 * arg0, u32 arg1, u32 see inline static void Decrypt2(u16 * arg0, u32 count, u32 arg2) { - u16 seed = (arg2 + 1) * 596947; + u16 seed = (u16)((arg2 + 1) * 596947); while (count-- > 0) { *arg0 ^= seed; - seed += 18749; arg0++; + seed += 18749; } } -void DecryptMessageDirect(struct UnkStruct_200A394 * r3, u32 r5, u16 * r4) +void DecryptMessageDirect(struct UnkStruct_200A394 * table, u32 num, u16 * dest) { struct UnkStruct_200A394_4 sp0; - if (r5 < r3->unk0) + if (num < table->unk0) + { + sp0 = table->unk4[num]; + Decrypt1(&sp0, num, table->unk2); + + CopyEncryptedMessage16(dest, (const u16 *)((u8 *)table + sp0.unk0), &sp0); + Decrypt2(dest, sp0.unk4, num); + } + else + { + GF_ASSERT(0); + } +} + +void DecryptMessageViaNewNarcHandle(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest) +{ + NARC * narc = NARC_ctor(narc_id, heap_id); + u16 spC[2]; + struct UnkStruct_200A394_4 sp4; + if (narc != NULL) { - sp0 = r3->unk4[r5]; - Decrypt1(&sp0, r5, r3->unk2); + NARC_ReadFromMember(narc, group, 0, 4, spC); + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp4); + Decrypt1(&sp4, num, spC[1]); + NARC_ReadFromMember(narc, group, sp4.unk0, 2 * sp4.unk4, dest); + Decrypt2(dest, sp4.unk4, num); + NARC_dtor(narc); + } +} - CopyEncryptedMessage16(r4, (const u16 *)((u8 *)r3 + sp0.unk0), &sp0); - Decrypt2(r4, sp0.unk4, r5); +void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct UnkStruct_200A394_4 * param) +{ + MI_CpuCopy16(src, dest, 2 * param->unk4); +} + +void FUN_0200A4D4(struct UnkStruct_200A394 * table, u32 num, struct String * dest) +{ + struct UnkStruct_200A394_4 sp4; + u16 * buf; + if (num < table->unk0) + { + sp4 = table->unk4[num]; + Decrypt1(&sp4, num, table->unk2); + buf = AllocFromHeapAtEnd(0, 2 * sp4.unk4); + if (buf != NULL) + { + MI_CpuCopy16((char *)table + sp4.unk0, buf, 2 * sp4.unk4); + Decrypt2(buf, sp4.unk4, num); + FUN_02021E8C(dest, buf, sp4.unk4); + FreeToHeap(buf); + } + } + else + { + GF_ASSERT(0); + FUN_02021A4C(dest); + } +} + +struct String * FUN_0200A584(struct UnkStruct_200A394 * table, u32 num, u32 heap_id) +{ + struct UnkStruct_200A394_4 sp4; + u16 * buf; + struct String * dest; + if (num < table->unk0) + { + sp4 = table->unk4[num]; + Decrypt1(&sp4, num, table->unk2); + buf = AllocFromHeapAtEnd(heap_id, 2 * sp4.unk4); + if (buf != NULL) + { + MI_CpuCopy16((char *)table + sp4.unk0, buf, 2 * sp4.unk4); + Decrypt2(buf, sp4.unk4, num); + dest = FUN_020219F4(sp4.unk4, heap_id); + if (dest != NULL) + FUN_02021E8C(dest, buf, sp4.unk4); + FreeToHeap(buf); + return dest; + } + else + { + return NULL; + } + } + else + { + GF_ASSERT(0); + return FUN_020219F4(4, heap_id); + } +} + +void FUN_0200A648(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String * dest) +{ + NARC * narc = NARC_ctor(narc_id, heap_id); + if (narc != NULL) + { + FUN_0200A670(narc, group, num, heap_id, dest); + NARC_dtor(narc); + } +} + +void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest) +{ + u16 * buf; + u32 size; + u16 sp10[2]; + struct UnkStruct_200A394_4 sp8; + + NARC_ReadFromMember(narc, group, 0, 4, sp10); + if (num < sp10[0]) + { + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp8); + Decrypt1(&sp8, num, sp10[1]); + size = sp8.unk4 * 2; + buf = AllocFromHeapAtEnd(heap_id, size); + if (buf != NULL) + { + NARC_ReadFromMember(narc, group, sp8.unk0, size, buf); + Decrypt2(buf, sp8.unk4, num); + FUN_02021E8C(dest, buf, sp8.unk4); + FreeToHeap(buf); + return; + } + } + else + { + GF_ASSERT(0); + FUN_02021A4C(dest); + } +} + +struct String * FUN_0200A738(NarcId narc_id, u32 group, u32 num, u32 heap_id) +{ + NARC * narc = NARC_ctor(narc_id, heap_id); + struct String * string; + if (narc != NULL) + { + string = FUN_0200A76C(narc, group, num, heap_id); + NARC_dtor(narc); + } + else + { + string = FUN_020219F4(4, heap_id); + } + return string; +} + +struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id) +{ + struct String * dest; + u16 * buf; + u32 size; + u16 sp10[2]; + struct UnkStruct_200A394_4 sp8; + + NARC_ReadFromMember(narc, group, 0, 4, sp10); + if (num < sp10[0]) + { + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp8); + Decrypt1(&sp8, num, sp10[1]); + dest = FUN_020219F4(sp8.unk4, heap_id); + if (dest != NULL) + { + size = sp8.unk4 * 2; + buf = AllocFromHeapAtEnd(heap_id, size); + if (buf != NULL) + { + NARC_ReadFromMember(narc, group, sp8.unk0, size, buf); + Decrypt2(buf, sp8.unk4, num); + FUN_02021E8C(dest, buf, sp8.unk4); + FreeToHeap(buf); + } + } + return dest; } else { GF_ASSERT(0); + return FUN_020219F4(4, heap_id); } } -- cgit v1.2.3 From b138e415a2c6b4e42a08e776cd482d91d50bbc2a Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 19 Jun 2020 22:26:26 -0400 Subject: Finish msgdata.c --- arm9/src/msgdata.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) (limited to 'arm9/src/msgdata.c') diff --git a/arm9/src/msgdata.c b/arm9/src/msgdata.c index 007cb471..76d44338 100644 --- a/arm9/src/msgdata.c +++ b/arm9/src/msgdata.c @@ -4,6 +4,7 @@ #include "heap.h" #include "MI_memory.h" #include "string16.h" +#include "proto.h" #pragma thumb on @@ -18,6 +19,8 @@ void FUN_0200A648(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest); struct String * FUN_0200A738(NarcId narc_id, u32 group, u32 num, u32 heap_id); struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id); +u16 FUN_0200A848(struct UnkStruct_200A394 * tbl); +u16 FUN_0200A84C(NarcId narc_id, s32 file_id); void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id) { @@ -234,3 +237,166 @@ struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id) return FUN_020219F4(4, heap_id); } } + +u16 FUN_0200A848(struct UnkStruct_200A394 * tbl) +{ + return tbl->unk0; +} + +u16 FUN_0200A84C(NarcId narc_id, s32 file_id) +{ + u16 n[2]; + ReadFromNarcMemberByIdPair(&n, narc_id, file_id, 0, 4); + return n[0]; +} + +struct MsgData * NewMsgDataFromNarc(u32 type, NarcId narc_id, s32 file_id, u32 heap_id) +{ + struct MsgData * msgData = AllocFromHeapAtEnd(heap_id, sizeof(struct MsgData)); + if (msgData != NULL) + { + if (type == 0) + { + msgData->data.raw = LoadSingleElementFromNarc(narc_id, file_id, heap_id); + if (msgData->data.raw == NULL) + { + FreeToHeap(msgData); + return NULL; + } + } + else + { + msgData->data.narc = NARC_ctor(narc_id, heap_id); + } + msgData->type = (u16)type; + msgData->narc_id = (u16)narc_id; + msgData->file_id = (u16)file_id; + msgData->heap_id = (u16)heap_id; + } + return msgData; +} + +void DestroyMsgData(struct MsgData * msgData) +{ + if (msgData != NULL) + { + switch (msgData->type) + { + case 0: + FreeMsgDataRawData(msgData->data.raw); + break; + case 1: + NARC_dtor(msgData->data.narc); + break; + } + FreeToHeap(msgData); + } +} + +void FUN_0200A8E0(struct MsgData * msgData, u32 msg_no, struct String * dest) +{ + switch (msgData->type) + { + case 0: + FUN_0200A4D4(msgData->data.raw, msg_no, dest); + break; + case 1: + FUN_0200A670(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id, dest); + break; + } +} + +struct String * FUN_0200A914(struct MsgData * msgData, u32 msg_no) +{ + switch (msgData->type) + { + case 0: + return FUN_0200A584(msgData->data.raw, msg_no, msgData->heap_id); + case 1: + return FUN_0200A76C(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id); + default: + return NULL; + } +} + +u16 FUN_0200A940(struct MsgData * msgData) +{ + switch (msgData->type) + { + case 0: + return FUN_0200A848(msgData->data.raw); + case 1: + return FUN_0200A84C((NarcId)msgData->narc_id, msgData->file_id); + default: + return 0; + } +} + +void DecryptCopyString(struct MsgData * msgData, u32 msg_no, u16 * dest) +{ + switch (msgData->type) + { + case 0: + DecryptMessageDirect(msgData->data.raw, msg_no, dest); + break; + case 1: + DecryptMessageViaNewNarcHandle((NarcId)msgData->narc_id, msgData->file_id, msg_no, msgData->heap_id, dest); + break; + } +} + +void GetSpeciesName(u16 species, u32 heap_id, u16 * dest) +{ + struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 362, heap_id); + DecryptCopyString(msgData, species, dest); + DestroyMsgData(msgData); +} + +struct String * FUN_0200A9C4(u32 * a0, struct MsgData * msgData, u32 msgno, struct String * a3) +{ + struct String * ret = NULL; + struct String * r4 = FUN_020219F4(1024, 0); + struct String * r5; + if (r4 != NULL) + { + r5 = FUN_0200A914(msgData, msgno); + if (r5 != NULL) + { + FUN_0200B7B8(a0, r4, r5); + ret = FUN_02021ACC(r4, a3); + FUN_02021A20(r5); + } + FUN_02021A20(r4); + } + return ret; +} + +struct String * FUN_0200AA14(u32 msg_no, u32 heapno) +{ + struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 588, heapno); + struct String * ret; + if (msgData != NULL) + { + ret = FUN_020219F4(16, heapno); + if (ret != NULL) + { + FUN_0200A8E0(msgData, msg_no, ret); + } + DestroyMsgData(msgData); + return ret; + } + return NULL; +} + +struct String * FUN_0200AA50(u16 species, u32 heap_id) +{ + struct String * ret; + struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 362, heap_id); + if (msgData != NULL) + { + ret = FUN_0200A914(msgData, species); + DestroyMsgData(msgData); + return ret; + } + return NULL; +} -- cgit v1.2.3 From 1386f29730b42a640fde1d568255dc10be4ac759 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Sat, 20 Jun 2020 09:18:15 -0400 Subject: Name methods in msgdata.c and unk_02021934.s aka string16.s --- arm9/src/msgdata.c | 220 ++++++++++++++++++++++++++--------------------------- 1 file changed, 109 insertions(+), 111 deletions(-) (limited to 'arm9/src/msgdata.c') diff --git a/arm9/src/msgdata.c b/arm9/src/msgdata.c index 76d44338..ae33e0f5 100644 --- a/arm9/src/msgdata.c +++ b/arm9/src/msgdata.c @@ -1,6 +1,6 @@ #include "global.h" #include "filesystem.h" -#include "msg_data.h" +#include "msgdata.h" #include "heap.h" #include "MI_memory.h" #include "string16.h" @@ -8,36 +8,34 @@ #pragma thumb on -void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id); -void FreeMsgDataRawData(void * data); -void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct UnkStruct_200A394_4 * param); -void DecryptMessageDirect(struct UnkStruct_200A394 * r3, u32 r5, u16 * r4); -void DecryptMessageViaNewNarcHandle(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest); -void FUN_0200A4D4(struct UnkStruct_200A394 * r5, u32 r4, struct String * dest); -struct String * FUN_0200A584(struct UnkStruct_200A394 * r5, u32 r4, u32 heap_id); -void FUN_0200A648(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String * dest); -void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest); -struct String * FUN_0200A738(NarcId narc_id, u32 group, u32 num, u32 heap_id); -struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id); -u16 FUN_0200A848(struct UnkStruct_200A394 * tbl); -u16 FUN_0200A84C(NarcId narc_id, s32 file_id); - -void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id) +static void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id); +static void FreeMsgDataRawData(void * data); +static void ReadMsgData_ExistingTable_ExistingArray(struct MsgDataTable * table, u32 num, u16 * dest); +static void ReadMsgData_NewNarc_ExistingArray(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest); +static void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct MsgDataAlloc * param); +static void ReadMsgData_ExistingTable_ExistingString(struct MsgDataTable * table, u32 num, struct String * dest); +static struct String * ReadMsgData_ExistingTable_NewString(struct MsgDataTable * table, u32 num, u32 heap_id); +static void ReadMsgData_ExistingNarc_ExistingString(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest); +static struct String * ReadMsgData_ExistingNarc_NewString(NARC * narc, u32 group, u32 num, u32 heap_id); +static u16 GetMsgCount_ExistingTable(struct MsgDataTable * tbl); +static u16 GetMsgCount_TableFromNarc(NarcId narc_id, s32 file_id); + +static void * LoadSingleElementFromNarc(NarcId narc_id, s32 file_id, u32 heap_id) { return AllocAndReadWholeNarcMemberByIdPair(narc_id, file_id, heap_id); } -void FreeMsgDataRawData(void * data) +static void FreeMsgDataRawData(void * data) { FreeToHeap(data); } -inline static void Decrypt1(struct UnkStruct_200A394_4 * arg0, u32 arg1, u32 seed) +inline static void Decrypt1(struct MsgDataAlloc * arg0, u32 arg1, u32 seed) { seed = seed * 765 * (arg1 + 1) & 0xffff; seed |= seed << 16; - arg0->unk0 ^= seed; - arg0->unk4 ^= seed; + arg0->offset ^= seed; + arg0->length ^= seed; } inline static void Decrypt2(u16 * arg0, u32 count, u32 arg2) @@ -52,17 +50,17 @@ inline static void Decrypt2(u16 * arg0, u32 count, u32 arg2) } } -void DecryptMessageDirect(struct UnkStruct_200A394 * table, u32 num, u16 * dest) +static void ReadMsgData_ExistingTable_ExistingArray(struct MsgDataTable * table, u32 num, u16 * dest) { - struct UnkStruct_200A394_4 sp0; + struct MsgDataAlloc sp0; - if (num < table->unk0) + if (num < table->count) { - sp0 = table->unk4[num]; - Decrypt1(&sp0, num, table->unk2); + sp0 = table->alloc[num]; + Decrypt1(&sp0, num, table->key); - CopyEncryptedMessage16(dest, (const u16 *)((u8 *)table + sp0.unk0), &sp0); - Decrypt2(dest, sp0.unk4, num); + CopyEncryptedMessage16(dest, (const u16 *)((u8 *)table + sp0.offset), &sp0); + Decrypt2(dest, sp0.length, num); } else { @@ -70,68 +68,68 @@ void DecryptMessageDirect(struct UnkStruct_200A394 * table, u32 num, u16 * dest) } } -void DecryptMessageViaNewNarcHandle(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest) +static void ReadMsgData_NewNarc_ExistingArray(NarcId narc_id, u32 group, u32 num, u32 heap_id, u16 * dest) { NARC * narc = NARC_ctor(narc_id, heap_id); - u16 spC[2]; - struct UnkStruct_200A394_4 sp4; + u16 header[2]; + struct MsgDataAlloc alloc; if (narc != NULL) { - NARC_ReadFromMember(narc, group, 0, 4, spC); - NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp4); - Decrypt1(&sp4, num, spC[1]); - NARC_ReadFromMember(narc, group, sp4.unk0, 2 * sp4.unk4, dest); - Decrypt2(dest, sp4.unk4, num); + NARC_ReadFromMember(narc, group, 0, 4, header); + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &alloc); + Decrypt1(&alloc, num, header[1]); + NARC_ReadFromMember(narc, group, alloc.offset, 2 * alloc.length, dest); + Decrypt2(dest, alloc.length, num); NARC_dtor(narc); } } -void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct UnkStruct_200A394_4 * param) +static void CopyEncryptedMessage16(u16 * dest, const u16 * src, struct MsgDataAlloc * param) { - MI_CpuCopy16(src, dest, 2 * param->unk4); + MI_CpuCopy16(src, dest, 2 * param->length); } -void FUN_0200A4D4(struct UnkStruct_200A394 * table, u32 num, struct String * dest) +static void ReadMsgData_ExistingTable_ExistingString(struct MsgDataTable * table, u32 num, struct String * dest) { - struct UnkStruct_200A394_4 sp4; + struct MsgDataAlloc alloc; u16 * buf; - if (num < table->unk0) + if (num < table->count) { - sp4 = table->unk4[num]; - Decrypt1(&sp4, num, table->unk2); - buf = AllocFromHeapAtEnd(0, 2 * sp4.unk4); + alloc = table->alloc[num]; + Decrypt1(&alloc, num, table->key); + buf = AllocFromHeapAtEnd(0, 2 * alloc.length); if (buf != NULL) { - MI_CpuCopy16((char *)table + sp4.unk0, buf, 2 * sp4.unk4); - Decrypt2(buf, sp4.unk4, num); - FUN_02021E8C(dest, buf, sp4.unk4); + MI_CpuCopy16((char *)table + alloc.offset, buf, 2 * alloc.length); + Decrypt2(buf, alloc.length, num); + FUN_02021E8C(dest, buf, alloc.length); FreeToHeap(buf); } } else { GF_ASSERT(0); - FUN_02021A4C(dest); + StringSetEmpty(dest); } } -struct String * FUN_0200A584(struct UnkStruct_200A394 * table, u32 num, u32 heap_id) +static struct String * ReadMsgData_ExistingTable_NewString(struct MsgDataTable * table, u32 num, u32 heap_id) { - struct UnkStruct_200A394_4 sp4; + struct MsgDataAlloc alloc; u16 * buf; struct String * dest; - if (num < table->unk0) + if (num < table->count) { - sp4 = table->unk4[num]; - Decrypt1(&sp4, num, table->unk2); - buf = AllocFromHeapAtEnd(heap_id, 2 * sp4.unk4); + alloc = table->alloc[num]; + Decrypt1(&alloc, num, table->key); + buf = AllocFromHeapAtEnd(heap_id, 2 * alloc.length); if (buf != NULL) { - MI_CpuCopy16((char *)table + sp4.unk0, buf, 2 * sp4.unk4); - Decrypt2(buf, sp4.unk4, num); - dest = FUN_020219F4(sp4.unk4, heap_id); + MI_CpuCopy16((char *)table + alloc.offset, buf, 2 * alloc.length); + Decrypt2(buf, alloc.length, num); + dest = String_ctor(alloc.length, heap_id); if (dest != NULL) - FUN_02021E8C(dest, buf, sp4.unk4); + FUN_02021E8C(dest, buf, alloc.length); FreeToHeap(buf); return dest; } @@ -143,39 +141,39 @@ struct String * FUN_0200A584(struct UnkStruct_200A394 * table, u32 num, u32 heap else { GF_ASSERT(0); - return FUN_020219F4(4, heap_id); + return String_ctor(4, heap_id); } } -void FUN_0200A648(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String * dest) +void ReadMsgData_NewNarc_ExistingString(NarcId narc_id, u32 group, u32 num, u32 heap_id, struct String * dest) { NARC * narc = NARC_ctor(narc_id, heap_id); if (narc != NULL) { - FUN_0200A670(narc, group, num, heap_id, dest); + ReadMsgData_ExistingNarc_ExistingString(narc, group, num, heap_id, dest); NARC_dtor(narc); } } -void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest) +static void ReadMsgData_ExistingNarc_ExistingString(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * dest) { u16 * buf; u32 size; u16 sp10[2]; - struct UnkStruct_200A394_4 sp8; + struct MsgDataAlloc alloc; NARC_ReadFromMember(narc, group, 0, 4, sp10); if (num < sp10[0]) { - NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp8); - Decrypt1(&sp8, num, sp10[1]); - size = sp8.unk4 * 2; + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &alloc); + Decrypt1(&alloc, num, sp10[1]); + size = alloc.length * 2; buf = AllocFromHeapAtEnd(heap_id, size); if (buf != NULL) { - NARC_ReadFromMember(narc, group, sp8.unk0, size, buf); - Decrypt2(buf, sp8.unk4, num); - FUN_02021E8C(dest, buf, sp8.unk4); + NARC_ReadFromMember(narc, group, alloc.offset, size, buf); + Decrypt2(buf, alloc.length, num); + FUN_02021E8C(dest, buf, alloc.length); FreeToHeap(buf); return; } @@ -183,49 +181,49 @@ void FUN_0200A670(NARC * narc, u32 group, u32 num, u32 heap_id, struct String * else { GF_ASSERT(0); - FUN_02021A4C(dest); + StringSetEmpty(dest); } } -struct String * FUN_0200A738(NarcId narc_id, u32 group, u32 num, u32 heap_id) +struct String * ReadMsgData_NewNarc_NewString(NarcId narc_id, u32 group, u32 num, u32 heap_id) { NARC * narc = NARC_ctor(narc_id, heap_id); struct String * string; if (narc != NULL) { - string = FUN_0200A76C(narc, group, num, heap_id); + string = ReadMsgData_ExistingNarc_NewString(narc, group, num, heap_id); NARC_dtor(narc); } else { - string = FUN_020219F4(4, heap_id); + string = String_ctor(4, heap_id); } return string; } -struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id) +static struct String * ReadMsgData_ExistingNarc_NewString(NARC * narc, u32 group, u32 num, u32 heap_id) { struct String * dest; u16 * buf; u32 size; u16 sp10[2]; - struct UnkStruct_200A394_4 sp8; + struct MsgDataAlloc alloc; NARC_ReadFromMember(narc, group, 0, 4, sp10); if (num < sp10[0]) { - NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &sp8); - Decrypt1(&sp8, num, sp10[1]); - dest = FUN_020219F4(sp8.unk4, heap_id); + NARC_ReadFromMember(narc, group, 8 * num + 4, 8, &alloc); + Decrypt1(&alloc, num, sp10[1]); + dest = String_ctor(alloc.length, heap_id); if (dest != NULL) { - size = sp8.unk4 * 2; + size = alloc.length * 2; buf = AllocFromHeapAtEnd(heap_id, size); if (buf != NULL) { - NARC_ReadFromMember(narc, group, sp8.unk0, size, buf); - Decrypt2(buf, sp8.unk4, num); - FUN_02021E8C(dest, buf, sp8.unk4); + NARC_ReadFromMember(narc, group, alloc.offset, size, buf); + Decrypt2(buf, alloc.length, num); + FUN_02021E8C(dest, buf, alloc.length); FreeToHeap(buf); } } @@ -234,16 +232,16 @@ struct String * FUN_0200A76C(NARC * narc, u32 group, u32 num, u32 heap_id) else { GF_ASSERT(0); - return FUN_020219F4(4, heap_id); + return String_ctor(4, heap_id); } } -u16 FUN_0200A848(struct UnkStruct_200A394 * tbl) +static u16 GetMsgCount_ExistingTable(struct MsgDataTable * tbl) { - return tbl->unk0; + return tbl->count; } -u16 FUN_0200A84C(NarcId narc_id, s32 file_id) +static u16 GetMsgCount_TableFromNarc(NarcId narc_id, s32 file_id) { u16 n[2]; ReadFromNarcMemberByIdPair(&n, narc_id, file_id, 0, 4); @@ -293,94 +291,94 @@ void DestroyMsgData(struct MsgData * msgData) } } -void FUN_0200A8E0(struct MsgData * msgData, u32 msg_no, struct String * dest) +void ReadMsgDataIntoString(struct MsgData * msgData, u32 msg_no, struct String * dest) { switch (msgData->type) { case 0: - FUN_0200A4D4(msgData->data.raw, msg_no, dest); + ReadMsgData_ExistingTable_ExistingString(msgData->data.raw, msg_no, dest); break; case 1: - FUN_0200A670(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id, dest); + ReadMsgData_ExistingNarc_ExistingString(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id, dest); break; } } -struct String * FUN_0200A914(struct MsgData * msgData, u32 msg_no) +struct String * NewString_ReadMsgData(struct MsgData * msgData, u32 msg_no) { switch (msgData->type) { case 0: - return FUN_0200A584(msgData->data.raw, msg_no, msgData->heap_id); + return ReadMsgData_ExistingTable_NewString(msgData->data.raw, msg_no, msgData->heap_id); case 1: - return FUN_0200A76C(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id); + return ReadMsgData_ExistingNarc_NewString(msgData->data.narc, msgData->file_id, msg_no, msgData->heap_id); default: return NULL; } } -u16 FUN_0200A940(struct MsgData * msgData) +u16 MsgDataGetCount(struct MsgData * msgData) { switch (msgData->type) { case 0: - return FUN_0200A848(msgData->data.raw); + return GetMsgCount_ExistingTable(msgData->data.raw); case 1: - return FUN_0200A84C((NarcId)msgData->narc_id, msgData->file_id); + return GetMsgCount_TableFromNarc((NarcId)msgData->narc_id, msgData->file_id); default: return 0; } } -void DecryptCopyString(struct MsgData * msgData, u32 msg_no, u16 * dest) +void ReadMsgDataIntoU16Array(struct MsgData * msgData, u32 msg_no, u16 * dest) { switch (msgData->type) { case 0: - DecryptMessageDirect(msgData->data.raw, msg_no, dest); + ReadMsgData_ExistingTable_ExistingArray(msgData->data.raw, msg_no, dest); break; case 1: - DecryptMessageViaNewNarcHandle((NarcId)msgData->narc_id, msgData->file_id, msg_no, msgData->heap_id, dest); + ReadMsgData_NewNarc_ExistingArray((NarcId)msgData->narc_id, msgData->file_id, msg_no, msgData->heap_id, dest); break; } } -void GetSpeciesName(u16 species, u32 heap_id, u16 * dest) +void GetSpeciesNameIntoArray(u16 species, u32 heap_id, u16 * dest) { struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 362, heap_id); - DecryptCopyString(msgData, species, dest); + ReadMsgDataIntoU16Array(msgData, species, dest); DestroyMsgData(msgData); } -struct String * FUN_0200A9C4(u32 * a0, struct MsgData * msgData, u32 msgno, struct String * a3) +struct String * ReadMsgData_ExpandPlaceholders(u32 * a0, struct MsgData * msgData, u32 msgno, u32 a3) { struct String * ret = NULL; - struct String * r4 = FUN_020219F4(1024, 0); + struct String * r4 = String_ctor(1024, 0); struct String * r5; if (r4 != NULL) { - r5 = FUN_0200A914(msgData, msgno); + r5 = NewString_ReadMsgData(msgData, msgno); if (r5 != NULL) { - FUN_0200B7B8(a0, r4, r5); - ret = FUN_02021ACC(r4, a3); - FUN_02021A20(r5); + StringExpandPlaceholders(a0, r4, r5); + ret = StringDup(r4, a3); + String_dtor(r5); } - FUN_02021A20(r4); + String_dtor(r4); } return ret; } -struct String * FUN_0200AA14(u32 msg_no, u32 heapno) +struct String * GetMoveName(u32 move, u32 heapno) { struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 588, heapno); struct String * ret; if (msgData != NULL) { - ret = FUN_020219F4(16, heapno); + ret = String_ctor(16, heapno); if (ret != NULL) { - FUN_0200A8E0(msgData, msg_no, ret); + ReadMsgDataIntoString(msgData, move, ret); } DestroyMsgData(msgData); return ret; @@ -388,13 +386,13 @@ struct String * FUN_0200AA14(u32 msg_no, u32 heapno) return NULL; } -struct String * FUN_0200AA50(u16 species, u32 heap_id) +struct String * GetSpeciesName(u16 species, u32 heap_id) { struct String * ret; struct MsgData * msgData = NewMsgDataFromNarc(1, NARC_MSGDATA_MSG, 362, heap_id); if (msgData != NULL) { - ret = FUN_0200A914(msgData, species); + ret = NewString_ReadMsgData(msgData, species); DestroyMsgData(msgData); return ret; } -- cgit v1.2.3