Refactored platform code to use interfaces for patch code with a special feature and improved patch code file names

This commit is contained in:
Gericom
2026-01-02 15:18:45 +01:00
parent d6080984d1
commit 231f14a783
180 changed files with 1073 additions and 1057 deletions

View File

@@ -192,8 +192,8 @@ static void handleGetSdFunctionsCommand()
{
auto sdReadPatchCode = sLoaderPlatform->CreateSdReadPatchCode(patchCodeCollection, patchHeap);
auto sdWritePatchCode = sLoaderPlatform->CreateSdWritePatchCode(patchCodeCollection, patchHeap);
*(vu32*)0x037F8000 = (u32)sdReadPatchCode->GetSdReadFunction();
*(vu32*)0x037F8004 = (u32)sdWritePatchCode->GetSdWriteFunction();
*(vu32*)0x037F8000 = (u32)sdReadPatchCode->GetReadSectorsFunction();
*(vu32*)0x037F8004 = (u32)sdWritePatchCode->GetWriteSectorFunction();
patchCodeCollection.CopyAllToTarget();
}
dc_flushAll();

View File

@@ -0,0 +1,10 @@
#pragma once
class ISectorRemapPatchCode
{
protected:
ISectorRemapPatchCode() { }
public:
virtual const void* GetRemapFunction() const = 0;
};

View File

@@ -1,17 +1,17 @@
#pragma once
#include "sections.h"
#include "SectorRemapPatchCode.h"
#include "PatchCode.h"
#include "ISectorRemapPatchCode.h"
DEFINE_SECTION_SYMBOLS(offsettosectorremap);
extern "C" u32 offset_to_sector_remap(u32 romOffset);
class OffsetToSectorRemapPatchCode : public SectorRemapPatchCode
class OffsetToSectorRemapPatchCode : public PatchCode, public ISectorRemapPatchCode
{
public:
explicit OffsetToSectorRemapPatchCode(PatchHeap& patchHeap)
: SectorRemapPatchCode(SECTION_START(offsettosectorremap), SECTION_SIZE(offsettosectorremap), patchHeap)
{ }
: PatchCode(SECTION_START(offsettosectorremap), SECTION_SIZE(offsettosectorremap), patchHeap) { }
const void* GetRemapFunction() const override
{

View File

@@ -1,6 +1,7 @@
#pragma once
#include "sections.h"
#include "SectorRemapPatchCode.h"
#include "PatchCode.h"
#include "ISectorRemapPatchCode.h"
#include "fileInfo.h"
DEFINE_SECTION_SYMBOLS(saveoffsettosdsector);
@@ -9,11 +10,11 @@ extern "C" u32 save_offset_to_sd_sector_asm(u32 saveOffset);
extern u32 saveoffsettosdsector_fatDataPtr;
class SaveOffsetToSdSectorPatchCode : public SectorRemapPatchCode
class SaveOffsetToSdSectorPatchCode : public PatchCode, public ISectorRemapPatchCode
{
public:
SaveOffsetToSdSectorPatchCode(PatchHeap& patchHeap, const save_file_info_t* fatDataPtr)
: SectorRemapPatchCode(SECTION_START(saveoffsettosdsector), SECTION_SIZE(saveoffsettosdsector), patchHeap)
: PatchCode(SECTION_START(saveoffsettosdsector), SECTION_SIZE(saveoffsettosdsector), patchHeap)
{
saveoffsettosdsector_fatDataPtr = (u32)fatDataPtr;
}

View File

@@ -1,11 +0,0 @@
#pragma once
#include "PatchCode.h"
class SectorRemapPatchCode : public PatchCode
{
public:
SectorRemapPatchCode(const void* code, u32 size, PatchHeap& patchHeap)
: PatchCode(code, size, patchHeap) { }
virtual const void* GetRemapFunction() const = 0;
};

View File

@@ -1,8 +1,8 @@
#pragma once
#include "sections.h"
#include "../PatchCode.h"
#include "../SectorRemapPatchCode.h"
#include "../platform/SdReadPatchCode.h"
#include "patches/PatchCode.h"
#include "patches/ISectorRemapPatchCode.h"
#include "patches/platform/IReadSectorsPatchCode.h"
DEFINE_SECTION_SYMBOLS(readsave);
@@ -15,12 +15,12 @@ extern u32 readsave_sdread_asm_address;
class ReadSavePatchCode : public PatchCode
{
public:
ReadSavePatchCode(PatchHeap& patchHeap, const SectorRemapPatchCode* sectorRemapPatchCode,
const SdReadPatchCode* sdReadPatchCode, void* tmpBuffer)
ReadSavePatchCode(PatchHeap& patchHeap, const ISectorRemapPatchCode* sectorRemapPatchCode,
const IReadSectorsPatchCode* readSectorsPatchCode, void* tmpBuffer)
: PatchCode(SECTION_START(readsave), SECTION_SIZE(readsave), patchHeap)
{
readsave_save_offset_to_sd_sector_asm_address = (u32)sectorRemapPatchCode->GetRemapFunction();
readsave_sdread_asm_address = (u32)sdReadPatchCode->GetSdReadFunction();
readsave_sdread_asm_address = (u32)readSectorsPatchCode->GetReadSectorsFunction();
readsave_tmpBufferPtr = (u32)tmpBuffer;
}

View File

@@ -1,8 +1,8 @@
#pragma once
#include "sections.h"
#include "../PatchCode.h"
#include "../SectorRemapPatchCode.h"
#include "../platform/SdReadPatchCode.h"
#include "patches/PatchCode.h"
#include "patches/ISectorRemapPatchCode.h"
#include "patches/platform/IReadSectorsPatchCode.h"
DEFINE_SECTION_SYMBOLS(verifysave);
@@ -15,12 +15,12 @@ extern u32 verifysave_sdread_asm_address;
class VerifySavePatchCode : public PatchCode
{
public:
VerifySavePatchCode(PatchHeap& patchHeap, const SectorRemapPatchCode* sectorRemapPatchCode,
const SdReadPatchCode* sdReadPatchCode, void* tmpBuffer)
VerifySavePatchCode(PatchHeap& patchHeap, const ISectorRemapPatchCode* sectorRemapPatchCode,
const IReadSectorsPatchCode* readSectorsPatchCode, void* tmpBuffer)
: PatchCode(SECTION_START(verifysave), SECTION_SIZE(verifysave), patchHeap)
{
verifysave_save_offset_to_sd_sector_asm_address = (u32)sectorRemapPatchCode->GetRemapFunction();
verifysave_sdread_asm_address = (u32)sdReadPatchCode->GetSdReadFunction();
verifysave_sdread_asm_address = (u32)readSectorsPatchCode->GetReadSectorsFunction();
verifysave_tmpBufferPtr = (u32)tmpBuffer;
}

View File

@@ -1,9 +1,9 @@
#pragma once
#include "sections.h"
#include "../PatchCode.h"
#include "../SectorRemapPatchCode.h"
#include "../platform/SdReadPatchCode.h"
#include "../platform/SdWritePatchCode.h"
#include "patches/PatchCode.h"
#include "patches/ISectorRemapPatchCode.h"
#include "patches/platform/IReadSectorsPatchCode.h"
#include "patches/platform/IWriteSectorsPatchCode.h"
DEFINE_SECTION_SYMBOLS(writesave);
@@ -17,13 +17,13 @@ extern u32 writesave_sdwrite_asm_address;
class WriteSavePatchCode : public PatchCode
{
public:
WriteSavePatchCode(PatchHeap& patchHeap, const SectorRemapPatchCode* sectorRemapPatchCode,
const SdReadPatchCode* sdReadPatchCode, const SdWritePatchCode* sdWritePatchCode, void* tmpBuffer)
WriteSavePatchCode(PatchHeap& patchHeap, const ISectorRemapPatchCode* sectorRemapPatchCode,
const IReadSectorsPatchCode* readSectorsPatchCode, const IWriteSectorsPatchCode* writeSectorsPatchCode, void* tmpBuffer)
: PatchCode(SECTION_START(writesave), SECTION_SIZE(writesave), patchHeap)
{
writesave_save_offset_to_sd_sector_asm_address = (u32)sectorRemapPatchCode->GetRemapFunction();
writesave_sdread_asm_address = (u32)sdReadPatchCode->GetSdReadFunction();
writesave_sdwrite_asm_address = (u32)sdWritePatchCode->GetSdWriteFunction();
writesave_sdread_asm_address = (u32)readSectorsPatchCode->GetReadSectorsFunction();
writesave_sdwrite_asm_address = (u32)writeSectorsPatchCode->GetWriteSectorFunction();
writesave_tmpBufferPtr = (u32)tmpBuffer;
}

View File

@@ -3,12 +3,12 @@
#include <array>
#include "fileInfo.h"
#include "patches/PatchContext.h"
#include "patches/arm7/ReadSaveAsm.h"
#include "patches/arm7/WriteSaveAsm.h"
#include "patches/arm7/VerifySaveAsm.h"
#include "patches/arm7/ReadSavePatchCode.h"
#include "patches/arm7/WriteSavePatchCode.h"
#include "patches/arm7/VerifySavePatchCode.h"
#include "patches/FunctionSignature.h"
#include "patches/platform/LoaderPlatform.h"
#include "patches/SaveOffsetToSdSectorAsm.h"
#include "patches/SaveOffsetToSdSectorPatchCode.h"
#include "patches/arm7/CardiTaskThreadPatchAsm.h"
#include "thumbInstructions.h"
#include "CardiTaskThreadPatch.h"

View File

@@ -2,10 +2,10 @@
#include "patches/PatchContext.h"
#include "thumbInstructions.h"
#include "fileInfo.h"
#include "patches/arm7/ReadSaveAsm.h"
#include "patches/arm7/WriteSaveAsm.h"
#include "patches/arm7/VerifySaveAsm.h"
#include "patches/SaveOffsetToSdSectorAsm.h"
#include "patches/arm7/ReadSavePatchCode.h"
#include "patches/arm7/WriteSavePatchCode.h"
#include "patches/arm7/VerifySavePatchCode.h"
#include "patches/SaveOffsetToSdSectorPatchCode.h"
#include "patches/platform/LoaderPlatform.h"
#include "patches/arm7/CardiTaskThreadPatchAsm.h"
#include "CardiDoTaskFromArm9Patch.h"

View File

@@ -1,8 +1,8 @@
#pragma once
#include "patches/PatchCode.h"
#include "sections.h"
#include "patches/platform/SdReadPatchCode.h"
#include "patches/platform/SdWritePatchCode.h"
#include "patches/PatchCode.h"
#include "patches/platform/IReadSectorsPatchCode.h"
#include "patches/platform/IWriteSectorsPatchCode.h"
DEFINE_SECTION_SYMBOLS(patch_dsisdredirect);
@@ -16,12 +16,12 @@ extern u32 __patch_dsisdredirect_control_get_drive_struct_address;
class Sdk5DsiSdCardRedirectPatchCode : public PatchCode
{
public:
Sdk5DsiSdCardRedirectPatchCode(PatchHeap& patchHeap, const SdReadPatchCode* sdReadPatchCode,
const SdWritePatchCode* sdWritePatchCode, u32 getDriveStructAddress)
Sdk5DsiSdCardRedirectPatchCode(PatchHeap& patchHeap, const IReadSectorsPatchCode* readSectorsPatchCode,
const IWriteSectorsPatchCode* writeSectorsPatchCode, u32 getDriveStructAddress)
: PatchCode(SECTION_START(patch_dsisdredirect), SECTION_SIZE(patch_dsisdredirect), patchHeap)
{
__patch_dsisdredirect_io_readsd_asm_address = (u32)sdReadPatchCode->GetSdReadFunction();
__patch_dsisdredirect_io_writesd_asm_address = (u32)sdWritePatchCode->GetSdWriteFunction();
__patch_dsisdredirect_io_readsd_asm_address = (u32)readSectorsPatchCode->GetReadSectorsFunction();
__patch_dsisdredirect_io_writesd_asm_address = (u32)writeSectorsPatchCode->GetWriteSectorFunction();
__patch_dsisdredirect_control_get_drive_struct_address = getDriveStructAddress;
}

View File

@@ -2,7 +2,7 @@
#include "thumbInstructions.h"
#include "../PatchContext.h"
#include "../FunctionSignature.h"
#include "CardiReadRomIdCorePatchAsm.h"
#include "CardiReadRomIdCorePatchCode.h"
#include "CardiReadRomIdCorePatch.h"
static constexpr auto sSignaturesArm = std::to_array<const FunctionSignature>

Some files were not shown because too many files have changed in this diff Show More