Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Storage/Legacy/TextLegacy.cpp
1168 views
1
2
RSDK::Legacy::TextMenu RSDK::Legacy::gameMenu[LEGACY_TEXTMENU_COUNT];
3
int32 RSDK::Legacy::textMenuSurfaceNo = 0;
4
5
RSDK::Legacy::v3::FontCharacter RSDK::Legacy::v3::fontCharacterList[LEGACY_v3_FONTCHAR_COUNT];
6
7
void RSDK::Legacy::v3::LoadTextFile(TextMenu *menu, const char *filePath, uint8 mapCode)
8
{
9
bool32 finished = false;
10
FileInfo info;
11
InitFileInfo(&info);
12
13
if (LoadFile(&info, filePath, FMODE_RB)) {
14
menu->textDataPos = 0;
15
menu->rowCount = 0;
16
menu->entryStart[menu->rowCount] = menu->textDataPos;
17
menu->entrySize[menu->rowCount] = 0;
18
19
uint8 fileBuffer = ReadInt8(&info);
20
if (fileBuffer == 0xFF) {
21
fileBuffer = ReadInt8(&info);
22
23
while (!finished) {
24
uint16 character = ReadInt8(&info);
25
character |= ReadInt8(&info) << 8;
26
27
if (character != '\n') {
28
if (character == '\r') {
29
menu->rowCount += 1;
30
if (menu->rowCount >= 512) {
31
finished = true;
32
}
33
else {
34
menu->entryStart[menu->rowCount] = menu->textDataPos;
35
menu->entrySize[menu->rowCount] = 0;
36
}
37
}
38
else {
39
if (mapCode) {
40
int32 i = 0;
41
while (i < 1024) {
42
if (fontCharacterList[i].id == character) {
43
character = i;
44
i = 1025;
45
}
46
else {
47
++i;
48
}
49
}
50
51
if (i == 1024)
52
character = 0;
53
}
54
menu->textData[menu->textDataPos++] = character;
55
menu->entrySize[menu->rowCount]++;
56
}
57
}
58
59
if (!finished) {
60
finished = info.readPos >= info.fileSize;
61
if (menu->textDataPos >= LEGACY_TEXTDATA_COUNT)
62
finished = true;
63
}
64
}
65
}
66
else {
67
uint16 character = fileBuffer;
68
if (character != '\n') {
69
if (character == '\r') {
70
menu->rowCount++;
71
menu->entryStart[menu->rowCount] = menu->textDataPos;
72
menu->entrySize[menu->rowCount] = 0;
73
}
74
else {
75
if (mapCode) {
76
int32 i = 0;
77
while (i < 1024) {
78
if (fontCharacterList[i].id == character) {
79
character = i;
80
i = 1025;
81
}
82
else {
83
++i;
84
}
85
}
86
87
if (i == 1024)
88
character = 0;
89
}
90
menu->textData[menu->textDataPos++] = character;
91
menu->entrySize[menu->rowCount]++;
92
}
93
}
94
95
while (!finished) {
96
character = ReadInt8(&info);
97
if (character != '\n') {
98
if (character == '\r') {
99
menu->rowCount++;
100
if (menu->rowCount > 511) {
101
finished = true;
102
}
103
else {
104
menu->entryStart[menu->rowCount] = menu->textDataPos;
105
menu->entrySize[menu->rowCount] = 0;
106
}
107
}
108
else {
109
if (mapCode) {
110
int32 i = 0;
111
while (i < 1024) {
112
if (fontCharacterList[i].id == character) {
113
character = i;
114
i = 1025;
115
}
116
else {
117
++i;
118
}
119
}
120
121
if (i == 1024)
122
character = 0;
123
}
124
125
menu->textData[menu->textDataPos++] = character;
126
menu->entrySize[menu->rowCount]++;
127
}
128
}
129
130
if (!finished) {
131
finished = info.readPos >= info.fileSize;
132
if (menu->textDataPos >= LEGACY_TEXTDATA_COUNT)
133
finished = true;
134
}
135
}
136
}
137
menu->rowCount++;
138
139
CloseFile(&info);
140
}
141
}
142
143
void RSDK::Legacy::v4::LoadTextFile(TextMenu *menu, const char *filePath)
144
{
145
FileInfo info;
146
InitFileInfo(&info);
147
148
if (LoadFile(&info, filePath, FMODE_RB)) {
149
menu->textDataPos = 0;
150
menu->rowCount = 0;
151
menu->entryStart[menu->rowCount] = menu->textDataPos;
152
menu->entrySize[menu->rowCount] = 0;
153
154
while (menu->textDataPos < LEGACY_TEXTDATA_COUNT && info.readPos < info.fileSize) {
155
uint8 character = ReadInt8(&info);
156
if (character != '\n') {
157
if (character == '\r') {
158
menu->rowCount++;
159
menu->entryStart[menu->rowCount] = menu->textDataPos;
160
menu->entrySize[menu->rowCount] = 0;
161
}
162
else {
163
menu->textData[menu->textDataPos++] = character;
164
menu->entrySize[menu->rowCount]++;
165
}
166
}
167
}
168
169
menu->rowCount++;
170
CloseFile(&info);
171
}
172
}
173
174
void RSDK::Legacy::SetupTextMenu(TextMenu *menu, int32 rowCount)
175
{
176
menu->textDataPos = 0;
177
menu->rowCount = rowCount;
178
}
179
void RSDK::Legacy::AddTextMenuEntry(TextMenu *menu, const char *text)
180
{
181
menu->entryStart[menu->rowCount] = menu->textDataPos;
182
menu->entrySize[menu->rowCount] = 0;
183
menu->entryHighlight[menu->rowCount] = false;
184
185
int32 textLength = StrLength(text);
186
for (int32 i = 0; i < textLength;) {
187
if (text[i] != '\0') {
188
menu->textData[menu->textDataPos++] = text[i];
189
menu->entrySize[menu->rowCount]++;
190
++i;
191
}
192
else {
193
break;
194
}
195
}
196
menu->rowCount++;
197
}
198
void RSDK::Legacy::SetTextMenuEntry(TextMenu *menu, const char *text, int32 rowID)
199
{
200
menu->entryStart[rowID] = menu->textDataPos;
201
menu->entrySize[rowID] = 0;
202
menu->entryHighlight[menu->rowCount] = false;
203
204
int32 textLength = StrLength(text);
205
for (int32 i = 0; i < textLength;) {
206
if (text[i] != '\0') {
207
menu->textData[menu->textDataPos++] = text[i];
208
menu->entrySize[rowID]++;
209
++i;
210
}
211
else {
212
break;
213
}
214
}
215
}
216
void RSDK::Legacy::EditTextMenuEntry(TextMenu *menu, const char *text, int32 rowID)
217
{
218
int32 entryPos = menu->entryStart[rowID];
219
menu->entrySize[rowID] = 0;
220
menu->entryHighlight[menu->rowCount] = false;
221
222
int32 textLength = StrLength(text);
223
for (int32 i = 0; i < textLength;) {
224
if (text[i] != '\0') {
225
menu->textData[entryPos++] = text[i];
226
menu->entrySize[rowID]++;
227
++i;
228
}
229
else {
230
break;
231
}
232
}
233
}
234
235
void RSDK::Legacy::v3::LoadFontFile(const char *filePath)
236
{
237
FileInfo info;
238
InitFileInfo(&info);
239
240
if (LoadFile(&info, filePath, FMODE_RB)) {
241
int32 count = 0;
242
while (info.readPos < info.fileSize) {
243
fontCharacterList[count].id = ReadInt8(&info);
244
fontCharacterList[count].id += ReadInt8(&info) << 8;
245
fontCharacterList[count].id += ReadInt8(&info) << 16;
246
fontCharacterList[count].id += ReadInt8(&info) << 24;
247
248
fontCharacterList[count].srcX = ReadInt8(&info);
249
fontCharacterList[count].srcX += ReadInt8(&info) << 8;
250
251
fontCharacterList[count].srcY = ReadInt8(&info);
252
fontCharacterList[count].srcY += ReadInt8(&info) << 8;
253
254
fontCharacterList[count].width = ReadInt8(&info) + 1;
255
fontCharacterList[count].width += ReadInt8(&info) << 8;
256
257
fontCharacterList[count].height = ReadInt8(&info) + 1;
258
fontCharacterList[count].height += ReadInt8(&info) << 8;
259
260
fontCharacterList[count].pivotX = ReadInt8(&info);
261
uint8 fileBuffer = ReadInt8(&info);
262
if (fileBuffer > 0x80) {
263
fontCharacterList[count].pivotX += (fileBuffer - 0x80) << 8;
264
fontCharacterList[count].pivotX += -0x8000;
265
}
266
else {
267
fontCharacterList[count].pivotX += fileBuffer << 8;
268
}
269
270
fontCharacterList[count].pivotY = ReadInt8(&info);
271
fileBuffer = ReadInt8(&info);
272
if (fileBuffer > 0x80) {
273
fontCharacterList[count].pivotY += (fileBuffer - 0x80) << 8;
274
fontCharacterList[count].pivotY += -0x8000;
275
}
276
else {
277
fontCharacterList[count].pivotY += fileBuffer << 8;
278
}
279
280
fontCharacterList[count].xAdvance = ReadInt8(&info);
281
fileBuffer = ReadInt8(&info);
282
if (fileBuffer > 0x80) {
283
fontCharacterList[count].xAdvance += (fileBuffer - 0x80) << 8;
284
fontCharacterList[count].xAdvance += -0x8000;
285
}
286
else {
287
fontCharacterList[count].xAdvance += fileBuffer << 8;
288
}
289
290
// Unused
291
ReadInt8(&info);
292
ReadInt8(&info);
293
294
count++;
295
}
296
CloseFile(&info);
297
}
298
}
299
300
void RSDK::Legacy::v3::DrawBitmapText(void *menu, int32 XPos, int32 YPos, int32 scale, int32 spacing, int32 rowStart, int32 rowCount)
301
{
302
TextMenu *tMenu = (TextMenu *)menu;
303
int32 Y = YPos << 9;
304
if (rowCount < 0)
305
rowCount = tMenu->rowCount;
306
if (rowStart + rowCount > tMenu->rowCount)
307
rowCount = tMenu->rowCount - rowStart;
308
309
while (rowCount > 0) {
310
int32 X = XPos << 9;
311
for (int32 i = 0; i < tMenu->entrySize[rowStart]; ++i) {
312
uint16 c = tMenu->textData[tMenu->entryStart[rowStart] + i];
313
FontCharacter *fChar = &fontCharacterList[c];
314
DrawSpriteScaled(FLIP_NONE, X >> 9, Y >> 9, -fChar->pivotX, -fChar->pivotY, scale, scale, fChar->width, fChar->height, fChar->srcX,
315
fChar->srcY, textMenuSurfaceNo);
316
X += fChar->xAdvance * scale;
317
}
318
Y += spacing * scale;
319
rowStart++;
320
rowCount--;
321
}
322
}
323