2022-02-07 05:38:14 +00:00
|
|
|
|
using HarmonyLib;
|
2022-02-07 07:54:52 +00:00
|
|
|
|
using System;
|
2022-02-07 05:52:18 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2022-02-07 07:54:52 +00:00
|
|
|
|
using System.Linq;
|
2022-02-07 05:52:18 +00:00
|
|
|
|
using System.Reflection;
|
2022-02-07 07:09:55 +00:00
|
|
|
|
using UnityEngine;
|
2022-02-07 05:52:18 +00:00
|
|
|
|
using Debug = UnityEngine.Debug;
|
2022-02-07 05:38:14 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace EpicRerouter.ModSide;
|
|
|
|
|
|
|
|
|
|
public static class Interop
|
2022-02-07 05:38:14 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static EntitlementsManager.AsyncOwnershipStatus OwnershipStatus = EntitlementsManager.AsyncOwnershipStatus.NotReady;
|
2022-02-27 12:40:44 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static void Go()
|
|
|
|
|
{
|
|
|
|
|
if (typeof(EpicPlatformManager).GetField("_platformInterface", BindingFlags.NonPublic | BindingFlags.Instance) == null)
|
2022-02-07 05:38:14 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Log("not epic. don't reroute");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-07 05:52:18 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Log("go");
|
2022-02-07 08:35:59 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Patches.Apply();
|
2022-02-07 21:43:43 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
var processPath = Path.Combine(
|
|
|
|
|
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
|
|
|
|
|
"EpicRerouter.exe"
|
|
|
|
|
);
|
|
|
|
|
Log($"process path = {processPath}");
|
|
|
|
|
var gamePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(EpicPlatformManager).Assembly.Location)!, ".."));
|
|
|
|
|
Log($"game path = {gamePath}");
|
|
|
|
|
var workingDirectory = Path.Combine(gamePath, "Plugins", "x86_64");
|
|
|
|
|
Log($"working dir = {workingDirectory}");
|
|
|
|
|
var args = new[]
|
|
|
|
|
{
|
|
|
|
|
Application.productName,
|
|
|
|
|
Application.version,
|
|
|
|
|
Path.Combine(gamePath, "Managed")
|
|
|
|
|
};
|
|
|
|
|
Log($"args = {args.Join()}");
|
|
|
|
|
var gameArgs = Environment.GetCommandLineArgs();
|
|
|
|
|
Log($"game args = {gameArgs.Join()}");
|
|
|
|
|
var process = Process.Start(new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = processPath,
|
|
|
|
|
WorkingDirectory = workingDirectory,
|
|
|
|
|
Arguments = args
|
|
|
|
|
.Concat(gameArgs)
|
|
|
|
|
.Join(x => $"\"{x}\"", " "),
|
2022-02-07 06:05:24 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
UseShellExecute = false,
|
|
|
|
|
CreateNoWindow = true,
|
|
|
|
|
RedirectStandardOutput = true,
|
|
|
|
|
RedirectStandardError = true
|
|
|
|
|
});
|
|
|
|
|
process!.WaitForExit();
|
|
|
|
|
OwnershipStatus = (EntitlementsManager.AsyncOwnershipStatus)process.ExitCode;
|
|
|
|
|
Log($"ownership status = {OwnershipStatus}");
|
2022-02-25 06:04:54 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
Log($"output:\n{process.StandardOutput.ReadToEnd()}");
|
|
|
|
|
Log($"error:\n{process.StandardError.ReadToEnd()}");
|
2022-02-27 12:40:44 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
public static void Log(object msg) => Debug.Log($"[EpicRerouter] {msg}");
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|