diff --git a/README.md b/README.md index 502cdfa..67eca69 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ReplayModFixMod EN -[中](https://github.com/wohaopa/ReplayModFixMod/README_CN.md) +[中](https://github.com/wohaopa/ReplayModFixMod/blob/master/README_CN.md) **The following content is translated by machine** @@ -16,6 +16,6 @@ Used to fix mods where ReplayMod does not work in GTNH. Because ReplayMod is so ## Description If you have any problems using ReplayMod in GTNH, please give feedback in this project. ## How to use -Download ReplayMod 2.5.2. Use compression software to open, replace `com\replaymod\core\tweaker\ReplayModTweaker.class` with [ReplayModTweaker.class](https://github.com/wohaopa/ReplayModFixMod/replace/ReplayModTweaker.class) and put this mod and replaymod in the mods folder. Download and install directories [ffmpeg](https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-5.1.2-essentials_build.zip) through `.minecraft`. +Download ReplayMod 2.5.2. Use compression software to open, replace `com\replaymod\core\tweaker\ReplayModTweaker.class` with [ReplayModTweaker.class](https://github.com/wohaopa/ReplayModFixMod/blob/master/replace/ReplayModTweaker.class) and put this mod and replaymod in the mods folder. Download and install directories [ffmpeg](https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-5.1.2-essentials_build.zip) through `.minecraft`. \ No newline at end of file diff --git a/README_CN.md b/README_CN.md index 7d67e21..dd7b3b4 100644 --- a/README_CN.md +++ b/README_CN.md @@ -13,4 +13,4 @@ ## 说明 在GTNH中使用ReplayMod遇到问题请在本项目中反馈。 ## 使用方法 -下载ReplayMod 2.5.2版本。使用压缩软件打开,替换`com\replaymod\core\tweaker\ReplayModTweaker.class`为[ReplayModTweaker.class](https://github.com/wohaopa/ReplayModFixMod/replace/ReplayModTweaker.class) 将本mod与replaymod一并放入至mods文件夹。下载并安装[ffmpeg](https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-5.1.2-essentials_build.zip)至`.minecraft`目录即可。 \ No newline at end of file +下载ReplayMod 2.5.2版本。使用压缩软件打开,替换`com\replaymod\core\tweaker\ReplayModTweaker.class`为[ReplayModTweaker.class](https://github.com/wohaopa/ReplayModFixMod/blob/master/replace/ReplayModTweaker.class) 将本mod与replaymod一并放入至mods文件夹。下载并安装[ffmpeg](https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-5.1.2-essentials_build.zip)至`.minecraft`目录即可。 \ No newline at end of file diff --git a/replace/ReplayModTweaker.class b/replace/ReplayModTweaker.class new file mode 100644 index 0000000..68565e6 Binary files /dev/null and b/replace/ReplayModTweaker.class differ diff --git a/replace/ReplayModTweaker.java b/replace/ReplayModTweaker.java new file mode 100644 index 0000000..ad2bd02 --- /dev/null +++ b/replace/ReplayModTweaker.java @@ -0,0 +1,80 @@ +package com.replaymod.core.tweaker; + +import com.replaymod.extras.modcore.ModCoreInstaller; +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.Launch; +import net.minecraft.launchwrapper.LaunchClassLoader; +import org.spongepowered.asm.launch.GlobalProperties; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.launch.platform.MixinPlatformManager; +import org.spongepowered.asm.launch.platform.container.ContainerHandleURI; + +public class ReplayModTweaker implements ITweaker { + private static final String MIXIN_TWEAKER = "org.spongepowered.asm.launch.MixinTweaker"; + + public ReplayModTweaker() { + injectMixinTweaker(); + } + + private void injectMixinTweaker() { + List tweakClasses = (List)Launch.blackboard.get("TweakClasses"); + if (tweakClasses.contains("org.spongepowered.asm.launch.MixinTweaker")) + return; + if (GlobalProperties.get(GlobalProperties.Keys.INIT) != null) + return; + System.out.println("Injecting MixinTweaker from ReplayModTweaker"); + Launch.classLoader.addClassLoaderExclusion("org.spongepowered.asm.launch.MixinTweaker".substring(0, "org.spongepowered.asm.launch.MixinTweaker".lastIndexOf('.'))); + List tweaks = (List)Launch.blackboard.get("Tweaks"); + try { + tweaks.add((ITweaker)Class.forName("org.spongepowered.asm.launch.MixinTweaker", true, (ClassLoader)Launch.classLoader).newInstance()); + } catch (InstantiationException|IllegalAccessException|ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + public void acceptOptions(List args, File gameDir, File assetsDir, String profile) {} + + public void injectIntoClassLoader(LaunchClassLoader classLoader) { + URI uri; + try { + uri = getClass().getProtectionDomain().getCodeSource().getLocation().toURI(); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + MixinPlatformManager platform = MixinBootstrap.getPlatform(); + platform.addContainer(new ContainerHandleURI(uri)); + } + + public String getLaunchTarget() { + return null; + } + + public String[] getLaunchArguments() { + return new String[0]; + } + + private void initModCore(String mcVer) { + try { + if (System.getProperty("REPLAYMOD_SKIP_MODCORE", "false").equalsIgnoreCase("true")) { + System.out.println("ReplayMod not initializing ModCore because REPLAYMOD_SKIP_MODCORE is true."); + return; + } + if (((Boolean)Launch.blackboard.get("fml.deobfuscatedEnvironment")).booleanValue()) { + System.out.println("ReplayMod not initializing ModCore because we're in a development environment."); + return; + } + int result = ModCoreInstaller.initialize(Launch.minecraftHome, mcVer + "_forge"); + if (result != -2) + System.out.println("ReplayMod ModCore init result: " + result); + if (ModCoreInstaller.isErrored()) + System.err.println(ModCoreInstaller.getError()); + } catch (Throwable t) { + System.err.println("ReplayMod caught error during ModCore init:"); + t.printStackTrace(); + } + } +}