From 67107758e52fde34bfd5d1252b7c08a0cdd4fe85 Mon Sep 17 00:00:00 2001 From: patataofcourse Date: Mon, 23 Oct 2023 08:59:43 +0200 Subject: [PATCH 1/4] No more trailing spaces --- .../kotlin/rhmodding/tickompiler/Functions.kt | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/rhmodding/tickompiler/Functions.kt b/src/main/kotlin/rhmodding/tickompiler/Functions.kt index 73db4b6..693ea8d 100644 --- a/src/main/kotlin/rhmodding/tickompiler/Functions.kt +++ b/src/main/kotlin/rhmodding/tickompiler/Functions.kt @@ -250,16 +250,25 @@ class BytesFunction : Function(-1, "bytes", 1..Int.MAX_VALUE) { } override fun produceTickflow(state: DecompilerState, opcode: Long, specialArg: Long, args: LongArray, comments: CommentType, specialArgStrings: Map): String { - return this.name + " " + argsToTickflowArgs(args, specialArgStrings) + if (args.size == 0) { + return this.name + } else { + return this.name + " " + argsToTickflowArgs(args, specialArgStrings) + } } } class OpcodeFunction : Function(-1, "opcode", 0..Integer.MAX_VALUE) { override fun produceTickflow(state: DecompilerState, opcode: Long, specialArg: Long, args: LongArray, comments: CommentType, specialArgStrings: Map): String { - return getHex(opcode) + + if (args.size == 0) { + return getHex(opcode) + addSpecialArg(specialArg) + } + else { + return getHex(opcode) + addSpecialArg(specialArg) + " " + argsToTickflowArgs(args, specialArgStrings) + } } override fun produceBytecode(funcCall: FunctionCall): LongArray { @@ -358,7 +367,12 @@ open class AliasedFunction(opcode: Long, alias: String, argsNeeded: IntRange, va comments: CommentType, specialArgStrings: Map): String { state.nextIndentLevel += indentChange state.currentAdjust = currentAdjust - return this.name + addSpecialArg(specialArg) + " " + argsToTickflowArgs(args, specialArgStrings) + if (args.size == 0) { + return this.name + addSpecialArg(specialArg) + } + else { + return this.name + addSpecialArg(specialArg) + " " + argsToTickflowArgs(args, specialArgStrings) + } } override fun produceBytecode(funcCall: FunctionCall): LongArray { From a638a10310a362fa95199d3e2abc8f15669036b4 Mon Sep 17 00:00:00 2001 From: patataofcourse Date: Mon, 23 Oct 2023 09:20:26 +0200 Subject: [PATCH 2/4] make start take priority over assets --- src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt index 40392a4..1bcd7fa 100644 --- a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt +++ b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt @@ -73,8 +73,9 @@ class Decompiler(val array: ByteArray, val order: ByteOrder, val functions: Func if (useMetadata) { builder.append("#index 0x${readInt().toString(16).toUpperCase()}\n") - markers[readInt()] = "start" + val startPos = readInt() markers[readInt()] = "assets" + markers[startPos] = "start" } for ((key, value) in macros) { From 8cd66b38d5feb42aae6c7a925c6dd29876df02f1 Mon Sep 17 00:00:00 2001 From: patataofcourse Date: Mon, 23 Oct 2023 09:40:10 +0200 Subject: [PATCH 3/4] properly decompile bytes argument annotation - this makes strings decompile properly if inside a bytes function - also adds safeguard for pack - since it's functional but still holds the same bug, just in a less harmful way --- .../tickompiler/decompiler/Decompiler.kt | 17 ++++++++++++++++- .../tickompiler/gameputter/GamePutter.kt | 5 +++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt index 1bcd7fa..0c980b3 100644 --- a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt +++ b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt @@ -94,8 +94,23 @@ class Decompiler(val array: ByteArray, val order: ByteOrder, val functions: Func } if (opint == 0xFFFFFFFF) { val amount = readInt() + var bytes = 0L for (i in 1..amount) { - anns.add(readInt()) + val ann = readInt() + if (ann and 0xFF == 3L) { + bytes = ann ushr 8 + } + else { + anns.add(ann) + } + } + if (bytes != 0L) { + val bytes_padded = bytes + if (bytes % 4 == 0L) 0 else (4 - bytes % 4) + counter += bytes_padded + for (i in 1..bytes_padded) { + read() + } + continue } opint = readInt() } diff --git a/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt b/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt index 14fccf8..4ecaec0 100644 --- a/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt +++ b/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt @@ -34,6 +34,11 @@ object GamePutter { if (anncode == 0 || anncode == 1 || anncode == 2) { adjArgs.add(annArg) } + else if (anncode == 3) { + for (a in 1..(annArg/4 + if (annArg % 4 == 0) 0 else (4 - annArg % 4))) { + result.add(gameContents.int) + } + } } opint = gameContents.int } From 6e9da2ada157ba6cae6aa9ca76715e21d4aef6a8 Mon Sep 17 00:00:00 2001 From: patataofcourse Date: Fri, 3 May 2024 10:42:04 +0200 Subject: [PATCH 4/4] readability edits --- src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt | 3 ++- src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt index 0c980b3..c6cc5b1 100644 --- a/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt +++ b/src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt @@ -105,7 +105,8 @@ class Decompiler(val array: ByteArray, val order: ByteOrder, val functions: Func } } if (bytes != 0L) { - val bytes_padded = bytes + if (bytes % 4 == 0L) 0 else (4 - bytes % 4) + if (bytes % 4 == 0L) + bytes += 4 - bytes % 4 counter += bytes_padded for (i in 1..bytes_padded) { read() diff --git a/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt b/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt index 4ecaec0..1c08b76 100644 --- a/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt +++ b/src/main/kotlin/rhmodding/tickompiler/gameputter/GamePutter.kt @@ -35,7 +35,8 @@ object GamePutter { adjArgs.add(annArg) } else if (anncode == 3) { - for (a in 1..(annArg/4 + if (annArg % 4 == 0) 0 else (4 - annArg % 4))) { + val num_ints = annArg/4 + if (annArg % 4 == 0) 0 else 1 + for (a in 1..num_ints) { result.add(gameContents.int) } }