diff --git a/EpicRerouter/EpicEntitlementRetriever.cs b/EpicRerouter/ProcessSide/EpicEntitlementRetriever.cs similarity index 69% rename from EpicRerouter/EpicEntitlementRetriever.cs rename to EpicRerouter/ProcessSide/EpicEntitlementRetriever.cs index 5e4f6f37..03343cfd 100644 --- a/EpicRerouter/EpicEntitlementRetriever.cs +++ b/EpicRerouter/ProcessSide/EpicEntitlementRetriever.cs @@ -1,17 +1,16 @@ using Epic.OnlineServices; using Epic.OnlineServices.Ecom; -using UnityEngine; +using EpicRerouter.QsbSide; using static EntitlementsManager; -namespace EpicRerouter +namespace EpicRerouter.ProcessSide { /// /// runs on process side /// public static class EpicEntitlementRetriever { - public const string EOS_DLC_OFFER_ID = "379b9688bb1048f3a56d52b13800f4df"; - public const string EOS_DLC_ITEM_ID = "49a9ac61fe464cbf8c8c73f46b3f1133"; + private const string _eosDlcItemID = "49a9ac61fe464cbf8c8c73f46b3f1133"; private static EcomInterface _ecomInterface; private static OwnershipStatus _epicDlcOwnershipStatus; @@ -19,12 +18,12 @@ namespace EpicRerouter public static void Init() { - EpicPlatformManager.onAuthSuccess += EOSQueryOwnership; + EpicPlatformManager.OnAuthSuccess += EOSQueryOwnership; } public static void Uninit() { - EpicPlatformManager.onAuthSuccess -= EOSQueryOwnership; + EpicPlatformManager.OnAuthSuccess -= EOSQueryOwnership; } public static AsyncOwnershipStatus GetOwnershipStatus() @@ -42,14 +41,14 @@ namespace EpicRerouter return AsyncOwnershipStatus.Owned; } - public static void EOSQueryOwnership() + private static void EOSQueryOwnership() { - Debug.Log("[EOS] querying DLC ownership"); + Interop.Log("[EOS] querying DLC ownership"); _ecomInterface = EpicPlatformManager.PlatformInterface.GetEcomInterface(); var queryOwnershipOptions = new QueryOwnershipOptions { LocalUserId = EpicPlatformManager.LocalUserId, - CatalogItemIds = new[] { "49a9ac61fe464cbf8c8c73f46b3f1133" } + CatalogItemIds = new[] { _eosDlcItemID } }; _ecomInterface.QueryOwnership(queryOwnershipOptions, null, OnEOSQueryOwnershipComplete); } @@ -60,7 +59,7 @@ namespace EpicRerouter { _epicDlcOwnershipStatus = data.ItemOwnership[0].OwnershipStatus; _epicResultReceived = true; - Debug.Log($"[EOS] Query DLC ownership complete: {_epicDlcOwnershipStatus}"); + Interop.Log($"[EOS] Query DLC ownership complete: {_epicDlcOwnershipStatus}"); } } } diff --git a/EpicRerouter/EpicPlatformManager.cs b/EpicRerouter/ProcessSide/EpicPlatformManager.cs similarity index 58% rename from EpicRerouter/EpicPlatformManager.cs rename to EpicRerouter/ProcessSide/EpicPlatformManager.cs index d791881f..93cd9836 100644 --- a/EpicRerouter/EpicPlatformManager.cs +++ b/EpicRerouter/ProcessSide/EpicPlatformManager.cs @@ -1,30 +1,26 @@ using Epic.OnlineServices; using Epic.OnlineServices.Auth; using Epic.OnlineServices.Platform; +using EpicRerouter.QsbSide; using System; -using UnityEngine; -namespace EpicRerouter +namespace EpicRerouter.ProcessSide { /// /// runs on process side /// public static class EpicPlatformManager { - public const string EOS_PRODUCT_ID = "prod-starfish"; - public const string EOS_SANDBOX_ID = "starfish"; - public const string EOS_DEPLOYMENT_ID = "e176ecc84fbc4dd8934664684f44dc71"; - public const string EOS_CLIENT_ID = "5c553c6accee4111bc8ea3a3ae52229b"; - public const string EOS_CLIENT_SECRET = "k87Nfp75BzPref4nJFnnbNjYXQQR"; + private const string _eosProductID = "prod-starfish"; + private const string _eosSandboxID = "starfish"; + private const string _eosDeploymentID = "e176ecc84fbc4dd8934664684f44dc71"; + private const string _eosClientID = "5c553c6accee4111bc8ea3a3ae52229b"; + private const string _eosClientSecret = "k87Nfp75BzPref4nJFnnbNjYXQQR"; - private const float TICK_INTERVAL = 0.1f; - private const bool ENABLE_SDK_DEBUGGING = false; + public static PlatformInterface PlatformInterface; + public static EpicAccountId LocalUserId; - public static PlatformInterface PlatformInterface { get; private set; } - public static EpicAccountId LocalUserId { get; private set; } - private static float _lastTick; - - public static OWEvent onAuthSuccess = new(1); + public static OWEvent OnAuthSuccess = new(1); public static void Init() { @@ -38,7 +34,7 @@ namespace EpicRerouter { if (ex.Result == Result.AlreadyConfigured) { - Debug.Log("[EOS] platform already configured!"); + Console.WriteLine("[EOS] platform already configured!"); } } } @@ -48,11 +44,7 @@ namespace EpicRerouter public static void Tick() { - if (PlatformInterface != null && _lastTick + 0.1f <= Time.unscaledTime) - { - PlatformInterface.Tick(); - _lastTick = Time.unscaledTime; - } + PlatformInterface.Tick(); } public static void Uninit() @@ -66,8 +58,8 @@ namespace EpicRerouter { var result = PlatformInterface.Initialize(new InitializeOptions { - ProductName = Application.productName, - ProductVersion = Application.version + ProductName = Program.ProductName, + ProductVersion = Program.Version }); if (result != Result.Success) { @@ -76,22 +68,22 @@ namespace EpicRerouter var options = new Options { - ProductId = "prod-starfish", - SandboxId = "starfish", + ProductId = _eosProductID, + SandboxId = _eosSandboxID, ClientCredentials = new ClientCredentials { - ClientId = "5c553c6accee4111bc8ea3a3ae52229b", - ClientSecret = "k87Nfp75BzPref4nJFnnbNjYXQQR" + ClientId = _eosClientID, + ClientSecret = _eosClientSecret }, - DeploymentId = "e176ecc84fbc4dd8934664684f44dc71" + DeploymentId = _eosDeploymentID }; PlatformInterface = PlatformInterface.Create(options); - Debug.Log("[EOS] Platform interface has been created"); + Interop.Log("[EOS] Platform interface has been created"); } private static void Auth() { - Debug.Log("[EOS] Authenticating..."); + Interop.Log("[EOS] Authenticating..."); var loginOptions = new LoginOptions { Credentials = new Credentials @@ -104,7 +96,8 @@ namespace EpicRerouter }; if (PlatformInterface == null) { - Debug.LogError("[EOS] Platform interface is null!"); + Interop.Log("[EOS] Platform interface is null!"); + return; } PlatformInterface.GetAuthInterface().Login(loginOptions, null, OnLogin); @@ -129,15 +122,15 @@ namespace EpicRerouter if (loginCallbackInfo.ResultCode == Result.Success) { LocalUserId = loginCallbackInfo.LocalUserId; - Debug.Log($"[EOS SDK] login success! user ID: {LocalUserId}"); - onAuthSuccess.Invoke(); + Interop.Log($"[EOS SDK] login success! user ID: {LocalUserId}"); + OnAuthSuccess.Invoke(); return; } - Debug.LogError("[EOS SDK] Login failed"); + Interop.Log("[EOS SDK] Login failed"); } - public class EOSInitializeException : Exception + private class EOSInitializeException : Exception { public readonly Result Result; public EOSInitializeException(string msg, Result initResult) : base(msg) => Result = initResult; diff --git a/EpicRerouter/ProcessSide/Program.cs b/EpicRerouter/ProcessSide/Program.cs new file mode 100644 index 00000000..790fe485 --- /dev/null +++ b/EpicRerouter/ProcessSide/Program.cs @@ -0,0 +1,48 @@ +using System; +using System.Reflection; +using System.Threading; +using static EntitlementsManager; + +namespace EpicRerouter.ProcessSide +{ + /// + /// runs on process side + /// + internal static class Program + { + public static string ProductName; + public static string Version; + + private static void Main(string[] args) + { + try + { + foreach (var assemblyLocation in args) + { + var assembly = Assembly.LoadFile(assemblyLocation); + Console.WriteLine($"loaded {assembly}"); + } + + Console.WriteLine(); + + EpicPlatformManager.Init(); + EpicEntitlementRetriever.Init(); + + while (EpicEntitlementRetriever.GetOwnershipStatus() == AsyncOwnershipStatus.NotReady) + { + EpicPlatformManager.Tick(); + Thread.Sleep(100); + } + } + finally + { + EpicEntitlementRetriever.Uninit(); + EpicPlatformManager.Uninit(); + + Console.WriteLine("all done"); + Thread.Sleep(3000); + Environment.Exit((int)AsyncOwnershipStatus.Owned); + } + } + } +} diff --git a/EpicRerouter/Program.cs b/EpicRerouter/Program.cs deleted file mode 100644 index 0de52559..00000000 --- a/EpicRerouter/Program.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Reflection; -using System.Threading; -using static EntitlementsManager; - -namespace EpicRerouter -{ - /// - /// runs on process side - /// - internal static class Program - { - private static void Main(string[] assemblyLocations) - { - try - { - foreach (var assemblyLocation in assemblyLocations) - { - var assembly = Assembly.LoadFile(assemblyLocation); - Console.WriteLine($"loaded {assembly}"); - } - } - finally - { - Console.WriteLine("all done"); - Thread.Sleep(3000); - Environment.Exit((int)AsyncOwnershipStatus.Owned); - } - } - } -} diff --git a/EpicRerouter/Interop.cs b/EpicRerouter/QsbSide/Interop.cs similarity index 97% rename from EpicRerouter/Interop.cs rename to EpicRerouter/QsbSide/Interop.cs index c1956df3..d23a0c04 100644 --- a/EpicRerouter/Interop.cs +++ b/EpicRerouter/QsbSide/Interop.cs @@ -7,7 +7,7 @@ using System.Reflection; using static EntitlementsManager; using Debug = UnityEngine.Debug; -namespace EpicRerouter +namespace EpicRerouter.QsbSide { /// /// runs on qsb side diff --git a/EpicRerouter/Patches.cs b/EpicRerouter/QsbSide/Patches.cs similarity index 87% rename from EpicRerouter/Patches.cs rename to EpicRerouter/QsbSide/Patches.cs index 5d0f0c3a..4ac3b0df 100644 --- a/EpicRerouter/Patches.cs +++ b/EpicRerouter/QsbSide/Patches.cs @@ -1,11 +1,11 @@ using HarmonyLib; -namespace EpicRerouter +namespace EpicRerouter.QsbSide { /// /// runs on qsb side /// - [HarmonyPatch(typeof(EpicPlatformManager))] + [HarmonyPatch(typeof(ProcessSide.EpicPlatformManager))] internal static class Patches { [HarmonyPrefix] diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 58320e80..e9baf763 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -54,7 +54,7 @@ namespace QSB { if (true || typeof(EpicPlatformManager).Assembly.GetTypes().Any(x => x.Name == "EpicEntitlementRetriever")) { - EpicRerouter.Interop.Go(); + EpicRerouter.QsbSide.Interop.Go(); } UIHelper.ReplaceUI(UITextType.PleaseUseController,