project(internal): Mixins and injectors
This commit is contained in:
@@ -12,13 +12,10 @@ import com.openosrs.injector.InjectException;
|
||||
import com.openosrs.injector.InjectUtil;
|
||||
import com.openosrs.injector.injection.InjectData;
|
||||
import com.openosrs.injector.injectors.AbstractInjector;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import net.runelite.asm.Method;
|
||||
import net.runelite.asm.attributes.code.Instruction;
|
||||
import net.runelite.asm.attributes.code.InstructionType;
|
||||
import net.runelite.asm.attributes.code.Instructions;
|
||||
import net.runelite.asm.attributes.code.Label;
|
||||
import net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction;
|
||||
@@ -32,8 +29,6 @@ import net.runelite.asm.attributes.code.instructions.IfACmpNe;
|
||||
import net.runelite.asm.attributes.code.instructions.IfICmpNe;
|
||||
import net.runelite.asm.attributes.code.instructions.IfNe;
|
||||
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
|
||||
import net.runelite.asm.attributes.code.instructions.LDC;
|
||||
import net.runelite.asm.attributes.code.instructions.Return;
|
||||
import net.runelite.asm.pool.Field;
|
||||
|
||||
public class AddPlayerToMenu extends AbstractInjector
|
||||
@@ -45,15 +40,15 @@ public class AddPlayerToMenu extends AbstractInjector
|
||||
|
||||
public void inject()
|
||||
{
|
||||
final Method addPlayerOptions = InjectUtil.findMethod(inject, "addPlayerToMenu");
|
||||
final Method addPlayerOptions = inject.toVanilla(inject.getDeobfuscated().findClass("Scene")).findMethod("copy$addPlayerToMenu");
|
||||
final net.runelite.asm.pool.Method shouldHideAttackOptionFor =
|
||||
inject.getVanilla().findClass("client").findMethod("shouldHideAttackOptionFor").getPoolMethod();
|
||||
final net.runelite.asm.pool.Method shouldDrawMethod =
|
||||
inject.getVanilla().findStaticMethod("shouldDraw").getPoolMethod();
|
||||
// final net.runelite.asm.pool.Method shouldDrawMethod =
|
||||
// inject.getVanilla().findStaticMethod("shouldDraw").getPoolMethod();
|
||||
|
||||
try
|
||||
{
|
||||
injectSameTileFix(addPlayerOptions, shouldDrawMethod);
|
||||
// injectSameTileFix(addPlayerOptions, shouldDrawMethod);
|
||||
injectHideAttack(addPlayerOptions, shouldHideAttackOptionFor);
|
||||
injectHideCast(addPlayerOptions, shouldHideAttackOptionFor);
|
||||
}
|
||||
@@ -63,32 +58,32 @@ public class AddPlayerToMenu extends AbstractInjector
|
||||
}
|
||||
}
|
||||
|
||||
private void injectSameTileFix(Method addPlayerOptions, net.runelite.asm.pool.Method shouldDrawMethod)
|
||||
{
|
||||
// ALOAD 0
|
||||
// ICONST_0
|
||||
// INVOKESTATIC Scene.shouldDraw
|
||||
// IFNE CONTINUE_LABEL if returned true then jump to continue
|
||||
// RETURN
|
||||
// CONTINUE_LABEL
|
||||
// REST OF METHOD GOES HERE
|
||||
Instructions insns = addPlayerOptions.getCode().getInstructions();
|
||||
Label CONTINUE_LABEL = new Label(insns);
|
||||
List<Instruction> prependList = new ArrayList<>()
|
||||
{{
|
||||
add(new ALoad(insns, 0));
|
||||
add(new LDC(insns, 0));
|
||||
add(new InvokeStatic(insns, shouldDrawMethod));
|
||||
add(new IfNe(insns, CONTINUE_LABEL));
|
||||
add(new Return(insns, InstructionType.RETURN));
|
||||
add(CONTINUE_LABEL);
|
||||
}};
|
||||
int i = 0;
|
||||
for (Instruction instruction : prependList)
|
||||
{
|
||||
insns.addInstruction(i++, instruction);
|
||||
}
|
||||
}
|
||||
// private void injectSameTileFix(Method addPlayerOptions, net.runelite.asm.pool.Method shouldDrawMethod)
|
||||
// {
|
||||
// // ALOAD 0
|
||||
// // ICONST_0
|
||||
// // INVOKESTATIC Scene.shouldDraw
|
||||
// // IFNE CONTINUE_LABEL if returned true then jump to continue
|
||||
// // RETURN
|
||||
// // CONTINUE_LABEL
|
||||
// // REST OF METHOD GOES HERE
|
||||
// Instructions insns = addPlayerOptions.getCode().getInstructions();
|
||||
// Label CONTINUE_LABEL = new Label(insns);
|
||||
// List<Instruction> prependList = new ArrayList<>()
|
||||
// {{
|
||||
// add(new ALoad(insns, 0));
|
||||
// add(new LDC(insns, 0));
|
||||
// add(new InvokeStatic(insns, shouldDrawMethod));
|
||||
// add(new IfNe(insns, CONTINUE_LABEL));
|
||||
// add(new Return(insns, InstructionType.RETURN));
|
||||
// add(CONTINUE_LABEL);
|
||||
// }};
|
||||
// int i = 0;
|
||||
// for (Instruction instruction : prependList)
|
||||
// {
|
||||
// insns.addInstruction(i++, instruction);
|
||||
// }
|
||||
// }
|
||||
|
||||
private void injectHideAttack(Method addPlayerOptions, net.runelite.asm.pool.Method shouldHideAttackOptionFor)
|
||||
{
|
||||
|
||||
@@ -1,246 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
|
||||
* Copyright (c) 2019, ThatGamerBlue <thatgamerblue@gmail.com>
|
||||
* 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 java.util.HashMap;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(RSClient.class)
|
||||
public abstract class EntityHiderBridgeMixin implements RSClient
|
||||
{
|
||||
@Inject
|
||||
public static boolean isHidingEntities;
|
||||
|
||||
@Inject
|
||||
public static boolean hideOthers;
|
||||
|
||||
@Inject
|
||||
public static boolean hideOthers2D;
|
||||
|
||||
@Inject
|
||||
public static boolean hideFriends;
|
||||
|
||||
@Inject
|
||||
public static boolean hideClanMates;
|
||||
|
||||
@Inject
|
||||
public static boolean hideClanChatMembers;
|
||||
|
||||
@Inject
|
||||
public static boolean hideIgnores;
|
||||
|
||||
@Inject
|
||||
public static boolean hideLocalPlayer;
|
||||
|
||||
@Inject
|
||||
public static boolean hideLocalPlayer2D;
|
||||
|
||||
@Inject
|
||||
public static boolean hideNPCs;
|
||||
|
||||
@Inject
|
||||
public static boolean hideNPCs2D;
|
||||
|
||||
@Inject
|
||||
public static boolean hidePets;
|
||||
|
||||
@Inject
|
||||
public static boolean hideAttackers;
|
||||
|
||||
@Inject
|
||||
public static boolean hideProjectiles;
|
||||
|
||||
@Inject
|
||||
public static boolean hideDeadNPCs;
|
||||
|
||||
@Inject
|
||||
public static List<String> hideSpecificPlayers = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
public static HashMap<String, Integer> hiddenNpcsName = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public static List<Integer> hiddenNpcIndices = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setIsHidingEntities(boolean state)
|
||||
{
|
||||
isHidingEntities = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setOthersHidden(boolean state)
|
||||
{
|
||||
hideOthers = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setOthersHidden2D(boolean state)
|
||||
{
|
||||
hideOthers2D = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setFriendsHidden(boolean state)
|
||||
{
|
||||
hideFriends = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setFriendsChatMembersHidden(boolean state)
|
||||
{
|
||||
hideClanMates = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setClanChatMembersHidden(boolean state)
|
||||
{
|
||||
hideClanChatMembers = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setIgnoresHidden(boolean state)
|
||||
{
|
||||
hideIgnores = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setLocalPlayerHidden(boolean state)
|
||||
{
|
||||
hideLocalPlayer = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setLocalPlayerHidden2D(boolean state)
|
||||
{
|
||||
hideLocalPlayer2D = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setNPCsHidden(boolean state)
|
||||
{
|
||||
hideNPCs = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setNPCsHidden2D(boolean state)
|
||||
{
|
||||
hideNPCs2D = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setHideSpecificPlayers(List<String> players)
|
||||
{
|
||||
hideSpecificPlayers = players;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setPetsHidden(boolean state)
|
||||
{
|
||||
hidePets = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setAttackersHidden(boolean state)
|
||||
{
|
||||
hideAttackers = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setProjectilesHidden(boolean state)
|
||||
{
|
||||
hideProjectiles = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setDeadNPCsHidden(boolean state)
|
||||
{
|
||||
hideDeadNPCs = state;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void addHiddenNpcName(String npc)
|
||||
{
|
||||
npc = npc.toLowerCase();
|
||||
int i = hiddenNpcsName.getOrDefault(npc, 0);
|
||||
if (i == Integer.MAX_VALUE)
|
||||
{
|
||||
throw new RuntimeException("NPC name " + npc + " has been hidden Integer.MAX_VALUE times, is something wrong?");
|
||||
}
|
||||
|
||||
hiddenNpcsName.put(npc, ++i);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void removeHiddenNpcName(String npc)
|
||||
{
|
||||
npc = npc.toLowerCase();
|
||||
int i = hiddenNpcsName.getOrDefault(npc, 0);
|
||||
if (i == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hiddenNpcsName.put(npc, --i);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setHiddenNpcIndices(List<Integer> npcIndices)
|
||||
{
|
||||
hiddenNpcIndices = new ArrayList<>(npcIndices);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public List<Integer> getHiddenNpcIndices()
|
||||
{
|
||||
return new ArrayList<>(hiddenNpcIndices);
|
||||
}
|
||||
}
|
||||
@@ -25,12 +25,16 @@
|
||||
*/
|
||||
package net.runelite.mixins;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.runelite.api.mixins.*;
|
||||
import net.runelite.rs.api.*;
|
||||
|
||||
import java.util.List;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.mixins.Copy;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.api.mixins.Replace;
|
||||
import net.runelite.api.mixins.Shadow;
|
||||
import net.runelite.rs.api.RSActor;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSPlayer;
|
||||
import net.runelite.rs.api.RSRenderable;
|
||||
import net.runelite.rs.api.RSScene;
|
||||
|
||||
@Mixin(RSScene.class)
|
||||
public abstract class EntityHiderMixin implements RSScene
|
||||
@@ -38,65 +42,11 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
@Shadow("client")
|
||||
private static RSClient client;
|
||||
|
||||
@Shadow("isHidingEntities")
|
||||
private static boolean isHidingEntities;
|
||||
|
||||
@Shadow("hideOthers")
|
||||
private static boolean hideOthers;
|
||||
|
||||
@Shadow("hideOthers2D")
|
||||
private static boolean hideOthers2D;
|
||||
|
||||
@Shadow("hideFriends")
|
||||
private static boolean hideFriends;
|
||||
|
||||
@Shadow("hideClanMates")
|
||||
private static boolean hideClanMates;
|
||||
|
||||
@Shadow("hideClanChatMembers")
|
||||
private static boolean hideClanChatMembers;
|
||||
|
||||
@Shadow("hideLocalPlayer")
|
||||
private static boolean hideLocalPlayer;
|
||||
|
||||
@Shadow("hideLocalPlayer2D")
|
||||
private static boolean hideLocalPlayer2D;
|
||||
|
||||
@Shadow("hideIgnores")
|
||||
private static boolean hideIgnores;
|
||||
|
||||
@Shadow("hideNPCs")
|
||||
private static boolean hideNPCs;
|
||||
|
||||
@Shadow("hideSpecificPlayers")
|
||||
private static List<String> hideSpecificPlayers;
|
||||
|
||||
@Shadow("hideNPCs2D")
|
||||
private static boolean hideNPCs2D;
|
||||
|
||||
@Shadow("hidePets")
|
||||
private static boolean hidePets;
|
||||
|
||||
@Shadow("hideAttackers")
|
||||
private static boolean hideAttackers;
|
||||
|
||||
@Shadow("hideProjectiles")
|
||||
private static boolean hideProjectiles;
|
||||
|
||||
@Shadow("hideDeadNPCs")
|
||||
private static boolean hideDeadNPCs;
|
||||
|
||||
@Shadow("hiddenNpcsName")
|
||||
private static HashMap<String, Integer> hiddenNpcsName;
|
||||
|
||||
@Shadow("hiddenNpcIndices")
|
||||
private static List<Integer> hiddenNpcIndices;
|
||||
|
||||
@Copy("newGameObject")
|
||||
@Replace("newGameObject")
|
||||
boolean copy$addEntityMarker(int var1, int var2, int var3, int var4, int var5, int x, int y, int var8, RSRenderable entity, int var10, boolean var11, long var12, int var13)
|
||||
{
|
||||
final boolean shouldDraw = shouldDraw(entity, false);
|
||||
final boolean shouldDraw = client.getCallbacks().draw(entity, false);
|
||||
|
||||
if (!shouldDraw)
|
||||
{
|
||||
@@ -117,124 +67,29 @@ public abstract class EntityHiderMixin implements RSScene
|
||||
@Replace("drawActor2d")
|
||||
private static void copy$draw2DExtras(RSActor actor, int var1, int var2, int var3, int var4, int var5)
|
||||
{
|
||||
if (shouldDraw(actor, true))
|
||||
if (client.getCallbacks().draw(actor, true))
|
||||
{
|
||||
copy$draw2DExtras(actor, var1, var2, var3, var4, var5);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
private static boolean shouldDraw(Object entity, boolean drawingUI)
|
||||
@Copy("addPlayerToMenu")
|
||||
@Replace("addPlayerToMenu")
|
||||
static void copy$addPlayerToMenu(RSPlayer var0, int var1, int var2, int var3)
|
||||
{
|
||||
if (!isHidingEntities)
|
||||
if (client.getCallbacks().draw(var0, false))
|
||||
{
|
||||
return true;
|
||||
copy$addPlayerToMenu(var0, var1, var2, var3);
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof RSRenderable)
|
||||
@Copy("addNpcToMenu")
|
||||
@Replace("addNpcToMenu")
|
||||
static void copy$addNpcToMenu(NPC var0, int var1, int var2, int var3)
|
||||
{
|
||||
if (client.getCallbacks().draw(var0, false))
|
||||
{
|
||||
if (((RSRenderable) entity).isHidden())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
copy$addNpcToMenu(var0, var1, var2, var3);
|
||||
}
|
||||
|
||||
if (entity instanceof RSPlayer)
|
||||
{
|
||||
RSPlayer player = (RSPlayer) entity;
|
||||
RSPlayer local = client.getLocalPlayer();
|
||||
if (player.getName() == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (player == local)
|
||||
{
|
||||
return drawingUI ? !hideLocalPlayer2D : !hideLocalPlayer;
|
||||
}
|
||||
|
||||
for (String name : hideSpecificPlayers)
|
||||
{
|
||||
if (name != null && !name.equals(""))
|
||||
{
|
||||
if (player.getName() != null && player.getName().equalsIgnoreCase(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hideAttackers && player.getInteracting() == local)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.isFriend())
|
||||
{
|
||||
return !hideFriends;
|
||||
}
|
||||
|
||||
if (player.isFriendsChatMember())
|
||||
{
|
||||
return !hideClanMates;
|
||||
}
|
||||
|
||||
if (player.isClanMember())
|
||||
{
|
||||
return !hideClanChatMembers;
|
||||
}
|
||||
|
||||
if (client.getFriendManager().isIgnored(player.getRsName()))
|
||||
{
|
||||
return !hideIgnores;
|
||||
}
|
||||
|
||||
return drawingUI ? !hideOthers2D : !hideOthers;
|
||||
}
|
||||
else if (entity instanceof RSNPC)
|
||||
{
|
||||
RSNPC npc = (RSNPC) entity;
|
||||
|
||||
if (hiddenNpcIndices.contains(npc.getIndex()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Integer> entry : hiddenNpcsName.entrySet())
|
||||
{
|
||||
String name = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
if (name != null && !name.equals(""))
|
||||
{
|
||||
if (count > 0 && npc.getName() != null && npc.getName().equalsIgnoreCase(name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (npc.isDead() && hideDeadNPCs)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (npc.getComposition().isFollower() && npc.getIndex() != client.getFollowerIndex() && hidePets)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (npc.getInteracting() == client.getLocalPlayer() && hideAttackers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return drawingUI ? !hideNPCs2D : !hideNPCs;
|
||||
}
|
||||
else if (entity instanceof RSProjectile)
|
||||
{
|
||||
return !hideProjectiles;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3089,5 +3089,15 @@ public abstract class RSClientMixin implements RSClient
|
||||
Arrays.fill(client.getBufferProvider().getPixels(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
@Nullable
|
||||
public RSNPC getFollower()
|
||||
{
|
||||
int var1 = client.getFollowerIndex();
|
||||
RSNPC[] var2 = this.getCachedNPCs();
|
||||
return var1 >= 0 && var1 < var2.length ? var2[var1] : null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,9 @@ public interface RSUserList<T extends Nameable> extends NameableContainer<T>
|
||||
@Import("getSize")
|
||||
int getCount();
|
||||
|
||||
@Import("capacity")
|
||||
int getSize();
|
||||
|
||||
@Import("getByUsername")
|
||||
T findByName(RSUsername name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user