56 lines
1.5 KiB
C#
Raw Normal View History

2022-02-06 21:38:14 -08:00
using HarmonyLib;
using System.Diagnostics;
using System.IO;
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"
);
Log($"process path = {processPath}");
2022-02-06 23:38:50 -08:00
var gamePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(EpicPlatformManager).Assembly.Location)!, ".."));
Log($"game path = {gamePath}");
2022-02-06 23:23:49 -08:00
var args = new[]
{
Application.productName,
Application.version,
2022-02-06 23:38:50 -08:00
Path.Combine(gamePath, "Managed")
2022-02-06 23:23:49 -08:00
};
Log($"args = {args.Join()}");
var process = Process.Start(new ProcessStartInfo
{
FileName = processPath,
2022-02-06 23:38:50 -08:00
WorkingDirectory = Path.Combine(gamePath, "Plugins", "x86_64"),
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
}
}