From 4197ffa859e1d5396584895db21567def66f1106 Mon Sep 17 00:00:00 2001 From: tom-overton Date: Fri, 21 Oct 2022 08:12:30 -0700 Subject: Gen 5: Add support for Guaranteed Catching Pokemon --- .../sneed/pkrandom/constants/Gen5Constants.java | 2 ++ .../sneed/pkrandom/romhandlers/Gen5RomHandler.java | 26 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/com/sneed/pkrandom/constants/Gen5Constants.java b/src/com/sneed/pkrandom/constants/Gen5Constants.java index 110e1b4..56e49e9 100644 --- a/src/com/sneed/pkrandom/constants/Gen5Constants.java +++ b/src/com/sneed/pkrandom/constants/Gen5Constants.java @@ -375,6 +375,8 @@ public class Gen5Constants { public static final String friendshipValueForEvoLocator = "DC282FD3"; + public static final String perfectOddsBranchLocator = "08DB002801D0012000E0"; + public static final List consumableHeldItems = setupAllConsumableItems(); private static List setupAllConsumableItems() { diff --git a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java index 538c8da..05081b5 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java @@ -2426,6 +2426,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { if (romEntry.romType == Gen5Constants.Type_BW2) { available |= MiscTweak.FORCE_CHALLENGE_MODE.getValue(); } + available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue(); return available; } @@ -2461,6 +2462,8 @@ public class Gen5RomHandler extends AbstractDSRomHandler { updateTypeEffectiveness(); } else if (tweak == MiscTweak.FORCE_CHALLENGE_MODE) { forceChallengeMode(); + } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) { + enableGuaranteedPokemonCatching(); } } @@ -2639,6 +2642,29 @@ public class Gen5RomHandler extends AbstractDSRomHandler { } } + private void enableGuaranteedPokemonCatching() { + try { + byte[] battleOverlay = readOverlay(romEntry.getInt("BattleOvlNumber")); + int offset = find(battleOverlay, Gen5Constants.perfectOddsBranchLocator); + if (offset > 0) { + // The game checks to see if your odds are greater then or equal to 255 using the following + // code. Note that they compare to 0xFF000 instead of 0xFF; it looks like all catching code + // probabilities are shifted like this? + // mov r0, #0xFF + // lsl r0, r0, #0xC + // cmp r7, r0 + // blt oddsLessThanOrEqualTo254 + // The below code just nops the branch out so it always acts like our odds are 255, and + // Pokemon are automatically caught no matter what. + battleOverlay[offset] = 0x00; + battleOverlay[offset + 1] = 0x00; + writeOverlay(romEntry.getInt("BattleOvlNumber"), battleOverlay); + } + } catch (IOException e) { + throw new RandomizerIOException(e); + } + } + private boolean genericIPSPatch(byte[] data, String ctName) { String patchName = romEntry.tweakFiles.get(ctName); if (patchName == null) { -- cgit v1.2.3