diff --git a/Assets/Plugins/PS5.meta b/Assets/Plugins/PS5.meta new file mode 100644 index 0000000..5991894 --- /dev/null +++ b/Assets/Plugins/PS5.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0677463dddd99144083c9a34be65a720 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/PS5/PS5Utils.prx b/Assets/Plugins/PS5/PS5Utils.prx new file mode 100644 index 0000000..831ccca Binary files /dev/null and b/Assets/Plugins/PS5/PS5Utils.prx differ diff --git a/Assets/Plugins/PS5/PS5Utils.prx.meta b/Assets/Plugins/PS5/PS5Utils.prx.meta new file mode 100644 index 0000000..b640be5 --- /dev/null +++ b/Assets/Plugins/PS5/PS5Utils.prx.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 43fd785f2224f2745a11794c21b7e30c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + PS5: PS5 + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/EOSNativeHelper.cs b/Assets/Scripts/EOSNativeHelper.cs index 80c8fbb..7f8265d 100644 --- a/Assets/Scripts/EOSNativeHelper.cs +++ b/Assets/Scripts/EOSNativeHelper.cs @@ -3,6 +3,7 @@ using System.IO; using System.Runtime.InteropServices; using AOT; using Epic.OnlineServices; +using Epic.OnlineServices.Platform; public static class EOSNativeHelper { @@ -28,29 +29,24 @@ public static class EOSNativeHelper [DllImport("kernel32")] public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); -#endif - [UnmanagedFunctionPointer(Config.LibraryCallingConvention)] - public delegate IntPtr AllocateMemoryFunc(IntPtr size, IntPtr alignment); +#else [MonoPInvokeCallback(typeof(AllocateMemoryFunc))] - public static IntPtr AllocateMemory(IntPtr size, IntPtr alignment) + public static IntPtr AllocateMemory(UIntPtr size, UIntPtr alignment) { - return Marshal.AllocHGlobal(size); + return Marshal.AllocHGlobal((IntPtr)size.ToUInt64()); //return HeapAlloc(GetProcessHeap(), 0, 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) + public static IntPtr ReallocateMemory(IntPtr pointer, UIntPtr size, UIntPtr alignment) { // EOS will sometimes request a reallocation for a null pointer, so we need to specifically handle that if (pointer == IntPtr.Zero) - return Marshal.AllocHGlobal(size); + return Marshal.AllocHGlobal((IntPtr)size.ToUInt64()); - return Marshal.ReAllocHGlobal(pointer, size); + return Marshal.ReAllocHGlobal(pointer, (IntPtr)size.ToUInt64()); // if (pointer == IntPtr.Zero) // return HeapAlloc(GetProcessHeap(), 0, size); @@ -58,9 +54,6 @@ public static class EOSNativeHelper // return HeapReAlloc(GetProcessHeap(), 0, pointer, size); } - [UnmanagedFunctionPointer(Config.LibraryCallingConvention)] - public delegate void ReleaseMemoryFunc(IntPtr pointer); - [MonoPInvokeCallback(typeof(ReleaseMemoryFunc))] public static void ReleaseMemory(IntPtr pointer) { @@ -80,4 +73,11 @@ public static class EOSNativeHelper [DllImport("kernel32")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool HeapFree(IntPtr hHeap, int dwFlags, IntPtr lpMem); + +#endif + +#if UNITY_PS4 || UNITY_PS5 + [DllImport("PS5Utils.prx")] + public static extern void GetMemoryFunctions(out IntPtr allocFunc, out IntPtr reallocFunc, out IntPtr releaseFunc); +#endif } diff --git a/Assets/Scripts/EpicVoiceChatTest.cs b/Assets/Scripts/EpicVoiceChatTest.cs index 3ac7c26..138c522 100644 --- a/Assets/Scripts/EpicVoiceChatTest.cs +++ b/Assets/Scripts/EpicVoiceChatTest.cs @@ -121,19 +121,27 @@ public class EpicVoiceChatTest : MonoBehaviour // This delay is just here to give us some time to connect the debugger yield return new WaitForSeconds(5f); #endif + +#if UNITY_PS4 || UNITY_PS5 + EOSNativeHelper.GetMemoryFunctions(out var allocFunc, out var reallocFunc, out var releaseFunc); +#endif var result = PlatformInterface.Initialize(new InitializeOptions { ProductName = "WW1Test", ProductVersion = "1.0.0.0", -#if UNITY_GAMECORE || UNITY_PS4 || UNITY_PS5 +#if UNITY_GAMECORE // EOS SDK on Game Core will not initialize without these memory management function pointers - AllocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.AllocateMemoryFunc)EOSNativeHelper.AllocateMemory), - ReallocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.ReallocateMemoryFunc)EOSNativeHelper.ReallocateMemory), - ReleaseMemoryFunction = Marshal.GetFunctionPointerForDelegate((EOSNativeHelper.ReleaseMemoryFunc)EOSNativeHelper.ReleaseMemory), + AllocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((AllocateMemoryFunc)EOSNativeHelper.AllocateMemory), + ReallocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((ReallocateMemoryFunc)EOSNativeHelper.ReallocateMemory), + ReleaseMemoryFunction = Marshal.GetFunctionPointerForDelegate((ReleaseMemoryFunc)EOSNativeHelper.ReleaseMemory), +#elif UNITY_PS4 || UNITY_PS5 + AllocateMemoryFunction = allocFunc, + ReallocateMemoryFunction = reallocFunc, + ReleaseMemoryFunction = releaseFunc, #endif }); - + if (result != Result.Success) { Debug.LogError("Failed to initialize EOS, result = " + result);