diff options
author | tom-overton <tom.overton@outlook.com> | 2021-12-16 13:41:41 -0800 |
---|---|---|
committer | tom-overton <tom.overton@outlook.com> | 2021-12-16 13:41:43 -0800 |
commit | de54f00e18a532366a2a14ef0c9f52b035ab1e0a (patch) | |
tree | ef748acdc76fc40411f724ec46d7ca8b1cf0338f | |
parent | 790af2e873d1c4be0ceb8654f4e48134bc7d51ff (diff) |
Rename FileFunctions functions to call out big endian functions
The little endian functions were used way more often, so they should have short names.
-rw-r--r-- | src/com/dabomstew/pkrandom/CustomNamesSet.java | 4 | ||||
-rwxr-xr-x | src/com/dabomstew/pkrandom/FileFunctions.java | 32 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/Settings.java | 8 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/SettingsUpdater.java | 12 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/ctr/AMX.java | 20 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/ctr/BFLIM.java | 22 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/ctr/Mini.java | 6 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/ctr/NCCH.java | 142 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/ctr/SMDH.java | 2 | ||||
-rwxr-xr-x | src/com/dabomstew/pkrandom/romhandlers/AbstractDSRomHandler.java | 12 | ||||
-rwxr-xr-x | src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java | 18 | ||||
-rwxr-xr-x | src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java | 26 | ||||
-rwxr-xr-x | src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java | 18 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/romhandlers/Gen6RomHandler.java | 128 | ||||
-rw-r--r-- | src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java | 112 | ||||
-rw-r--r-- | src/compressors/DSDecmp.java | 4 |
16 files changed, 283 insertions, 283 deletions
diff --git a/src/com/dabomstew/pkrandom/CustomNamesSet.java b/src/com/dabomstew/pkrandom/CustomNamesSet.java index adbf03d..81396e0 100644 --- a/src/com/dabomstew/pkrandom/CustomNamesSet.java +++ b/src/com/dabomstew/pkrandom/CustomNamesSet.java @@ -72,7 +72,7 @@ public class CustomNamesSet { private List<String> readNamesBlock(InputStream in) throws IOException { // Read the size of the block to come. byte[] szData = FileFunctions.readFullyIntoBuffer(in, 4); - int size = FileFunctions.readFullInt(szData, 0); + int size = FileFunctions.readFullIntBigEndian(szData, 0); if (in.available() < size) { throw new IOException("Invalid size specified."); } @@ -119,7 +119,7 @@ public class CustomNamesSet { } byte[] namesData = outNames.toString().getBytes("UTF-8"); byte[] szData = new byte[4]; - FileFunctions.writeFullInt(szData, 0, namesData.length); + FileFunctions.writeFullIntBigEndian(szData, 0, namesData.length); out.write(szData); out.write(namesData); } diff --git a/src/com/dabomstew/pkrandom/FileFunctions.java b/src/com/dabomstew/pkrandom/FileFunctions.java index 1c2a9fd..00c1f12 100755 --- a/src/com/dabomstew/pkrandom/FileFunctions.java +++ b/src/com/dabomstew/pkrandom/FileFunctions.java @@ -97,7 +97,7 @@ public class FileFunctions { return cns; } - public static long readFullLongLittleEndian(byte[] data, int offset) { + public static long readFullLong(byte[] data, int offset) { ByteBuffer buf = ByteBuffer.allocate(8); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(data, offset, 8); @@ -105,7 +105,7 @@ public class FileFunctions { return buf.getLong(); } - public static int readFullIntLittleEndian(byte[] data, int offset) { + public static int readFullInt(byte[] data, int offset) { ByteBuffer buf = ByteBuffer.allocate(4); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(data, offset, 4); @@ -113,36 +113,36 @@ public class FileFunctions { return buf.getInt(); } - public static int readFullInt(byte[] data, int offset) { + public static int readFullIntBigEndian(byte[] data, int offset) { ByteBuffer buf = ByteBuffer.allocate(4).put(data, offset, 4); buf.rewind(); return buf.getInt(); } - public static int read2ByteInt(byte[] data, int index) { + public static int read2ByteIntBigEndian(byte[] data, int index) { return (data[index + 1] & 0xFF) | ((data[index] & 0xFF) << 8); } - public static int read2ByteIntLittleEndian(byte[] data, int index) { + public static int read2ByteInt(byte[] data, int index) { return (data[index] & 0xFF) | ((data[index + 1] & 0xFF) << 8); } - public static void write2ByteIntLittleEndian(byte[] data, int offset, int value) { + public static void write2ByteInt(byte[] data, int offset, int value) { data[offset] = (byte) (value & 0xFF); data[offset + 1] = (byte) ((value >> 8) & 0xFF); } - public static void writeFullIntLittleEndian(byte[] data, int offset, int value) { + public static void writeFullInt(byte[] data, int offset, int value) { byte[] valueBytes = ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(value).array(); System.arraycopy(valueBytes, 0, data, offset, 4); } - public static void writeFullInt(byte[] data, int offset, int value) { + public static void writeFullIntBigEndian(byte[] data, int offset, int value) { byte[] valueBytes = ByteBuffer.allocate(4).putInt(value).array(); System.arraycopy(valueBytes, 0, data, offset, 4); } - public static void writeFullLongLittleEndian(byte[] data, int offset, long value) { + public static void writeFullLong(byte[] data, int offset, long value) { byte[] valueBytes = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(value).array(); System.arraycopy(valueBytes, 0, data, offset, 8); } @@ -175,25 +175,25 @@ public class FileFunctions { } } - public static int read2ByteIntFromFile(RandomAccessFile file, long offset) throws IOException { + public static int read2ByteBigEndianIntFromFile(RandomAccessFile file, long offset) throws IOException { byte[] buf = new byte[2]; file.seek(offset); file.readFully(buf); - return read2ByteInt(buf, 0); + return read2ByteIntBigEndian(buf, 0); } - public static int readIntFromFile(RandomAccessFile file, long offset) throws IOException { + public static int readBigEndianIntFromFile(RandomAccessFile file, long offset) throws IOException { byte[] buf = new byte[4]; file.seek(offset); file.readFully(buf); - return readFullInt(buf, 0); + return readFullIntBigEndian(buf, 0); } - public static int readLittleEndianIntFromFile(RandomAccessFile file, long offset) throws IOException { + public static int readIntFromFile(RandomAccessFile file, long offset) throws IOException { byte[] buf = new byte[4]; file.seek(offset); file.readFully(buf); - return readFullIntLittleEndian(buf, 0); + return readFullInt(buf, 0); } public static void writeBytesToFile(String filename, byte[] data) throws IOException { @@ -243,7 +243,7 @@ public class FileFunctions { int switches = data[byteIndex] & 0xFF; if (((switches >> switchIndex) & 0x01) == 0x01) { // have to check the CRC - int crc = readFullInt(data, offsetInData); + int crc = readFullIntBigEndian(data, offsetInData); return getFileChecksum(filename) == crc; } diff --git a/src/com/dabomstew/pkrandom/Settings.java b/src/com/dabomstew/pkrandom/Settings.java index 521a468..cfe7da3 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.read2ByteIntLittleEndian(data, 5) + 1,
- FileFunctions.read2ByteIntLittleEndian(data, 7) + 1, FileFunctions.read2ByteIntLittleEndian(data, 9) + 1 });
+ settings.setCustomStarters(new int[] { FileFunctions.read2ByteInt(data, 5) + 1,
+ FileFunctions.read2ByteInt(data, 7) + 1, FileFunctions.read2ByteInt(data, 9) + 1 });
settings.setMovesetsMod(restoreEnum(MovesetsMod.class, data[11], 2, // UNCHANGED
1, // RANDOM_PREFER_SAME_TYPE
@@ -783,14 +783,14 @@ public class Settings { settings.setShinyChance(restoreState(data[27], 6));
// gen restrictions
- int genLimit = FileFunctions.readFullInt(data, 28);
+ int genLimit = FileFunctions.readFullIntBigEndian(data, 28);
GenRestrictions restrictions = null;
if (genLimit != 0) {
restrictions = new GenRestrictions(genLimit);
}
settings.setCurrentRestrictions(restrictions);
- int codeTweaks = FileFunctions.readFullInt(data, 32);
+ int codeTweaks = FileFunctions.readFullIntBigEndian(data, 32);
settings.setCurrentMiscTweaks(codeTweaks);
diff --git a/src/com/dabomstew/pkrandom/SettingsUpdater.java b/src/com/dabomstew/pkrandom/SettingsUpdater.java index 265b4f8..609459e 100644 --- a/src/com/dabomstew/pkrandom/SettingsUpdater.java +++ b/src/com/dabomstew/pkrandom/SettingsUpdater.java @@ -170,7 +170,7 @@ public class SettingsUpdater { insertExtraByte(22, (byte) 1); // Move some bits from general options to misc tweaks - int oldTweaks = FileFunctions.readFullInt(dataBlock, 27); + int oldTweaks = FileFunctions.readFullIntBigEndian(dataBlock, 27); if ((dataBlock[0] & 1) != 0) { oldTweaks |= MiscTweak.LOWER_CASE_POKEMON_NAMES.getValue(); } @@ -183,7 +183,7 @@ public class SettingsUpdater { if ((dataBlock[2] & (1 << 5)) != 0) { oldTweaks |= MiscTweak.FORCE_CHALLENGE_MODE.getValue(); } - FileFunctions.writeFullInt(dataBlock, 27, oldTweaks); + FileFunctions.writeFullIntBigEndian(dataBlock, 27, oldTweaks); // Now remap the affected bytes dataBlock[0] = getRemappedByte(dataBlock[0], new int[] { 2, 3, 4, 6, 7 }); @@ -273,9 +273,9 @@ public class SettingsUpdater { // This tweak used to be "Randomize Hidden Hollows", which got moved to static Pokemon // randomization, so the misc tweak became unused in this version. It eventually *was* // used in a future version for something else, but don't get confused by the new name. - int oldTweaks = FileFunctions.readFullInt(dataBlock, 32); + int oldTweaks = FileFunctions.readFullIntBigEndian(dataBlock, 32); oldTweaks &= ~MiscTweak.FORCE_CHALLENGE_MODE.getValue(); - FileFunctions.writeFullInt(dataBlock, 32, oldTweaks); + FileFunctions.writeFullIntBigEndian(dataBlock, 32, oldTweaks); // Trainer Pokemon held items insertExtraByte(48, (byte) 0); @@ -286,9 +286,9 @@ public class SettingsUpdater { insertExtraByte(49, (byte) 0); // Clear "assoc" state from GenRestrictions as it doesn't exist any longer - int genRestrictions = FileFunctions.readFullInt(dataBlock, 28); + int genRestrictions = FileFunctions.readFullIntBigEndian(dataBlock, 28); genRestrictions &= 127; - FileFunctions.writeFullInt(dataBlock, 28, genRestrictions); + FileFunctions.writeFullIntBigEndian(dataBlock, 28, genRestrictions); } // fix checksum diff --git a/src/com/dabomstew/pkrandom/ctr/AMX.java b/src/com/dabomstew/pkrandom/ctr/AMX.java index 456a7ce..1e09798 100644 --- a/src/com/dabomstew/pkrandom/ctr/AMX.java +++ b/src/com/dabomstew/pkrandom/ctr/AMX.java @@ -60,10 +60,10 @@ public class AMX { public AMX(byte[] data, int scriptNum) throws IOException { int found = 0; for (int i = 0; i < data.length - 3; i++) { - int val = FileFunctions.readFullIntLittleEndian(data,i); + int val = FileFunctions.readFullInt(data,i); if (val == amxMagic) { if (found == scriptNum) { - int length = FileFunctions.readFullIntLittleEndian(data,i-4); + int length = FileFunctions.readFullInt(data,i-4); readHeaderAndDecompress(Arrays.copyOfRange(data,i-4,i-4+length)); scriptOffset = i-4; break; @@ -80,19 +80,19 @@ public class AMX { // Credit to the creators of pk3DS (Kaphotics et al) private void readHeaderAndDecompress(byte[] encData) throws IOException { - length = FileFunctions.readFullIntLittleEndian(encData,0); - int magic = FileFunctions.readFullIntLittleEndian(encData,4); + length = FileFunctions.readFullInt(encData,0); + int magic = FileFunctions.readFullInt(encData,4); if (magic != amxMagic) { throw new IOException(); } - ptrOffset = FileFunctions.read2ByteIntLittleEndian(encData,8); - ptrCount = FileFunctions.read2ByteIntLittleEndian(encData,0xA); + ptrOffset = FileFunctions.read2ByteInt(encData,8); + ptrCount = FileFunctions.read2ByteInt(encData,0xA); - scriptInstrStart = FileFunctions.readFullIntLittleEndian(encData,0xC); - scriptMovementStart = FileFunctions.readFullIntLittleEndian(encData,0x10); - finalOffset = FileFunctions.readFullIntLittleEndian(encData,0x14); - allocatedMemory = FileFunctions.readFullIntLittleEndian(encData,0x18); + scriptInstrStart = FileFunctions.readFullInt(encData,0xC); + scriptMovementStart = FileFunctions.readFullInt(encData,0x10); + finalOffset = FileFunctions.readFullInt(encData,0x14); + allocatedMemory = FileFunctions.readFullInt(encData,0x18); compLength = length - scriptInstrStart; byte[] compressedBytes = Arrays.copyOfRange(encData,scriptInstrStart,length); diff --git a/src/com/dabomstew/pkrandom/ctr/BFLIM.java b/src/com/dabomstew/pkrandom/ctr/BFLIM.java index f644add..49e540b 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.read2ByteIntLittleEndian(data, inputOffset); + int value = FileFunctions.read2ByteInt(data, inputOffset); if (image.format == 7) { decodeRGBA5551(output, outputOffset, value); } else if (image.format == 8) { @@ -160,19 +160,19 @@ public class BFLIM { public Header(byte[] bflimBytes) { int headerOffset = bflimBytes.length - 0x28; - int signature = FileFunctions.readFullInt(bflimBytes, headerOffset); + int signature = FileFunctions.readFullIntBigEndian(bflimBytes, headerOffset); if (signature != 0x464C494D) { throw new IllegalArgumentException("Invalid BFLIM: cannot find FLIM header"); } - boolean bigEndian = FileFunctions.read2ByteIntLittleEndian(bflimBytes, headerOffset + 4) == 0xFFFE; + boolean bigEndian = FileFunctions.read2ByteInt(bflimBytes, headerOffset + 4) == 0xFFFE; if (bigEndian) { throw new IllegalArgumentException("Unsupported BFLIM: this is a big endian BFLIM"); } - int headerSize = FileFunctions.read2ByteIntLittleEndian(bflimBytes, headerOffset + 6); + int headerSize = FileFunctions.read2ByteInt(bflimBytes, headerOffset + 6); if (headerSize != 0x14) { throw new IllegalArgumentException("Invalid BFLIM: header length does not equal 0x14"); } - version = FileFunctions.readFullIntLittleEndian(bflimBytes, headerOffset + 8); + version = FileFunctions.readFullInt(bflimBytes, headerOffset + 8); } } @@ -187,17 +187,17 @@ public class BFLIM { public Image(byte[] bflimBytes) { int imageHeaderOffset = bflimBytes.length - 0x14; - int signature = FileFunctions.readFullInt(bflimBytes, imageHeaderOffset); + int signature = FileFunctions.readFullIntBigEndian(bflimBytes, imageHeaderOffset); if (signature != 0x696D6167) { throw new IllegalArgumentException("Invalid BFLIM: cannot find imag header"); } - size = FileFunctions.readFullIntLittleEndian(bflimBytes, imageHeaderOffset + 4); - width = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 8); - height = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 10); - alignment = (short) FileFunctions.read2ByteIntLittleEndian(bflimBytes, imageHeaderOffset + 12); + size = FileFunctions.readFullInt(bflimBytes, imageHeaderOffset + 4); + width = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 8); + height = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 10); + alignment = (short) FileFunctions.read2ByteInt(bflimBytes, imageHeaderOffset + 12); format = bflimBytes[imageHeaderOffset + 14]; flags = bflimBytes[imageHeaderOffset + 15]; - imageSize = FileFunctions.readFullIntLittleEndian(bflimBytes, imageHeaderOffset + 16); + imageSize = FileFunctions.readFullInt(bflimBytes, imageHeaderOffset + 16); } } } diff --git a/src/com/dabomstew/pkrandom/ctr/Mini.java b/src/com/dabomstew/pkrandom/ctr/Mini.java index 490d10f..b0a66c6 100644 --- a/src/com/dabomstew/pkrandom/ctr/Mini.java +++ b/src/com/dabomstew/pkrandom/ctr/Mini.java @@ -83,13 +83,13 @@ public class Mini { return null; } - int count = FileFunctions.read2ByteIntLittleEndian(fileData, 2); + int count = FileFunctions.read2ByteInt(fileData, 2); int ctr = 4; - int start = FileFunctions.readFullIntLittleEndian(fileData, ctr); + int start = FileFunctions.readFullInt(fileData, ctr); ctr += 4; byte[][] returnData = new byte[count][]; for (int i = 0; i < count; i++) { - int end = FileFunctions.readFullIntLittleEndian(fileData, ctr); + int end = FileFunctions.readFullInt(fileData, ctr); ctr += 4; int len = end - start; byte[] data = new byte[len]; diff --git a/src/com/dabomstew/pkrandom/ctr/NCCH.java b/src/com/dabomstew/pkrandom/ctr/NCCH.java index 34bbc5a..02f918c 100644 --- a/src/com/dabomstew/pkrandom/ctr/NCCH.java +++ b/src/com/dabomstew/pkrandom/ctr/NCCH.java @@ -127,8 +127,8 @@ public class NCCH { } private void readFileSystem() throws IOException { - exefsOffset = ncchStartingOffset + FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x1A0) * media_unit_size; - romfsOffset = ncchStartingOffset + FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x1B0) * media_unit_size; + exefsOffset = ncchStartingOffset + FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x1A0) * media_unit_size; + romfsOffset = ncchStartingOffset + FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x1B0) * media_unit_size; baseRom.seek(ncchStartingOffset + 0x20D); byte systemControlInfoFlags = baseRom.readByte(); codeCompressed = (systemControlInfoFlags & 0x01) != 0; @@ -168,29 +168,29 @@ public class NCCH { baseRom.seek(romfsOffset); baseRom.readFully(romfsHeaderData); originalRomfsHeaderCRC = FileFunctions.getCRC32(romfsHeaderData); - int magic1 = FileFunctions.readFullInt(romfsHeaderData, 0x00); - int magic2 = FileFunctions.readFullInt(romfsHeaderData, 0x04); + int magic1 = FileFunctions.readFullIntBigEndian(romfsHeaderData, 0x00); + int magic2 = FileFunctions.readFullIntBigEndian(romfsHeaderData, 0x04); if (magic1 != romfs_magic_1 || magic2 != romfs_magic_2) { // Not a valid romfs return; } - int masterHashSize = FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x08); - int level3HashBlockSize = 1 << FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x4C); + int masterHashSize = FileFunctions.readFullInt(romfsHeaderData, 0x08); + int level3HashBlockSize = 1 << FileFunctions.readFullInt(romfsHeaderData, 0x4C); long level3Offset = romfsOffset + alignLong(0x60 + masterHashSize, level3HashBlockSize); byte[] level3HeaderData = new byte[level3_header_size]; baseRom.seek(level3Offset); baseRom.readFully(level3HeaderData); - int headerLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x00); + int headerLength = FileFunctions.readFullInt(level3HeaderData, 0x00); if (headerLength != level3_header_size) { // Not a valid romfs return; } - int directoryMetadataOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x0C); - int directoryMetadataLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x10); - int fileMetadataOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x1c); - int fileMetadataLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x20); - int fileDataOffsetFromHeaderStart = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x24); + int directoryMetadataOffset = FileFunctions.readFullInt(level3HeaderData, 0x0C); + int directoryMetadataLength = FileFunctions.readFullInt(level3HeaderData, 0x10); + int fileMetadataOffset = FileFunctions.readFullInt(level3HeaderData, 0x1c); + int fileMetadataLength = FileFunctions.readFullInt(level3HeaderData, 0x20); + int fileDataOffsetFromHeaderStart = FileFunctions.readFullInt(level3HeaderData, 0x24); fileDataOffset = level3Offset + fileDataOffsetFromHeaderStart; byte[] directoryMetadataBlock = new byte[directoryMetadataLength]; @@ -261,8 +261,8 @@ public class NCCH { // The logo is small enough (8KB) to just read the whole thing into memory. Write it to the new ROM directly // after the header, then update the new ROM's logo offset - long logoOffset = ncchStartingOffset + FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x198) * media_unit_size; - long logoLength = FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x19C) * media_unit_size; + long logoOffset = ncchStartingOffset + FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x198) * media_unit_size; + long logoLength = FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x19C) * media_unit_size; if (logoLength > 0) { byte[] logo = new byte[(int) logoLength]; baseRom.seek(logoOffset); @@ -275,8 +275,8 @@ public class NCCH { } // The plain region is even smaller (1KB) so repeat the same process - long plainOffset = ncchStartingOffset + FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x190) * media_unit_size; - long plainLength = FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x194) * media_unit_size; + long plainOffset = ncchStartingOffset + FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x190) * media_unit_size; + long plainLength = FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x194) * media_unit_size; if (plainLength > 0) { byte[] plain = new byte[(int) plainLength]; baseRom.seek(plainOffset); @@ -311,14 +311,14 @@ public class NCCH { // Lastly, reconstruct the superblock hashes MessageDigest digest = MessageDigest.getInstance("SHA-256"); - int exefsHashRegionSize = FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x1A8) * media_unit_size; + int exefsHashRegionSize = FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x1A8) * media_unit_size; byte[] exefsDataToHash = new byte[exefsHashRegionSize]; fNew.seek(newExefsOffset); fNew.readFully(exefsDataToHash); byte[] exefsSuperblockHash = digest.digest(exefsDataToHash); fNew.seek(0x1C0); fNew.write(exefsSuperblockHash); - int romfsHashRegionSize = FileFunctions.readLittleEndianIntFromFile(baseRom, ncchStartingOffset + 0x1B8) * media_unit_size; + int romfsHashRegionSize = FileFunctions.readIntFromFile(baseRom, ncchStartingOffset + 0x1B8) * media_unit_size; byte[] romfsDataToHash = new byte[romfsHashRegionSize]; fNew.seek(newRomfsOffset); fNew.readFully(romfsDataToHash); @@ -407,8 +407,8 @@ public class NCCH { // updated file data. We're assuming here that the master hash size is smaller than the level 3 // hash block size, which it almost certainly will because we're not adding large amounts of data // to the romfs - int masterHashSize = FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x08); - int level3HashBlockSize = 1 << FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x4C); + int masterHashSize = FileFunctions.readFullInt(romfsHeaderData, 0x08); + int level3HashBlockSize = 1 << FileFunctions.readFullInt(romfsHeaderData, 0x4C); long level3Offset = romfsOffset + alignLong(0x60 + masterHashSize, level3HashBlockSize); long newLevel3Offset = newRomfsOffset + alignLong(0x60 + masterHashSize, level3HashBlockSize); @@ -422,12 +422,12 @@ public class NCCH { // Write out both hash tables and the directory metadata table. Since we're not adding or removing // any files/directories, we can just use what's in the base ROM for this. - int directoryHashTableOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x04); - int directoryHashTableLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x08); - int directoryMetadataTableOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x0C); - int directoryMetadataTableLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x10); - int fileHashTableOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x14); - int fileHashTableLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x18); + int directoryHashTableOffset = FileFunctions.readFullInt(level3HeaderData, 0x04); + int directoryHashTableLength = FileFunctions.readFullInt(level3HeaderData, 0x08); + int directoryMetadataTableOffset = FileFunctions.readFullInt(level3HeaderData, 0x0C); + int directoryMetadataTableLength = FileFunctions.readFullInt(level3HeaderData, 0x10); + int fileHashTableOffset = FileFunctions.readFullInt(level3HeaderData, 0x14); + int fileHashTableLength = FileFunctions.readFullInt(level3HeaderData, 0x18); byte[] directoryHashTable = new byte[directoryHashTableLength]; baseRom.seek(level3Offset + directoryHashTableOffset); baseRom.readFully(directoryHashTable); @@ -445,14 +445,14 @@ public class NCCH { fNew.write(fileHashTable); // Now reconstruct the file metadata table. It may need to be changed if any file grew or shrunk - int fileMetadataTableOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x1C); - int fileMetadataTableLength = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x20); + int fileMetadataTableOffset = FileFunctions.readFullInt(level3HeaderData, 0x1C); + int fileMetadataTableLength = FileFunctions.readFullInt(level3HeaderData, 0x20); byte[] newFileMetadataTable = updateFileMetadataTable(fileMetadataTableLength); fNew.seek(newLevel3Offset + fileMetadataTableOffset); fNew.write(newFileMetadataTable); // Using the new file metadata table, output the file data - int fileDataOffset = FileFunctions.readFullIntLittleEndian(level3HeaderData, 0x24); + int fileDataOffset = FileFunctions.readFullInt(level3HeaderData, 0x24); long endOfFileDataOffset = 0; for (FileMetadata metadata : fileMetadataList) { // Users have sent us bug reports with really bizarre errors here that seem to indicate @@ -483,10 +483,10 @@ public class NCCH { long newLevel3EndingOffset = endOfFileDataOffset; long newLevel3HashdataSize = newLevel3EndingOffset - newLevel3Offset; long numberOfLevel3HashBlocks = alignLong(newLevel3HashdataSize, level3HashBlockSize) / level3HashBlockSize; - int level2HashBlockSize = 1 << FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x34); + int level2HashBlockSize = 1 << FileFunctions.readFullInt(romfsHeaderData, 0x34); long newLevel2HashdataSize = numberOfLevel3HashBlocks * 0x20; long numberOfLevel2HashBlocks = alignLong(newLevel2HashdataSize, level2HashBlockSize) / level2HashBlockSize; - int level1HashBlockSize = 1 << FileFunctions.readFullIntLittleEndian(romfsHeaderData, 0x1C); + int level1HashBlockSize = 1 << FileFunctions.readFullInt(romfsHeaderData, 0x1C); long newLevel1HashdataSize = numberOfLevel2HashBlocks * 0x20; long newLevel1Offset = newLevel3Offset + alignLong(newLevel3HashdataSize, level3HashBlockSize); long newLevel2Offset = newLevel1Offset + alignLong(newLevel1HashdataSize, level1HashBlockSize); @@ -528,13 +528,13 @@ public class NCCH { long level1LogicalOffset = 0; long level2LogicalOffset = alignLong(newLevel1HashdataSize, level1HashBlockSize); long level3LogicalOffset = alignLong(level2LogicalOffset + newLevel2HashdataSize, level2HashBlockSize); - FileFunctions.writeFullIntLittleEndian(romfsHeaderData, 0x08, (int) numberOfLevel1HashBlocks * 0x20); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x0C, level1LogicalOffset); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x14, newLevel1HashdataSize); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x24, level2LogicalOffset); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x2C, newLevel2HashdataSize); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x3C, level3LogicalOffset); - FileFunctions.writeFullLongLittleEndian(romfsHeaderData, 0x44, newLevel3HashdataSize); + FileFunctions.writeFullInt(romfsHeaderData, 0x08, (int) numberOfLevel1HashBlocks * 0x20); + FileFunctions.writeFullLong(romfsHeaderData, 0x0C, level1LogicalOffset); + FileFunctions.writeFullLong(romfsHeaderData, 0x14, newLevel1HashdataSize); + FileFunctions.writeFullLong(romfsHeaderData, 0x24, level2LogicalOffset); + FileFunctions.writeFullLong(romfsHeaderData, 0x2C, newLevel2HashdataSize); + FileFunctions.writeFullLong(romfsHeaderData, 0x3C, level3LogicalOffset); + FileFunctions.writeFullLong(romfsHeaderData, 0x44, newLevel3HashdataSize); fNew.seek(newRomfsOffset); fNew.write(romfsHeaderData); long currentLength = newFileEndingOffset - newRomfsOffset; @@ -802,21 +802,21 @@ public class NCCH { 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); + int magic = FileFunctions.readBigEndianIntFromFile(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); + int certChainSize = FileFunctions.readIntFromFile(this.baseRom, 0x08); + int ticketSize = FileFunctions.readIntFromFile(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 signatureType = FileFunctions.readBigEndianIntFromFile(this.baseRom, tmdOffset); int signatureSize, paddingSize; switch (signatureType) { case 0x010003: @@ -845,7 +845,7 @@ public class NCCH { // 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); + return FileFunctions.read2ByteBigEndianIntFromFile(this.baseRom, tmdHeaderOffset + 0x9C); } catch (IOException e) { throw new RandomizerIOException(e); } @@ -859,13 +859,13 @@ public class NCCH { public static long getCXIOffsetInFile(String filename) { try { RandomAccessFile rom = new RandomAccessFile(filename, "r"); - int ciaHeaderSize = FileFunctions.readLittleEndianIntFromFile(rom, 0x00); + int ciaHeaderSize = FileFunctions.readIntFromFile(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); + int certChainSize = FileFunctions.readIntFromFile(rom, 0x08); + int ticketSize = FileFunctions.readIntFromFile(rom, 0x0C); + int tmdFileSize = FileFunctions.readIntFromFile(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 @@ -873,7 +873,7 @@ public class NCCH { 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); + int magic = FileFunctions.readBigEndianIntFromFile(rom, contentOffset + ncch_and_ncsd_magic_offset); if (magic == ncch_magic) { // This CIA's content contains a valid CXI! return contentOffset; @@ -883,7 +883,7 @@ public class NCCH { // 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); + int magic = FileFunctions.readBigEndianIntFromFile(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 @@ -913,8 +913,8 @@ public class NCCH { byte[] filenameBytes = new byte[0x8]; System.arraycopy(exefsHeaderData, fileHeaderOffset, filenameBytes, 0, 0x8); this.filename = new String(filenameBytes, StandardCharsets.UTF_8).trim(); - this.offset = FileFunctions.readFullIntLittleEndian(exefsHeaderData, fileHeaderOffset + 0x08); - this.size = FileFunctions.readFullIntLittleEndian(exefsHeaderData, fileHeaderOffset + 0x0C); + this.offset = FileFunctions.readFullInt(exefsHeaderData, fileHeaderOffset + 0x08); + this.size = FileFunctions.readFullInt(exefsHeaderData, fileHeaderOffset + 0x0C); } public boolean isValid() { @@ -925,8 +925,8 @@ public class NCCH { byte[] output = new byte[0x10]; byte[] filenameBytes = this.filename.getBytes(StandardCharsets.UTF_8); System.arraycopy(filenameBytes, 0, output, 0, filenameBytes.length); - FileFunctions.writeFullIntLittleEndian(output, 0x08, this.offset); - FileFunctions.writeFullIntLittleEndian(output, 0x0C, this.size); + FileFunctions.writeFullInt(output, 0x08, this.offset); + FileFunctions.writeFullInt(output, 0x0C, this.size); return output; } } @@ -941,12 +941,12 @@ public class NCCH { public String name; public DirectoryMetadata(byte[] directoryMetadataBlock, int offset) { - parentDirectoryOffset = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset); - siblingDirectoryOffset = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset + 0x04); - firstChildDirectoryOffset = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset + 0x08); - firstFileOffset = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset + 0x0C); - nextDirectoryInHashBucketOffset = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset + 0x10); - nameLength = FileFunctions.readFullIntLittleEndian(directoryMetadataBlock, offset + 0x14); + parentDirectoryOffset = FileFunctions.readFullInt(directoryMetadataBlock, offset); + siblingDirectoryOffset = FileFunctions.readFullInt(directoryMetadataBlock, offset + 0x04); + firstChildDirectoryOffset = FileFunctions.readFullInt(directoryMetadataBlock, offset + 0x08); + firstFileOffset = FileFunctions.readFullInt(directoryMetadataBlock, offset + 0x0C); + nextDirectoryInHashBucketOffset = FileFunctions.readFullInt(directoryMetadataBlock, offset + 0x10); + nameLength = FileFunctions.readFullInt(directoryMetadataBlock, offset + 0x14); name = ""; if (nameLength != metadata_unused) { byte[] nameBytes = new byte[nameLength]; @@ -969,12 +969,12 @@ public class NCCH { public FileMetadata(byte[] fileMetadataBlock, int offset) { this.offset = offset; - parentDirectoryOffset = FileFunctions.readFullIntLittleEndian(fileMetadataBlock, offset); - siblingFileOffset = FileFunctions.readFullIntLittleEndian(fileMetadataBlock, offset + 0x04); - fileDataOffset = FileFunctions.readFullLongLittleEndian(fileMetadataBlock, offset + 0x08); - fileDataLength = FileFunctions.readFullLongLittleEndian(fileMetadataBlock, offset + 0x10); - nextFileInHashBucketOffset = FileFunctions.readFullIntLittleEndian(fileMetadataBlock, offset + 0x18); - nameLength = FileFunctions.readFullIntLittleEndian(fileMetadataBlock, offset + 0x1C); + parentDirectoryOffset = FileFunctions.readFullInt(fileMetadataBlock, offset); + siblingFileOffset = FileFunctions.readFullInt(fileMetadataBlock, offset + 0x04); + fileDataOffset = FileFunctions.readFullLong(fileMetadataBlock, offset + 0x08); + fileDataLength = FileFunctions.readFullLong(fileMetadataBlock, offset + 0x10); + nextFileInHashBucketOffset = FileFunctions.readFullInt(fileMetadataBlock, offset + 0x18); + nameLength = FileFunctions.readFullInt(fileMetadataBlock, offset + 0x1C); name = ""; if (nameLength != metadata_unused) { byte[] nameBytes = new byte[nameLength]; @@ -989,12 +989,12 @@ public class NCCH { metadataLength += alignInt(nameLength, 4); } byte[] output = new byte[metadataLength]; - FileFunctions.writeFullIntLittleEndian(output, 0x00, this.parentDirectoryOffset); - FileFunctions.writeFullIntLittleEndian(output, 0x04, this.siblingFileOffset); - FileFunctions.writeFullLongLittleEndian(output, 0x08, this.fileDataOffset); - FileFunctions.writeFullLongLittleEndian(output, 0x10, this.fileDataLength); - FileFunctions.writeFullIntLittleEndian(output, 0x18, this.nextFileInHashBucketOffset); - FileFunctions.writeFullIntLittleEndian(output, 0x1C, this.nameLength); + FileFunctions.writeFullInt(output, 0x00, this.parentDirectoryOffset); + FileFunctions.writeFullInt(output, 0x04, this.siblingFileOffset); + FileFunctions.writeFullLong(output, 0x08, this.fileDataOffset); + FileFunctions.writeFullLong(output, 0x10, this.fileDataLength); + FileFunctions.writeFullInt(output, 0x18, this.nextFileInHashBucketOffset); + FileFunctions.writeFullInt(output, 0x1C, this.nameLength); if (!name.equals("")) { byte[] nameBytes = name.getBytes(StandardCharsets.UTF_16LE); System.arraycopy(nameBytes, 0, output, 0x20, nameBytes.length); diff --git a/src/com/dabomstew/pkrandom/ctr/SMDH.java b/src/com/dabomstew/pkrandom/ctr/SMDH.java index cae41c2..7155d02 100644 --- a/src/com/dabomstew/pkrandom/ctr/SMDH.java +++ b/src/com/dabomstew/pkrandom/ctr/SMDH.java @@ -71,7 +71,7 @@ public class SMDH { } private boolean isValid() { - int magic = FileFunctions.readFullIntLittleEndian(data, 0x0); + int magic = FileFunctions.readFullInt(data, 0x0); return magic == smdh_magic; } diff --git a/src/com/dabomstew/pkrandom/romhandlers/AbstractDSRomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/AbstractDSRomHandler.java index bf79ddf..c42f43f 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/AbstractDSRomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/AbstractDSRomHandler.java @@ -354,11 +354,11 @@ public abstract class AbstractDSRomHandler extends AbstractRomHandler { int tcmCopyingPointersOffset = find(arm9, prefix); tcmCopyingPointersOffset += prefix.length() / 2; // because it was a prefix - int oldDestPointersOffset = FileFunctions.readFullIntLittleEndian(arm9, tcmCopyingPointersOffset) - arm9Offset; + int oldDestPointersOffset = FileFunctions.readFullInt(arm9, tcmCopyingPointersOffset) - arm9Offset; int itcmSrcOffset = - FileFunctions.readFullIntLittleEndian(arm9, tcmCopyingPointersOffset + 8) - arm9Offset; + FileFunctions.readFullInt(arm9, tcmCopyingPointersOffset + 8) - arm9Offset; int itcmSizeOffset = oldDestPointersOffset + 4; - int oldITCMSize = FileFunctions.readFullIntLittleEndian(arm9, itcmSizeOffset); + int oldITCMSize = FileFunctions.readFullInt(arm9, itcmSizeOffset); int oldDTCMOffset = itcmSrcOffset + oldITCMSize; @@ -368,11 +368,11 @@ public abstract class AbstractDSRomHandler extends AbstractRomHandler { // 1. Pointer to destination pointers/sizes // 2. ARM9 size // 3. Size of the area copied to ITCM - FileFunctions.writeFullIntLittleEndian(newARM9, tcmCopyingPointersOffset, + FileFunctions.writeFullInt(newARM9, tcmCopyingPointersOffset, oldDestPointersOffset + extendBy + arm9Offset); - FileFunctions.writeFullIntLittleEndian(newARM9, tcmCopyingPointersOffset + 4, + FileFunctions.writeFullInt(newARM9, tcmCopyingPointersOffset + 4, newARM9.length + arm9Offset); - FileFunctions.writeFullIntLittleEndian(newARM9, itcmSizeOffset, oldITCMSize + extendBy); + FileFunctions.writeFullInt(newARM9, itcmSizeOffset, oldITCMSize + extendBy); // Finally, shift everything System.arraycopy(newARM9, oldDTCMOffset, newARM9, oldDTCMOffset + extendBy, diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java index 4e83de2..b76654e 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen3RomHandler.java @@ -2028,7 +2028,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler { rom[offset + 22] = 0x57; // In the space formerly occupied by the first 0x2000000, write Latios's ID - FileFunctions.writeFullIntLittleEndian(rom, offset + 128, pokedexToInternal[Species.latios]); + FileFunctions.writeFullInt(rom, offset + 128, pokedexToInternal[Species.latios]); // Where the original function computes Latios's ID by setting r0 to 0xCC << 1, just pc-relative // load our constant. We have four bytes of space to play with, and we need to make sure the offset @@ -2047,7 +2047,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler { // Latios's species ID. rom[offset + 182] = 0x00; rom[offset + 183] = (byte) 0xBD; - FileFunctions.writeFullIntLittleEndian(rom, offset + 184, pokedexToInternal[Species.latios]); + FileFunctions.writeFullInt(rom, offset + 184, pokedexToInternal[Species.latios]); // Now write a pc-relative load to this new species ID constant over the original move and lsl. Similar // to before, we need to write a nop first for alignment, then pc-relative load into r6. @@ -2067,7 +2067,7 @@ public class Gen3RomHandler extends AbstractGBRomHandler { rom[offset + 14] = 0x41; // In the space formerly occupied by the first 0x03005D8C, write Latios's ID - FileFunctions.writeFullIntLittleEndian(rom, offset + 28, pokedexToInternal[Species.latios]); + FileFunctions.writeFullInt(rom, offset + 28, pokedexToInternal[Species.latios]); // In the original function, we "lsl r0, r0, #0x10" then compare r0 to 0. The thing is, this left // shift doesn't actually matter, because 0 << 0x10 = 0, and [non-zero] << 0x10 = [non-zero]. @@ -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.read2ByteIntLittleEndian(rom, offset); + int val = FileFunctions.read2ByteInt(rom, offset); while (val != 0x0000) { items.add(val); offset += 2; - val = FileFunctions.read2ByteIntLittleEndian(rom, offset); + val = FileFunctions.read2ByteInt(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.write2ByteIntLittleEndian(rom, offset, iterItems.next()); + FileFunctions.write2ByteInt(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.write2ByteIntLittleEndian(rom, offset, balancedPrice); + FileFunctions.write2ByteInt(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.read2ByteIntLittleEndian(rom, itemOffset); + int item = FileFunctions.read2ByteInt(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.write2ByteIntLittleEndian(rom, itemOffset, pickupItems.get(i).item); + FileFunctions.write2ByteInt(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 7045f34..803c28e 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen4RomHandler.java @@ -1815,7 +1815,7 @@ public class Gen4RomHandler extends AbstractDSRomHandler { // constant that has the same effect.
int newRange = maxLevel - level;
int divisor = (0xFFFF / (newRange + 1)) + 1;
- FileFunctions.writeFullIntLittleEndian(encounterOverlay, offset + 148, divisor);
+ FileFunctions.writeFullInt(encounterOverlay, offset + 148, divisor);
}
writeExtraEncountersDPPt(honeyTreeData, 0, honeyTreeEncounters.encounters);
}
@@ -3163,7 +3163,7 @@ public class Gen4RomHandler extends AbstractDSRomHandler { // The original code had an entry for Darkrai; its species ID is pc-relative loaded. Since this
// entry is clearly unused, just replace Darkrai's species ID constant with Cresselia's, since
// in the original code, her ID is computed as 0x7A << 0x2
- FileFunctions.writeFullIntLittleEndian(arm9, offset + 244, Species.cresselia);
+ FileFunctions.writeFullInt(arm9, offset + 244, Species.cresselia);
// Now write a pc-relative load to our new constant over where Cresselia's ID is normally mov'd
// into r7 and shifted.
@@ -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.read2ByteIntLittleEndian(arm9, offset));
+ int val = (FileFunctions.read2ByteInt(arm9, offset));
while ((val & 0xFFFF) != 0xFFFF) {
if (val != 0) {
items.add(val);
}
offset += 2;
- val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
+ val = (FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(arm9, offset) & 0xFFFF) != 0xFFFF) {
+ while ((FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(arm9, offset) & 0xFFFF) != 0xFFFF) {
+ while ((FileFunctions.read2ByteInt(arm9, offset) & 0xFFFF) != 0xFFFF) {
offset += 2;
}
offset += 2;
continue;
}
Iterator<Integer> iterItems = thisShop.items.iterator();
- int val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
+ int val = (FileFunctions.read2ByteInt(arm9, offset));
while ((val & 0xFFFF) != 0xFFFF) {
if (val != 0) {
- FileFunctions.write2ByteIntLittleEndian(arm9,offset,iterItems.next());
+ FileFunctions.write2ByteInt(arm9,offset,iterItems.next());
}
offset += 2;
- val = (FileFunctions.read2ByteIntLittleEndian(arm9, offset));
+ val = (FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteInt(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.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteInt(battleOverlay, itemOffset, item);
}
for (int i = 0; i < Gen4Constants.numberOfRarePickupItems; i++) {
int itemOffset = rarePickupItemsTableOffset + (2 * i);
int item = itemIterator.next().item;
- FileFunctions.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteInt(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 18c05cf..fcf07c1 100755 --- a/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java +++ b/src/com/dabomstew/pkrandom/romhandlers/Gen5RomHandler.java @@ -2196,12 +2196,12 @@ public class Gen5RomHandler extends AbstractDSRomHandler { int firstConstantOffset = find(boxLegendaryOverlay, Gen5Constants.blackBoxLegendaryCheckPrefix1);
if (firstConstantOffset > 0) {
firstConstantOffset += Gen5Constants.blackBoxLegendaryCheckPrefix1.length() / 2; // because it was a prefix
- FileFunctions.writeFullIntLittleEndian(boxLegendaryOverlay, firstConstantOffset, boxLegendarySpecies);
+ FileFunctions.writeFullInt(boxLegendaryOverlay, firstConstantOffset, boxLegendarySpecies);
}
int secondConstantOffset = find(boxLegendaryOverlay, Gen5Constants.blackBoxLegendaryCheckPrefix2);
if (secondConstantOffset > 0) {
secondConstantOffset += Gen5Constants.blackBoxLegendaryCheckPrefix2.length() / 2; // because it was a prefix
- FileFunctions.writeFullIntLittleEndian(boxLegendaryOverlay, secondConstantOffset, boxLegendarySpecies);
+ FileFunctions.writeFullInt(boxLegendaryOverlay, secondConstantOffset, boxLegendarySpecies);
}
} else {
// In White, Zekrom's species ID is always loaded by loading 161 into a register
@@ -2220,7 +2220,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { // In the space that used to hold the address of the "scrcmd_pokemon_fld.c"
// string, we're going to instead store the species ID of the box legendary
// so that we can do a pc-relative load to it.
- FileFunctions.writeFullIntLittleEndian(boxLegendaryOverlay, firstFunctionOffset + 320, boxLegendarySpecies);
+ FileFunctions.writeFullInt(boxLegendaryOverlay, firstFunctionOffset + 320, boxLegendarySpecies);
// Zekrom's species ID is originally loaded by doing a mov into r1 and then a shift
// on that same register four instructions later. This nops out the first instruction
@@ -2248,7 +2248,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { boxLegendaryOverlay[secondFunctionOffset + 505] = 0x1C;
// Now replace the 0x00000000 constant with the species ID
- FileFunctions.writeFullIntLittleEndian(boxLegendaryOverlay, secondFunctionOffset + 556, boxLegendarySpecies);
+ FileFunctions.writeFullInt(boxLegendaryOverlay, secondFunctionOffset + 556, boxLegendarySpecies);
// Lastly, replace the mov and lsl that originally puts Zekrom's species ID into r1
// with a pc-relative of the above constant and a nop.
@@ -2273,7 +2273,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { overlay[offset + 10] = 0x00;
// Now in the space that used to do "mov r0, #0x2" and return, write Thundurus's ID
- FileFunctions.writeFullIntLittleEndian(overlay, offset + 20, Species.thundurus);
+ FileFunctions.writeFullInt(overlay, offset + 20, Species.thundurus);
// Lastly, instead of computing Thundurus's ID as TornadusID + 1, pc-relative load it
// from what we wrote earlier.
@@ -2977,7 +2977,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { // Finally, we replace what used to store the address of "shinka_demo.c"
// with the species ID of Nincada's new extra evolution.
int newSpeciesIDOffset = functionOffset + patchOffsets[2];
- FileFunctions.writeFullIntLittleEndian(evolutionOverlay, newSpeciesIDOffset, extraEvolution.number);
+ FileFunctions.writeFullInt(evolutionOverlay, newSpeciesIDOffset, extraEvolution.number);
writeOverlay(romEntry.getInt("EvolutionOvlNumber"), evolutionOverlay);
}
@@ -3304,7 +3304,7 @@ public class Gen5RomHandler extends AbstractDSRomHandler { // Now write the species ID in the 4 bytes of space now available at the bottom,
// and then write a pc-relative load to this species ID at the offset.
- FileFunctions.writeFullIntLittleEndian(introCryOverlay, offset + 38, introPokemon);
+ FileFunctions.writeFullInt(introCryOverlay, offset + 38, introPokemon);
introCryOverlay[offset] = 0x9;
introCryOverlay[offset + 1] = 0x48;
writeOverlay(romEntry.getInt("IntroCryOvlNumber"), introCryOverlay);
@@ -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.read2ByteIntLittleEndian(battleOverlay, itemOffset);
+ int item = FileFunctions.read2ByteInt(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.write2ByteIntLittleEndian(battleOverlay, itemOffset, item);
+ FileFunctions.write2ByteInt(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 081b868..6fe036a 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.read2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset); - int item2 = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset); + int item1 = FileFunctions.read2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset); + int item2 = FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset); + pkmn.darkGrassHeldItem = FileFunctions.read2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset); } int formeCount = stats[Gen6Constants.bsFormeCountOffset] & 0xFF; if (formeCount > 1) { if (!altFormes.keySet().contains(pkmn.number)) { - int firstFormeOffset = FileFunctions.read2ByteIntLittleEndian(stats, Gen6Constants.bsFormeOffset); + int firstFormeOffset = FileFunctions.read2ByteInt(stats, Gen6Constants.bsFormeOffset); if (firstFormeOffset != 0) { for (int i = 1; i < formeCount; i++) { - 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 + 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 if (Gen6Constants.actuallyCosmeticForms.contains(firstFormeOffset+i-1)) { if (pkmn.number != Species.pikachu && pkmn.number != Species.cherrim) { // No Pikachu/Cherrim pkmn.cosmeticForms += 1; @@ -647,13 +647,13 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { // Held items if (pkmn.guaranteedHeldItem > 0) { - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset, 0); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset, 0); } else { - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.rareHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen6Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsRareHeldItemOffset, pkmn.rareHeldItem); + FileFunctions.write2ByteInt(stats, Gen6Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem); } if (pkmn.fullName().equals("Meowstic")) { @@ -921,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.read2ByteIntLittleEndian(staticCRO,offset+i*size); + int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size); Pokemon pokemon = pokes[species]; int forme = staticCRO[offset+i*size + 4]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -933,7 +933,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = staticCRO[offset+i*size + 5]; - int heldItem = FileFunctions.readFullIntLittleEndian(staticCRO,offset+i*size + 12); + int heldItem = FileFunctions.readFullInt(staticCRO,offset+i*size + 12); if (heldItem < 0) { heldItem = 0; } @@ -1072,7 +1072,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { wildMapNames.put(i, "? Unknown ?"); } String mapName = wildMapNames.get(i); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0x10; + int offset = FileFunctions.readFullInt(b, 0x10) + 0x10; int length = b.length - offset; if (length < 0x178) { // No encounters in this map continue; @@ -1195,8 +1195,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { wildMapNames.put(i, "? Unknown ?"); } String mapName = wildMapNames.get(i); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0xE; - int offset2 = FileFunctions.readFullIntLittleEndian(b, 0x14); + int offset = FileFunctions.readFullInt(b, 0x10) + 0xE; + int offset2 = FileFunctions.readFullInt(b, 0x14); int length = offset2 - offset; if (length < 0xF6) { // No encounters in this map continue; @@ -1352,7 +1352,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { Iterator<EncounterSet> encounters = encountersList.iterator(); for (int i = 0; i < encounterGarc.files.size() - 1; i++) { byte[] b = encounterGarc.files.get(i).get(0); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0x10; + int offset = FileFunctions.readFullInt(b, 0x10) + 0x10; int length = b.length - offset; if (length < 0x178) { // No encounters in this map continue; @@ -1453,8 +1453,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { byte[] decStorage = encounterGarc.files.get(encounterGarc.files.size() - 1).get(0); for (int i = 0; i < encounterGarc.files.size() - 2; i++) { byte[] b = encounterGarc.files.get(i).get(0); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0xE; - int offset2 = FileFunctions.readFullIntLittleEndian(b, 0x14); + int offset = FileFunctions.readFullInt(b, 0x10) + 0xE; + int offset2 = FileFunctions.readFullInt(b, 0x14); int length = offset2 - offset; if (length < 0xF6) { // No encounters in this map continue; @@ -1520,7 +1520,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { System.arraycopy(encounterData, 0, b, offset, 0xF6); // Also write the encounter data to the decStorage file - int decStorageOffset = FileFunctions.readFullIntLittleEndian(decStorage, (i + 1) * 4) + 0xE; + int decStorageOffset = FileFunctions.readFullInt(decStorage, (i + 1) * 4) + 0xE; System.arraycopy(encounterData, 0, decStorage, decStorageOffset, 0xF4); } @@ -1541,7 +1541,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { // Read all the "normal" encounters in the encounters GARC. for (int i = 0; i < encounterGarc.files.size() - 1; i++) { byte[] b = encounterGarc.files.get(i).get(0); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0x10; + int offset = FileFunctions.readFullInt(b, 0x10) + 0x10; int length = b.length - offset; if (length < 0x178) { // No encounters in this map continue; @@ -1606,8 +1606,8 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { int currentMapNum = 0; for (int i = 0; i < encounterGarc.files.size() - 2; i++) { byte[] b = encounterGarc.files.get(i).get(0); - int offset = FileFunctions.readFullIntLittleEndian(b, 0x10) + 0xE; - int offset2 = FileFunctions.readFullIntLittleEndian(b, 0x14); + int offset = FileFunctions.readFullInt(b, 0x10) + 0xE; + int offset2 = FileFunctions.readFullInt(b, 0x14); int length = offset2 - offset; if (length < 0xF6) { // No encounters in this map continue; @@ -1657,9 +1657,9 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { int perPokemonAreaDataLength = romEntry.romType == Gen6Constants.Type_XY ? Gen6Constants.perPokemonAreaDataLengthXY : Gen6Constants.perPokemonAreaDataLengthORAS; int offset = pkmn.getBaseNumber() * perPokemonAreaDataLength + areaIndex * 4; - int value = FileFunctions.readFullIntLittleEndian(pokedexAreaData, offset); + int value = FileFunctions.readFullInt(pokedexAreaData, offset); value |= encounterType; - FileFunctions.writeFullIntLittleEndian(pokedexAreaData, offset, value); + FileFunctions.writeFullInt(pokedexAreaData, offset, value); } } @@ -2001,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.read2ByteIntLittleEndian(staticCRO,offset+i*size); + int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size); Pokemon pokemon = pokes[species]; int forme = staticCRO[offset+i*size + 2]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -2013,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.read2ByteIntLittleEndian(staticCRO,offset+i*size + 4); + short heldItem = (short)FileFunctions.read2ByteInt(staticCRO,offset+i*size + 4); if (heldItem < 0) { heldItem = 0; } @@ -2031,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.read2ByteIntLittleEndian(staticCRO,offset+i*size); + int species = FileFunctions.read2ByteInt(staticCRO,offset+i*size); Pokemon pokemon = pokes[species]; int forme = staticCRO[offset+i*size + 4]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -2043,13 +2043,13 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = staticCRO[offset+i*size + 5]; - int heldItem = FileFunctions.readFullIntLittleEndian(staticCRO,offset+i*size + 12); + int heldItem = FileFunctions.readFullInt(staticCRO,offset+i*size + 12); if (heldItem < 0) { heldItem = 0; } se.heldItem = heldItem; if (romEntry.romType == Gen6Constants.Type_ORAS) { - int metLocation = FileFunctions.read2ByteIntLittleEndian(staticCRO, offset + i * size + 18); + int metLocation = FileFunctions.read2ByteInt(staticCRO, offset + i * size + 18); if (metLocation == 0xEA64) { se.isEgg = true; } @@ -2161,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.write2ByteIntLittleEndian(data, boxLegendaryScriptOffsets[i], boxLegendarySpecies); + FileFunctions.write2ByteInt(data, boxLegendaryScriptOffsets[i], boxLegendarySpecies); } byte[] modifiedScript = localScript.getBytes(); System.arraycopy(modifiedScript, 0, boxLegendaryRoomData, Gen6Constants.boxLegendaryLocalScriptOffsetXY, modifiedScript.length); @@ -2237,7 +2237,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { for (int i = 0; i < roamers.length; i++) { int offset = freeSpaceOffset + 8 + (i * 4); int species = roamers[i].pkmn.getBaseNumber(); - FileFunctions.writeFullIntLittleEndian(code, offset, species); + FileFunctions.writeFullInt(code, offset, species); } // To load the species ID, the game currently does "moveq r4, #0x90" for Articuno and similar @@ -2271,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.write2ByteIntLittleEndian(data, Gen6Constants.rayquazaScriptOffsetsORAS[i], rayquazaEncounterSpecies); + FileFunctions.write2ByteInt(data, Gen6Constants.rayquazaScriptOffsetsORAS[i], rayquazaEncounterSpecies); } scriptGarc.setFile(rayquazaScriptFile, rayquazaAMX.getBytes()); writeGARC(romEntry.getString("Scripts"), scriptGarc); @@ -2376,7 +2376,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { // beq returnFromFunction // The below code nops out that comparison and makes the move and branch instructions // non-conditional; no matter what's on the save file, the player will have all dexes. - FileFunctions.writeFullIntLittleEndian(code, offset, 0); + FileFunctions.writeFullInt(code, offset, 0); code[offset + 7] = (byte) 0xE3; code[offset + 11] = (byte) 0xEA; } @@ -2401,15 +2401,15 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { // cmp r0, #0x0 // moveq r0, #0x1 // ldmia sp!,{r4 r5 r6 r7 r8 r9 r10 r11 r12 pc} - FileFunctions.writeFullInt(code, offset + 32, 0x0700A0E1); - FileFunctions.writeFullInt(code, offset + 36, 0x000050E3); - FileFunctions.writeFullInt(code, offset + 40, 0x0100A003); - FileFunctions.writeFullInt(code, offset + 44, 0xF09FBDE8); + FileFunctions.writeFullIntBigEndian(code, offset + 32, 0x0700A0E1); + FileFunctions.writeFullIntBigEndian(code, offset + 36, 0x000050E3); + FileFunctions.writeFullIntBigEndian(code, offset + 40, 0x0100A003); + FileFunctions.writeFullIntBigEndian(code, offset + 44, 0xF09FBDE8); // At the end of the function, the game normally does "mov r0, r7" and then returns, where r7 // contains the number of Pokemon caught in the Hoenn Pokedex. Instead, branch to the code we // wrote above. - FileFunctions.writeFullInt(code, offset + 208, 0xD2FFFFEA); + FileFunctions.writeFullIntBigEndian(code, offset + 208, 0xD2FFFFEA); } } } @@ -2586,7 +2586,7 @@ public class Gen6RomHandler extends Abstract3DSRomHandler { if (mtOffset > 0) { int val = 0; while (val != 0xFFFF) { - val = FileFunctions.read2ByteIntLittleEndian(code,mtOffset); + val = FileFunctions.read2ByteInt(code,mtOffset); mtOffset += 2; if (val == 0x26E || val == 0xFFFF) continue; mtMoves.add(val); @@ -2603,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.write2ByteIntLittleEndian(code,mtOffset + i*8, moves.get(i)); + FileFunctions.write2ByteInt(code,mtOffset + i*8, moves.get(i)); } } mtOffset = getMoveTutorMovesOffset(); if (mtOffset > 0) { for (int move: moves) { - int val = FileFunctions.read2ByteIntLittleEndian(code,mtOffset); + int val = FileFunctions.read2ByteInt(code,mtOffset); if (val == 0x26E) mtOffset += 2; - FileFunctions.write2ByteIntLittleEndian(code,mtOffset,move); + FileFunctions.write2ByteInt(code,mtOffset,move); mtOffset += 2; } } @@ -3296,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.read2ByteIntLittleEndian(data,i); + int item = FileFunctions.read2ByteInt(data,i); fieldItems.add(item); } @@ -3307,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.read2ByteIntLittleEndian(data,i); + int item = FileFunctions.read2ByteInt(data,i); fieldItems.add(item); } } else { @@ -3316,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.read2ByteIntLittleEndian(code, offsHidden + (i * 0xE) + 2); + int item = FileFunctions.read2ByteInt(code, offsHidden + (i * 0xE) + 2); fieldItems.add(item); } } @@ -3342,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.read2ByteIntLittleEndian(megaStoneItemEvent.decData, offset); + int item = FileFunctions.read2ByteInt(megaStoneItemEvent.decData, offset); fieldMegaStones.add(item); } return fieldMegaStones; @@ -3359,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.write2ByteIntLittleEndian(data,i,item); + FileFunctions.write2ByteInt(data,i,item); } scriptGarc.setFile(normalItemsFile,normalItemAMX.getBytes()); @@ -3371,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.write2ByteIntLittleEndian(data,i,item); + FileFunctions.write2ByteInt(data,i,item); } scriptGarc.setFile(hiddenItemsFile,hiddenItemAMX.getBytes()); } else { @@ -3381,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.write2ByteIntLittleEndian(code,offsHidden + (i * 0xE) + 2, item); + FileFunctions.write2ByteInt(code,offsHidden + (i * 0xE) + 2, item); } } } @@ -3401,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.write2ByteIntLittleEndian(megaStoneItemEvent.decData, offset, replacementItem); + FileFunctions.write2ByteInt(megaStoneItemEvent.decData, offset, replacementItem); } else { - FileFunctions.write2ByteIntLittleEndian(megaStoneItemEvent.decData, offset, newItem); + FileFunctions.write2ByteInt(megaStoneItemEvent.decData, offset, newItem); megaStoneMap.put(oldItem, newItem); } } @@ -3430,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.read2ByteIntLittleEndian(code,offset)]; + trade.givenPokemon = pokes[FileFunctions.read2ByteInt(code,offset)]; trade.ivs = new int[6]; for (int iv = 0; iv < 6; iv++) { trade.ivs[iv] = code[offset + 5 + iv]; } - trade.otId = FileFunctions.read2ByteIntLittleEndian(code,offset + 0xE); - trade.item = FileFunctions.read2ByteIntLittleEndian(code,offset + 0x10); + trade.otId = FileFunctions.read2ByteInt(code,offset + 0xE); + trade.item = FileFunctions.read2ByteInt(code,offset + 0x10); trade.otName = tradeStrings.get(textOffset + count + i); - trade.requestedPokemon = pokes[FileFunctions.read2ByteIntLittleEndian(code,offset + 0x20)]; + trade.requestedPokemon = pokes[FileFunctions.read2ByteInt(code,offset + 0x20)]; trades.add(trade); offset += Gen6Constants.ingameTradeSize; } @@ -3461,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.write2ByteIntLittleEndian(code,offset,trade.givenPokemon.number); + FileFunctions.write2ByteInt(code,offset,trade.givenPokemon.number); for (int iv = 0; iv < 6; iv++) { code[offset + 5 + iv] = (byte)trade.ivs[iv]; } - FileFunctions.write2ByteIntLittleEndian(code,offset + 0xE,trade.otId); - FileFunctions.write2ByteIntLittleEndian(code,offset + 0x10,trade.item); + FileFunctions.write2ByteInt(code,offset + 0xE,trade.otId); + FileFunctions.write2ByteInt(code,offset + 0x10,trade.item); tradeStrings.set(textOffset + count + i, trade.otName); - FileFunctions.write2ByteIntLittleEndian(code,offset + 0x20, + FileFunctions.write2ByteInt(code,offset + 0x20, trade.requestedPokemon == null ? 0 : trade.requestedPokemon.number); offset += Gen6Constants.ingameTradeSize; @@ -3609,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.read2ByteIntLittleEndian(code,offset)); + items.add(FileFunctions.read2ByteInt(code,offset)); offset += 2; } Shop shop = new Shop(); @@ -3656,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.write2ByteIntLittleEndian(code,offset,item); + FileFunctions.write2ByteInt(code,offset,item); offset += 2; } } @@ -3702,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.read2ByteIntLittleEndian(code, itemOffset); + int item = FileFunctions.read2ByteInt(code, itemOffset); PickupItem pickupItem = new PickupItem(item); pickupItems.add(pickupItem); } @@ -3732,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.write2ByteIntLittleEndian(code, itemOffset, item); + FileFunctions.write2ByteInt(code, itemOffset, item); } } } diff --git a/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java b/src/com/dabomstew/pkrandom/romhandlers/Gen7RomHandler.java index 52b33ed..5ced081 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.read2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset); - int item2 = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset); + int item1 = FileFunctions.read2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset); + int item2 = FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset); + pkmn.darkGrassHeldItem = FileFunctions.read2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset); } int formeCount = stats[Gen7Constants.bsFormeCountOffset] & 0xFF; if (formeCount > 1) { if (!altFormes.keySet().contains(pkmn.number)) { - int firstFormeOffset = FileFunctions.read2ByteIntLittleEndian(stats, Gen7Constants.bsFormeOffset); + int firstFormeOffset = FileFunctions.read2ByteInt(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.read2ByteIntLittleEndian(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.read2ByteInt(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.read2ByteIntLittleEndian(stats,Gen7Constants.bsFormeSpriteOffset))); + altFormes.put(firstFormeOffset + i - 1,new FormeInfo(theAltForme,j,FileFunctions.read2ByteInt(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.write2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset, 0); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.guaranteedHeldItem); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.guaranteedHeldItem); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset, 0); } else { - FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.rareHeldItem); - FileFunctions.write2ByteIntLittleEndian(stats, Gen7Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsCommonHeldItemOffset, pkmn.commonHeldItem); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsRareHeldItemOffset, pkmn.rareHeldItem); + FileFunctions.write2ByteInt(stats, Gen7Constants.bsDarkGrassHeldItemOffset, pkmn.darkGrassHeldItem); } if (pkmn.fullName().equals("Meowstic")) { @@ -778,7 +778,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { int offset = find(code, Gen7Constants.ninjaskSpeciesPrefix); if (offset > 0) { offset += Gen7Constants.ninjaskSpeciesPrefix.length() / 2; // because it was a prefix - FileFunctions.writeFullIntLittleEndian(code, offset, primaryEvolution.number); + FileFunctions.writeFullInt(code, offset, primaryEvolution.number); } // In the game's executable, there's a hardcoded value to indicate what "extra" @@ -990,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.read2ByteIntLittleEndian(giftsFile, offset); + int species = FileFunctions.read2ByteInt(giftsFile, offset); Pokemon pokemon = pokes[species]; int forme = giftsFile[offset + 2]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -1002,7 +1002,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = giftsFile[offset + 3]; - se.heldItem = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset + 8); + se.heldItem = FileFunctions.read2ByteInt(giftsFile, offset + 8); starters.add(se); } } catch (IOException e) { @@ -1388,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.read2ByteIntLittleEndian(worldData, i * 0x2); + zoneData[i].worldIndex = FileFunctions.read2ByteInt(worldData, i * 0x2); zoneData[i].locationName = locationList.get(zoneData[i].parentMap); byte[] world = worlds.get(zoneData[i].worldIndex); - int mappingOffset = FileFunctions.readFullIntLittleEndian(world, 0x8); + int mappingOffset = FileFunctions.readFullInt(world, 0x8); for (int offset = mappingOffset; offset < world.length; offset += 4) { - int potentialZoneIndex = FileFunctions.read2ByteIntLittleEndian(world, offset); + int potentialZoneIndex = FileFunctions.read2ByteInt(world, offset); if (potentialZoneIndex == i) { - zoneData[i].areaIndex = FileFunctions.read2ByteIntLittleEndian(world, offset + 0x2); + zoneData[i].areaIndex = FileFunctions.read2ByteInt(world, offset + 0x2); break; } } @@ -1486,7 +1486,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { tpk.spatkEVs = trpoke[pokeOffs + 5]; tpk.spdefEVs = trpoke[pokeOffs + 6]; tpk.speedEVs = trpoke[pokeOffs + 7]; - tpk.IVs = FileFunctions.readFullIntLittleEndian(trpoke, pokeOffs + 8); + tpk.IVs = FileFunctions.readFullInt(trpoke, pokeOffs + 8); tpk.level = level; if (romEntry.romType == Gen7Constants.Type_USUM) { if (i == 78) { @@ -1580,7 +1580,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { trpoke[pokeOffs + 5] = tp.spatkEVs; trpoke[pokeOffs + 6] = tp.spdefEVs; trpoke[pokeOffs + 7] = tp.speedEVs; - FileFunctions.writeFullIntLittleEndian(trpoke, pokeOffs + 8, tp.IVs); + FileFunctions.writeFullInt(trpoke, pokeOffs + 8, tp.IVs); writeWord(trpoke, pokeOffs + 14, tp.level); writeWord(trpoke, pokeOffs + 16, tp.pokemon.number); writeWord(trpoke, pokeOffs + 18, tp.forme); @@ -1641,7 +1641,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { Pokemon boostedPokemon = uniquePokemon.get(i); int auraNumber = getAuraNumberForHighestStat(boostedPokemon); int speciesNumber = boostedPokemon.getBaseNumber(); - FileFunctions.write2ByteIntLittleEndian(battleCRO, offset + (i * 0x10), speciesNumber); + FileFunctions.write2ByteInt(battleCRO, offset + (i * 0x10), speciesNumber); battleCRO[offset + (i * 0x10) + 2] = (byte) auraNumber; } writeFile(romEntry.getString("Battle"), battleCRO); @@ -1785,7 +1785,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { for (int i: totemIndices) { int offset = i * 0x38; TotemPokemon totem = new TotemPokemon(); - int species = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset); + int species = FileFunctions.read2ByteInt(staticEncountersFile, offset); Pokemon pokemon = pokes[species]; int forme = staticEncountersFile[offset + 2]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -1797,7 +1797,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { totem.pkmn = pokemon; totem.forme = forme; totem.level = staticEncountersFile[offset + 3]; - int heldItem = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset + 4); + int heldItem = FileFunctions.read2ByteInt(staticEncountersFile, offset + 4); if (heldItem == 0xFFFF) { heldItem = 0; } @@ -1894,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.read2ByteIntLittleEndian(giftsFile, offset); + int species = FileFunctions.read2ByteInt(giftsFile, offset); Pokemon pokemon = pokes[species]; int forme = giftsFile[offset + 2]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -1906,7 +1906,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = giftsFile[offset + 3]; - se.heldItem = FileFunctions.read2ByteIntLittleEndian(giftsFile, offset + 8); + se.heldItem = FileFunctions.read2ByteInt(giftsFile, offset + 8); se.isEgg = giftsFile[offset + 10] == 1; statics.add(se); } @@ -1932,7 +1932,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { private StaticEncounter readStaticEncounter(byte[] staticEncountersFile, int offset) { StaticEncounter se = new StaticEncounter(); - int species = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset); + int species = FileFunctions.read2ByteInt(staticEncountersFile, offset); Pokemon pokemon = pokes[species]; int forme = staticEncountersFile[offset + 2]; if (forme > pokemon.cosmeticForms && forme != 30 && forme != 31) { @@ -1944,7 +1944,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { se.pkmn = pokemon; se.forme = forme; se.level = staticEncountersFile[offset + 3]; - int heldItem = FileFunctions.read2ByteIntLittleEndian(staticEncountersFile, offset + 4); + int heldItem = FileFunctions.read2ByteInt(staticEncountersFile, offset + 4); if (heldItem == 0xFFFF) { heldItem = 0; } @@ -1980,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.read2ByteIntLittleEndian(code, speciesOffset); + int species = FileFunctions.read2ByteInt(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 @@ -1988,7 +1988,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { // don't care about all of this; we just wrote a "mov r0, #forme" over the ldr instead. // Thus, if the original ldr instruction is still there, assume we haven't touched it. int forme = 0; - if (FileFunctions.readFullIntLittleEndian(code, formeOffset) == 0xE59D0040) { + if (FileFunctions.readFullInt(code, formeOffset) == 0xE59D0040) { // Since we haven't modified the code yet, this is Zygarde. For SM, use 10%, // since you can get it fairly early. For USUM, use 50%, since it's only // obtainable in the postgame. @@ -2113,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.write2ByteIntLittleEndian(code, speciesOffset, se.pkmn.getBaseNumber()); + FileFunctions.write2ByteInt(code, speciesOffset, se.pkmn.getBaseNumber()); // Just write "mov r0, #forme" to where the game originally loaded the forme. code[formeOffset] = (byte) se.forme; @@ -2334,7 +2334,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { mtOffset += Gen7Constants.tutorsPrefix.length() / 2; int val = 0; while (val != 0xFFFF) { - val = FileFunctions.read2ByteIntLittleEndian(code, mtOffset); + val = FileFunctions.read2ByteInt(code, mtOffset); mtOffset += 2; if (val == 0xFFFF) continue; mtMoves.add(val); @@ -2350,7 +2350,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { if (mtOffset > 0) { mtOffset += Gen7Constants.tutorsPrefix.length() / 2; for (int move: moves) { - FileFunctions.write2ByteIntLittleEndian(code,mtOffset, move); + FileFunctions.write2ByteInt(code,mtOffset, move); mtOffset += 2; } } @@ -2359,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.write2ByteIntLittleEndian(tutorCRO, offset, moves.get(i)); + FileFunctions.write2ByteInt(tutorCRO, offset, moves.get(i)); } writeFile(romEntry.getString("ShopsAndTutors"), tutorCRO); } catch (IOException e) { @@ -2951,7 +2951,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { int itemCount = itemData[0]; for (int j = 0; j < itemCount; j++) { - fieldItems.add(FileFunctions.read2ByteIntLittleEndian(itemData,(j * 64) + 52)); + fieldItems.add(FileFunctions.read2ByteInt(itemData,(j * 64) + 52)); } } } @@ -2962,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.read2ByteIntLittleEndian(berryPileData,4 + j*68 + 54 + k*2)); + fieldItems.add(FileFunctions.read2ByteInt(berryPileData,4 + j*68 + 54 + k*2)); } } } @@ -2989,7 +2989,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { int itemCount = itemData[0]; for (int j = 0; j < itemCount; j++) { - FileFunctions.write2ByteIntLittleEndian(itemData,(j * 64) + 52,iterItems.next()); + FileFunctions.write2ByteInt(itemData,(j * 64) + 52,iterItems.next()); } } } @@ -3004,7 +3004,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { for (int j = 0; j < pileCount; j++) { for (int k = 0; k < 7; k++) { - FileFunctions.write2ByteIntLittleEndian(berryPileData,4 + j*68 + 54 + k*2,iterItems.next()); + FileFunctions.write2ByteInt(berryPileData,4 + j*68 + 54 + k*2,iterItems.next()); } } } @@ -3031,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.read2ByteIntLittleEndian(tradesFile, offset); - int requestedSpecies = FileFunctions.read2ByteIntLittleEndian(tradesFile, offset + 0x2C); + int givenSpecies = FileFunctions.read2ByteInt(tradesFile, offset); + int requestedSpecies = FileFunctions.read2ByteInt(tradesFile, offset + 0x2C); Pokemon givenPokemon = pokes[givenSpecies]; Pokemon requestedPokemon = pokes[requestedSpecies]; int forme = tradesFile[offset + 4]; @@ -3044,14 +3044,14 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { } trade.givenPokemon = givenPokemon; trade.requestedPokemon = requestedPokemon; - 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.nickname = tradeStrings.get(FileFunctions.read2ByteInt(tradesFile, offset + 2)); + trade.otName = tradeStrings.get(FileFunctions.read2ByteInt(tradesFile, offset + 0x18)); + trade.otId = FileFunctions.readFullInt(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.read2ByteIntLittleEndian(tradesFile, offset + 0x14); + trade.item = FileFunctions.read2ByteInt(tradesFile, offset + 0x14); if (trade.item < 0) { trade.item = 0; } @@ -3081,16 +3081,16 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { forme = givenPokemon.formeNumber; givenPokemon = givenPokemon.baseForme; } - FileFunctions.write2ByteIntLittleEndian(tradesFile, offset, givenPokemon.number); + FileFunctions.write2ByteInt(tradesFile, offset, givenPokemon.number); tradesFile[offset + 4] = (byte) forme; - 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); + 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.writeFullInt(tradesFile, offset + 0x10, trade.otId); for (int iv = 0; iv < 6; iv++) { tradesFile[offset + 6 + iv] = (byte) trade.ivs[iv]; } - FileFunctions.write2ByteIntLittleEndian(tradesFile, offset + 0x14, trade.item); + FileFunctions.write2ByteInt(tradesFile, offset + 0x14, trade.item); List<Integer> hardcodedTextOffsetsForThisTrade = hardcodedTradeTextOffsets.get(i); if (hardcodedTextOffsetsForThisTrade != null) { @@ -3219,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.read2ByteIntLittleEndian(shopsCRO, offset)); + items.add(FileFunctions.read2ByteInt(shopsCRO, offset)); offset += 2; } Shop shop = new Shop(); @@ -3266,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.write2ByteIntLittleEndian(shopsCRO, offset, item); + FileFunctions.write2ByteInt(shopsCRO, offset, item); offset += 2; } } @@ -3296,10 +3296,10 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { try { GARCArchive pickupGarc = this.readGARC(romEntry.getString("PickupData"), false); byte[] pickupData = pickupGarc.getFile(0); - int numberOfPickupItems = FileFunctions.readFullIntLittleEndian(pickupData, 0) - 1; // GameFreak why??? + int numberOfPickupItems = FileFunctions.readFullInt(pickupData, 0) - 1; // GameFreak why??? for (int i = 0; i < numberOfPickupItems; i++) { int offset = 4 + (i * 0xC); - int item = FileFunctions.read2ByteIntLittleEndian(pickupData, offset); + int item = FileFunctions.read2ByteInt(pickupData, offset); PickupItem pickupItem = new PickupItem(item); for (int levelRange = 0; levelRange < 10; levelRange++) { pickupItem.probabilities[levelRange] = pickupData[offset + levelRange + 2]; @@ -3320,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.write2ByteIntLittleEndian(pickupData, offset, item); + FileFunctions.write2ByteInt(pickupData, offset, item); } this.writeGARC(romEntry.getString("PickupData"), pickupGarc); } catch (IOException e) { @@ -3358,7 +3358,7 @@ public class Gen7RomHandler extends Abstract3DSRomHandler { public ZoneData(byte[] zoneDataBytes, int index) { data = new byte[size]; System.arraycopy(zoneDataBytes, index * size, data, 0, size); - parentMap = FileFunctions.readFullIntLittleEndian(data, 0x1C); + parentMap = FileFunctions.readFullInt(data, 0x1C); } } diff --git a/src/compressors/DSDecmp.java b/src/compressors/DSDecmp.java index 05f8c59..de003d8 100644 --- a/src/compressors/DSDecmp.java +++ b/src/compressors/DSDecmp.java @@ -47,7 +47,7 @@ public class DSDecmp { int length = (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8) | ((data[offset + 2] & 0xFF) << 16); offset += 3; if (length == 0) { - length = FileFunctions.readFullInt(data, offset); + length = FileFunctions.readFullIntBigEndian(data, offset); offset += 4; } @@ -96,7 +96,7 @@ public class DSDecmp { int length = (data[offset] & 0xFF) | ((data[offset + 1] & 0xFF) << 8) | ((data[offset + 2] & 0xFF) << 16); offset += 3; if (length == 0) { - length = FileFunctions.readFullInt(data, offset); + length = FileFunctions.readFullIntBigEndian(data, offset); offset += 4; } |