diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index 2026f5e..8928945 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -6,6 +6,7 @@ import rt4.Player; /** * The base plugin class which is meant to be extended by plugins. * Contains callbacks to many parts of the internal client code. + * @author ceikry */ public abstract class Plugin { long timeOfLastDraw; @@ -55,4 +56,6 @@ public abstract class Plugin { * @param screenY the Y coordinate on the screen for overhead drawing */ public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {} + + public void ProcessCommand(String commandStr, String[] args) {} } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 7c58c99..096e692 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -1,12 +1,14 @@ package plugin; import rt4.GlobalJsonConfig; +import rt4.JagString; import rt4.Npc; import rt4.Player; import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import java.util.Arrays; import java.util.HashMap; import java.util.Objects; @@ -90,4 +92,10 @@ public class PluginRepository { public static void PlayerOverheadDraw(Player player, int screenX, int screenY) { loadedPlugins.values().forEach((plugin) -> plugin.PlayerOverheadDraw(player, screenX, screenY)); } + + public static void ProcessCommand(JagString commandStr) { + String[] tokens = commandStr.toString().split(" "); + String[] args = Arrays.copyOfRange(tokens, 1, tokens.length); + loadedPlugins.values().forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); + } } diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index e9d9692..504d6e4 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -1,9 +1,11 @@ package plugin.api; -import rt4.Font; -import rt4.Fonts; -import rt4.JagString; +import rt4.*; +/** + * API used for writing plugins, so dozens of plugins don't break when we rename shit :) + * @author ceikry + */ public class API { public static void DrawText(FontType fontType, FontColor color, TextModifier mod, String text, int screenX, int screenY) { JagString js = JagString.parse(text); @@ -41,4 +43,8 @@ public class API { break; } } + + public static boolean PlayerHasPrivilege(Privileges privilege) { + return LoginManager.staffModLevel >= privilege.ordinal(); + } } diff --git a/client/src/main/java/plugin/api/Privileges.java b/client/src/main/java/plugin/api/Privileges.java new file mode 100644 index 0000000..75216b6 --- /dev/null +++ b/client/src/main/java/plugin/api/Privileges.java @@ -0,0 +1,7 @@ +package plugin.api; + +public enum Privileges { + NONE, + PMOD, + JMOD +} diff --git a/client/src/main/java/rt4/Cheat.java b/client/src/main/java/rt4/Cheat.java index 5c44533..9f046f2 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -109,6 +109,7 @@ public class Cheat { @OriginalMember(owner = "client!k", name = "a", descriptor = "(Lclient!na;Z)V") public static void execute(@OriginalArg(0) JagString arg0) { + PluginRepository.ProcessCommand(arg0); // if (LoginManager.staffModLevel >= 2) { @Pc(18) int local18; @Pc(38) int local38; diff --git a/plugin-playground/build.gradle b/plugin-playground/build.gradle index 63b66f7..3000054 100644 --- a/plugin-playground/build.gradle +++ b/plugin-playground/build.gradle @@ -21,7 +21,46 @@ test { useJUnitPlatform() } -task buildPlugins { - dependsOn(classes) +task initializeNewPlugin { + doLast { + def pluginFile = new File("src/main/java/MyPlugin") + pluginFile.mkdirs() + def props = new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/java/MyPlugin/plugin.properties").text = """ +AUTHOR='Me' +DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! +VERSION=-1.1 +""" + def java = new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/java/MyPlugin/plugin.java").text = """ +package MyPlugin; + +import plugin.Plugin; + +public class plugin extends Plugin { + @Override + public void Init() { + //Init() is called when the plugin is loaded + } + + @Override + public void Update() { + //Update() is called once per tick (600ms) + } + + @Override + public void Draw(long deltaTime) { + //Draw() is called once per frame, with deltaTime being the time since last frame. + } + + //Check the source of plugin.Plugin for more methods you can override! Happy hacking! <3 + //There are also many methods to aid in plugin development in plugin.api.API +} +""" + } +} + +task buildPlugins(type: Copy, dependsOn: classes) { + def pluginsPath = rootProject.project("client").projectDir.absolutePath + File.separator + "plugins" + from "build/classes/java/main" + into pluginsPath } \ No newline at end of file diff --git a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java index 35c0d03..610c31a 100644 --- a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java @@ -1,15 +1,19 @@ package OverheadDebugPlugin; import plugin.Plugin; -import plugin.api.API; -import plugin.api.FontColor; -import plugin.api.FontType; -import plugin.api.TextModifier; +import plugin.api.*; import rt4.*; +/** + * @author ceikry + */ public class plugin extends Plugin { + private boolean isEnabled = false; + @Override public void PlayerOverheadDraw(Player player, int screenX, int screenY) { + if (!isEnabled) return; + API.DrawText( FontType.SMALL, FontColor.YELLOW, @@ -22,6 +26,8 @@ public class plugin extends Plugin { @Override public void NPCOverheadDraw(Npc npc, int screenX, int screenY) { + if (!isEnabled) return; + String npcSb = (npc.type.name.strEquals(JagString.parse("null")) ? npc.type.getMultiNpc() != null @@ -44,4 +50,13 @@ public class plugin extends Plugin { screenY ); } + + @Override + public void ProcessCommand(String commandStr, String[] args) { + if (!API.PlayerHasPrivilege(Privileges.JMOD)) return; + + if (commandStr.equalsIgnoreCase("::npcdebug")) { + isEnabled = !isEnabled; + } + } } diff --git a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties new file mode 100644 index 0000000..9972734 --- /dev/null +++ b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties @@ -0,0 +1,3 @@ +AUTHOR="Ceikry" +DESCRIPTION="Renders helpful debug text over the heads of players and NPCs." +VERSION=1.0 \ No newline at end of file