Allow goats in Sigma mountain biomes
This commit is contained in:
parent
1309c4d338
commit
903e21dbe6
1 changed files with 117 additions and 4 deletions
40
tools/SigmaGoatMerge.java
Normal file
40
tools/SigmaGoatMerge.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
class SigmaGoatMerge {
|
||||
public static void main(String[] args) throws Exception {
|
||||
var reader = new ClassReader(Files.readAllBytes(Path.of(args[0])));
|
||||
var retained = new ClassNode();
|
||||
reader.accept(retained, 0);
|
||||
if (!retained.name.equals("com/example/duneterrain/PlanetMobs")
|
||||
|| retained.methods.stream().noneMatch(m -> m.name.equals("allowedColdPig"))) {
|
||||
throw new IllegalArgumentException("Expected the retained Sigma cold-pig baseline");
|
||||
}
|
||||
var allowed = retained.methods.stream()
|
||||
.filter(m -> m.name.equals("allowed") && m.desc.equals("(Ljava/lang/String;Ljava/lang/String;Z)Z"))
|
||||
.findFirst().orElseThrow();
|
||||
var resume = new LabelNode();
|
||||
var patch = new InsnList();
|
||||
match(patch, "sigma_draconis_iv", 0, resume);
|
||||
match(patch, "GOAT", 1, resume);
|
||||
patch.add(new InsnNode(Opcodes.ICONST_1));
|
||||
patch.add(new InsnNode(Opcodes.IRETURN));
|
||||
patch.add(resume);
|
||||
patch.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
|
||||
allowed.instructions.insert(patch);
|
||||
var writer = new ClassWriter(reader, 0);
|
||||
retained.accept(writer);
|
||||
Files.write(Path.of(args[1]), writer.toByteArray());
|
||||
}
|
||||
|
||||
private static void match(InsnList patch, String value, int local, LabelNode resume) {
|
||||
patch.add(new LdcInsnNode(value));
|
||||
patch.add(new VarInsnNode(Opcodes.ALOAD, local));
|
||||
patch.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false));
|
||||
patch.add(new JumpInsnNode(Opcodes.IFEQ, resume));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff