diff options
author | tom-overton <tom.overton@outlook.com> | 2021-12-03 21:13:44 -0800 |
---|---|---|
committer | tom-overton <tom.overton@outlook.com> | 2021-12-03 21:13:44 -0800 |
commit | fa40dfc68ffc23e181823aeb61bf9b76357b8ec9 (patch) | |
tree | 2956752e1f1bf8c3f9a2c6ffa8db5431617028db /src/com/dabomstew/pkrandom | |
parent | 58909132cb438049223d8369e23a6101453288d1 (diff) |
XY: Fix hardcoded in-game trade text
Diffstat (limited to 'src/com/dabomstew/pkrandom')
3 files changed, 54 insertions, 1 deletions
diff --git a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini index 5943ffc..1f6fb2e 100644 --- a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini +++ b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini @@ -15,6 +15,14 @@ TextStringsIt=a/0/7/6 TextStringsDe=a/0/7/7 TextStringsEs=a/0/7/8 TextStringsKo=a/0/7/9 +StoryTextJaKana=a/0/8/0 +StoryTextJaKanji=a/0/8/1 +StoryText=a/0/8/2 +StoryTextFr=a/0/8/3 +StoryTextIt=a/0/8/4 +StoryTextDe=a/0/8/5 +StoryTextEs=a/0/8/6 +StoryTextKo=a/0/8/7 PokemonGraphics=a/0/9/3 PokedexAreaData=a/2/0/2 MoveData=a/2/1/2 @@ -94,6 +102,14 @@ TextStringsIt=a/0/7/5 TextStringsDe=a/0/7/6 TextStringsEs=a/0/7/7 TextStringsKo=a/0/7/8 +StoryTextJaKana=a/0/7/9 +StoryTextJaKanji=a/0/8/0 +StoryText=a/0/8/1 +StoryTextFr=a/0/8/2 +StoryTextIt=a/0/8/3 +StoryTextDe=a/0/8/4 +StoryTextEs=a/0/8/5 +StoryTextKo=a/0/8/6 PokemonGraphics=a/0/9/1 PokedexAreaData=a/1/8/1 MoveData=a/1/8/9 diff --git a/src/com/dabomstew/pkrandom/constants/Gen6Constants.java b/src/com/dabomstew/pkrandom/constants/Gen6Constants.java index 445fdee..040ac1d 100644 --- a/src/com/dabomstew/pkrandom/constants/Gen6Constants.java +++ b/src/com/dabomstew/pkrandom/constants/Gen6Constants.java @@ -249,6 +249,9 @@ public class Gen6Constants { public static final String xyRoamerFreeSpacePostfix = "540095E50220A0E30810A0E1", xyRoamerSpeciesLocator = "9040A0030400000A", xyRoamerLevelPrefix = "B020DDE13F3BC1E3"; + public static List<Integer> xyHardcodedTradeOffsets = Arrays.asList(1, 8); + public static List<Integer> xyHardcodedTradeTexts = Arrays.asList(129, 349); + public static final List<Integer> consumableHeldItems = setupAllConsumableItems(); private static List<Integer> setupAllConsumableItems() { diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java index 7d9d3af..b04d953 100644 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java @@ -254,6 +254,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { try { stringsGarc = readGARC(romEntry.getString("TextStrings"),true); + storyTextGarc = readGARC(romEntry.getString("StoryText"), true); } catch (IOException e) { throw new RandomizerIOException(e); } @@ -577,6 +578,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { try { writeCode(code); writeGARC(romEntry.getString("TextStrings"), stringsGarc); + writeGARC(romEntry.getString("StoryText"), storyTextGarc); } catch (IOException e) { throw new RandomizerIOException(e); } @@ -3440,7 +3442,9 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { @Override public void setIngameTrades(List<IngameTrade> trades) { - + List<IngameTrade> oldTrades = this.getIngameTrades(); + int[] hardcodedTradeOffsets = romEntry.arrayEntries.get("HardcodedTradeOffsets"); + int[] hardcodedTradeTexts = romEntry.arrayEntries.get("HardcodedTradeTexts"); int count = romEntry.getInt("IngameTradeCount"); String prefix = Gen6Constants.getIngameTradesPrefix(romEntry.romType); List<String> tradeStrings = getStrings(false, romEntry.getInt("IngameTradesTextOffset")); @@ -3461,11 +3465,41 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { FileFunctions.write2ByteInt(code,offset + 0x20, trade.requestedPokemon == null ? 0 : trade.requestedPokemon.number); offset += Gen6Constants.ingameTradeSize; + + // In XY, there are some trades that use hardcoded strings. Go and forcibly update + // the story text so that the trainer says what they want to trade. + if (romEntry.romType == Gen6Constants.Type_XY && Gen6Constants.xyHardcodedTradeOffsets.contains(i)) { + int hardcodedTradeIndex = Gen6Constants.xyHardcodedTradeOffsets.indexOf(i); + updateHardcodedTradeText(oldTrades.get(i), trade, Gen6Constants.xyHardcodedTradeTexts.get(hardcodedTradeIndex)); + } } this.setStrings(false, romEntry.getInt("IngameTradesTextOffset"), tradeStrings); } } + // NOTE: This method is kind of stupid, in that it doesn't try to reflow the text to better fit; it just + // blindly replaces the Pokemon's name. However, it seems to work well enough for what we need. + private void updateHardcodedTradeText(IngameTrade oldTrade, IngameTrade newTrade, int hardcodedTradeTextFile) { + List<String> hardcodedTradeStrings = getStrings(true, hardcodedTradeTextFile); + Pokemon oldRequested = oldTrade.requestedPokemon; + String oldRequestedName = oldRequested != null ? oldRequested.name : null; + String oldGivenName = oldTrade.givenPokemon.name; + Pokemon newRequested = newTrade.requestedPokemon; + String newRequestedName = newRequested != null ? newRequested.name : null; + String newGivenName = newTrade.givenPokemon.name; + for (int i = 0; i < hardcodedTradeStrings.size(); i++) { + String hardcodedTradeString = hardcodedTradeStrings.get(i); + if (oldRequestedName != null && newRequestedName != null && hardcodedTradeString.contains(oldRequestedName)) { + hardcodedTradeString = hardcodedTradeString.replace(oldRequestedName, newRequestedName); + } + if (hardcodedTradeString.contains(oldGivenName)) { + hardcodedTradeString = hardcodedTradeString.replace(oldGivenName, newGivenName); + } + hardcodedTradeStrings.set(i, hardcodedTradeString); + } + this.setStrings(true, hardcodedTradeTextFile, hardcodedTradeStrings); + } + @Override public boolean hasDVs() { return false; |