From 17dd88d50aacd5619bccf878f02abb12c7cc178e Mon Sep 17 00:00:00 2001 From: Ganom Date: Sat, 21 Sep 2019 18:25:03 -0400 Subject: [PATCH] client: add setters for selected spells and items (#1634) * client: add setters for selected spells and items (thanks to Skitzo the absolute beast.) * deob: change "changeSpellFlag" method name to "selectSpell" * deob: export "selectSpell" for tests. --- .../main/java/net/runelite/api/Client.java | 105 +++++++++++------- .../java/net/runelite/rs/api/RSClient.java | 32 ++++++ runescape-client/src/main/java/Client.java | 5 +- .../src/main/java/EnumDefinition.java | 26 ++--- .../src/main/java/FloorDecoration.java | 2 +- runescape-client/src/main/java/Player.java | 13 ++- runescape-client/src/main/java/Tiles.java | 2 +- runescape-client/src/main/java/class83.java | 3 +- 8 files changed, 124 insertions(+), 64 deletions(-) diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index b7a0492384..a202d3baf9 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -116,10 +116,10 @@ public interface Client extends GameShell /** * Adds a new chat message to the chatbox. * - * @param type the type of message - * @param name the name of the player that sent the message + * @param type the type of message + * @param name the name of the player that sent the message * @param message the message contents - * @param sender the sender/channel name + * @param sender the sender/channel name */ void addChatMessage(ChatMessageType type, String name, String message, String sender); @@ -358,13 +358,13 @@ public interface Client extends GameShell /** * Creates an item icon sprite with passed variables. * - * @param itemId the item ID - * @param quantity the item quantity - * @param border whether to draw a border + * @param itemId the item ID + * @param quantity the item quantity + * @param border whether to draw a border * @param shadowColor the shadow color - * @param stackable whether the item is stackable - * @param noted whether the item is noted - * @param scale the scale of the sprite + * @param stackable whether the item is stackable + * @param noted whether the item is noted + * @param scale the scale of the sprite * @return the created sprite */ @Nullable @@ -373,9 +373,9 @@ public interface Client extends GameShell /** * Loads and creates the sprite images of the passed archive and file IDs. * - * @param source the sprite index + * @param source the sprite index * @param archiveId the sprites archive ID - * @param fileId the sprites file ID + * @param fileId the sprites file ID * @return the sprite image of the file */ @Nullable @@ -504,6 +504,7 @@ public interface Client extends GameShell /** * Creates a new widget element + * * @return */ Widget createWidget(); @@ -633,6 +634,7 @@ public interface Client extends GameShell * | |rot| y chunk coord | x chunk coord |pln| | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * } + * * @return the array of instance template chunks * @see Constants#CHUNK_SIZE * @see InstanceTemplates @@ -711,14 +713,14 @@ public interface Client extends GameShell * Sets the value of a given variable. * * @param varbit the variable - * @param value the new value + * @param value the new value */ void setVarbit(Varbits varbit, int value); /** * Gets the value of a given variable. * - * @param varps passed varbits + * @param varps passed varbits * @param varbitId the variable ID * @return the value * @see Varbits @@ -728,7 +730,7 @@ public interface Client extends GameShell /** * Gets the value of a given VarPlayer. * - * @param varps passed varps + * @param varps passed varps * @param varpId the VarpPlayer id * @return the value * @see VarPlayer#id @@ -738,9 +740,9 @@ public interface Client extends GameShell /** * Sets the value of a given VarPlayer. * - * @param varps passed varps + * @param varps passed varps * @param varpId the VarpPlayer id - * @param value the value + * @param value the value * @see VarPlayer#id */ void setVarpValue(int[] varps, int varpId, int value); @@ -748,9 +750,9 @@ public interface Client extends GameShell /** * Sets the value of a given variable. * - * @param varps passed varbits + * @param varps passed varbits * @param varbit the variable - * @param value the value + * @param value the value * @see Varbits */ void setVarbitValue(int[] varps, int varbit, int value); @@ -922,7 +924,7 @@ public interface Client extends GameShell * pixels. * * @param pixels the pixels - * @param width the width + * @param width the width * @param height the height * @return the sprite image */ @@ -956,31 +958,31 @@ public interface Client extends GameShell * normally played. * * @param id the ID of the sound to play. Any int is allowed, but see - * {@link SoundEffectID} for some common ones + * {@link SoundEffectID} for some common ones */ void playSoundEffect(int id); /** * Play a sound effect from some point in the world. * - * @param id the ID of the sound to play. Any int is allowed, but see - * {@link SoundEffectID} for some common ones - * @param x the ground coordinate on the x axis - * @param y the ground coordinate on the y axis + * @param id the ID of the sound to play. Any int is allowed, but see + * {@link SoundEffectID} for some common ones + * @param x the ground coordinate on the x axis + * @param y the ground coordinate on the y axis * @param range the number of tiles away that the sound can be heard - * from + * from */ void playSoundEffect(int id, int x, int y, int range); /** * Play a sound effect from some point in the world. * - * @param id the ID of the sound to play. Any int is allowed, but see - * {@link SoundEffectID} for some common ones - * @param x the ground coordinate on the x axis - * @param y the ground coordinate on the y axis + * @param id the ID of the sound to play. Any int is allowed, but see + * {@link SoundEffectID} for some common ones + * @param x the ground coordinate on the x axis + * @param y the ground coordinate on the y axis * @param range the number of tiles away that the sound can be heard - * from + * from * @param delay the amount of frames before the sound starts playing */ void playSoundEffect(int id, int x, int y, int range, int delay); @@ -1078,7 +1080,7 @@ public interface Client extends GameShell /** * Checks whether a player is on the friends list. * - * @param name the name of the player + * @param name the name of the player * @param mustBeLoggedIn if they player is online * @return true if the player is friends */ @@ -1261,7 +1263,7 @@ public interface Client extends GameShell /** * Executes a client script from the cache - * + *

* This method must be ran on the client thread and is not reentrant * * @param args the script id, then any additional arguments to execute the script with @@ -1651,6 +1653,7 @@ public interface Client extends GameShell /** * Hops using in-game world hopper widget to another world + * * @param world target world to hop to */ void hopToWorld(World world); @@ -1670,11 +1673,15 @@ public interface Client extends GameShell void setGpu(boolean gpu); int get3dZoom(); + int getCenterX(); + int getCenterY(); int getCameraX2(); + int getCameraY2(); + int getCameraZ2(); TextureProvider getTextureProvider(); @@ -1684,8 +1691,11 @@ public interface Client extends GameShell void setRenderArea(boolean[][] renderArea); int getRasterizer3D_clipMidX2(); + int getRasterizer3D_clipNegativeMidX(); + int getRasterizer3D_clipNegativeMidY(); + int getRasterizer3D_clipMidY2(); void checkClickbox(Model model, int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z, long hash); @@ -1726,15 +1736,14 @@ public interface Client extends GameShell void setRenderSelf(boolean enabled); /** - * - * @param param0 This is SceneX for gameObject, index for items, and 0 for npc. - * @param param1 This is SceneY for gameObject, static for items, and 0 for npc. - * @param type Menu entry Action opcode. - * @param id Targets ID - * @param menuEntry Do these actually matter? + * @param param0 This is SceneX for gameObject, index for items, and 0 for npc. + * @param param1 This is SceneY for gameObject, static for items, and 0 for npc. + * @param type Menu entry Action opcode. + * @param id Targets ID + * @param menuEntry Do these actually matter? * @param targetString Do these actually matter? - * @param canvasX Canvas X Point - * @param canvasY Canvas Y Point + * @param canvasX Canvas X Point + * @param canvasY Canvas Y Point */ void invokeMenuAction(int param0, int param1, int type, int id, String menuEntry, String targetString, int canvasX, int canvasY); @@ -1744,6 +1753,8 @@ public interface Client extends GameShell String getSelectedSpellName(); + void setSelectedSpellName(String name); + boolean isSpellSelected(); /** @@ -1794,4 +1805,18 @@ public interface Client extends GameShell * Adds a MenuEntry to the current menu. */ void insertMenuItem(String action, String target, int opcode, int identifier, int argument1, int argument2, boolean forceLeftClick); + + void setSelectedItemID(int id); + + void setSelectedItemWidget(int widgetID); + + void setSelectedItemSlot(int idx); + + int getSelectedSpellWidget(); + + int getSelectedSpellChildIndex(); + + void setSelectedSpellWidget(int widgetID); + + void setSelectedSpellChildIndex(int index); } \ No newline at end of file diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java index 2e4e0fa829..8e1c1f89bd 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java @@ -1016,6 +1016,10 @@ public interface RSClient extends RSGameShell, Client @Import("selectedSpellName") String getSelectedSpellName(); + @Import("selectedSpellName") + @Override + void setSelectedSpellName(String name); + @Import("isSpellSelected") boolean isSpellSelected(); @@ -1054,4 +1058,32 @@ public interface RSClient extends RSGameShell, Client @Import("insertMenuItem") @Override void insertMenuItem(String action, String target, int opcode, int identifier, int argument1, int argument2, boolean forceLeftClick); + + @Import("selectedItemId") + @Override + void setSelectedItemID(int id); + + @Import("selectedItemSlot") + @Override + void setSelectedItemSlot(int index); + + @Import("selectedItemWidget") + @Override + void setSelectedItemWidget(int widgetID); + + @Import("selectedSpellWidget") + @Override + int getSelectedSpellWidget(); + + @Import("selectedSpellChildIndex") + @Override + int getSelectedSpellChildIndex(); + + @Import("selectedSpellWidget") + @Override + void setSelectedSpellWidget(int widgetID); + + @Import("selectedSpellChildIndex") + @Override + void setSelectedSpellChildIndex(int index); } \ No newline at end of file diff --git a/runescape-client/src/main/java/Client.java b/runescape-client/src/main/java/Client.java index 03cbb28a3a..5edc3e303e 100644 --- a/runescape-client/src/main/java/Client.java +++ b/runescape-client/src/main/java/Client.java @@ -1236,7 +1236,8 @@ public final class Client extends GameShell implements Usernamed { @ObfuscatedGetter( intValue = -465859219 ) - static int field687; + @Export("selectedSpellChildIndex") + static int selectedSpellChildIndex; @ObfuscatedName("ml") @ObfuscatedGetter( intValue = -1436921851 @@ -1410,7 +1411,7 @@ public final class Client extends GameShell implements Usernamed { isItemSelected = 0; selectedItemName = null; isSpellSelected = false; - field687 = -1; + selectedSpellChildIndex = -1; field648 = -1; selectedSpellActionName = null; selectedSpellName = null; diff --git a/runescape-client/src/main/java/EnumDefinition.java b/runescape-client/src/main/java/EnumDefinition.java index 7bb7ecb0f2..d6240e22e7 100644 --- a/runescape-client/src/main/java/EnumDefinition.java +++ b/runescape-client/src/main/java/EnumDefinition.java @@ -323,11 +323,11 @@ public class EnumDefinition extends DualNode { Client.destinationX = var0; Client.destinationY = var1; var8 = MenuAction.getPacketBufferNode(ClientPacket.field2196, Client.packetWriter.isaacCipher); - var8.packetBuffer.writeIntLE16(class83.field1138); + var8.packetBuffer.writeIntLE16(class83.selectedSpellWidget); var8.packetBuffer.writeShort(var3); var8.packetBuffer.method5500(ScriptEvent.baseY + var1); var8.packetBuffer.method5566(KeyHandler.KeyHandler_pressedKeys[82] ? 1 : 0); - var8.packetBuffer.writeIntME(Client.field687); + var8.packetBuffer.writeIntME(Client.selectedSpellChildIndex); var8.packetBuffer.writeIntME(class4.baseX * 64 + var0); Client.packetWriter.addNode(var8); } else if (var2 == 3) { @@ -412,8 +412,8 @@ public class EnumDefinition extends DualNode { Client.destinationX = var0; Client.destinationY = var1; var9 = MenuAction.getPacketBufferNode(ClientPacket.field2280, Client.packetWriter.isaacCipher); - var9.packetBuffer.method5502(Client.field687); - var9.packetBuffer.writeIntLE16(class83.field1138); + var9.packetBuffer.method5502(Client.selectedSpellChildIndex); + var9.packetBuffer.writeIntLE16(class83.selectedSpellWidget); var9.packetBuffer.method5500(var3); var9.packetBuffer.method5493(KeyHandler.KeyHandler_pressedKeys[82] ? 1 : 0); Client.packetWriter.addNode(var9); @@ -517,9 +517,9 @@ public class EnumDefinition extends DualNode { Client.destinationX = var0; Client.destinationY = var1; var9 = MenuAction.getPacketBufferNode(ClientPacket.field2194, Client.packetWriter.isaacCipher); - var9.packetBuffer.writeIntLE(class83.field1138); + var9.packetBuffer.writeIntLE(class83.selectedSpellWidget); var9.packetBuffer.writeShort(var3); - var9.packetBuffer.method5500(Client.field687); + var9.packetBuffer.method5500(Client.selectedSpellChildIndex); var9.packetBuffer.method5566(KeyHandler.KeyHandler_pressedKeys[82] ? 1 : 0); Client.packetWriter.addNode(var9); } @@ -547,8 +547,8 @@ public class EnumDefinition extends DualNode { Client.destinationX = var0; Client.destinationY = var1; var8 = MenuAction.getPacketBufferNode(ClientPacket.field2233, Client.packetWriter.isaacCipher); - var8.packetBuffer.writeIntLE(class83.field1138); - var8.packetBuffer.writeShort(Client.field687); + var8.packetBuffer.writeIntLE(class83.selectedSpellWidget); + var8.packetBuffer.writeShort(Client.selectedSpellChildIndex); var8.packetBuffer.method5500(ScriptEvent.baseY + var1); var8.packetBuffer.method5500(var3); var8.packetBuffer.method5500(class4.baseX * 64 + var0); @@ -645,7 +645,7 @@ public class EnumDefinition extends DualNode { var16 = class49.getWidgetChild(var1, var0); if (var16 != null) { FloorDecoration.Widget_runOnTargetLeave(); - Player.method1196(var1, var0, WorldMapElement.method4390(class60.getWidgetClickMask(var16)), var16.itemId); + Player.selectSpell(var1, var0, WorldMapElement.method4390(class60.getWidgetClickMask(var16)), var16.itemId); Client.isItemSelected = 0; Client.selectedSpellActionName = class16.method165(var16); if (Client.selectedSpellActionName == null) { @@ -709,11 +709,11 @@ public class EnumDefinition extends DualNode { Client.field728 = var0; } else if (var2 == 32) { var8 = MenuAction.getPacketBufferNode(ClientPacket.field2219, Client.packetWriter.isaacCipher); - var8.packetBuffer.writeShort(Client.field687); + var8.packetBuffer.writeShort(Client.selectedSpellChildIndex); var8.packetBuffer.method5500(var0); var8.packetBuffer.writeShortLE(var1); var8.packetBuffer.method5500(var3); - var8.packetBuffer.writeIntLE16(class83.field1138); + var8.packetBuffer.writeIntLE16(class83.selectedSpellWidget); Client.packetWriter.addNode(var8); Client.field727 = 0; Entity.field1835 = Player.getWidget(var1); @@ -944,8 +944,8 @@ public class EnumDefinition extends DualNode { var16 = class49.getWidgetChild(var1, var0); if (var16 != null) { var9 = MenuAction.getPacketBufferNode(ClientPacket.field2229, Client.packetWriter.isaacCipher); - var9.packetBuffer.writeShortLE(class83.field1138); - var9.packetBuffer.writeIntME(Client.field687); + var9.packetBuffer.writeShortLE(class83.selectedSpellWidget); + var9.packetBuffer.writeIntME(Client.selectedSpellChildIndex); var9.packetBuffer.writeIntLE(var1); var9.packetBuffer.writeShort(var0); var9.packetBuffer.writeIntME(Client.field648); diff --git a/runescape-client/src/main/java/FloorDecoration.java b/runescape-client/src/main/java/FloorDecoration.java index 89ede5411a..aee053b45b 100644 --- a/runescape-client/src/main/java/FloorDecoration.java +++ b/runescape-client/src/main/java/FloorDecoration.java @@ -139,7 +139,7 @@ public final class FloorDecoration { @Export("Widget_runOnTargetLeave") static void Widget_runOnTargetLeave() { if (Client.isSpellSelected) { - Widget var0 = class49.getWidgetChild(class83.field1138, Client.field687); + Widget var0 = class49.getWidgetChild(class83.selectedSpellWidget, Client.selectedSpellChildIndex); if (var0 != null && var0.onTargetLeave != null) { ScriptEvent var1 = new ScriptEvent(); var1.widget = var0; diff --git a/runescape-client/src/main/java/Player.java b/runescape-client/src/main/java/Player.java index f8b779ad36..3cd3ff308b 100644 --- a/runescape-client/src/main/java/Player.java +++ b/runescape-client/src/main/java/Player.java @@ -741,8 +741,9 @@ public final class Player extends Actor { signature = "(IIIII)V", garbageValue = "16777215" ) - static void method1196(int var0, int var1, int var2, int var3) { - Widget var4 = class49.getWidgetChild(var0, var1); + @Export("selectSpell") + static void selectSpell(int widgetId, int childId, int clickMaskId, int id) { + Widget var4 = class49.getWidgetChild(widgetId, childId); if (var4 != null && var4.onTargetEnter != null) { ScriptEvent var5 = new ScriptEvent(); var5.widget = var4; @@ -750,11 +751,11 @@ public final class Player extends Actor { SecureRandomFuture.runScriptEvent(var5); } - Client.field648 = var3; + Client.field648 = id; Client.isSpellSelected = true; - class83.field1138 = var0; - Client.field687 = var1; - BuddyRankComparator.selectedSpellFlags = var2; + class83.selectedSpellWidget = widgetId; + Client.selectedSpellChildIndex = childId; + BuddyRankComparator.selectedSpellFlags = clickMaskId; WorldMapID.invalidateWidget(var4); } } diff --git a/runescape-client/src/main/java/Tiles.java b/runescape-client/src/main/java/Tiles.java index b1cea69b41..c409ba8fae 100644 --- a/runescape-client/src/main/java/Tiles.java +++ b/runescape-client/src/main/java/Tiles.java @@ -360,7 +360,7 @@ public final class Tiles { TileItem.method2093(var20 + 1, var9.id, var9.childIndex, var9.itemId, ""); } else if (var20 == 10) { FloorDecoration.Widget_runOnTargetLeave(); - Player.method1196(var9.id, var9.childIndex, WorldMapElement.method4390(class60.getWidgetClickMask(var9)), var9.itemId); + Player.selectSpell(var9.id, var9.childIndex, WorldMapElement.method4390(class60.getWidgetClickMask(var9)), var9.itemId); Client.selectedSpellActionName = class16.method165(var9); if (Client.selectedSpellActionName == null) { Client.selectedSpellActionName = "null"; diff --git a/runescape-client/src/main/java/class83.java b/runescape-client/src/main/java/class83.java index cb307e965d..0cdad153e4 100644 --- a/runescape-client/src/main/java/class83.java +++ b/runescape-client/src/main/java/class83.java @@ -20,7 +20,8 @@ public class class83 { @ObfuscatedGetter( intValue = 670190247 ) - static int field1138; + @Export("selectedSpellWidget") + static int selectedSpellWidget; static { field1142 = new BigInteger("10001", 16);