Skip to content

Commit 59741de

Browse files
committed
Fix not returning to hiyaCFW menu
1 parent ea2fd59 commit 59741de

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

retail/arm9/source/conf_sd.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,8 +1602,16 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
16021602
}
16031603
*(vu32*)0x03700000 = wordBak;
16041604
}
1605-
if (access("sd:/hiya.dsi", F_OK) == 0) {
1606-
conf->valueBits2 |= BIT(6);
1605+
if (isDSiMode() && conf->consoleModel < 2 && access("sd:/hiya.dsi", F_OK) == 0 && access("sd:/shared1/TWLCFG0.dat", F_OK) == 0 && access("sd:/sys/HWINFO_N.dat", F_OK) == 0 && REG_SCFG_EXT7 != 0) {
1606+
FILE* twlCfgFile = fopen("sd:/shared1/TWLCFG0.dat", "rb");
1607+
fseek(twlCfgFile, 0x88, SEEK_SET);
1608+
fread((void*)0x02000400, 1, 0x128, twlCfgFile);
1609+
fclose(twlCfgFile);
1610+
1611+
u32 srBackendId[2] = {*(u32*)0x02000428, *(u32*)0x0200042C};
1612+
if (srBackendId[0] != 0x53524C41 || srBackendId[1] != 0x00030004) {
1613+
conf->valueBits2 |= BIT(6);
1614+
}
16071615
}
16081616

16091617
if (!conf->isDSiWare || !scfgSdmmcEnabled) {
@@ -1619,7 +1627,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
16191627
(u8*)CARDENGINEI_ARM7_BUFFERED_LOCATION
16201628
);
16211629
if (rc == 0) {
1622-
if (REG_SCFG_EXT7 != 0) {
1630+
if (REG_SCFG_EXT7 != 0 && !(conf->valueBits2 & BIT(6))) {
16231631
tonccpy((u8*)LOADER_RETURN_SDK5_LOCATION, twlmenuResetGamePath, 256);
16241632
}
16251633
tonccpy((u8*)LOADER_RETURN_SDK5_LOCATION+0x100, &srBackendId, 8);
@@ -1645,7 +1653,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
16451653
(u8*)CARDENGINEI_ARM7_BUFFERED_LOCATION
16461654
);
16471655
if (rc == 0) {
1648-
if (REG_SCFG_EXT7 != 0) {
1656+
if (REG_SCFG_EXT7 != 0 && !(conf->valueBits2 & BIT(6))) {
16491657
tonccpy((u8*)LOADER_RETURN_LOCATION, twlmenuResetGamePath, 256);
16501658
}
16511659
tonccpy((u8*)LOADER_RETURN_LOCATION+0x100, &srBackendId, 8);
@@ -1712,7 +1720,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
17121720
(u8*)CARDENGINEI_ARM7_BUFFERED_LOCATION
17131721
);
17141722
if (rc == 0) {
1715-
if (REG_SCFG_EXT7 != 0) {
1723+
if (REG_SCFG_EXT7 != 0 && !(conf->valueBits2 & BIT(6))) {
17161724
tonccpy((u8*)LOADER_RETURN_DSIWARE_LOCATION, twlmenuResetGamePath, 256);
17171725
}
17181726
tonccpy((u8*)LOADER_RETURN_DSIWARE_LOCATION+0x100, &srBackendId, 8);

retail/cardenginei/arm7/source/cardengine.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ static void unlaunchSetFilename(bool boot) {
233233
}
234234

235235
static void unlaunchSetHiyaFilename(void) {
236-
if (!(valueBits & hiyaCfwFound)) return;
237-
238236
tonccpy((u8*)0x02000800, unlaunchAutoLoadID, 12);
239237
*(u16*)(0x0200080C) = 0x3F0; // Unlaunch Length for CRC16 (fixed, must be 3F0h)
240238
*(u16*)(0x0200080E) = 0; // Unlaunch CRC16 (empty)
@@ -483,7 +481,11 @@ void reset(const bool downloadedSrl) {
483481
*(u32*)0x02000000 = BIT(3);
484482
*(u32*)0x02000004 = 0x54455352; // 'RSET'
485483
if (consoleModel < 2) {
486-
(*(u32*)(ce7+0xB500) == 0 && (valueBits & b_dsiSD)) ? unlaunchSetFilename(false) : unlaunchSetHiyaFilename();
484+
if (valueBits & hiyaCfwFound) {
485+
unlaunchSetHiyaFilename();
486+
} else if (*(u32*)(ce7+0xB500) == 0 && (valueBits & b_dsiSD)) {
487+
unlaunchSetFilename(false);
488+
}
487489
}
488490
if (*(u32*)(ce7+0xB500) == 0 && (valueBits & b_dsiSD)) {
489491
tonccpy((u32*)0x02000300, sr_data_srloader, 0x20);
@@ -778,12 +780,16 @@ void forceGameReboot(void) {
778780
sharedAddr[4] = 0x57534352;
779781
IPC_SendSync(0x8);
780782
if (consoleModel < 2) {
781-
if (valueBits & b_dsiSD) {
783+
if (valueBits & hiyaCfwFound) {
784+
unlaunchSetHiyaFilename();
785+
} else if ((valueBits & b_dsiSD) &&
782786
#ifdef TWLSDK
783-
(*(u32*)(ce7+0x8500) == 0) ? unlaunchSetFilename(false) : unlaunchSetHiyaFilename();
787+
(*(u32*)(ce7+0x8500) == 0)
784788
#else
785-
(*(u32*)(ce7+0xB500) == 0) ? unlaunchSetFilename(false) : unlaunchSetHiyaFilename();
789+
(*(u32*)(ce7+0xB500) == 0)
786790
#endif
791+
) {
792+
unlaunchSetFilename(false);
787793
}
788794
waitFrames(5); // Wait for DSi screens to stabilize
789795
}
@@ -847,7 +853,9 @@ void returnToLoader(bool reboot) {
847853
}
848854
waitFrames(1);
849855
} else {
850-
if (*(u32*)(ce7+0x8500) == 0) {
856+
if (valueBits & hiyaCfwFound) {
857+
unlaunchSetHiyaFilename();
858+
} else if (*(u32*)(ce7+0x8500) == 0) {
851859
unlaunchSetFilename(true);
852860
} else {
853861
// Use different SR backend ID
@@ -958,8 +966,9 @@ void returnToLoader(bool reboot) {
958966
}
959967
waitFrames(1);
960968
} else {
961-
if (*(u32*)(ce7+0xB500) == 0 && (valueBits & b_dsiSD))
962-
{
969+
if (valueBits & hiyaCfwFound) {
970+
unlaunchSetHiyaFilename();
971+
} else if (*(u32*)(ce7+0xB500) == 0 && (valueBits & b_dsiSD)) {
963972
unlaunchSetFilename(true);
964973
} else {
965974
// Use different SR backend ID

retail/cardenginei/arm7_dsiware/source/cardengine.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ static void unlaunchSetFilename(bool boot) {
150150
}
151151

152152
static void unlaunchSetHiyaFilename(void) {
153-
if (!(valueBits & hiyaCfwFound)) return;
154-
155153
tonccpy((u8*)0x02000800, unlaunchAutoLoadID, 12);
156154
*(u16*)(0x0200080C) = 0x3F0; // Unlaunch Length for CRC16 (fixed, must be 3F0h)
157155
*(u16*)(0x0200080E) = 0; // Unlaunch CRC16 (empty)
@@ -426,7 +424,11 @@ void forceGameReboot(void) {
426424
sharedAddr[4] = 0x57534352;
427425
IPC_SendSync(0x8);
428426
if (consoleModel < 2) {
429-
(*(u32*)(ce7+0x8100) == 0) ? unlaunchSetFilename(false) : unlaunchSetHiyaFilename();
427+
if (valueBits & hiyaCfwFound) {
428+
unlaunchSetHiyaFilename();
429+
} else if (*(u32*)(ce7+0x8100) == 0) {
430+
unlaunchSetFilename(false);
431+
}
430432
waitFrames(5); // Wait for DSi screens to stabilize
431433
}
432434
u32 clearBuffer = 0;
@@ -475,7 +477,9 @@ void returnToLoader(bool reboot) {
475477
}
476478
//waitFrames(1);
477479
} else {
478-
if (*(u32*)(ce7+0x8100) == 0) {
480+
if (valueBits & hiyaCfwFound) {
481+
unlaunchSetHiyaFilename();
482+
} else if (*(u32*)(ce7+0x8100) == 0) {
479483
unlaunchSetFilename(true);
480484
} else {
481485
// Use different SR backend ID

0 commit comments

Comments
 (0)