Skip to content

Commit

Permalink
V1 API with full backward compatibility
Browse files Browse the repository at this point in the history
continue moving code under new package
  • Loading branch information
thecatcore committed Apr 26, 2024
1 parent 6eace07 commit d96d904
Show file tree
Hide file tree
Showing 33 changed files with 534 additions and 332 deletions.
27 changes: 1 addition & 26 deletions src/main/java/fr/catcore/modremapperapi/ModRemappingAPI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package fr.catcore.modremapperapi;

import fr.catcore.modremapperapi.api.ModRemapper;
import fr.catcore.modremapperapi.utils.FakeModManager;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.ModRemappingAPIImpl;
import net.fabricmc.loader.api.FabricLoader;

import java.io.File;
Expand All @@ -10,31 +10,6 @@

public class ModRemappingAPI {

public static final List<ModRemapper> MOD_REMAPPERS = new ArrayList<>();
private static final String entrypointName = "mod-remapper-api:modremapper";

public static boolean remapClassEdits = false;

public static final boolean BABRIC = FabricLoader.getInstance().getModContainer("fabricloader")
.get().getMetadata().getVersion().getFriendlyString().contains("babric");

private static boolean init = false;
private static boolean initializing = false;

public static void init() {
if (!init && !initializing) {
initializing = true;

FabricLoader.getInstance().getConfigDir().toFile().mkdirs();
remapClassEdits = new File(FabricLoader.getInstance().getConfigDir().toFile(), ".remapclassedits").exists();

MOD_REMAPPERS.addAll(FabricLoader.getInstance().getEntrypoints(entrypointName, ModRemapper.class));
FakeModManager.init();

for (ModRemapper remapper : MOD_REMAPPERS) remapper.afterRemap();

initializing = false;
init = true;
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/fr/catcore/modremapperapi/api/ModRemapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import java.util.Map;
import java.util.Optional;

/**
* @deprecated Use {@link io.github.fabriccompatibiltylayers.modremappingapi.api.v1.ModRemapper} instead with entrypoint key "mod-remapper-api:modremapper_v1"
*/
@Deprecated
public interface ModRemapper {

String[] getJarFolders();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;

@Deprecated
public class RemapLibrary {
public final String url;
public final Path path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import net.fabricmc.tinyremapper.api.TrClass;
import org.objectweb.asm.ClassVisitor;

public class MRAPostApplyVisitor implements TinyRemapper.ApplyVisitorProvider {
public class MRAApplyVisitor implements TinyRemapper.ApplyVisitorProvider {
private VisitorInfosImpl infos;

@Override
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
final String className = cls.getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.catcore.modremapperapi.remapping;

import io.github.fabriccompatibiltylayers.modremappingapi.api.v1.VisitorInfos;
import io.github.fabriccompatibiltylayers.modremappingapi.impl.VisitorInfosImpl;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
Expand Down Expand Up @@ -40,16 +41,16 @@ public void visitFieldInsn(int opcode, String owner, String name, String descrip
String currentDescriptor = descriptor;

if (infos.FIELD_REF.containsKey(owner)) {
Map<String, Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember>> fields = infos.FIELD_REF.get(owner);
Map<String, Map<String, VisitorInfos.FullClassMember>> fields = infos.FIELD_REF.get(owner);

Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember> args = fields.get(name);
Map<String, VisitorInfos.FullClassMember> args = fields.get(name);

if (args == null) {
args = fields.get("");
}

if (args != null) {
io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember classMember = args.get(descriptor);
VisitorInfos.FullClassMember classMember = args.get(descriptor);

if (classMember == null) {
classMember = args.get("");
Expand Down Expand Up @@ -90,16 +91,16 @@ public void visitMethodInsn(int opcode, String owner, String name, String descri

if (!skip && (opcode == INVOKEVIRTUAL || opcode == INVOKESTATIC)) {
if (infos.METHOD_INVOCATION.containsKey(owner)) {
Map<String, Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember>> methods = infos.METHOD_INVOCATION.get(owner);
Map<String, Map<String, VisitorInfos.FullClassMember>> methods = infos.METHOD_INVOCATION.get(owner);

Map<String, io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember> args = methods.get(currentName);
Map<String, VisitorInfos.FullClassMember> args = methods.get(currentName);

if (args == null) {
args = methods.get("");
}

if (args != null) {
io.github.fabriccompatibiltylayers.modremappingapi.api.VisitorInfos.FullClassMember fullClassMember = args.get(currentDescriptor);
VisitorInfos.FullClassMember fullClassMember = args.get(currentDescriptor);

if (fullClassMember == null) {
fullClassMember = args.get("");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package fr.catcore.modremapperapi.remapping;

import fr.catcore.modremapperapi.ModRemappingAPI;
import fr.catcore.wfvaio.FabricVariants;
import fr.catcore.wfvaio.WhichFabricVariantAmIOn;
import net.fabricmc.mappingio.MappedElementKind;
import net.fabricmc.mappingio.MappingVisitor;
import org.jetbrains.annotations.ApiStatus;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Deprecated
public class MappingBuilder {
private static final boolean BABRIC = WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC || WhichFabricVariantAmIOn.getVariant() == FabricVariants.BABRIC_NEW_FORMAT;

Expand All @@ -20,56 +23,41 @@ private MappingBuilder(String obfucated, String intermediary) {
this.intermediary = intermediary;
}

private static String toString(String... line) {
StringBuilder builder = new StringBuilder(line[0]);
for (int j = 1; j < line.length; j++) {
builder.append('\t');
builder.append(line[j]);
}
return builder.toString();
}

@ApiStatus.Internal
public static MappingBuilder create(String obfucated, String intermediary) {
return new MappingBuilder(obfucated, intermediary);
}

@ApiStatus.Internal
public static MappingBuilder create(String name) {
return new MappingBuilder(name, name);
}

@Deprecated
public MappingBuilder field(String obfuscated, String intermediary, String description) {
this.entries.add(new Entry(obfuscated, intermediary, description, Type.FIELD));
return this;
}

@Deprecated
public MappingBuilder field(String name, String description) {
this.entries.add(new Entry(name, name, description, Type.FIELD));
return this;
}

@Deprecated
public MappingBuilder method(String obfuscated, String intermediary, String description) {
this.entries.add(new Entry(obfuscated, intermediary, description, Type.METHOD));
return this;
}

@Deprecated
public MappingBuilder method(String name, String description) {
this.entries.add(new Entry(name, name, description, Type.METHOD));
return this;
}

public List<String> build() {
List<String> list = new ArrayList<>();
if (ModRemappingAPI.BABRIC) {
list.add(toString("CLASS", this.intermediary, this.intermediary, this.obfucated, this.obfucated, this.intermediary));
} else {
list.add(toString("CLASS", this.obfucated, this.intermediary, this.intermediary));
}

entries.forEach(entry -> list.add(entry.toString(ModRemappingAPI.BABRIC ? this.intermediary : this.obfucated)));

return list;
}

@ApiStatus.Internal
public void accept(MappingVisitor visitor) throws IOException {
visitor.visitClass(BABRIC ? intermediary : obfucated);
visitor.visitDstName(MappedElementKind.CLASS, 0, BABRIC ? obfucated : this.intermediary);
Expand All @@ -79,6 +67,7 @@ public void accept(MappingVisitor visitor) throws IOException {
}
}

@ApiStatus.Internal
public static class Entry {
private final String obfuscated;
private final String intermediary;
Expand All @@ -92,14 +81,7 @@ public Entry(String obfuscated, String intermediary, String description, Type ty
this.type = type;
}

public String toString(String className) {
if (ModRemappingAPI.BABRIC) {
return MappingBuilder.toString(this.type.name(), className, this.description, this.intermediary, this.intermediary, this.obfuscated, this.obfuscated, this.intermediary);
} else {
return MappingBuilder.toString(this.type.name(), className, this.description, this.obfuscated, this.intermediary, this.intermediary);
}
}

@ApiStatus.Internal
public void accept(MappingVisitor visitor) throws IOException {
if (type == Type.FIELD) visitor.visitField(BABRIC ? intermediary : obfuscated, description);
else visitor.visitMethod(BABRIC ? intermediary : obfuscated, description);
Expand All @@ -108,6 +90,7 @@ public void accept(MappingVisitor visitor) throws IOException {
}
}

@ApiStatus.Internal
public enum Type {
METHOD, FIELD;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
import java.util.ArrayList;
import java.util.List;

public class MixinPostApplyVisitor implements TinyRemapper.ApplyVisitorProvider{
private final List<MappingTree.ClassMapping> classDefs = new ArrayList<>();
public MixinPostApplyVisitor(MappingTree[] trees) {
for (MappingTree tree : trees) {
classDefs.addAll(tree.getClasses());
}
}
public class MixinPostApplyVisitor implements TinyRemapper.ApplyVisitorProvider {
public MixinPostApplyVisitor() {}

@Override
public ClassVisitor insertApplyVisitor(TrClass cls, ClassVisitor next) {
Expand Down
Loading

0 comments on commit d96d904

Please sign in to comment.