From 36e77d2a5e32e3b1f86c31cf97c949bf2437671d Mon Sep 17 00:00:00 2001 From: tom-overton Date: Fri, 21 Oct 2022 04:39:33 -0700 Subject: Gen 2: Add support for Guaranteed Pokemon Catching --- src/com/sneed/pkrandom/config/gen2_offsets.ini | 4 +++ .../sneed/pkrandom/romhandlers/Gen2RomHandler.java | 35 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/com/sneed/pkrandom/config/gen2_offsets.ini b/src/com/sneed/pkrandom/config/gen2_offsets.ini index daa3373..7033fe5 100755 --- a/src/com/sneed/pkrandom/config/gen2_offsets.ini +++ b/src/com/sneed/pkrandom/config/gen2_offsets.ini @@ -49,6 +49,7 @@ CatchingTutorialOffsets=[0x128DBB, 0x128DF1, 0x128E39] PicPointers=0x48000 PokemonPalettes=0xAD3D TypeEffectivenessOffset=0x34D01 +GuaranteedCatchPrefix=D147FA19D1FE03 StaticPokemonSupport=1 GameCornerPokemonNameLength=11 StaticPokemon{}={Species=[0x111772, 0x111775], Level=[0x111776]} // Lapras @@ -195,6 +196,7 @@ MoveTutorMoves=[0x492B4, 0x492B7, 0x492B1] MoveTutorMenuOffset=0x19896C MoveTutorMenuNewSpace=0x19BB00 TypeEffectivenessOffset=0x34BB1 +GuaranteedCatchPrefix=47FA30D2FE03 StaticPokemonSupport=1 GameCornerPokemonNameLength=11 StaticPokemon{}={Species=[0x5A321, 0x5A324], Level=[0x5A325]} // Lapras @@ -387,6 +389,7 @@ CatchingTutorialOffsets=[0xD1295, 0xD12CB, 0xD1313] PicPointers=0x48000 PokemonPalettes=0xACC3 TypeEffectivenessOffset=0x34CFD +GuaranteedCatchPrefix=47FA0BD1FE03 StaticPokemonSupport=0 CRC32=524478D4 @@ -458,6 +461,7 @@ TextDelayFunctionOffset=0x3109 PicPointers=0x120000 PokemonPalettes=0xA88B TypeEffectivenessOffset=0x34BB1 +GuaranteedCatchPrefix=47FA61D2FE03 StaticPokemonSupport=0 IntroSpriteOffset=0x5FC2 IntroCryOffset=0x60BE diff --git a/src/com/sneed/pkrandom/romhandlers/Gen2RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen2RomHandler.java index ef2c6ac..ba34e74 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen2RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen2RomHandler.java @@ -80,6 +80,7 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { private List tmTexts = new ArrayList<>(); private Map entries = new HashMap<>(); private Map arrayEntries = new HashMap<>(); + private Map strings = new HashMap<>(); private List staticPokemon = new ArrayList<>(); private int getValue(String key) { @@ -88,6 +89,13 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { } return entries.get(key); } + + private String getString(String key) { + if (!strings.containsKey(key)) { + strings.put(key, ""); + } + return strings.get(key); + } } private static class TMTextEntry { @@ -166,6 +174,7 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { boolean cTT = (current.getValue("CopyTMText") == 1); current.arrayEntries.putAll(otherEntry.arrayEntries); current.entries.putAll(otherEntry.entries); + current.strings.putAll(otherEntry.strings); if (cSP) { current.staticPokemon.addAll(otherEntry.staticPokemon); current.entries.put("StaticPokemonSupport", 1); @@ -180,6 +189,8 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { current.extraTableFile = otherEntry.extraTableFile; } } + } else if (r[0].endsWith("Locator") || r[0].endsWith("Prefix")) { + current.strings.put(r[0], r[1]); } else { if (r[1].startsWith("[") && r[1].endsWith("]")) { String[] offsets = r[1].substring(1, r[1].length() - 1).split(","); @@ -2215,6 +2226,9 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { available |= MiscTweak.RANDOMIZE_CATCHING_TUTORIAL.getValue(); } available |= MiscTweak.BAN_LUCKY_EGG.getValue(); + if (romEntry.strings.containsKey("GuaranteedCatchPrefix")) { + available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue(); + } return available; } @@ -2233,6 +2247,8 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { nonBadItems.banSingles(Gen2Items.luckyEgg); } else if (tweak == MiscTweak.UPDATE_TYPE_EFFECTIVENESS) { updateTypeEffectiveness(); + } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) { + enableGuaranteedPokemonCatching(); } } @@ -2360,6 +2376,25 @@ public class Gen2RomHandler extends AbstractGBCRomHandler { } } + private void enableGuaranteedPokemonCatching() { + String prefix = romEntry.getString("GuaranteedCatchPrefix"); + int offset = find(rom, prefix); + if (offset > 0) { + offset += prefix.length() / 2; // because it was a prefix + + // The game guarantees that the catching tutorial always succeeds in catching by running + // the following code: + // ld a, [wBattleType] + // cp BATTLETYPE_TUTORIAL + // jp z, .catch_without_fail + // By making the jump here unconditional, we can ensure that catching always succeeds no + // matter the battle type. We check that the original condition is present just for safety. + if (rom[offset] == (byte)0xCA) { + rom[offset] = (byte)0xC3; + } + } + } + @Override public void randomizeIntroPokemon() { // Intro sprite -- cgit v1.2.3