Annotate with @SuppressWarnings("NullableProblems"), clean up imports, and adjust nullability annotations for improved clarity and consistency.
This commit is contained in:
1 parent
c22aa29c88
commit
30b0b0572f
4 files changed
+14
-24
No files matched your search
@@ -7,6 +7,7 @@ import org.objectweb.asm.tree.ClassNode;
|
|||||||
|
|
||||||
/** A build-time change to one class of the vanilla server jar. */
|
/** A build-time change to one class of the vanilla server jar. */
|
||||||
@Internal
|
@Internal
|
||||||
|
@SuppressWarnings("NullableProblems")
|
||||||
public interface ClassPatch {
|
public interface ClassPatch {
|
||||||
/** Internal name of the class to patch, e.g. {@code zombie/network/GameServer}. */
|
/** Internal name of the class to patch, e.g. {@code zombie/network/GameServer}. */
|
||||||
String target();
|
String target();
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package dev.overlord.zomboidforge.patcher;
|
package dev.overlord.zomboidforge.patcher;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
|
|
||||||
@@ -7,15 +9,7 @@ import java.io.IOException;
|
|||||||
import java.io.UncheckedIOException;
|
import java.io.UncheckedIOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
@@ -84,7 +78,7 @@ public final class JarPatcher
|
|||||||
{
|
{
|
||||||
try (ZipFile zip = new ZipFile(jar.toFile()))
|
try (ZipFile zip = new ZipFile(jar.toFile()))
|
||||||
{
|
{
|
||||||
byte[] core = read(zip, GameVersionReader.CORE_CLASS + ".class");
|
byte[] core = JarPatcher.read(zip, GameVersionReader.CORE_CLASS + ".class");
|
||||||
if (core == null) throw new IllegalStateException("'" + jar + "' contains no " + GameVersionReader.CORE_CLASS + ".class");
|
if (core == null) throw new IllegalStateException("'" + jar + "' contains no " + GameVersionReader.CORE_CLASS + ".class");
|
||||||
|
|
||||||
return GameVersionReader.read(core);
|
return GameVersionReader.read(core);
|
||||||
@@ -104,12 +98,8 @@ public final class JarPatcher
|
|||||||
*/
|
*/
|
||||||
public static List<ClassPatch> applicablePatches(PatchSet patchSet, GameVersion version, Set<String> disabled)
|
public static List<ClassPatch> applicablePatches(PatchSet patchSet, GameVersion version, Set<String> disabled)
|
||||||
{
|
{
|
||||||
if (patchSet.build() != version.major()) {
|
if (patchSet.build() != version.major())
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException("Patch set is for Build " + patchSet.build() + ", but the server jar is Project Zomboid " + version + ".");
|
||||||
"Patch set is for Build " + patchSet.build()
|
|
||||||
+ ", but the server jar is Project Zomboid " + version
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> unknown = new TreeSet<>(disabled);
|
Set<String> unknown = new TreeSet<>(disabled);
|
||||||
patchSet.patches().forEach(patch -> unknown.remove(patch.getClass().getSimpleName()));
|
patchSet.patches().forEach(patch -> unknown.remove(patch.getClass().getSimpleName()));
|
||||||
@@ -218,7 +208,7 @@ public final class JarPatcher
|
|||||||
patch.apply(node);
|
patch.apply(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
HierarchyClassWriter writer = new HierarchyClassWriter(name -> read(jar, name + ".class"));
|
HierarchyClassWriter writer = new HierarchyClassWriter(name -> Objects.requireNonNull(JarPatcher.read(jar, name + ".class")));
|
||||||
node.accept(writer);
|
node.accept(writer);
|
||||||
|
|
||||||
return writer.toByteArray();
|
return writer.toByteArray();
|
||||||
@@ -230,7 +220,7 @@ public final class JarPatcher
|
|||||||
catch (IllegalStateException e) { throw new IllegalStateException("'" + patch.getClass().getSimpleName() + "': " + e.getMessage(), e); }
|
catch (IllegalStateException e) { throw new IllegalStateException("'" + patch.getClass().getSimpleName() + "': " + e.getMessage(), e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] read(ZipFile jar, String entryName)
|
private static byte @Nullable [] read(ZipFile jar, String entryName)
|
||||||
{
|
{
|
||||||
ZipEntry entry = jar.getEntry(entryName);
|
ZipEntry entry = jar.getEntry(entryName);
|
||||||
if (entry == null) return null;
|
if (entry == null) return null;
|
||||||
|
|||||||
+2
-3
@@ -3,7 +3,6 @@ package dev.overlord.zomboidforge.patcher.Patches;
|
|||||||
import dev.overlord.zomboidforge.patcher.Anchor;
|
import dev.overlord.zomboidforge.patcher.Anchor;
|
||||||
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
||||||
import dev.overlord.zomboidforge.patcher.Hook;
|
import dev.overlord.zomboidforge.patcher.Hook;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
@@ -24,7 +23,7 @@ public abstract class HookInjectionPatch implements ClassPatch
|
|||||||
private final Anchor.Call anchor;
|
private final Anchor.Call anchor;
|
||||||
private final Hook hook;
|
private final Hook hook;
|
||||||
|
|
||||||
protected HookInjectionPatch(String target, Anchor.Call anchor, @NotNull Hook hook)
|
protected HookInjectionPatch(String target, Anchor.Call anchor, Hook hook)
|
||||||
{
|
{
|
||||||
if (!hook.desc().equals(HookInjectionPatch.HOOK_DESC))
|
if (!hook.desc().equals(HookInjectionPatch.HOOK_DESC))
|
||||||
throw new IllegalArgumentException("Hook '" + hook + "' must have descriptor '" + HookInjectionPatch.HOOK_DESC + "'.");
|
throw new IllegalArgumentException("Hook '" + hook + "' must have descriptor '" + HookInjectionPatch.HOOK_DESC + "'.");
|
||||||
@@ -39,7 +38,7 @@ public abstract class HookInjectionPatch implements ClassPatch
|
|||||||
@Override
|
@Override
|
||||||
public final Anchor.Call anchor() { return this.anchor; }
|
public final Anchor.Call anchor() { return this.anchor; }
|
||||||
@Override
|
@Override
|
||||||
public final @NotNull Hook hook() { return this.hook; }
|
public final Hook hook() { return this.hook; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void apply(ClassNode node)
|
public final void apply(ClassNode node)
|
||||||
|
|||||||
+3
-3
@@ -4,7 +4,7 @@ import dev.overlord.zomboidforge.patcher.Anchor;
|
|||||||
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
import dev.overlord.zomboidforge.patcher.ClassPatch;
|
||||||
import dev.overlord.zomboidforge.patcher.GameVersion;
|
import dev.overlord.zomboidforge.patcher.GameVersion;
|
||||||
import dev.overlord.zomboidforge.patcher.Hook;
|
import dev.overlord.zomboidforge.patcher.Hook;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
@@ -24,13 +24,13 @@ public abstract class PerformancePatch implements ClassPatch
|
|||||||
{
|
{
|
||||||
private final String target;
|
private final String target;
|
||||||
private final Anchor anchor;
|
private final Anchor anchor;
|
||||||
private final Hook hook;
|
private final @Nullable Hook hook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param hook the runtime method the patched code calls, or {@code null} when the patch
|
* @param hook the runtime method the patched code calls, or {@code null} when the patch
|
||||||
* only changes the target class itself
|
* only changes the target class itself
|
||||||
*/
|
*/
|
||||||
protected PerformancePatch(String target, @NotNull Anchor anchor, @Nullable Hook hook)
|
protected PerformancePatch(String target, Anchor anchor, @Nullable Hook hook)
|
||||||
{
|
{
|
||||||
this.target = Objects.requireNonNull(target);
|
this.target = Objects.requireNonNull(target);
|
||||||
this.anchor = Objects.requireNonNull(anchor);
|
this.anchor = Objects.requireNonNull(anchor);
|
||||||
|
|||||||
Reference in new issue
Block a user