Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Rubberduckycooly
GitHub Repository: Rubberduckycooly/RSDKv5-Decompilation
Path: blob/master/RSDKv5/RSDK/Storage/Text.hpp
1163 views
1
#ifndef TEXT_H
2
#define TEXT_H
3
4
namespace RSDK
5
{
6
7
struct GameVersionInfo {
8
char gameTitle[0x40];
9
char gameSubtitle[0x100];
10
char version[0x10];
11
#if !RETRO_REV02
12
uint8 platform;
13
uint8 language;
14
uint8 region;
15
#endif
16
};
17
18
extern GameVersionInfo gameVerInfo;
19
20
struct String {
21
uint16 *chars; // text
22
uint16 length; // string length
23
uint16 size; // total alloc length
24
};
25
26
#if RETRO_REV0U
27
inline void StrCopy(char *dest, const char *src)
28
{
29
#ifdef USE_STDLIB
30
strcpy(dest, src);
31
#else
32
int32 i = 0;
33
for (; src[i]; ++i) dest[i] = src[i];
34
dest[i] = 0;
35
#endif
36
}
37
38
inline void StrAdd(char *dest, const char *src)
39
{
40
int32 destStrPos = 0;
41
int32 srcStrPos = 0;
42
while (dest[destStrPos]) ++destStrPos;
43
while (true) {
44
if (!src[srcStrPos]) {
45
break;
46
}
47
dest[destStrPos++] = src[srcStrPos++];
48
}
49
dest[destStrPos] = 0;
50
}
51
52
inline bool StrComp(const char *stringA, const char *stringB)
53
{
54
bool32 match = true;
55
bool32 finished = false;
56
while (!finished) {
57
if (*stringA == *stringB || *stringA == *stringB + ' ' || *stringA == *stringB - ' ') {
58
if (*stringA) {
59
++stringA;
60
++stringB;
61
}
62
else {
63
finished = true;
64
}
65
}
66
else {
67
match = false;
68
finished = true;
69
}
70
}
71
72
return match;
73
}
74
75
inline int32 StrLength(const char *string)
76
{
77
int32 len = 0;
78
for (len = 0; string[len]; len++)
79
;
80
return len;
81
}
82
83
int32 FindStringToken(const char *string, const char *token, uint8 stopID);
84
#endif
85
86
inline void StringLowerCase(char *dest, const char *src)
87
{
88
int32 destPos = 0;
89
int32 curChar = *src;
90
if (*src) {
91
int32 srcPos = 0;
92
do {
93
while ((uint32)curChar - 'A' < 26) {
94
destPos = srcPos;
95
dest[destPos] = curChar + ' ';
96
curChar = src[++srcPos];
97
if (!curChar) {
98
dest[++destPos] = 0;
99
return;
100
}
101
}
102
destPos = srcPos;
103
dest[destPos] = curChar;
104
curChar = src[++srcPos];
105
} while (curChar);
106
}
107
dest[++destPos] = 0;
108
}
109
110
inline void StringUpperCase(char *dest, const char *src)
111
{
112
int32 destPos = 0;
113
int32 curChar = *src;
114
if (*src) {
115
int32 srcPos = 0;
116
do {
117
while ((uint32)curChar - 'a' < 26) {
118
destPos = srcPos;
119
dest[destPos] = curChar - ' ';
120
curChar = src[++srcPos];
121
if (!curChar) {
122
dest[++destPos] = 0;
123
return;
124
}
125
}
126
destPos = srcPos;
127
dest[destPos] = curChar;
128
curChar = src[++srcPos];
129
} while (curChar);
130
}
131
dest[++destPos] = 0;
132
}
133
134
extern char textBuffer[0x400];
135
void GenerateHashMD5(uint32 *buffer, char *textBuffer, int32 textBufferLen);
136
void GenerateHashCRC(uint32 *id, char *inputString);
137
138
#define RETRO_HASH_MD5(name) uint32 name[4]
139
#define HASH_SIZE_MD5 (4 * sizeof(uint32))
140
#define HASH_MATCH_MD5(a, b) (memcmp(a, b, HASH_SIZE_MD5) == 0)
141
// this is NOT thread-safe!
142
#define GEN_HASH_MD5(text, hash) \
143
strcpy(textBuffer, text); \
144
GenerateHashMD5(hash, textBuffer, (int32)strlen(textBuffer))
145
// this one is but assumes buffer has already been setup
146
#define GEN_HASH_MD5_BUFFER(buffer, hash) GenerateHashMD5(hash, buffer, (int32)strlen(buffer))
147
#define HASH_COPY_MD5(dst, src) memcpy(dst, src, HASH_SIZE_MD5)
148
#define HASH_CLEAR_MD5(hash) MEM_ZERO(hash)
149
150
inline void InitString(String *string, const char *text, uint32 textLength)
151
{
152
string->length = 0;
153
string->size = 0;
154
155
if (text != NULL) {
156
string->length = 0;
157
while (text[string->length] != '\0') ++string->length;
158
159
if (textLength != 0 && textLength >= string->length)
160
string->size = textLength;
161
else
162
string->size = string->length;
163
164
if (string->size == 0)
165
string->size = 1;
166
167
AllocateStorage((void **)&string->chars, sizeof(uint16) * string->size, DATASET_STR, false);
168
169
for (uint32 pos = 0; text[pos] != '\0'; ++pos)
170
string->chars[pos] = text[pos];
171
}
172
}
173
174
void SetString(String *string, const char *text);
175
176
inline void CopyString(String *dst, String *src)
177
{
178
if (dst == src)
179
return;
180
181
int32 srcLength = src->length;
182
dst->chars = NULL;
183
if (dst->size >= srcLength) {
184
if (!dst->chars) {
185
AllocateStorage((void **)&dst->chars, sizeof(uint16) * dst->size, DATASET_STR, false);
186
}
187
}
188
else {
189
dst->size = srcLength;
190
AllocateStorage((void **)&dst->chars, sizeof(uint16) * dst->size, DATASET_STR, false);
191
}
192
193
dst->length = src->length;
194
for (int32 c = 0; c < dst->length; ++c) dst->chars[c] = src->chars[c];
195
}
196
197
inline void GetCString(char *destChars, String *string)
198
{
199
if (!string->chars)
200
return;
201
202
char *cString = destChars ? destChars : textBuffer;
203
int32 textLen = destChars ? string->length : 0x400;
204
205
int32 c = 0;
206
for (; c < textLen; ++c) cString[c] = (char)string->chars[c];
207
cString[c] = 0;
208
}
209
210
void AppendText(String *string, const char *appendText);
211
void AppendString(String *string, String *appendString);
212
bool32 CompareStrings(String *string1, String *string2, bool32 exactMatch);
213
214
void InitStringList(String *stringList, int32 size);
215
void LoadStringList(String *stringList, const char *filePath, uint32 charSize);
216
bool32 SplitStringList(String *splitStrings, String *stringList, int32 startStringID, int32 stringCount);
217
218
#if RETRO_REV0U
219
#include "Legacy/TextLegacy.hpp"
220
#endif
221
222
} // namespace RSDK
223
224
#endif
225
226