diff --git a/core/src/main/kotlin/de/darkatra/bfme2/ConversionExtensions.kt b/core/src/main/kotlin/de/darkatra/bfme2/ConversionExtensions.kt index 3d77d15..21fc22b 100644 --- a/core/src/main/kotlin/de/darkatra/bfme2/ConversionExtensions.kt +++ b/core/src/main/kotlin/de/darkatra/bfme2/ConversionExtensions.kt @@ -30,21 +30,21 @@ fun Boolean.toByte(): Byte = when (this) { // Bytes to Data fun ByteArray.toBigEndianShort(): Short = ByteBuffer.wrap(this).order(ByteOrder.BIG_ENDIAN).short fun ByteArray.toLittleEndianShort(): Short = ByteBuffer.wrap(this).order(ByteOrder.LITTLE_ENDIAN).short -fun ByteArray.toBigEndianUShort(): UShort = toBigEndianUInt().toUShort() -fun ByteArray.toLittleEndianUShort(): UShort = toLittleEndianUInt().toUShort() +fun ByteArray.toBigEndianUShort(): UShort = toBigEndianShort().toUShort() +fun ByteArray.toLittleEndianUShort(): UShort = toLittleEndianShort().toUShort() fun ByteArray.toBigEndianInt(): Int = ByteBuffer.wrap(this).order(ByteOrder.BIG_ENDIAN).int fun ByteArray.toLittleEndianInt(): Int = ByteBuffer.wrap(this).order(ByteOrder.LITTLE_ENDIAN).int -fun ByteArray.toBigEndianUInt(): UInt = this.map { it.toUInt() and 0xFFu }.reduce { acc, uInt -> acc shl 8 or uInt } -fun ByteArray.toLittleEndianUInt(): UInt = this.reversedArray().map { it.toUInt() and 0xFFu }.reduce { acc, uInt -> acc shl 8 or uInt } +fun ByteArray.toBigEndianUInt(): UInt = toBigEndianInt().toUInt() +fun ByteArray.toLittleEndianUInt(): UInt = toLittleEndianInt().toUInt() fun ByteArray.toBigEndianLong(): Long = ByteBuffer.wrap(this).order(ByteOrder.BIG_ENDIAN).long fun ByteArray.toLittleEndianLong(): Long = ByteBuffer.wrap(this).order(ByteOrder.LITTLE_ENDIAN).long -fun ByteArray.toBigEndianULong(): ULong = this.map { it.toULong() and 0xFFu }.reduce { acc, uLong -> acc shl 8 or uLong } -fun ByteArray.toLittleEndianULong(): ULong = this.reversedArray().map { it.toULong() and 0xFFu }.reduce { acc, uLong -> acc shl 8 or uLong } +fun ByteArray.toBigEndianULong(): ULong = toBigEndianLong().toULong() +fun ByteArray.toLittleEndianULong(): ULong = toLittleEndianLong().toULong() -fun ByteArray.toBigEndianFloat(): Float = java.lang.Float.intBitsToFloat(ByteBuffer.wrap(this).order(ByteOrder.BIG_ENDIAN).int) -fun ByteArray.toLittleEndianFloat(): Float = java.lang.Float.intBitsToFloat(ByteBuffer.wrap(this).order(ByteOrder.LITTLE_ENDIAN).int) +fun ByteArray.toBigEndianFloat(): Float = java.lang.Float.intBitsToFloat(this.toBigEndianInt()) +fun ByteArray.toLittleEndianFloat(): Float = java.lang.Float.intBitsToFloat(this.toLittleEndianInt()) fun Byte.toBoolean(): Boolean = when (this) { 0.toByte() -> false diff --git a/core/src/test/kotlin/de/darkatra/bfme2/InputStreamExtensionsTest.kt b/core/src/test/kotlin/de/darkatra/bfme2/InputStreamExtensionsTest.kt index fe1ac8f..da666ca 100644 --- a/core/src/test/kotlin/de/darkatra/bfme2/InputStreamExtensionsTest.kt +++ b/core/src/test/kotlin/de/darkatra/bfme2/InputStreamExtensionsTest.kt @@ -86,7 +86,7 @@ internal class InputStreamExtensionsTest { @Test internal fun shouldReadUShortPrefixedStringWithUS_ASCIIEncoding() { - // byte representation of "LothlorienGrass05" with the length (17) prefixed as UShort + // byte representation of "LothlorienGrass05" in US_ASCII with the length (17) prefixed as UShort // 17, 0 is the UShort 17 // 76, 111, 116, 104, 108, 111, 114, 105, 101, 110, 71, 114, 97, 115, 115, 48, 53 is the String "LothlorienGrass05" encoded in US_ASCII val bytes = byteArrayOf(17, 0, 76, 111, 116, 104, 108, 111, 114, 105, 101, 110, 71, 114, 97, 115, 115, 48, 53) @@ -99,7 +99,7 @@ internal class InputStreamExtensionsTest { @Test internal fun shouldReadUShortPrefixedStringWithUTF_16Encoding() { - // byte representation of "Neutral" with the length (7) prefixed as UShort + // byte representation of "Neutral" in UTF_16LE with the length (7) prefixed as UShort // 7, 0 is the UShort 7 // 78, 0, 101, 0, 117, 0, 116, 0, 114, 0, 97, 0, 108, 0 is the String "Neutral" encoded in UTF_16LE val bytes = byteArrayOf(7, 0, 78, 0, 101, 0, 117, 0, 116, 0, 114, 0, 97, 0, 108, 0) diff --git a/map/src/main/kotlin/de/darkatra/bfme2/map/reader/PropertyKeyReader.kt b/map/src/main/kotlin/de/darkatra/bfme2/map/reader/PropertyKeyReader.kt index 6b977ab..41971f2 100644 --- a/map/src/main/kotlin/de/darkatra/bfme2/map/reader/PropertyKeyReader.kt +++ b/map/src/main/kotlin/de/darkatra/bfme2/map/reader/PropertyKeyReader.kt @@ -12,7 +12,7 @@ class PropertyKeyReader { val propertyType = PropertyType.ofByte(reader.readByte()) - val nameIndex = reader.readNBytes(3).toLittleEndianUInt() + val nameIndex = byteArrayOf(*reader.readNBytes(3), 0).toLittleEndianUInt() val name = context.getAssetName(nameIndex) return PropertyKey( diff --git a/pom.xml b/pom.xml index 1fcbbee..fee995d 100644 --- a/pom.xml +++ b/pom.xml @@ -49,21 +49,23 @@ 1.5.10 11 + + 2.10.0 + 3.20.1 + 1.28 + 3.0.0-M5 + org.jetbrains.kotlin kotlin-stdlib-jdk8 ${kotlin.version} - - org.jetbrains.kotlin - kotlin-maven-plugin - ${kotlin.version} - + de.darkatra.bfme2 big @@ -85,12 +87,14 @@ ${project.version} + commons-io commons-io - 2.10.0 + ${version.commons-io} + org.jetbrains.kotlin kotlin-test @@ -104,10 +108,11 @@ test + org.assertj assertj-core - 3.20.1 + ${version.assertj} test @@ -150,7 +155,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M5 + ${version.surefire}