1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
#include "d/dolzel.h" // IWYU pragma: keep
#include "d/d_msg_unit.h"
#include "d/d_com_inf_game.h"
#include "stdio.h"
#include "d/d_kankyo.h"
#include "d/d_meter2_info.h"
// temporary until a better solution is found
typedef struct dMsgUnit_inf1_entry {
u32 dat1EntryOffset;
#if REGION_JPN
u16 field_0x04;
u16 field_0x06;
u16 field_0x08;
u16 field_0x0a;
u16 field_0x0c;
u16 field_0x0e;
u16 field_0x10;
u16 field_0x12;
u16 field_0x14;
u16 field_0x16;
u16 field_0x18;
#else
u16 startFrame;
u16 endFrame;
#endif
} dMsgUnit_inf1_entry;
typedef struct dMsgUnit_inf1_section_t {
/* 0x00 */ u32 msgType; // sectionType
/* 0x04 */ u32 size; // total size of the section
/* 0x08 */ u16 entryCount;
/* 0x0A */ u16 entryLength;
/* 0x0C */ u16 msgArchiveId;
/* 0x10 */ dMsgUnit_inf1_entry entries[0];
} dMsgUnit_inf1_section_t;
dMsgUnit_c::dMsgUnit_c() {}
dMsgUnit_c::~dMsgUnit_c() {}
#if REGION_JPN
void dMsgUnit_c::setTag(int i_type, int i_value, char* o_buffer, bool param_4) {
*o_buffer = 0;
bool stack9 = false;
bool stack8 = false;
int value = i_value;
if (i_type == 0x10000) {
sprintf(o_buffer, "%d", i_value);
return;
}
if (i_type == 0x10001) {
int tens_digit = i_value / 10;
int ones_digit = i_value % 10;
sprintf(o_buffer, "%d-%d", tens_digit, ones_digit);
return;
}
if ((i_type == 4 && param_4 == true) || (i_type == 5 && param_4 == false)) {
int seconds = i_value / 1000;
int minutes = seconds / 60;
seconds -= minutes * 60;
if (minutes > 99) {
minutes = 99;
seconds = 59;
}
if (minutes == 0 && seconds == 0) {
if (strcmp(dComIfGp_getStartStageName(), "F_SP00") == 0) {
return;
}
}
if (i_type == 4) {
i_value = minutes;
if (minutes == 0) {
stack9 = true;
}
}
if (i_type == 5) {
if (seconds == 0 && minutes != 0) {
return;
}
i_value = seconds;
}
}
if ((i_type == 3 && param_4 == true) || i_type == 4 && param_4 == false) {
f32 dayTime = g_env_light.getDaytime();
f32 hour = dayTime / 15.0f;
f32 iVar8b = ((s32)(1000000.0f * dayTime) % 15000000) / 1000000.0f;
f32 minute = 60.0f * (iVar8b / 15.0f);
// not sure why this affects codegen, in theory it should be optimized out
f32 minute2 = 60.0f * (iVar8b / 15.0f);
if (i_type == 3) {
i_value = (s32)hour;
}
if (i_type == 4) {
i_value = (s32)minute;
}
}
if (i_type == 9 && param_4 == true) {
sprintf(o_buffer, "%d", i_value);
stack8 = true;
}
if (!stack9) {
bmg_header_t* pHeader = (bmg_header_t*)dMeter2Info_getMsgUnitResource();
dMsgUnit_inf1_section_t* pInfoBlock = NULL;
const void* pMsgDataBlock = NULL;
str1_section_t* pStrAttributeBlock = NULL;
int filepos = sizeof(bmg_header_t);
u32 filesize = pHeader->size;
bmg_section_t* pSection = (bmg_section_t*)(((u8*)pHeader) + filepos);
for (; filepos < filesize; filepos += pSection->size) {
switch(pSection->magic) {
case 'FLW1':
break;
case 'FLI1':
break;
case 'INF1':
pInfoBlock = (dMsgUnit_inf1_section_t*)pSection;
break;
case 'DAT1':
pMsgDataBlock = pSection;
break;
case 'STR1':
pStrAttributeBlock = (str1_section_t*)pSection;
break;
}
pSection = (bmg_section_t*)((u8*)pSection + pSection->size);
}
u16 vals[12];
vals[0] = pInfoBlock->entries[i_type].field_0x04;
vals[1] = pInfoBlock->entries[i_type].field_0x06;
vals[2] = pInfoBlock->entries[i_type].field_0x08;
vals[3] = pInfoBlock->entries[i_type].field_0x0a;
vals[4] = pInfoBlock->entries[i_type].field_0x0c;
vals[5] = pInfoBlock->entries[i_type].field_0x0e;
vals[6] = pInfoBlock->entries[i_type].field_0x10;
vals[7] = pInfoBlock->entries[i_type].field_0x12;
vals[8] = pInfoBlock->entries[i_type].field_0x14;
vals[9] = pInfoBlock->entries[i_type].field_0x16;
vals[10] = pInfoBlock->entries[i_type].field_0x18;
int entryOff = pInfoBlock->entries[i_type].dat1EntryOffset;
char* value2 = (char*)((uintptr_t)pMsgDataBlock + entryOff + 8);
const char* uVar5;
if (i_value == 0) {
uVar5 = pStrAttributeBlock->entries->str + vals[0];
} else {
if ((i_value % 10) == 0) {
uVar5 = pStrAttributeBlock->entries->str + (vals[10]);
} else {
uVar5 = pStrAttributeBlock->entries->str + vals[i_value % 10];
}
}
int uVar5Len = strlen(uVar5);
if (uVar5Len == 0) {
if (stack8) {
strcat(o_buffer, value2);
} else {
sprintf(o_buffer, "%d%s", i_value, value2);
}
} else {
char unkCharArr[7];
unkCharArr[0] = 26;
unkCharArr[1] = uVar5Len + 6;
unkCharArr[2] = -1;
unkCharArr[3] = -1;
unkCharArr[4] = 2;
unkCharArr[5] = strlen(value2) / 2;
unkCharArr[6] = 0;
if (stack8) {
strcat(o_buffer, unkCharArr);
strcat(o_buffer, uVar5);
strcat(o_buffer, value2);
} else {
sprintf(o_buffer, "%d%s%s%s", i_value, unkCharArr, uVar5, value2);
}
}
}
if (i_type == 3 && param_4 == true) {
char buffer[20];
setTag(4, 0, buffer, false);
strcat(o_buffer, buffer);
}
if (i_type == 4 && param_4 == true) {
char buffer[20];
setTag(5, value, buffer, false);
strcat(o_buffer, buffer);
}
}
#else
void dMsgUnit_c::setTag(int i_type, int i_value, char* o_buffer, bool param_4) {
*o_buffer = 0;
bool stack9 = false;
bool stack8 = false;
int param_2b = i_value; // sp40
int tens_digit; // sp3C
int ones_digit; // sp38
int seconds; // r27
int minutes; // sp34
if (i_type == 0x10000) {
sprintf(o_buffer, "%d", i_value);
return;
}
if (i_type == 0x10001) {
tens_digit = i_value / 10;
ones_digit = i_value % 10;
sprintf(o_buffer, "%d-%d", tens_digit, ones_digit);
return;
}
if (i_type == 4 && param_4 == true) {
seconds = i_value / 1000;
minutes = seconds / 60;
seconds -= minutes * 60;
if (minutes > 99) {
minutes = 99;
seconds = 59;
}
if (minutes != 0 || seconds != 0) {
sprintf(o_buffer, "%d:%02d", minutes, seconds);
}
return;
}
if (i_type == 3 && param_4 == true) {
f32 iVar8b;
f32 dayTime = g_env_light.getDaytime();
f32 hour = dayTime / 15.0f;
iVar8b = ((s32)(1000000.0f * dayTime) % 15000000) / 1000000.0f;
f32 minute = 60.0f * (iVar8b / 15.0f);
iVar8b = ((s32)(1000000.0f * dayTime) % 250000) / 1000000.0f;
f32 iVar9 = 60.0f * (iVar8b / 0.25f);
sprintf(o_buffer, "%d:%02d", (s32)hour, (s32)minute);
} else {
if (i_type == 9 && param_4 == true) {
int value = i_value;
sprintf(o_buffer, "%d", value);
stack8 = true;
}
if (!stack9) {
bmg_header_t* pHeader = (bmg_header_t*)dMeter2Info_getMsgUnitResource();
bmg_section_t* pInfoBlock = NULL;
const void* pMsgDataBlock = NULL;
str1_section_t* pStrAttributeBlock = NULL;
int filepos = sizeof(bmg_header_t);
u32 filesize = pHeader->size;
u8* pSection = ((u8*)pHeader) + filepos;
for (; filepos < filesize; filepos += ((bmg_section_t*)pSection)->size) {
switch (((bmg_section_t*)pSection)->magic) {
case 'FLW1':
break;
case 'FLI1':
break;
case 'INF1':
pInfoBlock = (bmg_section_t*)pSection;
break;
case 'DAT1':
pMsgDataBlock = pSection;
break;
case 'STR1':
pStrAttributeBlock = (str1_section_t*)pSection;
break;
}
pSection += ((bmg_section_t*)pSection)->size;
}
// This section is weird. The debug seems like entriesStr is outside the condition
// but the normal build doesn't really work with that. Same for pInfoBlock->entries.
#if DEBUG
dMsgUnit_inf1_entry* entriesInf = &((dMsgUnit_inf1_section_t*)pInfoBlock)->entries[i_type];
u32 dat1EntryOffset = entriesInf->dat1EntryOffset;
const char* uVar5;
u16 vals[14];
vals[0] = entriesInf->startFrame;
vals[1] = entriesInf->endFrame;
str1_entry_t* entriesStr = pStrAttributeBlock->entries;
#else
u32 dat1EntryOffset = ((dMsgUnit_inf1_section_t*)pInfoBlock)->entries[i_type].dat1EntryOffset;
const char* uVar5;
u16 vals[14];
vals[0] = ((dMsgUnit_inf1_section_t*)pInfoBlock)->entries[i_type].startFrame;
vals[1] = ((dMsgUnit_inf1_section_t*)pInfoBlock)->entries[i_type].endFrame;
#endif
#if REGION_PAL
if (i_value == 1 ||
(dComIfGs_getPalLanguage() == dSv_player_config_c::LANGAUGE_FRENCH &&
i_value == 0)) {
#elif !REGION_USA
if (i_value == 1 ||
(dComIfGs_getPalLanguage() == dSv_player_config_c::LANGAUGE_SPANISH &&
i_value == 0)) {
#else
if (i_value == 1) {
#endif
#if DEBUG
uVar5 = entriesStr->str + vals[0];
#else
uVar5 = pStrAttributeBlock->entries->str + vals[0];
#endif
} else {
#if DEBUG
uVar5 = entriesStr->str + vals[1];
#else
uVar5 = pStrAttributeBlock->entries->str + vals[1];
#endif
}
if (strcmp(uVar5, "") == 0) {
sprintf(o_buffer, "%d%s", i_value, uVar5);
} else {
sprintf(o_buffer, "%d %s", i_value, uVar5);
}
}
if (i_type == 3 && param_4 == true) {
char buffer[20];
setTag(4, 0, buffer, false);
strcat(o_buffer, buffer);
}
if (i_type == 4 && param_4 == true) {
char buffer[20];
setTag(5, param_2b, buffer, false);
strcat(o_buffer, buffer);
}
}
}
#endif
dMsgUnit_c g_msg_unit;
|