From a6577064b04ca658aacd5f086e9a574f10e7f7a0 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 08:13:32 -0500 Subject: [PATCH 01/16] 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 1c98155b..7f0f5fdf 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 00000000..2026f5e2 --- /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 00000000..11d64f8f --- /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 00000000..7c58c99d --- /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 00000000..e9d9692b --- /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 00000000..8418192e --- /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 00000000..f03ab169 --- /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 00000000..6fd88eda --- /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 01217ada..5c445338 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -3,6 +3,7 @@ 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 static void execute(@OriginalArg(0) JagString arg0) { 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 43169a34..b20e51eb 100644 --- a/client/src/main/java/rt4/Cs1ScriptRunner.java +++ b/client/src/main/java/rt4/Cs1ScriptRunner.java @@ -3,6 +3,7 @@ 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 static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 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 2157f764..19b03ada 100644 --- a/client/src/main/java/rt4/GlobalJsonConfig.java +++ b/client/src/main/java/rt4/GlobalJsonConfig.java @@ -26,5 +26,5 @@ public static void load(String path) { 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 43e328c5..da0ac1ec 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 072db7dc..7c1823a0 100644 --- a/client/src/main/java/rt4/ScriptRunner.java +++ b/client/src/main/java/rt4/ScriptRunner.java @@ -3,6 +3,7 @@ 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 static void method4326(@OriginalArg(1) int arg0, @OriginalArg(2) boolean 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 static void method4326(@OriginalArg(1) int arg0, @OriginalArg(2) boolean } @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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 @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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } @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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 @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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } } 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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } } } - 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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } @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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } } 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 static void method2726(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 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 static void openUrl(@OriginalArg(0) JagString arg0, @OriginalArg(2) boole } @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 b21b0259..9698d9e5 100644 --- a/client/src/main/java/rt4/WorldMap.java +++ b/client/src/main/java/rt4/WorldMap.java @@ -3,6 +3,7 @@ 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 baea4863..dd870730 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.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 00000000..63b66f7f --- /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 00000000..35c0d037 --- /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 8cf112ca..2dd45939 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,3 +17,5 @@ include( ) startParameter.excludedTaskNames << ':playground:run' +include 'plugin-playground' + From 8dfbcb94238cd254604acf22ed04d26f5c8f746e Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 09:58:08 -0500 Subject: [PATCH 02/16] More plugin system work --- client/src/main/java/plugin/Plugin.java | 3 ++ .../main/java/plugin/PluginRepository.java | 8 ++++ client/src/main/java/plugin/api/API.java | 12 ++++-- .../src/main/java/plugin/api/Privileges.java | 7 +++ client/src/main/java/rt4/Cheat.java | 1 + plugin-playground/build.gradle | 43 ++++++++++++++++++- .../main/java/OverheadDebugPlugin/plugin.java | 23 ++++++++-- .../OverheadDebugPlugin/plugin.properties | 3 ++ 8 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 client/src/main/java/plugin/api/Privileges.java create mode 100644 plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index 2026f5e2..8928945b 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -6,6 +6,7 @@ /** * 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 void PlayerOverheadDraw(Player player, int screenX, int screenY) {} * @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 7c58c99d..096e6927 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 static void NPCOverheadDraw(Npc npc, int screenX, int screenY) { 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 e9d9692b..504d6e49 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 static void DrawText(FontType fontType, FontColor color, TextModifier mod 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 00000000..75216b67 --- /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 5c445338..9f046f24 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -109,6 +109,7 @@ public static void teleport(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @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 63b66f7f..30000542 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 35c0d037..610c31a3 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 void PlayerOverheadDraw(Player player, int screenX, int screenY) { @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 void NPCOverheadDraw(Npc npc, int screenX, int screenY) { 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 00000000..99727349 --- /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 From d69ac42050a172b0c24e13b8cde05fc88ab553e0 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 14:27:06 -0500 Subject: [PATCH 03/16] Interface debugging --- client/src/main/java/plugin/Plugin.java | 5 + .../main/java/plugin/PluginRepository.java | 9 +- client/src/main/java/plugin/api/API.java | 4 + .../src/main/java/plugin/api/FontColor.java | 2 +- .../src/main/java/rt4/ComponentPointer.java | 2 +- client/src/main/java/rt4/Cs1ScriptRunner.java | 31 +++++-- client/src/main/java/rt4/GlSprite.java | 2 +- client/src/main/java/rt4/InterfaceList.java | 14 +-- client/src/main/java/rt4/Protocol.java | 6 +- client/src/main/java/rt4/ScriptRunner.java | 2 +- .../main/java/rt4/SoftwareAlphaSprite.java | 2 +- client/src/main/java/rt4/SoftwareSprite.java | 2 +- client/src/main/java/rt4/Sprite.java | 4 +- .../java/InterfaceDebugPlugin/plugin.java | 91 +++++++++++++++++++ .../InterfaceDebugPlugin/plugin.properties | 4 + 15 files changed, 149 insertions(+), 31 deletions(-) create mode 100644 plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java create mode 100644 plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index 8928945b..5cbb948e 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -1,7 +1,9 @@ package plugin; +import rt4.Component; import rt4.Npc; import rt4.Player; +import rt4.Tile; /** * The base plugin class which is meant to be extended by plugins. @@ -58,4 +60,7 @@ public void PlayerOverheadDraw(Player player, int screenX, int screenY) {} public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {} public void ProcessCommand(String commandStr, String[] args) {} + + public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {} + } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 096e6927..b21e2a3f 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -1,9 +1,6 @@ package plugin; -import rt4.GlobalJsonConfig; -import rt4.JagString; -import rt4.Npc; -import rt4.Player; +import rt4.*; import java.io.File; import java.net.URL; @@ -98,4 +95,8 @@ public static void ProcessCommand(JagString commandStr) { String[] args = Arrays.copyOfRange(tokens, 1, tokens.length); loadedPlugins.values().forEach((plugin) -> plugin.ProcessCommand(tokens[0], args)); } + + public static void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { + loadedPlugins.values().forEach((plugin) -> plugin.ComponentDraw(componentIndex, component, screenX, screenY)); + } } diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index 504d6e49..157ddb1a 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -47,4 +47,8 @@ public static void DrawText(FontType fontType, FontColor color, TextModifier mod public static boolean PlayerHasPrivilege(Privileges privilege) { return LoginManager.staffModLevel >= privilege.ordinal(); } + + public static boolean IsHD() { + return GlRenderer.enabled; + } } diff --git a/client/src/main/java/plugin/api/FontColor.java b/client/src/main/java/plugin/api/FontColor.java index 8418192e..8b6a7728 100644 --- a/client/src/main/java/plugin/api/FontColor.java +++ b/client/src/main/java/plugin/api/FontColor.java @@ -7,7 +7,7 @@ public class FontColor { public final int colorCode; - FontColor(int colorCode) { + public FontColor(int colorCode) { this.colorCode = colorCode; } diff --git a/client/src/main/java/rt4/ComponentPointer.java b/client/src/main/java/rt4/ComponentPointer.java index 2c456a69..ca89cca3 100644 --- a/client/src/main/java/rt4/ComponentPointer.java +++ b/client/src/main/java/rt4/ComponentPointer.java @@ -7,7 +7,7 @@ public final class ComponentPointer extends Node { @OriginalMember(owner = "client!wk", name = "r", descriptor = "I") - public int anInt5878; + public int interfaceId; @OriginalMember(owner = "client!wk", name = "s", descriptor = "I") public int anInt5879; diff --git a/client/src/main/java/rt4/Cs1ScriptRunner.java b/client/src/main/java/rt4/Cs1ScriptRunner.java index b20e51eb..86398387 100644 --- a/client/src/main/java/rt4/Cs1ScriptRunner.java +++ b/client/src/main/java/rt4/Cs1ScriptRunner.java @@ -304,7 +304,7 @@ public static boolean isTrue(@OriginalArg(0) Component component) { } @OriginalMember(owner = "client!gn", name = "a", descriptor = "(III[Lclient!be;IIIIBI)V") - public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) Component[] components, @OriginalArg(4) int arg4, @OriginalArg(5) int layer, @OriginalArg(6) int arg6, @OriginalArg(7) int arg7, @OriginalArg(9) int parentRectangle) { + public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) Component[] components, @OriginalArg(4) int arg4, @OriginalArg(5) int layer, @OriginalArg(6) int arg6, @OriginalArg(7) int arg7, @OriginalArg(9) int parentRectangle) { if (GlRenderer.enabled) { GlRaster.setClip(arg0, arg6, arg4, arg7); } else { @@ -573,9 +573,9 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 component.scrollY = 0; } } - method1809(local166, local114 - component.scrollY, -component.scrollX + local123, components, local302, component.id, local164, local291, rectangle); + renderComponent(local166, local114 - component.scrollY, -component.scrollX + local123, components, local302, component.id, local164, local291, rectangle); if (component.createdComponents != null) { - method1809(local166, local114 - component.scrollY, -component.scrollX + local123, component.createdComponents, local302, component.id, local164, local291, rectangle); + renderComponent(local166, local114 - component.scrollY, -component.scrollX + local123, component.createdComponents, local302, component.id, local164, local291, rectangle); } @Pc(1186) ComponentPointer local1186 = (ComponentPointer) InterfaceList.openInterfaces.get(component.id); if (local1186 != null) { @@ -586,7 +586,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 MiniMenu.actions[0] = 1005; MiniMenu.opBases[0] = JagString.EMPTY; } - method86(local1186.anInt5878, local166, local302, local123, rectangle, local291, local164, local114); + method86(local1186.interfaceId, local166, local302, local123, rectangle, local291, local164, local114); } if (GlRenderer.enabled) { GlRaster.setClip(arg0, arg6, arg4, arg7); @@ -712,6 +712,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local270++; } } + PluginRepository.ComponentDraw(i, component, local123, local114); } else if (component.type == 3) { if (isTrue(component)) { local270 = component.activeColor; @@ -747,6 +748,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } else { SoftwareRaster.method2487(local123, local114, component.width, component.height, local270, 256 - (alpha & 0xFF)); } + PluginRepository.ComponentDraw(i, component, local123, local114); } else { @Pc(1921) Font local1921; if (component.type == 4) { @@ -785,6 +787,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local1934 = interpolate(component, local1934); } local1921.drawInterfaceText(local1934, local123, local114, component.width, component.height, local276, component.shadowed ? 0 : -1, component.halign, component.valign, component.vpadding); + PluginRepository.ComponentDraw(i, component, local123, local114); } else if (Component.aBoolean72) { InterfaceList.redraw(component); } @@ -817,6 +820,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } else { local2282.method1426(local123, local114, 256 - (alpha & 0xFF), memory, color); } + PluginRepository.ComponentDraw(i, component, local123, local114); } else if (local2274) { for (local563 = 0; local563 < color; local563++) { if (alpha == 0) { @@ -825,6 +829,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local2282.method1426(local123, local114 + local563 * local468, -(alpha & 0xFF) + 256, memory, 1); } } + PluginRepository.ComponentDraw(i, component, local123, local114); } else if (local2279) { for (local563 = 0; local563 < memory; local563++) { if (alpha == 0) { @@ -833,6 +838,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local2282.method1426(local276 * local563 + local123, local114, 256 - (alpha & 0xFF), 1, color); } } + PluginRepository.ComponentDraw(i, component, local123, local114); } else { for (local563 = 0; local563 < memory; local563++) { for (local571 = 0; local571 < color; local571++) { @@ -843,6 +849,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } } } + PluginRepository.ComponentDraw(i, component, local123 + local276, local468 + local114); } GlRaster.setClip(arg0, arg6, arg4, arg7); @@ -851,7 +858,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 for (cardMemory = 0; cardMemory < memory; cardMemory++) { for (local556 = 0; local556 < color; local556++) { if (component.angle2d != 0) { - sprite.method1420(local114 + local468 * local556 + local468 / 2, component.angle2d, 4096, cardMemory * local276 + local123 + local276 / 2); + sprite.renderAngled(local114 + local468 * local556 + local468 / 2, component.angle2d, 4096, cardMemory * local276 + local123 + local276 / 2); } else if (alpha == 0) { sprite.render(cardMemory * local276 + local123, local468 * local556 + local114); } else { @@ -859,21 +866,23 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } } } + PluginRepository.ComponentDraw(i, component, local123 + local276, local114 + local468); SoftwareRaster.setClip(arg0, arg6, arg4, arg7); } } else { memory = component.width * 4096 / local276; if (component.angle2d != 0) { - sprite.method1420(local114 + component.height / 2, component.angle2d, memory, local123 + component.width / 2); + sprite.renderAngled(local114 + component.height / 2, component.angle2d, memory, local123 + component.width / 2); } else if (alpha != 0) { - sprite.method1422(local123, local114, component.width, component.height, 256 - (alpha & 0xFF)); + sprite.renderAlpha(local123, local114, component.width, component.height, 256 - (alpha & 0xFF)); } else if (local276 == component.width && local468 == component.height) { sprite.render(local123, local114); } else { // render icons in a container i.e bank icons sprite.renderResized(local123, local114, component.width, component.height); } + PluginRepository.ComponentDraw(i, component, local123, local114); } } else if (Component.aBoolean72) { InterfaceList.redraw(component); @@ -992,6 +1001,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 Rasteriser.prepareOffsets(); } } + PluginRepository.ComponentDraw(i, component, local123 + component.width / 2, local114 + component.height / 2); } else { if (component.type == 7) { local1921 = component.method491(Sprites.nameIcons); @@ -1025,6 +1035,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local276++; } } + PluginRepository.ComponentDraw(i, component, local123 + component.invMarginX + 115, local114 + component.invMarginY + 12); } if (component.type == 8 && Protocol.aClass13_11 == component && Protocol.anInt5235 == anInt4504) { local276 = 0; @@ -1083,6 +1094,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 local3299.renderLeft(local3325, cardMemory + 3, objId, 0, -1); objId += local3299.lineHeight + 1; } + PluginRepository.ComponentDraw(i, component, cardMemory + 3, objId); } if (component.type == 9) { if (component.aBoolean20) { @@ -1105,6 +1117,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 } else { SoftwareRaster.method2494(local123, local276, local468, memory, component.color, component.lineWidth); } + PluginRepository.ComponentDraw(i, component, local468, local276); } } } @@ -1120,7 +1133,7 @@ public static void method1809(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1 @OriginalMember(owner = "client!ag", name = "a", descriptor = "(IIIIIIIII)V") public static void method86(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) int arg2, @OriginalArg(4) int arg3, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5, @OriginalArg(7) int arg6, @OriginalArg(8) int arg7) { if (InterfaceList.load(arg0)) { - method1809(arg1, arg7, arg3, InterfaceList.components[arg0], arg2, -1, arg6, arg5, arg4); + renderComponent(arg1, arg7, arg3, InterfaceList.components[arg0], arg2, -1, arg6, arg5, arg4); } else if (arg4 == -1) { for (@Pc(27) int local27 = 0; local27 < 100; local27++) { InterfaceList.aBooleanArray100[local27] = true; @@ -1135,7 +1148,7 @@ public static void method182() { aClass13Array13 = null; method86(InterfaceList.topLevelInterface, 0, GameShell.canvasWidth, 0, -1, GameShell.canvasHeight, 0, 0); if (aClass13Array13 != null) { - method1809(0, anInt3126, anInt4696, aClass13Array13, GameShell.canvasWidth, -1412584499, 0, GameShell.canvasHeight, aClass13_1.rectangle); + renderComponent(0, anInt3126, anInt4696, aClass13Array13, GameShell.canvasWidth, -1412584499, 0, GameShell.canvasHeight, aClass13_1.rectangle); aClass13Array13 = null; } } diff --git a/client/src/main/java/rt4/GlSprite.java b/client/src/main/java/rt4/GlSprite.java index aa587400..5fa4f73b 100644 --- a/client/src/main/java/rt4/GlSprite.java +++ b/client/src/main/java/rt4/GlSprite.java @@ -363,7 +363,7 @@ protected final void method1416(@OriginalArg(0) int arg0, @OriginalArg(1) int ar @OriginalMember(owner = "client!cf", name = "b", descriptor = "(IIIII)V") @Override - public final void method1422(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { + public final void renderAlpha(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { if (arg2 <= 0 || arg3 <= 0) { return; } diff --git a/client/src/main/java/rt4/InterfaceList.java b/client/src/main/java/rt4/InterfaceList.java index 0fc9f2a1..f04009af 100644 --- a/client/src/main/java/rt4/InterfaceList.java +++ b/client/src/main/java/rt4/InterfaceList.java @@ -198,7 +198,7 @@ public static void method1287() { @OriginalMember(owner = "client!i", name = "i", descriptor = "(Z)V") public static void redrawActiveInterfaces() { for (@Pc(6) ComponentPointer local6 = (ComponentPointer) openInterfaces.head(); local6 != null; local6 = (ComponentPointer) openInterfaces.next()) { - @Pc(14) int local14 = local6.anInt5878; + @Pc(14) int local14 = local6.interfaceId; if (load(local14)) { @Pc(21) boolean local21 = true; @Pc(25) Component[] local25 = components[local14]; @@ -318,7 +318,7 @@ public static void method531(@OriginalArg(0) Component arg0, @OriginalArg(1) boo } @Pc(66) ComponentPointer local66 = (ComponentPointer) openInterfaces.get(arg0.id); if (local66 != null) { - method4017(local32, arg1, local66.anInt5878, local20); + method4017(local32, arg1, local66.interfaceId, local20); } } @@ -368,7 +368,7 @@ public static void method1626(@OriginalArg(0) int arg0) { @OriginalMember(owner = "client!ke", name = "a", descriptor = "(ZLclient!wk;Z)V") public static void closeInterface(@OriginalArg(0) boolean arg0, @OriginalArg(1) ComponentPointer arg1) { @Pc(9) int local9 = (int) arg1.key; - @Pc(16) int local16 = arg1.anInt5878; + @Pc(16) int local16 = arg1.interfaceId; arg1.unlink(); if (arg0) { method2275(local16); @@ -532,7 +532,7 @@ public static Component method4668(@OriginalArg(0) Component arg0) { @Pc(28) int local28 = arg0.id >>> 16; @Pc(33) HashTableIterator local33 = new HashTableIterator(openInterfaces); for (@Pc(38) ComponentPointer local38 = (ComponentPointer) local33.method2701(); local38 != null; local38 = (ComponentPointer) local33.method2700()) { - if (local28 == local38.anInt5878) { + if (local28 == local38.interfaceId) { return getComponent((int) local38.key); } } @@ -575,7 +575,7 @@ public static void method7(@OriginalArg(0) Component[] arg0, @OriginalArg(2) int } @Pc(49) ComponentPointer local49 = (ComponentPointer) openInterfaces.get(local23.id); if (local49 != null) { - runScripts(arg1, local49.anInt5878); + runScripts(arg1, local49.interfaceId); } } @Pc(72) HookRequest local72; @@ -1045,7 +1045,7 @@ public static void method946(@OriginalArg(0) Component[] arg0, @OriginalArg(1) i } @Pc(1595) ComponentPointer local1595 = (ComponentPointer) openInterfaces.get(component.id); if (local1595 != null) { - method1320(local50, local63, local55, local65, local1595.anInt5878, local61, local67); + method1320(local50, local63, local55, local65, local1595.interfaceId, local61, local67); } } } @@ -1232,7 +1232,7 @@ public static void method2354(@OriginalArg(1) int arg0, @OriginalArg(2) Componen } @Pc(73) ComponentPointer local73 = (ComponentPointer) openInterfaces.get(local15.id); if (local73 != null) { - method1949(local73.anInt5878); + method1949(local73.interfaceId); } } if (local15.type == 6) { diff --git a/client/src/main/java/rt4/Protocol.java b/client/src/main/java/rt4/Protocol.java index e825cea6..0c3aef4c 100644 --- a/client/src/main/java/rt4/Protocol.java +++ b/client/src/main/java/rt4/Protocol.java @@ -1712,7 +1712,7 @@ public static boolean readPacketInternal() throws IOException { @Pc(3449) ComponentPointer src = (ComponentPointer) InterfaceList.openInterfaces.get(source); ComponentPointer tgt = (ComponentPointer) InterfaceList.openInterfaces.get(target); if (tgt != null) { - InterfaceList.closeInterface(src == null || tgt.anInt5878 != src.anInt5878, tgt); + InterfaceList.closeInterface(src == null || tgt.interfaceId != src.interfaceId, tgt); } if (src != null) { src.unlink(); @@ -1852,7 +1852,7 @@ public static boolean readPacketInternal() throws IOException { setVerifyId(tracknum); ComponentPointer ptr = (ComponentPointer) InterfaceList.openInterfaces.get(pointer); if (ptr != null) { - InterfaceList.closeInterface(ptr.anInt5878 != component, ptr); + InterfaceList.closeInterface(ptr.interfaceId != component, ptr); } method1148(component, pointer, type); opcode = -1; @@ -3472,7 +3472,7 @@ public static void spawnGroundObject(@OriginalArg(0) int arg0, @OriginalArg(2) i public static ComponentPointer method1148(@OriginalArg(1) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) int arg2) { @Pc(9) ComponentPointer local9 = new ComponentPointer(); local9.anInt5879 = arg2; - local9.anInt5878 = arg0; + local9.interfaceId = arg0; InterfaceList.openInterfaces.put(local9, arg1); InterfaceList.method1753(arg0); @Pc(28) Component local28 = InterfaceList.getComponent(arg1); diff --git a/client/src/main/java/rt4/ScriptRunner.java b/client/src/main/java/rt4/ScriptRunner.java index 7c1823a0..b03ce2bc 100644 --- a/client/src/main/java/rt4/ScriptRunner.java +++ b/client/src/main/java/rt4/ScriptRunner.java @@ -2989,7 +2989,7 @@ public static void run(@OriginalArg(1) int maxCycles, @OriginalArg(2) HookReques int1 = intStack[isp]; int3 = intStack[isp + 1]; @Pc(12663) ComponentPointer local12663 = (ComponentPointer) InterfaceList.openInterfaces.get(int1); - if (local12663 != null && local12663.anInt5878 == int3) { + if (local12663 != null && local12663.interfaceId == int3) { intStack[isp++] = 1; continue; } diff --git a/client/src/main/java/rt4/SoftwareAlphaSprite.java b/client/src/main/java/rt4/SoftwareAlphaSprite.java index 0a31dabc..9663a24a 100644 --- a/client/src/main/java/rt4/SoftwareAlphaSprite.java +++ b/client/src/main/java/rt4/SoftwareAlphaSprite.java @@ -740,7 +740,7 @@ public final void renderRotated(@OriginalArg(0) int x, @OriginalArg(1) int y, @O @OriginalMember(owner = "client!am", name = "b", descriptor = "(IIIII)V") @Override - public final void method1422(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { + public final void renderAlpha(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { if (arg2 <= 0 || arg3 <= 0) { return; } diff --git a/client/src/main/java/rt4/SoftwareSprite.java b/client/src/main/java/rt4/SoftwareSprite.java index 034a0b12..7176d476 100644 --- a/client/src/main/java/rt4/SoftwareSprite.java +++ b/client/src/main/java/rt4/SoftwareSprite.java @@ -1213,7 +1213,7 @@ public final void drawShadow(@OriginalArg(0) int rgb) { @OriginalMember(owner = "client!mm", name = "b", descriptor = "(IIIII)V") @Override - public void method1422(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { + public void renderAlpha(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4) { if (arg2 <= 0 || arg3 <= 0) { return; } diff --git a/client/src/main/java/rt4/Sprite.java b/client/src/main/java/rt4/Sprite.java index 29b789c2..a1ea8246 100644 --- a/client/src/main/java/rt4/Sprite.java +++ b/client/src/main/java/rt4/Sprite.java @@ -43,7 +43,7 @@ protected Sprite() { public abstract void renderResized(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3); @OriginalMember(owner = "client!qf", name = "a", descriptor = "(IIIII)V") - public final void method1420(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3) { + public final void renderAngled(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3) { @Pc(8) int local8 = this.anInt1860 << 3; @Pc(17) int local17 = this.anInt1866 << 3; @Pc(25) int local25 = (arg3 << 4) + (local8 & 0xF); @@ -55,7 +55,7 @@ public final void method1420(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, public abstract void renderHorizontalFlip(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1); @OriginalMember(owner = "client!qf", name = "b", descriptor = "(IIIII)V") - public abstract void method1422(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4); + public abstract void renderAlpha(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1, @OriginalArg(2) int arg2, @OriginalArg(3) int arg3, @OriginalArg(4) int arg4); @OriginalMember(owner = "client!qf", name = "e", descriptor = "(II)V") public abstract void render(@OriginalArg(0) int arg0, @OriginalArg(1) int arg1); diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java new file mode 100644 index 00000000..fd78ea9f --- /dev/null +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java @@ -0,0 +1,91 @@ +package InterfaceDebugPlugin; + +import plugin.Plugin; +import plugin.api.*; +import rt4.Component; +import rt4.GameShell; + +import java.util.ArrayList; +import java.util.Arrays; + +public class plugin extends Plugin { + private boolean isEnabled; + private boolean isVerbose; + + private ArrayList activeVarps = new ArrayList<>(); + + @Override + public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { + if (!isEnabled) return; + + FontColor color = new FontColor((((component.type * 50) << 16) | 255 << 8 | Math.min(component.type * 50, 255))); + + if (!isVerbose) { + if + ( + component.type != 0 + && component.type != 9 + && (component.type != 5 + || (component.onOptionClick != null + || component.onMouseOver != null + || component.onHold != null + || component.varpTriggers != null + || component.onVarcstrTransmit != null + || component.onVarcTransmit != null + || component.cs1ComparisonOpcodes != null)) + || component.hidden + ) return; + } + + API.DrawText( + FontType.SMALL, + color, + TextModifier.LEFT, + componentIndex + "", + screenX, + screenY + ); + + if (component.varpTriggers != null) { + Arrays.stream(component.varpTriggers).forEach(varp -> { if(!activeVarps.contains(varp)) activeVarps.add(varp); }); + } + } + + @Override + public void Draw(long timeDelta) { + if (!isEnabled) return; + + StringBuilder sb = new StringBuilder(); + sb.append("Varps: ["); + + for (int varp : activeVarps) sb.append(varp).append(" "); + + sb.append("]"); + + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.CENTER, + sb.toString(), + GameShell.canvasWidth / 2 - 100, + 20 + ); + } + + @Override + public void ProcessCommand(String commandStr, String[] args) { + if (!API.PlayerHasPrivilege(Privileges.JMOD)) return; + + if (commandStr.equalsIgnoreCase("::debug_iface")){ + isEnabled = !isEnabled; + } + + if (commandStr.equalsIgnoreCase("::debug_iface_verbose")) { + isVerbose = !isVerbose; + } + + if (commandStr.equalsIgnoreCase("::clear_iface_varps")) { + activeVarps.clear(); + } + } +} diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties new file mode 100644 index 00000000..31de62cc --- /dev/null +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties @@ -0,0 +1,4 @@ + +AUTHOR='Me' +DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! +VERSION=-1.1 From 4bbb8e045895a2f19f5c9c3c3db00339a15fa66d Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 15:31:18 -0500 Subject: [PATCH 04/16] Plumbed in varp update handling --- client/src/main/java/plugin/Plugin.java | 18 +++++ .../main/java/plugin/PluginRepository.java | 4 ++ client/src/main/java/rt4/VarpDomain.java | 5 ++ .../InterfaceDebugPlugin/plugin.properties | 4 +- .../src/main/java/VarpLogPlugin/plugin.java | 70 +++++++++++++++++++ .../main/java/VarpLogPlugin/plugin.properties | 4 ++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 plugin-playground/src/main/java/VarpLogPlugin/plugin.java create mode 100644 plugin-playground/src/main/java/VarpLogPlugin/plugin.properties diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index 5cbb948e..c9fc9770 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -59,8 +59,26 @@ public void PlayerOverheadDraw(Player player, int screenX, int screenY) {} */ public void NPCOverheadDraw(Npc npc, int screenX, int screenY) {} + /** + * ProcessCommand is called when a user types and sends a message prefixed with :: + * @param commandStr the command the user used - should include :: in comparisons, eg
commandStr.equals("::command")
+ * @param args any other tokens included with the initial message. Tokens are determined by spaces. + */ public void ProcessCommand(String commandStr, String[] args) {} + /** + * ComponentDraw is called when an interface component is being rendered by the client. + * @param componentIndex the index of the component in its parent interface. + * @param component the component itself + * @param screenX the screen X coordinate of this component + * @param screenY the screen Y coordinate of this component + */ public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {} + /** + * OnVarpUpdate is called when varps are updated by the server sending packets. + * @param id the ID of the varp + * @param value the value the varp is being set to. + */ + public void OnVarpUpdate(int id, int value) {} } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index b21e2a3f..4f2e7d59 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -99,4 +99,8 @@ public static void ProcessCommand(JagString commandStr) { public static void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { loadedPlugins.values().forEach((plugin) -> plugin.ComponentDraw(componentIndex, component, screenX, screenY)); } + + public static void OnVarpUpdate(int id, int value) { + loadedPlugins.values().forEach((plugin) -> plugin.OnVarpUpdate(id, value)); + } } diff --git a/client/src/main/java/rt4/VarpDomain.java b/client/src/main/java/rt4/VarpDomain.java index cca66108..5fb00eb9 100644 --- a/client/src/main/java/rt4/VarpDomain.java +++ b/client/src/main/java/rt4/VarpDomain.java @@ -3,6 +3,7 @@ import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; public class VarpDomain { @OriginalMember(owner = "client!gj", name = "q", descriptor = "[I") @@ -36,6 +37,10 @@ public class VarpDomain { @OriginalMember(owner = "client!nh", name = "a", descriptor = "(BII)V") public static void set(@OriginalArg(1) int value, @OriginalArg(2) int id) { + PluginRepository.OnVarpUpdate(id, value); + + if (id > varp.length) return; + varp[id] = value; @Pc(20) LongNode local20 = (LongNode) aClass133_20.get(id); if (local20 == null) { diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties index 31de62cc..2a2d1b22 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties @@ -1,4 +1,4 @@ -AUTHOR='Me' -DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! +AUTHOR='Ceikry' +DESCRIPTION='Enables visual display of component children and a log of interface-related varps.' VERSION=-1.1 diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java new file mode 100644 index 00000000..a78ebe7a --- /dev/null +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java @@ -0,0 +1,70 @@ +package VarpLogPlugin; + +import plugin.Plugin; +import plugin.api.*; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; + +public class plugin extends Plugin { + boolean isEnabled; + + int MAX_VISIBLE_UPDATES = 5; + + ArrayList varpUpdates = new ArrayList<>(); + ArrayList updateCreationTime = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + + @Override + public void Init() { + if (API.IsHD()) MAX_VISIBLE_UPDATES = 10; + } + + @Override + public void OnVarpUpdate(int id, int value) { + if (!isEnabled) return; + + if (varpUpdates.size() == MAX_VISIBLE_UPDATES) { + varpUpdates.remove(0); + updateCreationTime.remove(0); + } + varpUpdates.add(id + " = " + value); + String formattedTime = sdf.format(new Date()); + updateCreationTime.add(formattedTime); + System.out.println("[VARP Update]" + formattedTime + " " + id + "->" + value); + } + + @Override + public void Draw(long timeDelta) { + if (!isEnabled) return; + + int startX = 10; + int startY = 30; + + API.DrawText(FontType.SMALL, FontColor.YELLOW, TextModifier.LEFT, "Varp Updates:", startX, startY); + + for (int i = 0; i < varpUpdates.size(); i++){ + String update = varpUpdates.get(i); + String time = updateCreationTime.get(i); + + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.LEFT, + "[" + time + "] " + update, + startX, + startY + (i + 1) * 15 + ); + } + } + + @Override + public void ProcessCommand(String commandStr, String[] args) { + if (!API.PlayerHasPrivilege(Privileges.JMOD)) return; + + if (commandStr.equalsIgnoreCase("::varplog")) { + isEnabled = !isEnabled; + } + } +} diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties new file mode 100644 index 00000000..97aa366c --- /dev/null +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties @@ -0,0 +1,4 @@ + +AUTHOR='Ceikry' +DESCRIPTION='Draws some info about varp changes on the screen.' +VERSION=-1.0 From 86de4b8e425e10f612824bb4e7393d342a5837fa Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 15:38:58 -0500 Subject: [PATCH 05/16] Should probably include all the prebuilt stuff by default. --- client/plugins/VarpLogPlugin/plugin.properties | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 client/plugins/VarpLogPlugin/plugin.properties diff --git a/client/plugins/VarpLogPlugin/plugin.properties b/client/plugins/VarpLogPlugin/plugin.properties new file mode 100644 index 00000000..97aa366c --- /dev/null +++ b/client/plugins/VarpLogPlugin/plugin.properties @@ -0,0 +1,4 @@ + +AUTHOR='Ceikry' +DESCRIPTION='Draws some info about varp changes on the screen.' +VERSION=-1.0 From be61fd1daf98761714502515a530dc4113f9bafa Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 15:38:58 -0500 Subject: [PATCH 06/16] Should probably include all the prebuilt stuff by default. From 529f741e13dee3b701e61f0d57ddc6bc27e05684 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 18:46:25 -0500 Subject: [PATCH 07/16] Add XP drop plugin --- client/build.gradle | 4 + client/src/main/java/plugin/Plugin.java | 9 +- .../main/java/plugin/PluginRepository.java | 8 + client/src/main/java/plugin/api/API.java | 62 ++++++- .../src/main/java/plugin/api/FontColor.java | 2 +- .../src/main/java/plugin/api/WindowMode.java | 7 + client/src/main/java/rt4/Cheat.java | 2 +- client/src/main/java/rt4/Cs1ScriptRunner.java | 34 +--- client/src/main/java/rt4/DateUtil.java | 12 +- client/src/main/java/rt4/DisplayMode.java | 14 +- client/src/main/java/rt4/JagString.java | 53 ++++-- client/src/main/java/rt4/LoginManager.java | 2 + client/src/main/java/rt4/Protocol.java | 20 +- client/src/main/java/rt4/client.java | 4 +- plugin-playground/build.gradle | 4 + .../src/main/java/VarpLogPlugin/plugin.java | 2 +- .../src/main/kotlin/XPDropPlugin/plugin.kt | 171 ++++++++++++++++++ .../kotlin/XPDropPlugin/plugin.properties | 3 + 18 files changed, 342 insertions(+), 71 deletions(-) create mode 100644 client/src/main/java/plugin/api/WindowMode.java create mode 100644 plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt create mode 100644 plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties diff --git a/client/build.gradle b/client/build.gradle index 394d2157..b559543e 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -1,6 +1,7 @@ plugins { id 'java' id 'application' + id 'org.jetbrains.kotlin.jvm' version '1.4.10' } mainClassName = 'rt4.client' @@ -35,6 +36,8 @@ dependencies { implementation 'lib:jogl-all-natives-linux-i586' implementation 'lib:jogl-all-natives-macosx-universal' implementation 'lib:jogl-all-natives-android-aarch64' + + runtime 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10' } jar { @@ -42,4 +45,5 @@ jar { attributes 'Main-Class': "$mainClassName" } from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + duplicatesStrategy = DuplicatesStrategy.INCLUDE } diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index c9fc9770..fd09102f 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -37,8 +37,10 @@ public void Init() {} /** * OnXPUpdate() is called when the client receives an XP update packet. This includes at login. + * @param skill - the skill ID being updated + * @param xp - the new total XP for the skill. */ - public void OnXPUpdate() {} + public void OnXPUpdate(int skill, int xp) {} /** * Update() is called once per tick, aka once every 600ms. @@ -81,4 +83,9 @@ public void ComponentDraw(int componentIndex, Component component, int screenX, * @param value the value the varp is being set to. */ public void OnVarpUpdate(int id, int value) {} + + /** + * OnLogout is called when the client logs out. This should be used to clear player-relevant plugin state. + */ + public void OnLogout() {} } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 4f2e7d59..89fa1e3d 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -103,4 +103,12 @@ public static void ComponentDraw(int componentIndex, Component component, int sc public static void OnVarpUpdate(int id, int value) { loadedPlugins.values().forEach((plugin) -> plugin.OnVarpUpdate(id, value)); } + + public static void OnXPUpdate(int skill, int xp) { + loadedPlugins.values().forEach((plugin) -> plugin.OnXPUpdate(skill, xp)); + } + + public static void OnLogout() { + loadedPlugins.values().forEach(Plugin::OnLogout); + } } diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index 157ddb1a..2db5ca8e 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -1,6 +1,10 @@ package plugin.api; import rt4.*; +import rt4.DisplayMode; +import rt4.Font; + +import java.awt.*; /** * API used for writing plugins, so dozens of plugins don't break when we rename shit :) @@ -8,7 +12,7 @@ */ public class API { public static void DrawText(FontType fontType, FontColor color, TextModifier mod, String text, int screenX, int screenY) { - JagString js = JagString.parse(text); + JagString js = JagString.of(text); Font font; switch (fontType) { @@ -51,4 +55,60 @@ public static boolean PlayerHasPrivilege(Privileges privilege) { public static boolean IsHD() { return GlRenderer.enabled; } + + public static Sprite GetSprite(int spriteId) { + Sprite rawSprite = null; + + if (client.js5Archive8.isFileReady(spriteId)) { + rawSprite = SpriteLoader.loadSprites(spriteId, client.js5Archive8); + } + + return rawSprite; + } + + public static WindowMode GetWindowMode() { + int mode = DisplayMode.getWindowMode(); + switch(mode) { + case 2: + return WindowMode.RESIZABLE; + case 3: + return WindowMode.FULLSCREEN; + default: + return WindowMode.FIXED; + } + } + + public static Dimension GetWindowDimensions() { + return new Dimension(GameShell.canvasWidth, GameShell.canvasHeight); + } + + public static void FillRect(int x, int y, int width, int height, int color, int alpha) { + if (IsHD()) { + if (alpha != 0) + GlRaster.fillRectAlpha(x,y,width,height,color,alpha); + else + GlRaster.fillRect(x,y,width,height,color); + } else { + if (alpha != 0) + SoftwareRaster.fillRectAlpha(x,y,width,height,color,alpha); + else + SoftwareRaster.fillRect(x,y,width,height,color); + } + } + + public static void DrawRect(int x, int y, int width, int height, int color) { + if (IsHD()) { + GlRaster.drawRect(x, y, width, height, color); + } else { + SoftwareRaster.drawRect(x, y, width, height, color); + } + } + + public static void ClipRect(int x, int y, int width, int height) { + if (IsHD()) { + GlRaster.setClip(x,y,width,height); + } else { + SoftwareRaster.setClip(x,y,width,height); + } + } } diff --git a/client/src/main/java/plugin/api/FontColor.java b/client/src/main/java/plugin/api/FontColor.java index 8b6a7728..a7e43e70 100644 --- a/client/src/main/java/plugin/api/FontColor.java +++ b/client/src/main/java/plugin/api/FontColor.java @@ -12,6 +12,6 @@ public FontColor(int colorCode) { } public static FontColor fromColor(Color color) { - return new FontColor(color.getRed() << 16 + color.getGreen() << 8 + color.getBlue()); + return new FontColor((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue()); } } diff --git a/client/src/main/java/plugin/api/WindowMode.java b/client/src/main/java/plugin/api/WindowMode.java new file mode 100644 index 00000000..f4b2a1b7 --- /dev/null +++ b/client/src/main/java/plugin/api/WindowMode.java @@ -0,0 +1,7 @@ +package plugin.api; + +public enum WindowMode { + FIXED, + RESIZABLE, + FULLSCREEN +} diff --git a/client/src/main/java/rt4/Cheat.java b/client/src/main/java/rt4/Cheat.java index 9f046f24..8a42f14e 100644 --- a/client/src/main/java/rt4/Cheat.java +++ b/client/src/main/java/rt4/Cheat.java @@ -102,7 +102,7 @@ public class Cheat { @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) { - @Pc(66) JagString local66 = JagString.concatenate(new JagString[]{aClass100_521, JagString.parseInt(arg2), Cs1ScriptRunner.aClass100_760, JagString.parseInt(arg0 >> 6), Cs1ScriptRunner.aClass100_760, JagString.parseInt(arg1 >> 6), Cs1ScriptRunner.aClass100_760, JagString.parseInt(arg0 & 0x3F), Cs1ScriptRunner.aClass100_760, JagString.parseInt(arg1 & 0x3F)}); + @Pc(66) JagString local66 = JagString.concatenate(new JagString[]{aClass100_521, JagString.parseInt(arg2), JagString.aClass100_760, JagString.parseInt(arg0 >> 6), JagString.aClass100_760, JagString.parseInt(arg1 >> 6), JagString.aClass100_760, JagString.parseInt(arg0 & 0x3F), JagString.aClass100_760, JagString.parseInt(arg1 & 0x3F)}); local66.print(); execute(local66); } diff --git a/client/src/main/java/rt4/Cs1ScriptRunner.java b/client/src/main/java/rt4/Cs1ScriptRunner.java index 86398387..0bf18970 100644 --- a/client/src/main/java/rt4/Cs1ScriptRunner.java +++ b/client/src/main/java/rt4/Cs1ScriptRunner.java @@ -34,22 +34,6 @@ public class Cs1ScriptRunner { public static final int anInt671 = 0x332d25; @OriginalMember(owner = "client!pg", name = "V", descriptor = "I") public static final int anInt4504 = 50; - @OriginalMember(owner = "client!wa", name = "pb", descriptor = "Lclient!na;") - public static final JagString aClass100_556 = JagString.parse("
"); - @OriginalMember(owner = "client!ed", name = "H", descriptor = "Lclient!na;") - public static final JagString aClass100_375 = JagString.parse("<)4col> x"); - @OriginalMember(owner = "client!je", name = "db", descriptor = "Lclient!na;") - public static final JagString aClass100_589 = JagString.parse(" "); - @OriginalMember(owner = "client!uf", name = "s", descriptor = "Lclient!na;") - public static final JagString aClass100_1043 = JagString.parse(" "); - @OriginalMember(owner = "client!wj", name = "b", descriptor = "Lclient!na;") - public static final JagString aClass100_1101 = JagString.parse(" "); - @OriginalMember(owner = "client!mi", name = "R", descriptor = "Lclient!na;") - public static final JagString aClass100_760 = JagString.parse(")1"); - @OriginalMember(owner = "client!sj", name = "w", descriptor = "Lclient!na;") - public static final JagString aClass100_978 = JagString.parse("<)4col>"); - @OriginalMember(owner = "client!jb", name = "c", descriptor = "Lclient!na;") - public static final JagString aClass100_583 = JagString.parse("(Y<)4col>"); @OriginalMember(owner = "client!th", name = "m", descriptor = "[Lclient!be;") public static Component[] aClass13Array13; @OriginalMember(owner = "client!k", name = "j", descriptor = "I") @@ -776,7 +760,7 @@ public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int local1934 = MiniMenu.NULL; } if ((local1989.stackable == 1 || component.objCount != 1) && component.objCount != -1) { - local1934 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local1934, aClass100_375, method1548(component.objCount)}); + local1934 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local1934, JagString.aClass100_375, method1548(component.objCount)}); } } if (aClass13_10 == component) { @@ -1018,9 +1002,9 @@ public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int local2611 = ObjTypeList.get(component.objTypes[local276] - 1); @Pc(3159) JagString local3159; if (local2611.stackable != 1 && component.objCounts[local276] == 1) { - local3159 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local2611.name, aClass100_978}); + local3159 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local2611.name, JagString.aClass100_978}); } else { - local3159 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local2611.name, aClass100_375, method1548(component.objCounts[local276])}); + local3159 = JagString.concatenate(new JagString[]{MiniMenu.aClass100_32, local2611.name, JagString.aClass100_375, method1548(component.objCounts[local276])}); } local556 = local123 + memory * (component.invMarginX + 115); objId = (component.invMarginY + 12) * local468 + local114; @@ -1045,7 +1029,7 @@ public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int local3297 = interpolate(component, local3297); @Pc(3325) JagString local3325; while (local3297.length() > 0) { - cardMemory = local3297.indexOf(aClass100_556); + cardMemory = local3297.indexOf(JagString.aClass100_556); if (cardMemory == -1) { local3325 = local3297; local3297 = JagString.EMPTY; @@ -1083,7 +1067,7 @@ public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int objId = local556 + local3299.lineHeight + 2; local3297 = interpolate(component, local3297); while (local3297.length() > 0) { - local563 = local3297.indexOf(aClass100_556); + local563 = local3297.indexOf(JagString.aClass100_556); if (local563 == -1) { local3325 = local3297; local3297 = JagString.EMPTY; @@ -1257,14 +1241,14 @@ public static void method13(@OriginalArg(1) Component arg0) { public static JagString method1548(@OriginalArg(1) int arg0) { @Pc(9) JagString local9 = JagString.parseInt(arg0); for (@Pc(21) int local21 = local9.length() - 3; local21 > 0; local21 -= 3) { - local9 = JagString.concatenate(new JagString[]{local9.substring(local21, 0), aClass100_760, local9.substring(local21)}); + local9 = JagString.concatenate(new JagString[]{local9.substring(local21, 0), JagString.aClass100_760, local9.substring(local21)}); } if (local9.length() > 9) { - return JagString.concatenate(new JagString[]{aClass100_1043, local9.substring(local9.length() - 8, 0), LocalizedText.MILLION_SHORT, MiniMenu.OPEN_PARENTHESIS, local9, aClass100_583}); + return JagString.concatenate(new JagString[]{JagString.aClass100_1043, local9.substring(local9.length() - 8, 0), LocalizedText.MILLION_SHORT, MiniMenu.OPEN_PARENTHESIS, local9, JagString.aClass100_583}); } else if (local9.length() > 6) { - return JagString.concatenate(new JagString[]{aClass100_589, local9.substring(local9.length() - 4, 0), LocalizedText.THOUSAND_SHORT, MiniMenu.OPEN_PARENTHESIS, local9, aClass100_583}); + return JagString.concatenate(new JagString[]{JagString.aClass100_589, local9.substring(local9.length() - 4, 0), LocalizedText.THOUSAND_SHORT, MiniMenu.OPEN_PARENTHESIS, local9, JagString.aClass100_583}); } else { - return JagString.concatenate(new JagString[]{aClass100_1101, local9, aClass100_978}); + return JagString.concatenate(new JagString[]{JagString.aClass100_1101, local9, JagString.aClass100_978}); } } diff --git a/client/src/main/java/rt4/DateUtil.java b/client/src/main/java/rt4/DateUtil.java index 8933053b..6def7667 100644 --- a/client/src/main/java/rt4/DateUtil.java +++ b/client/src/main/java/rt4/DateUtil.java @@ -12,16 +12,6 @@ public final class DateUtil { @OriginalMember(owner = "client!cl", name = "K", descriptor = "Ljava/util/Calendar;") public static final Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); - @OriginalMember(owner = "client!fn", name = "Z", descriptor = "Lclient!na;") - public static final JagString aClass100_461 = JagString.parse(")1 "); - @OriginalMember(owner = "client!wb", name = "a", descriptor = "Lclient!na;") - public static final JagString aClass100_1089 = JagString.parse(")2"); - @OriginalMember(owner = "client!dm", name = "j", descriptor = "Lclient!na;") - public static final JagString SPACE = JagString.parse(" "); - @OriginalMember(owner = "client!vh", name = "c", descriptor = "Lclient!na;") - public static final JagString COLON = JagString.parse(":"); - @OriginalMember(owner = "client!ee", name = "a", descriptor = "Lclient!na;") - public static final JagString TIMEZONE = JagString.parse(" GMT"); @OriginalMember(owner = "client!km", name = "tc", descriptor = "Lclient!na;") private static final JagString DEC = JagString.parse("Dec"); @@ -104,6 +94,6 @@ public static JagString getDateString(@OriginalArg(0) long date) { @Pc(36) int local36 = calendar.get(Calendar.HOUR_OF_DAY); @Pc(40) int local40 = calendar.get(Calendar.MINUTE); @Pc(44) int local44 = calendar.get(Calendar.SECOND); - return JagString.concatenate(new JagString[]{DAYS[local13 - 1], aClass100_461, JagString.parseInt(local17 / 10), JagString.parseInt(local17 % 10), aClass100_1089, MONTHS[local21], aClass100_1089, JagString.parseInt(local32), SPACE, JagString.parseInt(local36 / 10), JagString.parseInt(local36 % 10), COLON, JagString.parseInt(local40 / 10), JagString.parseInt(local40 % 10), COLON, JagString.parseInt(local44 / 10), JagString.parseInt(local44 % 10), TIMEZONE}); + return JagString.concatenate(new JagString[]{DAYS[local13 - 1], JagString.aClass100_461, JagString.parseInt(local17 / 10), JagString.parseInt(local17 % 10), JagString.aClass100_1089, MONTHS[local21], JagString.aClass100_1089, JagString.parseInt(local32), JagString.SPACE, JagString.parseInt(local36 / 10), JagString.parseInt(local36 % 10), JagString.COLON, JagString.parseInt(local40 / 10), JagString.parseInt(local40 % 10), JagString.COLON, JagString.parseInt(local44 / 10), JagString.parseInt(local44 % 10), JagString.TIMEZONE}); } } diff --git a/client/src/main/java/rt4/DisplayMode.java b/client/src/main/java/rt4/DisplayMode.java index e892fde8..06cfcb9d 100644 --- a/client/src/main/java/rt4/DisplayMode.java +++ b/client/src/main/java/rt4/DisplayMode.java @@ -75,7 +75,7 @@ public static int getWindowMode() { } @OriginalMember(owner = "client!pm", name = "a", descriptor = "(ZIZIZII)V") - public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) int arg1, @OriginalArg(2) boolean arg2, @OriginalArg(3) int arg3, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5) { + public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) int arg1, @OriginalArg(2) boolean arg2, @OriginalArg(3) int mode, @OriginalArg(5) int arg4, @OriginalArg(6) int arg5) { if (arg2) { GlRenderer.quit(); } @@ -92,7 +92,7 @@ public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) i } } if (arg1 == 3 && GameShell.fullScreenFrame == null) { - setWindowMode(true, Preferences.favoriteWorlds, true, arg3, -1, -1); + setWindowMode(true, Preferences.favoriteWorlds, true, mode, -1, -1); return; } @Pc(85) Container local85; @@ -146,7 +146,7 @@ public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) i GameShell.canvas.setLocation(GameShell.leftMargin, GameShell.topMargin); } } - if (arg1 == 0 && arg3 > 0) { + if (arg1 == 0 && mode > 0) { GlRenderer.createAndDestroyContext(GameShell.canvas); } if (arg2 && arg1 > 0) { @@ -167,7 +167,7 @@ public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) i } catch (@Pc(277) Exception local277) { } GameShell.method2704(); - if (arg3 == 0) { + if (mode == 0) { SoftwareRaster.frameBuffer = FrameBuffer.create(503, 765, GameShell.canvas); } else { SoftwareRaster.frameBuffer = null; @@ -185,10 +185,10 @@ public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) i } } if (!GlRenderer.enabled && arg1 > 0) { - setWindowMode(true, 0, true, arg3, -1, -1); + setWindowMode(true, 0, true, mode, -1, -1); return; } - if (arg1 > 0 && arg3 == 0) { + if (arg1 > 0 && mode == 0) { GameShell.thread.setPriority(5); SoftwareRaster.frameBuffer = null; SoftwareModel.method4580(); @@ -197,7 +197,7 @@ public static void setWindowMode(@OriginalArg(0) boolean arg0, @OriginalArg(1) i Rasteriser.setBrightness(0.7F); } LoginManager.method4637(); - } else if (arg1 == 0 && arg3 > 0) { + } else if (arg1 == 0 && mode > 0) { GameShell.thread.setPriority(1); SoftwareRaster.frameBuffer = FrameBuffer.create(503, 765, GameShell.canvas); SoftwareModel.method4583(); diff --git a/client/src/main/java/rt4/JagString.java b/client/src/main/java/rt4/JagString.java index fb8be2df..449090e9 100644 --- a/client/src/main/java/rt4/JagString.java +++ b/client/src/main/java/rt4/JagString.java @@ -19,13 +19,39 @@ public final class JagString implements StringInterface { @OriginalMember(owner = "client!pi", name = "Q", descriptor = "Lclient!na;") public static final JagString aClass100_853 = parse("null"); @OriginalMember(owner = "client!t", name = "C", descriptor = "Lclient!na;") - public static final JagString aClass100_994 = parse(")3"); + public static final JagString PERIOD = parse(")3"); @OriginalMember(owner = "client!vk", name = "a", descriptor = "[I") public static final int[] anIntArray471 = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 73, 74, 76, 78, 83, 84, 85, 86, 91, 92, 93, 94, 95, 97, 103, 104, 105, 106, 107, 108, 113, 114, 115, 116, 118, 119, 120, 121, 122, 123, 124, 125, 133, 134, 136, 138, 143, 144, 145, 146, 151, 152, 153, 154, 155, 157, 163, 164, 165, 166, 168, 169, 174, 175, 176, 177, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 97, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 157, 215, 216, 117, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 66, 66, 66, 66, 66, 66, 65, 75, 79, 79, 79, 79, 87, 87, 87, 87, 77, 96, 98, 98, 98, 98, 98, 250, 251, 109, 109, 109, 109, 117, 252, 167, 126, 126, 126, 126, 126, 126, 125, 135, 139, 139, 139, 139, 147, 147, 147, 147, 137, 156, 158, 158, 158, 158, 158, 253, 254, 170, 170, 170, 170, 178, 255, 178}; @OriginalMember(owner = "client!sh", name = "e", descriptor = "Lclient!na;") public static final JagString aClass100_967 = parse(""); @OriginalMember(owner = "client!dm", name = "n", descriptor = "Lclient!na;") public static final JagString PERCENT_SIGN = parse("(U"); + @OriginalMember(owner = "client!wa", name = "pb", descriptor = "Lclient!na;") + public static final JagString aClass100_556 = parse("
"); + @OriginalMember(owner = "client!ed", name = "H", descriptor = "Lclient!na;") + public static final JagString aClass100_375 = parse("<)4col> x"); + @OriginalMember(owner = "client!je", name = "db", descriptor = "Lclient!na;") + public static final JagString aClass100_589 = parse(" "); + @OriginalMember(owner = "client!uf", name = "s", descriptor = "Lclient!na;") + public static final JagString aClass100_1043 = parse(" "); + @OriginalMember(owner = "client!wj", name = "b", descriptor = "Lclient!na;") + public static final JagString aClass100_1101 = parse(" "); + @OriginalMember(owner = "client!mi", name = "R", descriptor = "Lclient!na;") + public static final JagString aClass100_760 = parse(")1"); + @OriginalMember(owner = "client!sj", name = "w", descriptor = "Lclient!na;") + public static final JagString aClass100_978 = parse("<)4col>"); + @OriginalMember(owner = "client!jb", name = "c", descriptor = "Lclient!na;") + public static final JagString aClass100_583 = parse("(Y<)4col>"); + @OriginalMember(owner = "client!fn", name = "Z", descriptor = "Lclient!na;") + public static final JagString aClass100_461 = parse(")1 "); + @OriginalMember(owner = "client!wb", name = "a", descriptor = "Lclient!na;") + public static final JagString aClass100_1089 = parse(")2"); + @OriginalMember(owner = "client!dm", name = "j", descriptor = "Lclient!na;") + public static final JagString SPACE = parse(" "); + @OriginalMember(owner = "client!vh", name = "c", descriptor = "Lclient!na;") + public static final JagString COLON = parse(":"); + @OriginalMember(owner = "client!ee", name = "a", descriptor = "Lclient!na;") + public static final JagString TIMEZONE = parse(" GMT"); @OriginalMember(owner = "client!li", name = "w", descriptor = "Lclient!sc;") public static HashTable aClass133_13; @OriginalMember(owner = "client!na", name = "T", descriptor = "[B") @@ -203,7 +229,7 @@ public static JagString parseIntTrue(@OriginalArg(2) int arg0) { @OriginalMember(owner = "client!oi", name = "a", descriptor = "(II)Lclient!na;") public static JagString formatIp(@OriginalArg(0) int arg0) { - return concatenate(new JagString[]{parseInt(arg0 >> 24 & 0xFF), aClass100_994, parseInt(arg0 >> 16 & 0xFF), aClass100_994, parseInt(arg0 >> 8 & 0xFF), aClass100_994, parseInt(arg0 & 0xFF)}); + return concatenate(new JagString[]{parseInt(arg0 >> 24 & 0xFF), PERIOD, parseInt(arg0 >> 16 & 0xFF), PERIOD, parseInt(arg0 >> 8 & 0xFF), PERIOD, parseInt(arg0 & 0xFF)}); } @OriginalMember(owner = "client!nb", name = "a", descriptor = "(II)Lclient!na;") @@ -215,18 +241,21 @@ public static JagString getNbsp() { return str; } + /** + * @return A JagString consisting of the actual bytes in the provided string. + */ @OriginalMember(owner = "client!sj", name = "a", descriptor = "(Ljava/lang/String;I)Lclient!na;") - public static JagString method3952(@OriginalArg(0) String arg0) { - @Pc(14) byte[] local14 = arg0.getBytes(StandardCharsets.ISO_8859_1); - @Pc(23) JagString local23 = new JagString(); - local23.chars = local14; - local23.length = 0; - for (@Pc(31) int local31 = 0; local31 < local14.length; local31++) { - if (local14[local31] != 0) { - local14[local23.length++] = local14[local31]; + public static JagString of(@OriginalArg(0) String string) { + @Pc(14) byte[] bytes = string.getBytes(StandardCharsets.ISO_8859_1); + @Pc(23) JagString js = new JagString(); + js.chars = bytes; + js.length = 0; + for (@Pc(31) int i = 0; i < bytes.length; i++) { + if (bytes[i] != 0) { + bytes[js.length++] = bytes[i]; } } - return local23; + return js; } @OriginalMember(owner = "client!gn", name = "a", descriptor = "(BI)Lclient!na;") @@ -983,7 +1012,7 @@ public final JagString append(@OriginalArg(0) int arg0) { public final JagString fromParameters(@OriginalArg(1) Applet arg0) { @Pc(19) String local19 = new String(this.chars, 0, this.length); @Pc(23) String local23 = arg0.getParameter(local19); - return local23 == null ? null : method3952(local23); + return local23 == null ? null : of(local23); } @OriginalMember(owner = "client!na", name = "d", descriptor = "(Z)I") diff --git a/client/src/main/java/rt4/LoginManager.java b/client/src/main/java/rt4/LoginManager.java index 58dbba30..dc7eff68 100644 --- a/client/src/main/java/rt4/LoginManager.java +++ b/client/src/main/java/rt4/LoginManager.java @@ -3,6 +3,7 @@ import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; import java.io.IOException; import java.net.Socket; @@ -690,6 +691,7 @@ public static void processLogout() { Protocol.verifyId = 0; VarpDomain.reset(); InterfaceList.method1596(true); + PluginRepository.OnLogout(); } @OriginalMember(owner = "client!k", name = "a", descriptor = "(IIIIZIZ)V") diff --git a/client/src/main/java/rt4/Protocol.java b/client/src/main/java/rt4/Protocol.java index 0c3aef4c..ebd2de3e 100644 --- a/client/src/main/java/rt4/Protocol.java +++ b/client/src/main/java/rt4/Protocol.java @@ -3,6 +3,7 @@ import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -967,7 +968,7 @@ public static boolean readPacketInternal() throws IOException { } else if (opcode == ServerProt.MESSAGE_GAME) { @Pc(245) JagString message = inboundBuffer.gjstr(); if (message.endsWith(TRADEREQ)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -980,7 +981,7 @@ public static boolean readPacketInternal() throws IOException { Chat.add(name, 4, LocalizedText.TRADEREQ); } } else if (message.endsWith(CHALREQ)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -990,11 +991,11 @@ public static boolean readPacketInternal() throws IOException { } } if (!ignored && Player.inTutorialIsland == 0) { - JagString local506 = message.substring(message.length() - 9, message.indexOf(DateUtil.COLON) + 1); + JagString local506 = message.substring(message.length() - 9, message.indexOf(JagString.COLON) + 1); Chat.add(name, 8, local506); } } else if (message.endsWith(ASSISTREQ)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -1020,7 +1021,7 @@ public static boolean readPacketInternal() throws IOException { Chat.add(JagString.EMPTY, 13, name); } } else if (message.endsWith(DUELSTAKE)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -1033,7 +1034,7 @@ public static boolean readPacketInternal() throws IOException { Chat.add(name, 14, JagString.EMPTY); } } else if (message.endsWith(DUELFRIEND)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int local277 = 0; local277 < IgnoreList.size; local277++) { @@ -1046,7 +1047,7 @@ public static boolean readPacketInternal() throws IOException { Chat.add(name, 15, JagString.EMPTY); } } else if (message.endsWith(aClass100_916)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -1059,7 +1060,7 @@ public static boolean readPacketInternal() throws IOException { Chat.add(name, 16, JagString.EMPTY); } } else if (message.endsWith(aClass100_770)) { - JagString name = message.substring(message.indexOf(DateUtil.COLON), 0); + JagString name = message.substring(message.indexOf(JagString.COLON), 0); long name37 = name.encode37(); boolean ignored = false; for (int i = 0; i < IgnoreList.size; i++) { @@ -1069,7 +1070,7 @@ public static boolean readPacketInternal() throws IOException { } } if (!ignored && Player.inTutorialIsland == 0) { - JagString local506 = message.substring(message.length() - 9, message.indexOf(DateUtil.COLON) + 1); + JagString local506 = message.substring(message.length() - 9, message.indexOf(JagString.COLON) + 1); Chat.add(name, 21, local506); } } else { @@ -1459,6 +1460,7 @@ public static boolean readPacketInternal() throws IOException { PlayerSkillXpTable.baseLevels[skill] = i + 2; } } + PluginRepository.OnXPUpdate(skill, xp); PlayerSkillXpTable.updatedStats[PlayerSkillXpTable.updatedStatsWriterIndex++ & 0x1F] = skill; opcode = -1; return true; diff --git a/client/src/main/java/rt4/client.java b/client/src/main/java/rt4/client.java index dd870730..eee446db 100644 --- a/client/src/main/java/rt4/client.java +++ b/client/src/main/java/rt4/client.java @@ -776,7 +776,7 @@ protected final void mainRedraw() { } else if (gameState == 30) { LoginManager.method1841(); } else if (gameState == 40) { - Fonts.drawTextOnScreen(false, JagString.concatenate(new JagString[]{LocalizedText.CONLOST, Cs1ScriptRunner.aClass100_556, LocalizedText.ATTEMPT_TO_REESTABLISH})); + Fonts.drawTextOnScreen(false, JagString.concatenate(new JagString[]{LocalizedText.CONLOST, JagString.aClass100_556, LocalizedText.ATTEMPT_TO_REESTABLISH})); } if (GlRenderer.enabled && gameState != 0) { GlRenderer.swapBuffers(); @@ -1020,7 +1020,7 @@ protected final void mainInit() { } mainLoadPrimaryText = LocalizedText.GAME0_LOADING; if (modeWhere != 0) { - Cheat.displayFps = true; + //Cheat.displayFps = true; } } diff --git a/plugin-playground/build.gradle b/plugin-playground/build.gradle index 30000542..e993027e 100644 --- a/plugin-playground/build.gradle +++ b/plugin-playground/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'org.jetbrains.kotlin.jvm' version '1.4.10' } version 'unspecified' @@ -15,6 +16,7 @@ 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")) + compile 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10' } test { @@ -63,4 +65,6 @@ task buildPlugins(type: Copy, dependsOn: classes) { def pluginsPath = rootProject.project("client").projectDir.absolutePath + File.separator + "plugins" from "build/classes/java/main" into pluginsPath + from "build/classes/kotlin/main" + into pluginsPath } \ No newline at end of file diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java index a78ebe7a..32c5431c 100644 --- a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java @@ -8,7 +8,7 @@ import java.util.Date; public class plugin extends Plugin { - boolean isEnabled; + boolean isEnabled = false; int MAX_VISIBLE_UPDATES = 5; diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt new file mode 100644 index 00000000..f2068778 --- /dev/null +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt @@ -0,0 +1,171 @@ +package XPDropPlugin; + +import plugin.Plugin +import plugin.api.* +import java.awt.Color +import kotlin.math.ceil + +/** + * Displays some simple XP drops. + * @author Ceikry + */ +class plugin : Plugin() { + private val displayTimeout = 10000L // 10 seconds + private val drawStart = 175 + private val drawPadding = 25 + private val drawClear = 60 + private val lastXp = IntArray(24) + private var totalXp = 0 + private val activeGains = ArrayList() + private var lastGain = 0L + + override fun Draw(deltaTime: Long) { + if (System.currentTimeMillis() - lastGain >= displayTimeout && activeGains.isEmpty()) + return + + drawTotalXPBox() + + val removeList = ArrayList() + var posX = API.GetWindowDimensions().width / 2 + + if (API.GetWindowMode() == WindowMode.FIXED) + posX += 60 + + for(gain in activeGains) { + gain.currentPos -= ceil(deltaTime / 20.0).toInt() + if (gain.currentPos <= drawClear) { + removeList.add(gain) + totalXp += gain.xp + } else if (gain.currentPos <= drawStart){ + val sprite = API.GetSprite(getSpriteArchive(gain.skill)) + sprite?.render(posX - 25, gain.currentPos - 20) + API.DrawText( + FontType.SMALL, + FontColor.fromColor(Color.WHITE), + TextModifier.LEFT, + addCommas(gain.xp.toString()), + posX, + gain.currentPos + ) + } + } + + activeGains.removeAll(removeList.toSet()) + } + + override fun OnXPUpdate(skill: Int, xp: Int) { + if (xp == lastXp[skill]) return + + val gain = xp - lastXp[skill] + if (gain <= 0) return + + lastXp[skill] = xp + + val currentTail = try { + activeGains.last().currentPos + } catch (e: Exception) { + drawStart - drawPadding + } + + activeGains.add(XPGain(skill, gain, currentTail + drawPadding)) + lastGain = System.currentTimeMillis() + } + + override fun OnLogout() { + lastGain = 0L + for (i in 0 until 24) lastXp[i] = 0 + totalXp = 0 + activeGains.clear() + } + + private fun drawTotalXPBox() { + var posX = API.GetWindowDimensions().width / 2 + val posY = API.GetWindowDimensions().height / 4 + + if (API.GetWindowMode() == WindowMode.FIXED) + posX += 60 + + API.ClipRect(0, 0, posX * 2, posY * 4) + + val horizontal = API.GetSprite(822) + val horizontalTop = API.GetSprite(820) + val tlCorner = API.GetSprite(824) + val blCorner = API.GetSprite(826) + val trCorner = API.GetSprite(825) + val brCorner = API.GetSprite(827) + val bg = API.GetSprite(657) + + bg?.render(posX - 77, 10) + API.FillRect(posX - 75, 5, 140, 30, 0, 64) + + blCorner?.render(posX - 77, 10) + tlCorner?.render(posX - 77, 5) + trCorner?.render(posX + 41, 5) + brCorner?.render(posX + 41, 10) + + horizontalTop?.render(posX - 45, -8) + horizontal?.render(posX - 45, 22) + horizontalTop?.render(posX - 15, -8) + horizontal?.render(posX - 15, 22) + horizontalTop?.render(posX + 9, -8) + horizontal?.render(posX + 9, 22) + + API.DrawText( + FontType.SMALL, + FontColor.fromColor(Color.WHITE), + TextModifier.LEFT, + "Total Xp: ${addCommas(totalXp.toString())}", + posX - 65, + 28 + ) + } + + data class XPGain(val skill: Int, val xp: Int, var currentPos: Int) + + fun addCommas(num: String): String{ + var newString = "" + if(num.length > 9){ + return "Lots!" + } + var counter = 1 + num.reversed().forEach { + if(counter % 3 == 0 && counter != num.length){ + newString += "$it," + } else { + newString += it + } + counter++ + } + return newString.reversed() + } + + fun getSpriteArchive(skillId: Int): Int{ + return when(skillId) { + 0 -> 197 + 1 -> 199 + 2 -> 198 + 3 -> 203 + 4 -> 200 + 5 -> 201 + 6 -> 202 + 7 -> 212 + 8 -> 214 + 9 -> 208 + 10 -> 211 + 11 -> 213 + 12 -> 207 + 13 -> 210 + 14 -> 209 + 15 -> 205 + 16 -> 204 + 17 -> 206 + 18 -> 216 + 19 -> 217 + 20 -> 215 + 21 -> 220 + 22 -> 221 + 23 -> 222 + else -> 222 + } + } +} diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties new file mode 100644 index 00000000..1e4001da --- /dev/null +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties @@ -0,0 +1,3 @@ +AUTHOR='Ceikry' +DESCRIPTION='Displays some pretty awesome XP drops :)' +VERSION=-1.1 From 54b426f72d9c73ffe69c9c2f9f9fdc8f91d96685 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 19:26:15 -0500 Subject: [PATCH 08/16] Add slayer tracker plugin --- client/src/main/java/plugin/api/API.java | 4 + plugin-playground/build.gradle | 41 ++++- .../main/kotlin/SlayerTrackerPlugin/plugin.kt | 153 ++++++++++++++++++ .../SlayerTrackerPlugin/plugin.properties | 4 + 4 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt create mode 100644 plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index 2db5ca8e..2bf9c9f7 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -66,6 +66,10 @@ public static Sprite GetSprite(int spriteId) { return rawSprite; } + public static Sprite GetObjSprite(int objId, int qty, boolean drawText, int outlineType, int shadowIntensity) { + return Inv.getObjectSprite(outlineType, objId, drawText, qty, shadowIntensity); + } + public static WindowMode GetWindowMode() { int mode = DisplayMode.getWindowMode(); switch(mode) { diff --git a/plugin-playground/build.gradle b/plugin-playground/build.gradle index e993027e..ad7d59db 100644 --- a/plugin-playground/build.gradle +++ b/plugin-playground/build.gradle @@ -23,17 +23,17 @@ test { useJUnitPlatform() } -task initializeNewPlugin { +task initializeNewJavaPlugin { 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 = """ + 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 = """ + new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/java/MyPlugin/plugin.java").text = """ package MyPlugin; import plugin.Plugin; @@ -61,6 +61,41 @@ public class plugin extends Plugin { } } +task initializeNewKotlinPlugin { + doLast { + def pluginFile = new File("src/main/kotlin/MyPlugin") + pluginFile.mkdirs() + + new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/kotlin/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 +""" + new File(rootProject.project("plugin-playground").projectDir.absolutePath + File.separator + "src/main/kotlin/MyPlugin/plugin.kt").text = """ +package MyPlugin + +import plugin.Plugin + +class plugin : Plugin() { + override fun Init() { + //Init() is called when the plugin is loaded + } + + override fun Update() { + //Update() is called once per tick (600ms) + } + + override fun Draw(deltaTime: Long) { + //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" diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt new file mode 100644 index 00000000..14151357 --- /dev/null +++ b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt @@ -0,0 +1,153 @@ +package SlayerTrackerPlugin + +import plugin.Plugin +import plugin.api.API +import plugin.api.FontColor +import plugin.api.FontType +import plugin.api.TextModifier +import rt4.Sprite +import java.awt.Color +import java.lang.Exception + +class plugin : Plugin() { + val boxColor = 6116423 + val posX = 5 + val posY = 30 + val boxWidth = 90 + val boxHeight = 30 + val boxOpacity = 160 + val textX = 65 + val textY = 50 + val spriteX = 7 + val spriteY = 30 + + var slayerTaskID = -1 + var slayerTaskAmount = 0 + var curSprite: Sprite? = null + + override fun Draw(deltaTime: Long) { + if (slayerTaskAmount == 0 || slayerTaskID == -1) return + + API.FillRect(posX, posY, boxWidth, boxHeight, boxColor, boxOpacity) + curSprite?.render(spriteX, spriteY) + API.DrawText( + FontType.SMALL, + FontColor.fromColor(Color.WHITE), + TextModifier.LEFT, + slayerTaskAmount.toString(), + textX, + textY + ) + } + + override fun OnVarpUpdate(id: Int, value: Int) { + if (id == 2502) { + slayerTaskID = value and 0x7F + slayerTaskAmount = (value shr 7) and 0xFF + setSprite() + } + } + + override fun OnLogout() { + slayerTaskID = -1 + slayerTaskAmount = 0 + curSprite = null + } + + private fun setSprite() { + try { + val itemId: Int = when (slayerTaskID) { + 0 -> 4144 + 1 -> 4149 + 2 -> 560 + 3 -> 10176 + 4 -> 4135 + 5 -> 4139 + 6 -> 14072 + 7 -> 948 + 8 -> 12189 + 9 -> 3098 + 10 -> 1747 + 11 -> 4141 + 12 -> 1751 + 13 -> 11047 + 14 -> 2349 + 15 -> 9008 + 16 -> 4521 + 17 -> 4134 + 18 -> 8900 + 19 -> 4520 + 20 -> 4137 + 21 -> 1739 + 22 -> 7982 + 23 -> 10149 + 24 -> 532 + 25 -> 8141 + 26 -> 6637 + 27 -> 6695 + 28 -> 8132 + 29 -> 4145 + 30 -> 7500 + 31 -> 1422 + 32 -> 1387 + 33 -> 9011 + 34 -> 4147 + 35 -> 552 + 36 -> 6722 + 37 -> 10998 + 38 -> 9016 + 39 -> 2402 + 40 -> 1753 + 41 -> 7050 + 42 -> 8137 + 43 -> 12570 + 44 -> 8133 + 45 -> 4671 + 46 -> 4671 + 47 -> 1159 + 48 -> 4140 + 49 -> 2351 + 50 -> 4142 + 51 -> 7778 + 52 -> 8139 + 53 -> 4146 + 54 -> 2402 + 55 -> 2359 + 56 -> 12079 + 57 -> 12201 + 58 -> 12570 + 59 -> 4148 + 60 -> 4818 + 61 -> 6107 + 62 -> 4138 + 63 -> 14074 + 64 -> 4136 + 65 -> 6297 + 66 -> 10634 + 67 -> 553 + 68 -> 8135 + 69 -> 11732 + 70 -> 10284 + 71 -> 13923 + 72 -> 2353 + 73 -> 8136 + 74 -> 4143 + 75 -> 6528 + 76 -> 10109 + 77 -> 1403 + 78 -> 2952 + 79 -> 958 + 80 -> 7594 + 89 -> 6811 + else -> -1 + } + + val sprite = API.GetObjSprite(itemId, 1, false, 1, 1) + + curSprite = sprite + } catch (ignored: Exception){} + } + + //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 +} diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties new file mode 100644 index 00000000..31de62cc --- /dev/null +++ b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties @@ -0,0 +1,4 @@ + +AUTHOR='Me' +DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! +VERSION=-1.1 From 1890fe808739070dbb1ec954c21cd6c04b45cb1e Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 19:33:10 -0500 Subject: [PATCH 09/16] Update plugin descriptions and minor xp drop bugfix --- .../src/main/java/InterfaceDebugPlugin/plugin.properties | 3 +-- .../src/main/java/VarpLogPlugin/plugin.properties | 3 +-- .../src/main/kotlin/SlayerTrackerPlugin/plugin.kt | 4 ++++ .../src/main/kotlin/SlayerTrackerPlugin/plugin.properties | 7 +++---- plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt | 5 +++++ .../src/main/kotlin/XPDropPlugin/plugin.properties | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties index 2a2d1b22..c3e8109b 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties @@ -1,4 +1,3 @@ - AUTHOR='Ceikry' DESCRIPTION='Enables visual display of component children and a log of interface-related varps.' -VERSION=-1.1 +VERSION=1.1 diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties index 97aa366c..2d38f54b 100644 --- a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties @@ -1,4 +1,3 @@ - AUTHOR='Ceikry' DESCRIPTION='Draws some info about varp changes on the screen.' -VERSION=-1.0 +VERSION=1.0 diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt index 14151357..0c1f50d9 100644 --- a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt +++ b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt @@ -9,6 +9,10 @@ import rt4.Sprite import java.awt.Color import java.lang.Exception +/** + * Very simple slayer task tracker + * @author Ceikry + */ class plugin : Plugin() { val boxColor = 6116423 val posX = 5 diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties index 31de62cc..afca955d 100644 --- a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties +++ b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties @@ -1,4 +1,3 @@ - -AUTHOR='Me' -DESCRIPTION='Make sure to rename both the MyPlugin folder and the package statement in plugin.java! -VERSION=-1.1 +AUTHOR='Ceikry' +DESCRIPTION='Helps to keep track of kills remaining on a slayer task.' +VERSION=1.1 diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt index f2068778..2b4b0820 100644 --- a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt @@ -59,6 +59,11 @@ class plugin : Plugin() { val gain = xp - lastXp[skill] if (gain <= 0) return + if (lastXp[skill] == 0) { + lastXp[skill] = xp + totalXp += xp + return + } lastXp[skill] = xp val currentTail = try { diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties index 1e4001da..9ce85d31 100644 --- a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties @@ -1,3 +1,3 @@ AUTHOR='Ceikry' DESCRIPTION='Displays some pretty awesome XP drops :)' -VERSION=-1.1 +VERSION=1.1 From 02df637c4b6184f080cb19eb7ebd428b3f149594 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 10 Jul 2022 22:16:52 -0500 Subject: [PATCH 10/16] Update build.gradle for playground --- playground/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/playground/build.gradle b/playground/build.gradle index 3ff5a899..fbf4a3d8 100644 --- a/playground/build.gradle +++ b/playground/build.gradle @@ -24,4 +24,5 @@ jar { attributes 'Main-Class': "$mainClassName" } from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + duplicatesStrategy = DuplicatesStrategy.INCLUDE } From d4b68d135f297b167b2fa0227cbcee6f5d4af368 Mon Sep 17 00:00:00 2001 From: ceikry Date: Mon, 11 Jul 2022 08:35:50 -0500 Subject: [PATCH 11/16] Show model ID in interface debug --- .../src/main/java/InterfaceDebugPlugin/plugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java index fd78ea9f..b6cd5a6a 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java @@ -41,7 +41,7 @@ public void ComponentDraw(int componentIndex, Component component, int screenX, FontType.SMALL, color, TextModifier.LEFT, - componentIndex + "", + componentIndex + "" + (component.modelId != 0 ? " (" + component.modelId + ")" : ""), screenX, screenY ); From a8e211b5d4a75f08764a462432e7d6bd56c06a45 Mon Sep 17 00:00:00 2001 From: ceikry Date: Fri, 15 Jul 2022 15:32:38 -0500 Subject: [PATCH 12/16] Enhanced NPC overhead debug --- client/src/main/java/rt4/Npc.java | 2 +- client/src/main/java/rt4/PathingEntity.java | 2 +- client/src/main/java/rt4/Player.java | 2 +- .../src/main/java/OverheadDebugPlugin/plugin.java | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/src/main/java/rt4/Npc.java b/client/src/main/java/rt4/Npc.java index 71e047ec..828f9631 100644 --- a/client/src/main/java/rt4/Npc.java +++ b/client/src/main/java/rt4/Npc.java @@ -132,7 +132,7 @@ public final void render(@OriginalArg(0) int orientation, @OriginalArg(1) int ar @OriginalMember(owner = "client!km", name = "b", descriptor = "(I)I") @Override - protected final int getBasId() { + public final int getBasId() { if (client.game != 0 && this.type.multiNpcs != null) { @Pc(17) NpcType local17 = this.type.getMultiNpc(); if (local17 != null && local17.bastypeid != -1) { diff --git a/client/src/main/java/rt4/PathingEntity.java b/client/src/main/java/rt4/PathingEntity.java index 8d311d44..11d1d6b5 100644 --- a/client/src/main/java/rt4/PathingEntity.java +++ b/client/src/main/java/rt4/PathingEntity.java @@ -628,7 +628,7 @@ protected final void method2687(@OriginalArg(0) Model arg0) { } @OriginalMember(owner = "client!fe", name = "b", descriptor = "(I)I") - protected abstract int getBasId(); + public abstract int getBasId(); @OriginalMember(owner = "client!fe", name = "c", descriptor = "(I)V") public final void method2689() { diff --git a/client/src/main/java/rt4/Player.java b/client/src/main/java/rt4/Player.java index b99f4037..a80cb6d7 100644 --- a/client/src/main/java/rt4/Player.java +++ b/client/src/main/java/rt4/Player.java @@ -300,7 +300,7 @@ public final int getSize() { @OriginalMember(owner = "client!e", name = "b", descriptor = "(I)I") @Override - protected final int getBasId() { + public final int getBasId() { return this.anInt3365; } diff --git a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java index 610c31a3..0cf52aa9 100644 --- a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java @@ -31,13 +31,13 @@ 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.getMultiNpc().name + "]" : "Wrapper" : npc.type.name) + - " [Lvl: " + - npc.type.combatLevel + - "] [ID: " + - npc.type.id + + " [G: " + + npc.spotAnimId + + "] [R: " + npc.getBasId() + + "] [A: " + npc.seqId + "] [Vb: " + npc.type.multiNpcVarbit + "]"; From 9750195081c48d9e0524c0ffd5f27356aac33703 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sat, 16 Jul 2022 08:25:28 -0500 Subject: [PATCH 13/16] Fix bug with plugin draw callbacks that was causing interface flickering --- client/src/main/java/rt4/Cs1ScriptRunner.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client/src/main/java/rt4/Cs1ScriptRunner.java b/client/src/main/java/rt4/Cs1ScriptRunner.java index 0bf18970..cf7cd091 100644 --- a/client/src/main/java/rt4/Cs1ScriptRunner.java +++ b/client/src/main/java/rt4/Cs1ScriptRunner.java @@ -485,6 +485,11 @@ public static void renderComponent(@OriginalArg(0) int arg0, @OriginalArg(1) int } if (component.clientCode == 1405) { PluginRepository.Draw(); + InterfaceList.aBooleanArray100[rectangle] = true; + InterfaceList.rectangleRedraw[rectangle] = true; + + //Above are inauthentic changes to call plugin draws and redraw this interface. Below I have left intact all the authentic code. + if (!Cheat.displayFps) { continue; } From 3e12a9115dfbef2b8a8e4fb52c0bdfbfb2d87448 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sat, 16 Jul 2022 10:12:27 -0500 Subject: [PATCH 14/16] Update to allow plugin metadata definition from annotations and load other classes in same folder as plugin.class. --- .../plugins/VarpLogPlugin/plugin.properties | 4 -- client/src/main/java/plugin/PluginInfo.java | 18 +++++++- .../main/java/plugin/PluginRepository.java | 27 +++++++++--- .../java/plugin/annotations/PluginMeta.java | 11 +++++ .../java/InterfaceDebugPlugin/plugin.java | 6 +++ .../InterfaceDebugPlugin/plugin.properties | 3 -- .../main/java/OverheadDebugPlugin/plugin.java | 9 ++-- .../OverheadDebugPlugin/plugin.properties | 3 -- .../src/main/java/VarpLogPlugin/plugin.java | 6 +++ .../main/java/VarpLogPlugin/plugin.properties | 3 -- .../main/kotlin/SlayerTrackerPlugin/plugin.kt | 10 +++-- .../SlayerTrackerPlugin/plugin.properties | 3 -- .../src/main/kotlin/XPDropPlugin/XPSprites.kt | 40 ++++++++++++++++++ .../src/main/kotlin/XPDropPlugin/plugin.kt | 42 ++++--------------- .../kotlin/XPDropPlugin/plugin.properties | 3 -- 15 files changed, 121 insertions(+), 67 deletions(-) delete mode 100644 client/plugins/VarpLogPlugin/plugin.properties create mode 100644 client/src/main/java/plugin/annotations/PluginMeta.java delete mode 100644 plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties delete mode 100644 plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties delete mode 100644 plugin-playground/src/main/java/VarpLogPlugin/plugin.properties delete mode 100644 plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties create mode 100644 plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt delete mode 100644 plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties diff --git a/client/plugins/VarpLogPlugin/plugin.properties b/client/plugins/VarpLogPlugin/plugin.properties deleted file mode 100644 index 97aa366c..00000000 --- a/client/plugins/VarpLogPlugin/plugin.properties +++ /dev/null @@ -1,4 +0,0 @@ - -AUTHOR='Ceikry' -DESCRIPTION='Draws some info about varp changes on the screen.' -VERSION=-1.0 diff --git a/client/src/main/java/plugin/PluginInfo.java b/client/src/main/java/plugin/PluginInfo.java index 11d64f8f..01fddc65 100644 --- a/client/src/main/java/plugin/PluginInfo.java +++ b/client/src/main/java/plugin/PluginInfo.java @@ -1,5 +1,7 @@ package plugin; +import plugin.annotations.PluginMeta; + import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; @@ -42,7 +44,21 @@ public static PluginInfo loadFromFile(File file) { ); } - @Override + public static PluginInfo loadFromClass(Class clazz) { + PluginMeta info = clazz.getAnnotation(PluginMeta.class); + + if (info == null) { + return null; + } + + return new PluginInfo( + info.author(), + info.description(), + info.version() + ); + } + + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 89fa1e3d..901e0797 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -7,7 +7,9 @@ import java.net.URLClassLoader; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * Responsible for loading and broadcasting methods to all plugins. @@ -39,23 +41,29 @@ public static void Init() { for(File file : Objects.requireNonNull(pluginsDirectory.listFiles())) { if(!file.isDirectory()) continue; + if(file.getName().equals("META-INF")) continue; File infoFile = new File(file.getAbsoluteFile() + File.separator + "plugin.properties"); File pluginRoot = new File(file.getAbsoluteFile() + File.separator + "plugin.class"); + 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"); + PluginInfo info; if (infoFile.exists()) info = PluginInfo.loadFromFile(infoFile); else - info = new PluginInfo("Unknown", "", 1.0); + info = PluginInfo.loadFromClass(clazz); - if (!pluginRoot.exists()) { - System.err.println("Unable to load plugin " + file.getName() + " because plugin.class is absent!"); + if (info == null) { + System.err.println("Unable to load plugin " + file.getName() + " because it contains no information about author, version, etc!"); continue; } - Class clazz = loader.loadClass(file.getName() + ".plugin"); - try { Plugin thisPlugin = (Plugin) clazz.newInstance(); thisPlugin._init(); @@ -66,6 +74,15 @@ public static void Init() { return; } + List otherClasses = Arrays.stream(Objects.requireNonNull(file.listFiles())) + .filter((f) -> + !f.getName().equals("plugin.class") && f.getName().contains(".class")) + .collect(Collectors.toList()); + + for (File f : otherClasses) { + loader.loadClass(file.getName() + "." + f.getName().replace(".class","")); + } + System.out.println("Successfully loaded plugin " + file.getName() + ", version " + info.version); } } catch (Exception e) { diff --git a/client/src/main/java/plugin/annotations/PluginMeta.java b/client/src/main/java/plugin/annotations/PluginMeta.java new file mode 100644 index 00000000..cd84f12c --- /dev/null +++ b/client/src/main/java/plugin/annotations/PluginMeta.java @@ -0,0 +1,11 @@ +package plugin.annotations; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface PluginMeta { + String author(); + String description(); + double version(); +} diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java index b6cd5a6a..7d1eff78 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java @@ -1,6 +1,7 @@ package InterfaceDebugPlugin; import plugin.Plugin; +import plugin.annotations.PluginMeta; import plugin.api.*; import rt4.Component; import rt4.GameShell; @@ -8,6 +9,11 @@ import java.util.ArrayList; import java.util.Arrays; +@PluginMeta( + author = "Ceikry", + description = "Aids in identifying interface components/varps/model IDs.", + version = 1.2 +) public class plugin extends Plugin { private boolean isEnabled; private boolean isVerbose; diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties deleted file mode 100644 index c3e8109b..00000000 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -AUTHOR='Ceikry' -DESCRIPTION='Enables visual display of component children and a log of interface-related varps.' -VERSION=1.1 diff --git a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java index 0cf52aa9..ea77cd66 100644 --- a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.java @@ -1,12 +1,15 @@ package OverheadDebugPlugin; import plugin.Plugin; +import plugin.annotations.PluginMeta; import plugin.api.*; import rt4.*; -/** - * @author ceikry - */ +@PluginMeta( + author = "Ceikry", + description = "Draws helpful overhead debug information.", + version = 1.3 +) public class plugin extends Plugin { private boolean isEnabled = false; diff --git a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties b/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties deleted file mode 100644 index 99727349..00000000 --- a/plugin-playground/src/main/java/OverheadDebugPlugin/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -AUTHOR="Ceikry" -DESCRIPTION="Renders helpful debug text over the heads of players and NPCs." -VERSION=1.0 \ No newline at end of file diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java index 32c5431c..3c2a5b75 100644 --- a/plugin-playground/src/main/java/VarpLogPlugin/plugin.java +++ b/plugin-playground/src/main/java/VarpLogPlugin/plugin.java @@ -1,12 +1,18 @@ package VarpLogPlugin; import plugin.Plugin; +import plugin.annotations.PluginMeta; import plugin.api.*; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +@PluginMeta( + author = "Ceikry", + description = "Adds a simple log of varp changes drawn directly to the screen.", + version = 1.0 +) public class plugin extends Plugin { boolean isEnabled = false; diff --git a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties b/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties deleted file mode 100644 index 2d38f54b..00000000 --- a/plugin-playground/src/main/java/VarpLogPlugin/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -AUTHOR='Ceikry' -DESCRIPTION='Draws some info about varp changes on the screen.' -VERSION=1.0 diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt index 0c1f50d9..6efd3751 100644 --- a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt +++ b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.kt @@ -1,6 +1,7 @@ package SlayerTrackerPlugin import plugin.Plugin +import plugin.annotations.PluginMeta import plugin.api.API import plugin.api.FontColor import plugin.api.FontType @@ -9,10 +10,11 @@ import rt4.Sprite import java.awt.Color import java.lang.Exception -/** - * Very simple slayer task tracker - * @author Ceikry - */ +@PluginMeta( + author = "Ceikry", + description = "Draws a simple slayer task tracker onto the screen if one is active.", + version = 1.0 +) class plugin : Plugin() { val boxColor = 6116423 val posX = 5 diff --git a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties b/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties deleted file mode 100644 index afca955d..00000000 --- a/plugin-playground/src/main/kotlin/SlayerTrackerPlugin/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -AUTHOR='Ceikry' -DESCRIPTION='Helps to keep track of kills remaining on a slayer task.' -VERSION=1.1 diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt b/plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt new file mode 100644 index 00000000..a7c2173d --- /dev/null +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/XPSprites.kt @@ -0,0 +1,40 @@ +package XPDropPlugin + +import plugin.api.API +import rt4.Sprite + +object XPSprites { + fun getSpriteForSkill(skillId: Int) : Sprite? { + return API.GetSprite(getSpriteId(skillId)) + } + + private fun getSpriteId(skillId: Int) : Int { + return when (skillId) { + 0 -> 197 + 1 -> 199 + 2 -> 198 + 3 -> 203 + 4 -> 200 + 5 -> 201 + 6 -> 202 + 7 -> 212 + 8 -> 214 + 9 -> 208 + 10 -> 211 + 11 -> 213 + 12 -> 207 + 13 -> 210 + 14 -> 209 + 15 -> 205 + 16 -> 204 + 17 -> 206 + 18 -> 216 + 19 -> 217 + 20 -> 215 + 21 -> 220 + 22 -> 221 + 23 -> 222 + else -> 222 + } + } +} \ No newline at end of file diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt index 2b4b0820..6e316a2a 100644 --- a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt +++ b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.kt @@ -1,14 +1,16 @@ package XPDropPlugin; import plugin.Plugin +import plugin.annotations.PluginMeta import plugin.api.* import java.awt.Color import kotlin.math.ceil -/** - * Displays some simple XP drops. - * @author Ceikry - */ +@PluginMeta( + author = "Ceikry", + description = "Draws nice and clean experience drops onto the screen.", + version = 1.2 +) class plugin : Plugin() { private val displayTimeout = 10000L // 10 seconds private val drawStart = 175 @@ -37,7 +39,7 @@ class plugin : Plugin() { removeList.add(gain) totalXp += gain.xp } else if (gain.currentPos <= drawStart){ - val sprite = API.GetSprite(getSpriteArchive(gain.skill)) + val sprite = XPSprites.getSpriteForSkill(skillId = gain.skill) sprite?.render(posX - 25, gain.currentPos - 20) API.DrawText( FontType.SMALL, @@ -143,34 +145,4 @@ class plugin : Plugin() { } return newString.reversed() } - - fun getSpriteArchive(skillId: Int): Int{ - return when(skillId) { - 0 -> 197 - 1 -> 199 - 2 -> 198 - 3 -> 203 - 4 -> 200 - 5 -> 201 - 6 -> 202 - 7 -> 212 - 8 -> 214 - 9 -> 208 - 10 -> 211 - 11 -> 213 - 12 -> 207 - 13 -> 210 - 14 -> 209 - 15 -> 205 - 16 -> 204 - 17 -> 206 - 18 -> 216 - 19 -> 217 - 20 -> 215 - 21 -> 220 - 22 -> 221 - 23 -> 222 - else -> 222 - } - } } diff --git a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties b/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties deleted file mode 100644 index 9ce85d31..00000000 --- a/plugin-playground/src/main/kotlin/XPDropPlugin/plugin.properties +++ /dev/null @@ -1,3 +0,0 @@ -AUTHOR='Ceikry' -DESCRIPTION='Displays some pretty awesome XP drops :)' -VERSION=1.1 From 4377d4958e1ccc9b97c6c99b9e2a9df8dfbae5e5 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sat, 16 Jul 2022 12:37:57 -0500 Subject: [PATCH 15/16] Reimplemented all input QOL changes as a plugin --- client/config.json | 4 +- client/src/main/java/plugin/api/API.java | 80 ++++++++++++ client/src/main/java/rt4/JavaMouseWheel.java | 16 +-- client/src/main/java/rt4/Mouse.java | 40 +++--- client/src/main/java/rt4/client.java | 2 +- .../java/InterfaceDebugPlugin/plugin.java | 2 +- .../src/main/kotlin/BasicInputQOL/plugin.kt | 115 ++++++++++++++++++ 7 files changed, 219 insertions(+), 40 deletions(-) create mode 100644 plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt diff --git a/client/config.json b/client/config.json index 7f0f5fdf..5222e056 100644 --- a/client/config.json +++ b/client/config.json @@ -1,6 +1,6 @@ { - "ip_management": "play.2009scape.org", - "ip_address": "play.2009scape.org", + "ip_management": "test.2009scape.org", + "ip_address": "test.2009scape.org", "world": 1, "server_port": 43594, "wl_port": 43595, diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index 2bf9c9f7..a4577bd2 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -5,6 +5,9 @@ import rt4.Font; import java.awt.*; +import java.awt.event.*; + +import static rt4.MathUtils.clamp; /** * API used for writing plugins, so dozens of plugins don't break when we rename shit :) @@ -115,4 +118,81 @@ public static void ClipRect(int x, int y, int width, int height) { SoftwareRaster.setClip(x,y,width,height); } } + + public static void AddMouseListener(MouseAdapter m) { + GameShell.canvas.addMouseListener(m); + GameShell.canvas.addMouseMotionListener(m); + } + + public static void AddMouseWheelListener(MouseWheelListener mw) { + GameShell.canvas.addMouseWheelListener(mw); + } + + public static void AddKeyboardListener(KeyAdapter k) { + GameShell.canvas.addKeyListener(k); + } + + public static void SetCameraYaw(double targetYaw) { + Camera.yawTarget = targetYaw; + Camera.clampCameraAngle(); + } + + public static void UpdateCameraYaw(double yawDiff) { + Camera.yawTarget += yawDiff; + Camera.clampCameraAngle(); + } + + public static double GetCameraYaw() { + return Camera.yawTarget; + } + + public static void SetCameraPitch(double targetPitch) { + Camera.pitchTarget = targetPitch; + Camera.clampCameraAngle(); + } + + public static void UpdateCameraPitch(double pitchDiff) { + Camera.pitchTarget += pitchDiff; + Camera.clampCameraAngle(); + } + + public static double GetCameraPitch() { + return Camera.pitchTarget; + } + + public static void UpdateCameraZoom(int zoomDiff) { + Camera.ZOOM = clamp(200, 1200, Camera.ZOOM + (zoomDiff >= 0 ? 50 : -50)); + } + + public static void SetCameraZoom(int zoomTarget) { + Camera.ZOOM = clamp(200, 1200, zoomTarget); + } + + public static int GetCameraZoom() { + return Camera.ZOOM; + } + + public static int GetMouseWheelRotation() { + return ((JavaMouseWheel) client.mouseWheel).currentRotation; + } + + public static int GetPreviousMouseWheelRotation() { + return ((JavaMouseWheel) client.mouseWheel).previousRotation; + } + + public static int GetMouseX() { + return Mouse.currentMouseX; + } + + public static int GetMouseY() { + return Mouse.currentMouseY; + } + + /** + * Very simple wrapper around the already rename Keyboard checks. + * @param keycode the keycode to use. Keyboard class has named constants for these + */ + public static boolean IsKeyPressed(int keycode) { + return Keyboard.pressedKeys[keycode]; + } } diff --git a/client/src/main/java/rt4/JavaMouseWheel.java b/client/src/main/java/rt4/JavaMouseWheel.java index 6c09d0d6..dd06da50 100644 --- a/client/src/main/java/rt4/JavaMouseWheel.java +++ b/client/src/main/java/rt4/JavaMouseWheel.java @@ -15,7 +15,8 @@ public final class JavaMouseWheel extends MouseWheel implements MouseWheelListener { @OriginalMember(owner = "client!o", name = "g", descriptor = "I") - private int anInt4233 = 0; + public int currentRotation = 0; + public int previousRotation = 0; @OriginalMember(owner = "client!o", name = "a", descriptor = "(ZLjava/awt/Component;)V") @Override @@ -26,21 +27,16 @@ public final void stop(@OriginalArg(1) Component arg0) { @OriginalMember(owner = "client!o", name = "a", descriptor = "(I)I") @Override public final synchronized int getRotation() { - @Pc(2) int local2 = this.anInt4233; - this.anInt4233 = 0; + @Pc(2) int local2 = this.currentRotation; + this.currentRotation = 0; return local2; } @OriginalMember(owner = "client!o", name = "mouseWheelMoved", descriptor = "(Ljava/awt/event/MouseWheelEvent;)V") @Override public final synchronized void mouseWheelMoved(@OriginalArg(0) MouseWheelEvent arg0) { - int previous = this.anInt4233; - this.anInt4233 += arg0.getWheelRotation(); - int diff = this.anInt4233 - previous; - - if (((GlobalJsonConfig.instance != null && GlobalJsonConfig.instance.mouseWheelZoom) || (GlobalJsonConfig.instance == null && GlobalConfig.MOUSEWHEEL_ZOOM)) && Keyboard.pressedKeys[Keyboard.KEY_SHIFT]) { - Camera.ZOOM = clamp(200, 1200, Camera.ZOOM + (diff >= 0 ? 50 : -50)); - } + this.previousRotation = this.currentRotation; + this.currentRotation += arg0.getWheelRotation(); } @OriginalMember(owner = "client!o", name = "a", descriptor = "(Ljava/awt/Component;I)V") diff --git a/client/src/main/java/rt4/Mouse.java b/client/src/main/java/rt4/Mouse.java index 923e69a7..bc759db8 100644 --- a/client/src/main/java/rt4/Mouse.java +++ b/client/src/main/java/rt4/Mouse.java @@ -39,9 +39,9 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis @OriginalMember(owner = "client!dc", name = "W", descriptor = "I") public static volatile int anInt1313 = 0; @OriginalMember(owner = "client!nb", name = "j", descriptor = "I") - public static volatile int anInt4039 = -1; + public static volatile int currentMouseY = -1; @OriginalMember(owner = "client!lh", name = "u", descriptor = "I") - public static volatile int anInt3521 = -1; + public static volatile int currentMouseX = -1; @OriginalMember(owner = "client!sa", name = "Y", descriptor = "I") public static volatile int anInt4973 = 0; @OriginalMember(owner = "client!wi", name = "W", descriptor = "I") @@ -50,8 +50,6 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis public static long prevClickTime = 0L; @OriginalMember(owner = "client!wl", name = "u", descriptor = "I") public static int anInt5895 = 0; - public int mouseWheelX; - public int mouseWheelY; @OriginalMember(owner = "client!sc", name = "a", descriptor = "(ILjava/awt/Component;)V") public static void stop(@OriginalArg(1) Component arg0) { @@ -76,8 +74,8 @@ public static void loop() { @Pc(2) Mouse local2 = instance; synchronized (instance) { pressedButton = anInt1759; - lastMouseX = anInt3521; - lastMouseY = anInt4039; + lastMouseX = currentMouseX; + lastMouseY = currentMouseY; clickButton = anInt1313; clickX = anInt1034; anInt2467++; @@ -112,8 +110,8 @@ public static void setIdleLoops(@OriginalArg(1) int arg0) { public final synchronized void mouseMoved(@OriginalArg(0) MouseEvent arg0) { if (instance != null) { anInt2467 = 0; - anInt3521 = arg0.getX(); - anInt4039 = arg0.getY(); + currentMouseX = arg0.getX(); + currentMouseY = arg0.getY(); } } @@ -130,21 +128,13 @@ public final synchronized void focusLost(@OriginalArg(0) FocusEvent arg0) { public final synchronized void mouseDragged(@OriginalArg(0) MouseEvent event) { int x = event.getX(); int y = event.getY(); - if (SwingUtilities.isMiddleMouseButton(event)) { - int accelX = this.mouseWheelX - x; - int accelY = this.mouseWheelY - y; - this.mouseWheelX = x; - this.mouseWheelY = y; - Camera.yawTarget += accelX * 2; - Camera.pitchTarget -= accelY * 2; - Camera.clampCameraAngle(); - return; - } + + if (SwingUtilities.isMiddleMouseButton(event)) return; if (instance != null) { anInt2467 = 0; - anInt3521 = x; - anInt4039 = y; + currentMouseX = x; + currentMouseY = y; } } @@ -184,8 +174,6 @@ public final void focusGained(@OriginalArg(0) FocusEvent arg0) { @Override public final synchronized void mousePressed(@OriginalArg(0) MouseEvent event) { if (SwingUtilities.isMiddleMouseButton(event)) { - this.mouseWheelX = event.getX(); - this.mouseWheelY = event.getY(); return; } @@ -219,8 +207,8 @@ public final synchronized void mousePressed(@OriginalArg(0) MouseEvent event) { public final synchronized void mouseExited(@OriginalArg(0) MouseEvent arg0) { if (instance != null) { anInt2467 = 0; - anInt3521 = -1; - anInt4039 = -1; + currentMouseX = -1; + currentMouseY = -1; } } @@ -229,8 +217,8 @@ public final synchronized void mouseExited(@OriginalArg(0) MouseEvent arg0) { public final synchronized void mouseEntered(@OriginalArg(0) MouseEvent arg0) { if (instance != null) { anInt2467 = 0; - anInt3521 = arg0.getX(); - anInt4039 = arg0.getY(); + currentMouseX = arg0.getX(); + currentMouseY = arg0.getY(); } } } diff --git a/client/src/main/java/rt4/client.java b/client/src/main/java/rt4/client.java index eee446db..53d04d63 100644 --- a/client/src/main/java/rt4/client.java +++ b/client/src/main/java/rt4/client.java @@ -218,7 +218,6 @@ 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(); } @@ -1022,6 +1021,7 @@ protected final void mainInit() { if (modeWhere != 0) { //Cheat.displayFps = true; } + PluginRepository.Init(); } @OriginalMember(owner = "client!client", name = "c", descriptor = "(I)V") diff --git a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java index 7d1eff78..1edf1dfc 100644 --- a/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java +++ b/plugin-playground/src/main/java/InterfaceDebugPlugin/plugin.java @@ -18,7 +18,7 @@ public class plugin extends Plugin { private boolean isEnabled; private boolean isVerbose; - private ArrayList activeVarps = new ArrayList<>(); + private final ArrayList activeVarps = new ArrayList<>(); @Override public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) { diff --git a/plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt b/plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt new file mode 100644 index 00000000..526a1268 --- /dev/null +++ b/plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt @@ -0,0 +1,115 @@ +package BasicInputQOL + +import plugin.Plugin +import plugin.annotations.PluginMeta +import plugin.api.* +import rt4.Keyboard +import java.awt.event.* +import javax.swing.SwingUtilities + +@PluginMeta( + author = "Ceikry", + description = "Provides some basic input QOL like scroll zoom, middle click panning, etc.", + version = 1.0 +) +class plugin : Plugin() { + private var cameraDebugEnabled = false + private var mouseDebugEnabled = false + + companion object { + private var lastMouseWheelX = 0 + private var lastMouseWheelY = 0 + private val defaultCameraPYZ = Triple(128.0, 0.0, 600) + } + + override fun Init() { + API.AddMouseListener(MouseCallbacks) + API.AddMouseWheelListener(MouseWheelCallbacks) + } + + override fun ProcessCommand(commandStr: String?, args: Array?) { + commandStr ?: return + if (API.PlayerHasPrivilege(Privileges.JMOD)) { + when(commandStr) { + "::mousedebug" -> mouseDebugEnabled = !mouseDebugEnabled + "::cameradebug" -> cameraDebugEnabled = !cameraDebugEnabled + } + } + } + + override fun Draw(timeDelta: Long) { + if (mouseDebugEnabled) { + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.LEFT, + "Mouse Coords: (${API.GetMouseX()}, ${API.GetMouseY()})", + 10, + 40 + ) + } + if (cameraDebugEnabled) { + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.LEFT, + "Camera: [P=${API.GetCameraPitch()}, Y=${API.GetCameraYaw()}, Z=${API.GetCameraZoom()}]", + 10, + 50 + ) + } + } + + object MouseWheelCallbacks : MouseWheelListener { + override fun mouseWheelMoved(e: MouseWheelEvent?) { + e ?: return + if (API.IsKeyPressed(Keyboard.KEY_SHIFT)) { + val previous = API.GetPreviousMouseWheelRotation() + val current = API.GetMouseWheelRotation() + val diff = current - previous + API.UpdateCameraZoom(diff) + } + } + } + + object MouseCallbacks : MouseAdapter() { + override fun mouseDragged(e: MouseEvent?) { + e ?: return + if (SwingUtilities.isMiddleMouseButton(e)) { + val x = e.x + val y = e.y + val accelX = lastMouseWheelX - x + val accelY = lastMouseWheelY - y + lastMouseWheelX = x + lastMouseWheelY = y + API.UpdateCameraYaw(accelX * 2.0) + API.UpdateCameraPitch(-accelY * 2.0) + } + } + + override fun mouseClicked(e: MouseEvent?) { + e ?: return + + val width = API.GetWindowDimensions().width; + val compassBordersX = intArrayOf(width - 165, width - 125) + val compassBordersY = intArrayOf(0, 45) + + if ( + e.x in compassBordersX[0]..compassBordersX[1] + && e.y in compassBordersY[0]..compassBordersY[1] + ) + { + API.SetCameraPitch(defaultCameraPYZ.first) + API.SetCameraYaw(defaultCameraPYZ.second) + } + } + + override fun mousePressed(e: MouseEvent?) { + e ?: return + if (SwingUtilities.isMiddleMouseButton(e)) { + lastMouseWheelX = e.x + lastMouseWheelY = e.y + } + } + } +} \ No newline at end of file From 2f750e124ad22dcad7821800db38d7a156ef8b95 Mon Sep 17 00:00:00 2001 From: ceikry Date: Sun, 17 Jul 2022 13:56:34 -0500 Subject: [PATCH 16/16] Reimplement menu-related QOL. --- client/src/main/java/plugin/Plugin.java | 7 + .../main/java/plugin/PluginRepository.java | 6 + client/src/main/java/plugin/api/API.java | 10 + .../main/java/plugin/api/MiniMenuAction.java | 51 +++ .../main/java/plugin/api/MiniMenuEntry.java | 81 +++++ .../main/java/plugin/api/MiniMenuType.java | 10 + client/src/main/java/rt4/LoginManager.java | 138 +------ client/src/main/java/rt4/MiniMenu.java | 340 ++++++++++++++---- .../src/main/kotlin/MiniMenuQOL/plugin.kt | 89 +++++ 9 files changed, 531 insertions(+), 201 deletions(-) create mode 100644 client/src/main/java/plugin/api/MiniMenuAction.java create mode 100644 client/src/main/java/plugin/api/MiniMenuEntry.java create mode 100644 client/src/main/java/plugin/api/MiniMenuType.java create mode 100644 plugin-playground/src/main/kotlin/MiniMenuQOL/plugin.kt diff --git a/client/src/main/java/plugin/Plugin.java b/client/src/main/java/plugin/Plugin.java index fd09102f..31123ea9 100644 --- a/client/src/main/java/plugin/Plugin.java +++ b/client/src/main/java/plugin/Plugin.java @@ -1,5 +1,6 @@ package plugin; +import plugin.api.MiniMenuEntry; import rt4.Component; import rt4.Npc; import rt4.Player; @@ -88,4 +89,10 @@ public void OnVarpUpdate(int id, int value) {} * OnLogout is called when the client logs out. This should be used to clear player-relevant plugin state. */ public void OnLogout() {} + + /** + * DrawMiniMenu is called when a MiniMenu entry has been created. + * @param entry the entry + */ + public void DrawMiniMenu(MiniMenuEntry entry) {} } diff --git a/client/src/main/java/plugin/PluginRepository.java b/client/src/main/java/plugin/PluginRepository.java index 901e0797..599aff98 100644 --- a/client/src/main/java/plugin/PluginRepository.java +++ b/client/src/main/java/plugin/PluginRepository.java @@ -1,5 +1,7 @@ package plugin; +import plugin.api.MiniMenuEntry; +import plugin.api.MiniMenuType; import rt4.*; import java.io.File; @@ -128,4 +130,8 @@ public static void OnXPUpdate(int skill, int xp) { public static void OnLogout() { loadedPlugins.values().forEach(Plugin::OnLogout); } + + public static void DrawMiniMenu(MiniMenuEntry entry) { + loadedPlugins.values().forEach((plugin) -> plugin.DrawMiniMenu(entry)); + } } diff --git a/client/src/main/java/plugin/api/API.java b/client/src/main/java/plugin/api/API.java index a4577bd2..ba7efdc6 100644 --- a/client/src/main/java/plugin/api/API.java +++ b/client/src/main/java/plugin/api/API.java @@ -6,6 +6,7 @@ import java.awt.*; import java.awt.event.*; +import java.util.ArrayList; import static rt4.MathUtils.clamp; @@ -195,4 +196,13 @@ public static int GetMouseY() { public static boolean IsKeyPressed(int keycode) { return Keyboard.pressedKeys[keycode]; } + + public static MiniMenuEntry[] GetMiniMenuEntries() { + ArrayList entries = new ArrayList<>(); + for (int i = 0; i < MiniMenu.size; i++) { + if (MiniMenu.opBases[i] == null) continue; + entries.add(new MiniMenuEntry(i)); + } + return entries.toArray(new MiniMenuEntry[]{}); + } } diff --git a/client/src/main/java/plugin/api/MiniMenuAction.java b/client/src/main/java/plugin/api/MiniMenuAction.java new file mode 100644 index 00000000..d1044591 --- /dev/null +++ b/client/src/main/java/plugin/api/MiniMenuAction.java @@ -0,0 +1,51 @@ +package plugin.api; + +import java.util.HashMap; + +public enum MiniMenuAction { + WALK_HERE(60), + NPC_1(17), + NPC_2(16), + NPC_3(4), + NPC_4(19), + NPC_5(2), + NPC_EXAMINE(1007), + PLAYER_1(30), + PLAYER_BLOCK(34), + PLAYER_TRADE(29), + PLAYER_REQ_ASSIST(37), + PLAYER_FOLLOW(31), + PLAYER_5(57), + OBJ_1(47), + OBJ_EQUIP(5), + OBJ_4(35), + OBJ_OPERATE(23), + OBJ_5(58), + OBJ_EXAMINE(1002), + OBJSTACK_1(18), + OBJSTACK_2(20), + LOC_1(42), + LOC_2(50), + LOC_3(49), + LOC_4(46), + LOC_5(1001), + LOC_EXAMINE(1004) + ; + + public final short actionCode; + public static HashMap actionCodeMap = new HashMap<>(); + + MiniMenuAction(int actionCode) { + this.actionCode = (short) actionCode; + } + + static { + for (MiniMenuAction a : values()) { + actionCodeMap.put((int) a.actionCode, a); + } + } + + public static MiniMenuAction forActionCode(short actionCode) { + return actionCodeMap.get((int) actionCode); + } +} diff --git a/client/src/main/java/plugin/api/MiniMenuEntry.java b/client/src/main/java/plugin/api/MiniMenuEntry.java new file mode 100644 index 00000000..cff7f7d0 --- /dev/null +++ b/client/src/main/java/plugin/api/MiniMenuEntry.java @@ -0,0 +1,81 @@ +package plugin.api; + +import rt4.JagString; +import rt4.MiniMenu; + +/** + * Convenience wrapper for mini menu entries + * @author ceikry + */ +public class MiniMenuEntry { + int index; + public MiniMenuEntry(int index) { + this.index = index; + } + + public String getSubject() { + return MiniMenu.opBases[index].toString(); + } + + public void setSubject(String name) { + MiniMenu.opBases[index] = JagString.of(name); + } + + public long getSubjectIndex() { + return MiniMenu.keys[index]; + } + + public MiniMenuType getType() { + if (getSubject().length() < 11) return MiniMenuType.TILE; + + String color = getSubject().substring(5,11); + if (color.equals("00ffff")) return MiniMenuType.LOCATION; + if (color.equals("ffff00")) return MiniMenuType.NPC; + if (color.equals("ffffff")) return MiniMenuType.PLAYER; + if (color.equals("ff9040")) return MiniMenuType.OBJ; + else return MiniMenuType.TILE; + } + + public String getVerb() { + return MiniMenu.ops[index].toString(); + } + + public void setVerb(String verb) { + MiniMenu.ops[index] = JagString.of(verb); + } + + public int getIntArg1() { + return MiniMenu.intArgs1[index]; + } + + public int getIntArg2() { + return MiniMenu.intArgs2[index]; + } + + public int getCursor() { + return MiniMenu.cursors[index]; + } + + public MiniMenuAction getAction() { + int actionCode = MiniMenu.actions[index]; + if (isStrictlySecondary()) actionCode -= 2000; + return MiniMenuAction.forActionCode((short) actionCode); + } + + public short getActionCode() { + return MiniMenu.actions[index]; + } + + public void setAction(MiniMenuAction action) { + MiniMenu.actions[index] = action.actionCode; + } + + public void toggleStrictlySecondary() { + if (isStrictlySecondary()) MiniMenu.actions[index] -= 2000; + else MiniMenu.actions[index] += 2000; + } + + public boolean isStrictlySecondary() { + return MiniMenu.actions[index] >= 2000; + } +} diff --git a/client/src/main/java/plugin/api/MiniMenuType.java b/client/src/main/java/plugin/api/MiniMenuType.java new file mode 100644 index 00000000..5a45741c --- /dev/null +++ b/client/src/main/java/plugin/api/MiniMenuType.java @@ -0,0 +1,10 @@ +package plugin.api; + +public enum MiniMenuType { + NPC, + PLAYER, + LOCATION, + TILE, + OBJ, + OBJSTACK +} diff --git a/client/src/main/java/rt4/LoginManager.java b/client/src/main/java/rt4/LoginManager.java index dc7eff68..4a904266 100644 --- a/client/src/main/java/rt4/LoginManager.java +++ b/client/src/main/java/rt4/LoginManager.java @@ -1448,9 +1448,9 @@ public static void method1841() { MiniMenu.sort(); if (Cs1ScriptRunner.aBoolean108) { if (InterfaceList.aBoolean298) { - method2297(); + MiniMenu.drawB(); } else { - method2744(); + MiniMenu.drawA(); } } else if (aClass13_13 != null) { MiniMenu.method1207(aClass13_13, Cs1ScriptRunner.anInt3484, Cs1ScriptRunner.anInt3260); @@ -1494,140 +1494,6 @@ public static int method4044() { return Cheat.shiftClick && Keyboard.pressedKeys[Keyboard.KEY_SHIFT] && MiniMenu.size > 2 ? MiniMenu.cursors[MiniMenu.size - 2] : MiniMenu.cursors[MiniMenu.size - 1]; } - @OriginalMember(owner = "client!ij", name = "a", descriptor = "(B)V") - public static void method2297() { - @Pc(3) int local3 = InterfaceList.anInt4271; - @Pc(9) int local9 = InterfaceList.anInt5138; - @Pc(11) int local11 = InterfaceList.anInt436; - @Pc(13) int local13 = InterfaceList.anInt761; - if (aClass3_Sub2_Sub1_1 == null || aClass3_Sub2_Sub1_9 == null) { - if (client.js5Archive8.isFileReady(anInt1736) && client.js5Archive8.isFileReady(anInt4073)) { - aClass3_Sub2_Sub1_1 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt1736); - aClass3_Sub2_Sub1_9 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt4073); - if (GlRenderer.enabled) { - if (aClass3_Sub2_Sub1_1 instanceof SoftwareAlphaSprite) { - aClass3_Sub2_Sub1_1 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_1); - } else { - aClass3_Sub2_Sub1_1 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_1); - } - if (aClass3_Sub2_Sub1_9 instanceof SoftwareAlphaSprite) { - aClass3_Sub2_Sub1_9 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_9); - } else { - aClass3_Sub2_Sub1_9 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_9); - } - } - } else if (GlRenderer.enabled) { - GlRaster.fillRectAlpha(local3, local9, local13, 20, anInt1275, 256 - anInt2910); - } else { - SoftwareRaster.fillRectAlpha(local3, local9, local13, 20, anInt1275, 256 - anInt2910); - } - } - @Pc(112) int local112; - @Pc(114) int local114; - if (aClass3_Sub2_Sub1_1 != null && aClass3_Sub2_Sub1_9 != null) { - local112 = local13 / aClass3_Sub2_Sub1_1.width; - for (local114 = 0; local114 < local112; local114++) { - aClass3_Sub2_Sub1_1.render(local114 * aClass3_Sub2_Sub1_1.width + local3, local9); - } - aClass3_Sub2_Sub1_9.render(local3, local9); - aClass3_Sub2_Sub1_9.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_9.width, local9); - } - Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local3 + 3, local9 + 14, anInt4581, -1); - if (GlRenderer.enabled) { - GlRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, anInt1275, 256 - anInt2910); - } else { - SoftwareRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, anInt1275, 256 - anInt2910); - } - local114 = Mouse.lastMouseY; - local112 = Mouse.lastMouseX; - @Pc(203) int local203; - @Pc(219) int local219; - for (local203 = 0; local203 < MiniMenu.size; local203++) { - local219 = (MiniMenu.size - local203 - 1) * 15 + local9 + 35; - if (local3 < local112 && local112 < local3 + local13 && local114 > local219 - 13 && local114 < local219 + 3) { - if (GlRenderer.enabled) { - GlRaster.fillRectAlpha(local3, local219 - 13, local13, 16, anInt5457, 256 - anInt5208); - } else { - SoftwareRaster.fillRectAlpha(local3, local219 - 13, local13, 16, anInt5457, 256 - anInt5208); - } - } - } - if ((aClass3_Sub2_Sub1_8 == null || aClass3_Sub2_Sub1_6 == null || aClass3_Sub2_Sub1_10 == null) && client.js5Archive8.isFileReady(anInt2261) && client.js5Archive8.isFileReady(anInt3324) && client.js5Archive8.isFileReady(anInt5556)) { - aClass3_Sub2_Sub1_8 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt2261); - aClass3_Sub2_Sub1_6 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt3324); - aClass3_Sub2_Sub1_10 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt5556); - if (GlRenderer.enabled) { - if (aClass3_Sub2_Sub1_8 instanceof SoftwareAlphaSprite) { - aClass3_Sub2_Sub1_8 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_8); - } else { - aClass3_Sub2_Sub1_8 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_8); - } - if (aClass3_Sub2_Sub1_6 instanceof SoftwareAlphaSprite) { - aClass3_Sub2_Sub1_6 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_6); - } else { - aClass3_Sub2_Sub1_6 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_6); - } - if (aClass3_Sub2_Sub1_10 instanceof SoftwareAlphaSprite) { - aClass3_Sub2_Sub1_10 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_10); - } else { - aClass3_Sub2_Sub1_10 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_10); - } - } - } - @Pc(418) int local418; - if (aClass3_Sub2_Sub1_8 != null && aClass3_Sub2_Sub1_6 != null && aClass3_Sub2_Sub1_10 != null) { - local203 = local13 / aClass3_Sub2_Sub1_8.width; - for (local219 = 0; local219 < local203; local219++) { - aClass3_Sub2_Sub1_8.render(local3 + aClass3_Sub2_Sub1_8.width * local219, local11 + local9 + -aClass3_Sub2_Sub1_8.height); - } - local219 = (local11 - 20) / aClass3_Sub2_Sub1_6.height; - for (local418 = 0; local418 < local219; local418++) { - aClass3_Sub2_Sub1_6.render(local3, local9 + local418 * aClass3_Sub2_Sub1_6.height + 20); - aClass3_Sub2_Sub1_6.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_6.width, local9 + 20 + local418 * aClass3_Sub2_Sub1_6.height); - } - aClass3_Sub2_Sub1_10.render(local3, local11 + local9 - aClass3_Sub2_Sub1_10.height); - aClass3_Sub2_Sub1_10.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_10.width, local9 - -local11 + -aClass3_Sub2_Sub1_10.height); - } - for (local203 = 0; local203 < MiniMenu.size; local203++) { - local219 = (MiniMenu.size - local203 - 1) * 15 + local9 + 35; - local418 = anInt4581; - if (local3 < local112 && local13 + local3 > local112 && local219 - 13 < local114 && local114 < local219 + 3) { - local418 = anInt5752; - } - Fonts.b12Full.renderLeft(MiniMenu.getOp(local203), local3 + 3, local219, local418, 0); - } - InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761); - } - - @OriginalMember(owner = "client!lf", name = "b", descriptor = "(I)V") - public static void method2744() { - @Pc(3) int local3 = InterfaceList.anInt5138; - @Pc(9) int local9 = InterfaceList.anInt761; - @Pc(11) int local11 = InterfaceList.anInt4271; - @Pc(15) int local15 = InterfaceList.anInt436; - if (GlRenderer.enabled) { - GlRaster.fillRect(local11, local3, local9, local15, 6116423); - GlRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0); - GlRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0); - } else { - SoftwareRaster.fillRect(local11, local3, local9, local15, 6116423); - SoftwareRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0); - SoftwareRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0); - } - Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local11 + 3, local3 + 14, 6116423, -1); - @Pc(96) int local96 = Mouse.lastMouseY; - @Pc(98) int local98 = Mouse.lastMouseX; - for (@Pc(107) int local107 = 0; local107 < MiniMenu.size; local107++) { - @Pc(127) int local127 = (MiniMenu.size - local107 - 1) * 15 + local3 + 31; - @Pc(129) int local129 = 16777215; - if (local11 < local98 && local98 < local11 + local9 && local127 - 13 < local96 && local96 < local127 + 3) { - local129 = 16776960; - } - Fonts.b12Full.renderLeft(MiniMenu.getOp(local107), local11 + 3, local127, local129, 0); - } - InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761); - } - @OriginalMember(owner = "client!gn", name = "a", descriptor = "(ZI)V") public static void method1805(@OriginalArg(0) boolean arg0) { @Pc(7) byte local7; diff --git a/client/src/main/java/rt4/MiniMenu.java b/client/src/main/java/rt4/MiniMenu.java index ecf13278..ed813623 100644 --- a/client/src/main/java/rt4/MiniMenu.java +++ b/client/src/main/java/rt4/MiniMenu.java @@ -3,6 +3,8 @@ import org.openrs2.deob.annotation.OriginalArg; import org.openrs2.deob.annotation.OriginalMember; import org.openrs2.deob.annotation.Pc; +import plugin.PluginRepository; +import plugin.api.MiniMenuEntry; public class MiniMenu { @OriginalMember(owner = "client!df", name = "l", descriptor = "Lclient!na;") @@ -138,6 +140,79 @@ public class MiniMenu { @OriginalMember(owner = "client!ml", name = "Q", descriptor = "I") public static int anInt3953 = 0; + /*********************** + * Action Constants * + ***********************/ + /* Tiles */ + public static final int WALK_HERE = 60; + /* NPCs */ + public static final int NPC_ACTION_1 = 17; + public static final int NPC_ACTION_2 = 16; + public static final int NPC_ACTION_3 = 4; + public static final int NPC_ACTION_4 = 19; + public static final int NPC_ACTION_5 = 2; + public static final int NPC_EXAMINE = 1007; + /* Players */ + public static final int PLAYER_ACTION_1 = 30; + public static final int PLAYER_ACTION_BLOCK = 34; + public static final int PLAYER_ACTION_TRADE = 29; + public static final int PLAYER_REQ_ASSIST_ACTION = 37; + public static final int PLAYER_FOLLOW_ACTION = 31; + public static final int PLAYER_ACTION_5 = 57; + /* Objects */ + public static final int OBJ_ACTION_1 = 47; + public static final int OBJ_EQUIP_ACTION = 5; + public static final int OBJ_ACTION_4 = 35; + public static final int OBJ_OPERATE_ACTION = 23; + public static final int OBJ_ACTION_5 = 58; + public static final int OBJ_EXAMINE = 1002; + public static final int OBJ_PLAYER_ACTION = 1; + public static final int OBJ_OBJSTACK_ACTION = 33; + public static final int OBJ_NPC_ACTION = 26; + public static final int OBJ_LOC_ACTION = 14; + public static final int OBJ_OBJ_ACTION = 40; + /* Object Stacks */ + public static final int OBJSTACK_ACTION_1 = 18; + public static final int OBJSTACK_ACTION_2 = 20; + /* Locations */ + public static final int LOC_ACTION_1 = 42; + public static final int LOC_ACTION_2 = 50; + public static final int LOC_ACTION_3 = 49; + public static final int LOC_ACTION_4 = 46; + public static final int LOC_ACTION_5 = 1001; + public static final int LOC_ACTION_EXAMINE = 1004; + /* Components */ + public static final int COMPONENT_ACTION_CLOSE = 28; + public static final int COMPONENT_OBJSTACK_ACTION = 39; + public static final int OBJ_IN_COMPONENT_ACTION_4 = 43; + public static final int COMPONENT_LOC_ACTION = 38; + public static final int LOGOUT_ACTION_2 = 59; + public static final int LOGOUT_ACTION = 51; + public static final int OBJ_IN_COMPONENT_ACTION_1 = 25; + public static final int COMPONENT_PLAYER_ACTION = 15; + public static final int COMPONENT_OBJ_ACTION = 3; + public static final int COMPONENT_NPC_ACTION = 45; + public static final int OBJ_EXAMINE_IN_COMPONENT = 1006; + /* Unknown/Unidentified */ + public static final int UNKNOWN_13 = 13; + public static final int UNKNOWN_22 = 22; + public static final int UNKNOWN_48 = 48; + public static final int UNKNOWN_12 = 12; + public static final int UNKNOWN_36 = 36; + public static final int UNKNOWN_6 = 6; + public static final int UNKNOWN_24 = 24; + public static final int UNKNOWN_7 = 7; + public static final int UNKNOWN_8 = 8; + public static final int UNKNOWN_11 = 11; + public static final int UNKNOWN_32 = 32; + public static final int UNKNOWN_21 = 21; + public static final int UNKNOWN_9 = 9; + public static final int UNKNOWN_1003 = 1003; + public static final int UNKNOWN_41 = 41; + public static final int UNKNOWN_10 = 10; + public static final int UNKNOWN_44 = 44; + + @OriginalMember(owner = "client!va", name = "a", descriptor = "(IZILclient!be;)V") public static void addComponentEntries(@OriginalArg(0) int arg0, @OriginalArg(2) int arg1, @OriginalArg(3) Component component) { if (component.buttonType == 1) { @@ -292,17 +367,18 @@ public static void addComponentEntries(@OriginalArg(0) int arg0, @OriginalArg(2) } @OriginalMember(owner = "client!hj", name = "a", descriptor = "(IJBLclient!na;ISLclient!na;I)V") - public static void add(@OriginalArg(0) int cursor, @OriginalArg(1) long arg1, @OriginalArg(3) JagString arg2, @OriginalArg(4) int arg3, @OriginalArg(5) short arg4, @OriginalArg(6) JagString arg5, @OriginalArg(7) int arg6) { + public static void add(@OriginalArg(0) int cursor, @OriginalArg(1) long arg1, @OriginalArg(3) JagString opName, @OriginalArg(4) int arg3, @OriginalArg(5) short arg4, @OriginalArg(6) JagString arg5, @OriginalArg(7) int arg6) { if (Cs1ScriptRunner.aBoolean108 || size >= 500) { return; } ops[size] = arg5; - opBases[size] = arg2; + opBases[size] = opName; cursors[size] = cursor == -1 ? anInt1092 : cursor; actions[size] = arg4; keys[size] = arg1; intArgs1[size] = arg3; intArgs2[size] = arg6; + PluginRepository.DrawMiniMenu(new MiniMenuEntry(size)); size++; } @@ -367,14 +443,14 @@ public static void doAction(@OriginalArg(1) int arg0) { } @Pc(15) int local15 = intArgs1[arg0]; @Pc(19) int local19 = intArgs2[arg0]; - @Pc(23) int local23 = actions[arg0]; - if (local23 >= 2000) { - local23 -= 2000; + @Pc(23) int actionCode = actions[arg0]; + if (actionCode >= 2000) { + actionCode -= 2000; } @Pc(31) long local31 = keys[arg0]; @Pc(36) int local36 = (int) keys[arg0]; @Pc(43) Player local43; - if (local23 == 31) { + if (actionCode == PLAYER_FOLLOW_ACTION) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -386,14 +462,14 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } } - if (local23 == 46) { + if (actionCode == LOC_ACTION_4) { PathFinder.findPathToLoc(local31, local19, local15); Protocol.outboundBuffer.p1isaac(247); Protocol.outboundBuffer.ip2(Camera.originZ + local19); Protocol.outboundBuffer.ip2add(local15 + Camera.originX); Protocol.outboundBuffer.p2(Integer.MAX_VALUE & (int) (local31 >>> 32)); } - if (local23 == 40) { + if (actionCode == OBJ_OBJ_ACTION) { Protocol.outboundBuffer.p1isaac(27); Protocol.outboundBuffer.p2(anInt4370); Protocol.outboundBuffer.ip4(local19); @@ -406,7 +482,7 @@ public static void doAction(@OriginalArg(1) int arg0) { anInt5444 = local15; } @Pc(192) Npc local192; - if (local23 == 19) { + if (actionCode == NPC_ACTION_4) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -418,7 +494,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(local36); } } - if (local23 == 17) { + if (actionCode == NPC_ACTION_1) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -430,7 +506,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2(local36); } } - if (local23 == 44) { + if (actionCode == UNKNOWN_44) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -442,7 +518,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2(local36); } } - if (local23 == 58) { + if (actionCode == OBJ_ACTION_5) { Protocol.outboundBuffer.p1isaac(135); Protocol.outboundBuffer.p2add(local36); Protocol.outboundBuffer.p2add(local15); @@ -451,17 +527,17 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 42) { + if (actionCode == LOC_ACTION_1) { PathFinder.findPathToLoc(local31, local19, local15); Protocol.outboundBuffer.p1isaac(254); Protocol.outboundBuffer.ip2(local15 + Camera.originX); Protocol.outboundBuffer.p2add((int) (local31 >>> 32) & Integer.MAX_VALUE); Protocol.outboundBuffer.p2(local19 + Camera.originZ); } - if (local23 == 28) { + if (actionCode == COMPONENT_ACTION_CLOSE) { ClientProt.closeWidget(); } - if (local23 == 45) { + if (actionCode == COMPONENT_NPC_ACTION) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -476,7 +552,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } } @Pc(560) boolean local560; - if (local23 == 18) { + if (actionCode == OBJSTACK_ACTION_1) { if (client.game == 1) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); } else { @@ -494,14 +570,14 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(local36); Protocol.outboundBuffer.ip2add(local19 + Camera.originZ); } - if (local23 == 1001) { + if (actionCode == LOC_ACTION_5) { PathFinder.findPathToLoc(local31, local19, local15); Protocol.outboundBuffer.p1isaac(170); Protocol.outboundBuffer.ip2add(Integer.MAX_VALUE & (int) (local31 >>> 32)); Protocol.outboundBuffer.ip2add(local15 + Camera.originX); Protocol.outboundBuffer.ip2add(local19 + Camera.originZ); } - if (local23 == 1002) { + if (actionCode == OBJ_EXAMINE) { Cross.type = 2; Cross.x = Mouse.clickX; Cross.y = Mouse.clickY; @@ -510,7 +586,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } @Pc(693) Component local693; - if (local23 == 1006) { + if (actionCode == OBJ_EXAMINE_IN_COMPONENT) { local693 = InterfaceList.getComponent(local19); if (local693 == null || local693.objCounts[local15] < 100000) { Protocol.outboundBuffer.p1isaac(92); @@ -522,7 +598,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 60) { + if (actionCode == WALK_HERE) { if (local36 == 0) { method3556(Player.plane, local15, local19); } else if (local36 == 1) { @@ -543,7 +619,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } } } - if (local23 == 1007) { + if (actionCode == NPC_EXAMINE) { Cross.milliseconds = 0; Cross.type = 2; Cross.y = Mouse.clickY; @@ -560,7 +636,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } } } - if (local23 == 47) { + if (actionCode == OBJ_ACTION_1) { Protocol.outboundBuffer.p1isaac(156); Protocol.outboundBuffer.ip2add(local15); Protocol.outboundBuffer.p2add(local36); @@ -569,7 +645,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 3) { + if (actionCode == COMPONENT_OBJ_ACTION) { Protocol.outboundBuffer.p1isaac(253); Protocol.outboundBuffer.ip4(anInt2512); Protocol.outboundBuffer.ip2add(local15); @@ -580,7 +656,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 10) { + if (actionCode == UNKNOWN_10) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -592,19 +668,19 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2(local36); } } - if (local23 == 41 && Cs1ScriptRunner.aClass13_10 == null) { + if (actionCode == UNKNOWN_41 && Cs1ScriptRunner.aClass13_10 == null) { method10(local15, local19); Cs1ScriptRunner.aClass13_10 = InterfaceList.method1418(local19, local15); InterfaceList.redraw(Cs1ScriptRunner.aClass13_10); } - if (local23 == 49) { + if (actionCode == LOC_ACTION_3) { PathFinder.findPathToLoc(local31, local19, local15); Protocol.outboundBuffer.p1isaac(84); Protocol.outboundBuffer.ip2add(Integer.MAX_VALUE & (int) (local31 >>> 32)); Protocol.outboundBuffer.ip2add(Camera.originZ + local19); Protocol.outboundBuffer.ip2(local15 + Camera.originX); } - if (local23 == 23) { + if (actionCode == OBJ_OPERATE_ACTION) { Protocol.outboundBuffer.p1isaac(206); Protocol.outboundBuffer.p2add(local36); Protocol.outboundBuffer.ip2(local15); @@ -613,7 +689,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 14 && PathFinder.findPathToLoc(local31, local19, local15)) { + if (actionCode == OBJ_LOC_ACTION && PathFinder.findPathToLoc(local31, local19, local15)) { Protocol.outboundBuffer.p1isaac(134); Protocol.outboundBuffer.p2add(Camera.originX + local15); Protocol.outboundBuffer.p2(anInt4997); @@ -622,7 +698,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.mp4(MiniMap.anInt5062); Protocol.outboundBuffer.p2add((int) (local31 >>> 32) & Integer.MAX_VALUE); } - if (local23 == 37) { + if (actionCode == PLAYER_REQ_ASSIST_ACTION) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -634,10 +710,10 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } } - if (local23 == 9 || local23 == 1003) { + if (actionCode == UNKNOWN_9 || actionCode == UNKNOWN_1003) { ClientProt.method4512(opBases[arg0], local15, local36, local19); } - if (local23 == 5) { + if (actionCode == OBJ_EQUIP_ACTION) { Protocol.outboundBuffer.p1isaac(55); Protocol.outboundBuffer.ip2(local36); Protocol.outboundBuffer.p2add(local15); @@ -646,7 +722,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 21) { + if (actionCode == UNKNOWN_21) { if (client.game == 1) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); } else { @@ -664,7 +740,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2(Camera.originX + local15); Protocol.outboundBuffer.ip2add(Camera.originZ + local19); } - if (local23 == 4) { + if (actionCode == NPC_ACTION_3) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -676,7 +752,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2add(local36); } } - if (local23 == 32) { + if (actionCode == UNKNOWN_32) { local693 = InterfaceList.method1418(local19, local15); if (local693 != null) { method1294(); @@ -695,7 +771,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } return; } - if (local23 == 29) { + if (actionCode == PLAYER_ACTION_TRADE) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -707,7 +783,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } } - if (local23 == 35) { + if (actionCode == OBJ_ACTION_4) { Protocol.outboundBuffer.p1isaac(161); Protocol.outboundBuffer.ip4(local19); Protocol.outboundBuffer.ip2add(local36); @@ -716,7 +792,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 15) { + if (actionCode == COMPONENT_PLAYER_ACTION) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -730,7 +806,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } } - if (local23 == 34) { + if (actionCode == PLAYER_ACTION_BLOCK) { if (client.game == 1) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); } else { @@ -748,7 +824,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(local15 + Camera.originX); Protocol.outboundBuffer.ip2add(local36); } - if (local23 == 25) { + if (actionCode == OBJ_IN_COMPONENT_ACTION_1) { Protocol.outboundBuffer.p1isaac(81); Protocol.outboundBuffer.p2add(local15); Protocol.outboundBuffer.p2(local36); @@ -757,7 +833,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 2) { + if (actionCode == NPC_ACTION_5) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -770,7 +846,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } } @Pc(1955) int local1955; - if (local23 == 51) { + if (actionCode == LOGOUT_ACTION) { Protocol.outboundBuffer.p1isaac(10); Protocol.outboundBuffer.p4(local19); local693 = InterfaceList.getComponent(local19); @@ -782,7 +858,7 @@ public static void doAction(@OriginalArg(1) int arg0) { } } } - if (local23 == 26) { + if (actionCode == OBJ_NPC_ACTION) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -797,7 +873,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(anInt4997); } } - if (local23 == 59) { + if (actionCode == LOGOUT_ACTION_2) { Protocol.outboundBuffer.p1isaac(10); Protocol.outboundBuffer.p4(local19); local693 = InterfaceList.getComponent(local19); @@ -807,7 +883,7 @@ public static void doAction(@OriginalArg(1) int arg0) { VarpDomain.refreshMagicVarp(local1955); } } - if (local23 == 33) { + if (actionCode == OBJ_OBJSTACK_ACTION) { local560 = PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 0, false, 0, local15, 0, 0, 2, local19, PlayerList.self.movementQueueX[0]); if (!local560) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); @@ -824,7 +900,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(Camera.originZ + local19); Protocol.outboundBuffer.mp4(MiniMap.anInt5062); } - if (local23 == 1004) { + if (actionCode == LOC_ACTION_EXAMINE) { Cross.milliseconds = 0; Cross.x = Mouse.clickX; Cross.type = 2; @@ -832,7 +908,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p1isaac(94); Protocol.outboundBuffer.ip2add(local36); } - if (local23 == 11) { + if (actionCode == UNKNOWN_11) { if (local36 == 0) { anInt3096 = 1; method3556(Player.plane, local15, local19); @@ -844,7 +920,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2add(local19 + Camera.originZ); } } - if (local23 == 8) { + if (actionCode == UNKNOWN_8) { local693 = InterfaceList.getComponent(local19); @Pc(2287) boolean local2287 = true; if (local693.clientCode > 0) { @@ -855,7 +931,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p4(local19); } } - if (local23 == 1) { + if (actionCode == OBJ_PLAYER_ACTION) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -870,7 +946,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.mp4(MiniMap.anInt5062); } } - if (local23 == 7) { + if (actionCode == UNKNOWN_7) { Protocol.outboundBuffer.p1isaac(85); Protocol.outboundBuffer.imp4(local19); Protocol.outboundBuffer.p2(local15); @@ -879,7 +955,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 24) { + if (actionCode == UNKNOWN_24) { if (client.game == 1) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); } else { @@ -897,7 +973,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); Protocol.outboundBuffer.ip2(Camera.originZ + local19); } - if (local23 == 38 && PathFinder.findPathToLoc(local31, local19, local15)) { + if (actionCode == COMPONENT_LOC_ACTION && PathFinder.findPathToLoc(local31, local19, local15)) { Protocol.outboundBuffer.p1isaac(233); Protocol.outboundBuffer.ip2add(local19 + Camera.originZ); Protocol.outboundBuffer.p2add(Camera.originX + local15); @@ -905,7 +981,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.imp4(anInt2512); Protocol.outboundBuffer.p2add((int) (local31 >>> 32) & Integer.MAX_VALUE); } - if (local23 == 13) { + if (actionCode == UNKNOWN_13) { Protocol.outboundBuffer.p1isaac(6); Protocol.outboundBuffer.p4(local19); Protocol.outboundBuffer.p2add(local15); @@ -914,7 +990,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 57) { + if (actionCode == PLAYER_ACTION_5) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -926,7 +1002,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2add(local36); } } - if (local23 == 22) { + if (actionCode == UNKNOWN_22) { method1294(); local693 = InterfaceList.getComponent(local19); MiniMap.anInt5062 = local19; @@ -940,14 +1016,14 @@ public static void doAction(@OriginalArg(1) int arg0) { } return; } - if (local23 == 50) { + if (actionCode == LOC_ACTION_2) { PathFinder.findPathToLoc(local31, local19, local15); Protocol.outboundBuffer.p1isaac(194); Protocol.outboundBuffer.ip2add(local19 + Camera.originZ); Protocol.outboundBuffer.ip2(Camera.originX + local15); Protocol.outboundBuffer.p2((int) (local31 >>> 32) & Integer.MAX_VALUE); } - if (local23 == 48) { + if (actionCode == UNKNOWN_48) { Protocol.outboundBuffer.p1isaac(154); Protocol.outboundBuffer.ip2(local15); Protocol.outboundBuffer.imp4(local19); @@ -956,7 +1032,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 30) { + if (actionCode == PLAYER_ACTION_1) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -968,7 +1044,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local36); } } - if (local23 == 43) { + if (actionCode == OBJ_IN_COMPONENT_ACTION_4) { Protocol.outboundBuffer.p1isaac(153); Protocol.outboundBuffer.ip4(local19); Protocol.outboundBuffer.ip2(local15); @@ -977,7 +1053,7 @@ public static void doAction(@OriginalArg(1) int arg0) { pressedInventoryComponent = InterfaceList.getComponent(local19); anInt5444 = local15; } - if (local23 == 39) { + if (actionCode == COMPONENT_OBJSTACK_ACTION) { local560 = PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 0, false, 0, local15, 0, 0, 2, local19, PlayerList.self.movementQueueX[0]); if (!local560) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); @@ -993,14 +1069,14 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.ip2add(local15 + Camera.originX); Protocol.outboundBuffer.ip2(anInt506); } - if (local23 == 12) { + if (actionCode == UNKNOWN_12) { Protocol.outboundBuffer.p1isaac(82); Protocol.outboundBuffer.p2(anInt506); Protocol.outboundBuffer.imp4(local19); Protocol.outboundBuffer.p4(anInt2512); Protocol.outboundBuffer.ip2add(local15); } - if (local23 == 36) { + if (actionCode == UNKNOWN_36) { if (local36 == 0) { Protocol.anInt4422 = 1; method3556(Player.plane, local15, local19); @@ -1012,7 +1088,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(local15 + Camera.originX); } } - if (local23 == 6) { + if (actionCode == UNKNOWN_6) { local43 = PlayerList.players[local36]; if (local43 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local43.movementQueueX[0], 1, 0, 2, local43.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -1024,7 +1100,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(local36); } } - if (local23 == 20) { + if (actionCode == OBJSTACK_ACTION_2) { if (client.game == 1) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local15, 1, 0, 2, local19, PlayerList.self.movementQueueX[0]); } else { @@ -1042,7 +1118,7 @@ public static void doAction(@OriginalArg(1) int arg0) { Protocol.outboundBuffer.p2(Camera.originX + local15); Protocol.outboundBuffer.ip2(Camera.originZ + local19); } - if (local23 == 16) { + if (actionCode == NPC_ACTION_2) { local192 = NpcList.npcs[local36]; if (local192 != null) { PathFinder.findPath(PlayerList.self.movementQueueZ[0], 0, 1, false, 0, local192.movementQueueX[0], 1, 0, 2, local192.movementQueueZ[0], PlayerList.self.movementQueueX[0]); @@ -1379,7 +1455,7 @@ public static void addNpcEntries(@OriginalArg(0) NpcType arg0, @OriginalArg(1) i if (local129[local140] != null && local129[local140].equalsIgnoreCase(LocalizedText.ATTACK)) { @Pc(271) short local271 = 0; if (arg0.combatLevel > PlayerList.self.combatLevel) { - local271 = 2000; + local271 = 2000; //THIS iS FOR LEFT CLICK ATTACK } @Pc(281) short local281 = 0; if (local140 == 0) { @@ -1603,4 +1679,138 @@ public static void method10(@OriginalArg(0) int arg0, @OriginalArg(2) int arg1) Protocol.outboundBuffer.imp4(arg1); Protocol.outboundBuffer.ip2(arg0); } + + @OriginalMember(owner = "client!lf", name = "b", descriptor = "(I)V") + public static void drawA() { + @Pc(3) int local3 = InterfaceList.anInt5138; + @Pc(9) int local9 = InterfaceList.anInt761; + @Pc(11) int local11 = InterfaceList.anInt4271; + @Pc(15) int local15 = InterfaceList.anInt436; + if (GlRenderer.enabled) { + GlRaster.fillRect(local11, local3, local9, local15, 6116423); + GlRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0); + GlRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0); + } else { + SoftwareRaster.fillRect(local11, local3, local9, local15, 6116423); + SoftwareRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0); + SoftwareRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0); + } + Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local11 + 3, local3 + 14, 6116423, -1); + @Pc(96) int local96 = Mouse.lastMouseY; + @Pc(98) int local98 = Mouse.lastMouseX; + for (@Pc(107) int local107 = 0; local107 < size; local107++) { + @Pc(127) int local127 = (size - local107 - 1) * 15 + local3 + 31; + @Pc(129) int color = 16777215; //WHITE + if (local11 < local98 && local98 < local11 + local9 && local127 - 13 < local96 && local96 < local127 + 3) { + color = 16776960; //YELLOW + } + Fonts.b12Full.renderLeft(getOp(local107), local11 + 3, local127, color, 0); + } + InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761); + } + + @OriginalMember(owner = "client!ij", name = "a", descriptor = "(B)V") + public static void drawB() { + @Pc(3) int local3 = InterfaceList.anInt4271; + @Pc(9) int local9 = InterfaceList.anInt5138; + @Pc(11) int local11 = InterfaceList.anInt436; + @Pc(13) int local13 = InterfaceList.anInt761; + if (LoginManager.aClass3_Sub2_Sub1_1 == null || LoginManager.aClass3_Sub2_Sub1_9 == null) { + if (client.js5Archive8.isFileReady(LoginManager.anInt1736) && client.js5Archive8.isFileReady(LoginManager.anInt4073)) { + LoginManager.aClass3_Sub2_Sub1_1 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, LoginManager.anInt1736); + LoginManager.aClass3_Sub2_Sub1_9 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, LoginManager.anInt4073); + if (GlRenderer.enabled) { + if (LoginManager.aClass3_Sub2_Sub1_1 instanceof SoftwareAlphaSprite) { + LoginManager.aClass3_Sub2_Sub1_1 = new GlAlphaSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_1); + } else { + LoginManager.aClass3_Sub2_Sub1_1 = new GlSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_1); + } + if (LoginManager.aClass3_Sub2_Sub1_9 instanceof SoftwareAlphaSprite) { + LoginManager.aClass3_Sub2_Sub1_9 = new GlAlphaSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_9); + } else { + LoginManager.aClass3_Sub2_Sub1_9 = new GlSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_9); + } + } + } else if (GlRenderer.enabled) { + GlRaster.fillRectAlpha(local3, local9, local13, 20, LoginManager.anInt1275, 256 - LoginManager.anInt2910); + } else { + SoftwareRaster.fillRectAlpha(local3, local9, local13, 20, LoginManager.anInt1275, 256 - LoginManager.anInt2910); + } + } + @Pc(112) int local112; + @Pc(114) int local114; + if (LoginManager.aClass3_Sub2_Sub1_1 != null && LoginManager.aClass3_Sub2_Sub1_9 != null) { + local112 = local13 / LoginManager.aClass3_Sub2_Sub1_1.width; + for (local114 = 0; local114 < local112; local114++) { + LoginManager.aClass3_Sub2_Sub1_1.render(local114 * LoginManager.aClass3_Sub2_Sub1_1.width + local3, local9); + } + LoginManager.aClass3_Sub2_Sub1_9.render(local3, local9); + LoginManager.aClass3_Sub2_Sub1_9.renderHorizontalFlip(local3 + local13 - LoginManager.aClass3_Sub2_Sub1_9.width, local9); + } + Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local3 + 3, local9 + 14, LoginManager.anInt4581, -1); + if (GlRenderer.enabled) { + GlRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, LoginManager.anInt1275, 256 - LoginManager.anInt2910); + } else { + SoftwareRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, LoginManager.anInt1275, 256 - LoginManager.anInt2910); + } + local114 = Mouse.lastMouseY; + local112 = Mouse.lastMouseX; + @Pc(203) int local203; + @Pc(219) int local219; + for (local203 = 0; local203 < size; local203++) { + local219 = (size - local203 - 1) * 15 + local9 + 35; + if (local3 < local112 && local112 < local3 + local13 && local114 > local219 - 13 && local114 < local219 + 3) { + if (GlRenderer.enabled) { + GlRaster.fillRectAlpha(local3, local219 - 13, local13, 16, LoginManager.anInt5457, 256 - LoginManager.anInt5208); + } else { + SoftwareRaster.fillRectAlpha(local3, local219 - 13, local13, 16, LoginManager.anInt5457, 256 - LoginManager.anInt5208); + } + } + } + if ((LoginManager.aClass3_Sub2_Sub1_8 == null || LoginManager.aClass3_Sub2_Sub1_6 == null || LoginManager.aClass3_Sub2_Sub1_10 == null) && client.js5Archive8.isFileReady(LoginManager.anInt2261) && client.js5Archive8.isFileReady(LoginManager.anInt3324) && client.js5Archive8.isFileReady(LoginManager.anInt5556)) { + LoginManager.aClass3_Sub2_Sub1_8 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, LoginManager.anInt2261); + LoginManager.aClass3_Sub2_Sub1_6 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, LoginManager.anInt3324); + LoginManager.aClass3_Sub2_Sub1_10 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, LoginManager.anInt5556); + if (GlRenderer.enabled) { + if (LoginManager.aClass3_Sub2_Sub1_8 instanceof SoftwareAlphaSprite) { + LoginManager.aClass3_Sub2_Sub1_8 = new GlAlphaSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_8); + } else { + LoginManager.aClass3_Sub2_Sub1_8 = new GlSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_8); + } + if (LoginManager.aClass3_Sub2_Sub1_6 instanceof SoftwareAlphaSprite) { + LoginManager.aClass3_Sub2_Sub1_6 = new GlAlphaSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_6); + } else { + LoginManager.aClass3_Sub2_Sub1_6 = new GlSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_6); + } + if (LoginManager.aClass3_Sub2_Sub1_10 instanceof SoftwareAlphaSprite) { + LoginManager.aClass3_Sub2_Sub1_10 = new GlAlphaSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_10); + } else { + LoginManager.aClass3_Sub2_Sub1_10 = new GlSprite((SoftwareSprite) LoginManager.aClass3_Sub2_Sub1_10); + } + } + } + @Pc(418) int local418; + if (LoginManager.aClass3_Sub2_Sub1_8 != null && LoginManager.aClass3_Sub2_Sub1_6 != null && LoginManager.aClass3_Sub2_Sub1_10 != null) { + local203 = local13 / LoginManager.aClass3_Sub2_Sub1_8.width; + for (local219 = 0; local219 < local203; local219++) { + LoginManager.aClass3_Sub2_Sub1_8.render(local3 + LoginManager.aClass3_Sub2_Sub1_8.width * local219, local11 + local9 + -LoginManager.aClass3_Sub2_Sub1_8.height); + } + local219 = (local11 - 20) / LoginManager.aClass3_Sub2_Sub1_6.height; + for (local418 = 0; local418 < local219; local418++) { + LoginManager.aClass3_Sub2_Sub1_6.render(local3, local9 + local418 * LoginManager.aClass3_Sub2_Sub1_6.height + 20); + LoginManager.aClass3_Sub2_Sub1_6.renderHorizontalFlip(local3 + local13 - LoginManager.aClass3_Sub2_Sub1_6.width, local9 + 20 + local418 * LoginManager.aClass3_Sub2_Sub1_6.height); + } + LoginManager.aClass3_Sub2_Sub1_10.render(local3, local11 + local9 - LoginManager.aClass3_Sub2_Sub1_10.height); + LoginManager.aClass3_Sub2_Sub1_10.renderHorizontalFlip(local3 + local13 - LoginManager.aClass3_Sub2_Sub1_10.width, local9 - -local11 + -LoginManager.aClass3_Sub2_Sub1_10.height); + } + for (local203 = 0; local203 < size; local203++) { + local219 = (size - local203 - 1) * 15 + local9 + 35; + local418 = LoginManager.anInt4581; + if (local3 < local112 && local13 + local3 > local112 && local219 - 13 < local114 && local114 < local219 + 3) { + local418 = LoginManager.anInt5752; + } + Fonts.b12Full.renderLeft(getOp(local203), local3 + 3, local219, local418, 0); + } + InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761); + } } diff --git a/plugin-playground/src/main/kotlin/MiniMenuQOL/plugin.kt b/plugin-playground/src/main/kotlin/MiniMenuQOL/plugin.kt new file mode 100644 index 00000000..d19124bd --- /dev/null +++ b/plugin-playground/src/main/kotlin/MiniMenuQOL/plugin.kt @@ -0,0 +1,89 @@ +package MiniMenuQOL + +import plugin.Plugin +import plugin.annotations.PluginMeta +import plugin.api.* +import rt4.NpcList +import rt4.NpcType +import rt4.ObjType +import rt4.ObjTypeList + +@PluginMeta( + author = "Ceikry", + description = "Provides debug and some basic QOL for the MiniMenu", + version = 1.0 +) +class plugin : Plugin() { + private var debugEnabled = false + + override fun ProcessCommand(commandStr: String?, args: Array?) { + when (commandStr) { + "::mmdebug" -> debugEnabled = !debugEnabled + } + } + + override fun Draw(timeDelta: Long) { + if (!debugEnabled) return + val sb = StringBuilder() + val entries = API.GetMiniMenuEntries() + val strings = ArrayList() + + for (entry in entries) { + sb.append(entry.subject) + sb.append(" - ") + sb.append(entry.verb) + sb.append("(") + sb.append(entry.actionCode) + sb.append(")") + strings.add(sb.toString()) + sb.clear() + } + + if (debugEnabled) { + var screenY = 50 + for (string in strings) { + API.DrawText( + FontType.SMALL, + FontColor.YELLOW, + TextModifier.LEFT, + string, + 10, + screenY + ) + screenY += 10 + } + } + } + + override fun DrawMiniMenu(entry: MiniMenuEntry) { + when (entry.type) { + MiniMenuType.NPC -> { + val index = entry.subjectIndex + val npc = NpcList.npcs[index.toInt()] + val type = npc.type + if (debugEnabled && entry.verb.equals("examine", true)) + entry.subject = entry.subject + "(I:${entry.subjectIndex},ID:${type.id})" + if (entry.isStrictlySecondary) + entry.toggleStrictlySecondary() + } + + MiniMenuType.LOCATION -> { + if (debugEnabled && entry.verb.equals("examine", true)) + entry.subject = entry.subject + "(ID:${entry.subjectIndex})" + } + + MiniMenuType.PLAYER -> { + if (debugEnabled && entry.verb.equals("follow", true)) + entry.subject = entry.subject + "(I:${entry.subjectIndex})" + } + + MiniMenuType.OBJ -> { + val def = ObjTypeList.get(entry.subjectIndex.toInt()) + if (debugEnabled) + entry.subject = entry.subject + "(ID:${entry.subjectIndex})" + if (def.cost >= 1000) + entry.subject = "" + entry.subject.substring(12) + } + } + } +} \ No newline at end of file