mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2025-12-09 16:45:46 -07:00
Reimplemented all input QOL changes as a plugin
This commit is contained in:
parent
3e12a9115d
commit
4377d4958e
7 changed files with 219 additions and 40 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"ip_management": "play.2009scape.org",
|
"ip_management": "test.2009scape.org",
|
||||||
"ip_address": "play.2009scape.org",
|
"ip_address": "test.2009scape.org",
|
||||||
"world": 1,
|
"world": 1,
|
||||||
"server_port": 43594,
|
"server_port": 43594,
|
||||||
"wl_port": 43595,
|
"wl_port": 43595,
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@ import rt4.DisplayMode;
|
||||||
import rt4.Font;
|
import rt4.Font;
|
||||||
|
|
||||||
import java.awt.*;
|
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 :)
|
* 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);
|
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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ import static rt4.MathUtils.clamp;
|
||||||
public final class JavaMouseWheel extends MouseWheel implements MouseWheelListener {
|
public final class JavaMouseWheel extends MouseWheel implements MouseWheelListener {
|
||||||
|
|
||||||
@OriginalMember(owner = "client!o", name = "g", descriptor = "I")
|
@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")
|
@OriginalMember(owner = "client!o", name = "a", descriptor = "(ZLjava/awt/Component;)V")
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -26,21 +27,16 @@ public final class JavaMouseWheel extends MouseWheel implements MouseWheelListen
|
||||||
@OriginalMember(owner = "client!o", name = "a", descriptor = "(I)I")
|
@OriginalMember(owner = "client!o", name = "a", descriptor = "(I)I")
|
||||||
@Override
|
@Override
|
||||||
public final synchronized int getRotation() {
|
public final synchronized int getRotation() {
|
||||||
@Pc(2) int local2 = this.anInt4233;
|
@Pc(2) int local2 = this.currentRotation;
|
||||||
this.anInt4233 = 0;
|
this.currentRotation = 0;
|
||||||
return local2;
|
return local2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OriginalMember(owner = "client!o", name = "mouseWheelMoved", descriptor = "(Ljava/awt/event/MouseWheelEvent;)V")
|
@OriginalMember(owner = "client!o", name = "mouseWheelMoved", descriptor = "(Ljava/awt/event/MouseWheelEvent;)V")
|
||||||
@Override
|
@Override
|
||||||
public final synchronized void mouseWheelMoved(@OriginalArg(0) MouseWheelEvent arg0) {
|
public final synchronized void mouseWheelMoved(@OriginalArg(0) MouseWheelEvent arg0) {
|
||||||
int previous = this.anInt4233;
|
this.previousRotation = this.currentRotation;
|
||||||
this.anInt4233 += arg0.getWheelRotation();
|
this.currentRotation += 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OriginalMember(owner = "client!o", name = "a", descriptor = "(Ljava/awt/Component;I)V")
|
@OriginalMember(owner = "client!o", name = "a", descriptor = "(Ljava/awt/Component;I)V")
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
@OriginalMember(owner = "client!dc", name = "W", descriptor = "I")
|
@OriginalMember(owner = "client!dc", name = "W", descriptor = "I")
|
||||||
public static volatile int anInt1313 = 0;
|
public static volatile int anInt1313 = 0;
|
||||||
@OriginalMember(owner = "client!nb", name = "j", descriptor = "I")
|
@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")
|
@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")
|
@OriginalMember(owner = "client!sa", name = "Y", descriptor = "I")
|
||||||
public static volatile int anInt4973 = 0;
|
public static volatile int anInt4973 = 0;
|
||||||
@OriginalMember(owner = "client!wi", name = "W", descriptor = "I")
|
@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;
|
public static long prevClickTime = 0L;
|
||||||
@OriginalMember(owner = "client!wl", name = "u", descriptor = "I")
|
@OriginalMember(owner = "client!wl", name = "u", descriptor = "I")
|
||||||
public static int anInt5895 = 0;
|
public static int anInt5895 = 0;
|
||||||
public int mouseWheelX;
|
|
||||||
public int mouseWheelY;
|
|
||||||
|
|
||||||
@OriginalMember(owner = "client!sc", name = "a", descriptor = "(ILjava/awt/Component;)V")
|
@OriginalMember(owner = "client!sc", name = "a", descriptor = "(ILjava/awt/Component;)V")
|
||||||
public static void stop(@OriginalArg(1) Component arg0) {
|
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;
|
@Pc(2) Mouse local2 = instance;
|
||||||
synchronized (instance) {
|
synchronized (instance) {
|
||||||
pressedButton = anInt1759;
|
pressedButton = anInt1759;
|
||||||
lastMouseX = anInt3521;
|
lastMouseX = currentMouseX;
|
||||||
lastMouseY = anInt4039;
|
lastMouseY = currentMouseY;
|
||||||
clickButton = anInt1313;
|
clickButton = anInt1313;
|
||||||
clickX = anInt1034;
|
clickX = anInt1034;
|
||||||
anInt2467++;
|
anInt2467++;
|
||||||
|
|
@ -112,8 +110,8 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
public final synchronized void mouseMoved(@OriginalArg(0) MouseEvent arg0) {
|
public final synchronized void mouseMoved(@OriginalArg(0) MouseEvent arg0) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
anInt2467 = 0;
|
anInt2467 = 0;
|
||||||
anInt3521 = arg0.getX();
|
currentMouseX = arg0.getX();
|
||||||
anInt4039 = arg0.getY();
|
currentMouseY = arg0.getY();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,21 +128,13 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
public final synchronized void mouseDragged(@OriginalArg(0) MouseEvent event) {
|
public final synchronized void mouseDragged(@OriginalArg(0) MouseEvent event) {
|
||||||
int x = event.getX();
|
int x = event.getX();
|
||||||
int y = event.getY();
|
int y = event.getY();
|
||||||
if (SwingUtilities.isMiddleMouseButton(event)) {
|
|
||||||
int accelX = this.mouseWheelX - x;
|
if (SwingUtilities.isMiddleMouseButton(event)) return;
|
||||||
int accelY = this.mouseWheelY - y;
|
|
||||||
this.mouseWheelX = x;
|
|
||||||
this.mouseWheelY = y;
|
|
||||||
Camera.yawTarget += accelX * 2;
|
|
||||||
Camera.pitchTarget -= accelY * 2;
|
|
||||||
Camera.clampCameraAngle();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
anInt2467 = 0;
|
anInt2467 = 0;
|
||||||
anInt3521 = x;
|
currentMouseX = x;
|
||||||
anInt4039 = y;
|
currentMouseY = y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,8 +174,6 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
@Override
|
@Override
|
||||||
public final synchronized void mousePressed(@OriginalArg(0) MouseEvent event) {
|
public final synchronized void mousePressed(@OriginalArg(0) MouseEvent event) {
|
||||||
if (SwingUtilities.isMiddleMouseButton(event)) {
|
if (SwingUtilities.isMiddleMouseButton(event)) {
|
||||||
this.mouseWheelX = event.getX();
|
|
||||||
this.mouseWheelY = event.getY();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,8 +207,8 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
public final synchronized void mouseExited(@OriginalArg(0) MouseEvent arg0) {
|
public final synchronized void mouseExited(@OriginalArg(0) MouseEvent arg0) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
anInt2467 = 0;
|
anInt2467 = 0;
|
||||||
anInt3521 = -1;
|
currentMouseX = -1;
|
||||||
anInt4039 = -1;
|
currentMouseY = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,8 +217,8 @@ public final class Mouse implements MouseListener, MouseMotionListener, FocusLis
|
||||||
public final synchronized void mouseEntered(@OriginalArg(0) MouseEvent arg0) {
|
public final synchronized void mouseEntered(@OriginalArg(0) MouseEvent arg0) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
anInt2467 = 0;
|
anInt2467 = 0;
|
||||||
anInt3521 = arg0.getX();
|
currentMouseX = arg0.getX();
|
||||||
anInt4039 = arg0.getY();
|
currentMouseY = arg0.getY();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -218,7 +218,6 @@ public final class client extends GameShell {
|
||||||
public static void main(@OriginalArg(0) String[] arg0) {
|
public static void main(@OriginalArg(0) String[] arg0) {
|
||||||
try {
|
try {
|
||||||
GlobalJsonConfig.load(GlobalConfig.EXTENDED_CONFIG_PATH);
|
GlobalJsonConfig.load(GlobalConfig.EXTENDED_CONFIG_PATH);
|
||||||
PluginRepository.Init();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -1022,6 +1021,7 @@ public final class client extends GameShell {
|
||||||
if (modeWhere != 0) {
|
if (modeWhere != 0) {
|
||||||
//Cheat.displayFps = true;
|
//Cheat.displayFps = true;
|
||||||
}
|
}
|
||||||
|
PluginRepository.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OriginalMember(owner = "client!client", name = "c", descriptor = "(I)V")
|
@OriginalMember(owner = "client!client", name = "c", descriptor = "(I)V")
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ public class plugin extends Plugin {
|
||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
private boolean isVerbose;
|
private boolean isVerbose;
|
||||||
|
|
||||||
private ArrayList<Integer> activeVarps = new ArrayList<>();
|
private final ArrayList<Integer> activeVarps = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {
|
public void ComponentDraw(int componentIndex, Component component, int screenX, int screenY) {
|
||||||
|
|
|
||||||
115
plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt
Normal file
115
plugin-playground/src/main/kotlin/BasicInputQOL/plugin.kt
Normal file
|
|
@ -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<out String>?) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue