Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/main/kotlin/rhmodding/tickompiler/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, String>): 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<Int, String>): 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 {
Expand Down Expand Up @@ -358,7 +367,12 @@ open class AliasedFunction(opcode: Long, alias: String, argsNeeded: IntRange, va
comments: CommentType, specialArgStrings: Map<Int, String>): 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 {
Expand Down
21 changes: 19 additions & 2 deletions src/main/kotlin/rhmodding/tickompiler/decompiler/Decompiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -93,8 +94,24 @@ 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) {
if (bytes % 4 == 0L)
bytes += 4 - bytes % 4
counter += bytes_padded
for (i in 1..bytes_padded) {
read()
}
continue
}
opint = readInt()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ object GamePutter {
if (anncode == 0 || anncode == 1 || anncode == 2) {
adjArgs.add(annArg)
}
else if (anncode == 3) {
val num_ints = annArg/4 + if (annArg % 4 == 0) 0 else 1
for (a in 1..num_ints) {
result.add(gameContents.int)
}
}
}
opint = gameContents.int
}
Expand Down