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
Initial DSProtect for ARM9 static
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "patches/arm9/CardiReadRomIdCorePatch.h"
|
||||
#include "patches/arm9/OSResetSystemPatch.h"
|
||||
#include "patches/arm9/PokemonDownloaderArm9Patch.h"
|
||||
#include "patches/arm9/DSProtectArm9Patch.h"
|
||||
#include "patches/arm9/OverlayPatches/FsStartOverlayHookPatch.h"
|
||||
#include "patches/arm9/OverlayPatches/DSProtectPatches/DSProtectOverlayPatch.h"
|
||||
#include "patches/arm9/OverlayPatches/DSProtectPatches/DSProtectPuyoPuyo7Patch.h"
|
||||
@@ -243,7 +244,9 @@ void Arm9Patcher::AddDSProtectPatches(
|
||||
{
|
||||
if (regularOverlayId == AP_LIST_OVERLAY_ID_STATIC_ARM9)
|
||||
{
|
||||
LOG_WARNING("Patching DSProtect in main memory currently not supported\n");
|
||||
patchCollection.AddPatch(new DSProtectArm9Patch(
|
||||
apListEntry->GetRegularOffset(), apListEntry->GetDSProtectVersion(),
|
||||
apListEntry->GetDSProtectFunctionMask()));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -255,17 +258,18 @@ void Arm9Patcher::AddDSProtectPatches(
|
||||
u32 sOverlayId = apListEntry->GetSOverlayId();
|
||||
if (sOverlayId != AP_LIST_OVERLAY_ID_INVALID)
|
||||
{
|
||||
auto version = apListEntry->GetDSProtectVersion();
|
||||
if (version < DSProtectVersion::v2_00s)
|
||||
{
|
||||
version = (DSProtectVersion)((u32)version - (u32)DSProtectVersion::v2_00 + (u32)DSProtectVersion::v2_00s);
|
||||
}
|
||||
if (sOverlayId == AP_LIST_OVERLAY_ID_STATIC_ARM9)
|
||||
{
|
||||
LOG_WARNING("Patching DSProtect in main memory currently not supported\n");
|
||||
patchCollection.AddPatch(new DSProtectArm9Patch(
|
||||
apListEntry->GetSOffset(), version, ~0u));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto version = apListEntry->GetDSProtectVersion();
|
||||
if (version < DSProtectVersion::v2_00s)
|
||||
{
|
||||
version = (DSProtectVersion)((u32)version - (u32)DSProtectVersion::v2_00 + (u32)DSProtectVersion::v2_00s);
|
||||
}
|
||||
overlayHookPatch->AddOverlayPatch(new DSProtectOverlayPatch(
|
||||
sOverlayId, apListEntry->GetSOffset(), version, ~0u));
|
||||
}
|
||||
|
||||
19
arm9/source/patches/arm9/DSProtectArm9Patch.cpp
Normal file
19
arm9/source/patches/arm9/DSProtectArm9Patch.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "common.h"
|
||||
#include "DSProtectArm9Patch.h"
|
||||
#include "OverlayPatches/DSProtectPatches/DSProtectOverlayPatch.h"
|
||||
#include "ApList.h"
|
||||
#include "sharedMemory.h"
|
||||
#include "ndsHeader.h"
|
||||
|
||||
bool DSProtectArm9Patch::FindPatchTarget(PatchContext& patchContext)
|
||||
{
|
||||
return true; // target already specified by _arm9Offset
|
||||
}
|
||||
|
||||
void DSProtectArm9Patch::ApplyPatch(PatchContext& patchContext)
|
||||
{
|
||||
auto patch = new DSProtectOverlayPatch(
|
||||
AP_LIST_OVERLAY_ID_STATIC_ARM9, _arm9Offset, _version, _functionMask);
|
||||
auto romHeader = (const nds_header_ntr_t*)TWL_SHARED_MEMORY->ntrSharedMem.romHeader;
|
||||
patch->ApplyPatchForStaticArm9(romHeader->arm9LoadAddress);
|
||||
}
|
||||
19
arm9/source/patches/arm9/DSProtectArm9Patch.h
Normal file
19
arm9/source/patches/arm9/DSProtectArm9Patch.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "../Patch.h"
|
||||
#include "DSProtectVersion.h"
|
||||
|
||||
/// @brief Arm9 static patch for DS Protect.
|
||||
class DSProtectArm9Patch : public Patch
|
||||
{
|
||||
public:
|
||||
DSProtectArm9Patch(u32 arm9Offset, DSProtectVersion version, u32 functionMask)
|
||||
: _arm9Offset(arm9Offset), _version(version), _functionMask(functionMask) { }
|
||||
|
||||
bool FindPatchTarget(PatchContext& patchContext) override;
|
||||
void ApplyPatch(PatchContext& patchContext) override;
|
||||
|
||||
private:
|
||||
u32 _arm9Offset;
|
||||
DSProtectVersion _version;
|
||||
u32 _functionMask;
|
||||
};
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "common.h"
|
||||
#include "../../../PatchContext.h"
|
||||
#include "thumbInstructions.h"
|
||||
#include "gameCode.h"
|
||||
#include "DSProtectOverlayPatchAsm.h"
|
||||
#include "DSProtectOverlayPatch.h"
|
||||
|
||||
@@ -23,7 +21,10 @@
|
||||
|
||||
const void* DSProtectOverlayPatch::InsertPatch(PatchContext& patchContext)
|
||||
{
|
||||
ConfigurePatch(patchContext);
|
||||
// Next patch and target overlay ID
|
||||
dsprotectpatch_nextAddress = next ? (const void*)next->InsertPatch(patchContext) : nullptr;
|
||||
dsprotectpatch_overlayId = _overlayId;
|
||||
CalculateOffsets();
|
||||
|
||||
u32 patchSize = SECTION_SIZE(dsprotectpatch);
|
||||
void* patchAddress = patchContext.GetPatchHeap().Alloc(patchSize);
|
||||
@@ -33,12 +34,21 @@ const void* DSProtectOverlayPatch::InsertPatch(PatchContext& patchContext)
|
||||
return (const void*)entryAddress;
|
||||
}
|
||||
|
||||
void DSProtectOverlayPatch::ConfigurePatch(PatchContext& patchContext) const
|
||||
void DSProtectOverlayPatch::ApplyPatchForStaticArm9(u32 arm9LoadAddress) const
|
||||
{
|
||||
// Next patch and target overlay ID
|
||||
dsprotectpatch_nextAddress = next ? (const void*)next->InsertPatch(patchContext) : nullptr;
|
||||
dsprotectpatch_overlayId = _overlayId;
|
||||
u32 fakeOverlayInfo[2];
|
||||
fakeOverlayInfo[0] = _overlayId; // ovy_id
|
||||
fakeOverlayInfo[1] = arm9LoadAddress; // ram_start
|
||||
|
||||
dsprotectpatch_nextAddress = nullptr;
|
||||
dsprotectpatch_overlayId = _overlayId;
|
||||
CalculateOffsets();
|
||||
|
||||
dsprotectpatch_executeWithParam(fakeOverlayInfo);
|
||||
}
|
||||
|
||||
void DSProtectOverlayPatch::CalculateOffsets() const
|
||||
{
|
||||
u32 regionOffset = _overlayOffset;
|
||||
|
||||
// Default invalid, enable below
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
: _overlayId(overlayId), _overlayOffset(overlayOffset), _version(version), _functionMask(functionMask) { }
|
||||
|
||||
const void* InsertPatch(PatchContext& patchContext) override;
|
||||
void ApplyPatchForStaticArm9(u32 arm9LoadAddress) const;
|
||||
|
||||
private:
|
||||
u32 _overlayId;
|
||||
@@ -17,5 +18,5 @@ private:
|
||||
DSProtectVersion _version;
|
||||
u32 _functionMask;
|
||||
|
||||
void ConfigurePatch(PatchContext& patchContext) const;
|
||||
void CalculateOffsets() const;
|
||||
};
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
DEFINE_SECTION_SYMBOLS(dsprotectpatch);
|
||||
|
||||
extern "C" void dsprotectpatch_entry();
|
||||
extern "C" void dsprotectpatch_executeWithParam(u32* overlayInfo);
|
||||
|
||||
extern u32 dsprotectpatch_patchType; // 0=write dsprotectpatch_writeWord, 1=copy subsequent word
|
||||
extern u32 dsprotectpatch_writeWord; // Word to write if dsprotectpatch_patchType=0
|
||||
extern u32 dsprotectpatch_offsetA1; // Target offset for A1 (0xFFFFFFFF=invalid)
|
||||
extern u32 dsprotectpatch_offsetNotA1; // Target offset for NotA1 (0xFFFFFFFF=invalid)
|
||||
extern u32 dsprotectpatch_offsetA1; // Target offset for A1 (0x8xxxxxxx=invalid)
|
||||
extern u32 dsprotectpatch_offsetNotA1; // Target offset for NotA1 (0x8xxxxxxx=invalid)
|
||||
|
||||
extern u32 dsprotectpatch_overlayId; // Target overlay ID
|
||||
extern const void* dsprotectpatch_nextAddress; // Next patch address
|
||||
|
||||
@@ -86,4 +86,16 @@ dsprotectpatch_nextAddress:
|
||||
|
||||
.pool
|
||||
|
||||
.text
|
||||
|
||||
.global dsprotectpatch_executeWithParam
|
||||
.type dsprotectpatch_executeWithParam, %function
|
||||
dsprotectpatch_executeWithParam:
|
||||
push {r5, lr}
|
||||
movs r5, r0
|
||||
bl dsprotectpatch_entry
|
||||
pop {r5, pc}
|
||||
|
||||
.pool
|
||||
|
||||
.end
|
||||
|
||||
Reference in New Issue
Block a user