2022-02-06 21:38:14 -08:00
|
|
|
|
using HarmonyLib;
|
2022-02-06 21:52:18 -08:00
|
|
|
|
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;
|
2022-02-06 21:52:18 -08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2022-02-06 22:46:05 -08:00
|
|
|
|
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();
|
2022-02-06 21:52:18 -08:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
};
|
2022-02-06 21:52:18 -08:00
|
|
|
|
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}\"", " "),
|
2022-02-06 21:52:18 -08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|