diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XSX.meta b/Assets/Plugins/EpicOnlineServices/Bin/XSX.meta new file mode 100644 index 0000000..47bcc77 --- /dev/null +++ b/Assets/Plugins/EpicOnlineServices/Bin/XSX.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1618c8f79f89c134088963ea48d5feec +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll b/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll new file mode 100644 index 0000000..b82c4b5 Binary files /dev/null and b/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll differ diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll.meta b/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll.meta new file mode 100644 index 0000000..6d9d783 --- /dev/null +++ b/Assets/Plugins/EpicOnlineServices/Bin/XSX/EOSSDK-XSX-Shipping.dll.meta @@ -0,0 +1,72 @@ +fileFormatVersion: 2 +guid: bdedd06abc64213438d3d7cdf13f6c2f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude GameCoreScarlett: 0 + Exclude GameCoreXboxOne: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude PS4: 1 + Exclude PS5: 1 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + GameCoreScarlett: GameCoreScarlett + second: + enabled: 1 + settings: {} + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK.meta b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK.meta new file mode 100644 index 0000000..2acb67a --- /dev/null +++ b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 83f49b86b5dfd7c4d8b27c6610a41102 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll new file mode 100644 index 0000000..497e3b5 Binary files /dev/null and b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll differ diff --git a/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll.meta b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll.meta new file mode 100644 index 0000000..b536d63 --- /dev/null +++ b/Assets/Plugins/EpicOnlineServices/Bin/XboxOneGDK/EOSSDK-XboxOneGDK-Shipping.dll.meta @@ -0,0 +1,72 @@ +fileFormatVersion: 2 +guid: 825f617a5f5c90649a592f99a77ed57f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude GameCoreScarlett: 1 + Exclude GameCoreXboxOne: 0 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude PS4: 1 + Exclude PS5: 1 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + GameCoreXboxOne: GameCoreXboxOne + second: + enabled: 1 + settings: {} + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: None + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/EpicOnlineServices/Source/Core/Config.cs b/Assets/Plugins/EpicOnlineServices/Source/Core/Config.cs index 2ca826c..6f73278 100644 --- a/Assets/Plugins/EpicOnlineServices/Source/Core/Config.cs +++ b/Assets/Plugins/EpicOnlineServices/Source/Core/Config.cs @@ -8,7 +8,7 @@ #define EOS_EDITOR #endif -#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_PS4 || UNITY_XBOXONE || UNITY_SWITCH || UNITY_IOS || UNITY_ANDROID +#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_PS4 || UNITY_XBOXONE || UNITY_SWITCH || UNITY_IOS || UNITY_ANDROID || UNITY_PS5 || UNITY_GAMECORE #define EOS_UNITY #endif @@ -40,6 +40,15 @@ #elif UNITY_ANDROID || __ANDROID__ #define EOS_PLATFORM_ANDROID +#elif UNITY_PS5 + #define EOS_PLATFORM_PS5 + +#elif UNITY_GAMECORE_XBOXONE + #define EOS_PLATFORM_XBOXONE_GDK + +#elif UNITY_GAMECORE_SCARLETT + #define EOS_PLATFORM_XBOXSERIESX + #endif using System.Runtime.InteropServices; @@ -78,6 +87,15 @@ namespace Epic.OnlineServices #elif EOS_PLATFORM_ANDROID "EOSSDK" + + #elif EOS_PLATFORM_PS4 + "" + #elif EOS_PLATFORM_PS5 + "" + #elif EOS_PLATFORM_XBOXONE_GDK + "EOSSDK-XboxOneGDK-Shipping.dll" + #elif EOS_PLATFORM_XBOXSERIESX + "EOSSDK-XSX-Shipping.dll" #else #error Unable to determine the name of the EOSSDK library. Ensure you have set the correct EOS compilation symbol for the current platform, such as EOS_PLATFORM_WINDOWS_32 or EOS_PLATFORM_WINDOWS_64, so that the correct EOSSDK library can be targeted. diff --git a/Assets/Scripts/MagnificentVoiceChat.cs b/Assets/Scripts/MagnificentVoiceChat.cs index ea8275d..b10c7cd 100644 --- a/Assets/Scripts/MagnificentVoiceChat.cs +++ b/Assets/Scripts/MagnificentVoiceChat.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; +using System.Runtime.InteropServices; using System.Text; using Epic.OnlineServices; using Epic.OnlineServices.Auth; @@ -16,6 +17,11 @@ using Credentials = Epic.OnlineServices.Auth.Credentials; using LoginCallbackInfo = Epic.OnlineServices.Auth.LoginCallbackInfo; using LoginOptions = Epic.OnlineServices.Auth.LoginOptions; +#if UNITY_GAMECORE +using Unity.GameCore; +using UnityEngine.GameCore; +#endif + public class MagnificentVoiceChat : MonoBehaviour { private const string DebugLobbyId = "a0f6a51f-6b61-4c95-9ed8-a1d508fe4eb6"; @@ -35,6 +41,8 @@ public class MagnificentVoiceChat : MonoBehaviour private EOSVoiceChat voiceChat; + private string xstsToken; + private string XAudio29DllPath => #if UNITY_EDITOR Path.Combine(Application.dataPath, @"Plugins\EpicOnlineServices\Bin\x64\xaudio2_9redist.dll"); @@ -42,27 +50,63 @@ public class MagnificentVoiceChat : MonoBehaviour Path.Combine(Application.dataPath, @"Plugins\x86_64\xaudio2_9redist.dll"); #endif - void Start() + IEnumerator Start() { -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_STANDALONE LoadLibrary(); +#elif UNITY_GAMECORE + int hresult = SDK.XGameRuntimeInitialize(); + if (HR.FAILED(hresult)) + { + Debug.LogError($"Error initializing game runtime, hresult = 0x{hresult:X}"); + yield break; + } + + Debug.Log("GXDK game runtime initialized."); + + hresult = SDK.XBL.XblInitialize(GameCoreSettings.SCID); + if (HR.FAILED(hresult)) + { + Debug.LogError($"Error initializing Xbox Live services, hresult = 0x{hresult:X}"); + yield break; + } + + hresult = SDK.XGameGetXboxTitleId(out uint titleId); + if (HR.FAILED(hresult)) + { + Debug.LogError($"Error obtaining Xbox Title ID, hresult = 0x{hresult:X}"); + yield break; + } + + Debug.Log("Xbox Live services initialized."); + + yield return new WaitForSeconds(5f); #endif var result = PlatformInterface.Initialize(new InitializeOptions { - ProductName = "WW1 Test", - ProductVersion = "0.1", + ProductName = "WW1Test", + ProductVersion = "1.0.0.0", +#if UNITY_GAMECORE + AllocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((SystemLibrary.AllocateMemoryFunc)SystemLibrary.AllocateMemory), + ReallocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((SystemLibrary.ReallocateMemoryFunc)SystemLibrary.ReallocateMemory), + ReleaseMemoryFunction = Marshal.GetFunctionPointerForDelegate((SystemLibrary.ReleaseMemoryFunc)SystemLibrary.ReleaseMemory), +#endif }); if (result != Result.Success) { Debug.LogError("Failed to initialize EOS, result = " + result); - return; + status.AppendLine("EOS initialization failed..."); + yield break; } LoggingInterface.SetLogLevel(LogCategory.AllCategories, LogLevel.Warning); LoggingInterface.SetCallback(OnEOSLogMessage); +#if UNITY_STANDALONE_WIN + Debug.Log("XAudio library path: " + XAudio29DllPath); + var options = new WindowsOptions // Okay so this will need to be platform-specific { ProductId = "b21a28c2c5404c8099d72f5a28c59c16", @@ -90,16 +134,37 @@ public class MagnificentVoiceChat : MonoBehaviour } }, }; +#else + var options = new Options + { + ProductId = "b21a28c2c5404c8099d72f5a28c59c16", + SandboxId = "b630f2c3933a4838a971ce53d5b0db3b", + DeploymentId = "9a36f589572c492fbee14bd299173c12", + + ClientCredentials = new ClientCredentials + { + ClientId = "xyza7891UOFoUhfvfbKgO2xRCIiuAIjH", + ClientSecret = "NArwIQT1laFfsS7fdcN1MKDdgwy490w9MBJsAlHN4QI", + }, + + Flags = PlatformFlags.DisableOverlay, + + CacheDirectory = null, + EncryptionKey = null, + + IsServer = false, + + RTCOptions = new RTCOptions(), + }; +#endif - Debug.Log("XAudio library path: " + XAudio29DllPath); - platformInterface = PlatformInterface.Create(options); if (platformInterface == null) { Debug.LogError("Failed to create EOS platform interface"); status.AppendLine("Failed to create EOS platform interface"); - return; + yield break; } Debug.Log("EOS platform interface successfully created!"); @@ -120,22 +185,57 @@ public class MagnificentVoiceChat : MonoBehaviour audioInterface = rtcInterface.GetAudioInterface(); status.AppendLine("Audio interface: " + audioInterface); - authInterface.Login(new LoginOptions - { - Credentials = GetEpicCredentials(), - ScopeFlags = AuthScopeFlags.BasicProfile, - }, null, HandleLoginResult); - voiceChat = new EOSVoiceChat(lobbyInterface, rtcInterface, audioInterface, () => localProductUserId); voiceChat.OnChatConnected += () => status.AppendLine("Chat lobby successfully connected!"); voiceChat.OnChatConnectionFailed += () => status.AppendLine("Chat lobby connection failed..."); voiceChat.OnChatDisconnected += () => status.AppendLine("Chat lobby disconnected"); voiceChat.OnChatUserJoined += userId => status.AppendLine($"Chat user {userId} joined"); voiceChat.OnChatUserLeft += userId => status.AppendLine($"Chat user {userId} left"); + +#if UNITY_GAMECORE + SDK.XUserAddAsync(XUserAddOptions.AddDefaultUserAllowingUI, (hr, userHandle) => + { + if (HR.FAILED(hr)) + { + Debug.LogError($"Add Xbox user failed, hresult = 0x{hr:X}"); + status.AppendLine("Add Xbox user failed..."); + return; + } + + status.AppendLine("Xbox user added"); + SDK.XUserGetTokenAndSignatureUtf16Async(userHandle, XUserGetTokenAndSignatureOptions.ForceRefresh, + "GET", "https://api.epicgames.dev/", null, null, HandleTokenAndSignature); + }); + + yield return new WaitUntil(() => !string.IsNullOrEmpty(xstsToken)); +#endif + + authInterface.Login(new LoginOptions + { + Credentials = GetEpicCredentials(), + ScopeFlags = AuthScopeFlags.BasicProfile, + }, null, HandleLoginResult); } + +#if UNITY_GAMECORE + private void HandleTokenAndSignature(int hresult, XUserGetTokenAndSignatureUtf16Data tokenAndSignature) + { + if (HR.FAILED(hresult)) + { + Debug.LogError($"Xbox Live authentication failed, hresult = 0x{hresult:X}"); + status.AppendLine("Xbox Live authentication failed..."); + return; + } + + Debug.Log($"Xbox Live authenticated, XSTS token = {tokenAndSignature.Token}"); + status.AppendLine("Xbox Live successfully authenticated"); + xstsToken = tokenAndSignature.Token; + } +#endif private Credentials GetEpicCredentials() // This is platform-specific { +#if UNITY_STANDALONE return new Credentials { // Type = LoginCredentialType.AccountPortal, // Use ExternalAuth on console platform @@ -143,6 +243,15 @@ public class MagnificentVoiceChat : MonoBehaviour Type = LoginCredentialType.Developer, Token = SystemInfo.deviceName, }; +#elif UNITY_GAMECORE + return new Credentials + { + Type = LoginCredentialType.ExternalAuth, + ExternalType = ExternalCredentialType.XblXstsToken, + Token = xstsToken, + }; +#elif UNITY_PS4 || UNITY_PS5 +#endif } private void HandleLoginResult(LoginCallbackInfo data) @@ -155,14 +264,24 @@ public class MagnificentVoiceChat : MonoBehaviour status.AppendLine("EOS login successful: " + localEpicAccountId); authInterface.CopyUserAuthToken(new CopyUserAuthTokenOptions(), localEpicAccountId, out Token token); + Debug.Log($"User auth access token: {token.AccessToken}"); connectInterface.Login(new Epic.OnlineServices.Connect.LoginOptions { +#if UNITY_STANDALONE Credentials = new Epic.OnlineServices.Connect.Credentials { Type = ExternalCredentialType.Epic, // Can be XSTS or PSN ID as well, platform-specific Token = token.AccessToken, }, +#elif UNITY_GAMECORE + Credentials = new Epic.OnlineServices.Connect.Credentials + { + Type = ExternalCredentialType.XblXstsToken, // Isn't this kinda redundant? Should we be logging in to our Epic account here? + Token = xstsToken, + }, +#elif UNITY_PS4 || UNITY_PS5 +#endif }, null, HandleConnectResult); break; default: @@ -225,7 +344,12 @@ public class MagnificentVoiceChat : MonoBehaviour void Update() { - platformInterface.Tick(); + if (platformInterface != null) + platformInterface.Tick(); + +#if UNITY_GAMECORE + SDK.XTaskQueueDispatch(); +#endif } private void OnDestroy() @@ -244,12 +368,12 @@ public class MagnificentVoiceChat : MonoBehaviour PlatformInterface.Shutdown(); -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_STANDALONE UnloadLibrary(); #endif } -#if UNITY_EDITOR +#if UNITY_EDITOR && UNITY_STANDALONE private IntPtr eosLbraryHandle; private void LoadLibrary() diff --git a/Assets/Scripts/SystemLibrary.cs b/Assets/Scripts/SystemLibrary.cs index b538398..3a088f9 100644 --- a/Assets/Scripts/SystemLibrary.cs +++ b/Assets/Scripts/SystemLibrary.cs @@ -1,6 +1,8 @@ using System; using System.IO; using System.Runtime.InteropServices; +using AOT; +using Epic.OnlineServices; public static class SystemLibrary { @@ -27,4 +29,34 @@ public static class SystemLibrary [DllImport("kernel32")] public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); #endif + + [UnmanagedFunctionPointer(Config.LibraryCallingConvention)] + public delegate IntPtr AllocateMemoryFunc(IntPtr size, IntPtr alignment); + + [MonoPInvokeCallback(typeof(AllocateMemoryFunc))] + public static IntPtr AllocateMemory(IntPtr size, IntPtr alignment) + { + return Marshal.AllocHGlobal(size); + } + + [UnmanagedFunctionPointer(Config.LibraryCallingConvention)] + public delegate IntPtr ReallocateMemoryFunc(IntPtr pointer, IntPtr size, IntPtr alignment); + + [MonoPInvokeCallback(typeof(ReallocateMemoryFunc))] + public static IntPtr ReallocateMemory(IntPtr pointer, IntPtr size, IntPtr alignment) + { + if (pointer == IntPtr.Zero) + return Marshal.AllocHGlobal(size); + + return Marshal.ReAllocHGlobal(pointer, size); + } + + [UnmanagedFunctionPointer(Config.LibraryCallingConvention)] + public delegate void ReleaseMemoryFunc(IntPtr pointer); + + [MonoPInvokeCallback(typeof(ReleaseMemoryFunc))] + public static void ReleaseMemory(IntPtr pointer) + { + Marshal.FreeHGlobal(pointer); + } } diff --git a/ProjectSettings/GameCoreXboxOneSettings.asset b/ProjectSettings/GameCoreXboxOneSettings.asset index 0d3d482..79f46f0 100644 --- a/ProjectSettings/GameCoreXboxOneSettings.asset +++ b/ProjectSettings/GameCoreXboxOneSettings.asset @@ -2,7 +2,7 @@ "buildSubtarget": 0, "deploymentMethod": 0, "deploymentDrive": 0, - "scid": "00000000-0000-0000-0000-000000000000", + "scid": "d4e10100-9ffc-4e73-961d-26353b554207", "packageEncryption": 0, "xboxOneResolutionWidth": 1920, "xboxOneResolutionHeight": 1080, diff --git a/ProjectSettings/XboxOneGame.config b/ProjectSettings/XboxOneGame.config index 66f33ef..e8b89b4 100644 --- a/ProjectSettings/XboxOneGame.config +++ b/ProjectSettings/XboxOneGame.config @@ -1,6 +1,10 @@ - + + C1N8H8WTPDSC + 00000000442372A0 + 3b554207 + true \ No newline at end of file