You've already forked pico-loader
mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-01-09 16:28:35 -08:00
Added support for nand saving in Face Training and Nintendo DS Guide (fixes #6), calculate nand save size from header, fixed Band Brothers save initialization
This commit is contained in:
@@ -13,7 +13,9 @@
|
||||
#include "patches/arm9/OSResetSystemPatch.h"
|
||||
#include "patches/arm9/PokemonDownloaderArm9Patch.h"
|
||||
#include "patches/arm9/DSProtectArm9Patch.h"
|
||||
#include "patches/arm9/NandSave/FaceTrainingNandSavePatch.h"
|
||||
#include "patches/arm9/NandSave/JamWithTheBandNandSavePatch.h"
|
||||
#include "patches/arm9/NandSave/NintendoDSGuideNandSavePatch.h"
|
||||
#include "patches/arm9/NandSave/WarioWareDiyNandSavePatch.h"
|
||||
#include "patches/arm9/OverlayPatches/FsStartOverlayHookPatch.h"
|
||||
#include "patches/arm9/OverlayPatches/DSProtectPatches/DSProtectOverlayPatch.h"
|
||||
@@ -390,6 +392,18 @@ void Arm9Patcher::AddGameSpecificPatches(
|
||||
patchCollection.AddPatch(new JamWithTheBandNandSavePatch());
|
||||
break;
|
||||
}
|
||||
// Face Training
|
||||
case GAMECODE("USKV"):
|
||||
{
|
||||
patchCollection.AddPatch(new FaceTrainingNandSavePatch());
|
||||
break;
|
||||
}
|
||||
// Nintendo DS Guide
|
||||
case GAMECODE("UGDA"):
|
||||
{
|
||||
patchCollection.AddPatch(new NintendoDSGuideNandSavePatch());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "common.h"
|
||||
#include "gameCode.h"
|
||||
#include "patches/platform/LoaderPlatform.h"
|
||||
#include "patches/SaveOffsetToSdSectorAsm.h"
|
||||
#include "ReadNandSaveAsm.h"
|
||||
#include "WriteNandSaveAsm.h"
|
||||
#include "FaceTrainingNandSavePatch.h"
|
||||
|
||||
// This code was based on nds-bootstrap:
|
||||
// https://github.com/DS-Homebrew/nds-bootstrap/blob/89f27d1392a68436695d0050992ee84258ef41bc/retail/bootloader/source/arm7/patch_arm9.c#L2531
|
||||
|
||||
bool FaceTrainingNandSavePatch::FindPatchTarget(PatchContext& patchContext)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void FaceTrainingNandSavePatch::ApplyPatch(PatchContext& patchContext)
|
||||
{
|
||||
auto sectorRemapPatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<SaveOffsetToSdSectorPatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
SHARED_SAVE_FILE_INFO
|
||||
);
|
||||
auto loaderPlatform = patchContext.GetLoaderPlatform();
|
||||
auto readNandSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<ReadNandSavePatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
loaderPlatform->CreateSdReadPatchCode(patchContext.GetPatchCodeCollection(), patchContext.GetPatchHeap())
|
||||
);
|
||||
auto writeNandSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<WriteNandSavePatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
loaderPlatform->CreateSdWritePatchCode(patchContext.GetPatchCodeCollection(), patchContext.GetPatchHeap())
|
||||
);
|
||||
|
||||
// u32 nandInit(void* data)
|
||||
*(u32*)0x020E2AEC = 0xE3A00001; // mov r0, #1
|
||||
*(u32*)0x020E2AF0 = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandResume(void)
|
||||
*(u32*)0x020E2EC0 = 0xE3A00000; // mov r0, #0
|
||||
*(u32*)0x020E2EC4 = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandError(void)
|
||||
*(u32*)0x020E3150 = 0xE3A00000; // mov r0, #0
|
||||
*(u32*)0x020E3154 = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandWrite(const void* memory, u32 flash, u32 size, u32 dmaChannel)
|
||||
*(u32*)0x020E2BF0 = 0xE51FF004; // ldr pc,= patch_writeNandSave
|
||||
*(u32*)0x020E2BF4 = (u32)writeNandSavePatchCode->GetWriteNandSaveFunction();
|
||||
|
||||
// u32 nandRead(void* memory, u32 flash, u32 size, u32 dmaChannel)
|
||||
*(u32*)0x020E2F3C = 0xE51FF004; // ldr pc,= patch_readNandSave
|
||||
*(u32*)0x020E2F40 = (u32)readNandSavePatchCode->GetReadNandSaveFunction();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "patches/Patch.h"
|
||||
|
||||
class FunctionSignature;
|
||||
|
||||
/// @brief Arm9 patch to redirect Face Training nand saving to the SD card.
|
||||
class FaceTrainingNandSavePatch : public Patch
|
||||
{
|
||||
public:
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "common.h"
|
||||
#include "gameCode.h"
|
||||
#include "patches/platform/LoaderPlatform.h"
|
||||
#include "patches/SaveOffsetToSdSectorAsm.h"
|
||||
#include "ReadNandSaveAsm.h"
|
||||
#include "WriteNandSaveAsm.h"
|
||||
#include "NintendoDSGuideNandSavePatch.h"
|
||||
|
||||
// This code was based on nds-bootstrap:
|
||||
// https://github.com/DS-Homebrew/nds-bootstrap/blob/89f27d1392a68436695d0050992ee84258ef41bc/retail/bootloader/source/arm7/patch_arm9.c#L2531
|
||||
|
||||
bool NintendoDSGuideNandSavePatch::FindPatchTarget(PatchContext& patchContext)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void NintendoDSGuideNandSavePatch::ApplyPatch(PatchContext& patchContext)
|
||||
{
|
||||
auto sectorRemapPatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<SaveOffsetToSdSectorPatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
SHARED_SAVE_FILE_INFO
|
||||
);
|
||||
auto loaderPlatform = patchContext.GetLoaderPlatform();
|
||||
auto readNandSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<ReadNandSavePatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
loaderPlatform->CreateSdReadPatchCode(patchContext.GetPatchCodeCollection(), patchContext.GetPatchHeap())
|
||||
);
|
||||
auto writeNandSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<WriteNandSavePatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
loaderPlatform->CreateSdWritePatchCode(patchContext.GetPatchCodeCollection(), patchContext.GetPatchHeap())
|
||||
);
|
||||
|
||||
// u32 nandInit(void* data)
|
||||
*(u32*)0x02009298 = 0xE3A00001; // mov r0, #1
|
||||
*(u32*)0x0200929C = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandResume(void)
|
||||
*(u32*)0x020098C8 = 0xE3A00000; // mov r0, #0
|
||||
*(u32*)0x020098CC = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandState(void)
|
||||
*(u32*)0x02009AA8 = 0xE1A00000; //nop
|
||||
*(u32*)0x02009AB0 = 0x06600000;
|
||||
|
||||
// u32 nandError(void)
|
||||
*(u32*)0x02009AB4 = 0xE3A00000; // mov r0, #0
|
||||
*(u32*)0x02009AB8 = 0xE12FFF1E; // bx lr
|
||||
|
||||
// u32 nandWrite(const void* memory, u32 flash, u32 size, u32 dmaChannel)
|
||||
*(u32*)0x0200961C = 0xE51FF004; // ldr pc,= patch_writeNandSave
|
||||
*(u32*)0x02009620 = (u32)writeNandSavePatchCode->GetWriteNandSaveFunction();
|
||||
|
||||
// u32 nandRead(void* memory, u32 flash, u32 size, u32 dmaChannel)
|
||||
*(u32*)0x02009940 = 0xE51FF004; // ldr pc,= patch_readNandSave
|
||||
*(u32*)0x02009944 = (u32)readNandSavePatchCode->GetReadNandSaveFunction();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "patches/Patch.h"
|
||||
|
||||
class FunctionSignature;
|
||||
|
||||
/// @brief Arm9 patch to redirect Nintendo DS Guide nand saving to the SD card.
|
||||
class NintendoDSGuideNandSavePatch : public Patch
|
||||
{
|
||||
public:
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
};
|
||||
Reference in New Issue
Block a user