From c9e41e2c91be8b7517a73b8f0adae8f1189fd7ec Mon Sep 17 00:00:00 2001 From: Overlord Date: Thu, 1 Oct 2026 14:00:23 +0200 Subject: [PATCH 1/5] Document `FORGE_VERSION` default and new `DISABLED_PATCHES` option in README, update Dockerfile to reflect default `FORGE_VERSION`. --- Dockerfile | 6 +++--- README.md | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6ea2e67..c4ad651 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ ARG PZ_BRANCH=public ARG PZ_VERSION="" ARG STEAMCLIENT=bundled -ARG FORGE_VERSION="" +ARG FORGE_VERSION="0.0.0-prerelease" ARG STEAM_BUILDID="" # --- Stage 1: vanilla dedicated server ----------------------------------------- @@ -53,8 +53,8 @@ COPY agent agent COPY patcher patcher COPY --from=server /server/java/projectzomboid.jar /pz/projectzomboid.jar -# An empty PZ_VERSION keeps pz.version from gradle.properties; an empty FORGE_VERSION gives -# the build the fallback version 0.0.0-prerelease (the image has no git history). +# An empty PZ_VERSION keeps pz.version from gradle.properties. FORGE_VERSION always has a +# value (default 0.0.0-prerelease): this stage has no git, so the version cannot come from a tag. ARG PZ_VERSION ARG FORGE_VERSION ARG DISABLED_PATCHES="" diff --git a/README.md b/README.md index 4312723..80817cd 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ podman build --platform linux/amd64 -t zomboidforge . # or: docker build ... | `PZ_BRANCH` | `public` | Steam branch: `public`, `unstable`, or a version branch such as `42.19` | | `PZ_VERSION` | `pz.version` | Expected Project Zomboid version | | `STEAMCLIENT` | `bundled` | `steamcmd` replaces the server's `steamclient.so` files with steamcmd's newer copies (workaround for failing Workshop downloads) | +| `FORGE_VERSION` | `0.0.0-prerelease` | ZomboidForge version (jar manifest, image label). The build stage has no `git`, so the version is never read from a tag there; `ci/release.sh` passes it | +| `DISABLED_PATCHES` | | Comma-separated simple class names of build-time patches to skip (debug builds only), e.g. `IsoZombieVehiclePerformancePatch` | Published images are tagged `-pz-build` (immutable), `-pz`, and `latest`. From 1a53f833e3c46d7f9bc29329aa0b941403e02655 Mon Sep 17 00:00:00 2001 From: Overlord Date: Thu, 1 Oct 2026 14:16:44 +0200 Subject: [PATCH 2/5] Add and test `Anchor.Sequence` to match instruction patterns, skipping labels and line numbers. Document sequence matching behavior and integrate new matchers (constant, opcode, invoke). --- .../overlord/zomboidforge/patcher/Anchor.java | 137 ++++++++++++++++++ .../zomboidforge/patcher/AnchorTest.java | 117 +++++++++++++++ 2 files changed, 254 insertions(+) diff --git a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Anchor.java b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Anchor.java index 6bad840..b24d152 100644 --- a/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Anchor.java +++ b/patcher/src/main/java/dev/overlord/zomboidforge/patcher/Anchor.java @@ -1,12 +1,19 @@ package dev.overlord.zomboidforge.patcher; +import org.jetbrains.annotations.Nullable; + +import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.IntInsnNode; +import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.util.Printer; import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * The landmark in the target class that a {@link ClassPatch} depends on. A patch can only @@ -71,4 +78,134 @@ public sealed interface Anchor && call.desc.equals(this.desc); } } + + /** + * Consecutive instructions inside the method {@code in}, one per element of {@code pattern}. + * Labels, line numbers and stack map frames between them are skipped, so a jump target or a + * new source line inside the sequence does not break a match. Overlapping matches count + * separately. + */ + record Sequence(Method in, List pattern) implements Anchor + { + public Sequence + { + if (pattern.isEmpty()) throw new IllegalArgumentException("A sequence anchor needs at least one instruction."); + + pattern = List.copyOf(pattern); + } + + public Sequence(Method in, Instruction... pattern) { this(in, List.of(pattern)); } + + /** The matched instructions, one per element of {@link #pattern()}, in the same order. */ + public List resolve(ClassNode node) + { + List instructions = Sequence.realInstructions(this.in.resolve(node)); + List> matches = new ArrayList<>(); + + for (int start = 0; start + this.pattern.size() <= instructions.size(); start++) { + List candidate = instructions.subList(start, start + this.pattern.size()); + if (this.matches(candidate)) matches.add(candidate); + } + + if (matches.size() != 1) { + throw new IllegalStateException( + "Expected exactly one sequence " + this.pattern + " in '" + node.name + "." + this.in.name() + this.in.desc() + + "', found " + matches.size() + ); + } + + return List.copyOf(matches.getFirst()); + } + + @Override + public void verify(ClassNode node) { this.resolve(node); } + + private boolean matches(List candidate) + { + for (int i = 0; i < candidate.size(); i++) { + if (!this.pattern.get(i).matches(candidate.get(i))) return false; + } + + return true; + } + + /** The instructions of {@code method} without labels, line numbers and frames (opcode -1). */ + private static List realInstructions(MethodNode method) + { + List instructions = new ArrayList<>(); + + for (AbstractInsnNode instruction : method.instructions) { + if (instruction.getOpcode() != -1) instructions.add(instruction); + } + + return instructions; + } + } + + /** One element of a {@link Sequence}: a test for a single instruction. */ + sealed interface Instruction + { + boolean matches(AbstractInsnNode instruction); + + /** Any instruction with this opcode, e.g. {@code Opcodes.FSTORE} for a store to any local variable. */ + record Opcode(int opcode) implements Instruction + { + public Opcode + { + if (opcode < 0 || opcode >= Printer.OPCODES.length) throw new IllegalArgumentException("Not an opcode: " + opcode); + } + + @Override + public boolean matches(AbstractInsnNode instruction) { return instruction.getOpcode() == this.opcode; } + + @Override + public String toString() { return Printer.OPCODES[this.opcode].toLowerCase(Locale.ROOT); } + } + + /** + * A constant push of {@code value}: {@code ldc}, or the shorter forms used for small + * values ({@code iconst_}, {@code lconst_}, {@code fconst_}, {@code dconst_}, + * {@code bipush}, {@code sipush}). The boxed type has to match: {@code 0} (an + * {@code Integer}) does not match {@code fconst_0}. A class literal is an + * {@link org.objectweb.asm.Type}. + */ + record Constant(Object value) implements Instruction + { + @Override + public boolean matches(AbstractInsnNode instruction) { return this.value.equals(Constant.valueOf(instruction)); } + + @Override + public String toString() { return "constant " + this.value; } + + private static @Nullable Object valueOf(AbstractInsnNode instruction) + { + int opcode = instruction.getOpcode(); + + if (instruction instanceof LdcInsnNode ldc) return ldc.cst; + if (opcode == Opcodes.BIPUSH || opcode == Opcodes.SIPUSH) return ((IntInsnNode) instruction).operand; + if (opcode >= Opcodes.ICONST_M1 && opcode <= Opcodes.ICONST_5) return opcode - Opcodes.ICONST_0; + if (opcode >= Opcodes.LCONST_0 && opcode <= Opcodes.LCONST_1) return (long) (opcode - Opcodes.LCONST_0); + if (opcode >= Opcodes.FCONST_0 && opcode <= Opcodes.FCONST_2) return (float) (opcode - Opcodes.FCONST_0); + if (opcode >= Opcodes.DCONST_0 && opcode <= Opcodes.DCONST_1) return (double) (opcode - Opcodes.DCONST_0); + + return null; + } + } + + /** A static, virtual, special or interface call to {@code owner.name desc}. */ + record Invoke(String owner, String name, String desc) implements Instruction + { + @Override + public boolean matches(AbstractInsnNode instruction) + { + return instruction instanceof MethodInsnNode call + && call.owner.equals(this.owner) + && call.name.equals(this.name) + && call.desc.equals(this.desc); + } + + @Override + public String toString() { return "invoke '" + this.owner + "." + this.name + this.desc + "'"; } + } + } } diff --git a/patcher/src/test/java/dev/overlord/zomboidforge/patcher/AnchorTest.java b/patcher/src/test/java/dev/overlord/zomboidforge/patcher/AnchorTest.java index ca30463..bdcb240 100644 --- a/patcher/src/test/java/dev/overlord/zomboidforge/patcher/AnchorTest.java +++ b/patcher/src/test/java/dev/overlord/zomboidforge/patcher/AnchorTest.java @@ -2,15 +2,32 @@ package dev.overlord.zomboidforge.patcher; import org.junit.jupiter.api.Test; import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnList; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.IntInsnNode; +import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.tree.LineNumberNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.VarInsnNode; + +import java.util.List; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.objectweb.asm.Opcodes.ACC_STATIC; +import static org.objectweb.asm.Opcodes.BIPUSH; +import static org.objectweb.asm.Opcodes.FCONST_0; +import static org.objectweb.asm.Opcodes.FSTORE; +import static org.objectweb.asm.Opcodes.ICONST_M1; import static org.objectweb.asm.Opcodes.INVOKESTATIC; +import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL; +import static org.objectweb.asm.Opcodes.LCONST_1; import static org.objectweb.asm.Opcodes.RETURN; class AnchorTest @@ -18,6 +35,12 @@ class AnchorTest private static final Anchor.Method RUN = new Anchor.Method("run", "()V"); private static final Anchor.Call CALL = new Anchor.Call(RUN, "t/Dep", "go", "()V"); + private static final Anchor.Sequence FORCED_STORE = new Anchor.Sequence( + RUN, + new Anchor.Instruction.Constant(1000000.0F), + new Anchor.Instruction.Opcode(FSTORE) + ); + private static ClassNode classWithRun(int callsToGo) { ClassNode node = new ClassNode(); @@ -75,4 +98,98 @@ class AnchorTest assertDoesNotThrow(() -> AnchorTest.CALL.verify(node)); } + + /** {@code run()V} with {@code ldc 1000000.0F;