Add getters for before-ly-hooked fields

This commit is contained in:
Lucas
2019-06-09 23:39:06 +02:00
parent 9e504000eb
commit 6e497d3a4b
7 changed files with 45 additions and 16 deletions

View File

@@ -303,7 +303,7 @@ public class Inject
apiMethod = findImportMethodOnApi(targetApiClass, exportedName, false);
if (apiMethod == null)
{
// logger.debug("Unable to find import method on api class {} with imported name {}, not injecting getter", targetApiClass, exportedName);
//logger.debug("Unable to find import method on api class {} with imported name {}, not injecting getter", targetApiClass, exportedName);
continue;
}

View File

@@ -41,9 +41,11 @@ import net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction;
import net.runelite.asm.attributes.code.instructions.ArrayStore;
import net.runelite.asm.attributes.code.instructions.CheckCast;
import net.runelite.asm.attributes.code.instructions.Dup;
import net.runelite.asm.attributes.code.instructions.IMul;
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
import net.runelite.asm.attributes.code.instructions.InvokeVirtual;
import net.runelite.asm.attributes.code.instructions.LDC;
import net.runelite.asm.attributes.code.instructions.LMul;
import net.runelite.asm.attributes.code.instructions.PutField;
import net.runelite.asm.attributes.code.instructions.Swap;
import net.runelite.asm.execution.Execution;
@@ -63,6 +65,7 @@ public class InjectHook
String clazz;
Method method;
boolean before;
Number getter;
}
private static final String HOOK_METHOD_SIGNATURE = "(I)V";
@@ -154,7 +157,7 @@ public class InjectHook
}
else
{
// idx + 1 to insert after the set
// idx + 1 to insert after the set
injectCallback(ins, idx + 1, hookInfo, null, objectStackContext);
}
}
@@ -262,6 +265,22 @@ public class InjectHook
ins.getInstructions().add(idx++, new Dup(ins)); // dup value
idx = recursivelyPush(ins, idx, object);
ins.getInstructions().add(idx++, new Swap(ins));
if (hookInfo.getter != null)
{
assert hookInfo.getter instanceof Integer || hookInfo.getter instanceof Long;
if (hookInfo.getter instanceof Integer)
{
ins.getInstructions().add(new LDC(ins, (int) hookInfo.getter));
ins.getInstructions().add(new IMul(ins));
}
else
{
ins.getInstructions().add(new LDC(ins, (long) hookInfo.getter));
ins.getInstructions().add(new LMul(ins));
}
}
if (!value.type.equals(methodArgumentType))
{
CheckCast checkCast = new CheckCast(ins);

View File

@@ -909,6 +909,13 @@ public class MixinInjector
throw new InjectionException("Field hook for nonexistent field " + hookName + " on " + method);
}
Annotation an = targetField.getAnnotations().find(DeobAnnotations.OBFUSCATED_GETTER);
Number getter = null;
if (an != null)
{
getter = (Number) an.getElement().getValue();
}
Field obField = inject.toObField(targetField);
if (method.isStatic() != targetField.isStatic())
@@ -922,6 +929,7 @@ public class MixinInjector
hookInfo.fieldName = hookName;
hookInfo.method = method;
hookInfo.before = before;
hookInfo.getter = getter;
injectHook.hook(obField, hookInfo);
}
}

View File

@@ -448,9 +448,7 @@ public class SpellbookPlugin extends Plugin
}
// CHECKSTYLE:OFF
Collection<Spell> gson = GSON.fromJson(cfg, new TypeToken<List<Spell>>()
{
}.getType());
Collection<Spell> gson = GSON.fromJson(cfg, new TypeToken<List<Spell>>() {}.getType());
// CHECKSTYLE:ON
gson.stream().filter(Objects::nonNull).forEach(s -> spells.put(s.getWidget(), s));
@@ -465,7 +463,7 @@ public class SpellbookPlugin extends Plugin
private void saveSpells()
{
if (spells.isEmpty())
if (spells.isEmpty() || tmp == null || tmp.isEmpty())
{
return;
}

View File

@@ -258,6 +258,11 @@ public abstract class RSWidgetMixin implements RSWidget
for (int i = 0; i < itemIds.length; ++i)
{
if (itemIds[i] <= 0)
{
continue;
}
WidgetItem item = getWidgetItem(i);
if (item != null)
@@ -287,19 +292,17 @@ public abstract class RSWidgetMixin implements RSWidget
int itemId = itemIds[index];
int itemQuantity = itemQuantities[index];
Point widgetCanvasLocation = getCanvasLocation();
if (itemId <= 0 || itemQuantity <= 0 || columns <= 0)
if (columns <= 0)
{
return null;
}
int row = index / columns;
int col = index % columns;
int itemX = widgetCanvasLocation.getX() + ((ITEM_SLOT_SIZE + xPitch) * col);
int itemY = widgetCanvasLocation.getY() + ((ITEM_SLOT_SIZE + yPitch) * row);
int itemX = rl$x + ((ITEM_SLOT_SIZE + xPitch) * col);
int itemY = rl$y + ((ITEM_SLOT_SIZE + yPitch) * row);
Rectangle bounds = new Rectangle(itemX - 1, itemY - 1, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE);
Rectangle bounds = new Rectangle(itemX, itemY, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE);
return new WidgetItem(itemId - 1, itemQuantity, index, bounds, this);
}

View File

@@ -4710,7 +4710,7 @@ public final class Client extends GameShell implements Usernamed {
int var8;
if(!isMenuOpen) {
if(__client_lq != -1) {
class39.method741(__client_lq, __client_ln);
class39.drawMenuActionTextAt(__client_lq, __client_ln);
}
} else {
var1 = class25.menuX;

View File

@@ -767,7 +767,8 @@ public class class39 extends class21 {
signature = "(IIB)V",
garbageValue = "3"
)
static final void method741(int var0, int var1) {
@Export("drawMenuActionTextAt")
static final void drawMenuActionTextAt(int var0, int var1) {
if(Client.menuOptionsCount >= 2 || Client.isItemSelected != 0 || Client.isSpellSelected) {
if(Client.showMouseOverText) {
int var2 = Client.menuOptionsCount - 1;
@@ -790,10 +791,10 @@ public class class39 extends class21 {
}
if(Client.menuOptionsCount > 2) {
var4 = var4 + BufferedFile.colorStartTag(16777215) + " " + '/' + " " + (Client.menuOptionsCount - 2) + " more options";
var4 = var4 + BufferedFile.colorStartTag(0xffffff) + " " + '/' + " " + (Client.menuOptionsCount - 2) + " more options";
}
class2.fontBold12.drawRandomAlphaAndSpacing(var4, var0 + 4, var1 + 15, 16777215, 0, Client.cycle / 1000);
class2.fontBold12.drawRandomAlphaAndSpacing(var4, var0 + 4, var1 + 15, 0xffffff, 0, Client.cycle / 1000);
}
}
}