From 79018dee0d7467876be8be547ca48d513597852c Mon Sep 17 00:00:00 2001 From: taxicat1 <32942550+taxicat1@users.noreply.github.com> Date: Sat, 6 Dec 2025 09:10:10 -0500 Subject: [PATCH] Fix folder name to proper case --- .../PokemonIr/PokemonIrApPatch.cpp | 45 +++++++++++++++++++ .../PokemonIr/PokemonIrApPatch.h | 16 +++++++ .../PokemonIr/PokemonIrApPatchAsm.h | 26 +++++++++++ .../PokemonIr/PokemonIrApPatchAsm.s | 40 +++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.cpp create mode 100644 arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.h create mode 100644 arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.h create mode 100644 arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.s diff --git a/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.cpp b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.cpp new file mode 100644 index 0000000..0d5ebda --- /dev/null +++ b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.cpp @@ -0,0 +1,45 @@ +#include "common.h" +#include "../../../PatchContext.h" +#include "PokemonIrApPatchAsm.h" +#include "PokemonIrApPatch.h" + +const void* PokemonIrApPatch::InsertPatch(PatchContext& patchContext) +{ + ConfigurePatch(); + return patchContext.GetPatchCodeCollection().AddUniquePatchCode + ( + patchContext.GetPatchHeap(), + next ? next->InsertPatch(patchContext) : nullptr + )->GetPatchFunction(); +} + +void PokemonIrApPatch::ConfigurePatch() const { + switch (_version) + { + // All of these offsets are luckily region-independent + case PokemonIrVersion::Hgss: + { + pokemonirappatch_overlayId = 1; + pokemonirappatch_offset = 0xD2C + 0x12; + break; + } + case PokemonIrVersion::Bw1: + { + pokemonirappatch_overlayId = 231; + pokemonirappatch_offset = 0x1B8 + 0x12; + break; + } + case PokemonIrVersion::Bw2: + { + pokemonirappatch_overlayId = 338; + pokemonirappatch_offset = 0x1B8 + 0x12; + break; + } + default: + { + LOG_WARNING("Unsupported Pokemon IR version\n"); + pokemonirappatch_overlayId = 0xFFFFFFFF; + break; + } + } +} diff --git a/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.h b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.h new file mode 100644 index 0000000..2d6fe29 --- /dev/null +++ b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatch.h @@ -0,0 +1,16 @@ +#pragma once +#include "../OverlayPatch.h" +#include "PokemonIrVersion.h" + +/// @brief Arm9 overlay patch to disable the IR-sensor anti-piracy in Pokemon HeartGold, SoulSilver, Black, White, Black 2, and White 2. +class PokemonIrApPatch : public OverlayPatch +{ +public: + PokemonIrApPatch(PokemonIrVersion version) : _version(version) { } + const void* InsertPatch(PatchContext& patchContext) override; + +private: + PokemonIrVersion _version; + + void ConfigurePatch() const; +}; diff --git a/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.h b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.h new file mode 100644 index 0000000..9bcddaa --- /dev/null +++ b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.h @@ -0,0 +1,26 @@ +#pragma once +#include "sections.h" +#include "../../../PatchCode.h" + +DEFINE_SECTION_SYMBOLS(pokemonirappatch); + +extern "C" void pokemonirappatch_entry(); + +extern u32 pokemonirappatch_overlayId; +extern u32 pokemonirappatch_offset; +extern u32 pokemonirappatch_nextAddress; + +class PokemonIrApPatchCode : public PatchCode +{ +public: + PokemonIrApPatchCode(PatchHeap& patchHeap, const void* nextPatch) + : PatchCode(SECTION_START(pokemonirappatch), SECTION_SIZE(pokemonirappatch), patchHeap) + { + pokemonirappatch_nextAddress = (u32)nextPatch; + } + + const void* GetPatchFunction() const + { + return GetAddressAtTarget((void*)pokemonirappatch_entry); + } +}; diff --git a/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.s b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.s new file mode 100644 index 0000000..a966f8f --- /dev/null +++ b/arm9/source/patches/arm9/OverlayPatches/PokemonIr/PokemonIrApPatchAsm.s @@ -0,0 +1,40 @@ +.cpu arm946e-s +.syntax unified +.section "pokemonirappatch", "ax" +.thumb + +.global pokemonirappatch_entry +.type pokemonirappatch_entry, %function +pokemonirappatch_entry: + push {r5,lr} + + ldmia r5!, {r1, r2} // overlay id, ram address + ldr r0, pokemonirappatch_overlayId + cmp r0, r1 + bne continue_to_next + + ldr r1, pokemonirappatch_offset + movs r0, #1 // force return value of function to 1 instead of 0 + strb r0, [r2, r1] + +continue_to_next: + ldr r0, pokemonirappatch_nextAddress + pop {r5,pc} + +.balign 4 + +.global pokemonirappatch_overlayId +pokemonirappatch_overlayId: + .word 0 + +.global pokemonirappatch_offset +pokemonirappatch_offset: + .word 0 + +.global pokemonirappatch_nextAddress +pokemonirappatch_nextAddress: + .word 0 + +.pool + +.end