diff --git a/client/config.json b/client/config.json index 7f0f5fd..5222e05 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 2bf9c9f..a4577bd 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.DisplayMode; 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 class API { 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 6c09d0d..dd06da5 100644 --- a/client/src/main/java/rt4/JavaMouseWheel.java +++ b/client/src/main/java/rt4/JavaMouseWheel.java @@ -15,7 +15,8 @@ import static rt4.MathUtils.clamp; 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 class JavaMouseWheel extends MouseWheel implements MouseWheelListen @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 923e69a..bc759db 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 final class Mouse implements MouseListener, MouseMotionListener, FocusLis @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 final class Mouse implements MouseListener, MouseMotionListener, FocusLis 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 class Mouse implements MouseListener, MouseMotionListener, FocusLis 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 class Mouse implements MouseListener, MouseMotionListener, FocusLis @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 class Mouse implements MouseListener, MouseMotionListener, FocusLis 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 class Mouse implements MouseListener, MouseMotionListener, FocusLis 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 eee446d..53d04d6 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 @@ public final class client extends GameShell { 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 7d1eff7..1edf1df 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 0000000..526a126 --- /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