Skip to content

Commit

Permalink
Add Polyfrost mods patch & fix LP patch
Browse files Browse the repository at this point in the history
  • Loading branch information
kappa-maintainer committed Sep 13, 2024
1 parent 072c159 commit cefde7b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ public class FugueLoadingPlugin implements IFMLLoadingPlugin {
if (FugueConfig.modPatchConfig.enableCrossbow) {
TransformerDelegate.registerExplicitTransformerByInstance(new TransformerEntityArrowTransformer(), "git.jbredwards.crossbow.mod.asm.transformer.TransformerEntityArrow");
}
if (FugueConfig.modPatchConfig.enablePolyForst) {
TransformerDelegate.registerExplicitTransformerByInstance(
new LaunchWrapperTweakerTransformer(),
"cc.polyfrost.oneconfig.loader.stage0.LaunchWrapperTweaker",
"cc.polyfrost.oneconfig.loader.OneConfigLoader"
);
}
if (FugueConfig.getCodeSourcePatchTargets.length > 0) {
TransformerDelegate.registerExplicitTransformerByInstance(new ITweakerTransformer(), FugueConfig.getCodeSourcePatchTargets);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,6 @@ public class ModPatchConfig {
public boolean enableInfLib = true;
@Config.Name("Enable Crossbow(jbredwards) Patch")
public boolean enableCrossbow = true;
@Config.Name("Enable Patch to PolyForst mods")
public boolean enablePolyForst = true;
}
15 changes: 15 additions & 0 deletions src/main/java/com/cleanroommc/fugue/helper/HookHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import top.outlands.foundation.TransformerDelegate;
import top.outlands.foundation.boot.ActualClassLoader;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -189,4 +190,18 @@ public static Object computeIfAbsent(Map<Object, Object> map, Object key, Functi
return value;
}
}

public static boolean isInitialized(File file) {
try {
return Arrays.asList(Launch.classLoader.getURLs()).contains(file.toURI().toURL());
} catch (MalformedURLException e) {
return false;
}
}

public static void addToClasspath(File file) {
try {
Launch.classLoader.addURL(file.toURI().toURL());
} catch (MalformedURLException ignored) {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cleanroommc.fugue.transformer;

import com.cleanroommc.fugue.common.Fugue;
import javassist.ClassPool;
import javassist.CtClass;
import top.outlands.foundation.IExplicitTransformer;

import java.io.ByteArrayInputStream;

public class LaunchWrapperTweakerTransformer implements IExplicitTransformer {
@Override
public byte[] transform(byte[] bytes) {
try {
CtClass cc = ClassPool.getDefault().makeClass(new ByteArrayInputStream(bytes));
cc.getDeclaredMethod("isInitialized").setBody("{return com.cleanroommc.fugue.helper.HookHelper#isInitialized($$);}");
cc.getDeclaredMethod("addToClasspath").setBody("{com.cleanroommc.fugue.helper.HookHelper#addToClasspath($$);}");
bytes = cc.toBytecode();
} catch (Throwable t) {
Fugue.LOGGER.error("Exception {} on {}", t, this.getClass().getSimpleName());
}
return bytes;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.cleanroommc.fugue.transformer.logisticpipes;

import com.cleanroommc.fugue.common.Fugue;
import net.minecraft.launchwrapper.Launch;
import top.outlands.foundation.IExplicitTransformer;

public class LogisticsPipesTrigger implements IExplicitTransformer {
@Override
public byte[] transform(byte[] bytes) {
Fugue.LOGGER.info("Loading LP classes...");
try {
Launch.classLoader.findClass("logisticspipes.network.packets.routingdebug.RoutingUpdateUntrace");
Launch.classLoader.findClass("logisticspipes.network.packets.modules.SupplierPipeMode");
Launch.classLoader.findClass("logisticspipes.network.packets.module.ModuleBasedItemSinkList");
Launch.classLoader.findClass("logisticspipes.network.packets.pipe.FluidSupplierMinMode");
Launch.classLoader.findClass("logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider");
Launch.classLoader.findClass("logisticspipes.network.guis.upgrade.SneakyUpgradeConfigGuiProvider");
Expand Down

0 comments on commit cefde7b

Please sign in to comment.