mirror of
https://github.com/LNH-team/pico-loader.git
synced 2026-06-02 09:16:49 +02:00
Preserve cheats when OS_ResetSystem is used, move temporary save buffer to main memory
This commit is contained in:
@@ -5,16 +5,14 @@
|
||||
class CheatEnginePatch : public Patch
|
||||
{
|
||||
public:
|
||||
explicit CheatEnginePatch(const void* cheats)
|
||||
: _cheats(cheats) { }
|
||||
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
|
||||
void SetCheats(const void* cheats)
|
||||
{
|
||||
_cheats = cheats;
|
||||
}
|
||||
|
||||
private:
|
||||
const void* _cheats = nullptr;
|
||||
const void* _cheats;
|
||||
u32* _vblankIrqHandler = nullptr;
|
||||
const u32* _foundPattern = nullptr;
|
||||
};
|
||||
|
||||
@@ -103,13 +103,12 @@ void CardiTaskThreadPatch::ApplyPatch(PatchContext& patchContext)
|
||||
patchContext.GetPatchHeap(),
|
||||
(const save_file_info_t*)((u32)SHARED_SAVE_FILE_INFO - 0x02F00000 + 0x02700000)
|
||||
);
|
||||
void* tmpBuffer = patchContext.GetPatchHeap().Alloc(512);
|
||||
auto readSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<ReadSavePatchCode>
|
||||
(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
auto writeSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<WriteSavePatchCode>
|
||||
(
|
||||
@@ -117,13 +116,13 @@ void CardiTaskThreadPatch::ApplyPatch(PatchContext& patchContext)
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
writePatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
auto verifySavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<VerifySavePatchCode>(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
|
||||
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
||||
|
||||
@@ -22,11 +22,15 @@ public:
|
||||
ThumbF
|
||||
};
|
||||
|
||||
explicit CardiTaskThreadPatch(void* saveTmpBuffer)
|
||||
: _saveTmpBuffer(saveTmpBuffer) { }
|
||||
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
|
||||
private:
|
||||
u32* _cardiTaskThread = nullptr;
|
||||
void* _saveTmpBuffer;
|
||||
PatchVariant _patchVariant = PatchVariant::None;
|
||||
|
||||
void ApplyArmPatch(void* patch1Address) const;
|
||||
|
||||
@@ -68,25 +68,24 @@ void CardiDoTaskFromArm9Patch::ApplyPatch(PatchContext& patchContext)
|
||||
patchContext.GetPatchCodeCollection(), patchContext.GetPatchHeap());
|
||||
auto sectorRemapPatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<SaveOffsetToSdSectorPatchCode>(
|
||||
patchContext.GetPatchHeap(), SHARED_SAVE_FILE_INFO);
|
||||
void* tmpBuffer = patchContext.GetPatchHeap().Alloc(512);
|
||||
auto readSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<ReadSavePatchCode>(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
auto writeSavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<WriteSavePatchCode>(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
writePatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
auto verifySavePatchCode = patchContext.GetPatchCodeCollection().AddUniquePatchCode<VerifySavePatchCode>(
|
||||
patchContext.GetPatchHeap(),
|
||||
sectorRemapPatchCode,
|
||||
readPatchCode,
|
||||
tmpBuffer
|
||||
_saveTmpBuffer
|
||||
);
|
||||
|
||||
__patch_carditaskthread_readsave_asm_address = (u32)readSavePatchCode->GetReadSaveFunction();
|
||||
|
||||
@@ -5,12 +5,16 @@
|
||||
class CardiDoTaskFromArm9Patch : public Patch
|
||||
{
|
||||
public:
|
||||
explicit CardiDoTaskFromArm9Patch(void* saveTmpBuffer)
|
||||
: _saveTmpBuffer(saveTmpBuffer) { }
|
||||
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
|
||||
private:
|
||||
u32* _cardiDoTaskFromArm9 = nullptr;
|
||||
const u32* _foundPattern = nullptr;
|
||||
void* _saveTmpBuffer;
|
||||
u16 _thumb = false;
|
||||
|
||||
void TryPattern(PatchContext& patchContext, const u32* pattern);
|
||||
|
||||
@@ -126,5 +126,7 @@ void OSResetSystemPatch::ApplyPatch(PatchContext& patchContext)
|
||||
|
||||
*(u32*)((u8*)_osResetSystem + offset) = 0xE51FF004;
|
||||
*(u32*)((u8*)_osResetSystem + offset + 4) = (u32)patchCode->GetOSResetSystemFunction();
|
||||
|
||||
_cheatsPointer = patchCodePart2->GetCheatsPointerAtTarget();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,14 @@ public:
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
|
||||
void** GetCheatsPointerAtTarget() const
|
||||
{
|
||||
return _cheatsPointer;
|
||||
}
|
||||
|
||||
private:
|
||||
u32* _osResetSystem = nullptr;
|
||||
u32 _hybrid = false;
|
||||
const loader_info_t* _loaderInfo;
|
||||
void** _cheatsPointer = nullptr;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@ extern u32 patch_osresetsystem_readSdSectors_address;
|
||||
extern u32 patch_osresetsystem_bootPicoLoader_address;
|
||||
extern u16 patch_osresetsystem_entry_jump_to_twl_arm7_sync;
|
||||
extern u32 patch_osresetsystem_arm7Entry_address;
|
||||
extern u32 patch_osresetsystem_cheats_address;
|
||||
|
||||
class OSResetSystemPart2PatchCode : public PatchCode
|
||||
{
|
||||
@@ -28,6 +29,11 @@ public:
|
||||
{
|
||||
return GetAddressAtTarget((void*)patch_osresetsystem_bootPicoLoader);
|
||||
}
|
||||
|
||||
void** GetCheatsPointerAtTarget() const
|
||||
{
|
||||
return (void**)GetAddressAtTarget(&patch_osresetsystem_cheats_address);
|
||||
}
|
||||
};
|
||||
|
||||
class OSResetSystemPatchCode : public PatchCode
|
||||
|
||||
@@ -108,16 +108,24 @@ patch_osresetsystem_bootPicoLoader:
|
||||
ldmia r5, {r3, r5}
|
||||
ldrh r0, [r3, #2] // loader_info_t::picoLoaderBootDrive
|
||||
strh r0, [r5, #8] // pload_header7_t::bootDrive
|
||||
ldr r0, [r5] // pload_header7_t::entryPoint
|
||||
|
||||
adr r0, regVramCntA
|
||||
ldmia r0, {r0, r4, r6, r7}
|
||||
// r0 = regVramCntA
|
||||
// r4 = patch_osresetsystem_arm7Entry_address
|
||||
// r6 = vramCDSettings
|
||||
// r7 = patch_osresetsystem_cheats_address
|
||||
|
||||
movs r2, #0x41
|
||||
lsls r2, r2, #4 // 0x410
|
||||
str r7, [r5, r2] // pload_header7_t::v3.cheats
|
||||
ldr r1, [r5] // pload_header7_t::entryPoint
|
||||
|
||||
// set NTR_SHARED_MEMORY->romHeader.arm7EntryAddress
|
||||
ldr r4, patch_osresetsystem_arm7Entry_address
|
||||
str r0, [r4]
|
||||
str r1, [r4]
|
||||
|
||||
// map vram CD to arm7
|
||||
ldr r0,= 0x04000240
|
||||
ldr r7,= 0x8A82
|
||||
strh r7, [r0, #2]
|
||||
strh r6, [r0, #2]
|
||||
|
||||
adds r0, #(0x04000180 - 0x04000240) // REG_IPC_SYNC
|
||||
movs r1, #1
|
||||
@@ -139,21 +147,17 @@ twl_arm7_sync:
|
||||
ldr r7,= 0x02FFFC24
|
||||
movs r1, #1
|
||||
strh r1, [r7, #4]
|
||||
|
||||
ldrh r6, [r7, #2]
|
||||
ldrh r1, [r7]
|
||||
1:
|
||||
adds r1, #1
|
||||
strh r1, [r7]
|
||||
ldrh r4, [r7, #2]
|
||||
cmp r6, r4
|
||||
beq 1b
|
||||
adds r1, #1
|
||||
strh r1, [r7]
|
||||
mov r11, pc
|
||||
b do_sync
|
||||
|
||||
movs r1, #3
|
||||
strh r1, [r7, #4]
|
||||
mov r11, pc
|
||||
b do_sync
|
||||
|
||||
mov pc, lr
|
||||
|
||||
do_sync:
|
||||
ldrh r6, [r7, #2]
|
||||
ldrh r1, [r7]
|
||||
1:
|
||||
@@ -164,14 +168,23 @@ twl_arm7_sync:
|
||||
beq 1b
|
||||
adds r1, #1
|
||||
strh r1, [r7]
|
||||
|
||||
mov pc, lr
|
||||
mov pc, r11
|
||||
|
||||
.balign 4
|
||||
|
||||
regVramCntA:
|
||||
.word 0x04000240
|
||||
|
||||
.global patch_osresetsystem_arm7Entry_address
|
||||
patch_osresetsystem_arm7Entry_address:
|
||||
.word 0x027FFE34
|
||||
|
||||
vramCDSettings:
|
||||
.word 0x8A82
|
||||
|
||||
.global patch_osresetsystem_cheats_address
|
||||
patch_osresetsystem_cheats_address:
|
||||
.word 0
|
||||
|
||||
.pool
|
||||
.end
|
||||
|
||||
Reference in New Issue
Block a user