From 74b1c45b35d6a0f093f9a1f8ddc99b01584ff71e Mon Sep 17 00:00:00 2001 From: tom-overton Date: Fri, 21 Oct 2022 06:54:03 -0700 Subject: Gen 6: Add support for Guaranteed Pokemon Catching --- src/com/sneed/pkrandom/config/gen6_offsets.ini | 1 + .../sneed/pkrandom/constants/Gen6Constants.java | 2 ++ .../sneed/pkrandom/romhandlers/Gen6RomHandler.java | 28 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/com/sneed/pkrandom/config/gen6_offsets.ini b/src/com/sneed/pkrandom/config/gen6_offsets.ini index 3b96a9e..b97ebbe 100644 --- a/src/com/sneed/pkrandom/config/gen6_offsets.ini +++ b/src/com/sneed/pkrandom/config/gen6_offsets.ini @@ -33,6 +33,7 @@ File= File= File= File= +File= File= File= File= diff --git a/src/com/sneed/pkrandom/constants/Gen6Constants.java b/src/com/sneed/pkrandom/constants/Gen6Constants.java index 4b2f2d6..6e4aa3b 100644 --- a/src/com/sneed/pkrandom/constants/Gen6Constants.java +++ b/src/com/sneed/pkrandom/constants/Gen6Constants.java @@ -249,6 +249,8 @@ public class Gen6Constants { public static final String friendshipValueForEvoLocator = "DC0050E3BC00002A"; + public static final String perfectOddsBranchLocator = "050000BA000050E3"; + public static final String[] fastestTextPrefixes = new String[]{"1080BDE80000A0E31080BDE8F0412DE9", "485080E59C4040E24C50C0E5EC009FE5"}; private static final List mainGameShopsXY = Arrays.asList( diff --git a/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java index 86bfec7..ecbbc92 100644 --- a/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen6RomHandler.java @@ -2622,6 +2622,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { available |= MiscTweak.BAN_LUCKY_EGG.getValue(); available |= MiscTweak.RETAIN_ALT_FORMES.getValue(); available |= MiscTweak.NATIONAL_DEX_AT_START.getValue(); + available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue(); return available; } @@ -2640,6 +2641,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { } } else if (tweak == MiscTweak.NATIONAL_DEX_AT_START) { patchForNationalDex(); + } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) { + enableGuaranteedPokemonCatching(); } } @@ -2731,6 +2734,30 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { } } + // TODO: Battle CRO for XY + private void enableGuaranteedPokemonCatching() { + try { + byte[] battleCRO = readFile(romEntry.getFile("Battle")); + int offset = find(battleCRO, Gen6Constants.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? + // cmp r6, #0xFF000 + // 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. + battleCRO[offset] = 0x00; + battleCRO[offset + 1] = 0x00; + battleCRO[offset + 2] = 0x00; + battleCRO[offset + 3] = 0x00; + writeFile(romEntry.getFile("Battle"), battleCRO); + } + } catch (IOException e) { + throw new RandomizerIOException(e); + } + } + @Override public List getTMMoves() { String tmDataPrefix = Gen6Constants.tmDataPrefix; @@ -4092,6 +4119,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { long expectedCRC32 = romEntry.files.get(fileKey).expectedCRC32s[index]; long actualCRC32 = actualFileCRC32s.get(fileKey); if (expectedCRC32 != actualCRC32) { + System.out.println(actualCRC32); return false; } } -- cgit v1.2.3