summaryrefslogtreecommitdiff
path: root/src/com/dabomstew/pkrandom/romhandlers
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2021-12-03 21:13:44 -0800
committertom-overton <tom.overton@outlook.com>2021-12-03 21:13:44 -0800
commitfa40dfc68ffc23e181823aeb61bf9b76357b8ec9 (patch)
tree2956752e1f1bf8c3f9a2c6ffa8db5431617028db /src/com/dabomstew/pkrandom/romhandlers
parent58909132cb438049223d8369e23a6101453288d1 (diff)
XY: Fix hardcoded in-game trade text
Diffstat (limited to 'src/com/dabomstew/pkrandom/romhandlers')
-rw-r--r--src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java36
1 files changed, 35 insertions, 1 deletions
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;