From 8f044f29bf1806a6b301b4195ea2f761b63060b6 Mon Sep 17 00:00:00 2001 From: tom-overton Date: Thu, 20 Oct 2022 22:05:04 -0700 Subject: Gen 4: Add support for Guaranteed Pokemon Catching --- .../sneed/pkrandom/constants/Gen4Constants.java | 2 ++ .../sneed/pkrandom/romhandlers/Gen4RomHandler.java | 26 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/com/sneed/pkrandom/constants/Gen4Constants.java b/src/com/sneed/pkrandom/constants/Gen4Constants.java index 7a0acfa..1309073 100644 --- a/src/com/sneed/pkrandom/constants/Gen4Constants.java +++ b/src/com/sneed/pkrandom/constants/Gen4Constants.java @@ -770,6 +770,8 @@ public class Gen4Constants { public static final String friendshipValueForEvoLocator = "DC286AD3"; + public static final String catchFailBranchLocator = "FF2901D30425"; + public static final int[] dpptOverworldDexMaps = new int[] { 1, 2, 3, 4, 5, -1, -1, 6, -1, 7, // 0-9 (cities, pkmn league, wind/ironworks) -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 10-19 (all mt coronet) diff --git a/src/com/sneed/pkrandom/romhandlers/Gen4RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen4RomHandler.java index 7d12c47..cc98c3b 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen4RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen4RomHandler.java @@ -5265,6 +5265,7 @@ public class Gen4RomHandler extends AbstractDSRomHandler { if (romEntry.romType == Gen4Constants.Type_Plat || romEntry.romType == Gen4Constants.Type_HGSS) { available |= MiscTweak.UPDATE_ROTOM_FORME_TYPING.getValue(); } + available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue(); return available; } @@ -5291,6 +5292,8 @@ public class Gen4RomHandler extends AbstractDSRomHandler { applyFastDistortionWorld(); } else if (tweak == MiscTweak.UPDATE_ROTOM_FORME_TYPING) { updateRotomFormeTyping(); + } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) { + enableGuaranteedPokemonCatching(); } } @@ -5530,6 +5533,29 @@ public class Gen4RomHandler extends AbstractDSRomHandler { pokes[Species.Gen4Formes.rotomM].secondaryType = Type.GRASS; } + private void enableGuaranteedPokemonCatching() { + try { + byte[] battleOverlay = readOverlay(romEntry.getInt("BattleOvlNumber")); + int offset = find(battleOverlay, Gen4Constants.catchFailBranchLocator); + if (offset > 0) { + // In Cmd_handleballthrow (name taken from pokeemerald decomp), the middle of the function checks + // if the odds of catching a Pokemon is greater than 254; if it is, then the Pokemon is automatically + // caught. In ASM, this is represented by: + // cmp r1, #0xFF + // bcc oddsLessThanOrEqualTo254 + // The below code just nops these two instructions so that we *always* act like our odds are 255, + // and Pokemon are automatically caught no matter what. + battleOverlay[offset] = 0x00; + battleOverlay[offset + 1] = 0x00; + battleOverlay[offset + 2] = 0x00; + battleOverlay[offset + 3] = 0x00; + writeOverlay(romEntry.getInt("BattleOvlNumber"), battleOverlay); + } + } catch (IOException e) { + throw new RandomizerIOException(e); + } + } + @Override public void applyCorrectStaticMusic(Map specialMusicStaticChanges) { List replaced = new ArrayList<>(); -- cgit v1.2.3