From b285c81c09156c0bf626cfe2a422af94fdabb72e Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 7 Oct 2018 13:59:28 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20=D0=B6?= =?UTF-8?q?=D0=B5=20=D1=81=D1=80=D0=B0=D0=B1=D0=B0=D1=82=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D1=8B=20?= =?UTF-8?q?=D0=BA=D1=80=D0=B0=D1=88=D0=B8=D1=82=20=D0=BF=D1=80=D0=BE=D1=86?= =?UTF-8?q?=D0=B5=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launcher/AvanguardStarter.java | 30 ++++++++++++++++--- .../java/cpw/mods/fml/SafeExitJVMLegacy.java | 10 ++++++- .../net/minecraftforge/fml/SafeExitJVM.java | 10 ++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java index 89f8f9f9..06081e55 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java +++ b/Launcher/src/main/java/ru/gravit/launcher/AvanguardStarter.java @@ -5,6 +5,8 @@ import java.nio.file.Path; import java.util.Arrays; +import cpw.mods.fml.SafeExitJVMLegacy; +import net.minecraftforge.fml.SafeExitJVM; import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.utils.helper.CommonHelper; @@ -17,29 +19,44 @@ public class AvanguardStarter { static class SecurityThread implements Runnable { + static long macID = GuardBind.avnGetMacId(); @Override public void run() { while (!Thread.interrupted()) { try { + if(macID != GuardBind.avnGetMacId()) { + LogHelper.error("MacID changed"); + safeHalt(8); + } if (!GuardBind.avnIsStarted()) { LogHelper.error("Avanguard stopped! Process stopped"); - System.exit(5); + safeHalt(5); } } catch (NullPointerException e) { LogHelper.error("Avanguard unloaded! Process stopped"); - System.exit(6); + safeHalt(6); } try { Thread.sleep(2000); } catch (InterruptedException e) { + GuardBind.avnGetMacId(); if (!GuardBind.avnIsStarted()) { LogHelper.error("Thread stopped! Process stopped"); - System.exit(7); + safeHalt(7); } } } } } + static void safeHalt(int exitcode) + { + try { + SafeExitJVM.exit(exitcode); + } catch (Throwable e) + { + SafeExitJVMLegacy.exit(exitcode); + } + } public static final String NAME = Launcher.getConfig().projectname; public static String avn32 = null, avn64 = null; @@ -76,7 +93,12 @@ public static void main(boolean init) { GuardBind.avnRegisterThreatNotifier((int threatType) -> { System.err.println("Threat " + GuardBind.ThreatType.getThreat(threatType).name()); LogHelper.error("Cheating == crash!"); - System.exit(12); + try { + SafeExitJVM.exit(threatType + 7000); + } catch (Throwable e) + { + SafeExitJVMLegacy.exit(threatType + 7000); + } return false; }); // нужно делать до пуска таймера! diff --git a/libLauncher/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java b/libLauncher/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java index ad9e0111..afc6c870 100644 --- a/libLauncher/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java +++ b/libLauncher/src/main/java/cpw/mods/fml/SafeExitJVMLegacy.java @@ -1,9 +1,17 @@ package cpw.mods.fml; + +import ru.gravit.utils.helper.JVMHelper; + // FMLSecurityManager запрещает делать System.exit из классов // Не входящих в пакеты самого Forge public class SafeExitJVMLegacy { public static void exit(int code) { - System.exit(code); + try { + JVMHelper.RUNTIME.halt(code); + } catch (Throwable e) + { + System.exit(code); + } } } diff --git a/libLauncher/src/main/java/net/minecraftforge/fml/SafeExitJVM.java b/libLauncher/src/main/java/net/minecraftforge/fml/SafeExitJVM.java index 64e5497a..6bf36d66 100644 --- a/libLauncher/src/main/java/net/minecraftforge/fml/SafeExitJVM.java +++ b/libLauncher/src/main/java/net/minecraftforge/fml/SafeExitJVM.java @@ -1,9 +1,17 @@ package net.minecraftforge.fml; + +import ru.gravit.utils.helper.JVMHelper; + // FMLSecurityManager запрещает делать System.exit из классов // Не входящих в пакеты самого Forge public class SafeExitJVM { public static void exit(int code) { - System.exit(code); + try { + JVMHelper.RUNTIME.halt(code); + } catch (Throwable e) + { + System.exit(code); + } } }