summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2022-10-21 08:12:30 -0700
committerRafael Marçalo <raroma09@gmail.com>2022-10-21 22:46:52 +0100
commit4197ffa859e1d5396584895db21567def66f1106 (patch)
tree24f9aee381925727508d336bcf3d8f6e0b35738c
parent74b1c45b35d6a0f093f9a1f8ddc99b01584ff71e (diff)
Gen 5: Add support for Guaranteed Catching Pokemon
-rw-r--r--src/com/sneed/pkrandom/constants/Gen5Constants.java2
-rwxr-xr-xsrc/com/sneed/pkrandom/romhandlers/Gen5RomHandler.java26
2 files changed, 28 insertions, 0 deletions
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<Integer> consumableHeldItems = setupAllConsumableItems();
private static List<Integer> 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) {