Skip to content

Commit

Permalink
Fix #1768
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Jan 23, 2025
1 parent 54e97ca commit e642590
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions retail/bootloaderi/source/arm7/hook_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ int hookNdsRetailArm9(
extern u32 cheatSizeTotal;
const bool cheatsEnabled = (cheatSizeTotal > 4 && cheatSizeTotal <= 0x8000);
const bool specialTitle = (strncmp(romTid, "V2G", 3) == 0 || strncmp(romTid, "DD3", 3) == 0);
const bool pkmnTitle = (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0);
extern bool pkmnGen5;

ce9->cacheAddress = (consoleModel > 0 ? dev_CACHE_ADRESS_START_TWLSDK : (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_CHEAT : retail_CACHE_ADRESS_START_TWLSDK));
if (consoleModel == 0 && !gameOnFlashcard) {
if (pkmnTitle) {
if (pkmnGen5) {
ce9->cacheAddress = (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_LARGE_CHEAT : retail_CACHE_ADRESS_START_TWLSDK_LARGE);
} else if (specialTitle) {
ce9->cacheAddress = (cheatsEnabled ? retail_CACHE_ADRESS_START_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_START_TWLSDK_SMALL);
Expand All @@ -308,7 +308,7 @@ int hookNdsRetailArm9(
ce9->romLocation = ce9->cacheAddress;
ce9->cacheSlots = (consoleModel > 0 ? (cheatsEnabled ? dev_CACHE_ADRESS_SIZE_TWLSDK_CHEAT : dev_CACHE_ADRESS_SIZE_TWLSDK) : (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK))/cacheBlockSize;
if (consoleModel == 0 && !gameOnFlashcard) {
if (pkmnTitle) {
if (pkmnGen5) {
ce9->cacheSlots = (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK_LARGE)/cacheBlockSize;
} else if (specialTitle) {
ce9->cacheSlots = (cheatsEnabled ? retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL_CHEAT : retail_CACHE_ADRESS_SIZE_TWLSDK_SMALL)/cacheBlockSize;
Expand Down
9 changes: 7 additions & 2 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ u16 baseHeaderCRC = 0;
u32 baseChipID = 0;
u32 romPaddingSize = 0;
bool pkmnHeader = false;
bool pkmnGen5 = false;
bool ndmaDisabled = false;
bool sharedWramEnabled = false;

Expand Down Expand Up @@ -778,6 +779,8 @@ static void loadBinary_ARM7(const tDSiHeader* dsiHeaderTemp, aFile* file) {
tNDSHeader* ndsHeaderPokemon = (tNDSHeader*)NDS_HEADER_POKEMON;
fileRead((char*)ndsHeaderPokemon, file, 0, 0x160);
pkmnHeader = true;
} else {
pkmnGen5 = (strncmp(baseTid, "IRB", 3) == 0 || strncmp(baseTid, "IRA", 3) == 0 || strncmp(baseTid, "IRE", 3) == 0 || strncmp(baseTid, "IRD", 3) == 0);
}

fileRead((char*)&baseArm9Off, file, 0x20, sizeof(u32));
Expand Down Expand Up @@ -837,11 +840,13 @@ bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const b
const bool ntrType = (ndsHeader->unitCode == 0);
const u32 romLocationOld = *romLocation;
if (*romLocation == 0x0C3FC000) {
*romLocation += 0x4000;
*romLocation += pkmnGen5 ? 0x4020 : 0x4000;
} else if (*romLocation == 0x0C7C0000 && !laterSdk) {
*romLocation += 0x28000;
} else if (*romLocation == 0x0C7C4000) {
*romLocation += 0x4000;
} else if (*romLocation == 0x0C7C4020) {
*romLocation += 0x3FE0;
} else if (*romLocation == 0x0C7D8000 && laterSdk) {
if (ntrType) {
extern bool hasVramWifiBinary;
Expand Down Expand Up @@ -2226,7 +2231,7 @@ int arm7_main(void) {
if (ROMsupportsDsiMode(ndsHeader) && dsiModeConfirmed) {
cheatEngineOffset = (consoleModel > 0) ? CHEAT_ENGINE_TWLSDK_LOCATION_3DS : CHEAT_ENGINE_TWLSDK_SMALL_LOCATION;
if (consoleModel == 0 && !gameOnFlashcard) {
if (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0) {
if (pkmnGen5) {
cheatEngineOffset = CHEAT_ENGINE_TWLSDK_LARGE_LOCATION;
} else if (strncmp(romTid, "V2G", 3) != 0 && strncmp(romTid, "DD3", 3) != 0) {
cheatEngineOffset = CHEAT_ENGINE_TWLSDK_LOCATION;
Expand Down
3 changes: 2 additions & 1 deletion retail/bootloaderi/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ void patchHiHeapPointer(const module_params_t* moduleParams, const tNDSHeader* n
const bool ROMsupportsDsiMode = (ndsHeader->unitCode > 0 && dsiModeConfirmed);
const bool cheatsEnabled = (cheatSizeTotal > 4 && cheatSizeTotal <= 0x8000);
const char* romTid = getRomTid(ndsHeader);
extern bool pkmnGen5;

if (moduleParams->sdk_version < 0x2008000 || !dsiModeConfirmed || strncmp(romTid, "UBR", 3) == 0) {
return;
Expand Down Expand Up @@ -1423,7 +1424,7 @@ void patchHiHeapPointer(const module_params_t* moduleParams, const tNDSHeader* n
}
} else { */
// DSi mode title loaded on DSi from SD card, or DSi/3DS with external DSi BIOS files loaded
if (!gameOnFlashcard && (strncmp(romTid, "IRB", 3) == 0 || strncmp(romTid, "IRA", 3) == 0 || strncmp(romTid, "IRE", 3) == 0 || strncmp(romTid, "IRD", 3) == 0)) {
if (!gameOnFlashcard && pkmnGen5) {
// Pokemon Black & White 1&2
switch (*heapPointer) {
case 0x13A007BE:
Expand Down

0 comments on commit e642590

Please sign in to comment.