Refactor patching structure: introduce PerformancePatch class and relocate HookInjectionPatch to Patches package.
This commit is contained in:
1 parent
abc6c6c53e
commit
d7151f60e8
4 files changed
+59
-2
No files matched your search
+1
-1
@@ -2,7 +2,7 @@ package dev.overlord.zomboidforge.compat.b42.patches;
|
||||
|
||||
import dev.overlord.zomboidforge.patcher.Anchor;
|
||||
import dev.overlord.zomboidforge.patcher.Hook;
|
||||
import dev.overlord.zomboidforge.patcher.HookInjectionPatch;
|
||||
import dev.overlord.zomboidforge.patcher.Patches.HookInjectionPatch;
|
||||
|
||||
/**
|
||||
* Calls {@code ServerHooks.onServerStarted()} in {@code GameServer.main}, directly after
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
package dev.overlord.zomboidforge.patcher;
|
||||
package dev.overlord.zomboidforge.patcher.Patches;
|
||||
|
||||
import dev.overlord.zomboidforge.patcher.Anchor;
|
||||
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
||||
import dev.overlord.zomboidforge.patcher.Hook;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.overlord.zomboidforge.patcher.Patches;
|
||||
|
||||
import dev.overlord.zomboidforge.patcher.Anchor;
|
||||
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
||||
import dev.overlord.zomboidforge.patcher.GameVersion;
|
||||
import dev.overlord.zomboidforge.patcher.Hook;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Base class for patches that make a vanilla method cheaper without changing what it returns
|
||||
* or does. Unlike {@link HookInjectionPatch}, which only inserts a call, a performance patch
|
||||
* may rewrite instructions of the anchor method or add fields to the target class, so
|
||||
* {@link #apply} is left to the subclass.
|
||||
*
|
||||
* <p>{@link #appliesTo} has no default: every performance patch names the game versions it was
|
||||
* verified on.
|
||||
*/
|
||||
public abstract class PerformancePatch implements ClassPatch
|
||||
{
|
||||
private final String target;
|
||||
private final Anchor anchor;
|
||||
private final Hook hook;
|
||||
|
||||
/**
|
||||
* @param hook the runtime method the patched code calls, or {@code null} when the patch
|
||||
* only changes the target class itself
|
||||
*/
|
||||
protected PerformancePatch(String target, @NotNull Anchor anchor, @Nullable Hook hook)
|
||||
{
|
||||
this.target = Objects.requireNonNull(target);
|
||||
this.anchor = Objects.requireNonNull(anchor);
|
||||
this.hook = hook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String target() { return this.target; }
|
||||
@Override
|
||||
public final Anchor anchor() { return this.anchor; }
|
||||
@Override
|
||||
public final @Nullable Hook hook() { return this.hook; }
|
||||
|
||||
@Override
|
||||
public abstract boolean appliesTo(GameVersion version);
|
||||
|
||||
@Override
|
||||
public abstract void apply(ClassNode node);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.overlord.zomboidforge.patcher;
|
||||
|
||||
import dev.overlord.zomboidforge.patcher.Patches.HookInjectionPatch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
|
||||
Reference in new issue
Block a user