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
|
#include <revolution/sc.h>
#include <revolution/os.h>
#include <cstring>
typedef struct {
s8 area;
char string[4];
} SCProductAreaAndString;
static SCProductAreaAndString ProductAreaAndStringTbl[] = {
0, "JPN",
1, "USA",
2, "EUR",
3, "AUS",
4, "BRA",
5, "TWN",
5, "ROC",
6, "KOR",
7, "HKG",
8, "ASI",
9, "LTN",
10, "SAF",
11, "CHN",
-1
};
BOOL __SCF1(const char* keyword, char* buf, u32 bufSize) {
BOOL result = FALSE;
u8* p = (u8*)OSPhysicalToCached(0x3800);
u32 size = 0x100, i, seed = 0x73b5dbfa, kwOffset = 0;
u8 data;
u32 bufOffset = 0;
for (i = 0; i < size; i++) {
data = p[i];
if (data != 0) {
data ^= seed;
if (keyword[kwOffset] == '\0') {
if (data == '=') {
result = TRUE;
break;
}
}
if (((keyword[kwOffset] ^ data) & 0xDF) == 0) {
kwOffset++;
}
else {
kwOffset = 0;
}
}
seed = (u32)((seed >> 31) | (seed << 1));
}
if (result) {
i++;
while (i < size && bufOffset < bufSize) {
seed = (u32)((seed >> 31) | (seed << 1));
data = p[i];
if (data != 0) {
data ^= seed;
if (data == '\x0d' || data == '\x0a') {
data = 0;
}
}
buf[bufOffset] = (char)data;
bufOffset++;
if (data == 0) {
return TRUE;
}
i++;
}
}
return FALSE;
}
BOOL SCGetProductAreaString(char* buf, u32 bufSize) {
return __SCF1("AREA", buf, bufSize);
}
s8 SCGetProductArea(void) {
char buf[4];
SCProductAreaAndString* p = ProductAreaAndStringTbl;
if (SCGetProductAreaString(buf, sizeof(buf))) {
while (p->area != -1) {
if (strcmp(p->string, buf) == 0) {
return p->area;
}
p++;
}
}
return -1;
}
typedef struct {
s8 game;
char string[3];
} SCProductGameRegionAndString;
static SCProductGameRegionAndString ProductGameRegionAndStringTbl[] = {
0, "JP",
1, "US",
2, "EU",
4, "KR",
5, "CN",
-1
};
s8 SCGetProductGameRegion(void) {
char buf[3];
SCProductGameRegionAndString* p = ProductGameRegionAndStringTbl;
if (__SCF1("GAME", buf, sizeof(buf))) {
while (p->game != -1) {
if (strcmp(p->string, buf) == 0) {
return p->game;
}
p++;
}
}
return -1;
}
|