From 6965244cc012abeb9fd11987af7507b3bac05d36 Mon Sep 17 00:00:00 2001 From: tom-overton Date: Thu, 20 Oct 2022 00:42:59 -0700 Subject: Gen 3: Add support for Guaranteed Pokemon Catching --- src/com/sneed/pkrandom/MiscTweak.java | 1 + src/com/sneed/pkrandom/Version.java | 5 +++-- src/com/sneed/pkrandom/constants/Gen3Constants.java | 2 ++ src/com/sneed/pkrandom/newgui/Bundle.properties | 2 ++ src/com/sneed/pkrandom/newgui/NewRandomizerGUI.form | 11 +++++++++++ src/com/sneed/pkrandom/newgui/NewRandomizerGUI.java | 1 + .../sneed/pkrandom/romhandlers/Gen3RomHandler.java | 20 ++++++++++++++++++++ 7 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/com/sneed/pkrandom/MiscTweak.java b/src/com/sneed/pkrandom/MiscTweak.java index 5cbdda1..7391c30 100755 --- a/src/com/sneed/pkrandom/MiscTweak.java +++ b/src/com/sneed/pkrandom/MiscTweak.java @@ -61,6 +61,7 @@ public class MiscTweak implements Comparable { public static final MiscTweak FASTER_HP_AND_EXP_BARS = new MiscTweak(1 << 19, "fasterHpAndExpBars", 0); public static final MiscTweak FAST_DISTORTION_WORLD = new MiscTweak(1 << 20, "fastDistortionWorld", 0); public static final MiscTweak UPDATE_ROTOM_FORME_TYPING = new MiscTweak(1 << 21, "updateRotomFormeTyping", 0); + public static final MiscTweak GUARANTEED_POKEMON_CATCHING = new MiscTweak(1 << 22, "guaranteedPokemonCatching", 0); /* @formatter:on */ private final int value; diff --git a/src/com/sneed/pkrandom/Version.java b/src/com/sneed/pkrandom/Version.java index 9a1d00a..c05394e 100644 --- a/src/com/sneed/pkrandom/Version.java +++ b/src/com/sneed/pkrandom/Version.java @@ -28,8 +28,8 @@ import java.util.HashMap; import java.util.Map; public class Version { - public static final int VERSION = 320; // Increment by 1 for new version. Updated for 4.5.1-dev. - public static final String VERSION_STRING = "4.5.1-dev"; + public static final int VERSION = 321; // Increment by 1 for new version. Updated for 4.5.2-dev. + public static final String VERSION_STRING = "4.5.2-dev"; public static final Map oldVersions = setupVersionsMap(); @@ -60,6 +60,7 @@ public class Version { map.put(317, "4.3.0"); map.put(318, "4.4.0"); map.put(319, "4.5.0"); + map.put(320, "4.5.1"); // Latest version - when version is updated, add the old version as an explicit put map.put(VERSION, VERSION_STRING); diff --git a/src/com/sneed/pkrandom/constants/Gen3Constants.java b/src/com/sneed/pkrandom/constants/Gen3Constants.java index 98815e6..892c1a4 100644 --- a/src/com/sneed/pkrandom/constants/Gen3Constants.java +++ b/src/com/sneed/pkrandom/constants/Gen3Constants.java @@ -164,6 +164,8 @@ public class Gen3Constants { public static final String friendshipValueForEvoLocator = "DB2900D8"; + public static final String catchFailBranchLocator = "FE2E2FD90020"; + public static final int unhackedMaxPokedex = 411, unhackedRealPokedex = 386, hoennPokesStart = 252; public static final int evolutionMethodCount = 15; diff --git a/src/com/sneed/pkrandom/newgui/Bundle.properties b/src/com/sneed/pkrandom/newgui/Bundle.properties index 6b5ec6b..e297729 100644 --- a/src/com/sneed/pkrandom/newgui/Bundle.properties +++ b/src/com/sneed/pkrandom/newgui/Bundle.properties @@ -519,6 +519,8 @@ CodeTweaks.fastDistortionWorld.name=Fast Distortion World CodeTweaks.fastDistortionWorld.toolTipText=Cuts out most of the Distortion World by instantly warping you to the Cyrus fight when you enter it. CodeTweaks.updateRotomFormeTyping.name=Update Rotom Appliance Typings CodeTweaks.updateRotomFormeTyping.toolTipText=Updates the typings of Rotom's alternate formes (i.e., the appliances) to match the typings they have in Gen 5 and onwards.
For example, Wash Rotom will change from Electric/Ghost to Electric/Water. +CodeTweaks.guaranteedPokemonCatching.name=Guaranteed Pokemon Catching +CodeTweaks.guaranteedPokemonCatching.toolTipText=Makes it so that any Poke Ball thrown at a wild Pokemon will be guaranteed to catch them, so long as the Pokemon is catchable in the first place. CustomNamesEditorDialog.trainerNamesSP.TabConstraints.tabTitle=Trainer Names CustomNamesEditorDialog.title=Custom Names Editor CustomNamesEditorDialog.closeBtn.text=Close diff --git a/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.form b/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.form index 4b1ff5d..838994c 100644 --- a/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.form +++ b/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.form @@ -3609,6 +3609,17 @@ + + + + + + + + + + + diff --git a/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.java b/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.java index 5eecbe7..a625e8c 100644 --- a/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.java +++ b/src/com/sneed/pkrandom/newgui/NewRandomizerGUI.java @@ -297,6 +297,7 @@ public class NewRandomizerGUI { private JCheckBox tpBetterMovesetsCheckBox; private JCheckBox paEnsureTwoAbilitiesCheckbox; private JCheckBox miscUpdateRotomFormeTypingCheckBox; + private JCheckBox miscGuaranteedPokemonCatchingCheckBox; private static JFrame frame; diff --git a/src/com/sneed/pkrandom/romhandlers/Gen3RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen3RomHandler.java index a9dff29..36c92a7 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen3RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen3RomHandler.java @@ -4112,6 +4112,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler { if (romEntry.romType == Gen3Constants.RomType_FRLG) { available |= MiscTweak.BALANCE_STATIC_LEVELS.getValue(); } + available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue(); return available; } @@ -4141,6 +4142,8 @@ public class Gen3RomHandler extends AbstractGBRomHandler { } } else if (tweak == MiscTweak.UPDATE_TYPE_EFFECTIVENESS) { updateTypeEffectiveness(); + } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) { + enableGuaranteedPokemonCatching(); } } @@ -4329,6 +4332,23 @@ public class Gen3RomHandler extends AbstractGBRomHandler { } } + private void enableGuaranteedPokemonCatching() { + int offset = find(rom, Gen3Constants.catchFailBranchLocator); + if (offset > 0) { + // In Cmd_handleballthrow, 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 r6, #0xFE + // bls 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. + rom[offset] = 0x00; + rom[offset + 1] = 0x00; + rom[offset + 2] = 0x00; + rom[offset + 3] = 0x00; + } + } + @Override public boolean isRomValid() { return romEntry.expectedCRC32 == actualCRC32; -- cgit v1.2.3