summaryrefslogtreecommitdiff
path: root/src/com/dabomstew
diff options
context:
space:
mode:
authortom-overton <tom.overton@outlook.com>2021-12-16 12:38:00 -0800
committertom-overton <tom.overton@outlook.com>2021-12-16 12:38:00 -0800
commit790af2e873d1c4be0ceb8654f4e48134bc7d51ff (patch)
tree29b95ba9eb072e372a01030a629446ce1abcdce8 /src/com/dabomstew
parent65026e179ddbcab08393af7db0d99574f45d629f (diff)
Only allow the latest update for a given 3DS game to be loaded
Diffstat (limited to 'src/com/dabomstew')
-rwxr-xr-xsrc/com/dabomstew/pkrandom/FileFunctions.java13
-rw-r--r--src/com/dabomstew/pkrandom/Settings.java4
-rw-r--r--src/com/dabomstew/pkrandom/config/gen6_offsets.ini5
-rw-r--r--src/com/dabomstew/pkrandom/config/gen7_offsets.ini4
-rw-r--r--src/com/dabomstew/pkrandom/ctr/AMX.java5
-rw-r--r--src/com/dabomstew/pkrandom/ctr/BFLIM.java12
-rw-r--r--src/com/dabomstew/pkrandom/ctr/Mini.java2
-rw-r--r--src/com/dabomstew/pkrandom/ctr/NCCH.java123
-rw-r--r--src/com/dabomstew/pkrandom/exceptions/UnsupportedUpdateException.java35
-rw-r--r--src/com/dabomstew/pkrandom/newgui/Bundle.properties1
-rw-r--r--src/com/dabomstew/pkrandom/newgui/NewRandomizerGUI.java6
-rw-r--r--src/com/dabomstew/pkrandom/romhandlers/Abstract3DSRomHandler.java71
-rwxr-xr-xsrc/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java12
-rwxr-xr-xsrc/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java22
-rwxr-xr-xsrc/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java4
-rw-r--r--src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java91
-rw-r--r--src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java99
17 files changed, 322 insertions, 187 deletions
diff --git a/src/com/dabomstew/pkrandom/FileFunctions.java b/src/com/dabomstew/pkrandom/FileFunctions.java
index 3f0adbe..1c2a9fd 100755
--- a/src/com/dabomstew/pkrandom/FileFunctions.java
+++ b/src/com/dabomstew/pkrandom/FileFunctions.java
@@ -120,10 +120,14 @@ public class FileFunctions {
}
public static int read2ByteInt(byte[] data, int index) {
+ return (data[index + 1] & 0xFF) | ((data[index] & 0xFF) << 8);
+ }
+
+ public static int read2ByteIntLittleEndian(byte[] data, int index) {
return (data[index] & 0xFF) | ((data[index + 1] & 0xFF) << 8);
}
- public static void write2ByteInt(byte[] data, int offset, int value) {
+ public static void write2ByteIntLittleEndian(byte[] data, int offset, int value) {
data[offset] = (byte) (value & 0xFF);
data[offset + 1] = (byte) ((value >> 8) & 0xFF);
}
@@ -171,6 +175,13 @@ public class FileFunctions {
}
}
+ public static int read2ByteIntFromFile(RandomAccessFile file, long offset) throws IOException {
+ byte[] buf = new byte[2];
+ file.seek(offset);
+ file.readFully(buf);
+ return read2ByteInt(buf, 0);
+ }
+
public static int readIntFromFile(RandomAccessFile file, long offset) throws IOException {
byte[] buf = new byte[4];
file.seek(offset);
diff --git a/src/com/dabomstew/pkrandom/Settings.java b/src/com/dabomstew/pkrandom/Settings.java
index 1302cae..521a468 100644
--- a/src/com/dabomstew/pkrandom/Settings.java
+++ b/src/com/dabomstew/pkrandom/Settings.java
@@ -648,8 +648,8 @@ public class Settings {
settings.setBanBadRandomStarterHeldItems(restoreState(data[4], 5));
settings.setAllowStarterAltFormes(restoreState(data[4],6));
- settings.setCustomStarters(new int[] { FileFunctions.read2ByteInt(data, 5) + 1,
- FileFunctions.read2ByteInt(data, 7) + 1, FileFunctions.read2ByteInt(data, 9) + 1 });
+ settings.setCustomStarters(new int[] { FileFunctions.read2ByteIntLittleEndian(data, 5) + 1,
+ FileFunctions.read2ByteIntLittleEndian(data, 7) + 1, FileFunctions.read2ByteIntLittleEndian(data, 9) + 1 });
settings.setMovesetsMod(restoreEnum(MovesetsMod.class, data[11], 2, // UNCHANGED
1, // RANDOM_PREFER_SAME_TYPE
diff --git a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini
index 1f6fb2e..9de5d3e 100644
--- a/src/com/dabomstew/pkrandom/config/gen6_offsets.ini
+++ b/src/com/dabomstew/pkrandom/config/gen6_offsets.ini
@@ -74,6 +74,7 @@ BoxLegendaryScriptOffsets=[4658, 5430, 16798]
LinkedStaticEncounterOffsets=[1:3, 2:12]
MainGameLegendaries=[716]
RoamingLegendaryOffsets=[6, 7, 8]
+FullyUpdatedVersionNumber=5232
[Y]
Game=CTR-P-EK2A
@@ -84,6 +85,7 @@ CopyFrom=CTR-P-EKJA
BoxLegendaryOffsets=[1, 3]
BoxLegendaryScriptOffsets=[4670, 5456, 17266]
MainGameLegendaries=[717]
+FullyUpdatedVersionNumber=5216
[Omega Ruby]
Game=CTR-P-ECRA
@@ -158,6 +160,7 @@ RayquazaEncounterScriptNumber=31
LinkedStaticEncounterOffsets=[26:49, 27:50, 29:58, 80:56, 81:57, 75:76]
MainGameLegendaries=[381,383]
MegaStoneItemScriptNumber=57
+FullyUpdatedVersionNumber=7280
[Alpha Sapphire]
Game=CTR-P-ECLA
@@ -165,4 +168,4 @@ TitleId=000400000011C500
Type=ORAS
Acronym=AS
CopyFrom=CTR-P-ECRA
-MainGameLegendaries=[380,382] \ No newline at end of file
+MainGameLegendaries=[380,382]
diff --git a/src/com/dabomstew/pkrandom/config/gen7_offsets.ini b/src/com/dabomstew/pkrandom/config/gen7_offsets.ini
index cfb9682..2c9c1a4 100644
--- a/src/com/dabomstew/pkrandom/config/gen7_offsets.ini
+++ b/src/com/dabomstew/pkrandom/config/gen7_offsets.ini
@@ -57,6 +57,7 @@ CosmoemEvolutionNumber=791
LinkedStaticEncounterOffsets=[112:113, 120:131, 124:130] // UBs probably need to be added to this too
MainGameLegendaries=[791]
ZygardeScriptLevelOffsets=[0x19D6, 0x19F8]
+FullyUpdatedVersionNumber=2112
[Moon]
Game=CTR-P-BNEA
@@ -127,6 +128,7 @@ CosmoemEvolutionNumber=791
LinkedStaticEncounterOffsets=[127:128, 135:146, 139:145] // Unused SM UBs need to be added to this, probably other stuff too
MainGameLegendaries=[800]
ZygardeScriptLevelOffsets=[0x1B3E, 0x1B60]
+FullyUpdatedVersionNumber=2080
[Ultra Moon]
Game=CTR-P-A2BA
@@ -135,4 +137,4 @@ Type=USUM
Acronym=UM
CopyFrom=CTR-P-A2AA
WildPokemon=a/0/8/3
-CosmoemEvolutionNumber=792 \ No newline at end of file
+CosmoemEvolutionNumber=792
diff --git a/src/com/dabomstew/pkrandom/ctr/AMX.java b/src/com/dabomstew/pkrandom/ctr/AMX.java
index 6287ac7..456a7ce 100644
--- a/src/com/dabomstew/pkrandom/ctr/AMX.java
+++ b/src/com/dabomstew/pkrandom/ctr/AMX.java
@@ -27,7 +27,6 @@ import com.dabomstew.pkrandom.exceptions.RandomizerIOException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
@@ -87,8 +86,8 @@ public class AMX {
throw new IOException();
}
- ptrOffset = FileFunctions.read2ByteInt(encData,8);
- ptrCount = FileFunctions.read2ByteInt(encData,0xA);
+ ptrOffset = FileFunctions.read2ByteIntLittleEndian(encData,8);
+ ptrCount = FileFunctions.read2ByteIntLittleEndian(encData,0xA);
scriptInstrStart = FileFunctions.readFullIntLittleEndian(encData,0xC);
scriptMovementStart = FileFunctions.readFullIntLittleEndian(encData,0x10);
diff --git a/src/com/dabomstew/pkrandom/ctr/BFLIM.java b/src/com/dabomstew/pkrandom/ctr/BFLIM.java
index 37dfaa0..f644add 100644
--- a/src/com/dabomstew/pkrandom/ctr/BFLIM.java
+++ b/src/com/dabomstew/pkrandom/ctr/BFLIM.java
@@ -85,7 +85,7 @@ public class BFLIM {
int x = SwizzleLUT[px] & 7;
int y = (SwizzleLUT[px] - x) >> 3;
int outputOffset = (tx + x + ((height - 1 - (ty + y)) * width)) * 4;
- int value = FileFunctions.read2ByteInt(data, inputOffset);
+ int value = FileFunctions.read2ByteIntLittleEndian(data, inputOffset);
if (image.format == 7) {
decodeRGBA5551(output, outputOffset, value);
} else if (image.format == 8) {
@@ -164,11 +164,11 @@ public class BFLIM {
if (signature != 0x464C494D) {
throw new IllegalArgumentException("Invalid BFLIM: cannot find FLIM header");
}
- boolean bigEndian = FileFunctions.read2ByteInt(bflimBytes, headerOffset + 4) == 0xFFFE;
+ boolean bigEndian = FileFunctions.read2ByteIntLittleEndian(bflimBytes, headerOffset + 4) == 0xFFFE;
if (bigEndian) {
throw new IllegalArgumentException("Unsupported BFLIM: this is a big endian BFLIM");
}
- int headerSize = FileFunctions.read2ByteInt(bflimBytes, headerOffset + 6);
+ int headerSize = FileFunctions.read2ByteIntLittleEndian(bflimBytes, headerOffset + 6);
if (headerSize != 0x14) {
throw new IllegalArgumentException("Invalid BFLIM: header length does not equal 0x14");
}
@@ -192,9 +192,9 @@ public class BFLIM {
throw new IllegalArgumentException("Invalid BFLIM: cannot find imag header");
}
size = FileFunctions.readFullIntLittleEndian(bflimBytes, imageHeaderOffset + 4);
- width = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 8);
- height = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 10);
- alignment = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 12);
+ width = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 8);
+ height = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 10);
+ alignment = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 12);
format = bflimBytes[imageHeaderOffset + 14];
flags = bflimBytes[imageHeaderOffset + 15];
imageSize = FileFunctions.readFullIntLittleEndian(bflimBytes, imageHeaderOffset + 16);
diff --git a/src/com/dabomstew/pkrandom/ctr/Mini.java b/src/com/dabomstew/pkrandom/ctr/Mini.java
index 7833fd3..490d10f 100644
--- a/src/com/dabomstew/pkrandom/ctr/Mini.java
+++ b/src/com/dabomstew/pkrandom/ctr/Mini.java
@@ -83,7 +83,7 @@ public class Mini {
return null;
}
- int count = FileFunctions.read2ByteInt(fileData, 2);
+ int count = FileFunctions.read2ByteIntLittleEndian(fileData, 2);
int ctr = 4;
int start = FileFunctions.readFullIntLittleEndian(fileData, ctr);
ctr += 4;
diff --git a/src/com/dabomstew/pkrandom/ctr/NCCH.java b/src/com/dabomstew/pkrandom/ctr/NCCH.java
index 0d9cfa9..34bbc5a 100644
--- a/src/com/dabomstew/pkrandom/ctr/NCCH.java
+++ b/src/com/dabomstew/pkrandom/ctr/NCCH.java
@@ -33,12 +33,12 @@ import java.security.*;
import java.util.*;
public class NCCH {
-
private String romFilename;
private RandomAccessFile baseRom;
private long ncchStartingOffset;
private String productCode;
private String titleId;
+ private int version;
private long exefsOffset, romfsOffset, fileDataOffset;
private ExefsFileHeader codeFileHeader;
private SMDH smdh;
@@ -56,6 +56,10 @@ public class NCCH {
private static final int media_unit_size = 0x200;
private static final int header_and_exheader_size = 0xA00;
+ private static final int ncsd_magic = 0x4E435344;
+ private static final int cia_header_size = 0x2020;
+ private static final int ncch_magic = 0x4E434348;
+ private static final int ncch_and_ncsd_magic_offset = 0x100;
private static final int exefs_header_size = 0x200;
private static final int romfs_header_size = 0x5C;
private static final int romfs_magic_1 = 0x49564643;
@@ -63,13 +67,18 @@ public class NCCH {
private static final int level3_header_size = 0x28;
private static final int metadata_unused = 0xFFFFFFFF;
- public NCCH(String filename, long ncchStartingOffset, String productCode, String titleId) throws IOException {
+ public NCCH(String filename, String productCode, String titleId) throws IOException {
this.romFilename = filename;
this.baseRom = new RandomAccessFile(filename, "r");
- this.ncchStartingOffset = ncchStartingOffset;
+ this.ncchStartingOffset = NCCH.getCXIOffsetInFile(filename);
this.productCode = productCode;
this.titleId = titleId;
this.romOpen = true;
+
+ if (this.ncchStartingOffset != -1) {
+ this.version = this.readVersionFromFile();
+ }
+
// TMP folder?
String rawFilename = new File(filename).getName();
String dataFolder = "tmp_" + rawFilename.substring(0, rawFilename.lastIndexOf('.'));
@@ -775,6 +784,10 @@ public class NCCH {
return titleId;
}
+ public int getVersion() {
+ return version;
+ }
+
public static int alignInt(int num, int alignment) {
int mask = ~(alignment - 1);
return (num + (alignment - 1)) & mask;
@@ -785,6 +798,110 @@ public class NCCH {
return (num + (alignment - 1)) & mask;
}
+ private int readVersionFromFile() {
+ try {
+ // Only CIAs can define a version in their TMD. If this is a different ROM type,
+ // just exit out early.
+ int magic = FileFunctions.readIntFromFile(this.baseRom, ncch_and_ncsd_magic_offset);
+ if (magic == ncch_magic || magic == ncsd_magic) {
+ return 0;
+ }
+
+ // For CIAs, we need to read the title metadata (TMD) in order to retrieve the version.
+ // The TMD is after the certificate chain and ticket.
+ int certChainSize = FileFunctions.readLittleEndianIntFromFile(this.baseRom, 0x08);
+ int ticketSize = FileFunctions.readLittleEndianIntFromFile(this.baseRom, 0x0C);
+ long certChainOffset = NCCH.alignLong(cia_header_size, 64);
+ long ticketOffset = NCCH.alignLong(certChainOffset + certChainSize, 64);
+ long tmdOffset = NCCH.alignLong(ticketOffset + ticketSize, 64);
+
+ // At the start of the TMD is a signature whose length varies based on what type of signature it is.
+ int signatureType = FileFunctions.readIntFromFile(this.baseRom, tmdOffset);
+ int signatureSize, paddingSize;
+ switch (signatureType) {
+ case 0x010003:
+ signatureSize = 0x200;
+ paddingSize = 0x3C;
+ break;
+ case 0x010004:
+ signatureSize = 0x100;
+ paddingSize = 0x3C;
+ break;
+ case 0x010005:
+ signatureSize = 0x3C;
+ paddingSize = 0x40;
+ break;
+ default:
+ signatureSize = -1;
+ paddingSize = -1;
+ break;
+ }
+ if (signatureSize == -1) {
+ // This shouldn't happen in practice, since all used and valid signature types are represented
+ // in the above switch. However, if we can't find the right signature type, then it's probably
+ // an invalid CIA anyway, so we're unlikely to get good version information out of it.
+ return 0;
+ }
+
+ // After the signature is the TMD header, which actually contains the version information.
+ long tmdHeaderOffset = tmdOffset + 4 + signatureSize + paddingSize;
+ return FileFunctions.read2ByteIntFromFile(this.baseRom, tmdHeaderOffset + 0x9C);
+ } catch (IOException e) {
+ throw new RandomizerIOException(e);
+ }
+ }
+
+ // At the bare minimum, a 3DS game consists of what's known as a CXI file, which
+ // is just an NCCH that contains executable code. However, 3DS games are packaged
+ // in various containers that can hold other NCCH files like the game manual and
+ // firmware updates, among other things. This function's determines the location
+ // of the CXI regardless of the container.
+ public static long getCXIOffsetInFile(String filename) {
+ try {
+ RandomAccessFile rom = new RandomAccessFile(filename, "r");
+ int ciaHeaderSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x00);
+ if (ciaHeaderSize == cia_header_size) {
+ // This *might* be a CIA; let's do our best effort to try to get
+ // a CXI out of this.
+ int certChainSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x08);
+ int ticketSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x0C);
+ int tmdFileSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x10);
+
+ // If this is *really* a CIA, we'll find our CXI at the beginning of the
+ // content section, which is after the certificate chain, ticket, and TMD
+ long certChainOffset = NCCH.alignLong(ciaHeaderSize, 64);
+ long ticketOffset = NCCH.alignLong(certChainOffset + certChainSize, 64);
+ long tmdOffset = NCCH.alignLong(ticketOffset + ticketSize, 64);
+ long contentOffset = NCCH.alignLong(tmdOffset + tmdFileSize, 64);
+ int magic = FileFunctions.readIntFromFile(rom, contentOffset + ncch_and_ncsd_magic_offset);
+ if (magic == ncch_magic) {
+ // This CIA's content contains a valid CXI!
+ return contentOffset;
+ }
+ }
+
+ // We don't put the following code in an else-block because there *might*
+ // exist a totally-valid CXI or CCI whose first four bytes just so
+ // *happen* to be the same as the first four bytes of a CIA file.
+ int magic = FileFunctions.readIntFromFile(rom, ncch_and_ncsd_magic_offset);
+ rom.close();
+ if (magic == ncch_magic) {
+ // Magic is NCCH, so this just a straight-up NCCH/CXI; there is no container
+ // around the game data. Thus, the CXI offset is the beginning of the file.
+ return 0;
+ } else if (magic == ncsd_magic) {
+ // Magic is NCSD, so this is almost certainly a CCI. The CXI is always
+ // a fixed distance away from the start.
+ return 0x4000;
+ } else {
+ // This doesn't seem to be a valid 3DS file.
+ return -1;
+ }
+ } catch (IOException e) {
+ throw new RandomizerIOException(e);
+ }
+ }
+
private class ExefsFileHeader {
public String filename;
public int offset;
diff --git a/src/com/dabomstew/pkrandom/exceptions/UnsupportedUpdateException.java b/src/com/dabomstew/pkrandom/exceptions/UnsupportedUpdateException.java
new file mode 100644
index 0000000..a5ab07d
--- /dev/null
+++ b/src/com/dabomstew/pkrandom/exceptions/UnsupportedUpdateException.java
@@ -0,0 +1,35 @@
+package com.dabomstew.pkrandom.exceptions;
+
+/*----------------------------------------------------------------------------*/
+/*-- EncryptedROMException.java - exception for a supplied game update is --*/
+/*-- not supported by the randomizer. --*/
+/*-- --*/
+/*-- Part of "Universal Pokemon Randomizer ZX" by the UPR-ZX team --*/
+/*-- Pokemon and any associated names and the like are --*/
+/*-- trademark and (C) Nintendo 1996-2020. --*/
+/*-- --*/
+/*-- The custom code written here is licensed under the terms of the GPL: --*/
+/*-- --*/
+/*-- This program is free software: you can redistribute it and/or modify --*/
+/*-- it under the terms of the GNU General Public License as published by --*/
+/*-- the Free Software Foundation, either version 3 of the License, or --*/
+/*-- (at your option) any later version. --*/
+/*-- --*/
+/*-- This program is distributed in the hope that it will be useful, --*/
+/*-- but WITHOUT ANY WARRANTY; without even the implied warranty of --*/
+/*-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --*/
+/*-- GNU General Public License for more details. --*/
+/*-- --*/
+/*-- You should have received a copy of the GNU General Public License --*/
+/*-- along with this program. If not, see <http://www.gnu.org/licenses/>. --*/
+/*----------------------------------------------------------------------------*/
+
+public class UnsupportedUpdateException extends RuntimeException {
+ public UnsupportedUpdateException(Exception e) {
+ super(e);
+ }
+
+ public UnsupportedUpdateException(String text) {
+ super(text);
+ }
+}
diff --git a/src/com/dabomstew/pkrandom/newgui/Bundle.properties b/src/com/dabomstew/pkrandom/newgui/Bundle.properties
index e0351ce..4e12acb 100644
--- a/src/com/dabomstew/pkrandom/newgui/Bundle.properties
+++ b/src/com/dabomstew/pkrandom/newgui/Bundle.properties
@@ -371,6 +371,7 @@ GUI.openedZIPfile=%s is a ZIP archive, not a ROM.\nYou should extract it and try
GUI.openedRARfile=%s is a RAR archive, not a ROM.\nYou should extract it and try to randomize the actual ROM file inside.
GUI.openedIPSfile=%s is an IPS patch, not a ROM.\nYou should apply it to a ROM first before trying to randomize the result.
GUI.unsupportedRom=Could not load %s - it's not a supported ROM.
+GUI.unsupportedUpdate=Could not load %s - it's not a supported game update.
GUI.encryptedRom=<html>Could not load %s as it appears to be an encrypted ROM.<br />Universal Pokemon Randomizer ZX does not currently support encrypted 3DS ROMs.<br/>If you believe your ROM is actually decrypted, please try decrypting your ROM with a different tool or try using a different ROM.
GUI.romSupportPrefix=Support:
GUI.processFailed=There was an unhandled exception trying to process your ROM.\nA log file containing some details has been saved to %s.\nPlease include this file in any bug reports you do.
diff --git a/src/com/dabomstew/pkrandom/newgui/NewRandomizerGUI.java b/src/com/dabomstew/pkrandom/newgui/NewRandomizerGUI.java
index e109105..a9a1e98 100644
--- a/src/com/dabomstew/pkrandom/newgui/NewRandomizerGUI.java
+++ b/src/com/dabomstew/pkrandom/newgui/NewRandomizerGUI.java
@@ -31,6 +31,7 @@ import com.dabomstew.pkrandom.constants.GlobalConstants;
import com.dabomstew.pkrandom.exceptions.EncryptedROMException;
import com.dabomstew.pkrandom.exceptions.InvalidSupplementFilesException;
import com.dabomstew.pkrandom.exceptions.RandomizationException;
+import com.dabomstew.pkrandom.exceptions.UnsupportedUpdateException;
import com.dabomstew.pkrandom.pokemon.ExpCurve;
import com.dabomstew.pkrandom.pokemon.GenRestrictions;
import com.dabomstew.pkrandom.pokemon.Pokemon;
@@ -1154,6 +1155,11 @@ public class NewRandomizerGUI {
} catch (EncryptedROMException ex) {
JOptionPane.showMessageDialog(mainPanel,
String.format(bundle.getString("GUI.encryptedRom"), fh.getAbsolutePath()));
+ return;
+ } catch (UnsupportedUpdateException ex) {
+ JOptionPane.showMessageDialog(mainPanel,
+ String.format(bundle.getString("GUI.unsupportedUpdate"), fh.getName()));
+ return;
}
removeGameUpdateMenuItem.setVisible(true);
romNameLabel.setText(romHandler.getROMName() + " (" + romHandler.getGameUpdateVersion() + ")");
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Abstract3DSRomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Abstract3DSRomHandler.java
index 246f108..054aa8a 100644
--- a/src/com/dabomstew/pkrandom/romhandlers/Abstract3DSRomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Abstract3DSRomHandler.java
@@ -29,6 +29,7 @@ import com.dabomstew.pkrandom.ctr.GARCArchive;
import com.dabomstew.pkrandom.ctr.NCCH;
import com.dabomstew.pkrandom.exceptions.EncryptedROMException;
import com.dabomstew.pkrandom.exceptions.RandomizerIOException;
+import com.dabomstew.pkrandom.exceptions.UnsupportedUpdateException;
import com.dabomstew.pkrandom.pokemon.Type;
import java.io.FileInputStream;
@@ -45,11 +46,6 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
private NCCH gameUpdate;
private String loadedFN;
- private static final int ncch_magic = 0x4E434348;
- private static final int ncsd_magic = 0x4E435344;
- private static final int cia_header_size = 0x2020;
- private static final int ncch_and_ncsd_magic_offset = 0x100;
-
public Abstract3DSRomHandler(Random random, PrintStream logStream) {
super(random, logStream);
}
@@ -63,7 +59,7 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
}
// Load inner rom
try {
- baseRom = new NCCH(filename, getCXIOffsetInFile(filename), productCode, titleId);
+ baseRom = new NCCH(filename, productCode, titleId);
if (!baseRom.isDecrypted()) {
throw new EncryptedROMException(filename);
}
@@ -110,6 +106,8 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
return true;
}
+ protected abstract boolean isGameUpdateSupported(int version);
+
@Override
public boolean hasGameUpdateLoaded() {
return gameUpdate != null;
@@ -120,10 +118,14 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
String productCode = getProductCodeFromFile(filename);
String titleId = getTitleIdFromFile(filename);
try {
- gameUpdate = new NCCH(filename, getCXIOffsetInFile(filename), productCode, titleId);
+ gameUpdate = new NCCH(filename, productCode, titleId);
if (!gameUpdate.isDecrypted()) {
throw new EncryptedROMException(filename);
}
+ int version = gameUpdate.getVersion();
+ if (!this.isGameUpdateSupported(version)) {
+ throw new UnsupportedUpdateException(filename);
+ }
} catch (IOException e) {
throw new RandomizerIOException(e);
}
@@ -252,60 +254,9 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
return baseRom.getTitleId();
}
- // At the bare minimum, a 3DS game consists of what's known as a CXI file, which
- // is just an NCCH that contains executable code. However, 3DS games are packaged
- // in various containers that can hold other NCCH files like the game manual and
- // firmware updates, among other things. This function's determines the location
- // of the CXI regardless of the container.
- protected static long getCXIOffsetInFile(String filename) {
- try {
- RandomAccessFile rom = new RandomAccessFile(filename, "r");
- int ciaHeaderSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x00);
- if (ciaHeaderSize == cia_header_size) {
- // This *might* be a CIA; let's do our best effort to try to get
- // a CXI out of this.
- int certChainSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x08);
- int ticketSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x0C);
- int tmdFileSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x10);
-
- // If this is *really* a CIA, we'll find our CXI at the beginning of the
- // content section, which is after the certificate chain, ticket, and TMD
- long certChainOffset = NCCH.alignLong(ciaHeaderSize, 64);
- long ticketOffset = NCCH.alignLong(certChainOffset + certChainSize, 64);
- long tmdOffset = NCCH.alignLong(ticketOffset + ticketSize, 64);
- long contentOffset = NCCH.alignLong(tmdOffset + tmdFileSize, 64);
- int magic = FileFunctions.readIntFromFile(rom, contentOffset + ncch_and_ncsd_magic_offset);
- if (magic == ncch_magic) {
- // This CIA's content contains a valid CXI!
- return contentOffset;
- }
- }
-
- // We don't put the following code in an else-block because there *might*
- // exist a totally-valid CXI or CCI whose first four bytes just so
- // *happen* to be the same as the first four bytes of a CIA file.
- int magic = FileFunctions.readIntFromFile(rom, ncch_and_ncsd_magic_offset);
- rom.close();
- if (magic == ncch_magic) {
- // Magic is NCCH, so this just a straight-up NCCH/CXI; there is no container
- // around the game data. Thus, the CXI offset is the beginning of the file.
- return 0;
- } else if (magic == ncsd_magic) {
- // Magic is NCSD, so this is almost certainly a CCI. The CXI is always
- // a fixed distance away from the start.
- return 0x4000;
- } else {
- // This doesn't seem to be a valid 3DS file.
- return -1;
- }
- } catch (IOException e) {
- throw new RandomizerIOException(e);
- }
- }
-
protected static String getProductCodeFromFile(String filename) {
try {
- long ncchStartingOffset = getCXIOffsetInFile(filename);
+ long ncchStartingOffset = NCCH.getCXIOffsetInFile(filename);
if (ncchStartingOffset == -1) {
return null;
}
@@ -321,7 +272,7 @@ public abstract class Abstract3DSRomHandler extends AbstractRomHandler {
public static String getTitleIdFromFile(String filename) {
try {
- long ncchStartingOffset = getCXIOffsetInFile(filename);
+ long ncchStartingOffset = NCCH.getCXIOffsetInFile(filename);
if (ncchStartingOffset == -1) {
return null;
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java
index ac76af6..4e83de2 100755
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java
@@ -2780,11 +2780,11 @@ public class Gen3RomHandler extends AbstractGBRomHandler {
if (!skipShops.contains(i)) {
int offset = shopItemOffsets[i];
List<Integer> items = new ArrayList<>();
- int val = FileFunctions.read2ByteInt(rom, offset);
+ int val = FileFunctions.read2ByteIntLittleEndian(rom, offset);
while (val != 0x0000) {
items.add(val);
offset += 2;
- val = FileFunctions.read2ByteInt(rom, offset);
+ val = FileFunctions.read2ByteIntLittleEndian(rom, offset);
}
Shop shop = new Shop();
shop.items = items;
@@ -2805,7 +2805,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler {
int offset = shopItemOffsets[i];
Iterator<Integer> iterItems = thisShop.items.iterator();
while (iterItems.hasNext()) {
- FileFunctions.write2ByteInt(rom, offset, iterItems.next());
+ FileFunctions.write2ByteIntLittleEndian(rom, offset, iterItems.next());
offset += 2;
}
}
@@ -2820,7 +2820,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler {
for (int i = 1; i < itemCount; i++) {
int balancedPrice = Gen3Constants.balancedItemPrices.get(i) * 10;
int offset = itemDataOffset + (i * entrySize) + 16;
- FileFunctions.write2ByteInt(rom, offset, balancedPrice);
+ FileFunctions.write2ByteIntLittleEndian(rom, offset, balancedPrice);
}
}
@@ -2843,7 +2843,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler {
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < pickupItemCount; i++) {
int itemOffset = pickupItemsTableOffset + (sizeOfPickupEntry * i);
- int item = FileFunctions.read2ByteInt(rom, itemOffset);
+ int item = FileFunctions.read2ByteIntLittleEndian(rom, itemOffset);
PickupItem pickupItem = new PickupItem(item);
pickupItems.add(pickupItem);
}
@@ -2898,7 +2898,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler {
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < pickupItems.size(); i++) {
int itemOffset = pickupItemsTableOffset + (sizeOfPickupEntry * i);
- FileFunctions.write2ByteInt(rom, itemOffset, pickupItems.get(i).item);
+ FileFunctions.write2ByteIntLittleEndian(rom, itemOffset, pickupItems.get(i).item);
}
}
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
index ce4c3d5..7045f34 100755
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java
@@ -3972,13 +3972,13 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
for (int i = 0; i < shopCount; i++) {
if (!skipShops.contains(i)) {
List<Integer> items = new ArrayList<>();
- int val = (FileFunctions.read2ByteInt(arm9, offset));
+ int val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
while ((val & 0xFFFF) != 0xFFFF) {
if (val != 0) {
items.add(val);
}
offset += 2;
- val = (FileFunctions.read2ByteInt(arm9, offset));
+ val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
}
offset += 2;
Shop shop = new Shop();
@@ -3987,7 +3987,7 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
shop.isMainGame = mainGameShops.contains(i);
shopItemsMap.put(i, shop);
} else {
- while ((FileFunctions.read2ByteInt(arm9, offset) & 0xFFFF) != 0xFFFF) {
+ while ((FileFunctions.read2ByteIntLittleEndian(arm9, offset) & 0xFFFF) != 0xFFFF) {
offset += 2;
}
offset += 2;
@@ -4006,20 +4006,20 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
for (int i = 0; i < shopCount; i++) {
Shop thisShop = shopItems.get(i);
if (thisShop == null || thisShop.items == null) {
- while ((FileFunctions.read2ByteInt(arm9, offset) & 0xFFFF) != 0xFFFF) {
+ while ((FileFunctions.read2ByteIntLittleEndian(arm9, offset) & 0xFFFF) != 0xFFFF) {
offset += 2;
}
offset += 2;
continue;
}
Iterator<Integer> iterItems = thisShop.items.iterator();
- int val = (FileFunctions.read2ByteInt(arm9, offset));
+ int val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
while ((val & 0xFFFF) != 0xFFFF) {
if (val != 0) {
- FileFunctions.write2ByteInt(arm9,offset,iterItems.next());
+ FileFunctions.write2ByteIntLittleEndian(arm9,offset,iterItems.next());
}
offset += 2;
- val = (FileFunctions.read2ByteInt(arm9, offset));
+ val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
}
offset += 2;
}
@@ -4070,13 +4070,13 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
if (pickupItemsTableOffset > 0 && rarePickupItemsTableOffset > 0) {
for (int i = 0; i < Gen4Constants.numberOfCommonPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
- int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteIntLittleEndian(battleOverlay, itemOffset);
PickupItem pickupItem = new PickupItem(item);
pickupItems.add(pickupItem);
}
for (int i = 0; i < Gen4Constants.numberOfRarePickupItems; i++) {
int itemOffset = rarePickupItemsTableOffset + (2 * i);
- int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteIntLittleEndian(battleOverlay, itemOffset);
PickupItem pickupItem = new PickupItem(item);
pickupItems.add(pickupItem);
}
@@ -4112,12 +4112,12 @@ public class Gen4RomHandler extends AbstractDSRomHandler {
for (int i = 0; i < Gen4Constants.numberOfCommonPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
int item = itemIterator.next().item;
- FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
}
for (int i = 0; i < Gen4Constants.numberOfRarePickupItems; i++) {
int itemOffset = rarePickupItemsTableOffset + (2 * i);
int item = itemIterator.next().item;
- FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
}
writeOverlay(romEntry.getInt("BattleOvlNumber"), battleOverlay);
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java
index edb1571..18c05cf 100755
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java
@@ -3933,7 +3933,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < Gen5Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
- int item = FileFunctions.read2ByteInt(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteIntLittleEndian(battleOverlay, itemOffset);
PickupItem pickupItem = new PickupItem(item);
pickupItems.add(pickupItem);
}
@@ -3968,7 +3968,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler {
for (int i = 0; i < Gen5Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
int item = pickupItems.get(i).item;
- FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
}
writeOverlay(romEntry.getInt("PickupOvlNumber"), battleOverlay);
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java
index 098d7fa..081b868 100644
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java
@@ -357,8 +357,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
}
// Held Items?
- int item1 = FileFunctions.read2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset);
- int item2 = FileFunctions.read2ByteInt(stats, Gen6Constants.bsRareHeldItemOffset);
+ int item1 = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset);
+ int item2 = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset);
if (item1 == item2) {
// guaranteed
@@ -370,16 +370,16 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
pkmn.guaranteedHeldItem = 0;
pkmn.commonHeldItem = item1;
pkmn.rareHeldItem = item2;
- pkmn.darkGrassHeldItem = FileFunctions.read2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset);
+ pkmn.darkGrassHeldItem = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset);
}
int formeCount = stats[Gen6Constants.bsFormeCountOffset] & 0xFF;
if (formeCount > 1) {
if (!altFormes.keySet().contains(pkmn.number)) {
- int firstFormeOffset = FileFunctions.read2ByteInt(stats, Gen6Constants.bsFormeOffset);
+ int firstFormeOffset = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsFormeOffset);
if (firstFormeOffset != 0) {
for (int i = 1; i < formeCount; i++) {
- altFormes.put(firstFormeOffset + i - 1,new FormeInfo(pkmn.number,i,FileFunctions.read2ByteInt(stats,Gen6Constants.bsFormeSpriteOffset))); // Assumes that formes are in memory in the same order as their numbers
+ altFormes.put(firstFormeOffset + i - 1,new FormeInfo(pkmn.number,i,FileFunctions.read2ByteIntLittleEndian(stats,Gen6Constants.bsFormeSpriteOffset))); // Assumes that formes are in memory in the same order as their numbers
if (Gen6Constants.actuallyCosmeticForms.contains(firstFormeOffset+i-1)) {
if (pkmn.number != Species.pikachu && pkmn.number != Species.cherrim) { // No Pikachu/Cherrim
pkmn.cosmeticForms += 1;
@@ -590,6 +590,11 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
}
@Override
+ protected boolean isGameUpdateSupported(int version) {
+ return version == romEntry.numbers.get("FullyUpdatedVersionNumber");
+ }
+
+ @Override
protected String getGameVersion() {
List<String> titleScreenText = getStrings(false, romEntry.getInt("TitleScreenTextOffset"));
if (titleScreenText.size() > romEntry.getInt("UpdateStringOffset")) {
@@ -642,13 +647,13 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
// Held items
if (pkmn.guaranteedHeldItem > 0) {
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem);
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem);
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset, 0);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset, 0);
} else {
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem);
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.rareHeldItem);
- FileFunctions.write2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.rareHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem);
}
if (pkmn.fullName().equals("Meowstic")) {
@@ -916,7 +921,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < count; i++) {
if (!starterIndices.contains(i)) continue;
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size);
+ int species = FileFunctions.read2ByteIntLittleEndian(staticCRO,offset+i*size);
Pokemon pokemon = pokes[species];
int forme = staticCRO[offset+i*size + 4];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -1996,7 +2001,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
int offset = romEntry.getInt("StaticPokemonOffset");
for (int i = 0; i < count; i++) {
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size);
+ int species = FileFunctions.read2ByteIntLittleEndian(staticCRO,offset+i*size);
Pokemon pokemon = pokes[species];
int forme = staticCRO[offset+i*size + 2];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -2008,7 +2013,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
se.pkmn = pokemon;
se.forme = forme;
se.level = staticCRO[offset+i*size + 3];
- short heldItem = (short)FileFunctions.read2ByteInt(staticCRO,offset+i*size + 4);
+ short heldItem = (short)FileFunctions.read2ByteIntLittleEndian(staticCRO,offset+i*size + 4);
if (heldItem < 0) {
heldItem = 0;
}
@@ -2026,7 +2031,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < count; i++) {
if (skipStarters.contains(i)) continue;
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size);
+ int species = FileFunctions.read2ByteIntLittleEndian(staticCRO,offset+i*size);
Pokemon pokemon = pokes[species];
int forme = staticCRO[offset+i*size + 4];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -2044,7 +2049,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
}
se.heldItem = heldItem;
if (romEntry.romType == Gen6Constants.Type_ORAS) {
- int metLocation = FileFunctions.read2ByteInt(staticCRO, offset + i * size + 18);
+ int metLocation = FileFunctions.read2ByteIntLittleEndian(staticCRO, offset + i * size + 18);
if (metLocation == 0xEA64) {
se.isEgg = true;
}
@@ -2156,7 +2161,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
byte[] data = localScript.decData;
int[] boxLegendaryScriptOffsets = romEntry.arrayEntries.get("BoxLegendaryScriptOffsets");
for (int i = 0; i < boxLegendaryScriptOffsets.length; i++) {
- FileFunctions.write2ByteInt(data, boxLegendaryScriptOffsets[i], boxLegendarySpecies);
+ FileFunctions.write2ByteIntLittleEndian(data, boxLegendaryScriptOffsets[i], boxLegendarySpecies);
}
byte[] modifiedScript = localScript.getBytes();
System.arraycopy(modifiedScript, 0, boxLegendaryRoomData, Gen6Constants.boxLegendaryLocalScriptOffsetXY, modifiedScript.length);
@@ -2266,7 +2271,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
AMX rayquazaAMX = new AMX(scriptGarc.files.get(rayquazaScriptFile).get(0));
byte[] data = rayquazaAMX.decData;
for (int i = 0; i < Gen6Constants.rayquazaScriptOffsetsORAS.length; i++) {
- FileFunctions.write2ByteInt(data, Gen6Constants.rayquazaScriptOffsetsORAS[i], rayquazaEncounterSpecies);
+ FileFunctions.write2ByteIntLittleEndian(data, Gen6Constants.rayquazaScriptOffsetsORAS[i], rayquazaEncounterSpecies);
}
scriptGarc.setFile(rayquazaScriptFile, rayquazaAMX.getBytes());
writeGARC(romEntry.getString("Scripts"), scriptGarc);
@@ -2581,7 +2586,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
if (mtOffset > 0) {
int val = 0;
while (val != 0xFFFF) {
- val = FileFunctions.read2ByteInt(code,mtOffset);
+ val = FileFunctions.read2ByteIntLittleEndian(code,mtOffset);
mtOffset += 2;
if (val == 0x26E || val == 0xFFFF) continue;
mtMoves.add(val);
@@ -2598,16 +2603,16 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
if (mtOffset > 0) {
mtOffset += Gen6Constants.tutorsShopPrefix.length() / 2; // because it was a prefix
for (int i = 0; i < Gen6Constants.tutorMoveCount; i++) {
- FileFunctions.write2ByteInt(code,mtOffset + i*8, moves.get(i));
+ FileFunctions.write2ByteIntLittleEndian(code,mtOffset + i*8, moves.get(i));
}
}
mtOffset = getMoveTutorMovesOffset();
if (mtOffset > 0) {
for (int move: moves) {
- int val = FileFunctions.read2ByteInt(code,mtOffset);
+ int val = FileFunctions.read2ByteIntLittleEndian(code,mtOffset);
if (val == 0x26E) mtOffset += 2;
- FileFunctions.write2ByteInt(code,mtOffset,move);
+ FileFunctions.write2ByteIntLittleEndian(code,mtOffset,move);
mtOffset += 2;
}
}
@@ -3291,7 +3296,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
AMX normalItemAMX = new AMX(scriptGarc.files.get(normalItemsFile).get(0));
byte[] data = normalItemAMX.decData;
for (int i = normalItemsOffset; i < data.length; i += 12) {
- int item = FileFunctions.read2ByteInt(data,i);
+ int item = FileFunctions.read2ByteIntLittleEndian(data,i);
fieldItems.add(item);
}
@@ -3302,7 +3307,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
AMX hiddenItemAMX = new AMX(scriptGarc.files.get(hiddenItemsFile).get(0));
data = hiddenItemAMX.decData;
for (int i = hiddenItemsOffset; i < data.length; i += 12) {
- int item = FileFunctions.read2ByteInt(data,i);
+ int item = FileFunctions.read2ByteIntLittleEndian(data,i);
fieldItems.add(item);
}
} else {
@@ -3311,7 +3316,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
if (offsHidden > 0) {
offsHidden += hiddenItemsPrefix.length() / 2;
for (int i = 0; i < Gen6Constants.hiddenItemCountORAS; i++) {
- int item = FileFunctions.read2ByteInt(code, offsHidden + (i * 0xE) + 2);
+ int item = FileFunctions.read2ByteIntLittleEndian(code, offsHidden + (i * 0xE) + 2);
fieldItems.add(item);
}
}
@@ -3337,7 +3342,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
AMX megaStoneItemEvent = new AMX(megaStoneItemEventBytes);
for (int i = 0; i < Gen6Constants.megastoneTableLengthORAS; i++) {
int offset = Gen6Constants.megastoneTableStartingOffsetORAS + (i * Gen6Constants.megastoneTableEntrySizeORAS);
- int item = FileFunctions.read2ByteInt(megaStoneItemEvent.decData, offset);
+ int item = FileFunctions.read2ByteIntLittleEndian(megaStoneItemEvent.decData, offset);
fieldMegaStones.add(item);
}
return fieldMegaStones;
@@ -3354,7 +3359,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
byte[] data = normalItemAMX.decData;
for (int i = normalItemsOffset; i < data.length; i += 12) {
int item = iterItems.next();
- FileFunctions.write2ByteInt(data,i,item);
+ FileFunctions.write2ByteIntLittleEndian(data,i,item);
}
scriptGarc.setFile(normalItemsFile,normalItemAMX.getBytes());
@@ -3366,7 +3371,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
data = hiddenItemAMX.decData;
for (int i = hiddenItemsOffset; i < data.length; i += 12) {
int item = iterItems.next();
- FileFunctions.write2ByteInt(data,i,item);
+ FileFunctions.write2ByteIntLittleEndian(data,i,item);
}
scriptGarc.setFile(hiddenItemsFile,hiddenItemAMX.getBytes());
} else {
@@ -3376,7 +3381,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
offsHidden += hiddenItemsPrefix.length() / 2;
for (int i = 0; i < Gen6Constants.hiddenItemCountORAS; i++) {
int item = iterItems.next();
- FileFunctions.write2ByteInt(code,offsHidden + (i * 0xE) + 2, item);
+ FileFunctions.write2ByteIntLittleEndian(code,offsHidden + (i * 0xE) + 2, item);
}
}
}
@@ -3396,9 +3401,9 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
// There are some duplicate entries for certain Mega Stones, and we're not quite sure why.
// Set them to the same item for sanity's sake.
int replacementItem = megaStoneMap.get(oldItem);
- FileFunctions.write2ByteInt(megaStoneItemEvent.decData, offset, replacementItem);
+ FileFunctions.write2ByteIntLittleEndian(megaStoneItemEvent.decData, offset, replacementItem);
} else {
- FileFunctions.write2ByteInt(megaStoneItemEvent.decData, offset, newItem);
+ FileFunctions.write2ByteIntLittleEndian(megaStoneItemEvent.decData, offset, newItem);
megaStoneMap.put(oldItem, newItem);
}
}
@@ -3425,15 +3430,15 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < count; i++) {
IngameTrade trade = new IngameTrade();
trade.nickname = tradeStrings.get(textOffset + i);
- trade.givenPokemon = pokes[FileFunctions.read2ByteInt(code,offset)];
+ trade.givenPokemon = pokes[FileFunctions.read2ByteIntLittleEndian(code,offset)];
trade.ivs = new int[6];
for (int iv = 0; iv < 6; iv++) {
trade.ivs[iv] = code[offset + 5 + iv];
}
- trade.otId = FileFunctions.read2ByteInt(code,offset + 0xE);
- trade.item = FileFunctions.read2ByteInt(code,offset + 0x10);
+ trade.otId = FileFunctions.read2ByteIntLittleEndian(code,offset + 0xE);
+ trade.item = FileFunctions.read2ByteIntLittleEndian(code,offset + 0x10);
trade.otName = tradeStrings.get(textOffset + count + i);
- trade.requestedPokemon = pokes[FileFunctions.read2ByteInt(code,offset + 0x20)];
+ trade.requestedPokemon = pokes[FileFunctions.read2ByteIntLittleEndian(code,offset + 0x20)];
trades.add(trade);
offset += Gen6Constants.ingameTradeSize;
}
@@ -3456,14 +3461,14 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < count; i++) {
IngameTrade trade = trades.get(i);
tradeStrings.set(textOffset + i, trade.nickname);
- FileFunctions.write2ByteInt(code,offset,trade.givenPokemon.number);
+ FileFunctions.write2ByteIntLittleEndian(code,offset,trade.givenPokemon.number);
for (int iv = 0; iv < 6; iv++) {
code[offset + 5 + iv] = (byte)trade.ivs[iv];
}
- FileFunctions.write2ByteInt(code,offset + 0xE,trade.otId);
- FileFunctions.write2ByteInt(code,offset + 0x10,trade.item);
+ FileFunctions.write2ByteIntLittleEndian(code,offset + 0xE,trade.otId);
+ FileFunctions.write2ByteIntLittleEndian(code,offset + 0x10,trade.item);
tradeStrings.set(textOffset + count + i, trade.otName);
- FileFunctions.write2ByteInt(code,offset + 0x20,
+ FileFunctions.write2ByteIntLittleEndian(code,offset + 0x20,
trade.requestedPokemon == null ? 0 : trade.requestedPokemon.number);
offset += Gen6Constants.ingameTradeSize;
@@ -3604,7 +3609,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
if (!badShop) {
List<Integer> items = new ArrayList<>();
for (int j = 0; j < shopItemSizes[i]; j++) {
- items.add(FileFunctions.read2ByteInt(code,offset));
+ items.add(FileFunctions.read2ByteIntLittleEndian(code,offset));
offset += 2;
}
Shop shop = new Shop();
@@ -3651,7 +3656,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
Iterator<Integer> iterItems = shopContents.iterator();
for (int j = 0; j < shopItemSizes[i]; j++) {
Integer item = iterItems.next();
- FileFunctions.write2ByteInt(code,offset,item);
+ FileFunctions.write2ByteIntLittleEndian(code,offset,item);
offset += 2;
}
}
@@ -3697,7 +3702,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
if (pickupItemsTableOffset > 0) {
for (int i = 0; i < Gen6Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
- int item = FileFunctions.read2ByteInt(code, itemOffset);
+ int item = FileFunctions.read2ByteIntLittleEndian(code, itemOffset);
PickupItem pickupItem = new PickupItem(item);
pickupItems.add(pickupItem);
}
@@ -3727,7 +3732,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < Gen6Constants.numberOfPickupItems; i++) {
int itemOffset = pickupItemsTableOffset + (2 * i);
int item = pickupItems.get(i).item;
- FileFunctions.write2ByteInt(code, itemOffset, item);
+ FileFunctions.write2ByteIntLittleEndian(code, itemOffset, item);
}
}
}
diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
index 5fc3732..52b33ed 100644
--- a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
+++ b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java
@@ -387,8 +387,8 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
pkmn.callRate = stats[Gen7Constants.bsCallRateOffset] & 0xFF;
// Held Items?
- int item1 = FileFunctions.read2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset);
- int item2 = FileFunctions.read2ByteInt(stats, Gen7Constants.bsRareHeldItemOffset);
+ int item1 = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset);
+ int item2 = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset);
if (item1 == item2) {
// guaranteed
@@ -400,13 +400,13 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
pkmn.guaranteedHeldItem = 0;
pkmn.commonHeldItem = item1;
pkmn.rareHeldItem = item2;
- pkmn.darkGrassHeldItem = FileFunctions.read2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset);
+ pkmn.darkGrassHeldItem = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset);
}
int formeCount = stats[Gen7Constants.bsFormeCountOffset] & 0xFF;
if (formeCount > 1) {
if (!altFormes.keySet().contains(pkmn.number)) {
- int firstFormeOffset = FileFunctions.read2ByteInt(stats, Gen7Constants.bsFormeOffset);
+ int firstFormeOffset = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsFormeOffset);
if (firstFormeOffset != 0) {
int j = 0;
int jMax = 0;
@@ -414,7 +414,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
Set<Integer> altFormesWithCosmeticForms = Gen7Constants.getAltFormesWithCosmeticForms(romEntry.romType).keySet();
for (int i = 1; i < formeCount; i++) {
if (j == 0 || j > jMax) {
- altFormes.put(firstFormeOffset + i - 1,new FormeInfo(pkmn.number,i,FileFunctions.read2ByteInt(stats,Gen7Constants.bsFormeSpriteOffset))); // Assumes that formes are in memory in the same order as their numbers
+ altFormes.put(firstFormeOffset + i - 1,new FormeInfo(pkmn.number,i,FileFunctions.read2ByteIntLittleEndian(stats,Gen7Constants.bsFormeSpriteOffset))); // Assumes that formes are in memory in the same order as their numbers
if (Gen7Constants.getActuallyCosmeticForms(romEntry.romType).contains(firstFormeOffset+i-1)) {
if (!Gen7Constants.getIgnoreForms(romEntry.romType).contains(firstFormeOffset+i-1)) { // Skip ignored forms (identical or confusing cosmetic forms)
pkmn.cosmeticForms += 1;
@@ -422,7 +422,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
}
}
} else {
- altFormes.put(firstFormeOffset + i - 1,new FormeInfo(theAltForme,j,FileFunctions.read2ByteInt(stats,Gen7Constants.bsFormeSpriteOffset)));
+ altFormes.put(firstFormeOffset + i - 1,new FormeInfo(theAltForme,j,FileFunctions.read2ByteIntLittleEndian(stats,Gen7Constants.bsFormeSpriteOffset)));
j++;
}
if (altFormesWithCosmeticForms.contains(firstFormeOffset + i - 1)) {
@@ -704,13 +704,13 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
// Held items
if (pkmn.guaranteedHeldItem > 0) {
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem);
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem);
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset, 0);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset, 0);
} else {
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem);
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.rareHeldItem);
- FileFunctions.write2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.rareHeldItem);
+ FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem);
}
if (pkmn.fullName().equals("Meowstic")) {
@@ -929,6 +929,11 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
}
@Override
+ protected boolean isGameUpdateSupported(int version) {
+ return version == romEntry.numbers.get("FullyUpdatedVersionNumber");
+ }
+
+ @Override
protected String getGameVersion() {
List<String> titleScreenText = getStrings(false, romEntry.getInt("TitleScreenTextOffset"));
if (titleScreenText.size() > romEntry.getInt("UpdateStringOffset")) {
@@ -985,7 +990,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < 3; i++) {
int offset = i * 0x14;
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(giftsFile, offset);
+ int species = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset);
Pokemon pokemon = pokes[species];
int forme = giftsFile[offset + 2];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -997,7 +1002,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
se.pkmn = pokemon;
se.forme = forme;
se.level = giftsFile[offset + 3];
- se.heldItem = FileFunctions.read2ByteInt(giftsFile, offset + 8);
+ se.heldItem = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset + 8);
starters.add(se);
}
} catch (IOException e) {
@@ -1383,15 +1388,15 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
ZoneData[] zoneData = new ZoneData[zoneDataBytes.length / ZoneData.size];
for (int i = 0; i < zoneData.length; i++) {
zoneData[i] = new ZoneData(zoneDataBytes, i);
- zoneData[i].worldIndex = FileFunctions.read2ByteInt(worldData, i * 0x2);
+ zoneData[i].worldIndex = FileFunctions.read2ByteIntLittleEndian(worldData, i * 0x2);
zoneData[i].locationName = locationList.get(zoneData[i].parentMap);
byte[] world = worlds.get(zoneData[i].worldIndex);
int mappingOffset = FileFunctions.readFullIntLittleEndian(world, 0x8);
for (int offset = mappingOffset; offset < world.length; offset += 4) {
- int potentialZoneIndex = FileFunctions.read2ByteInt(world, offset);
+ int potentialZoneIndex = FileFunctions.read2ByteIntLittleEndian(world, offset);
if (potentialZoneIndex == i) {
- zoneData[i].areaIndex = FileFunctions.read2ByteInt(world, offset + 0x2);
+ zoneData[i].areaIndex = FileFunctions.read2ByteIntLittleEndian(world, offset + 0x2);
break;
}
}
@@ -1636,7 +1641,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
Pokemon boostedPokemon = uniquePokemon.get(i);
int auraNumber = getAuraNumberForHighestStat(boostedPokemon);
int speciesNumber = boostedPokemon.getBaseNumber();
- FileFunctions.write2ByteInt(battleCRO, offset + (i * 0x10), speciesNumber);
+ FileFunctions.write2ByteIntLittleEndian(battleCRO, offset + (i * 0x10), speciesNumber);
battleCRO[offset + (i * 0x10) + 2] = (byte) auraNumber;
}
writeFile(romEntry.getString("Battle"), battleCRO);
@@ -1780,7 +1785,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int i: totemIndices) {
int offset = i * 0x38;
TotemPokemon totem = new TotemPokemon();
- int species = FileFunctions.read2ByteInt(staticEncountersFile, offset);
+ int species = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset);
Pokemon pokemon = pokes[species];
int forme = staticEncountersFile[offset + 2];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -1792,7 +1797,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
totem.pkmn = pokemon;
totem.forme = forme;
totem.level = staticEncountersFile[offset + 3];
- int heldItem = FileFunctions.read2ByteInt(staticEncountersFile, offset + 4);
+ int heldItem = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset + 4);
if (heldItem == 0xFFFF) {
heldItem = 0;
}
@@ -1889,7 +1894,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int i = 3; i < numberOfGifts; i++) {
int offset = i * 0x14;
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(giftsFile, offset);
+ int species = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset);
Pokemon pokemon = pokes[species];
int forme = giftsFile[offset + 2];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -1901,7 +1906,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
se.pkmn = pokemon;
se.forme = forme;
se.level = giftsFile[offset + 3];
- se.heldItem = FileFunctions.read2ByteInt(giftsFile, offset + 8);
+ se.heldItem = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset + 8);
se.isEgg = giftsFile[offset + 10] == 1;
statics.add(se);
}
@@ -1927,7 +1932,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
private StaticEncounter readStaticEncounter(byte[] staticEncountersFile, int offset) {
StaticEncounter se = new StaticEncounter();
- int species = FileFunctions.read2ByteInt(staticEncountersFile, offset);
+ int species = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset);
Pokemon pokemon = pokes[species];
int forme = staticEncountersFile[offset + 2];
if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) {
@@ -1939,7 +1944,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
se.pkmn = pokemon;
se.forme = forme;
se.level = staticEncountersFile[offset + 3];
- int heldItem = FileFunctions.read2ByteInt(staticEncountersFile, offset + 4);
+ int heldItem = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset + 4);
if (heldItem == 0xFFFF) {
heldItem = 0;
}
@@ -1975,7 +1980,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
if (speciesOffset > 0 && formeOffset > 0) {
speciesOffset += Gen7Constants.zygardeAssemblySpeciesPrefix.length() / 2; // because it was a prefix
formeOffset += Gen7Constants.zygardeAssemblyFormePrefix.length() / 2; // because it was a prefix
- int species = FileFunctions.read2ByteInt(code, speciesOffset);
+ int species = FileFunctions.read2ByteIntLittleEndian(code, speciesOffset);
// The original code for this passed in the forme via a parameter, stored that onto
// the stack, then did a ldr to put that stack variable into r0 before finally
@@ -2108,7 +2113,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
if (speciesOffset > 0 && formeOffset > 0) {
speciesOffset += Gen7Constants.zygardeAssemblySpeciesPrefix.length() / 2; // because it was a prefix
formeOffset += Gen7Constants.zygardeAssemblyFormePrefix.length() / 2; // because it was a prefix
- FileFunctions.write2ByteInt(code, speciesOffset, se.pkmn.getBaseNumber());
+ FileFunctions.write2ByteIntLittleEndian(code, speciesOffset, se.pkmn.getBaseNumber());
// Just write "mov r0, #forme" to where the game originally loaded the forme.
code[formeOffset] = (byte) se.forme;
@@ -2329,7 +2334,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
mtOffset += Gen7Constants.tutorsPrefix.length() / 2;
int val = 0;
while (val != 0xFFFF) {
- val = FileFunctions.read2ByteInt(code, mtOffset);
+ val = FileFunctions.read2ByteIntLittleEndian(code, mtOffset);
mtOffset += 2;
if (val == 0xFFFF) continue;
mtMoves.add(val);
@@ -2345,7 +2350,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
if (mtOffset > 0) {
mtOffset += Gen7Constants.tutorsPrefix.length() / 2;
for (int move: moves) {
- FileFunctions.write2ByteInt(code,mtOffset, move);
+ FileFunctions.write2ByteIntLittleEndian(code,mtOffset, move);
mtOffset += 2;
}
}
@@ -2354,7 +2359,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
byte[] tutorCRO = readFile(romEntry.getString("ShopsAndTutors"));
for (int i = 0; i < moves.size(); i++) {
int offset = Gen7Constants.tutorsOffset + i * 4;
- FileFunctions.write2ByteInt(tutorCRO, offset, moves.get(i));
+ FileFunctions.write2ByteIntLittleEndian(tutorCRO, offset, moves.get(i));
}
writeFile(romEntry.getString("ShopsAndTutors"), tutorCRO);
} catch (IOException e) {
@@ -2946,7 +2951,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
int itemCount = itemData[0];
for (int j = 0; j < itemCount; j++) {
- fieldItems.add(FileFunctions.read2ByteInt(itemData,(j * 64) + 52));
+ fieldItems.add(FileFunctions.read2ByteIntLittleEndian(itemData,(j * 64) + 52));
}
}
}
@@ -2957,7 +2962,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
int pileCount = berryPileData[0];
for (int j = 0; j < pileCount; j++) {
for (int k = 0; k < 7; k++) {
- fieldItems.add(FileFunctions.read2ByteInt(berryPileData,4 + j*68 + 54 + k*2));
+ fieldItems.add(FileFunctions.read2ByteIntLittleEndian(berryPileData,4 + j*68 + 54 + k*2));
}
}
}
@@ -2984,7 +2989,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
int itemCount = itemData[0];
for (int j = 0; j < itemCount; j++) {
- FileFunctions.write2ByteInt(itemData,(j * 64) + 52,iterItems.next());
+ FileFunctions.write2ByteIntLittleEndian(itemData,(j * 64) + 52,iterItems.next());
}
}
}
@@ -2999,7 +3004,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int j = 0; j < pileCount; j++) {
for (int k = 0; k < 7; k++) {
- FileFunctions.write2ByteInt(berryPileData,4 + j*68 + 54 + k*2,iterItems.next());
+ FileFunctions.write2ByteIntLittleEndian(berryPileData,4 + j*68 + 54 + k*2,iterItems.next());
}
}
}
@@ -3026,8 +3031,8 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < numberOfIngameTrades; i++) {
int offset = i * 0x34;
IngameTrade trade = new IngameTrade();
- int givenSpecies = FileFunctions.read2ByteInt(tradesFile, offset);
- int requestedSpecies = FileFunctions.read2ByteInt(tradesFile, offset + 0x2C);
+ int givenSpecies = FileFunctions.read2ByteIntLittleEndian(tradesFile, offset);
+ int requestedSpecies = FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 0x2C);
Pokemon givenPokemon = pokes[givenSpecies];
Pokemon requestedPokemon = pokes[requestedSpecies];
int forme = tradesFile[offset + 4];
@@ -3039,14 +3044,14 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
}
trade.givenPokemon = givenPokemon;
trade.requestedPokemon = requestedPokemon;
- trade.nickname = tradeStrings.get(FileFunctions.read2ByteInt(tradesFile, offset + 2));
- trade.otName = tradeStrings.get(FileFunctions.read2ByteInt(tradesFile, offset + 0x18));
+ trade.nickname = tradeStrings.get(FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 2));
+ trade.otName = tradeStrings.get(FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 0x18));
trade.otId = FileFunctions.readFullIntLittleEndian(tradesFile, offset + 0x10);
trade.ivs = new int[6];
for (int iv = 0; iv < 6; iv++) {
trade.ivs[iv] = tradesFile[offset + 6 + iv];
}
- trade.item = FileFunctions.read2ByteInt(tradesFile, offset + 0x14);
+ trade.item = FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 0x14);
if (trade.item < 0) {
trade.item = 0;
}
@@ -3076,16 +3081,16 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
forme = givenPokemon.formeNumber;
givenPokemon = givenPokemon.baseForme;
}
- FileFunctions.write2ByteInt(tradesFile, offset, givenPokemon.number);
+ FileFunctions.write2ByteIntLittleEndian(tradesFile, offset, givenPokemon.number);
tradesFile[offset + 4] = (byte) forme;
- FileFunctions.write2ByteInt(tradesFile, offset + 0x2C, trade.requestedPokemon.number);
- tradeStrings.set(FileFunctions.read2ByteInt(tradesFile, offset + 2), trade.nickname);
- tradeStrings.set(FileFunctions.read2ByteInt(tradesFile, offset + 0x18), trade.otName);
+ FileFunctions.write2ByteIntLittleEndian(tradesFile, offset + 0x2C, trade.requestedPokemon.number);
+ tradeStrings.set(FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 2), trade.nickname);
+ tradeStrings.set(FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 0x18), trade.otName);
FileFunctions.writeFullIntLittleEndian(tradesFile, offset + 0x10, trade.otId);
for (int iv = 0; iv < 6; iv++) {
tradesFile[offset + 6 + iv] = (byte) trade.ivs[iv];
}
- FileFunctions.write2ByteInt(tradesFile, offset + 0x14, trade.item);
+ FileFunctions.write2ByteIntLittleEndian(tradesFile, offset + 0x14, trade.item);
List<Integer> hardcodedTextOffsetsForThisTrade = hardcodedTradeTextOffsets.get(i);
if (hardcodedTextOffsetsForThisTrade != null) {
@@ -3214,7 +3219,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
if (!badShop) {
List<Integer> items = new ArrayList<>();
for (int j = 0; j < shopItemSizes[i]; j++) {
- items.add(FileFunctions.read2ByteInt(shopsCRO, offset));
+ items.add(FileFunctions.read2ByteIntLittleEndian(shopsCRO, offset));
offset += 2;
}
Shop shop = new Shop();
@@ -3261,7 +3266,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
Iterator<Integer> iterItems = shopContents.iterator();
for (int j = 0; j < shopItemSizes[i]; j++) {
Integer item = iterItems.next();
- FileFunctions.write2ByteInt(shopsCRO, offset, item);
+ FileFunctions.write2ByteIntLittleEndian(shopsCRO, offset, item);
offset += 2;
}
}
@@ -3294,7 +3299,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
int numberOfPickupItems = FileFunctions.readFullIntLittleEndian(pickupData, 0) - 1; // GameFreak why???
for (int i = 0; i < numberOfPickupItems; i++) {
int offset = 4 + (i * 0xC);
- int item = FileFunctions.read2ByteInt(pickupData, offset);
+ int item = FileFunctions.read2ByteIntLittleEndian(pickupData, offset);
PickupItem pickupItem = new PickupItem(item);
for (int levelRange = 0; levelRange < 10; levelRange++) {
pickupItem.probabilities[levelRange] = pickupData[offset + levelRange + 2];
@@ -3315,7 +3320,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler {
for (int i = 0; i < pickupItems.size(); i++) {
int offset = 4 + (i * 0xC);
int item = pickupItems.get(i).item;
- FileFunctions.write2ByteInt(pickupData, offset, item);
+ FileFunctions.write2ByteIntLittleEndian(pickupData, offset, item);
}
this.writeGARC(romEntry.getString("PickupData"), pickupGarc);
} catch (IOException e) {