Skip to content

Commit

Permalink
Fix SDK5 games crashing later on
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketRobz committed Dec 27, 2024
1 parent fba925c commit cc234a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 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 @@ -213,7 +213,7 @@ int hookNdsRetailArm9(
extern u32 dataToPreloadAddr;
extern u32 dataToPreloadSize;
// extern u32 dataToPreloadFrame;
extern bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool dsiBios, u32* romLocation);
extern bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool isSdk5, const bool dsiBios, u32* romLocation);
extern bool dataToPreloadFound(const tNDSHeader* ndsHeader);
const char* romTid = getRomTid(ndsHeader);
const bool laterSdk = ((moduleParams->sdk_version >= 0x2008000 && moduleParams->sdk_version != 0x2012774) || moduleParams->sdk_version == 0x20029A8);
Expand Down Expand Up @@ -340,7 +340,7 @@ int hookNdsRetailArm9(
configureRomMap(ce9, ndsHeader, dataToPreloadAddr, dsiMode);
for (u32 i = 0; i < dataToPreloadSize/*+dataToPreloadSize[1]*/; i += cacheBlockSize) {
ce9->cacheAddress += cacheBlockSize;
romLocationAdjust(ndsHeader, laterSdk, (ce9->valueBits & b_dsiBios), &ce9->cacheAddress);
romLocationAdjust(ndsHeader, laterSdk, (ce9->valueBits & b_dsiBios), (ce9->valueBits & b_isSdk5), &ce9->cacheAddress);
dataToPreloadSizeAligned += cacheBlockSize;
}
ce9->cacheSlots -= dataToPreloadSizeAligned/cacheBlockSize;
Expand Down Expand Up @@ -385,7 +385,7 @@ int hookNdsRetailArm9(
u32 addr = ce9->cacheAddress;

for (int slot = 0; slot < ce9->cacheSlots; slot++) {
romLocationAdjust(ndsHeader, laterSdk, (ce9->valueBits & b_dsiBios), &addr);
romLocationAdjust(ndsHeader, laterSdk, (ce9->valueBits & b_dsiBios), (ce9->valueBits & b_isSdk5), &addr);
cacheAddressTable[slot] = addr;
addr += cacheBlockSize;
}
Expand Down
6 changes: 3 additions & 3 deletions retail/bootloaderi/source/arm7/ips.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool applyIpsPatch(const tNDSHeader* ndsHeader, u8* ipsbyte, const bool arm9Only

bool armPatched = false;
const bool dsiBios = scfgBios9i();
extern bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool dsiBios, u32* romLocation);
extern bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool isSdk5, const bool dsiBios, u32* romLocation);

int ipson = 5;
int totalrepeats = 0;
Expand Down Expand Up @@ -77,7 +77,7 @@ bool applyIpsPatch(const tNDSHeader* ndsHeader, u8* ipsbyte, const bool arm9Only
rombyteOffset++;
if (ROMinRAM && (ndsHeader->unitCode == 0 || !dsiModeConfirmed)) {
u32 u32_rombyteOffset = (u32)rombyteOffset;
romLocationAdjust(ndsHeader, laterSdk, dsiBios, &u32_rombyteOffset);
romLocationAdjust(ndsHeader, laterSdk, isSdk5, dsiBios, &u32_rombyteOffset);
rombyteOffset = (u8*)u32_rombyteOffset;
}
}
Expand All @@ -92,7 +92,7 @@ bool applyIpsPatch(const tNDSHeader* ndsHeader, u8* ipsbyte, const bool arm9Only
rombyteOffset++;
if (ROMinRAM && (ndsHeader->unitCode == 0 || !dsiModeConfirmed)) {
u32 u32_rombyteOffset = (u32)rombyteOffset;
romLocationAdjust(ndsHeader, laterSdk, dsiBios, &u32_rombyteOffset);
romLocationAdjust(ndsHeader, laterSdk, isSdk5, dsiBios, &u32_rombyteOffset);
rombyteOffset = (u8*)u32_rombyteOffset;
}
}
Expand Down
6 changes: 3 additions & 3 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,12 @@ u32 getRomLocation(const tNDSHeader* ndsHeader, const bool isESdk2, const bool i
return getRomPartLocation(ndsHeader, isESdk2, isSdk5, dsiBios);
}

bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool dsiBios, u32* romLocation) {
bool romLocationAdjust(const tNDSHeader* ndsHeader, const bool laterSdk, const bool isSdk5, const bool dsiBios, u32* romLocation) {
const bool ntrType = (ndsHeader->unitCode == 0);
const u32 romLocationOld = *romLocation;
if (*romLocation == 0x0C3FC000) {
*romLocation += 0x4000;
} else if (*romLocation == 0x0C7C0000 && ((laterSdk && !dsiBios) || !laterSdk) && ntrType) {
} else if (*romLocation == 0x0C7C0000 && ((laterSdk && !dsiBios) || !laterSdk) && !isSdk5) {
*romLocation += laterSdk ? 0x8000 : 0x28000;
} else if (*romLocation == 0x0C7C4000) {
*romLocation += 0x4000;
Expand Down Expand Up @@ -1167,7 +1167,7 @@ static void buildRomMap(const tNDSHeader* ndsHeader, const module_params_t* modu
romLocationChangePrep += 0x4000;
romSizeEdit -= 0x4000;

readRom = (romSizeEdit <= 0) ? true : romLocationAdjust(ndsHeader, laterSdk, dsiBios, &romLocationChangePrep);
readRom = (romSizeEdit <= 0) ? true : romLocationAdjust(ndsHeader, laterSdk, isSdk5(moduleParams), dsiBios, &romLocationChangePrep);

// dbg_hexa(romLocationChangePrep);

Expand Down

0 comments on commit cc234a4

Please sign in to comment.