65 lines
1.4 KiB
C#
Raw Normal View History

2023-06-09 22:32:56 -07:00
using Steamworks;
using System;
2023-06-09 20:44:28 -07:00
using System.IO;
using System.Reflection;
2023-06-09 20:50:16 -07:00
namespace SteamRerouter.ExeSide;
2023-06-09 20:44:28 -07:00
2023-06-09 22:32:56 -07:00
/// <summary>
/// top level file on the exe
/// </summary>
2023-06-09 20:44:28 -07:00
public static class Program
{
private static void Main(string[] args)
{
2023-06-09 22:32:56 -07:00
var port = int.Parse(args[0]);
Log($"port = {port}");
var managedDir = args[1];
2023-06-09 20:44:28 -07:00
Log($"managed dir = {managedDir}");
AppDomain.CurrentDomain.AssemblyResolve += (_, e) =>
{
var name = new AssemblyName(e.Name).Name + ".dll";
var path = Path.Combine(managedDir, name);
return File.Exists(path) ? Assembly.LoadFile(path) : null;
};
2023-06-09 22:32:56 -07:00
Go(port);
2023-06-09 20:44:28 -07:00
}
2023-06-09 22:32:56 -07:00
private static void Go(int port)
2023-06-09 20:44:28 -07:00
{
2023-06-09 22:47:31 -07:00
Log("go");
2023-06-09 22:32:56 -07:00
// copied from QSBCore
if (!Packsize.Test())
2023-06-09 20:44:28 -07:00
{
2023-06-09 22:32:56 -07:00
Log("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.");
2023-06-09 20:44:28 -07:00
}
2023-06-09 22:32:56 -07:00
if (!DllCheck.Test())
2023-06-09 20:44:28 -07:00
{
2023-06-09 22:32:56 -07:00
Log("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.");
}
2023-06-09 20:44:28 -07:00
2023-06-09 22:32:56 -07:00
// from facepunch.steamworks SteamClient.cs
Environment.SetEnvironmentVariable("SteamAppId", "753641");
Environment.SetEnvironmentVariable("SteamGameId", "753641");
if (!SteamAPI.Init())
{
Log($"FATAL - SteamAPI.Init() failed. Refer to Valve's documentation.");
return;
2023-06-09 20:44:28 -07:00
}
2023-06-09 22:32:56 -07:00
2023-06-09 22:50:09 -07:00
IpcClient.Connect(port);
2023-06-09 22:47:31 -07:00
2023-06-09 22:50:09 -07:00
IpcClient.Loop();
2023-06-09 22:32:56 -07:00
Log("stop");
SteamAPI.Shutdown();
2023-06-09 20:44:28 -07:00
}
2023-06-09 22:32:56 -07:00
public static void Log(object msg) => Console.Out.WriteLine(msg);
}