fix accesswidener application, rename project
This commit is contained in:
parent
0e826dac3a
commit
1fdb459433
|
@ -2,7 +2,7 @@ import org.ecorous.esnesnon.gradle.ext.minecraft
|
|||
|
||||
plugins {
|
||||
java
|
||||
id("org.ecorous.esnesnon.nonsense-gradle").version("0.0.1-SNAPSHOT")
|
||||
id("org.ecorous.esnesnon.phytotelma") version "0.0.1-SNAPSHOT"
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
|
3
minecraft/src/main/resources/example_mod.accesswidener
Normal file
3
minecraft/src/main/resources/example_mod.accesswidener
Normal file
|
@ -0,0 +1,3 @@
|
|||
accessWidener v2 named
|
||||
|
||||
accessible method net/minecraft/world/level/block/TransparentBlock codec ()Lcom/mojang/serialization/MapCodec;
|
|
@ -21,4 +21,5 @@ breaks = [
|
|||
[frog.extensions]
|
||||
pre_launch = "org.ecorous.esnesnon.nonsense.loader.example.ExamplePreLaunchExtension"
|
||||
mixin_config = "example_mod.mixins.json"
|
||||
frog_aw = "example_mod.accesswidener"
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ pluginManagement {
|
|||
}
|
||||
}
|
||||
|
||||
rootProject.name = "nonsense-loader"
|
||||
rootProject.name = "frogloader"
|
||||
|
||||
include(":minecraft")
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import java.nio.file.*;
|
|||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.ecorous.esnesnon.nonsense.loader.api.mod.ModProperties;
|
||||
|
@ -23,18 +23,19 @@ import org.objectweb.asm.*;
|
|||
class AWProcessor {
|
||||
|
||||
private static final String AW_EXTENSION_NAME = BuiltinExtensions.ACCESSWIDENER;
|
||||
private static final Predicate<String> HEADER = Pattern.compile("accessWidener\\s+v[12]").asMatchPredicate();
|
||||
private static final Predicate<String> HEADER = Pattern.compile("accessWidener\\s+v[12]\\s+.*").asMatchPredicate();
|
||||
private static final Predicate<String> COMMENT = Pattern.compile("^#.*").asMatchPredicate();
|
||||
private static final Pattern SEPARATOR = Pattern.compile("[\\t ]+");
|
||||
private static final String SEPARATOR = "[\\t ]+";
|
||||
|
||||
static void apply(Collection<ModProperties> mods, Path input, Path output) throws IOException {
|
||||
List<Entry> entries = mods.parallelStream().map(ModProperties::extensions).map(e -> (String)e.get(AW_EXTENSION_NAME))
|
||||
.filter(Objects::nonNull).map(AWProcessor.class::getResourceAsStream).filter(Objects::nonNull)
|
||||
.filter(Objects::nonNull).map(s -> "/"+s).map(AWProcessor.class::getResourceAsStream).filter(Objects::nonNull)
|
||||
.map(InputStreamReader::new).map(BufferedReader::new).flatMap(BufferedReader::lines)
|
||||
.filter(l -> !l.isBlank()).filter(l -> !COMMENT.test(l)).filter(l -> !HEADER.test(l)).distinct()
|
||||
.map(l -> l.replace("transitive-", "")) // ignore all transitive declarations (just make them normal) as they're only relevant for dev envs
|
||||
.map(SEPARATOR::matcher).filter(Matcher::matches).map(Entry::new).toList();
|
||||
.map(l -> l.split(SEPARATOR)).filter(l -> l.length > 0).map(Entry::new).toList();
|
||||
|
||||
System.out.println(entries.stream().map(Entry::toString).collect(Collectors.joining()));
|
||||
Map<String, Entry> classMap = new HashMap<>();
|
||||
Map<String, Map<String, Entry>> methods = new HashMap<>();
|
||||
Map<String, Map<String, Entry>> fields = new HashMap<>();
|
||||
|
@ -98,9 +99,8 @@ class AWProcessor {
|
|||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
Path output = out.getPath(file.toString());
|
||||
Files.createDirectories(output.getParent());
|
||||
if (file.getFileName().toString().endsWith(".class")) {
|
||||
|
||||
var className = file.toString().substring(0, file.toString().length() - 6);
|
||||
var className = file.toString().substring(1, file.toString().length() - 6);
|
||||
if (file.getFileName().toString().endsWith(".class") && (classMap.containsKey(className) || fields.containsKey(className) || methods.containsKey(className) || mutations.containsKey(className))) {
|
||||
ClassReader reader = new ClassReader(Files.newInputStream(file));
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
ClassVisitor mapper = new ClassVisitor(Opcodes.ASM9, writer) {
|
||||
|
@ -108,10 +108,10 @@ class AWProcessor {
|
|||
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||
Entry e = classMap.get(className);
|
||||
if (e != null) {
|
||||
access = ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
access |= e.type.access;
|
||||
} else if (fields.containsKey(className) || methods.containsKey(className) || mutations.containsKey(className)) { // make all classes with modifications public as well
|
||||
access = ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
access |= Opcodes.ACC_PUBLIC;
|
||||
}
|
||||
super.visit(version, access, name, signature, superName, interfaces);
|
||||
|
@ -123,7 +123,7 @@ class AWProcessor {
|
|||
if (map != null) {
|
||||
Entry e = map.get(name + descriptor);
|
||||
if (e != null) {
|
||||
access = ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); // remove all access modifiers
|
||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC); // remove all access modifiers
|
||||
access |= e.type.access; // re-add the new one
|
||||
}
|
||||
}
|
||||
|
@ -142,8 +142,10 @@ class AWProcessor {
|
|||
if (map != null) {
|
||||
Entry e = map.get(name + descriptor);
|
||||
if (e != null) {
|
||||
access = ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
int old = access;
|
||||
access &= ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED | Opcodes.ACC_PUBLIC);
|
||||
access |= e.type.access;
|
||||
System.out.println("set access of "+name+" from "+old+" to "+access);
|
||||
}
|
||||
}
|
||||
return super.visitMethod(access, name, descriptor, signature, exceptions);
|
||||
|
@ -164,8 +166,8 @@ class AWProcessor {
|
|||
|
||||
private record Entry(AccessType type, String targetType, String className, String name, String descriptor) {
|
||||
|
||||
public Entry(Matcher line) {
|
||||
this(AccessType.of(line.group(1)), line.group(2), line.group(3), line.group(4), line.group(5));
|
||||
public Entry(String[] line) {
|
||||
this(AccessType.of(line[0]), line[1], line[2], line[3], line[4]);
|
||||
}
|
||||
|
||||
public boolean isAccessGreaterThan(Entry other) {
|
||||
|
|
|
@ -92,16 +92,15 @@ public class Minecraft implements NonsensePlugin {
|
|||
}
|
||||
});
|
||||
|
||||
if (!Files.exists(remappedGamePath)) {
|
||||
if (!loader.isDevelopment()) {
|
||||
if (!Files.exists(remappedGamePath)) {
|
||||
NonsenseRemapper.run(version, gamePath, remappedGamePath, true, false);
|
||||
} else {
|
||||
Files.copy(gamePath, remappedGamePath);
|
||||
}
|
||||
}
|
||||
|
||||
var awIn = loader.isDevelopment() ? gamePath : remappedGamePath;
|
||||
Path runtimePath = remappedGamePath.resolveSibling("game-" + version + "-runtime.jar");
|
||||
AWProcessor.apply(modProperties, remappedGamePath, runtimePath);
|
||||
AWProcessor.apply(modProperties, awIn, runtimePath);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
try {
|
||||
Files.deleteIfExists(runtimePath);
|
||||
|
|
Loading…
Reference in a new issue