summaryrefslogtreecommitdiff
path: root/src/com/dabomstew/pkrandom/romhandlers
diff options
context:
space:
mode:
authorAjarmar <axel.jarmar@gmail.com>2021-12-10 00:08:24 +0100
committerAjarmar <axel.jarmar@gmail.com>2021-12-10 00:08:24 +0100
commit0f3faac583352f62b3a4a43f9d536b0cedfe100b (patch)
tree0dfca28e1e1f2eeb004c65426070862da77b4a79 /src/com/dabomstew/pkrandom/romhandlers
parent8a16bea310af9f5b6a8ca7469f135c7532803cf4 (diff)
parent1cab307a269facce690c4f57aaed7d5f6b86c9b3 (diff)
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'src/com/dabomstew/pkrandom/romhandlers')
-rw-r--r--src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
index 9556293..a527ad6 100644
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
@@ -3061,8 +3061,10 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
@Override
public void setIngameTrades(List<IngameTrade> trades) {
try {
+ List<IngameTrade> oldTrades = this.getIngameTrades();
GARCArchive staticGarc = readGARC(romEntry.getString("StaticPokemon"), true);
List<String> tradeStrings = getStrings(true, romEntry.getInt("IngameTradesTextOffset"));
+ Map<Integer, List<Integer>> hardcodedTradeTextOffsets = Gen7Constants.getHardcodedTradeTextOffsets(romEntry.romType);
byte[] tradesFile = staticGarc.files.get(4).get(0);
int numberOfIngameTrades = tradesFile.length / 0x34;
for (int i = 0; i < numberOfIngameTrades; i++) {
@@ -3084,6 +3086,11 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
tradesFile[offset + 6 + iv] = (byte) trade.ivs[iv];
}
FileFunctions.write2ByteInt(tradesFile, offset + 0x14, trade.item);
+
+ List<Integer> hardcodedTextOffsetsForThisTrade = hardcodedTradeTextOffsets.get(i);
+ if (hardcodedTextOffsetsForThisTrade != null) {
+ updateHardcodedTradeText(oldTrades.get(i), trade, tradeStrings, hardcodedTextOffsetsForThisTrade);
+ }
}
writeGARC(romEntry.getString("StaticPokemon"), staticGarc);
setStrings(true, romEntry.getInt("IngameTradesTextOffset"), tradeStrings);
@@ -3092,6 +3099,21 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
}
}
+ // 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, List<String> tradeStrings, List<Integer> hardcodedTextOffsets) {
+ for (int offset : hardcodedTextOffsets) {
+ String hardcodedText = tradeStrings.get(offset);
+ String oldRequestedName = oldTrade.requestedPokemon.name;
+ String oldGivenName = oldTrade.givenPokemon.name;
+ String newRequestedName = newTrade.requestedPokemon.name;
+ String newGivenName = newTrade.givenPokemon.name;
+ hardcodedText = hardcodedText.replace(oldRequestedName, newRequestedName);
+ hardcodedText = hardcodedText.replace(oldGivenName, newGivenName);
+ tradeStrings.set(offset, hardcodedText);
+ }
+ }
+
@Override
public boolean hasDVs() {
return false;