├── .gitignore ├── src └── main │ ├── resources │ └── org │ │ └── runestar │ │ └── cs2 │ │ ├── boolean-names.tsv │ │ ├── setsize-names.tsv │ │ ├── windowmode-names.tsv │ │ ├── inv-names.tsv │ │ ├── settextalignh-names.tsv │ │ ├── settextalignv-names.tsv │ │ ├── clienttype-names.tsv │ │ ├── iftype-names.tsv │ │ ├── chatfilter-names.tsv │ │ ├── setposh-names.tsv │ │ ├── setposv-names.tsv │ │ ├── stat-names.tsv │ │ ├── fontmetrics-names.tsv │ │ ├── param-names.tsv │ │ ├── chattype-names.tsv │ │ ├── maparea-names.tsv │ │ ├── key-names.tsv │ │ ├── interface-names.tsv │ │ ├── struct-names.tsv │ │ └── param-types.tsv │ └── java │ └── org │ └── runestar │ └── cs2 │ ├── bin │ ├── StackType.kt │ ├── ClientScriptDesc.kt │ ├── Trigger.kt │ ├── Value.kt │ ├── ScriptName.kt │ ├── Type.kt │ ├── Script.kt │ └── Opcodes.kt │ ├── ir │ ├── FunctionSet.kt │ ├── CallGraph.kt │ ├── Function.kt │ ├── EventProperty.kt │ ├── Element.kt │ ├── Instruction.kt │ ├── Variable.kt │ ├── Typing.kt │ ├── Expression.kt │ ├── Typings.kt │ ├── Prototype.kt │ └── Interpreter.kt │ ├── cg │ ├── Generator.kt │ ├── Ints.kt │ └── StrictGenerator.kt │ ├── cfa │ ├── FlowGraph.kt │ ├── Construct.kt │ ├── Block.kt │ └── Reconstruct.kt │ ├── util │ ├── Chain.kt │ ├── ListStack.kt │ ├── Extensions.kt │ ├── DirectedGraph.kt │ ├── LinkedGraph.kt │ ├── PartitionedChain.kt │ ├── Loader.kt │ ├── DominatorTree.kt │ └── HashChain.kt │ ├── Decompiler.kt │ ├── dfa │ ├── DeleteNops.kt │ ├── ReorderArgs.kt │ ├── Phase.kt │ ├── RemoveDeadCode.kt │ ├── CombineSameLineOperations.kt │ ├── FindArrayArgs.kt │ ├── AddShortCircuitOperators.kt │ ├── CalcIdentifiers.kt │ ├── InlineStackDefinitions.kt │ └── CalcTypes.kt │ ├── Example.kt │ └── Resources.kt ├── NOTICE ├── pom.xml ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | target 3 | *.iml 4 | input/ 5 | scripts/ -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/boolean-names.tsv: -------------------------------------------------------------------------------- 1 | 0 false 2 | 1 true -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/setsize-names.tsv: -------------------------------------------------------------------------------- 1 | 0 abs 2 | 1 minus 3 | 2 2 -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/windowmode-names.tsv: -------------------------------------------------------------------------------- 1 | 1 fixed 2 | 2 resizable -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/inv-names.tsv: -------------------------------------------------------------------------------- 1 | 93 inv 2 | 94 worn 3 | 95 bank 4 | -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/settextalignh-names.tsv: -------------------------------------------------------------------------------- 1 | 0 left 2 | 1 centre 3 | 2 right -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/settextalignv-names.tsv: -------------------------------------------------------------------------------- 1 | 0 top 2 | 1 centre 3 | 2 bottom -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/clienttype-names.tsv: -------------------------------------------------------------------------------- 1 | 1 desktop 2 | 2 android 3 | 3 ios 4 | 4 enhanced 5 | -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/iftype-names.tsv: -------------------------------------------------------------------------------- 1 | 3 rectangle 2 | 4 text 3 | 5 graphic 4 | 6 model 5 | 9 line -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/chatfilter-names.tsv: -------------------------------------------------------------------------------- 1 | 0 on 2 | 1 friends 3 | 2 off 4 | 3 hide 5 | 4 autochat 6 | -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/setposh-names.tsv: -------------------------------------------------------------------------------- 1 | 0 abs_left 2 | 1 abs_centre 3 | 2 abs_right 4 | 3 3 5 | 4 4 6 | 5 5 -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/setposv-names.tsv: -------------------------------------------------------------------------------- 1 | 0 abs_top 2 | 1 abs_centre 3 | 2 abs_bottom 4 | 3 3 5 | 4 4 6 | 5 5 -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/bin/StackType.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.bin 2 | 3 | enum class StackType(val defaultType: Type) { 4 | INT(Type.INT), 5 | STRING(Type.STRING), 6 | } -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/ir/FunctionSet.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.ir 2 | 3 | class FunctionSet( 4 | val functions: Map, 5 | val typings: Typings, 6 | val callGraph: CallGraph, 7 | ) -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/cg/Generator.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.cg 2 | 3 | import org.runestar.cs2.cfa.Construct 4 | import org.runestar.cs2.ir.Function 5 | import org.runestar.cs2.ir.FunctionSet 6 | 7 | interface Generator { 8 | 9 | fun write(f: Function, fs: FunctionSet, root: Construct) 10 | } -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/cfa/FlowGraph.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.cfa 2 | 3 | import org.runestar.cs2.ir.Function 4 | import org.runestar.cs2.util.dominatorTree 5 | 6 | class FlowGraph(val f: Function) { 7 | 8 | val blocks = partitionBlocks(f) 9 | 10 | val graph = graphBlocks(blocks) 11 | 12 | val dtree = dominatorTree(graph) 13 | } -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/stat-names.tsv: -------------------------------------------------------------------------------- 1 | 0 attack 2 | 1 defence 3 | 2 strength 4 | 3 hitpoints 5 | 4 ranged 6 | 5 prayer 7 | 6 magic 8 | 7 cooking 9 | 8 woodcutting 10 | 9 fletching 11 | 10 fishing 12 | 11 firemaking 13 | 12 crafting 14 | 13 smithing 15 | 14 mining 16 | 15 herblore 17 | 16 agility 18 | 17 thieving 19 | 18 slayer 20 | 19 farming 21 | 20 runecraft 22 | 21 hunter 23 | 22 construction 24 | -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/fontmetrics-names.tsv: -------------------------------------------------------------------------------- 1 | 494 p11_full 2 | 495 p12_full 3 | 496 b12_full 4 | 497 q8_full 5 | 645 quill_oblique_large 6 | 646 quill_caps_large 7 | 647 lunar_alphabet 8 | 648 lunar_alphabet_lrg 9 | 764 barbassault_font 10 | 819 surok_font 11 | 1442 verdana_11pt_regular 12 | 1443 verdana_11pt_bold 13 | 1445 verdana_13pt_regular 14 | 1446 verdana_13pt_bold 15 | 1447 verdana_15pt_regular 16 | -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/ir/CallGraph.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.ir 2 | 3 | import org.runestar.cs2.bin.Trigger 4 | import org.runestar.cs2.util.LinkedGraph 5 | 6 | class CallGraph { 7 | 8 | // val graph = LinkedGraph() 9 | 10 | val triggers = HashMap() 11 | 12 | fun call(from: Int, to: Int, trigger: Trigger) { 13 | triggers[to] = trigger 14 | // graph.addSuccessor(from, to) 15 | } 16 | } -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/param-names.tsv: -------------------------------------------------------------------------------- 1 | 336 spell_spellbook 2 | 365 magic_runetype_1 3 | 366 magic_runecount_1 4 | 367 magic_runetype_2 5 | 368 magic_runecount_2 6 | 369 magic_runetype_3 7 | 370 magic_runecount_3 8 | 596 spell_button 9 | 597 spell_graphic1_on 10 | 598 spell_graphic1_off 11 | 599 spell_graphic2_on 12 | 600 spell_graphic2_off 13 | 601 spell_name 14 | 602 spell_desc 15 | 603 spell_membersonly 16 | 604 spell_levelreq 17 | 605 spell_type 18 | 606 magic_runetype_4 19 | 607 magic_runecount_4 -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/util/Chain.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.util 2 | 3 | interface Chain : MutableIterable { 4 | 5 | val first: E 6 | 7 | val last: E 8 | 9 | fun addFirst(e: E) 10 | 11 | fun addLast(e: E) 12 | 13 | fun next(e: E): E? 14 | 15 | fun previous(e: E): E? 16 | 17 | fun insertAfter(e: E, point: E) 18 | 19 | fun insertBefore(e: E, point: E) 20 | 21 | fun remove(e: E) 22 | 23 | override fun iterator(): MutableIterator = iterator(first, last) 24 | 25 | fun iterator(from: E, to: E): MutableIterator 26 | } -------------------------------------------------------------------------------- /src/main/resources/org/runestar/cs2/chattype-names.tsv: -------------------------------------------------------------------------------- 1 | 0 gamemessage 2 | 1 modchat 3 | 2 publicchat 4 | 3 privatechat 5 | 4 engine 6 | 5 loginlogoutnotification 7 | 6 privatechatout 8 | 7 modprivatechat 9 | 9 friendschat 10 | 11 friendschatnotification 11 | 14 broadcast 12 | 26 snapshotfeedback 13 | 27 obj_examine 14 | 28 npc_examine 15 | 29 loc_examine 16 | 30 friendnotification 17 | 31 ignorenotification 18 | 90 autotyper 19 | 91 modautotyper 20 | 99 console 21 | 101 tradereq 22 | 102 trade 23 | 103 chalreq_trade 24 | 104 chalreq_friendschat 25 | 105 spam 26 | 106 playerrelated 27 | 107 10sectimeout 28 | -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/util/ListStack.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.util 2 | 3 | data class ListStack(val delegate: MutableList) { 4 | 5 | val size: Int get() = delegate.size 6 | 7 | fun isEmpty(): Boolean = delegate.isEmpty() 8 | 9 | fun push(element: T) { delegate.add(element) } 10 | 11 | fun peek(): T = delegate[delegate.lastIndex] 12 | 13 | fun pop(): T = delegate.removeAt(delegate.lastIndex) 14 | 15 | fun popAll(): List = delegate.toList().also { delegate.clear() } 16 | 17 | fun pop(count: Int): List = MutableList(count) { pop() }.also { it.reverse() } 18 | } -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/ir/Function.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2.ir 2 | 3 | import org.runestar.cs2.bin.StackType 4 | import org.runestar.cs2.util.Chain 5 | 6 | class Function( 7 | val id: Int, 8 | var arguments: List, 9 | val instructions: Chain, 10 | val returnTypes: List 11 | ) { 12 | 13 | override fun toString() = buildString { 14 | append("id=").appendLine(id) 15 | append("arguments=").appendLine(arguments) 16 | append("returnTypes=").appendLine(returnTypes) 17 | instructions.forEach { appendLine(it) } 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/org/runestar/cs2/Decompiler.kt: -------------------------------------------------------------------------------- 1 | package org.runestar.cs2 2 | 3 | import org.runestar.cs2.bin.Script 4 | import org.runestar.cs2.cfa.reconstruct 5 | import org.runestar.cs2.cg.Generator 6 | import org.runestar.cs2.dfa.Phase 7 | import org.runestar.cs2.ir.Command 8 | import org.runestar.cs2.ir.interpret 9 | import org.runestar.cs2.util.Loader 10 | 11 | fun decompile( 12 | scripts: Loader.Keyed