quantum-space-buddies/SteamRerouter/ModSide/Interop.cs

61 lines
1.3 KiB
C#
Raw Normal View History

2023-06-10 03:44:28 +00:00
using HarmonyLib;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using UnityEngine;
using Debug = UnityEngine.Debug;
2023-06-10 03:50:16 +00:00
namespace SteamRerouter.ModSide;
2023-06-10 03:44:28 +00:00
2023-06-10 05:32:56 +00:00
/// <summary>
/// top level file on the mod
/// </summary>
public class Interop : MonoBehaviour
2023-06-10 03:44:28 +00:00
{
2023-06-10 05:32:56 +00:00
private static Process _process;
2023-06-10 03:44:28 +00:00
2023-06-10 05:32:56 +00:00
private void Awake()
2023-06-10 03:44:28 +00:00
{
2023-06-10 05:32:56 +00:00
Log("awake");
2023-06-10 03:44:28 +00:00
Patches.Apply();
2023-06-10 05:32:56 +00:00
var port = Socket.Listen();
2023-06-10 03:44:28 +00:00
var processPath = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!,
2023-06-10 03:57:38 +00:00
"SteamRerouter.exe"
2023-06-10 03:44:28 +00:00
);
Log($"process path = {processPath}");
2023-06-10 05:32:56 +00:00
var gamePath = Application.dataPath;
2023-06-10 03:44:28 +00:00
Log($"game path = {gamePath}");
var workingDirectory = Path.Combine(gamePath, "Plugins", "x86_64");
Log($"working dir = {workingDirectory}");
var args = new[]
{
2023-06-10 05:32:56 +00:00
port.ToString(),
2023-06-10 03:44:28 +00:00
Path.Combine(gamePath, "Managed")
};
Log($"args = {args.Join()}");
2023-06-10 05:32:56 +00:00
_process = Process.Start(new ProcessStartInfo
2023-06-10 03:44:28 +00:00
{
FileName = processPath,
WorkingDirectory = workingDirectory,
2023-06-10 05:32:56 +00:00
Arguments = args.Join(x => $"\"{x}\"", " "),
2023-06-10 03:44:28 +00:00
UseShellExecute = false,
2023-06-10 05:32:56 +00:00
CreateNoWindow = false //true
2023-06-10 03:44:28 +00:00
});
2023-06-10 05:32:56 +00:00
Socket.Accept();
}
private void OnDestroy()
{
Log("destroy");
Socket.Quit();
2023-06-10 03:44:28 +00:00
}
2023-06-10 03:57:38 +00:00
public static void Log(object msg) => Debug.Log($"[SteamRerouter] {msg}");
2023-06-10 05:32:56 +00:00
}