54 lines
1.3 KiB
C#
Raw Normal View History

2022-02-06 21:38:14 -08:00
using HarmonyLib;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
2022-02-06 23:09:55 -08:00
using UnityEngine;
2022-02-06 22:05:24 -08:00
using static EntitlementsManager;
using Debug = UnityEngine.Debug;
2022-02-06 21:38:14 -08:00
2022-02-06 23:09:55 -08:00
namespace EpicRerouter.ModSide
2022-02-06 21:38:14 -08:00
{
public static class Interop
{
2022-02-06 22:05:24 -08:00
public static AsyncOwnershipStatus OwnershipStatus { get; private set; } = AsyncOwnershipStatus.NotReady;
2022-02-06 21:38:14 -08:00
public static void Go()
{
if (typeof(EpicPlatformManager).GetField("_platformInterface", BindingFlags.NonPublic | BindingFlags.Instance) == null)
{
Log("not epic. don't reroute");
// return;
}
2022-02-06 21:38:14 -08:00
Log("go");
2022-02-06 23:09:55 -08:00
Patches.Apply();
var processPath = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
"EpicRerouter.exe"
);
2022-02-06 23:23:49 -08:00
var args = new[]
{
Application.productName,
Application.version,
Path.GetDirectoryName(typeof(EpicPlatformManager).Assembly.Location)
};
var process = Process.Start(new ProcessStartInfo
{
FileName = processPath,
WorkingDirectory = Path.GetDirectoryName(processPath)!,
2022-02-06 23:23:49 -08:00
Arguments = args.Join(x => $"\"{x}\"", " "),
UseShellExecute = false
});
process!.WaitForExit();
2022-02-06 22:05:24 -08:00
OwnershipStatus = (AsyncOwnershipStatus)process.ExitCode;
Log($"ownership status = {OwnershipStatus}");
2022-02-06 21:38:14 -08:00
}
2022-02-06 22:05:24 -08:00
public static void Log(object msg) => Debug.LogError($"[interop] {msg}");
2022-02-06 21:38:14 -08:00
}
}