Skip to content

Commit 5fe51b6

Browse files
committed
Load cheats from cheatData.bin
1 parent 2aeb4ba commit 5fe51b6

File tree

13 files changed

+27
-88
lines changed

13 files changed

+27
-88
lines changed

retail/arm9/include/configuration.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ typedef struct configuration {
3131
bool dldiPatchNds;
3232
int argc;
3333
const char** argv; //const char* argv[ARG_MAX];
34-
u32* cheat_data; //u32 cheat_data[CHEAT_DATA_MAX_LEN]
35-
u32 cheat_data_len;
3634
u32 backlightMode;
3735
} configuration;
3836

retail/arm9/include/nds_loader_arm9.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extern "C"
3131

3232
//#define LOAD_DEFAULT_NDS 0
3333

34-
void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 patchOffsetCacheCluster, u32 fatTableCluster, configuration* conf);
34+
void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 cheatCluster, u32 patchOffsetCacheCluster, u32 fatTableCluster, configuration* conf);
3535

3636
#ifdef __cplusplus
3737
}

retail/arm9/source/conf_sd.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,6 @@ static void load_conf(configuration* conf, const char* fn) {
138138
iniGetKey(IniData, IniCount, &Key);
139139
conf->logging = (bool)strtol(Key.Data, NULL, 0);
140140

141-
// Cheat data
142-
Key.Data = (char*)"";
143-
Key.Name = (char*)"CHEAT_DATA";
144-
iniGetKey(IniData, IniCount, &Key);
145-
conf->cheat_data = (u32*)malloc(CHEAT_DATA_MAX_SIZE);
146-
conf->cheat_data_len = 0;
147-
char* str = strdup(Key.Data);
148-
char* cheat = strtok(str, " ");
149-
if (cheat != NULL)
150-
printf("Cheat data present\n");
151-
while (cheat != NULL) {
152-
if (!checkCheatDataLen(conf->cheat_data_len)) {
153-
printf("Cheat data size limit reached, the cheats are ignored!\n");
154-
toncset(conf->cheat_data, 0, conf->cheat_data_len*sizeof(u32)); //cheats.clear();
155-
conf->cheat_data_len = 0;
156-
break;
157-
}
158-
printf(cheat);
159-
nocashMessage(cheat);
160-
printf(" ");
161-
162-
conf->cheat_data[conf->cheat_data_len] = strtoul(cheat, NULL, 16);
163-
164-
nocashMessage(tohex(conf->cheat_data[conf->cheat_data_len]));
165-
printf(" ");
166-
167-
++conf->cheat_data_len;
168-
169-
cheat = strtok(NULL, " ");
170-
}
171-
free(str);
172-
realloc(conf->cheat_data, conf->cheat_data_len*sizeof(u32));
173-
174141
// Backlight mode
175142
Key.Data = (char*)"";
176143
Key.Name = (char*)"BACKLIGHT_MODE";

retail/arm9/source/main.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ static inline void debugConf(configuration* conf) {
154154
//dbg_printf("dldiPatchNds: %s\n", btoa(conf->dldiPatchNds));
155155
//dbg_printf("argc: %lu\n", conf->argc);
156156
//const char** argv;
157-
//u32 cheat_data[CHEAT_DATA_MAX_LEN];
158-
dbg_printf("cheat_data_len: %lu\n", conf->cheat_data_len);
159157
dbg_printf("backlightMode: %lX\n", conf->backlightMode);
160158
}
161159

@@ -337,9 +335,11 @@ static int runNdsFile(configuration* conf) {
337335

338336
struct stat st;
339337
struct stat stSav;
338+
struct stat stCheat;
340339
struct stat stPatchOffsetCache;
341340
struct stat stFatTable;
342341
u32 clusterSav = 0;
342+
u32 clusterCheat = 0;
343343
u32 clusterPatchOffsetCache = 0;
344344
u32 clusterFatTable = 0;
345345
char filePath[PATH_MAX];
@@ -354,6 +354,12 @@ static int runNdsFile(configuration* conf) {
354354
clusterSav = stSav.st_ino;
355355
}
356356

357+
std::string cheatFilePath = "sd:/_nds/nds-bootstrap/cheatData.bin";
358+
359+
if (stat(cheatFilePath.c_str(), &stCheat) >= 0) {
360+
clusterCheat = stCheat.st_ino;
361+
}
362+
357363
std::string romFilename = ReplaceAll(conf->ndsPath, ".nds", ".bin");
358364
const size_t last_slash_idx = romFilename.find_last_of("/");
359365
if (std::string::npos != last_slash_idx)
@@ -398,7 +404,7 @@ static int runNdsFile(configuration* conf) {
398404
fread(load_bin, 1, loaderSize, bootloaderBin);
399405
fclose(bootloaderBin);
400406

401-
runNds(load_bin, loaderSize, st.st_ino, clusterSav, clusterPatchOffsetCache, clusterFatTable, conf);
407+
runNds(load_bin, loaderSize, st.st_ino, clusterSav, clusterCheat, clusterPatchOffsetCache, clusterFatTable, conf);
402408

403409
return 0;
404410
}
@@ -422,7 +428,6 @@ int main(int argc, char** argv) {
422428
free(conf->ndsPath);
423429
free(conf->savPath);
424430
free(conf->argv);
425-
free(conf->cheat_data);
426431
free(conf);
427432

428433
stop();

retail/arm9/source/nds_loader_arm9.c

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,7 @@ int loadArgs(int argc, const char** argv) {
181181
return true;
182182
}
183183

184-
int loadCheatData(u32* cheat_data, u32 cheat_data_len) {
185-
nocashMessage("loadCheatData");
186-
187-
cardengineArm7* ce7 = (cardengineArm7*)0x027E0000;
188-
nocashMessage("ce7");
189-
nocashMessage(tohex((u32)ce7));
190-
191-
u32* ce7_cheat_data = getCheatData(ce7);
192-
nocashMessage("ce7_cheat_data");
193-
nocashMessage(tohex((u32)ce7_cheat_data));
194-
195-
//tonccpy(ce7_cheat_data, cheat_data, 32768);
196-
tonccpy(ce7_cheat_data, cheat_data, cheat_data_len*sizeof(u32));
197-
198-
ce7->cheat_data_len = cheat_data_len;
199-
200-
return true;
201-
}
202-
203-
void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 patchOffsetCacheCluster, u32 fatTableCluster, configuration* conf) {
184+
void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u32 cheatCluster, u32 patchOffsetCacheCluster, u32 fatTableCluster, configuration* conf) {
204185
nocashMessage("runNds");
205186

206187
irqDisable(IRQ_ALL);
@@ -229,6 +210,7 @@ void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u3
229210
lc0->saveFileCluster = saveCluster;
230211
lc0->romSize = conf->romSize;
231212
lc0->saveSize = conf->saveSize;
213+
lc0->cheatFileCluster = cheatCluster;
232214
lc0->patchOffsetCacheFileCluster = patchOffsetCacheCluster;
233215
lc0->fatTableFileCluster = fatTableCluster;
234216
lc0->language = conf->language;
@@ -245,9 +227,6 @@ void runNds(const void* loader, u32 loaderSize, u32 cluster, u32 saveCluster, u3
245227
lc0->preciseVolumeControl = conf->preciseVolumeControl;
246228
lc0->logging = conf->logging;
247229

248-
loadCheatData(conf->cheat_data, conf->cheat_data_len);
249-
free(conf->cheat_data);
250-
251230
free(conf);
252231

253232
nocashMessage("irqDisable(IRQ_ALL);");

retail/bootloader/include/hook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ int hookNdsRetailArm7(
3434
const tNDSHeader* ndsHeader,
3535
const module_params_t* moduleParams,
3636
u32 fileCluster,
37+
u32 cheatFileCluster,
3738
u32 language,
3839
u32 dsiMode, // SDK5
3940
u32 ROMinRAM,

retail/bootloader/source/arm7/hook_arm7.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ int hookNdsRetailArm7(
9393
const tNDSHeader* ndsHeader,
9494
const module_params_t* moduleParams,
9595
u32 fileCluster,
96+
u32 cheatFileCluster,
9697
u32 language,
9798
u32 dsiMode, // SDK 5
9899
u32 ROMinRAM,
@@ -189,9 +190,6 @@ int hookNdsRetailArm7(
189190
ce7->gameSoftReset = gameSoftReset;
190191
ce7->preciseVolumeControl = preciseVolumeControl;
191192

192-
u32* ce7_cheat_data = getCheatData(ce7);
193-
endCheatData(ce7_cheat_data, &ce7->cheat_data_len);
194-
195193
*vblankHandler = ce7->patches->vblankHandler;
196194
if (!ROMinRAM) {
197195
*timer0Handler = ce7->patches->timer0Handler;
@@ -201,6 +199,11 @@ int hookNdsRetailArm7(
201199
*ipcSyncHandler = ce7->patches->fifoHandler;
202200
}
203201

202+
aFile cheatFile = getFileFromCluster(cheatFileCluster);
203+
if (cheatFile.firstCluster != CLUSTER_FREE) {
204+
fileRead(ce7->cheat_data_offset, cheatFile, 0, 0x8000, -1);
205+
}
206+
204207
dbg_printf("ERR_NONE\n");
205208
return ERR_NONE;
206209
}

retail/bootloader/source/arm7/load_crt0.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
.global saveFileCluster
3333
.global romSize
3434
.global saveSize
35+
.global cheatFileCluster
3536
.global patchOffsetCacheFileCluster
3637
.global fatTableFileCluster
3738
.global language
@@ -76,6 +77,8 @@ romSize:
7677
.word 0x00000000 @ .nds file size
7778
saveSize:
7879
.word 0x00000000 @ .sav file size
80+
cheatFileCluster:
81+
.word 0x00000000
7982
patchOffsetCacheFileCluster:
8083
.word 0x00000000
8184
fatTableFileCluster:

retail/bootloader/source/arm7/main.arm7.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern u32 initDisc;
8484
extern u32 saveFileCluster;
8585
extern u32 romSize;
8686
extern u32 saveSize;
87+
extern u32 cheatFileCluster;
8788
extern u32 patchOffsetCacheFileCluster;
8889
extern u32 fatTableFileCluster;
8990
extern u32 language;
@@ -845,6 +846,7 @@ int arm7_main(void) {
845846
ndsHeader,
846847
moduleParams,
847848
romFile->firstCluster,
849+
cheatFileCluster,
848850
language,
849851
dsiModeConfirmed,
850852
ROMinRAM,

retail/cardengine/arm7/source/card_engine_header.s

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ gameSoftReset:
6666
preciseVolumeControl:
6767
.word 0x00000000
6868
cheat_data_offset:
69-
.word cheat_data - patches_offset
70-
cheat_data_len:
71-
.word 0x00000000
69+
.word cheat_data
7270

7371
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
7472

retail/common/include/cardengine_header_arm7.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ typedef struct cardengineArm7 {
7676
u32 romread_LED;
7777
u32 gameSoftReset;
7878
u32 preciseVolumeControl;
79-
u32 cheat_data_offset; //u32* cheat_data;
80-
u32 cheat_data_len;
79+
u32* cheat_data_offset; //u32* cheat_data;
8180

8281
} __attribute__ ((__packed__)) cardengineArm7;
8382

84-
inline u32* getCheatData(const cardengineArm7* ce7) {
85-
return (u32*)((u32)ce7 + ce7->cheat_data_offset);
86-
}
87-
8883
#endif // CARDENGINE_HEADER_ARM7_H

retail/common/include/cheat_engine.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,4 @@
44
#define CHEAT_DATA_MAX_SIZE (32 * 1024) // 32KiB
55
#define CHEAT_DATA_MAX_LEN (CHEAT_DATA_MAX_SIZE / sizeof(u32))
66

7-
inline bool checkCheatDataLen(u32 cheat_data_len) {
8-
return (cheat_data_len + 2 <= CHEAT_DATA_MAX_LEN);
9-
}
10-
11-
inline void endCheatData(u32* cheat_data, u32* cheat_data_len_ptr) {
12-
if (*cheat_data_len_ptr + 2 > CHEAT_DATA_MAX_LEN) { // Not necessarily needed
13-
return;
14-
}
15-
cheat_data[*cheat_data_len_ptr] = 0xCF000000;
16-
cheat_data[*cheat_data_len_ptr + 1] = 0x00000000;
17-
*cheat_data_len_ptr += 2;
18-
}
19-
207
#endif // CHEAT_ENGINE_H

retail/common/include/load_crt0.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typedef struct loadCrt0 {
1717
u32 saveFileCluster;
1818
u32 romSize;
1919
u32 saveSize;
20+
u32 cheatFileCluster;
2021
u32 patchOffsetCacheFileCluster;
2122
u32 fatTableFileCluster;
2223
u32 language; //u8

0 commit comments

Comments
 (0)