Merge branch 'KondoKit-2.0' into 'master'

KondoKit 2.0

See merge request 2009scape/rt4-client!28
This commit is contained in:
Ceikry 2024-11-04 22:48:02 +00:00
commit 5cf2f18786
36 changed files with 2491 additions and 869 deletions

View file

@ -13,6 +13,7 @@ import rt4.Tile;
*/
public abstract class Plugin {
long timeOfLastDraw;
long timeOfLastLateDraw;
void _init() {
Init();
@ -24,6 +25,12 @@ public abstract class Plugin {
timeOfLastDraw = nowTime;
}
void _lateDraw() {
long nowTime = System.currentTimeMillis();
LateDraw(nowTime - timeOfLastLateDraw);
timeOfLastLateDraw = nowTime;
}
/**
* Draw() is called by the client rendering loop so that plugins can draw information onto the screen.
* This will be called once per frame, meaning it is framerate bound.
@ -31,6 +38,14 @@ public abstract class Plugin {
*/
public void Draw(long timeDelta) {}
/**
* LateDraw() is called at the end of a finalized frame
* This will be called once per frame, meaning it is framerate bound.
* @param timeDelta the time (ms) elapsed since the last draw call.
*/
public void LateDraw(long timeDelta) {}
/**
* Init() is called when the plugin is first loaded
*/

View file

@ -13,10 +13,10 @@ import java.util.Properties;
* A data class for storing information about plugins.
* @author ceikry
*/
class PluginInfo {
double version;
String author;
String description;
public class PluginInfo {
public double version;
public String author;
public String description;
public PluginInfo(String author, String description, double version) {
this.version = version;

View file

@ -160,6 +160,11 @@ public class PluginRepository {
pluginsSnapshot.forEach(Plugin::_draw);
}
public static void LateDraw() {
List<Plugin> pluginsSnapshot = new ArrayList<>(loadedPlugins.values());
pluginsSnapshot.forEach(Plugin::_lateDraw);
}
public static void NPCOverheadDraw(Npc npc, int screenX, int screenY) {
loadedPlugins.values().forEach((plugin) -> plugin.NPCOverheadDraw(npc, screenX, screenY));
}

View file

@ -12,7 +12,7 @@ import java.awt.*;
public abstract class FrameBuffer {
@OriginalMember(owner = "client!vk", name = "e", descriptor = "[I")
protected int[] pixels;
public int[] pixels;
@OriginalMember(owner = "client!vk", name = "g", descriptor = "Ljava/awt/Image;")
protected Image image;

View file

@ -9,6 +9,7 @@ import org.openrs2.deob.annotation.OriginalMember;
import org.openrs2.deob.annotation.Pc;
import java.awt.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;
@ -24,6 +25,11 @@ public final class GlRenderer {
public static float hFOV = 0;
private static ByteBuffer pixelByteBuffer;
private static IntBuffer pixelIntBuffer;
public static int[] pixelData;
@OriginalMember(owner = "client!tf", name = "c", descriptor = "F")
private static float aFloat30;
@ -200,10 +206,34 @@ public final class GlRenderer {
public static void swapBuffers() {
try {
drawable.swapBuffers();
readPixels();
} catch (@Pc(3) Exception local3) {
}
}
public static void initializePixelBuffer(int width, int height) {
// Allocate ByteBuffer for BGRA pixels (4 bytes per pixel)
pixelByteBuffer = ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder());
pixelIntBuffer = pixelByteBuffer.asIntBuffer();
pixelData = new int[width * height];
}
public static void readPixels() {
// Ensure the pixel buffer is initialized with the correct size
if (pixelByteBuffer == null || pixelIntBuffer.capacity() != canvasWidth * canvasHeight) {
initializePixelBuffer(canvasWidth, canvasHeight);
}
// Read pixels into the direct ByteBuffer
gl.glReadPixels(0, 0, canvasWidth, canvasHeight, GL2.GL_BGRA,
GlRenderer.bigEndian ? GL2.GL_UNSIGNED_INT_8_8_8_8_REV : GL2.GL_UNSIGNED_BYTE,
pixelByteBuffer);
// Convert to int array if needed
pixelIntBuffer.rewind(); // Prepare the IntBuffer for reading
pixelIntBuffer.get(pixelData, 0, pixelData.length); // Transfer to pixelData array if necessary
}
@OriginalMember(owner = "client!tf", name = "a", descriptor = "(Z)V")
public static void setFogEnabled(@OriginalArg(0) boolean enabled) {
if (enabled == fogEnabled) {

View file

@ -921,6 +921,7 @@ public final class client extends GameShell {
Preferences.safeMode = false;
Preferences.write(GameShell.signLink);
}
PluginRepository.LateDraw();
}
@OriginalMember(owner = "client!client", name = "c", descriptor = "(B)V")