diff options
author | tom-overton <tom.overton@outlook.com> | 2022-10-21 05:02:00 -0700 |
---|---|---|
committer | Rafael Marçalo <raroma09@gmail.com> | 2022-10-21 22:46:18 +0100 |
commit | 39c6a9d5feb861b4cd6ac5d7ae9276ee48a13845 (patch) | |
tree | 199bc833040c0e7e34effbcd145cad0f8067a095 /src/com/sneed | |
parent | 36e77d2a5e32e3b1f86c31cf97c949bf2437671d (diff) |
Gen 1: Add support for Guaranteed Pokemon Catching
Diffstat (limited to 'src/com/sneed')
-rw-r--r-- | src/com/sneed/pkrandom/constants/Gen1Constants.java | 2 | ||||
-rwxr-xr-x | src/com/sneed/pkrandom/romhandlers/Gen1RomHandler.java | 48 |
2 files changed, 46 insertions, 4 deletions
diff --git a/src/com/sneed/pkrandom/constants/Gen1Constants.java b/src/com/sneed/pkrandom/constants/Gen1Constants.java index 3476103..204608e 100644 --- a/src/com/sneed/pkrandom/constants/Gen1Constants.java +++ b/src/com/sneed/pkrandom/constants/Gen1Constants.java @@ -93,6 +93,8 @@ public class Gen1Constants { public static final int towerMapsStartIndex = 0x90, towerMapsEndIndex = 0x94; + public static final String guaranteedCatchPrefix = "CF7EFE01"; + public static final Type[] typeTable = constructTypeTable(); private static Type[] constructTypeTable() { diff --git a/src/com/sneed/pkrandom/romhandlers/Gen1RomHandler.java b/src/com/sneed/pkrandom/romhandlers/Gen1RomHandler.java index 470d7c7..657df3e 100755 --- a/src/com/sneed/pkrandom/romhandlers/Gen1RomHandler.java +++ b/src/com/sneed/pkrandom/romhandlers/Gen1RomHandler.java @@ -43,10 +43,7 @@ import java.util.TreeMap; import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import com.sneed.pkrandom.FileFunctions;
-import com.sneed.pkrandom.GFXFunctions;
-import com.sneed.pkrandom.MiscTweak;
-import com.sneed.pkrandom.Settings;
+import com.sneed.pkrandom.*;
import com.sneed.pkrandom.constants.*;
import com.sneed.pkrandom.exceptions.RandomizationException;
import com.sneed.pkrandom.exceptions.RandomizerIOException;
@@ -1816,6 +1813,24 @@ public class Gen1RomHandler extends AbstractGBCRomHandler { return (romEntry.getValue("StaticPokemonSupport") > 0) ? "Complete" : "No Static Pokemon";
}
+ private static int find(byte[] haystack, String hexString) {
+ if (hexString.length() % 2 != 0) {
+ return -3; // error
+ }
+ byte[] searchFor = new byte[hexString.length() / 2];
+ for (int i = 0; i < searchFor.length; i++) {
+ searchFor[i] = (byte) Integer.parseInt(hexString.substring(i * 2, i * 2 + 2), 16);
+ }
+ List<Integer> found = RomFunctions.search(haystack, searchFor);
+ if (found.size() == 0) {
+ return -1; // not found
+ } else if (found.size() > 1) {
+ return -2; // not unique
+ } else {
+ return found.get(0);
+ }
+ }
+
private void populateEvolutions() {
for (Pokemon pkmn : pokes) {
if (pkmn != null) {
@@ -2091,6 +2106,8 @@ public class Gen1RomHandler extends AbstractGBCRomHandler { if (romEntry.getValue("CatchingTutorialMonOffset") != 0) {
available |= MiscTweak.RANDOMIZE_CATCHING_TUTORIAL.getValue();
}
+
+ available |= MiscTweak.GUARANTEED_POKEMON_CATCHING.getValue();
return available;
}
@@ -2114,6 +2131,8 @@ public class Gen1RomHandler extends AbstractGBCRomHandler { updateTypeEffectiveness();
} else if (tweak == MiscTweak.RANDOMIZE_CATCHING_TUTORIAL) {
randomizeCatchingTutorial();
+ } else if (tweak == MiscTweak.GUARANTEED_POKEMON_CATCHING) {
+ enableGuaranteedPokemonCatching();
}
}
@@ -2158,6 +2177,27 @@ public class Gen1RomHandler extends AbstractGBCRomHandler { }
}
+ private void enableGuaranteedPokemonCatching() {
+ int offset = find(rom, Gen1Constants.guaranteedCatchPrefix);
+ if (offset > 0) {
+ offset += Gen1Constants.guaranteedCatchPrefix.length() / 2; // because it was a prefix
+
+ // The game ensures that the Master Ball always catches a Pokemon by running the following code:
+ // ; Get the item ID.
+ // ld hl, wcf91
+ // ld a, [hl]
+ //
+ // ; The Master Ball always succeeds.
+ // cp MASTER_BALL
+ // jp z, .captured
+ // By making the jump here unconditional, we can ensure that catching always succeeds no
+ // matter the ball type. We check that the original condition is present just for safety.
+ if (rom[offset] == (byte)0xCA) {
+ rom[offset] = (byte)0xC3;
+ }
+ }
+ }
+
private boolean genericIPSPatch(String ctName) {
String patchName = romEntry.tweakFiles.get(ctName);
if (patchName == null) {
|