70 lines
2.0 KiB
C#
Raw Normal View History

2022-02-06 21:38:14 -08:00
using HarmonyLib;
2022-02-06 23:54:52 -08:00
using System;
using System.Diagnostics;
using System.IO;
2022-02-06 23:54:52 -08:00
using System.Linq;
using System.Reflection;
2022-02-06 23:09:55 -08:00
using UnityEngine;
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-07 01:09:44 -08:00
public static EntitlementsManager.AsyncOwnershipStatus OwnershipStatus = EntitlementsManager.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");
2022-02-07 00:45:22 -08:00
return;
}
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:54:52 -08:00
var workingDirectory = Path.Combine(gamePath, "Plugins", "x86_64");
Log($"working dir = {workingDirectory}");
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()}");
2022-02-06 23:54:52 -08:00
var gameArgs = Environment.GetCommandLineArgs();
Log($"game args = {gameArgs.Join()}");
var process = Process.Start(new ProcessStartInfo
{
FileName = processPath,
2022-02-06 23:54:52 -08:00
WorkingDirectory = workingDirectory,
Arguments = args
.Concat(gameArgs)
.Join(x => $"\"{x}\"", " "),
2022-02-07 00:35:59 -08:00
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
});
process!.WaitForExit();
2022-02-07 01:09:44 -08:00
OwnershipStatus = (EntitlementsManager.AsyncOwnershipStatus)process.ExitCode;
2022-02-06 22:05:24 -08:00
Log($"ownership status = {OwnershipStatus}");
Log($"output:\n{process.StandardOutput.ReadToEnd()}");
Log($"error:\n{process.StandardError.ReadToEnd()}");
2022-02-06 21:38:14 -08:00
}
2022-02-06 22:05:24 -08:00
public static void Log(object msg) => Debug.Log($"[EpicRerouter] {msg}");
2022-02-06 21:38:14 -08:00
}
}