diff --git a/Assets/Plugins/PS5.meta b/Assets/Plugins/PS5.meta deleted file mode 100644 index 5991894..0000000 --- a/Assets/Plugins/PS5.meta +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 831ccca..0000000 Binary files a/Assets/Plugins/PS5/PS5Utils.prx and /dev/null differ diff --git a/Assets/Plugins/PS5/PS5Utils.prx.meta b/Assets/Plugins/PS5/PS5Utils.prx.meta deleted file mode 100644 index b640be5..0000000 --- a/Assets/Plugins/PS5/PS5Utils.prx.meta +++ /dev/null @@ -1,32 +0,0 @@ -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.cpp b/Assets/Scripts/EOSNativeHelper.cpp new file mode 100644 index 0000000..911d14b --- /dev/null +++ b/Assets/Scripts/EOSNativeHelper.cpp @@ -0,0 +1,52 @@ +#include + +#if defined(__ORBIS__) || defined(__PROSPERO__) + #define _aligned_malloc(s,a) aligned_alloc(a,s) + #define _aligned_realloc(p,s,a) reallocalign(p,s,a) + #define _aligned_free(p) free(p) +#else + #include +#endif + +#define DLL_EXPORT extern "C" __declspec(dllexport) + +static void *AllocateMemory(size_t size, size_t alignment) +{ + if (size == 0) + return nullptr; + + return _aligned_malloc(size, alignment); +} + +static void *ReallocateMemory(void *ptr, size_t size, size_t alignment) +{ + if (size == 0) + { + free(ptr); + return nullptr; + } + + // EOS will sometimes request a reallocation for a null pointer, so we need to specifically handle that + if (ptr == nullptr) + { + return _aligned_malloc(size, alignment); + } + + return _aligned_realloc(ptr, size, alignment); +} + +static void ReleaseMemory(void *ptr) +{ + return _aligned_free(ptr); +} + +typedef void* (*AllocateMemoryFunc)(size_t, size_t); +typedef void* (*ReallocateMemoryFunc)(void*, size_t, size_t); +typedef void (*ReleaseMemoryFunc)(void*); + +DLL_EXPORT void EOS_GetMemoryFunctions(AllocateMemoryFunc *allocFunc, ReallocateMemoryFunc *reallocFunc, ReleaseMemoryFunc *releaseFunc) +{ + *allocFunc = AllocateMemory; + *reallocFunc = ReallocateMemory; + *releaseFunc = ReleaseMemory; +} diff --git a/Assets/Scripts/EOSNativeHelper.cpp.meta b/Assets/Scripts/EOSNativeHelper.cpp.meta new file mode 100644 index 0000000..5c7c0b9 --- /dev/null +++ b/Assets/Scripts/EOSNativeHelper.cpp.meta @@ -0,0 +1,87 @@ +fileFormatVersion: 2 +guid: 9e01755363649f24bbc946e6dd5dd6ef +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: 0 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude PS4: 0 + Exclude PS5: 0 + 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: + GameCoreXboxOne: GameCoreXboxOne + second: + enabled: 1 + settings: {} + - first: + PS4: PS4 + second: + enabled: 1 + settings: {} + - first: + PS5: PS5 + 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/Scripts/EOSNativeHelper.cs b/Assets/Scripts/EOSNativeHelper.cs index 7f8265d..48edc7d 100644 --- a/Assets/Scripts/EOSNativeHelper.cs +++ b/Assets/Scripts/EOSNativeHelper.cs @@ -30,7 +30,10 @@ public static class EOSNativeHelper [DllImport("kernel32")] public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); -#else +#elif !UNITY_STANDALONE + + [DllImport("__Internal", EntryPoint = "EOS_GetMemoryFunctions")] + public static extern void GetMemoryFunctions(out IntPtr allocFunc, out IntPtr reallocFunc, out IntPtr releaseFunc); [MonoPInvokeCallback(typeof(AllocateMemoryFunc))] public static IntPtr AllocateMemory(UIntPtr size, UIntPtr alignment) @@ -75,9 +78,4 @@ public static class EOSNativeHelper 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 138c522..7210146 100644 --- a/Assets/Scripts/EpicVoiceChatTest.cs +++ b/Assets/Scripts/EpicVoiceChatTest.cs @@ -122,7 +122,7 @@ public class EpicVoiceChatTest : MonoBehaviour yield return new WaitForSeconds(5f); #endif -#if UNITY_PS4 || UNITY_PS5 +#if !UNITY_STANDALONE EOSNativeHelper.GetMemoryFunctions(out var allocFunc, out var reallocFunc, out var releaseFunc); #endif @@ -130,12 +130,8 @@ public class EpicVoiceChatTest : MonoBehaviour { ProductName = "WW1Test", ProductVersion = "1.0.0.0", -#if UNITY_GAMECORE - // EOS SDK on Game Core will not initialize without these memory management function pointers - AllocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((AllocateMemoryFunc)EOSNativeHelper.AllocateMemory), - ReallocateMemoryFunction = Marshal.GetFunctionPointerForDelegate((ReallocateMemoryFunc)EOSNativeHelper.ReallocateMemory), - ReleaseMemoryFunction = Marshal.GetFunctionPointerForDelegate((ReleaseMemoryFunc)EOSNativeHelper.ReleaseMemory), -#elif UNITY_PS4 || UNITY_PS5 +#if !UNITY_STANDALONE + // EOS SDK on consoles will not initialize without these memory management function pointers AllocateMemoryFunction = allocFunc, ReallocateMemoryFunction = reallocFunc, ReleaseMemoryFunction = releaseFunc,