From a6577064b04ca658aacd5f086e9a574f10e7f7a0 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 08:13:32 -0500 Subject: [PATCH] Commit start of plugin work --- client/config.json | 7 +- client/src/main/java/plugin/Plugin.java | 58 ++++++++++++ client/src/main/java/plugin/PluginInfo.java | 57 ++++++++++++ .../main/java/plugin/PluginRepository.java | 93 +++++++++++++++++++ client/src/main/java/plugin/api/API.java | 44 +++++++++ .../src/main/java/plugin/api/FontColor.java | 17 ++++ client/src/main/java/plugin/api/FontType.java | 6 ++ .../main/java/plugin/api/TextModifier.java | 10 ++ client/src/main/java/rt4/Cheat.java | 5 + client/src/main/java/rt4/Cs1ScriptRunner.java | 2 + .../src/main/java/rt4/GlobalJsonConfig.java | 2 +- client/src/main/java/rt4/NpcType.java | 2 +- client/src/main/java/rt4/ScriptRunner.java | 90 ++++++++++-------- client/src/main/java/rt4/WorldMap.java | 1 + client/src/main/java/rt4/client.java | 2 + plugin-playground/build.gradle | 27 ++++++ .../main/java/OverheadDebugPlugin/plugin.java | 47 ++++++++++ settings.gradle | 2 + 18 files changed, 426 insertions(+), 46 deletions(-) create mode 100644 client/src/main/java/plugin/Plugin.java create mode 100644 client/src/main/java/plugin/PluginInfo.java create mode 100644 client/src/main/java/plugin/PluginRepository.java create mode 100644 client/src/main/java/plugin/api/API.java create mode 100644 client/src/main/java/plugin/api/FontColor.java create mode 100644 client/src/main/java/plugin/api/FontType.java create mode 100644 client/src/main/java/plugin/api/TextModifier.java create mode 100644 plugin-playground/build.gradle create mode 100644 plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java diff --git a/client/config.json b/client/config.json index 1c98155..7f0f5fd 100644 --- a/client/config.json +++ b/client/config.json @@ -1,9 +1,10 @@ { - "ip_management": "test.2009scape.org", - "ip_address": "test.2009scape.org", + "ip_management": "play.2009scape.org", + "ip_address": "play.2009scape.org", "world": 1, "server_port": 43594, "wl_port": 43595, "js5_port": 43595, - "mouseWheelZoom": true + "mouseWheelZoom": true, + "pluginsFolder": "plugins" } \ No newline at end of file diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java new file mode 100644 index 0000000..2026f5e --- /dev/null +++ b/client/src/main/java/plugin/Plugin.java @@ -0,0 +1,58 @@ +package plugin; + +import rt4.Npc; +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. + */ +public abstract class Plugin { + long timeOfLastDraw; + + void _init() { + Init(); + } + + void _draw() { + long nowTime = System.currentTimeMillis(); + Draw(nowTime - timeOfLastDraw); + timeOfLastDraw = nowTime; + } + + /** + * Draw() is called by the client rendering loop so that plugins can draw information onto the screen. + * This will be called once per frame, meaning it is framerate bound. + * @param timeDelta the time (ms) elapsed since the last draw call. + */ + public void Draw(long timeDelta) {} + + /** + * Init() is called when the plugin is first loaded + */ + public void Init() {} + + /** + * OnXPUpdate() is called when the client receives an XP update packet. This includes at login. + */ + public void OnXPUpdate() {} + + /** + * Update() is called once per tick, aka once every 600ms. + */ + public void Update() {} + + /** + * PlayerOverheadDraw() is called once per frame, for every player on the screen. :) Expensive. + * @param screenX the X coordinate on the screen for overhead drawing + * @param screenY the Y coordinate on the screen for overhead drawing + */ + public void PlayerOverheadDraw(Player player, int screenX, int screenY) {} + + /** + * NPCOverheadDraw() is called once per frame, for every NPC on the screen. :) Expensive. + * @param screenX the X coordinate on the screen for overhead drawing + * @param screenY the Y coordinate on the screen for overhead drawing + */ + public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {} +} diff --git a/client/src/main/java/plugin/PluginInfo.java b/client/src/main/java/plugin/PluginInfo.java new file mode 100644 index 0000000..11d64f8 --- /dev/null +++ b/client/src/main/java/plugin/PluginInfo.java @@ -0,0 +1,57 @@ +package plugin; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.util.Objects; +import java.util.Properties; + +/** + * A data class for storing information about plugins. + * @author ceikry + */ +class PluginInfo { + double version; + String author; + String description; + + public PluginInfo(String author, String description, double version) { + this.version = version; + this.author = author; + this.description = description; + } + + public static PluginInfo loadFromFile(File file) { + Properties prop = new Properties(); + + try { + prop.load(new FileReader(file)); + } catch (FileNotFoundException e) { + System.err.println("File does not exist! - " + file.getAbsolutePath()); + return new PluginInfo("", "", 0.0); + } catch (IOException e) { + e.printStackTrace(); + return new PluginInfo("", "", 0.0); + } + + return new PluginInfo( + prop.get("AUTHOR").toString(), + prop.get("DESCRIPTION").toString(), + Double.parseDouble(prop.get("VERSION").toString()) + ); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PluginInfo that = (PluginInfo) o; + return Double.compare(that.version, version) == 0 && Objects.equals(author, that.author) && Objects.equals(description, that.description); + } + + @Override + public int hashCode() { + return Objects.hash(version, author, description); + } +} diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java new file mode 100644 index 0000000..7c58c99 --- /dev/null +++ b/client/src/main/java/plugin/PluginRepository.java @@ -0,0 +1,93 @@ +package plugin; + +import rt4.GlobalJsonConfig; +import rt4.Npc; +import rt4.Player; + +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.HashMap; +import java.util.Objects; + +/** + * Responsible for loading and broadcasting methods to all plugins. + * @author ceikry + */ +public class PluginRepository { + static HashMap loadedPlugins = new HashMap<>(); + + public static void registerPlugin(PluginInfo info, Plugin plugin) { + loadedPlugins.put(info, plugin); + } + + public static void reloadPlugins() { + loadedPlugins.clear(); + Init(); + } + + public static void Init() { + File pluginsDirectory = new File(GlobalJsonConfig.instance.pluginsFolder); + + if (!pluginsDirectory.exists()) { + System.out.println("Skipping plugin initialization - " + pluginsDirectory.getAbsolutePath() + " does not exist."); + return; + } + + try { + URL[] classPath = {pluginsDirectory.toURI().toURL()}; + URLClassLoader loader = new URLClassLoader(classPath); + + for(File file : Objects.requireNonNull(pluginsDirectory.listFiles())) { + if(!file.isDirectory()) continue; + + File infoFile = new File(file.getAbsoluteFile() + File.separator + "plugin.properties"); + File pluginRoot = new File(file.getAbsoluteFile() + File.separator + "plugin.class"); + + PluginInfo info; + if (infoFile.exists()) + info = PluginInfo.loadFromFile(infoFile); + else + info = new PluginInfo("Unknown", "", 1.0); + + if (!pluginRoot.exists()) { + System.err.println("Unable to load plugin " + file.getName() + " because plugin.class is absent!"); + continue; + } + + Class clazz = loader.loadClass(file.getName() + ".plugin"); + + try { + Plugin thisPlugin = (Plugin) clazz.newInstance(); + thisPlugin._init(); + registerPlugin(info, thisPlugin); + } catch (Exception e) { + System.err.println("Error loading plugin " + file.getName() + ":"); + e.printStackTrace(); + return; + } + + System.out.println("Successfully loaded plugin " + file.getName() + ", version " + info.version); + } + } catch (Exception e) { + System.err.println("Unexpected exception during plugin initialization:"); + e.printStackTrace(); + } + } + + public static void Update() { + loadedPlugins.values().forEach(Plugin::Update); + } + + public static void Draw() { + loadedPlugins.values().forEach(Plugin::_draw); + } + + public static void NPCOverheadDraw(Npc npc, int screenX, int screenY) { + loadedPlugins.values().forEach((plugin) -> plugin.NPCOverheadDraw(npc, screenX, screenY)); + } + + public static void PlayerOverheadDraw(Player player, int screenX, int screenY) { + loadedPlugins.values().forEach((plugin) -> plugin.PlayerOverheadDraw(player, screenX, screenY)); + } +} diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java new file mode 100644 index 0000000..e9d9692 --- /dev/null +++ b/client/src/main/java/plugin/api/API.java @@ -0,0 +1,44 @@ +package plugin.api; + +import rt4.Font; +import rt4.Fonts; +import rt4.JagString; + +public class API { + public static void DrawText(FontType fontType, FontColor color, TextModifier mod, String text, int screenX, int screenY) { + JagString js = JagString.parse(text); + + Font font; + switch (fontType) { + case SMALL: + font = Fonts.p11Full; + break; + case LARGE: + font = Fonts.p12Full; + break; + default: + return; + } + + switch (mod) { + case CENTER: + font.renderCenter(js, screenX, screenY, color.colorCode, -1); + break; + case LEFT: + font.renderLeft(js, screenX, screenY, color.colorCode, -1); + break; + case RIGHT: + font.renderRight(js, screenX, screenY, color.colorCode, -1); + break; + case SHAKE: + font.renderShake(js, screenX, screenY, color.colorCode, -1, 100); + break; + case WAVE: + font.renderWave(js, screenX, screenY, color.colorCode, -1); + break; + case WAVE_2: + font.renderWave2(js, screenX, screenY, color.colorCode, -1); + break; + } + } +} diff --git a/client/src/main/java/plugin/api/FontColor.java b/client/src/main/java/plugin/api/FontColor.java new file mode 100644 index 0000000..8418192 --- /dev/null +++ b/client/src/main/java/plugin/api/FontColor.java @@ -0,0 +1,17 @@ +package plugin.api; + +import java.awt.*; + +public class FontColor { + public static FontColor YELLOW = new FontColor(16776960); + + public final int colorCode; + + FontColor(int colorCode) { + this.colorCode = colorCode; + } + + public static FontColor fromColor(Color color) { + return new FontColor(color.getRed() << 16 + color.getGreen() << 8 + color.getBlue()); + } +} diff --git a/client/src/main/java/plugin/api/FontType.java b/client/src/main/java/plugin/api/FontType.java new file mode 100644 index 0000000..f03ab16 --- /dev/null +++ b/client/src/main/java/plugin/api/FontType.java @@ -0,0 +1,6 @@ +package plugin.api; + +public enum FontType { + SMALL, + LARGE +} diff --git a/client/src/main/java/plugin/api/TextModifier.java b/client/src/main/java/plugin/api/TextModifier.java new file mode 100644 index 0000000..6fd88ed --- /dev/null +++ b/client/src/main/java/plugin/api/TextModifier.java @@ -0,0 +1,10 @@ +package plugin.api; + +public enum TextModifier { + CENTER, + LEFT, + RIGHT, + SHAKE, + WAVE, + WAVE_2 +} diff --git a/client/src/main/java/rt4/Cheat.java b/client/src/main/java/rt4/Cheat.java index 01217ad..5c44533 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -3,6 +3,7 @@ package rt4; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; public class Cheat { @OriginalMember(owner = "client!p", name = "f", descriptor = "Lclient!na;") @@ -97,6 +98,7 @@ public class Cheat { public static int rectDebug = 0; @OriginalMember(owner = "client!jg", name = "e", descriptor = "Z") public static boolean qaOpTest = false; + public static final JagString RELOADPLUGINS = JagString.parse("::reloadplugins"); @OriginalMember(owner = "client!en", name = "a", descriptor = "(IIIB)V") public static void teleport(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2) { @@ -228,6 +230,9 @@ public class Cheat { shiftClick = true; } } + if (arg0.equalsIgnoreCase(RELOADPLUGINS)) { + PluginRepository.reloadPlugins(); + } //} Protocol.outboundBuffer.p1isaac(44); Protocol.outboundBuffer.p1(arg0.length() - 1); diff --git a/client/src/main/java/rt4/Cs1ScriptRunner.java b/client/src/main/java/rt4/Cs1ScriptRunner.java index 43169a3..b20e51e 100644 --- a/client/src/main/java/rt4/Cs1ScriptRunner.java +++ b/client/src/main/java/rt4/Cs1ScriptRunner.java @@ -3,6 +3,7 @@ package rt4; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; import java.nio.charset.StandardCharsets; @@ -499,6 +500,7 @@ public class Cs1ScriptRunner { continue; } if (component.clientCode == 1405) { + PluginRepository.Draw(); if (!Cheat.displayFps) { continue; } diff --git a/client/src/main/java/rt4/GlobalJsonConfig.java b/client/src/main/java/rt4/GlobalJsonConfig.java index 2157f76..19b03ad 100644 --- a/client/src/main/java/rt4/GlobalJsonConfig.java +++ b/client/src/main/java/rt4/GlobalJsonConfig.java @@ -26,5 +26,5 @@ public class GlobalJsonConfig { int wl_port; int js5_port; boolean mouseWheelZoom = GlobalConfig.MOUSEWHEEL_ZOOM; - + public String pluginsFolder = "plugins"; } diff --git a/client/src/main/java/rt4/NpcType.java b/client/src/main/java/rt4/NpcType.java index 43e328c..da0ac1e 100644 --- a/client/src/main/java/rt4/NpcType.java +++ b/client/src/main/java/rt4/NpcType.java @@ -154,7 +154,7 @@ public final class NpcType { private int resizeY = 128; @OriginalMember(owner = "client!me", name = "s", descriptor = "I") - private int multiNpcVarbit = -1; + public int multiNpcVarbit = -1; @OriginalMember(owner = "client!me", name = "fb", descriptor = "I") public int crawlSound = -1; diff --git a/client/src/main/java/rt4/ScriptRunner.java b/client/src/main/java/rt4/ScriptRunner.java index 072db7d..7c1823a 100644 --- a/client/src/main/java/rt4/ScriptRunner.java +++ b/client/src/main/java/rt4/ScriptRunner.java @@ -3,6 +3,7 @@ package rt4; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; import java.nio.charset.StandardCharsets; import java.util.Calendar; @@ -316,14 +317,14 @@ public final class ScriptRunner { MaterialManager.method2731(0, 0, 0, 0, 0); client.audioLoop(); method3858(); - method2726(arg4, arg3, arg2, anInt5029, arg0, anInt5029); + drawOverheads(arg4, arg3, arg2, anInt5029, arg0, anInt5029); MiniMap.method4000(arg3, arg2, arg0, anInt5029, anInt5029, arg4); } else { SoftwareRaster.fillRect(arg2, arg4, arg3, arg0, 0); SceneGraph.method2954(Camera.renderX, Camera.anInt40, Camera.renderZ, Camera.cameraPitch, Camera.cameraYaw, aByteArrayArrayArray15, anIntArray205, anIntArray338, anIntArray518, anIntArray134, anIntArray476, Player.plane + 1, local387, PlayerList.self.xFine >> 7, PlayerList.self.zFine >> 7); client.audioLoop(); method3858(); - method2726(arg4, arg3, arg2, 256, arg0, 256); + drawOverheads(arg4, arg3, arg2, 256, arg0, 256); MiniMap.method4000(arg3, arg2, arg0, 256, 256, arg4); } ((Js5GlTextureProvider) Rasteriser.textureProvider).method3239(Protocol.sceneDelta); @@ -350,7 +351,7 @@ public final class ScriptRunner { } @OriginalMember(owner = "client!lc", name = "a", descriptor = "(IIIIIII)V") - public static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4, @OriginalArg(5) int arg5) { + public static void drawOverheads(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4, @OriginalArg(5) int arg5) { OverheadChat.size = 0; @Pc(5) int local5; @Pc(642) int local642; @@ -360,18 +361,25 @@ public final class ScriptRunner { @Pc(359) int local359; @Pc(639) int local639; for (local5 = -1; local5 < PlayerList.size + NpcList.size; local5++) { - @Pc(17) PathingEntity local17; + @Pc(17) PathingEntity entity; if (local5 == -1) { - local17 = PlayerList.self; + entity = PlayerList.self; } else if (PlayerList.size > local5) { - local17 = PlayerList.players[PlayerList.ids[local5]]; + entity = PlayerList.players[PlayerList.ids[local5]]; } else { - local17 = NpcList.npcs[NpcList.ids[local5 - PlayerList.size]]; + entity = NpcList.npcs[NpcList.ids[local5 - PlayerList.size]]; } - if (local17 != null && local17.isVisible()) { + if (entity != null && entity.isVisible()) { + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, entity.method2691() + 15, arg1 >> 1); + if (local5 >= PlayerList.size) { + PluginRepository.NPCOverheadDraw((Npc) entity,arg2 + anInt1951, arg0 + anInt548); + } else { + PluginRepository.PlayerOverheadDraw((Player) entity,arg2 + anInt1951, arg0 + anInt548); + } + @Pc(58) NpcType local58; - if (local17 instanceof Npc) { - local58 = ((Npc) local17).type; + if (entity instanceof Npc) { + local58 = ((Npc) entity).type; if (local58.multiNpcs != null) { local58 = local58.getMultiNpc(); } @@ -381,17 +389,17 @@ public final class ScriptRunner { } @Pc(161) int local161; if (local5 >= PlayerList.size) { - local58 = ((Npc) local17).type; + local58 = ((Npc) entity).type; if (local58.multiNpcs != null) { local58 = local58.getMultiNpc(); } if (local58.headicon >= 0 && Sprites.headiconPrayers.length > local58.headicon) { if (local58.iconHeight == -1) { - local265 = local17.method2691() + 15; + local265 = entity.method2691() + 15; } else { local265 = local58.iconHeight + 15; } - method3326(arg4 >> 1, arg3, local17, arg5, local265, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, local265, arg1 >> 1); if (anInt1951 > -1) { Sprites.headiconPrayers[local58.headicon].render(arg2 + anInt1951 - 12, arg0 + -30 - -anInt548); } @@ -401,11 +409,11 @@ public final class ScriptRunner { @Pc(322) MapMarker local322 = local308[local310]; if (local322 != null && local322.type == 1 && local322.actorTargetId == NpcList.ids[local5 - PlayerList.size] && client.loop % 20 < 10) { if (local58.iconHeight == -1) { - local359 = local17.method2691() + 15; + local359 = entity.method2691() + 15; } else { local359 = local58.iconHeight + 15; } - method3326(arg4 >> 1, arg3, local17, arg5, local359, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, local359, arg1 >> 1); if (anInt1951 > -1) { Sprites.headhints[local322.anInt4048].render(arg2 + anInt1951 - 12, anInt548 + -28 + arg0); } @@ -413,9 +421,9 @@ public final class ScriptRunner { } } else { local74 = 30; - @Pc(77) Player local77 = (Player) local17; + @Pc(77) Player local77 = (Player) entity; if (local77.anInt1669 != -1 || local77.anInt1649 != -1) { - method3326(arg4 >> 1, arg3, local17, arg5, local17.method2691() + 15, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, entity.method2691() + 15, arg1 >> 1); if (anInt1951 > -1) { if (local77.anInt1669 != -1) { Sprites.headiconPks[local77.anInt1669].render(anInt1951 + arg2 - 12, arg0 + -30 + anInt548); @@ -432,7 +440,7 @@ public final class ScriptRunner { for (local161 = 0; local161 < local159.length; local161++) { @Pc(173) MapMarker local173 = local159[local161]; if (local173 != null && local173.type == 10 && PlayerList.ids[local5] == local173.actorTargetId) { - method3326(arg4 >> 1, arg3, local17, arg5, local17.method2691() + 15, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, entity.method2691() + 15, arg1 >> 1); if (anInt1951 > -1) { Sprites.headhints[local173.anInt4048].render(arg2 + anInt1951 - 12, arg0 + (anInt548 - local74)); } @@ -440,25 +448,25 @@ public final class ScriptRunner { } } } - if (local17.chatMessage != null && (local5 >= PlayerList.size || Chat.publicFilter == 0 || Chat.publicFilter == 3 || Chat.publicFilter == 1 && FriendsList.contains(((Player) local17).username))) { - method3326(arg4 >> 1, arg3, local17, arg5, local17.method2691(), arg1 >> 1); + if (entity.chatMessage != null && (local5 >= PlayerList.size || Chat.publicFilter == 0 || Chat.publicFilter == 3 || Chat.publicFilter == 1 && FriendsList.contains(((Player) entity).username))) { + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, entity.method2691(), arg1 >> 1); if (anInt1951 > -1 && OverheadChat.size < OverheadChat.CAPACITY) { - OverheadChat.anIntArray389[OverheadChat.size] = Fonts.b12Full.getStringWidth(local17.chatMessage) / 2; + OverheadChat.anIntArray389[OverheadChat.size] = Fonts.b12Full.getStringWidth(entity.chatMessage) / 2; OverheadChat.anIntArray387[OverheadChat.size] = Fonts.b12Full.lineHeight; OverheadChat.anIntArray385[OverheadChat.size] = anInt1951; OverheadChat.anIntArray392[OverheadChat.size] = anInt548; - OverheadChat.colors[OverheadChat.size] = local17.chatColor; - OverheadChat.effects[OverheadChat.size] = local17.chatEffect; - OverheadChat.loops[OverheadChat.size] = local17.chatLoops; - OverheadChat.messages[OverheadChat.size] = local17.chatMessage; + OverheadChat.colors[OverheadChat.size] = entity.chatColor; + OverheadChat.effects[OverheadChat.size] = entity.chatEffect; + OverheadChat.loops[OverheadChat.size] = entity.chatLoops; + OverheadChat.messages[OverheadChat.size] = entity.chatMessage; OverheadChat.size++; } } - if (local17.hitpointsBarVisibleUntil > client.loop) { + if (entity.hitpointsBarVisibleUntil > client.loop) { @Pc(508) Sprite local508 = Sprites.hitbars[0]; @Pc(512) Sprite local512 = Sprites.hitbars[1]; - if (local17 instanceof Npc) { - @Pc(518) Npc local518 = (Npc) local17; + if (entity instanceof Npc) { + @Pc(518) Npc local518 = (Npc) entity; @Pc(528) Sprite[] local528 = (Sprite[]) HitBarList.hitBars.get(local518.type.hitBarId); if (local528 == null) { local528 = SpriteLoader.loadAlphaSprites(local518.type.hitBarId, client.js5Archive8); @@ -472,19 +480,19 @@ public final class ScriptRunner { } @Pc(571) NpcType local571 = local518.type; if (local571.iconHeight == -1) { - local310 = local17.method2691(); + local310 = entity.method2691(); } else { local310 = local571.iconHeight; } } else { - local310 = local17.method2691(); + local310 = entity.method2691(); } - method3326(arg4 >> 1, arg3, local17, arg5, local508.height + local310 + 10, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, local508.height + local310 + 10, arg1 >> 1); if (anInt1951 > -1) { local161 = anInt1951 + arg2 - (local508.width >> 1); local359 = anInt548 + arg0 - 3; local508.render(local161, local359); - local639 = local508.width * local17.hitpointsBar / 255; + local639 = local508.width * entity.hitpointsBar / 255; local642 = local508.height; if (GlRenderer.enabled) { GlRaster.method1183(local161, local359, local161 + local639, local359 + local642); @@ -500,19 +508,19 @@ public final class ScriptRunner { } } for (local74 = 0; local74 < 4; local74++) { - if (local17.hitVisibleUntil[local74] > client.loop) { - if (local17 instanceof Npc) { - @Pc(725) Npc local725 = (Npc) local17; + if (entity.hitVisibleUntil[local74] > client.loop) { + if (entity instanceof Npc) { + @Pc(725) Npc local725 = (Npc) entity; @Pc(728) NpcType local728 = local725.type; if (local728.iconHeight == -1) { - local265 = local17.method2691() / 2; + local265 = entity.method2691() / 2; } else { local265 = local728.iconHeight / 2; } } else { - local265 = local17.method2691() / 2; + local265 = entity.method2691() / 2; } - method3326(arg4 >> 1, arg3, local17, arg5, local265, arg1 >> 1); + setOverheadScreenCoordinateOffsets(arg4 >> 1, arg3, entity, arg5, local265, arg1 >> 1); if (anInt1951 > -1) { if (local74 == 1) { anInt548 -= 20; @@ -525,8 +533,8 @@ public final class ScriptRunner { anInt548 -= 10; anInt1951 += 15; } - Sprites.hitmarks[local17.hitTypes[local74]].render(arg2 + anInt1951 - 12, arg0 + anInt548 - 12); - Fonts.p11Full.renderCenter(JagString.parseInt(local17.hitDamages[local74]), anInt1951 + arg2 - 1, anInt548 + 3 + arg0, 16777215, 0); + Sprites.hitmarks[entity.hitTypes[local74]].render(arg2 + anInt1951 - 12, arg0 + anInt548 - 12); + Fonts.p11Full.renderCenter(JagString.parseInt(entity.hitDamages[local74]), anInt1951 + arg2 - 1, anInt548 + 3 + arg0, 16777215, 0); } } } @@ -1224,7 +1232,7 @@ public final class ScriptRunner { } @OriginalMember(owner = "client!og", name = "a", descriptor = "(BIILclient!fe;III)V") - public static void method3326(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) PathingEntity arg2, @OriginalArg(4) int arg3, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5) { + public static void setOverheadScreenCoordinateOffsets(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) PathingEntity arg2, @OriginalArg(4) int arg3, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5) { method1026(arg5, arg1, arg2.zFine, arg4, arg0, arg2.xFine, arg3); } diff --git a/client/src/main/java/rt4/WorldMap.java b/client/src/main/java/rt4/WorldMap.java index b21b025..9698d9e 100644 --- a/client/src/main/java/rt4/WorldMap.java +++ b/client/src/main/java/rt4/WorldMap.java @@ -3,6 +3,7 @@ package rt4; import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; public class WorldMap { @OriginalMember(owner = "client!nc", name = "e", descriptor = "Lclient!na;") diff --git a/client/src/main/java/rt4/client.java b/client/src/main/java/rt4/client.java index baea486..dd87073 100644 --- a/client/src/main/java/rt4/client.java +++ b/client/src/main/java/rt4/client.java @@ -4,6 +4,7 @@ import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalClass; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; import java.awt.*; import java.io.IOException; @@ -217,6 +218,7 @@ public final class client extends GameShell { public static void main(@OriginalArg(0) String[] arg0) { try { GlobalJsonConfig.load(GlobalConfig.EXTENDED_CONFIG_PATH); + PluginRepository.Init(); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/plugin-playground/build.gradle b/plugin-playground/build.gradle new file mode 100644 index 0000000..63b66f7 --- /dev/null +++ b/plugin-playground/build.gradle @@ -0,0 +1,27 @@ +plugins { + id 'java' +} + +version 'unspecified' + +targetCompatibility = 1.8 +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1' + implementation(rootProject.project("client")) +} + +test { + useJUnitPlatform() +} + +task buildPlugins { + dependsOn(classes) + +} \ 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 new file mode 100644 index 0000000..35c0d03 --- /dev/null +++ b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java @@ -0,0 +1,47 @@ +package OverheadDebugPlugin; + +import plugin.Plugin; +import plugin.api.API; +import plugin.api.FontColor; +import plugin.api.FontType; +import plugin.api.TextModifier; +import rt4.*; + +public class plugin extends Plugin { + @Override + public void PlayerOverheadDraw(Player player, int screenX, int screenY) { + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.CENTER, + player.username.toString(), + screenX, + screenY + ); + } + + @Override + public void NPCOverheadDraw(Npc npc, int screenX, int screenY) { + String npcSb = + (npc.type.name.strEquals(JagString.parse("null")) + ? npc.type.getMultiNpc() != null + ? "Wrapper [" + npc.type.getMultiNpc().name + " " + npc.type.getMultiNpc().id + "]" + : "Wrapper" + : npc.type.name) + + " [Lvl: " + + npc.type.combatLevel + + "] [ID: " + + npc.type.id + + "] [Vb: " + + npc.type.multiNpcVarbit + "]"; + + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.CENTER, + npcSb, + screenX, + screenY + ); + } +} diff --git a/settings.gradle b/settings.gradle index 8cf112c..2dd4593 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,3 +17,5 @@ include( ) startParameter.excludedTaskNames << ':playground:run' +include 'plugin-playground' +