mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
Первое же срабатывание защиты крашит процесс
This commit is contained in:
parent
6167699c20
commit
b285c81c09
3 changed files with 44 additions and 6 deletions
|
@ -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;
|
||||
});
|
||||
// нужно делать до пуска таймера!
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue