Skip to content

Commit

Permalink
sk1er oam detector
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Oct 27, 2022
1 parent 5559818 commit 8c80085
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ loom {
noServerRunConfigs()
if (project.platform.isLegacyForge) {
launchConfigs.named("client") {
arg("--tweakClass", "cc.polyfrost.oneconfigwrapper.OneConfigWrapper")
arg("--tweakClass", "cc.polyfrost.overflowanimations.handlers.ModDetectorOneConfigTweaker")
property("mixin.debug.export", "true")
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ tasks {
"ForceLoadAsMod" to true,
"TweakOrder" to "0",
"MixinConfigs" to "mixins.${mod_id}.json",
"TweakClass" to "cc.polyfrost.oneconfigwrapper.OneConfigWrapper"
"TweakClass" to "cc.polyfrost.overflowanimations.handlers.ModDetectorOneConfigTweaker"
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod_name = OverflowAnimations
mod_id = overflowanimations
mod_version = 2.0.0
mod_version = 2.0.1-beta2

essential.defaults.loom=0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package cc.polyfrost.overflowanimations.handlers;

import cc.polyfrost.oneconfigwrapper.OneConfigWrapper;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.stream.MalformedJsonException;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;

import javax.swing.*;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class ModDetectorOneConfigTweaker extends OneConfigWrapper {
private final boolean alreadyLoaded;
public ModDetectorOneConfigTweaker() {
super();
boolean someWeirdThingForJava = false;
try {
Class.forName("cc.polyfrost.oneconfigloader.OneConfigLoader");
someWeirdThingForJava = true;
} catch (Exception ignored) {
}
alreadyLoaded = someWeirdThingForJava;
}

@Override
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
try {
Class.forName("club.sk1er.oldanimations.loader.AnimationsTweak");
File modsFolder = new File(Launch.minecraftHome, "mods");
File[] modFolder = modsFolder.listFiles((dir, name) -> name.endsWith(".jar"));
if (modFolder != null) {
final JsonParser PARSER = new JsonParser();
File oldFile = null;
for (File file : modFolder) {
try {
try (ZipFile mod = new ZipFile(file)) {
ZipEntry entry = mod.getEntry("mcmod.info");
if (entry != null) {
try (InputStream inputStream = mod.getInputStream(entry)) {
byte[] availableBytes = new byte[inputStream.available()];
inputStream.read(availableBytes, 0, inputStream.available());
JsonObject modInfo = PARSER.parse(new String(availableBytes)).getAsJsonArray().get(0).getAsJsonObject();
if (!modInfo.has("modid") || !modInfo.has("version")) {
continue;
}

String modid = modInfo.get("modid").getAsString();
if (!modid.equals("sk1er_old_animations")) {
continue;
} else {
oldFile = file;
break;
}
}
}
}
} catch (MalformedJsonException | IllegalStateException ignored) {
} catch (Exception e) {
e.printStackTrace();
}
}
if (oldFile != null) {
if (!oldFile.delete()) {
oldFile.deleteOnExit();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}

final JFrame frame = new JFrame();
frame.setUndecorated(true);
frame.setAlwaysOnTop(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

JOptionPane.showMessageDialog(
frame,
"You have both Sk1er Old Animations and Overflow Animations installed.\n" +
"Please remove Sk1er Old Animations from your mod folder, as OverflowAnimations replaces it.\n" +
"It is in " + oldFile.getAbsolutePath(),
"Sk1er Old Animations detected!", JOptionPane.ERROR_MESSAGE
);
try {
Method exit = Class.forName("java.lang.Shutdown").getDeclaredMethod("exit", int.class);
exit.setAccessible(true);
exit.invoke(null, 1);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
}
}

} catch (Exception ignored) {
// we fine
}
if (alreadyLoaded) {
return;
}
super.acceptOptions(args, gameDir, assetsDir, profile);
}

@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
if (alreadyLoaded) {
return;
}
super.injectIntoClassLoader(classLoader);
}
}

0 comments on commit 8c80085

Please sign in to comment.