Skip to content

Commit 70d08c2

Browse files
committed
Match DLL 21 "gametext"
1 parent 54a843a commit 70d08c2

15 files changed

+233
-22
lines changed

export_symbol_addrs.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ get_main_camera = 0x80000010;
1717
get_world_actors = 0x80000011;
1818
get_actor_child_position = 0x80000012;
1919
round_2_floats = 0x80000013;
20-
gDLL_text = 0x80000014;
20+
gDLL_21_gametext = 0x80000014;
2121
delayByte = 0x80000015;
2222
dl_apply_combine = 0x80000016;
2323
dl_apply_other_mode = 0x80000017;

include/dll.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef _DLL_H
22
#define _DLL_H
33

4+
#include "dlls/engine/21_gametext.h"
45
#include "dlls/engine/29_gplay.h"
56
#include "dlls/engine/30_task.h"
67
#include "dlls/engine/31_flash.h"
@@ -54,6 +55,7 @@ enum DLL_ID {
5455
// These are loaded on game init, are never unloaded, and are referenced by
5556
// their global variable instead of from loading the DLL.
5657

58+
extern DLLInst_21_gametext *gDLL_21_gametext;
5759
extern DLLInst_29_gplay *gDLL_29_gplay;
5860
extern DLLInst_30_task *gDLL_30_task;
5961
extern DLLInst_31_flash *gDLL_31_flash;
@@ -81,7 +83,6 @@ extern DLLInst_Unknown
8183
*gDLL_17,
8284
*gDLL_18,
8385
*gDLL_SCREENS,
84-
*gDLL_text,
8586
*gDLL_subtitles,
8687
*gDLL_23,
8788
*gDLL_waterfx,

include/dlls/engine/21_gametext.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef _DLLS_21_H
2+
#define _DLLS_21_H
3+
4+
#include <PR/ultratypes.h>
5+
#include "dll_def.h"
6+
7+
typedef struct {
8+
// Num strings
9+
u8 count;
10+
void *unk4;
11+
char **strings;
12+
} GameTextChunk;
13+
14+
DLL_INTERFACE_BEGIN(21_gametext)
15+
/*0*/ u16 (*bank_count)();
16+
/*1*/ u16 (*chunk_count)();
17+
/*2*/ void (*set_bank)(s8 bank);
18+
/*3*/ s8 (*curr_bank)();
19+
/*4*/ GameTextChunk *(*get_chunk)(u16 chunk);
20+
/*5*/ char *(*get_text)(u16 chunk, u16 strIndex);
21+
DLL_INTERFACE_END()
22+
23+
#endif //_DLLS_21_H

include/dlls/engine/30_task.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include "dll_def.h"
66

77
DLL_INTERFACE_BEGIN(30_task)
8-
void (*load_recently_completed)();
9-
void (*mark_task_completed)(u8 task);
10-
u8 (*get_num_recently_completed)();
11-
void (*func_390)(u8 param1);
12-
void (*func_3F8)();
13-
s16 (*get_completion_percentage)();
8+
/*0*/ void (*load_recently_completed)();
9+
/*1*/ void (*mark_task_completed)(u8 task);
10+
/*2*/ u8 (*get_num_recently_completed)();
11+
/*3*/ char *(*get_recently_completed_task_text)(u8 idx);
12+
/*4*/ char *(*get_completion_task_text)();
13+
/*5*/ s16 (*get_completion_percentage)();
1414
DLL_INTERFACE_END()
1515

1616
#endif //_DLLS_30_H

include/sys/asset_thread.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void create_asset_thread(void);
114114
void asset_thread_main(void *arg);
115115
void queue_alloc_load_file(void **dest, s32 fileId);
116116
void queue_load_file_to_ptr(void **dest, s32 fileId);
117-
void queue_load_file_region_to_ptr(void **dest, s32 fileId, s32 length, s32 offset);
117+
void queue_load_file_region_to_ptr(void **dest, s32 fileId, s32 offset, s32 length);
118118
void queue_load_map_object(void **dest, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6);
119119
void queue_load_texture(void **dest, s32 id);
120120
void queue_load_dll(void **dest, s32 id, s32 exportCount);

src/dlls/dlls.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# engine
22
16 = engine/16
3+
21 = engine/21_gametext
34
29 = engine/29_gplay
45
30 = engine/30_task
56
31 = engine/31_flash

src/dlls/engine/21_gametext/dll.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
compile: true

src/dlls/engine/21_gametext/exports.s

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.option pic2
2+
.section ".exports"
3+
.global _exports
4+
_exports:
5+
6+
# ctor/dtor
7+
.dword gametext_ctor
8+
.dword gametext_dtor
9+
10+
# export table
11+
.dword gametext_bank_count
12+
.dword gametext_chunk_count
13+
.dword gametext_set_bank
14+
.dword gametext_curr_bank
15+
.dword gametext_get_chunk
16+
.dword gametext_get_text
+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#include <PR/ultratypes.h>
2+
#include "common.h"
3+
#include "dlls/engine/21_gametext.h"
4+
#include "prevent_bss_reordering.h"
5+
6+
static s8 sCurrentBankIndex = -1;
7+
8+
/*0x0*/ static u16 sBankCount;
9+
/*0x2*/ static u16 sBankEntryCount;
10+
/*0x4*/ static u16 sBankSize;
11+
/*0x8*/ static u8 *sCurrentBank;
12+
/*0xc*/ static s32 sCurrentBank_GlobalOffset;
13+
// Number of strings in each chunk.
14+
/*0x10*/ static u8 *sCurrentBank_StrCounts;
15+
// Byte size of each chunk.
16+
/*0x14*/ static u16 *sCurrentBank_Sizes;
17+
// Byte offset to each chunk.
18+
/*0x18*/ static u16 *sCurrentBank_Offsets;
19+
20+
void gametext_set_bank(s8 bank);
21+
22+
void gametext_ctor(void *self) {
23+
u16 *header;
24+
25+
header = (u16*)malloc(4, 0x19, NULL);
26+
queue_load_file_region_to_ptr((void**)header, GAMETEXT_TAB, 0, 4);
27+
28+
sBankCount = header[0];
29+
sBankEntryCount = header[1];
30+
31+
free(header);
32+
33+
sBankSize = sBankEntryCount * 5 + 4;
34+
sCurrentBank = malloc(sBankSize, 0x19, NULL);
35+
sCurrentBank_StrCounts = sCurrentBank + 4;
36+
sCurrentBank_Sizes = (u16*)(sCurrentBank + sBankEntryCount + 4);
37+
sCurrentBank_Offsets = (u16*)(sCurrentBank + (sBankEntryCount * 3) + 4);
38+
39+
gametext_set_bank(0);
40+
}
41+
42+
void gametext_dtor(void *self) {
43+
free(sCurrentBank);
44+
}
45+
46+
u16 gametext_bank_count() {
47+
return sBankCount;
48+
}
49+
50+
u16 gametext_chunk_count() {
51+
return sBankEntryCount;
52+
}
53+
54+
void gametext_set_bank(s8 bank) {
55+
u32 offset;
56+
57+
offset = (sBankSize * bank) + 4;
58+
59+
if (sCurrentBankIndex == bank) {
60+
return;
61+
}
62+
63+
sCurrentBankIndex = bank;
64+
65+
queue_load_file_region_to_ptr(
66+
(void**)sCurrentBank,
67+
GAMETEXT_TAB,
68+
offset,
69+
sBankSize);
70+
71+
sCurrentBank_GlobalOffset = *((u32*)sCurrentBank);
72+
}
73+
74+
s8 gametext_curr_bank() {
75+
return sCurrentBankIndex;
76+
}
77+
78+
GameTextChunk *gametext_get_chunk(u16 chunk) {
79+
GameTextChunk *chunkPtr;
80+
s32 headerSize;
81+
s32 alignmentPad;
82+
s32 i;
83+
s32 k;
84+
85+
// mem map
86+
// 0x0 GameTextChunk
87+
// 0xC string pointer array
88+
// alignment padding
89+
// string chunk
90+
91+
// Size for struct and string pointers
92+
headerSize = sCurrentBank_StrCounts[chunk] * 4 + sizeof(GameTextChunk);
93+
// Room for alignment
94+
alignmentPad = headerSize % 8;
95+
96+
headerSize += alignmentPad + sCurrentBank_Sizes[chunk];
97+
98+
chunkPtr = (GameTextChunk*)malloc(headerSize, 0x19, NULL);
99+
100+
chunkPtr->strings = (char**)((u32)chunkPtr + sizeof(GameTextChunk));
101+
102+
chunkPtr->count = sCurrentBank_StrCounts[chunk];
103+
104+
// Where to load actual chunk contents to (also contains data for some chunks)
105+
chunkPtr->unk4 = (void*)((u32)chunkPtr->strings + sCurrentBank_StrCounts[chunk] * 4 + alignmentPad);
106+
107+
// Set up first string pointer
108+
chunkPtr->strings[0] = (char*)((u32)chunkPtr->unk4 + sCurrentBank_StrCounts[chunk] * 2);
109+
110+
queue_load_file_region_to_ptr(
111+
(void**)chunkPtr->unk4,
112+
GAMETEXT_BIN,
113+
sCurrentBank_Offsets[chunk] * 2 + sCurrentBank_GlobalOffset,
114+
sCurrentBank_Sizes[chunk]);
115+
116+
// Set up remaining pointers to each string
117+
for (i = 1; i < sCurrentBank_StrCounts[chunk]; i++) {
118+
k = 0;
119+
120+
while (chunkPtr->strings[i - 1][k++] != '\0') {}
121+
122+
chunkPtr->strings[i] = chunkPtr->strings[i - 1] + k;
123+
}
124+
125+
return chunkPtr;
126+
}
127+
128+
char *gametext_get_text(u16 chunk, u16 strIndex) {
129+
u8 *text;
130+
char *str;
131+
char *copy;
132+
s32 len;
133+
s32 i;
134+
s32 k;
135+
136+
text = malloc(sCurrentBank_Sizes[chunk], 0x19, NULL);
137+
138+
queue_load_file_region_to_ptr(
139+
(void**)text,
140+
GAMETEXT_BIN,
141+
sCurrentBank_Offsets[chunk] * 2,
142+
sCurrentBank_Sizes[chunk]);
143+
144+
str = (char*)(text + sCurrentBank_StrCounts[chunk] * 2);
145+
146+
for (i = 0; i != strIndex; i++) {
147+
k = 0;
148+
149+
while (str[k++] != '\0') {}
150+
151+
str += k;
152+
}
153+
154+
len = strlen(str) + 1;
155+
156+
copy = malloc(len, 0x19, NULL);
157+
bcopy(str, copy, len);
158+
159+
free(text);
160+
161+
return copy;
162+
}

src/dlls/engine/21_gametext/syms.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# functions
2+
gametext_ctor = 0x0;
3+
gametext_dtor = 0x120;
4+
gametext_bank_count = 0x160;
5+
gametext_chunk_count = 0x17C;
6+
gametext_set_bank = 0x198;
7+
gametext_curr_bank = 0x224;
8+
gametext_get_chunk = 0x240;
9+
gametext_get_text = 0x420;

src/dlls/engine/30_task/exports.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ _exports:
1111
.dword task_load_recently_completed
1212
.dword task_mark_task_completed
1313
.dword task_get_num_recently_completed
14-
.dword task_func_390
15-
.dword task_func_3F8
14+
.dword task_get_recently_completed_task_text
15+
.dword task_get_completion_task_text
1616
.dword task_get_completion_percentage

src/dlls/engine/30_task/syms.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ task_dtor = 0xC;
44
task_load_recently_completed = 0x18;
55
task_mark_task_completed = 0xDC;
66
task_get_num_recently_completed = 0x368;
7-
task_func_390 = 0x390;
8-
task_func_3F8 = 0x3F8;
7+
task_get_recently_completed_task_text = 0x390;
8+
task_get_completion_task_text = 0x3F8;
99
task_get_completion_percentage = 0x454;

src/dlls/engine/30_task/task.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ u8 task_get_num_recently_completed() {
109109
return sRecentlyCompletedNextIdx + 1;
110110
}
111111

112-
// TODO: this returns something
113-
void task_func_390(u8 param1) {
114-
gDLL_text->exports->func[5].withTwoArgs((u16)(sRecentlyCompleted[param1] + 244), 0);
112+
char *task_get_recently_completed_task_text(u8 idx) {
113+
return gDLL_21_gametext->exports->get_text(sRecentlyCompleted[idx] + 244, 0);
115114
}
116115

117-
// TODO: this returns something
118-
void task_func_3F8() {
119-
gDLL_text->exports->func[5].withTwoArgs((u16)(sCompletionIdx + 244), 1);
116+
char *task_get_completion_task_text() {
117+
return gDLL_21_gametext->exports->get_text(sCompletionIdx + 244, 1);
120118
}
121119

122120
s16 task_get_completion_percentage() {

src/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void game_init(void)
9494
temp_AMSEQ_DLL = dll_load_deferred(DLL_AMSEQ, 36);
9595
gDLL_AMSEQ2 = gDLL_AMSEQ = temp_AMSEQ_DLL;
9696
gDLL_AMSFX = dll_load_deferred(DLL_AMSFX, 18);
97-
gDLL_text = dll_load_deferred(DLL_TEXT, 5);
97+
gDLL_21_gametext = dll_load_deferred(DLL_TEXT, 5);
9898
gDLL_29_gplay = dll_load_deferred(DLL_GPLAY, 47);
9999
gDLL_31_flash = dll_load_deferred(DLL_FLASH, 2);
100100
gDLL_28 = dll_load_deferred(28, 4);
@@ -122,7 +122,7 @@ void game_init(void)
122122
gDLL_16 = dll_load_deferred(16, 3);
123123
gDLL_17 = dll_load_deferred(17, 2); //probably particle FX
124124
gDLL_SCREENS = dll_load_deferred(DLL_SCREENS, 3);
125-
gDLL_text = dll_load_deferred(DLL_TEXT, 5);
125+
gDLL_21_gametext = dll_load_deferred(DLL_TEXT, 5);
126126
gDLL_subtitles = dll_load_deferred(DLL_SUBTITLES, 7);
127127
gDLL_waterfx = dll_load_deferred(DLL_WATERFX, 7);
128128
gDLL_CURVES = dll_load_deferred(DLL_CURVES, 38);

symbol_addrs.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ gDLL_expgfx = 0x8008c9b4; // type:data size:0x4
953953
gDLL_modgfx = 0x8008c9b8; // type:data size:0x4
954954
gDLL_projgfx = 0x8008c9bc; // type:data size:0x4
955955
gDLL_SCREENS = 0x8008c9cc; // type:data size:0x4
956-
gDLL_text = 0x8008c9d0; // type:data size:0x4
956+
gDLL_21_gametext = 0x8008c9d0; // type:data size:0x4
957957
gDLL_subtitles = 0x8008c9d4; // type:data size:0x4
958958
gDLL_waterfx = 0x8008c9dc; // type:data size:0x4
959959
gDLL_CURVES = 0x8008c9e4; // type:data size:0x4

0 commit comments

Comments
 (0)