Skip to content

Commit

Permalink
Move things around a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Su5eD committed Jul 18, 2024
1 parent 1f0604d commit 4c3e67f
Show file tree
Hide file tree
Showing 100 changed files with 401 additions and 1,150 deletions.
26 changes: 2 additions & 24 deletions definition/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ java {
withSourcesJar()
}

val testClasses: SourceSet by sourceSets.creating

repositories {
mavenCentral()
maven {
Expand All @@ -43,22 +41,16 @@ dependencies {
implementation(group = "com.mojang", name = "logging", version = "1.1.1")
implementation(group = "com.google.guava", "guava", version = "32.1.2-jre")
implementation(group = "org.slf4j", "slf4j-api", "2.0.0")
"testClassesImplementation"(implementation(group = "net.fabricmc", name = "sponge-mixin", version = "0.14.0+mixin.0.8.6"))
implementation(group = "net.fabricmc", name = "sponge-mixin", version = "0.14.0+mixin.0.8.6")
compileOnly(group = "org.jetbrains", name = "annotations", version = "24.0.1")
"testClassesImplementation"(implementation(group = "io.github.llamalad7", name = "mixinextras-common", version = "0.3.1"))
implementation(group = "io.github.llamalad7", name = "mixinextras-common", version = "0.3.1")

api(platform("org.ow2.asm:asm-bom:9.5"))
api(group = "org.ow2.asm", name = "asm")
api(group = "org.ow2.asm", name = "asm-commons")
api(group = "org.ow2.asm", name = "asm-tree")
api(group = "org.ow2.asm", name = "asm-analysis")
api(group = "org.ow2.asm", name = "asm-util")

testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.assertj:assertj-core:3.25.1")

"testRuntimeOnly"(testClasses.output)
}

tasks {
Expand All @@ -67,20 +59,6 @@ tasks {
"Implementation-Version" to project.version
)
}

test {
useJUnitPlatform()
systemProperty("adapter.definition.paramdiff.debug", true)
outputs.upToDateWhen { false }
}

named("compileTestClassesJava", JavaCompile::class.java) {
options.compilerArgs = listOf("-parameters")
}

named("testClasses") {
dependsOn("compileTestClassesJava")
}
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.objectweb.asm.commons.InstructionAdapter;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.sinytra.adapter.patch.api.ClassTransform;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.api.MixinConstants;
import org.sinytra.adapter.patch.api.PatchEnvironment;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.selector.InjectionPointMatcher;
import org.sinytra.adapter.patch.selector.MethodMatcher;
import org.sinytra.adapter.patch.serialization.MethodTransformSerialization;
import org.sinytra.adapter.patch.transformer.*;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.InjectionPointMatcher;
import org.sinytra.adapter.patch.analysis.selector.MethodMatcher;
import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization;
import org.sinytra.adapter.patch.transformer.operation.DisableMixin;
import org.sinytra.adapter.patch.transformer.operation.DivertRedirectorTransform;
import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionPoint;
import org.sinytra.adapter.patch.util.MethodQualifier;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -138,28 +137,11 @@ public ClassPatchBuilder modifyInjectionPoint(String value, String target, boole
return transform(new ModifyInjectionPoint(value, target, resetValues, dontUpgrade));
}

@Override
public ClassPatchBuilder redirectShadowMethod(String original, String target, BiConsumer<MethodInsnNode, InsnList> callFixer) {
return transform(new RedirectShadowMethod(original, target, callFixer));
}

@Override
public ClassPatchBuilder divertRedirector(Consumer<InstructionAdapter> patcher) {
return transform(new DivertRedirectorTransform(patcher));
}

@Override
public ClassPatchBuilder updateRedirectTarget(String originalTarget, String newTarget) {
return targetInjectionPoint(originalTarget)
.transform(new ModifyRedirectToWrapper(
MethodQualifier.create(originalTarget).orElseThrow(),
MethodQualifier.create(newTarget).orElseThrow()
))
.modifyMixinType(MixinConstants.WRAP_OPERATION, b -> b
.sameTarget()
.injectionPoint("INVOKE", newTarget));
}

@Override
public ClassPatchBuilder disable() {
return transform(DisableMixin.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.api.MixinConstants;
import org.sinytra.adapter.patch.api.PatchEnvironment;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.FieldMatcher;
import org.sinytra.adapter.patch.serialization.MethodTransformSerialization;
import org.sinytra.adapter.patch.transformer.RedirectAccessor;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.FieldMatcher;
import org.sinytra.adapter.patch.transformer.serialization.MethodTransformSerialization;
import org.sinytra.adapter.patch.util.AdapterUtil;

import java.util.Collection;
Expand Down Expand Up @@ -89,11 +88,6 @@ public InterfacePatchBuilder targetField(String... targets) {
return this;
}

@Override
public InterfacePatchBuilder modifyValue(String value) {
return transform(new RedirectAccessor(value));
}

@Override
public PatchInstance build() {
return new InterfacePatchInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.sinytra.adapter.patch.api.MethodContext;
import org.sinytra.adapter.patch.api.MixinConstants;
import org.sinytra.adapter.patch.api.PatchContext;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.util.AdapterUtil;
import org.sinytra.adapter.patch.util.MethodQualifier;
import org.sinytra.adapter.patch.util.MockMixinRuntime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.sinytra.adapter.patch.api.*;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.transformer.ModifyTargetClasses;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.transformer.operation.ModifyTargetClasses;
import org.sinytra.adapter.patch.util.MethodTransformBuilderImpl;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sinytra.adapter.patch.transformer;
package org.sinytra.adapter.patch.analysis;

import it.unimi.dsi.fastutil.ints.Int2IntArrayMap;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import org.objectweb.asm.tree.*;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.transformer.param.TransformParameters;
import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters;
import org.sinytra.adapter.patch.util.AdapterUtil;
import org.sinytra.adapter.patch.util.OpcodeUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.transformer.param.*;
import org.sinytra.adapter.patch.transformer.operation.param.*;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import org.objectweb.asm.tree.LocalVariableNode;
import org.objectweb.asm.tree.MethodNode;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.transformer.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.param.InjectParameterTransform;
import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget;
import org.sinytra.adapter.patch.transformer.param.ParameterTransformer;
import org.sinytra.adapter.patch.transformer.param.TransformParameters;
import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform;
import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget;
import org.sinytra.adapter.patch.transformer.operation.param.ParameterTransformer;
import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters;
import org.sinytra.adapter.patch.util.AdapterUtil;
import org.sinytra.adapter.patch.util.GeneratedVariables;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.mojang.datafixers.util.Pair;
import org.objectweb.asm.Type;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget;
import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import org.objectweb.asm.commons.InstructionAdapter;
import org.sinytra.adapter.patch.api.MethodTransform;
import org.sinytra.adapter.patch.transformer.BundledMethodTransform;
import org.sinytra.adapter.patch.transformer.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.param.InjectParameterTransform;
import org.sinytra.adapter.patch.transformer.param.ParamTransformTarget;
import org.sinytra.adapter.patch.transformer.param.ParameterTransformer;
import org.sinytra.adapter.patch.transformer.param.TransformParameters;
import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.operation.param.InjectParameterTransform;
import org.sinytra.adapter.patch.transformer.operation.param.ParamTransformTarget;
import org.sinytra.adapter.patch.transformer.operation.param.ParameterTransformer;
import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters;
import org.sinytra.adapter.patch.util.AdapterUtil;
import org.slf4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.sinytra.adapter.patch.selector;
package org.sinytra.adapter.patch.analysis.selector;

import org.objectweb.asm.tree.AnnotationNode;

import java.util.*;
import java.util.stream.Stream;

public final class AnnotationHandle {
private AnnotationNode annotationNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sinytra.adapter.patch.selector;
package org.sinytra.adapter.patch.analysis.selector;

import org.objectweb.asm.tree.AnnotationNode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sinytra.adapter.patch.selector;
package org.sinytra.adapter.patch.analysis.selector;

import com.mojang.serialization.Codec;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sinytra.adapter.patch.selector;
package org.sinytra.adapter.patch.analysis.selector;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sinytra.adapter.patch.selector;
package org.sinytra.adapter.patch.analysis.selector;

import com.mojang.serialization.Codec;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.tree.ClassNode;
import org.sinytra.adapter.patch.api.Patch.Result;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;

public interface ClassTransform {
Result apply(ClassNode classNode, @Nullable AnnotationValueHandle<?> annotation, PatchContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.sinytra.adapter.patch.analysis.LocalVariableLookup;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.util.MethodQualifier;
import org.sinytra.adapter.patch.util.provider.ClassLookup;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.sinytra.adapter.patch.api;

import org.jetbrains.annotations.ApiStatus;
import org.sinytra.adapter.patch.transformer.ModifyInjectionTarget;
import org.sinytra.adapter.patch.transformer.ModifyMethodAccess;
import org.sinytra.adapter.patch.transformer.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.ModifyMixinType;
import org.sinytra.adapter.patch.transformer.param.TransformParameters;
import org.sinytra.adapter.patch.transformer.operation.ModifyInjectionTarget;
import org.sinytra.adapter.patch.transformer.operation.ModifyMethodAccess;
import org.sinytra.adapter.patch.transformer.operation.ModifyMethodParams;
import org.sinytra.adapter.patch.transformer.operation.ModifyMixinType;
import org.sinytra.adapter.patch.transformer.operation.param.TransformParameters;

import java.util.List;
import java.util.function.Consumer;
Expand All @@ -21,14 +21,10 @@ public interface MethodTransformBuilder<T extends MethodTransformBuilder<T>> {

T modifyTarget(ModifyInjectionTarget.Action action, String... methods);

T modifyVariableIndex(int start, int offset);

T modifyMethodAccess(ModifyMethodAccess.AccessChange... changes);

T extractMixin(String targetClass);

T splitMixin(String targetClass);

T improveModifyVar();

T modifyMixinType(String newType, Consumer<ModifyMixinType.Builder> consumer);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sinytra.adapter.patch.api;

import com.mojang.serialization.Codec;

public interface MethodTransformFilter {
Codec<? extends MethodTransformFilter> codec();

boolean test(MethodContext methodContext);
}
13 changes: 2 additions & 11 deletions definition/src/main/java/org/sinytra/adapter/patch/api/Patch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.sinytra.adapter.patch.ClassPatchInstance;
import org.sinytra.adapter.patch.InterfacePatchInstance;
import org.sinytra.adapter.patch.PatchInstance;
import org.sinytra.adapter.patch.selector.AnnotationHandle;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;

import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
Expand Down Expand Up @@ -100,18 +97,12 @@ default ClassPatchBuilder modifyInjectionPoint(String target) {
return modifyInjectionPoint(null, target);
}

ClassPatchBuilder redirectShadowMethod(String original, String target, BiConsumer<MethodInsnNode, InsnList> callFixer);

ClassPatchBuilder divertRedirector(Consumer<InstructionAdapter> patcher);

ClassPatchBuilder updateRedirectTarget(String originalTarget, String newTarget);

ClassPatchBuilder disable();
}

interface InterfacePatchBuilder extends Builder<InterfacePatchBuilder> {
InterfacePatchBuilder targetField(String... targets);

InterfacePatchBuilder modifyValue(String value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.sinytra.adapter.patch.api.*;
import org.sinytra.adapter.patch.selector.FieldMatcher;
import org.sinytra.adapter.patch.analysis.selector.FieldMatcher;
import org.sinytra.adapter.patch.util.AdapterUtil;

import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.sinytra.adapter.patch.api.ClassTransform;
import org.sinytra.adapter.patch.api.Patch;
import org.sinytra.adapter.patch.api.PatchContext;
import org.sinytra.adapter.patch.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.analysis.selector.AnnotationValueHandle;
import org.sinytra.adapter.patch.util.AdapterUtil;
import org.slf4j.Logger;

Expand Down
Loading

0 comments on commit 4c3e67f

Please sign in to comment.