mirror of
https://github.com/mii443/SaveEditor.git
synced 2025-12-05 04:08:23 +00:00
符号付きビッグエンディアンに対応
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -14,6 +14,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib"
|
||||
implementation 'org.junit.jupiter:junit-jupiter:5.4.2'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10"
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Converter.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\MainKt.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\SaveEditor.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\Data.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Byte.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Compound.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_End.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Int.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Long.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_String.class
|
||||
D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Converter.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\MainKt.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\SaveEditor.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\Data.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Byte.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Compound.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_End.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Int.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Long.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_Short.class;D:\Git\SaveEditor\build\classes\kotlin\main\codes\mii\SaveEditor\Types\NBT_String.class
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
45
|
||||
34
|
||||
50
|
||||
38
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +1 @@
|
||||
<EFBFBD>!<EFBFBD>$<EFBFBD>'<EFBFBD>#<EFBFBD>#<EFBFBD>
|
||||
<EFBFBD>;<3B>)<29>)<29>)<29>"<22>!<21>!<21><17><1D><15><18><17><17><16><14><14>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -80,7 +80,7 @@ case "`uname`" in
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/lib/SaveEditor-1.0-SNAPSHOT.jar:$APP_HOME/lib/kotlin-stdlib-jdk8-1.4.10.jar:$APP_HOME/lib/kotlin-stdlib-jdk7-1.4.10.jar:$APP_HOME/lib/kotlin-stdlib-1.4.10.jar:$APP_HOME/lib/kotlin-stdlib-common-1.4.10.jar:$APP_HOME/lib/annotations-13.0.jar
|
||||
CLASSPATH=$APP_HOME/lib/SaveEditor-1.0-SNAPSHOT.jar:$APP_HOME/lib/kotlin-stdlib-jdk8-1.4.10.jar:$APP_HOME/lib/kotlin-stdlib-jdk7-1.4.10.jar:$APP_HOME/lib/kotlin-stdlib-1.4.10.jar:$APP_HOME/lib/junit-jupiter-5.4.2.jar:$APP_HOME/lib/kotlin-stdlib-common-1.4.10.jar:$APP_HOME/lib/annotations-13.0.jar:$APP_HOME/lib/junit-jupiter-params-5.4.2.jar:$APP_HOME/lib/junit-jupiter-engine-5.4.2.jar:$APP_HOME/lib/junit-jupiter-api-5.4.2.jar:$APP_HOME/lib/junit-platform-engine-1.4.2.jar:$APP_HOME/lib/junit-platform-commons-1.4.2.jar:$APP_HOME/lib/apiguardian-api-1.0.0.jar:$APP_HOME/lib/opentest4j-1.1.1.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
|
||||
@@ -82,7 +82,7 @@ set CMD_LINE_ARGS=%*
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\lib\SaveEditor-1.0-SNAPSHOT.jar;%APP_HOME%\lib\kotlin-stdlib-jdk8-1.4.10.jar;%APP_HOME%\lib\kotlin-stdlib-jdk7-1.4.10.jar;%APP_HOME%\lib\kotlin-stdlib-1.4.10.jar;%APP_HOME%\lib\kotlin-stdlib-common-1.4.10.jar;%APP_HOME%\lib\annotations-13.0.jar
|
||||
set CLASSPATH=%APP_HOME%\lib\SaveEditor-1.0-SNAPSHOT.jar;%APP_HOME%\lib\kotlin-stdlib-jdk8-1.4.10.jar;%APP_HOME%\lib\kotlin-stdlib-jdk7-1.4.10.jar;%APP_HOME%\lib\kotlin-stdlib-1.4.10.jar;%APP_HOME%\lib\junit-jupiter-5.4.2.jar;%APP_HOME%\lib\kotlin-stdlib-common-1.4.10.jar;%APP_HOME%\lib\annotations-13.0.jar;%APP_HOME%\lib\junit-jupiter-params-5.4.2.jar;%APP_HOME%\lib\junit-jupiter-engine-5.4.2.jar;%APP_HOME%\lib\junit-jupiter-api-5.4.2.jar;%APP_HOME%\lib\junit-platform-engine-1.4.2.jar;%APP_HOME%\lib\junit-platform-commons-1.4.2.jar;%APP_HOME%\lib\apiguardian-api-1.0.0.jar;%APP_HOME%\lib\opentest4j-1.1.1.jar
|
||||
|
||||
@rem Execute SaveEditor
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SAVE_EDITOR_OPTS% -classpath "%CLASSPATH%" codes.mii.SaveEditor.MainKt %CMD_LINE_ARGS%
|
||||
|
||||
@@ -1,80 +1,142 @@
|
||||
package codes.mii.SaveEditor
|
||||
|
||||
import codes.mii.SaveEditor.Types.NBT_Byte
|
||||
import codes.mii.SaveEditor.Types.NBT_Compound
|
||||
import codes.mii.SaveEditor.Types.NBT_End
|
||||
import codes.mii.SaveEditor.Types.NBT_String
|
||||
import codes.mii.SaveEditor.Types.*
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.nio.file.Files
|
||||
import kotlin.experimental.and
|
||||
|
||||
class Converter {
|
||||
@ExperimentalUnsignedTypes
|
||||
fun convert(byte: ByteArray): NBT_Compound {
|
||||
val result = NBT_Compound(0, "")
|
||||
val byteSize = byte.size
|
||||
var readingPosition = 0
|
||||
|
||||
while (byteSize > readingPosition) {
|
||||
println(byte[readingPosition])
|
||||
try {
|
||||
while (byteSize > readingPosition) {
|
||||
println(byte[readingPosition])
|
||||
|
||||
val nowByte = byte[readingPosition]
|
||||
var nameLength = 0
|
||||
val name = StringBuilder()
|
||||
val nowByte = byte[readingPosition]
|
||||
var nameLength = 0
|
||||
val name = StringBuilder()
|
||||
|
||||
if (nowByte != 0.toByte()) {
|
||||
var nameLengthText = ""
|
||||
repeat(2) {
|
||||
readingPosition++
|
||||
nameLengthText += byte[readingPosition].toString(16)
|
||||
}
|
||||
nameLength = nameLengthText.toInt(16)
|
||||
|
||||
repeat (nameLength) {
|
||||
readingPosition++
|
||||
name.append(hexToAscii(byte[readingPosition].toString(16)))
|
||||
}
|
||||
}
|
||||
|
||||
when(nowByte) {
|
||||
0.toByte() -> {
|
||||
result.data.add(NBT_End())
|
||||
readingPosition++
|
||||
}
|
||||
|
||||
1.toByte() -> {
|
||||
readingPosition++
|
||||
result.data.add(NBT_Byte(nameLength.toByte(), name.toString(), byte[readingPosition]))
|
||||
}
|
||||
|
||||
8.toByte() -> {
|
||||
var textLengthText = ""
|
||||
if (nowByte != 0.toByte()) {
|
||||
val nameLengthText = StringBuilder()
|
||||
repeat(2) {
|
||||
readingPosition++
|
||||
textLengthText += byte[readingPosition].toString(16)
|
||||
val n = if (it != 1){
|
||||
(byte[readingPosition].toUByte()).toString(16)
|
||||
} else {
|
||||
(byte[readingPosition]).toString(16)
|
||||
}
|
||||
nameLengthText.append(if (n.length == 2) { n } else { "0$n" })
|
||||
}
|
||||
val textLength = textLengthText.toInt(16)
|
||||
nameLength = nameLengthText.toString().toInt(16)
|
||||
|
||||
val text = StringBuilder()
|
||||
repeat (textLength) {
|
||||
repeat(nameLength) {
|
||||
readingPosition++
|
||||
name.append(hexToAscii(byte[readingPosition].toString(16)))
|
||||
}
|
||||
}
|
||||
|
||||
when (nowByte) {
|
||||
0.toByte() -> { // END
|
||||
result.data.add(NBT_End())
|
||||
readingPosition++
|
||||
text.append(hexToAscii(byte[readingPosition].toString(16)))
|
||||
}
|
||||
|
||||
result.data.add(NBT_String(nameLength.toByte(), name.toString(), textLength.toByte(), text.toString()))
|
||||
}
|
||||
1.toByte() -> { // BYTE
|
||||
readingPosition++
|
||||
result.data.add(NBT_Byte(nameLength.toByte(), name.toString(), byte[readingPosition]))
|
||||
}
|
||||
|
||||
2.toByte() -> { // SHORT
|
||||
val bytes = StringBuilder()
|
||||
repeat(2) {
|
||||
readingPosition++
|
||||
val n = if (it != 1){
|
||||
(byte[readingPosition].toUByte()).toString(16)
|
||||
} else {
|
||||
(byte[readingPosition]).toString(16)
|
||||
}
|
||||
bytes.append(if (n.length == 2) { n } else { "0$n" })
|
||||
}
|
||||
|
||||
result.data.add(NBT_Short(nameLength.toByte(), name.toString(), bytes.toString().toInt(16)))
|
||||
}
|
||||
|
||||
3.toByte() -> { // INT
|
||||
var intText = StringBuilder()
|
||||
repeat(4) {
|
||||
readingPosition++
|
||||
val n = if (it != 1){
|
||||
(byte[readingPosition].toUByte()).toString(16)
|
||||
} else {
|
||||
(byte[readingPosition]).toString(16)
|
||||
}
|
||||
intText.append(if (n.length == 2) { n } else { "0$n" })
|
||||
}
|
||||
result.data.add(NBT_Int(nameLength.toByte(), name.toString(), intText.toString().toInt(16)))
|
||||
}
|
||||
|
||||
4.toByte() -> { // LONG
|
||||
val intText = StringBuilder()
|
||||
repeat(8) {
|
||||
readingPosition++
|
||||
val n = if (it != 1){
|
||||
(byte[readingPosition].toUByte()).toString(16)
|
||||
} else {
|
||||
(byte[readingPosition]).toString(16)
|
||||
}
|
||||
|
||||
intText.append(if (n.length == 2) { n } else { "0$n" })
|
||||
}
|
||||
result.data.add(NBT_Long(nameLength.toByte(), name.toString(), intText.toString().toLong(16)))
|
||||
}
|
||||
|
||||
8.toByte() -> { // STRING
|
||||
val textLengthText = StringBuilder()
|
||||
repeat(2) {
|
||||
readingPosition++
|
||||
val n = if (it != 1){
|
||||
(byte[readingPosition].toUByte()).toString(16)
|
||||
} else {
|
||||
(byte[readingPosition]).toString(16)
|
||||
}
|
||||
textLengthText.append(if (n.length == 2) { n } else { "0$n" })
|
||||
}
|
||||
val textLength = textLengthText.toString().toInt(16)
|
||||
|
||||
val text = StringBuilder()
|
||||
repeat(textLength) {
|
||||
readingPosition++
|
||||
text.append(hexToAscii(byte[readingPosition].toString(16)))
|
||||
}
|
||||
|
||||
result.data.add(NBT_String(nameLength.toByte(), name.toString(), textLength.toByte(), text.toString()))
|
||||
}
|
||||
|
||||
10.toByte() -> { // COMPOUND
|
||||
result.data.add(NBT_Compound(nameLength.toByte(), name.toString()))
|
||||
}
|
||||
|
||||
10.toByte() -> {
|
||||
result.data.add(NBT_Compound(nameLength.toByte(), name.toString()))
|
||||
|
||||
}
|
||||
|
||||
readingPosition++
|
||||
}
|
||||
|
||||
readingPosition++
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun byteToString(byte: ByteArray, readingPosition: Int) {
|
||||
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun convertFile(file: File): ByteArray? {
|
||||
return Files.readAllBytes(file.toPath())
|
||||
|
||||
@@ -10,12 +10,21 @@ class SaveEditor {
|
||||
val converter: Converter = Converter()
|
||||
|
||||
fun start(args: Array<String>) {
|
||||
println("Minecraft Save Editor.")
|
||||
println("NBT Editor.")
|
||||
|
||||
if (args.count() >= 1) {
|
||||
val bytes = converter.convertFile(File(args[0]))
|
||||
|
||||
val inp = StringBuilder()
|
||||
bytes?.forEach {
|
||||
val n = it.toString(16)
|
||||
inp.append(if (n.length == 1) { "0$n " } else { "$n " })
|
||||
}
|
||||
println("input: $inp")
|
||||
println("Converting...")
|
||||
val result = converter.convert(bytes!!)
|
||||
println("Converted.\n\nresult\n")
|
||||
|
||||
|
||||
result.data.forEach {
|
||||
when(it) {
|
||||
@@ -34,6 +43,22 @@ class SaveEditor {
|
||||
is NBT_Compound -> {
|
||||
println("COMPOUND, Name: ${it.name}")
|
||||
}
|
||||
|
||||
is NBT_Int -> {
|
||||
println("INT, Name: ${it.name}, Data: ${it.data}")
|
||||
}
|
||||
|
||||
is NBT_Short -> {
|
||||
println("SHORT, Name: ${it.name}, Data: ${it.data}")
|
||||
}
|
||||
|
||||
is NBT_Long -> {
|
||||
println("LONG, Name: ${it.name}, Data: ${it.data}")
|
||||
}
|
||||
|
||||
else -> {
|
||||
println("UNKNOWN, ${it::class.java}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Short.kt
Normal file
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Short.kt
Normal file
@@ -0,0 +1,5 @@
|
||||
package codes.mii.SaveEditor.Types
|
||||
|
||||
class NBT_Short(override val nameLength: Byte, override val name: String, val data: Int) : Data {
|
||||
override val typeByte: Byte = 2
|
||||
}
|
||||
14
src/test/kotlin/codes/mii/SaveEditor/SaveEditorTest.kt
Normal file
14
src/test/kotlin/codes/mii/SaveEditor/SaveEditorTest.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package codes.mii.SaveEditor
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
|
||||
internal class SaveEditorTest {
|
||||
|
||||
@Test
|
||||
fun start() {
|
||||
val args: Array<String> = arrayOf("D:\\Git\\SaveEditor\\build\\libs\\test")
|
||||
SaveEditor().start(args)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user