Skip to content

Commit

Permalink
#31 adding ChatListner
Browse files Browse the repository at this point in the history
  • Loading branch information
acorbin3 committed Jan 13, 2020
1 parent 63a5fe2 commit 9c0ceca
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
31 changes: 31 additions & 0 deletions src/com/p3achb0t/analyser/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,37 @@ class Analyser{
classes[runeStar.analyzers[clazzData.`class`]?.name]?.methods?.add(methodNode)
}

//Inject addMessage
if (clazzData.`class` == "ChatChannel") {
val methodHook = runeStar.analyzers[clazzData.`class`]?.methods?.find { it.method == "addMessage" }
println("MethodHook: $methodHook")
val list = methodHook?.descriptor?.split(")")!!
val argumentDescription = list[0] + ")" // Add back in the )
val returnDescriptor = list[1]
val clazzName = runeStar.classRefObs[cleanType(returnDescriptor)]?.`class`

val returnType = "L$classPath/$clazzName;"
println("Return type $returnType")

//Find the addMessage method, then inject the call back at the front
classes[runeStar.analyzers[clazzData.`class`]?.name]?.methods?.forEach { methodNode ->
println("Looking at method: ${methodNode.name}")
if (methodNode.name == methodHook.name && methodNode.desc.contains("ILjava/lang/String;Ljava/lang/String;Ljava/lang/String")) {
println("methodNode.desc: ${methodNode.desc}")
println("Time to insert instructions")
val il = InsnList()
il.add(FieldInsnNode(GETSTATIC, "client", "script", "Lcom/p3achb0t/interfaces/ScriptManager;"))
il.add(VarInsnNode(ILOAD, 1))
il.add(VarInsnNode(ALOAD, 2))
il.add(VarInsnNode(ALOAD, 3))
il.add(VarInsnNode(ALOAD, 4))
il.add(MethodInsnNode(INVOKEVIRTUAL, "com/p3achb0t/interfaces/ScriptManager", "notifyMessage", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"))
methodNode.instructions.insert(il)

}
}
}

// println("Methods:~~~~~~")
// addInvokeMethods(clazzData, runeStar, classPath, classes)

Expand Down
15 changes: 7 additions & 8 deletions src/com/p3achb0t/interfaces/ScriptManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScriptManager(val client: Any) {
private var isRunning = false
private var paused = false
lateinit var thread: Job
var gameLoopI = 0


fun setScript(s: AbstractScript) {
Expand All @@ -47,16 +48,14 @@ class ScriptManager(val client: Any) {
}
}

fun notifyMessage(){

fun notifyMessage(flags: Int, name: String, message: String, prefix: String?) {
println("Message received Flags: $flags, name:$name, message:$message, prefix:$prefix")
if (this.script is ChatListener) {
val updatedPrefix = prefix ?: ""
(this.script as ChatListener).notifyMessage(flags, name, message, updatedPrefix)
}
}

suspend fun gameLoop(){
if(this.script is ChatListener) {
(this.script as ChatListener).notifyMessage()
}

}


fun start() {
Expand Down

0 comments on commit 9c0ceca

Please sign in to comment.