forked from unimatrix/web
Fresh production baseline [skip ci]
This commit is contained in:
commit
0a11a18274
1 changed files with 229644 additions and 0 deletions
25
tools/PatchArrakisUpgrade.java
Normal file
25
tools/PatchArrakisUpgrade.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import java.nio.file.*;import java.security.*;import java.util.*;import java.util.zip.*;
|
||||
import org.objectweb.asm.*;import org.objectweb.asm.tree.*;
|
||||
/** Bounded transplant onto the exact current Arrakeen build; no outer bootstrap replacement. */
|
||||
public final class PatchArrakisUpgrade {
|
||||
static final String ROOT="com/example/duneterrain/",MAIN=ROOT+"DuneTerrain";
|
||||
static byte[] patch(byte[] original,byte[] compiled,Set<String> names){
|
||||
var before=new ClassNode();new ClassReader(original).accept(before,0);var newer=new ClassNode();new ClassReader(compiled).accept(newer,0);var changed=new HashSet<String>();
|
||||
for(int i=0;i<before.methods.size();i++){var old=before.methods.get(i);if(!names.contains(old.name))continue;var replacement=newer.methods.stream().filter(m->m.name.equals(old.name)&&m.desc.equals(old.desc)).findFirst().orElseThrow();before.methods.set(i,replacement);changed.add(old.name);}
|
||||
for(String name:names)if(!changed.contains(name)&&Set.of("shouldGenerateStructures","shouldGenerateCaves","shouldGenerateMobs","shouldGenerateDecorations","generateCaves","getBaseHeight").contains(name)){var additions=newer.methods.stream().filter(m->m.name.equals(name)).toList();if(additions.size()!=1)throw new IllegalStateException("Ambiguous native override");before.methods.add(additions.getFirst());changed.add(name);}
|
||||
if(!changed.equals(names))throw new IllegalStateException("Method set changed: "+changed);
|
||||
var writer=new ClassWriter(0);before.accept(writer);return writer.toByteArray();
|
||||
}
|
||||
public static void main(String[] args)throws Exception{
|
||||
Path input=Path.of(args[0]),classes=Path.of(args[1]),output=Path.of(args[2]);String expected=args[3];
|
||||
if(!HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(input))).equals(expected)||Files.exists(output))throw new IllegalStateException("Baseline/output changed");
|
||||
var entries=new LinkedHashMap<String,byte[]>();try(var zip=new ZipInputStream(Files.newInputStream(input))){for(ZipEntry e;(e=zip.getNextEntry())!=null;)entries.put(e.getName(),zip.readAllBytes());}
|
||||
for(var spec:Map.of(MAIN+"$PlanetChunkGenerator",Set.of("placeOres","placeDarkstoneIsland","shouldGenerateStructures","shouldGenerateCaves","shouldGenerateMobs","shouldGenerateDecorations","generateCaves","getBaseHeight"),MAIN+"$SietchPopulator",Set.of("populate","populateHighlands")).entrySet()){
|
||||
String path=spec.getKey()+".class";entries.put(path,patch(entries.get(path),Files.readAllBytes(classes.resolve(path)),spec.getValue()));
|
||||
}
|
||||
try(var paths=Files.list(classes.resolve(ROOT))){for(var file:paths.filter(p->p.getFileName().toString().matches("(?:ArrakisEcology|RockPlateaus|SietchReservoirs|OceanAquifers|TemperateLandscape)(?:\\$[A-Za-z0-9]+)?\\.class")).toList())entries.put(ROOT+file.getFileName(),Files.readAllBytes(file));}
|
||||
String descriptor=new String(entries.get("plugin.yml"),java.nio.charset.StandardCharsets.UTF_8);entries.put("plugin.yml",descriptor.replaceAll("(?m)^version:.*$","version: 1.0.12-arrakeen1-worlds2").getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
try(var zip=new ZipOutputStream(Files.newOutputStream(output,StandardOpenOption.CREATE_NEW))){for(var row:entries.entrySet()){var entry=new ZipEntry(row.getKey());entry.setTime(0);zip.putNextEntry(entry);zip.write(row.getValue());zip.closeEntry();}}
|
||||
System.out.println("Retained original bootstrap and unrelated entries. SHA256 "+HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(output))));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue

Staff