aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/djtheredstoner/perspectivemod/forge
diff options
context:
space:
mode:
authorasbyth <cyronize@gmail.com>2020-08-31 16:47:42 -0400
committerasbyth <cyronize@gmail.com>2020-08-31 16:47:42 -0400
commitc5b101efe2ed6aed5338d304acce2cd13b369725 (patch)
tree7648e103ffa817262fed18cba00360f9b53a10ac /src/main/java/me/djtheredstoner/perspectivemod/forge
parentf0e754871b6464a5c852f7b2b2d99b53b21f3896 (diff)
downloadPerspectiveModv4-c5b101efe2ed6aed5338d304acce2cd13b369725.tar.gz
PerspectiveModv4-c5b101efe2ed6aed5338d304acce2cd13b369725.tar.bz2
PerspectiveModv4-c5b101efe2ed6aed5338d304acce2cd13b369725.zip
detect canelex's perspective mod and die
Diffstat (limited to 'src/main/java/me/djtheredstoner/perspectivemod/forge')
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java2
-rw-r--r--src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java80
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
index c54efd7..1242671 100644
--- a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
+++ b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveModLoadingPlugin.java
@@ -1,5 +1,6 @@
package me.djtheredstoner.perspectivemod.forge;
+import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
import org.spongepowered.asm.launch.MixinBootstrap;
import org.spongepowered.asm.mixin.Mixins;
@@ -7,6 +8,7 @@ import org.spongepowered.asm.mixin.Mixins;
import java.util.Map;
// ONLY needed in development environment, the mixin tweaker handles this in prod.
+@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
public class PerspectiveModLoadingPlugin implements IFMLLoadingPlugin {
public PerspectiveModLoadingPlugin() {
diff --git a/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java
new file mode 100644
index 0000000..f22ba05
--- /dev/null
+++ b/src/main/java/me/djtheredstoner/perspectivemod/forge/PerspectiveTweaker.java
@@ -0,0 +1,80 @@
+package me.djtheredstoner.perspectivemod.forge;
+
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import net.minecraft.launchwrapper.Launch;
+import net.minecraftforge.common.ForgeVersion;
+import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
+
+import javax.swing.JOptionPane;
+import java.io.File;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+// this one will be loaded in prod, used to detect Canelex's perspective mod
+@IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion)
+public class PerspectiveTweaker implements IFMLLoadingPlugin {
+
+ public PerspectiveTweaker() {
+ File mods = new File(Launch.minecraftHome, "mods");
+
+ if (!mods.exists()) {
+ mods.mkdirs(); // mods folder may not exist in dev yet
+ }
+
+ File[] coreModList = mods.listFiles((dir, name) -> name.endsWith(".jar"));
+ for (File file : coreModList) {
+ try {
+ try (ZipFile zipFile = new ZipFile(file)) {
+ if (zipFile.getEntry("net/canelex/perspectivemod/PerspectiveMod.class") != null) {
+ halt("<html><p>Perspective Mod v4 is not compatible with Perspective Mod v3 by Canelex. Please remove Canelex's in order to launch the game.</p></html>");
+ continue;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void halt(final String message) {
+ JOptionPane.showMessageDialog(null, message, "Launch Aborted", JOptionPane.ERROR_MESSAGE);
+ try {
+ final Class<?> aClass = Class.forName("java.lang.Shutdown");
+ final Method exit = aClass.getDeclaredMethod("exit", int.class);
+ exit.setAccessible(true);
+ exit.invoke(null, 0);
+ } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public String[] getASMTransformerClass() {
+ return new String[0];
+ }
+
+ @Override
+ public String getModContainerClass() {
+ return null;
+ }
+
+ @Override
+ public String getSetupClass() {
+ return null;
+ }
+
+ @Override
+ public void injectData(Map<String, Object> map) {
+
+ }
+
+ @Override
+ public String getAccessTransformerClass() {
+ return null;
+ }
+}