Add mod command integration for Build 42: command hooks, lookup extensions, registry, and validation mechanisms. Include corresponding tests and documentation.

This commit is contained in:
Overlord committed 2026-10-03 11:27:06 +02:00
1 parent 22077514fe
commit af7174e128
26 files changed
+1117 -30

No files matched your search

@@ -18,6 +18,8 @@ public final class B42PatchSet implements PatchSet
new ServerTickPatch(),
new ServerStoppingPatch(),
new BackupStoragePatch(),
new CommandLookupPatch(),
new CommandListPatch(),
new IsoZombieVehiclePerformancePatch(),
new IsoZombieNetworkComponentPerformancePatch(),
new IsoZombieSpotChancePerformancePatch(),
@@ -0,0 +1,32 @@
package dev.overlord.zomboidforge.compat.b42.patches;
import dev.overlord.zomboidforge.patcher.Anchor;
import dev.overlord.zomboidforge.patcher.Hook;
import dev.overlord.zomboidforge.patcher.Patches.ReturnHookPatch;
import org.objectweb.asm.Opcodes;
import java.util.List;
/**
* Makes {@code CommandBase.getSubClasses()} return
* {@code CommandHooks.listCommands(childrenClasses)}: Project Zomboid's command classes followed
* by the mods'. The {@code help} command lists commands through this method.
*/
public final class CommandListPatch extends ReturnHookPatch
{
/** The whole method: {@code getstatic childrenClasses}, {@code areturn}. */
private static final Anchor.Sequence ANCHOR = new Anchor.Sequence(
new Anchor.Method("getSubClasses", "()[Ljava/lang/Class;"),
new Anchor.Instruction.Opcode(Opcodes.GETSTATIC),
new Anchor.Instruction.Opcode(Opcodes.ARETURN)
);
private static final Hook HOOK = new Hook(
"dev/overlord/zomboidforge/compat/b42/hooks/CommandHooks", "listCommands", "([Ljava/lang/Class;)[Ljava/lang/Class;"
);
public CommandListPatch() {
super("zombie/commands/CommandBase", CommandListPatch.ANCHOR, CommandListPatch.HOOK, List.of());
}
}
@@ -0,0 +1,33 @@
package dev.overlord.zomboidforge.compat.b42.patches;
import dev.overlord.zomboidforge.patcher.Anchor;
import dev.overlord.zomboidforge.patcher.Hook;
import dev.overlord.zomboidforge.patcher.HookArgument;
import dev.overlord.zomboidforge.patcher.Patches.ReturnHookPatch;
import org.objectweb.asm.Opcodes;
import java.util.List;
/**
* Makes {@code CommandBase.findCommandCls(command)} return
* {@code CommandHooks.findCommand(null, command)} where it returns {@code null}: when no command
* of Project Zomboid matches, the mods' commands are searched. The server console, RCON, chat
* commands, and {@code help <name>} look commands up through this method.
*/
public final class CommandLookupPatch extends ReturnHookPatch
{
private static final Anchor.Sequence ANCHOR = new Anchor.Sequence(
new Anchor.Method("findCommandCls", "(Ljava/lang/String;)Ljava/lang/Class;"),
new Anchor.Instruction.Opcode(Opcodes.ACONST_NULL),
new Anchor.Instruction.Opcode(Opcodes.ARETURN)
);
private static final Hook HOOK = new Hook(
"dev/overlord/zomboidforge/compat/b42/hooks/CommandHooks", "findCommand", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Class;"
);
public CommandLookupPatch() {
super("zombie/commands/CommandBase", CommandLookupPatch.ANCHOR, CommandLookupPatch.HOOK, List.of(new HookArgument.Parameter(0)));
}
}