Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver = "2"
members = ["native/agent", "native/inject", "native/app"]

[workspace.package]
version = "0.2.0"
version = "0.2.1"
edition = "2021"
license = "MIT"

Expand Down
2 changes: 1 addition & 1 deletion java/core/src/main/java/prism/core/Prism.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Layout of the Prism folder (home): bin/ (agent + core), plugins/, data/, logs/, cache/.
*/
public final class Prism {
public static final String VERSION = "0.2.0";
public static final String VERSION = "0.2.1";

private static final AtomicBoolean running = new AtomicBoolean();
private static Bus bus;
Expand Down
17 changes: 11 additions & 6 deletions java/core/src/main/java/prism/core/hook/GameHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ public static void register(Hooks hooks, Poster bus, Function<Float, int[]> scre
return false;
}));

java.util.function.Predicate<Object[]> overlay = args -> {
float pt = (Float) args[0];
int[] size = screenSize.apply(pt);
bus.post(new RenderOverlayEvent(pt, size[0], size[1]));
return false;
};
hooks.add(Hook.tail("overlay", "net/minecraft/client/gui/GuiIngame", "renderGameOverlay", "func_175180_a", "(F)V",
new int[] {1}, args -> {
float pt = (Float) args[0];
int[] size = screenSize.apply(pt);
bus.post(new RenderOverlayEvent(pt, size[0], size[1]));
return false;
}));
new int[] {1}, overlay));
// Forge (and Lunar with Forge mods) replaces the HUD with GuiIngameForge, which overrides
// renderGameOverlay without calling the vanilla one
hooks.add(Hook.tail("overlay-forge", "net/minecraftforge/client/GuiIngameForge", "renderGameOverlay", "func_175180_a", "(F)V",
new int[] {1}, overlay).optional());

hooks.add(Hook.beforeCall("world", "net/minecraft/client/renderer/EntityRenderer",
"renderWorldPass", "func_175068_a", "(IFJ)V",
Expand Down
7 changes: 7 additions & 0 deletions java/core/src/main/java/prism/core/hook/Hook.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum At { HEAD, TAIL, BEFORE_CALL }
final int[] argLocals; // local variable slots passed to the handler
final boolean cancelable;
final Predicate<Object[]> handler;
/** Only exists on some clients (e.g. Forge's classes): no warning when missing. */
boolean optional;

private Hook(String id, String owner, String[] names, String desc, At at, String callOwner,
String[] callNames, String callDesc, int[] argLocals, boolean cancelable,
Expand Down Expand Up @@ -56,6 +58,11 @@ static Hook beforeCall(String id, String owner, String mcp, String srg, String d
new String[] {callMcp, callSrg}, callDesc, args, false, handler);
}

Hook optional() {
optional = true;
return this;
}

String key() { return "prism.hook." + id; }

String name(String mappings) { return pick(names, mappings); }
Expand Down
5 changes: 4 additions & 1 deletion java/core/src/main/java/prism/core/hook/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public int install() {
try {
cls = Class.forName(e.getKey().replace('/', '.'), false, gameLoader);
} catch (Throwable t) {
for (Hook h : list) log.warn("hook " + h.id + ": class " + e.getKey() + " not found");
for (Hook h : list) {
if (h.optional) log.info("hook " + h.id + ": skipped (" + e.getKey() + " not on this client)");
else log.warn("hook " + h.id + ": class " + e.getKey() + " not found");
}
continue;
}
Patcher.Result[] result = new Patcher.Result[1];
Expand Down
2 changes: 1 addition & 1 deletion tests/fake-game/src/net/minecraft/client/Minecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Object addScheduledTask(Runnable r) {
public static void run() throws Exception {
Thread.sleep(1500); // "loading"
theMinecraft = new Minecraft();
theMinecraft.ingameGUI = new GuiIngame();
theMinecraft.ingameGUI = new net.minecraftforge.client.GuiIngameForge();
System.out.println("GAME: started");
while (true) { // game loop, 50 fps, a tick every other frame
synchronized (theMinecraft.scheduledTasks) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.minecraftforge.client;
import net.minecraft.client.gui.GuiIngame;
/** Like Forge: overrides the HUD without calling the vanilla method. */
public class GuiIngameForge extends GuiIngame {
@Override
public void renderGameOverlay(float partialTicks) {
if (partialTicks > 100) return;
}
}
6 changes: 3 additions & 3 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ grep -q "mcp names" "$W/home/logs/prism.log" || fail "mappings not detected as m
echo "ok injected, core started on the game's class loader, plugin loaded, chat on client thread"

# hooks
grep -q "hooks placed: 4" "$W/home/logs/prism.log" || fail "not all 4 hooks placed"
grep -q "hooks placed: 5" "$W/home/logs/prism.log" || fail "not all 5 hooks placed"
wait_for "$W/home/logs/prism.log" "counts tick=[1-9][0-9]* overlay=[1-9][0-9]* world=[1-9]"
grep -q "overlay size 427x240 pt 0.5" "$W/home/logs/prism.log" || fail "overlay event values wrong"
wait_for "$W/out.txt" "DRAW text '§dPrism"
Expand Down Expand Up @@ -79,7 +79,7 @@ cp "$ROOT/java/example-plugin/build/libs/example-plugin.jar" "$W/home/plugins/ex
jcmd $GAME JVMTI.agent_load "$ROOT/target/debug/libprism_agent.so" "$W/home|$W/home/bin/prism-core.jar" >/dev/null
for _ in $(seq 1 100); do tail -n +$((LINES+1)) "$W/out.txt" | grep -q "Loaded Example" && break; sleep 0.1; done
tail -n +$((LINES+1)) "$W/out.txt" | grep -q "Loaded Example" || fail "re-inject didn't load"
for _ in $(seq 1 50); do grep -q "hooks placed: 4" "$W/home/logs/prism.log" && break; sleep 0.1; done
grep -q "hooks placed: 4" "$W/home/logs/prism.log" || fail "hooks not placed after re-inject"
for _ in $(seq 1 50); do grep -q "hooks placed: 5" "$W/home/logs/prism.log" && break; sleep 0.1; done
grep -q "hooks placed: 5" "$W/home/logs/prism.log" || fail "hooks not placed after re-inject"
echo "ok injected again, hooks placed again"
echo "ALL PASSED"
Loading