mirror of
https://github.com/mii443/SaveEditor.git
synced 2025-12-07 13:18:31 +00:00
Add converter.
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.
@@ -1 +1 @@
|
|||||||
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\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
|
||||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
|||||||
12
|
45
|
||||||
10
|
34
|
||||||
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 +1 @@
|
|||||||
<EFBFBD>!
|
<EFBFBD>!<EFBFBD>$<EFBFBD>'<EFBFBD>#<EFBFBD>#<EFBFBD>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,93 @@
|
|||||||
package codes.mii.SaveEditor
|
package codes.mii.SaveEditor
|
||||||
|
|
||||||
class Converter {
|
import codes.mii.SaveEditor.Types.NBT_Byte
|
||||||
fun conver(byte: Byte) {
|
import codes.mii.SaveEditor.Types.NBT_Compound
|
||||||
|
import codes.mii.SaveEditor.Types.NBT_End
|
||||||
|
import codes.mii.SaveEditor.Types.NBT_String
|
||||||
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
import java.nio.file.Files
|
||||||
|
|
||||||
|
class Converter {
|
||||||
|
fun convert(byte: ByteArray): NBT_Compound {
|
||||||
|
val result = NBT_Compound(0, "")
|
||||||
|
val byteSize = byte.size
|
||||||
|
var readingPosition = 0
|
||||||
|
|
||||||
|
while (byteSize > readingPosition) {
|
||||||
|
println(byte[readingPosition])
|
||||||
|
|
||||||
|
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 = ""
|
||||||
|
repeat(2) {
|
||||||
|
readingPosition++
|
||||||
|
textLengthText += byte[readingPosition].toString(16)
|
||||||
|
}
|
||||||
|
val textLength = textLengthText.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() -> {
|
||||||
|
result.data.add(NBT_Compound(nameLength.toByte(), name.toString()))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readingPosition++
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun convertFile(file: File): ByteArray? {
|
||||||
|
return Files.readAllBytes(file.toPath())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hexToAscii(hexStr: String): String? {
|
||||||
|
val output = StringBuilder("")
|
||||||
|
var i = 0
|
||||||
|
while (i < hexStr.length) {
|
||||||
|
val str = hexStr.substring(i, i + 2)
|
||||||
|
output.append(str.toInt(16).toChar())
|
||||||
|
i += 2
|
||||||
|
}
|
||||||
|
return output.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,41 @@
|
|||||||
package codes.mii.SaveEditor
|
package codes.mii.SaveEditor
|
||||||
|
|
||||||
|
import codes.mii.SaveEditor.Types.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
|
||||||
class SaveEditor {
|
class SaveEditor {
|
||||||
|
|
||||||
|
val converter: Converter = Converter()
|
||||||
|
|
||||||
fun start(args: Array<String>) {
|
fun start(args: Array<String>) {
|
||||||
println("Minecraft Save Editor.")
|
println("Minecraft Save Editor.")
|
||||||
|
|
||||||
if (args.count() >= 1) {
|
if (args.count() >= 1) {
|
||||||
var bytes = convertFile(File(args[0]))
|
val bytes = converter.convertFile(File(args[0]))
|
||||||
var builder: StringBuilder = StringBuilder()
|
|
||||||
bytes?.forEach {
|
val result = converter.convert(bytes!!)
|
||||||
val byteString = it.toString(16)
|
|
||||||
builder.append(if (byteString.length == 1) { "0$byteString" } else { byteString } + " ")
|
result.data.forEach {
|
||||||
|
when(it) {
|
||||||
|
is NBT_String -> {
|
||||||
|
println("STRING, Name: ${it.name}, Data: ${it.data}")
|
||||||
|
}
|
||||||
|
|
||||||
|
is NBT_End -> {
|
||||||
|
println("END")
|
||||||
|
}
|
||||||
|
|
||||||
|
is NBT_Byte -> {
|
||||||
|
println("BYTE, Name: ${it.name}, Data: ${it.data}")
|
||||||
|
}
|
||||||
|
|
||||||
|
is NBT_Compound -> {
|
||||||
|
println("COMPOUND, Name: ${it.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
println(builder.toString())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
|
||||||
fun convertFile(file: File): ByteArray? {
|
|
||||||
return Files.readAllBytes(file.toPath())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,6 @@ package codes.mii.SaveEditor.Types
|
|||||||
|
|
||||||
interface Data {
|
interface Data {
|
||||||
val typeByte: Byte
|
val typeByte: Byte
|
||||||
|
val nameLength: Byte
|
||||||
|
val name: String
|
||||||
}
|
}
|
||||||
10
src/main/kotlin/codes/mii/SaveEditor/Types/NBT.kt
Normal file
10
src/main/kotlin/codes/mii/SaveEditor/Types/NBT.kt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
enum class NBT(val type: Data) {
|
||||||
|
End(NBT_End()),
|
||||||
|
Byte(NBT_Byte(0,"",0)),
|
||||||
|
Int(NBT_Int(0, "", 0)),
|
||||||
|
Long(NBT_Long(0, "", 0)),
|
||||||
|
String(NBT_String(0, "", 0, "tes")),
|
||||||
|
Compound(NBT_Compound(0, ""))
|
||||||
|
}
|
||||||
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Byte.kt
Normal file
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Byte.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_Byte(override val nameLength: Byte, override val name: String, val data: Byte) : Data {
|
||||||
|
override val typeByte: Byte = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_Compound(override val nameLength: Byte, override val name: String) : Data {
|
||||||
|
override val typeByte: Byte = 10
|
||||||
|
val data: MutableList<Data> = mutableListOf()
|
||||||
|
}
|
||||||
7
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_End.kt
Normal file
7
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_End.kt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_End : Data {
|
||||||
|
override val name: String = "End"
|
||||||
|
override val nameLength: Byte = 0
|
||||||
|
override val typeByte: Byte = 0
|
||||||
|
}
|
||||||
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Int.kt
Normal file
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Int.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_Int(override val nameLength: Byte, override val name: String, val data: Int) : Data {
|
||||||
|
override val typeByte: Byte = 3
|
||||||
|
}
|
||||||
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Long.kt
Normal file
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_Long.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_Long(override val nameLength: Byte, override val name: String, val data: Long) : Data {
|
||||||
|
override val typeByte: Byte = 4
|
||||||
|
}
|
||||||
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_String.kt
Normal file
5
src/main/kotlin/codes/mii/SaveEditor/Types/NBT_String.kt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package codes.mii.SaveEditor.Types
|
||||||
|
|
||||||
|
class NBT_String(override val nameLength: Byte, override val name: String, val length: Byte, val data: String) : Data {
|
||||||
|
override val typeByte: Byte = 8
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user