Skip to content

Commit

Permalink
staging
Browse files Browse the repository at this point in the history
  • Loading branch information
zeruth committed Jun 5, 2024
1 parent e5e68b2 commit 37ea713
Show file tree
Hide file tree
Showing 20 changed files with 371 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
<repository>
<id>jcenter</id>
<name>JCenter Repository</name>
<url>https://jcenter.bintray.com/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
Expand Down
5 changes: 5 additions & 0 deletions runelite-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<version>5.4</version>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
13 changes: 13 additions & 0 deletions runelite-client/src/main/java/ext/ethans/QuickPrayerExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ext.ethans

import com.example.EthanApiPlugin.Collections.query.QuickPrayer
import com.example.EthanApiPlugin.EthanApiPlugin

object QuickPrayerExt {
/**
* Checks whether an individual quick prayer is active
*/
fun QuickPrayer.isActive() : Boolean {
return EthanApiPlugin.isQuickPrayerActive(this)
}
}
5 changes: 5 additions & 0 deletions runelite-client/src/main/java/ext/runelite/NPCExt.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ext.runelite

import com.example.EthanApiPlugin.EthanApiPlugin
import ext.kotlin.KClassExt.getInstance
import ext.runelite.NPCCompositionExt.isOf
import net.runelite.api.Client
Expand Down Expand Up @@ -35,4 +36,8 @@ object NPCExt {
fun NPC.Companion.forEach(task : (NPC) -> Unit) {
client.npcs.filterNotNull().forEach(task)
}

fun NPC.getTrueAnimation() : Int {
return EthanApiPlugin.getAnimation(this)
}
}
6 changes: 6 additions & 0 deletions runelite-client/src/main/java/ext/runelite/PlayerExt.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ext.runelite

import com.example.EthanApiPlugin.EthanApiPlugin
import ext.kotlin.KClassExt.getInstance
import net.runelite.api.Client
import net.runelite.api.HeadIcon
import net.runelite.api.Player
import net.runelite.api.SkullIcon

Expand All @@ -15,4 +17,8 @@ object PlayerExt {
fun Player.Companion.forEach(task : (Player) -> Unit) {
client.players.filterNotNull().forEach(task)
}

fun Player.getSkullIcon() : SkullIcon {
return EthanApiPlugin.getSkullIcon(this)
}
}
37 changes: 37 additions & 0 deletions runelite-client/src/main/java/ext/runelite/PluginExt.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
package ext.runelite

import com.example.EthanApiPlugin.Collections.query.QuickPrayer
import com.example.EthanApiPlugin.EthanApiPlugin
import ext.kotlin.KClassExt.getInstance
import ext.runelite.PluginManagerExt.get
import hotlite.plugins.scriptmanager.ScriptManager
import net.runelite.api.ChatMessageType
import net.runelite.api.Client
import net.runelite.api.widgets.Widget
import net.runelite.api.widgets.WidgetInfo
import net.runelite.client.plugins.Plugin
import net.runelite.client.plugins.PluginManager

object PluginExt {
val client = Client::class.getInstance()
val pluginManager = PluginManager::class.getInstance()

inline fun <reified T> Plugin.getInjectedInstance(): T {
return injector.getInstance(T::class.java)
}

fun Plugin.loggedIn() : Boolean {
return EthanApiPlugin.loggedIn()
}

fun Plugin.getClient() : Client {
return EthanApiPlugin.getClient()
}

fun Plugin.isQuickPrayerEnabled() : Boolean {
return EthanApiPlugin.isQuickPrayerEnabled()
}

fun Plugin.sendGameMessage(message: String) {
getClient().addChatMessage(ChatMessageType.GAMEMESSAGE, "", message, "")
}

fun Plugin.getWidget(group: Int, child: Int): Widget? {
return client.getWidget(WidgetInfo.PACK(group, child))
}

fun Plugin.getScriptManager() : ScriptManager {
return pluginManager.get<ScriptManager>()
}
}
5 changes: 5 additions & 0 deletions runelite-client/src/main/java/ext/runelite/PrayerExt.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package ext.runelite

import net.runelite.api.Client
import net.runelite.api.Prayer

object PrayerExt {
fun Prayer.blah() {

}
}
5 changes: 5 additions & 0 deletions runelite-client/src/main/java/ext/runelite/SceneExt.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ext.runelite

import com.example.EthanApiPlugin.EthanApiPlugin
import ext.kotlin.KClassExt.getInstance
import ext.runelite.DecorativeObjectExt.isOf
import ext.runelite.DequeExt.withID
Expand Down Expand Up @@ -79,4 +80,8 @@ object SceneExt {
fun Scene.Companion.projectilesWithID(vararg ids: Int) : List<Projectile> {
return client.projectiles.withID(*ids)
}

fun Scene.containsRegion(regionID: Int) : Boolean {
return EthanApiPlugin.inRegion(regionID)
}
}
6 changes: 6 additions & 0 deletions runelite-client/src/main/java/ext/runelite/WidgetExt.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package ext.runelite

import com.example.Packets.WidgetPackets
import net.runelite.api.widgets.Widget

object WidgetExt {
fun Widget.doAction(action: String) {
WidgetPackets.queueWidgetAction(this, action)
}
}
11 changes: 11 additions & 0 deletions runelite-client/src/main/java/hotlite/api/Varp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hotlite.api

import net.runelite.api.Client
import net.runelite.client.RuneLite

open class Varp(val id: Int) {
private var client = RuneLite.getInjector().getInstance(Client::class.java)
fun getValue() : Int {
return client.getVarpValue(id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hotlite.api.varp

import hotlite.api.Varp

object TutorialProgressVarp : Varp(281) {
const val CHOOSE_NAME = 1
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package hotlite.plugins.example

import com.example.EthanApiPlugin.Collections.query.QuickPrayer
import com.example.EthanApiPlugin.EthanApiPlugin
import com.google.inject.Inject
import com.google.inject.Provides
import ext.ethans.QuickPrayerExt.isActive
import ext.runelite.NPCExt.getTrueAnimation
import ext.runelite.PlayerExt.getSkullIcon
import ext.runelite.PluginExt.getClient
import ext.runelite.PluginExt.getInjectedInstance
import net.runelite.api.Prayer
import net.runelite.api.events.GameTick
import net.runelite.client.config.ConfigManager
import net.runelite.client.eventbus.Subscribe
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package hotlite.plugins.scriptmanager

import com.example.EthanApiPlugin.EthanApiPlugin
import ext.kotlin.KClassExt.getInstance
import ext.runelite.PluginManagerExt.get
import net.runelite.api.Client
import net.runelite.api.widgets.Widget
import net.runelite.api.widgets.WidgetInfo
import net.runelite.client.RuneLite
import net.runelite.client.plugins.PluginManager

open class Script(var priority: Int = Int.MAX_VALUE-1) {
val client = Client::class.getInstance()
val childScripts = arrayListOf<Script>()
var message: String = ""
val ethans = PluginManager::class.getInstance().get<EthanApiPlugin>()
open fun onGameTick() : ((Script) -> ScriptState)? = null

fun getWidget(group: Int, child: Int): Widget? {
return client.getWidget(WidgetInfo.PACK(group, child))
}

fun error(message: String) : ScriptState {
println("ERROR: $message")
return ScriptState.ABORTED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package hotlite.plugins.scriptmanager

import net.runelite.api.events.GameTick
import net.runelite.client.eventbus.Subscribe
import net.runelite.client.plugins.Plugin
import net.runelite.client.plugins.PluginDescriptor

/**
* This controls the execution flow of [Script]s and their childScripts
*/
@PluginDescriptor(
name = "Z-ScriptManager",
description = "Script runner",
tags = ["kotlin"]
)
class ScriptManager : Plugin(){
val scripts = ArrayList<Script>()
val scriptsPendingRemoval = ArrayList<Script>()

fun onGameTickExecution(script: Script, execution: ((Script) -> ScriptState)) {
val result = execution.invoke(script)
when (result) {
ScriptState.RUNNING -> {}
ScriptState.PAUSED -> {}
ScriptState.FINISHED -> {
scriptsPendingRemoval.add(script)
}
ScriptState.ABORTED -> {
scriptsPendingRemoval.add(script)
}
}
}

fun ArrayList<Script>.priorityForEach(unit: (Script) -> ScriptState?) {
this
.sortedBy { it.priority }
.forEach {
val result = unit.invoke(it)
}
}

@Subscribe
private fun onGameTick(gameTick: GameTick) {
try {
scripts.priorityForEach { script ->
val rootResult = script.onGameTick()?.invoke(script)
script.childScripts.priorityForEach { childScript ->
childScript.onGameTick()?.invoke(childScript)
}
return@priorityForEach rootResult
}

scriptsPendingRemoval.forEach { scripts.remove(it) }
} catch (e: Exception) {
println("Uncaught Script Exception:")
e.printStackTrace()
}
}

fun registerScript(script: Script) {
scripts.add(script)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package hotlite.plugins.scriptmanager

enum class ScriptState {
RUNNING,
PAUSED,
FINISHED,
ABORTED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package hotlite.plugins.tutorial

import com.example.Packets.MousePackets
import com.example.Packets.WidgetPackets
import hotlite.plugins.scriptmanager.Script
import hotlite.plugins.scriptmanager.ScriptState
import net.runelite.api.widgets.Widget

object ChooseNameScript : Script() {
override fun onGameTick(): (Script) -> ScriptState = script@{
fetchSetDisplayNameRootWidget()?.let { rootWidget ->
if (rootWidget.isHidden)
return@script error("SetDisplayNameRootWidget must not be hidden")
else {
fetchSetDisplayNameTextFieldWidget()?.let { textField ->
if (textField.isHidden)
return@script error("SetDisplayNameTextFieldWidget must not be hidden")
else {
/* if (textField.text != "AliBaba") {
textField.setText("AliBaba")
return@script ScriptState.PAUSED
}*/
fetchLookupNameButtonWidget()?.let {
if (it.onOpListener != null) {
println("sending packet")
lookupName()
return@script ScriptState.PAUSED
} else {

}
}
}
}
}

}
return@script ScriptState.RUNNING
}

fun fetchSetDisplayNameRootWidget(): Widget? {
return getWidget(558, 3)
}

fun fetchSetDisplayNameTextFieldWidget(): Widget? {
return getWidget(558, 12)
}

fun fetchNameAvailabilityResponseTextWidget(): Widget? {
return getWidget(558, 13)
}

fun fetchLookupNameButtonWidget(): Widget? {
return getWidget(558, 18)
}

fun lookupName() {
fetchLookupNameButtonWidget()?.let {
if (it.onOpListener.isEmpty()) {
//name already taken and text field not edited yet
} else {
MousePackets.queueClickPacket()
WidgetPackets.queueWidgetActionPacket(1, it.id, it.itemId, it.index)
}
}
}

private fun Widget.lookupName() {

}
}
Loading

0 comments on commit 37ea713

Please sign in to comment.