From 8ed22caad47074588d893d2117a7dca33d2826bc Mon Sep 17 00:00:00 2001 From: Owain van Brakel Date: Wed, 11 May 2022 22:28:48 +0200 Subject: [PATCH 1/3] project(injector): Remove edge case checks and let the injector handle it --- .../injector/injectors/MixinInjector.java | 21 ++++++++++++------- .../injectors/raw/CopyRuneLiteClasses.java | 5 ----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/injector/src/main/java/com/openosrs/injector/injectors/MixinInjector.java b/injector/src/main/java/com/openosrs/injector/injectors/MixinInjector.java index 1408a3c419..762899c9b8 100644 --- a/injector/src/main/java/com/openosrs/injector/injectors/MixinInjector.java +++ b/injector/src/main/java/com/openosrs/injector/injectors/MixinInjector.java @@ -457,17 +457,22 @@ public class MixinInjector extends AbstractInjector } }*/ - Method copy = new Method(targetClass, mixinMethod.getName(), mixinMethod.getDescriptor()); - moveCode(copy, mixinMethod.getCode()); - copy.setAccessFlags(mixinMethod.getAccessFlags()); - copy.setPublic(); + Method method = targetClass.findMethod(mixinMethod.getName(), mixinMethod.getDescriptor()); + + if (method == null) + { + method = new Method(targetClass, mixinMethod.getName(), mixinMethod.getDescriptor()); + targetClass.addMethod(method); + } + + moveCode(method, mixinMethod.getCode()); + method.setAccessFlags(mixinMethod.getAccessFlags()); + method.setPublic(); assert mixinMethod.getExceptions().getExceptions().isEmpty(); - setOwnersToTargetClass(mixinClass, targetClass, copy, copiedMethods); + setOwnersToTargetClass(mixinClass, targetClass, method, copiedMethods); - targetClass.addMethod(copy); - - log.debug("[DEBUG] Injected mixin method {} to {}", copy, targetClass); + log.debug("[DEBUG] Injected mixin method {} to {}", method, targetClass); ++injected; } else if (mixinMethod.findAnnotation(REPLACE) != null) diff --git a/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java b/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java index 5e616527bc..49cd7ffe03 100644 --- a/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java +++ b/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java @@ -93,11 +93,6 @@ public class CopyRuneLiteClasses extends AbstractInjector for (Method method : runeLiteDeob.getMethods()) { - if (className.equals("RuneLiteMenuEntry") && (method.getName().equals("getItemId") || method.getName().equals("getWidget") || method.getName().equals("getItemOp"))) - { - continue; - } - transformMethod(method); runeliteObjectVanilla.addMethod(method); } From 28dcc47ac8ec9ebfa30d9c46242551ba3bfd68ad Mon Sep 17 00:00:00 2001 From: Owain van Brakel Date: Thu, 12 May 2022 01:50:21 +0200 Subject: [PATCH 2/3] project(injector): Make it possible to use rsc-api in rsc --- .../injectors/raw/CopyRuneLiteClasses.java | 35 +++++++++++++++---- runescape-client/runescape-client.gradle.kts | 1 + 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java b/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java index 49cd7ffe03..a96f018f0f 100644 --- a/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java +++ b/injector/src/main/java/com/openosrs/injector/injectors/raw/CopyRuneLiteClasses.java @@ -10,8 +10,10 @@ package com.openosrs.injector.injectors.raw; import com.openosrs.injector.InjectUtil; import com.openosrs.injector.injection.InjectData; import com.openosrs.injector.injectors.AbstractInjector; +import java.util.HashSet; import java.util.List; import java.util.ListIterator; +import java.util.Set; import net.runelite.asm.ClassFile; import net.runelite.asm.Field; import net.runelite.asm.Method; @@ -43,6 +45,9 @@ public class CopyRuneLiteClasses extends AbstractInjector "RuneLiteObject" ); + + private final Set shadowFields = new HashSet<>(); + public CopyRuneLiteClasses(InjectData inject) { super(inject); @@ -52,6 +57,8 @@ public class CopyRuneLiteClasses extends AbstractInjector { for (String className : RUNELITE_OBJECTS) { + shadowFields.clear(); + ClassFile runeliteObjectVanilla = inject.vanilla.findClass(className); final ClassFile runeLiteDeob = inject.getDeobfuscated() @@ -85,18 +92,23 @@ public class CopyRuneLiteClasses extends AbstractInjector runeliteObjectVanilla.getInterfaces().addInterface(interfaze); } - for (Field field : runeLiteDeob.getFields()) - { - field.setType(InjectUtil.deobToVanilla(inject, field.getType())); - runeliteObjectVanilla.addField(field); - } - for (Method method : runeLiteDeob.getMethods()) { transformMethod(method); runeliteObjectVanilla.addMethod(method); } + for (Field field : runeLiteDeob.getFields()) + { + if (shadowFields.contains(field.getType())) + { + continue; + } + + field.setType(InjectUtil.deobToVanilla(inject, field.getType())); + runeliteObjectVanilla.addField(field); + } + inject.vanilla.addClass(runeliteObjectVanilla); } } @@ -165,7 +177,16 @@ public class CopyRuneLiteClasses extends AbstractInjector net.runelite.asm.pool.Field field = ((GetStatic) i).getField(); Field vanilla = findField(field); - if (vanilla != null) + if (method.getClassFile().getName().equals(field.getClazz().getName()) && field.getType().toString().contains("Lnet/runelite/rs/api/RS")) + { + shadowFields.add(field.getType()); + + String fieldName = field.getType().toString().replace("Lnet/runelite/rs/api/RS", "").replace(";", ""); + final Field deobTargetField = InjectUtil.findStaticField(inject, fieldName.substring(0, 1).toLowerCase() + fieldName.substring(1), null, InjectUtil.apiToDeob(inject, field.getType())); + + iterator.set(new GetStatic(ins, inject.toVanilla(deobTargetField))); + } + else if (vanilla != null) { iterator.set(new GetStatic(ins, vanilla)); } diff --git a/runescape-client/runescape-client.gradle.kts b/runescape-client/runescape-client.gradle.kts index 5c177ff7b5..933ba6d6b7 100644 --- a/runescape-client/runescape-client.gradle.kts +++ b/runescape-client/runescape-client.gradle.kts @@ -27,6 +27,7 @@ group = "com.openosrs.rs" description = "RuneScape Client" dependencies { + api(project(":runescape-api")) api(project(":runelite-api")) implementation(project(":injection-annotations")) From 1a3d36abc11c5284cecb3c686a966017966517e4 Mon Sep 17 00:00:00 2001 From: Owain van Brakel Date: Thu, 12 May 2022 01:51:10 +0200 Subject: [PATCH 3/3] project(mixins): Convert menu entry from partly mixin to just rsc --- .../mixins/RuneLiteMenuEntryMixin.java | 142 ------------------ .../src/main/java/RuneLiteMenuEntry.java | 103 +++++++++++-- 2 files changed, 94 insertions(+), 151 deletions(-) delete mode 100644 runelite-mixins/src/main/java/net/runelite/mixins/RuneLiteMenuEntryMixin.java diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RuneLiteMenuEntryMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RuneLiteMenuEntryMixin.java deleted file mode 100644 index 1d443e3e6a..0000000000 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RuneLiteMenuEntryMixin.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2018, OpenOSRS - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.mixins; - -import net.runelite.api.MenuAction; -import net.runelite.api.mixins.Inject; -import net.runelite.api.mixins.Mixin; -import net.runelite.api.mixins.Shadow; -import net.runelite.api.widgets.Widget; -import net.runelite.rs.api.RSClient; -import net.runelite.rs.api.RSRuneLiteMenuEntry; - -@Mixin(RSRuneLiteMenuEntry.class) -public abstract class RuneLiteMenuEntryMixin implements RSRuneLiteMenuEntry -{ - @Shadow("client") - private static RSClient client; - - @Inject - @Override - public int getItemOp() - { - MenuAction var1 = this.getType(); - if (var1 == MenuAction.CC_OP || var1 == MenuAction.CC_OP_LOW_PRIORITY) - { - int identifier = this.getIdentifier(); - int param0 = this.getParam0(); - int param1 = this.getParam1(); - - if (param1 == 9764864) - { - switch (identifier) - { - case 1: - Widget widget = client.getWidget(param1); - if (widget != null && param0 != -1) - { - widget = widget.getChild(param0); - if (widget != null && widget.getItemId() > -1) - { - int shiftClickActionIndex = client.getItemComposition(widget.getItemId()).getShiftClickActionIndex(); - - if (shiftClickActionIndex >= 0) - { - return shiftClickActionIndex + 1; - } - } - } - break; - case 2: - return 1; - case 3: - return 2; - case 4: - return 3; - case 5: - default: - break; - case 6: - return 4; - case 7: - return 5; - } - } - } - - return -1; - } - - @Inject - @Override - public int getItemId() - { - MenuAction menuAction = this.getType(); - if (menuAction == MenuAction.CC_OP || menuAction == MenuAction.CC_OP_LOW_PRIORITY) - { - int param1 = this.getParam1(); - int param0 = this.getParam0(); - - if (param1 == 9764864) - { - Widget widget = client.getWidget(param1); - if (param0 != -1) - { - widget = widget.getChild(param0); - return widget.getItemId(); - } - } - } - - return -1; - } - - @Inject - @Override - public Widget getWidget() - { - int param1 = this.getParam1(); - int param0 = this.getParam0(); - - Widget widget = client.getWidget(param1); - - if (widget == null) - { - return null; - } - - if (param0 != -1) - { - Widget child = widget.getChild(param0); - - if (child != null) - { - return child; - } - } - - return widget; - } -} diff --git a/runescape-client/src/main/java/RuneLiteMenuEntry.java b/runescape-client/src/main/java/RuneLiteMenuEntry.java index 5f3fc47a26..0ac7adf6e8 100644 --- a/runescape-client/src/main/java/RuneLiteMenuEntry.java +++ b/runescape-client/src/main/java/RuneLiteMenuEntry.java @@ -2,10 +2,13 @@ import java.util.function.Consumer; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.widgets.Widget; +import net.runelite.rs.api.RSClient; import sun.reflect.generics.reflectiveObjects.NotImplementedException; public class RuneLiteMenuEntry implements MenuEntry { + private static RSClient client; + public Consumer consumer; public int idx; @@ -328,14 +331,15 @@ public class RuneLiteMenuEntry implements MenuEntry @Override public boolean isItemOp() { - MenuAction var1 = this.getType(); - if (var1 == MenuAction.CC_OP || var1 == MenuAction.CC_OP_LOW_PRIORITY) + MenuAction menuAction = this.getType(); + if (menuAction == MenuAction.CC_OP || menuAction == MenuAction.CC_OP_LOW_PRIORITY) { - int var2 = this.getIdentifier(); - int var3 = this.getParam1(); - if (var3 == 9764864) + int identifier = this.getIdentifier(); + int param1 = this.getParam1(); + + if (param1 == 9764864) { - switch (var2) + switch (identifier) { case 1: case 2: @@ -355,19 +359,100 @@ public class RuneLiteMenuEntry implements MenuEntry @Override public int getItemOp() { - throw new NotImplementedException(); + MenuAction menuAction = this.getType(); + if (menuAction == MenuAction.CC_OP || menuAction == MenuAction.CC_OP_LOW_PRIORITY) + { + int identifier = this.getIdentifier(); + int param0 = this.getParam0(); + int param1 = this.getParam1(); + + if (param1 == 9764864) + { + switch (identifier) + { + case 1: + Widget widget = client.getWidget(param1); + if (widget != null && param0 != -1) + { + widget = widget.getChild(param0); + if (widget != null && widget.getItemId() > -1) + { + int shiftClickActionIndex = client.getItemComposition(widget.getItemId()).getShiftClickActionIndex(); + + if (shiftClickActionIndex >= 0) + { + return shiftClickActionIndex + 1; + } + } + } + break; + case 2: + return 1; + case 3: + return 2; + case 4: + return 3; + case 5: + default: + break; + case 6: + return 4; + case 7: + return 5; + } + } + } + + return -1; } @Override public int getItemId() { - throw new NotImplementedException(); + MenuAction menuAction = this.getType(); + if (menuAction == MenuAction.CC_OP || menuAction == MenuAction.CC_OP_LOW_PRIORITY) + { + int param1 = this.getParam1(); + int param0 = this.getParam0(); + + if (param1 == 9764864) + { + Widget widget = client.getWidget(param1); + if (param0 != -1) + { + widget = widget.getChild(param0); + return widget.getItemId(); + } + } + } + + return -1; } @Override public Widget getWidget() { - throw new NotImplementedException(); + int param1 = this.getParam1(); + int param0 = this.getParam0(); + + Widget widget = client.getWidget(param1); + + if (widget == null) + { + return null; + } + + if (param0 != -1) + { + Widget child = widget.getChild(param0); + + if (child != null) + { + return child; + } + } + + return widget; } @Override