Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLP patch to read sav file #1663

Merged
merged 2 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions retail/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
export GAME_ICON := $(CURDIR)/$(ASSETS)/icon.bmp

#.PHONY: cardengine_arm7 cardengine_arm9 bootloader BootStrap clean
.PHONY: all dist release nightly bootloader bootloader2 bootloaderi bootloaderi2 cardengine_arm7 cardengine_arm9_igm cardengine_arm9_igm_extmem cardengine_arm9 cardengine_arm9_start cardengine_arm9_alt cardengine_arm9_alt2 cardengine_arm9_extmem cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 arm7/$(TARGET).elf arm9/$(TARGET).elf clean
.PHONY: all dist release nightly bootloader bootloader2 bootloaderi bootloaderi2 cardengine_arm7 cardengine_arm9_igm cardengine_arm9_igm_extmem cardengine_arm9 cardengine_arm9_start cardengine_arm9_alt cardengine_arm9_alt2 cardengine_arm9_extmem cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_dlp cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3 arm7/$(TARGET).elf arm9/$(TARGET).elf clean

all: $(OUTPUT)

Expand Down Expand Up @@ -169,7 +169,7 @@ bootloader2: $(DATA)
@$(MAKE) -C bootloader2

#---------------------------------------------------------------------------------
bootloaderi: $(DATA) cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3
bootloaderi: $(DATA) cardenginei_arm7 cardenginei_arm7_alt cardenginei_arm7_twlsdk cardenginei_arm7_twlsdk3 cardenginei_arm7_dsiware cardenginei_arm7_dsiware3 cardenginei_arm7_cheat cardenginei_arm9_igm cardenginei_arm9 cardenginei_arm9_alt cardenginei_arm9_alt2 cardenginei_arm9_dlp cardenginei_arm9_gsdd cardenginei_arm9_gsdd_alt cardenginei_arm9_dldi cardenginei_arm9_gsdd_dldi cardenginei_arm9_twlsdk cardenginei_arm9_twlsdk3 cardenginei_arm9_twlsdk_dldi cardenginei_arm9_twlsdk3_dldi cardenginei_arm9_dsiware cardenginei_arm9_dsiware3
@$(MAKE) -C bootloaderi

#---------------------------------------------------------------------------------
Expand Down Expand Up @@ -252,6 +252,10 @@ cardenginei_arm9_alt: $(DATA)
cardenginei_arm9_alt2: $(DATA)
@$(MAKE) -C cardenginei/arm9_alt2

#---------------------------------------------------------------------------------
cardenginei_arm9_dlp: $(DATA)
@$(MAKE) -C cardenginei/arm9_dlp

#---------------------------------------------------------------------------------
cardenginei_arm9_gsdd: $(DATA)
@$(MAKE) -C cardenginei/arm9_gsdd
Expand Down Expand Up @@ -323,6 +327,7 @@ clean:
@$(MAKE) -C cardenginei/arm9 clean
@$(MAKE) -C cardenginei/arm9_alt clean
@$(MAKE) -C cardenginei/arm9_alt2 clean
@$(MAKE) -C cardenginei/arm9_dlp clean
@$(MAKE) -C cardenginei/arm9_gsdd clean
@$(MAKE) -C cardenginei/arm9_gsdd_alt clean
@$(MAKE) -C cardenginei/arm9_dldi clean
Expand Down
10 changes: 7 additions & 3 deletions retail/arm9/source/conf_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,8 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
conf->dsiWramAccess = true;
}
if (conf->dsiWramAccess) {
if (strncmp(romTid, "ADA", 3) == 0 // Diamond
if (strncmp(romTid, "HND", 3) == 0 // DS Download Play
|| strncmp(romTid, "ADA", 3) == 0 // Diamond
|| strncmp(romTid, "APA", 3) == 0 // Pearl
|| strncmp(romTid, "Y3E", 3) == 0 // 2006-Nen 10-Gatsu Taikenban Soft
|| strncmp(romTid, "CPU", 3) == 0 // Platinum
Expand Down Expand Up @@ -1235,6 +1236,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
}
fclose(cebin);

const bool dlp = (memcmp(romTid, "HND", 3) == 0);
const bool gsdd = (memcmp(romTid, "BO5", 3) == 0);

if (conf->gameOnFlashcard) {
Expand All @@ -1252,7 +1254,9 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
fclose(cebin);
} else {
const char* ce9Path = conf->dsiWramAccess ? "nitro:/cardenginei_arm9.lz77" : "nitro:/cardenginei_arm9_alt.lz77";
if (gsdd) {
if (dlp) {
ce9Path = "nitro:/cardenginei_arm9_dlp.lz77";
} else if (gsdd) {
ce9Path = conf->dsiWramAccess ? "nitro:/cardenginei_arm9_gsdd.lz77" : "nitro:/cardenginei_arm9_gsdd_alt.lz77";
}

Expand All @@ -1264,7 +1268,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
}
fclose(cebin);

if (!conf->dsiWramAccess && !gsdd) {
if (!conf->dsiWramAccess && !dlp && !gsdd) {
// Load ce9 binary (alt 2)
cebin = fopen("nitro:/cardenginei_arm9_alt2.lz77", "rb");
if (cebin) {
Expand Down
8 changes: 4 additions & 4 deletions retail/bootloaderi/source/arm7/find_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu

if (moduleParams->sdk_version > 0x5000000) {
return findCardEndReadDmaSdk5(ndsHeader,moduleParams,usesThumb);
}
}

const u32* offsetDmaHandler = NULL;
if (moduleParams->sdk_version < 0x4000000) {
Expand Down Expand Up @@ -2736,11 +2736,11 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu

u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb) {
dbg_printf("findCardSetDma\n");

if (moduleParams->sdk_version > 0x5000000) {
return findCardSetDmaSdk5(ndsHeader,moduleParams,usesThumb);
}
}

//const u16* cardSetDmaSignatureStartThumb = cardSetDmaSignatureStartThumb4;
const u32* cardSetDmaSignatureStart = cardSetDmaSignatureStart4;
int cardSetDmaSignatureStartLen = 3;
Expand Down
4 changes: 4 additions & 0 deletions retail/bootloaderi/source/arm7/hook_arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define b_dsiBios BIT(18)
#define b_bootstrapOnFlashcard BIT(19)
#define b_ndmaDisabled BIT(20)
#define b_isDlp BIT(21)
#define b_scfgLocked BIT(31)

extern u32 newArm7binarySize;
Expand Down Expand Up @@ -399,6 +400,9 @@ int hookNdsRetailArm7(
if (ndmaDisabled) {
ce7->valueBits |= b_ndmaDisabled;
}
if (strncmp(romTid, "HND", 3) == 0) {
ce7->valueBits |= b_isDlp;
}
if (REG_SCFG_EXT == 0) {
ce7->valueBits |= b_scfgLocked;
}
Expand Down
4 changes: 4 additions & 0 deletions retail/bootloaderi/source/arm7/hook_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define b_asyncCardRead BIT(12)
#define b_softResetMb BIT(13)
#define b_cloneboot BIT(14)
#define b_isDlp BIT(15)


static const int MAX_HANDLER_LEN = 50;
Expand Down Expand Up @@ -329,6 +330,9 @@ int hookNdsRetailArm9(
if (usesCloneboot) {
ce9->valueBits |= b_cloneboot;
}
if (strncmp(romTid, "HND", 3) == 0) {
ce9->valueBits |= b_isDlp;
}
ce9->mainScreen = mainScreen;
ce9->overlaysSize = overlaysSize;
ce9->romPaddingSize = romPaddingSize;
Expand Down
6 changes: 6 additions & 0 deletions retail/bootloaderi/source/arm7/main.arm7.c
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,9 @@ int arm7_main(void) {
extern u32 clusterCache;

u32 add = (moduleParams->sdk_version >= 0x2008000 || moduleParams->sdk_version == 0x20029A8) ? 0xC8000 : 0xE8000; // 0x027C8000 : 0x027E8000
if (memcmp(romTid, "HND", 3) == 0) {
add = 0x108000; // 0x02808000
}
tonccpy((char*)0x02700000+add, (char*)0x02700000, 0x10000); // Move FAT table cache elsewhere
romFile->fatTableCache = (u32*)((u32)romFile->fatTableCache+add);
savFile->fatTableCache = (u32*)((u32)savFile->fatTableCache+add);
Expand Down Expand Up @@ -2011,6 +2014,9 @@ int arm7_main(void) {
} else {
const bool laterSdk = (moduleParams->sdk_version >= 0x2008000 || moduleParams->sdk_version == 0x20029A8);
ce9Location = dsiWramAccess ? CARDENGINEI_ARM9_LOCATION_DSI_WRAM : (!laterSdk ? CARDENGINEI_ARM9_LOCATION2 : CARDENGINEI_ARM9_LOCATION);
if (memcmp(romTid, "HND", 3) == 0) {
ce9Location = CARDENGINEI_ARM9_LOCATION_DLP;
}
ce9size = 0x5000;
tonccpy((u32*)ce9Location, (u32*)((!dsiWramAccess && !laterSdk) ? CARDENGINEI_ARM9_BUFFERED_LOCATION2 : CARDENGINEI_ARM9_BUFFERED_LOCATION), ce9size);
}
Expand Down
4 changes: 2 additions & 2 deletions retail/bootloaderi/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -2518,9 +2518,9 @@ u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const mod
if (strncmp(romTid, "UOR", 3) == 0) { // Start at 0x2003800 for "WarioWare: DIY"
startOffset = (u32)ndsHeader->arm9destination + 0x3800;
} else if (strncmp(romTid, "UXB", 3) == 0) { // Start at 0x2080000 for "Jam with the Band"
startOffset = (u32)ndsHeader->arm9destination + 0x80000;
startOffset = (u32)ndsHeader->arm9destination + 0x80000;
} else if (strncmp(romTid, "USK", 3) == 0) { // Start at 0x20E8000 for "Face Training"
startOffset = (u32)ndsHeader->arm9destination + 0xE4000;
startOffset = (u32)ndsHeader->arm9destination + 0xE4000;
}

dbg_printf("startOffset : ");
Expand Down
22 changes: 22 additions & 0 deletions retail/cardenginei/arm7/include/patcher/find.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,54 @@
// COMMON
//u8* memsearch(const u8* start, u32 dataSize, const u8* find, u32 findSize);
u32* memsearch32(const u32* start, u32 dataSize, const u32* find, u32 findSize, bool forward);
u32* memsearch32_2(const u32* start, u32 dataSize, const u32* find, const u32* find2, u32 findSize, bool forward);
u32* memsearch32_3(const u32* start, u32 dataSize, const u32* find, const u32* find2, const u32* find3, u32 findSize, bool forward);
u16* memsearch16(const u16* start, u32 dataSize, const u16* find, u32 findSize, bool forward);
u16* memsearch16_4(const u16* start, u32 dataSize, const u16* find, const u16* find2, const u16* find3, const u16* find4, u32 findSize, bool forward);

inline u32* findOffset(const u32* start, u32 dataSize, const u32* find, u32 findLen) {
return memsearch32(start, dataSize, find, findLen*sizeof(u32), true);
}
inline u32* findOffsetBackwards(const u32* start, u32 dataSize, const u32* find, u32 findLen) {
return memsearch32(start, dataSize, find, findLen*sizeof(u32), false);
}
inline u32* findOffsetBackwards2(const u32* start, u32 dataSize, const u32* find, const u32* find2, u32 findLen) {
return memsearch32_2(start, dataSize, find, find2, findLen*sizeof(u32), false);
}
inline u32* findOffsetBackwards3(const u32* start, u32 dataSize, const u32* find, const u32* find2, const u32* find3, u32 findLen) {
return memsearch32_3(start, dataSize, find, find2, find3, findLen*sizeof(u32), false);
}
inline u16* findOffsetThumb(const u16* start, u32 dataSize, const u16* find, u32 findLen) {
return memsearch16(start, dataSize, find, findLen*sizeof(u16), true);
}
inline u16* findOffsetBackwardsThumb(const u16* start, u32 dataSize, const u16* find, u32 findLen) {
return memsearch16(start, dataSize, find, findLen*sizeof(u16), false);
}
inline u16* findOffsetBackwardsThumb4(const u16* start, u32 dataSize, const u16* find, const u16* find2, const u16* find3, const u16* find4, u32 findLen) {
return memsearch16_4(start, dataSize, find, find2, find3, find4, findLen*sizeof(u16), false);
}

// ARM9
u32* a9_findSwi12Offset(const tNDSHeader* ndsHeader);
u32* findModuleParamsOffset(const tNDSHeader* ndsHeader);
u32* findCardReadEndOffsetType0(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 startOffset);
u32* findCardReadEndOffsetType1(const tNDSHeader* ndsHeader, u32 startOffset);
u16* findCardReadEndOffsetThumb(const tNDSHeader* ndsHeader, u32 startOffset);
u16* findCardReadEndOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 startOffset); // SDK 5
u16* findCardReadEndOffsetThumb5Type1(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, u32 startOffset); // SDK 5
u32* findCardReadStartOffsetType0(const module_params_t* moduleParams, const u32* cardReadEndOffset);
u32* findCardReadStartOffsetType1(const u32* cardReadEndOffset);
u32* findCardReadStartOffset5(const module_params_t* moduleParams, const u32* cardReadEndOffset); // SDK 5
u32* findCardReadCheckOffsetMvDK4(u32 startOffset);
u16* findCardReadStartOffsetThumb(const u16* cardReadEndOffset);
u16* findCardReadStartOffsetThumb5Type0(const module_params_t* moduleParams, const u16* cardReadEndOffset); // SDK 5
u16* findCardReadStartOffsetThumb5Type1(const module_params_t* moduleParams, const u16* cardReadEndOffset); // SDK 5
u32* findCardReadCachedEndOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams);
u32* findCardReadCachedStartOffset(const module_params_t* moduleParams, const u32* cardReadCachedEndOffset);
u32* findCardPullOutOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams);
u16* findCardPullOutOffsetThumb(const tNDSHeader* ndsHeader);
u16* findCardPullOutOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); // SDK 5
u16* findCardPullOutOffsetThumb5Type1(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); // SDK 5
u32* findCardIdEndOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const u32* cardReadEndOffset);
u16* findCardIdEndOffsetThumb(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const u16* cardReadEndOffset);
u32* findCardIdStartOffset(const module_params_t* moduleParams, const u32* cardIdEndOffset);
Expand All @@ -52,9 +72,11 @@ const u32* getMpuInitRegionSignature(u32 patchMpuRegion);
u32* findMpuStartOffset(const tNDSHeader* ndsHeader, u32 patchMpuRegion);
u32* findMpuDataOffset(const module_params_t* moduleParams, u32 patchMpuRegion, const u32* mpuStartOffset);
u32* findMpuDataOffsetAlt(const tNDSHeader* ndsHeader);
u32* findMpuChange(const tNDSHeader* ndsHeader);
u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader);
u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader);
u32* findRandomPatchOffset(const tNDSHeader* ndsHeader);
u32* findRandomPatchOffset5Second(const tNDSHeader* ndsHeader); // SDK 5
u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, bool* usesThumbPtr);
u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, const u32* cardReadDmaEndOffset, u32* offsetDmaHandler);
u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb);
Expand Down
Loading