Skip to content

Commit

Permalink
project(internal): Move a couple methods to mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
Owain94 committed Jun 12, 2022
1 parent a6763ba commit 3a9bec6
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
@NoArgsConstructor
public abstract class InjectData
{
public static final String HOOKS = "net/runelite/client/callback/Hooks";
public static final String CALLBACKS = "net/runelite/api/hooks/Callbacks";

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,23 @@
import net.runelite.asm.execution.InstructionContext;
import net.runelite.asm.execution.MethodContext;
import net.runelite.asm.execution.StackContext;
import net.runelite.asm.signature.Signature;
import static com.openosrs.injector.injection.InjectData.HOOKS;

public class ClearColorBuffer extends AbstractInjector
{
private static final net.runelite.asm.pool.Method CLEARBUFFER = new net.runelite.asm.pool.Method(
new net.runelite.asm.pool.Class(HOOKS),
"clearColorBuffer",
new Signature("(IIIII)V")
);

public ClearColorBuffer(InjectData inject)
{
super(inject);
}

public void inject()
{

/*
* This class stops the client from basically painting everything black before the scene is drawn
*/
final Execution exec = new Execution(inject.getVanilla());

final net.runelite.asm.pool.Method clearBuffer = inject.getVanilla().findClass("client").findMethod("clearColorBuffer").getPoolMethod();
final net.runelite.asm.pool.Method fillRectPool = InjectUtil.findMethod(inject, "Rasterizer2D_fillRectangle", "Rasterizer2D", null).getPoolMethod();
final Method drawEntities = InjectUtil.findMethod(inject, "drawEntities"); // XXX: should prob be called drawViewport?

Expand Down Expand Up @@ -83,7 +77,7 @@ public void inject()
}

Instructions ins = instr.getInstructions();
ins.replace(instr, new InvokeStatic(ins, CLEARBUFFER));
ins.replace(instr, new InvokeStatic(ins, clearBuffer));
log.debug("[DEBUG] Injected drawRectangle at {}", methodContext.getMethod().getPoolMethod());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,10 @@
import net.runelite.asm.execution.Execution;
import net.runelite.asm.execution.InstructionContext;
import net.runelite.asm.execution.MethodContext;
import net.runelite.asm.pool.Class;
import net.runelite.asm.pool.Field;
import net.runelite.asm.signature.Signature;
import static com.openosrs.injector.injection.InjectData.HOOKS;

public class DrawMenu extends AbstractInjector
{
private static final net.runelite.asm.pool.Method DRAWMENU = new net.runelite.asm.pool.Method(
new Class(HOOKS),
"drawMenu",
new Signature("()Z")
);

public DrawMenu(InjectData inject)
{
super(inject);
Expand Down Expand Up @@ -66,6 +57,7 @@ public void inject()
* --------
*/

final net.runelite.asm.pool.Method drawMenu = inject.getVanilla().findClass("client").findMethod("drawMenu").getPoolMethod();
final Method drawLoggedIn = InjectUtil.findMethod(inject, "drawLoggedIn", "Client", null, true, false);
final Field gameDrawMode = InjectUtil.findField(inject, "gameDrawingMode", "Client").getPoolField();
final Field isMenuOpen = InjectUtil.findField(inject, "isMenuOpen", "Client").getPoolField();
Expand Down Expand Up @@ -135,7 +127,7 @@ else if (((GetStatic) instruction).getField().equals(gameDrawMode))
final Instructions instrs = mc.getMethod().getCode().getInstructions();
int idx = instrs.getInstructions().indexOf(injectInvokeAfter);

instrs.addInstruction(++idx, new InvokeStatic(instrs, DRAWMENU));
instrs.addInstruction(++idx, new InvokeStatic(instrs, drawMenu));
instrs.addInstruction(++idx, new IfNe(instrs, labelToJumpTo));

log.info("[INFO] DrawMenu injected a method call at index {} in method {}. With a comparison jumping to {}", idx, drawLoggedIn, labelToJumpTo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@
import net.runelite.asm.attributes.code.Instructions;
import net.runelite.asm.attributes.code.instructions.InvokeStatic;
import net.runelite.asm.attributes.code.instructions.InvokeVirtual;
import net.runelite.asm.pool.Class;
import net.runelite.asm.signature.Signature;
import static com.openosrs.injector.injection.InjectData.HOOKS;

public class RenderDraw extends AbstractInjector
{
private static final net.runelite.asm.pool.Method RENDERDRAW = new net.runelite.asm.pool.Method(
new Class(HOOKS),
"renderDraw",
new Signature("(Lnet/runelite/api/Renderable;IIIIIIIIJ)V")
);
private static final int EXPECTED = 21;

public RenderDraw(InjectData inject)
Expand All @@ -38,6 +30,8 @@ public RenderDraw(InjectData inject)
@Override
public void inject()
{
final net.runelite.asm.pool.Method renderDraw = inject.toVanilla(inject.getDeobfuscated().findClass("Scene")).findMethod("renderDraw").getPoolMethod();

int replaced = 0;

/*
Expand All @@ -56,7 +50,7 @@ public void inject()
{
if (((InvokeVirtual) i).getMethod().equals(draw))
{
iterator.set(new InvokeStatic(ins, RENDERDRAW));
iterator.set(new InvokeStatic(ins, renderDraw));
log.debug("[DEBUG] Replaced method call at {}", i);
++replaced;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.BufferProvider;
import net.runelite.api.Client;
import net.runelite.api.MainBufferProvider;
import net.runelite.api.RenderOverview;
import net.runelite.api.Renderable;
import net.runelite.api.Skill;
import net.runelite.api.WorldMapManager;
import net.runelite.api.events.BeforeMenuRender;
import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.FakeXpDrop;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.hooks.Callbacks;
import net.runelite.api.hooks.DrawCallbacks;
import net.runelite.api.widgets.Widget;
import static net.runelite.api.widgets.WidgetInfo.WORLD_MAP_VIEW;
import net.runelite.api.widgets.WidgetItem;
Expand Down Expand Up @@ -124,6 +121,7 @@ public interface RenderableDrawListener
/**
* Get the Graphics2D for the MainBufferProvider image
* This caches the Graphics2D instance so it can be reused
*
* @param mainBufferProvider
* @return
*/
Expand Down Expand Up @@ -422,6 +420,7 @@ public void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x

/**
* Copy an image
*
* @param src
* @return
*/
Expand Down Expand Up @@ -568,45 +567,6 @@ public void unregisterRenderableDrawListener(RenderableDrawListener listener)
renderableDrawListeners.remove(listener);
}

public static void clearColorBuffer(int x, int y, int width, int height, int color)
{
BufferProvider bp = client.getBufferProvider();
int canvasWidth = bp.getWidth();
int[] pixels = bp.getPixels();

int pixelPos = y * canvasWidth + x;
int pixelJump = canvasWidth - width;

for (int cy = y; cy < y + height; cy++)
{
for (int cx = x; cx < x + width; cx++)
{
pixels[pixelPos++] = 0;
}
pixelPos += pixelJump;
}
}

public static void renderDraw(Renderable renderable, int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z, long hash)
{
DrawCallbacks drawCallbacks = client.getDrawCallbacks();
if (drawCallbacks != null)
{
drawCallbacks.draw(renderable, orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash);
}
else
{
renderable.draw(orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash);
}
}

public static boolean drawMenu()
{
BeforeMenuRender event = new BeforeMenuRender();
client.getCallbacks().post(event);
return event.isConsumed();
}

@Override
public boolean draw(Renderable renderable, boolean drawingUi)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import net.runelite.api.clan.ClanSettings;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.BeforeMenuRender;
import net.runelite.api.events.CanvasSizeChanged;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ClanChannelChanged;
Expand Down Expand Up @@ -3099,5 +3100,13 @@ public RSNPC getFollower()
RSNPC[] var2 = this.getCachedNPCs();
return var1 >= 0 && var1 < var2.length ? var2[var1] : null;
}

@Inject
public static boolean drawMenu()
{
BeforeMenuRender event = new BeforeMenuRender();
client.getCallbacks().post(event);
return event.isConsumed();
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.runelite.mixins;

import net.runelite.api.BufferProvider;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Inject;
import net.runelite.api.mixins.Mixin;
Expand Down Expand Up @@ -207,4 +208,24 @@ private static void drawAlpha(int[] pixels, int index, int value, int alpha)
}
}
}

@Inject
public static void clearColorBuffer(int x, int y, int width, int height, int color)
{
BufferProvider bp = client.getBufferProvider();
int canvasWidth = bp.getWidth();
int[] pixels = bp.getPixels();

int pixelPos = y * canvasWidth + x;
int pixelJump = canvasWidth - width;

for (int cy = y; cy < y + height; cy++)
{
for (int cx = x; cx < x + width; cx++)
{
pixels[pixelPos++] = 0;
}
pixelPos += pixelJump;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.runelite.api.DecorativeObject;
import net.runelite.api.GroundObject;
import net.runelite.api.Perspective;
import net.runelite.api.Renderable;
import net.runelite.api.SceneTileModel;
import net.runelite.api.SceneTilePaint;
import net.runelite.api.Tile;
Expand Down Expand Up @@ -1288,4 +1289,18 @@ public void removeGroundObject(GroundObject groundObject)
}
}
}

@Inject
public static void renderDraw(Renderable renderable, int orientation, int pitchSin, int pitchCos, int yawSin, int yawCos, int x, int y, int z, long hash)
{
DrawCallbacks drawCallbacks = client.getDrawCallbacks();
if (drawCallbacks != null)
{
drawCallbacks.draw(renderable, orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash);
}
else
{
renderable.draw(orientation, pitchSin, pitchCos, yawSin, yawCos, x, y, z, hash);
}
}
}

0 comments on commit 3a9bec6

Please sign in to comment.