From 0cad0dedc5f280251525f9a5ec581b3ba9bebbc0 Mon Sep 17 00:00:00 2001 From: thispixel Date: Thu, 12 Feb 2015 14:30:27 +0000 Subject: [PATCH] Add mouse clicked message support and decoding. --- .../message/impl/MouseClickedMessage.java | 82 +++++++++++++++++++ .../r317/MouseClickedMessageDecoder.java | 32 ++++++++ .../apollo/net/release/r317/Release317.java | 1 + 3 files changed, 115 insertions(+) create mode 100644 src/org/apollo/game/message/impl/MouseClickedMessage.java create mode 100644 src/org/apollo/net/release/r317/MouseClickedMessageDecoder.java diff --git a/src/org/apollo/game/message/impl/MouseClickedMessage.java b/src/org/apollo/game/message/impl/MouseClickedMessage.java new file mode 100644 index 00000000..d7eab5d7 --- /dev/null +++ b/src/org/apollo/game/message/impl/MouseClickedMessage.java @@ -0,0 +1,82 @@ +package org.apollo.game.message.impl; + +import org.apollo.game.message.Message; + +/** + * A {@link Message} sent by the client to indicate when the mouse button/s have been clicked. This can be used in + * combination with {@link org.apollo.game.message.impl.FocusUpdateMessage} to work out if the player is clicking + * whilst the client is closed + * + * @author Stuart + */ +public final class MouseClickedMessage extends Message { + + /** + * Time in milliseconds since the last click + */ + private final long lastClickedDelay; + /** + * Right mouse button flag + */ + private final boolean rightMouseButton; + /** + * The y position of the cursor + */ + private final int x; + /** + * The x position of the cursor + */ + private final int y; + + /** + * Creates a new mouse clicked message + * + * @param lastClickedDelay The delay since the last click + * @param rightMouseButton Whether or not the right mouse button was used + * @param x The x cursor position when clicked + * @param y The y cursor position when clicked + */ + public MouseClickedMessage(long lastClickedDelay, boolean rightMouseButton, int x, int y) { + this.lastClickedDelay = lastClickedDelay; + this.rightMouseButton = rightMouseButton; + this.x = x; + this.y = y; + } + + /** + * Gets the time in milliseconds since the last click + * + * @return The time in milliseconds since the last click + */ + public long getLastClickedDelay() { + return lastClickedDelay; + } + + /** + * Gets whether the right mouse button was used or not + * + * @return If the mouse right button was used to click + */ + public boolean usingRightMouseButton() { + return rightMouseButton; + } + + /** + * Gets the x position of the cursor + * + * @return The x position of the cursor when clicked + */ + public int getX() { + return x; + } + + /** + * Gets the y position of the cursor + * + * @return The y position of the cursor when clicked + */ + public int getY() { + return y; + } + +} diff --git a/src/org/apollo/net/release/r317/MouseClickedMessageDecoder.java b/src/org/apollo/net/release/r317/MouseClickedMessageDecoder.java new file mode 100644 index 00000000..70d40c7c --- /dev/null +++ b/src/org/apollo/net/release/r317/MouseClickedMessageDecoder.java @@ -0,0 +1,32 @@ +package org.apollo.net.release.r317; + +import org.apollo.game.message.impl.MouseClickedMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link org.apollo.net.release.MessageDecoder} for the {@link org.apollo.game.message.impl.MouseClickedMessage} + * + * @author Stuart + */ +public final class MouseClickedMessageDecoder extends MessageDecoder { + + @Override + public MouseClickedMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int value = (int)reader.getUnsigned(DataType.INT); + + long delay = (value >> 20) * 50; + + boolean rightMouseButton = ((value >> 19) & 0x1) == 1; + + int cords = (value & 0x3FFFF); + int x = cords % 765; + int y = cords / 765; + + return new MouseClickedMessage(delay, rightMouseButton, x, y); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/Release317.java b/src/org/apollo/net/release/r317/Release317.java index 4c4c1e49..b8a37cab 100644 --- a/src/org/apollo/net/release/r317/Release317.java +++ b/src/org/apollo/net/release/r317/Release317.java @@ -129,6 +129,7 @@ public final class Release317 extends Release { register(3, new FocusUpdateMessageDecoder()); register(45, new FlaggedMouseEventMessageDecoder()); + register(241, new MouseClickedMessageDecoder()); register(86, new ArrowKeyMessageDecoder()); register(95, new PrivacyOptionMessageDecoder());