From dfb083a800c749f024c8dc998ad8c3fc5e1dbac9 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 20 Jul 2021 17:43:17 +0200 Subject: [PATCH] Added a small shim library to allow access to the PS4 kernel's dynamic library functions, which are used to dynamically linking and unlink against the native engine library. I'm not sure if there isn't an easier way to do this, but this works for now. --- .gitignore | 2 + Assets/Plugins/orbis/SceKernelShim.prx | Bin 0 -> 59108 bytes Assets/Plugins/orbis/SceKernelShim.prx.meta | 77 +++++++++++++ Assets/Scripts/SystemLibrary.cs | 28 +++-- engine/SceKernelShim/SceKernelShim.sln | 31 +++++ engine/SceKernelShim/SceKernelShim.vcxproj | 106 ++++++++++++++++++ .../SceKernelShim.vcxproj.filters | 18 +++ engine/SceKernelShim/prx.cpp | 23 ++++ 8 files changed, 275 insertions(+), 10 deletions(-) create mode 100644 Assets/Plugins/orbis/SceKernelShim.prx create mode 100644 Assets/Plugins/orbis/SceKernelShim.prx.meta create mode 100644 engine/SceKernelShim/SceKernelShim.sln create mode 100644 engine/SceKernelShim/SceKernelShim.vcxproj create mode 100644 engine/SceKernelShim/SceKernelShim.vcxproj.filters create mode 100644 engine/SceKernelShim/prx.cpp diff --git a/.gitignore b/.gitignore index 5ad4c9d..bae3f14 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ mods/ *.orig Debug Portable/ BuildPS4/ +ORBIS_Debug/ +Prospero_Debug/ diff --git a/Assets/Plugins/orbis/SceKernelShim.prx b/Assets/Plugins/orbis/SceKernelShim.prx new file mode 100644 index 0000000000000000000000000000000000000000..08f0efdb86e5c4e3a5cd258cb40e44b8f256965d GIT binary patch literal 59108 zcmeHQeQ+DcbzcA?2~reENv=&twgg#LO*b|O@Dr3Giy%b_ia`r9MOm&WpANv0M1(H^ zphe2jgtqLC5sqh+)~%;W+WHSqr;};_YcsB!v~=Vuj^oKFu98tZO`5iGhK`a(P101U zKhXE~<8XHXnx;zsd#ky7`+o1e-M!!L-tHX)@Dmf!{ce}5m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45Gb^#h#o z|IsM^brBzT1UOXu+^lZ;DF|H^bfl literal 0 HcmV?d00001 diff --git a/Assets/Plugins/orbis/SceKernelShim.prx.meta b/Assets/Plugins/orbis/SceKernelShim.prx.meta new file mode 100644 index 0000000..e6b1b95 --- /dev/null +++ b/Assets/Plugins/orbis/SceKernelShim.prx.meta @@ -0,0 +1,77 @@ +fileFormatVersion: 2 +guid: 1979846846ce98c448853c7141a0171e +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: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude PS4: 0 + 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: + PS4: PS4 + second: + enabled: 1 + settings: {} + - first: + PS5: PS5 + second: + enabled: 0 + 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: x86 + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: x86_64 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SystemLibrary.cs b/Assets/Scripts/SystemLibrary.cs index 6064e54..e1c93f3 100644 --- a/Assets/Scripts/SystemLibrary.cs +++ b/Assets/Scripts/SystemLibrary.cs @@ -26,23 +26,31 @@ public static class SystemLibrary [DllImport("kernel32")] public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); -#else +#elif UNITY_PS4 || UNITY_PS5 + [DllImport("SceKernelShim.prx", EntryPoint = "LoadLibrary")] + private static extern Int32 LoadLibraryNative(string filename); + public static IntPtr LoadLibrary(string filename) { - // sceKernelLoadStartModule - return IntPtr.Zero; + Int32 moduleHandle = LoadLibraryNative(filename); + if (moduleHandle <= 0) + { + UnityEngine.Debug.LogError($"Error loading PRX module '{filename}', error code = 0x{moduleHandle:X}"); + return IntPtr.Zero; + } + + return new IntPtr(moduleHandle); } + [DllImport("SceKernelShim.prx", EntryPoint = "FreeLibrary")] + private static extern bool FreeLibraryNative(Int32 moduleHandle); + public static bool FreeLibrary(IntPtr hModule) { - // sceKernelStopUnloadModule - return false; + return FreeLibraryNative(hModule.ToInt32()); } - public static IntPtr GetProcAddress(IntPtr hModule, string procedureName) - { - // sceKernelDlsym - return IntPtr.Zero; - } + [DllImport("SceKernelShim.psx")] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); #endif } diff --git a/engine/SceKernelShim/SceKernelShim.sln b/engine/SceKernelShim/SceKernelShim.sln new file mode 100644 index 0000000..0597ad1 --- /dev/null +++ b/engine/SceKernelShim/SceKernelShim.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.1433 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SceKernelShim", "SceKernelShim.vcxproj", "{4587A77D-1FD8-4A92-9D11-26545047C1D1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|ORBIS = Debug|ORBIS + Debug|Prospero = Debug|Prospero + Release|ORBIS = Release|ORBIS + Release|Prospero = Release|Prospero + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Debug|ORBIS.ActiveCfg = Debug|ORBIS + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Debug|ORBIS.Build.0 = Debug|ORBIS + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Debug|Prospero.ActiveCfg = Debug|Prospero + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Debug|Prospero.Build.0 = Debug|Prospero + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Release|ORBIS.ActiveCfg = Release|ORBIS + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Release|ORBIS.Build.0 = Release|ORBIS + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Release|Prospero.ActiveCfg = Release|Prospero + {4587A77D-1FD8-4A92-9D11-26545047C1D1}.Release|Prospero.Build.0 = Release|Prospero + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5883AE2B-631A-4510-AF53-C0EB35922AA2} + EndGlobalSection +EndGlobal diff --git a/engine/SceKernelShim/SceKernelShim.vcxproj b/engine/SceKernelShim/SceKernelShim.vcxproj new file mode 100644 index 0000000..665bda6 --- /dev/null +++ b/engine/SceKernelShim/SceKernelShim.vcxproj @@ -0,0 +1,106 @@ + + + + + Debug + ORBIS + + + Debug + Prospero + + + Release + ORBIS + + + Release + Prospero + + + + {4587A77D-1FD8-4A92-9D11-26545047C1D1} + + + + DynamicLibrary + + + DynamicLibrary + + + DynamicLibrary + + + DynamicLibrary + + + v141 + + + v141 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + _DEBUG;%(PreprocessorDefinitions); + true + NotUsing + + + + + _DEBUG;%(PreprocessorDefinitions); + true + NotUsing + + + + + NDEBUG;%(PreprocessorDefinitions); + Level2 + NotUsing + + + + + NDEBUG;%(PreprocessorDefinitions); + Level2 + NotUsing + + + + + + + + + + + + \ No newline at end of file diff --git a/engine/SceKernelShim/SceKernelShim.vcxproj.filters b/engine/SceKernelShim/SceKernelShim.vcxproj.filters new file mode 100644 index 0000000..1b47693 --- /dev/null +++ b/engine/SceKernelShim/SceKernelShim.vcxproj.filters @@ -0,0 +1,18 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cxx;cc;s;asm + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp + + + + + Source Files + + + \ No newline at end of file diff --git a/engine/SceKernelShim/prx.cpp b/engine/SceKernelShim/prx.cpp new file mode 100644 index 0000000..13b26aa --- /dev/null +++ b/engine/SceKernelShim/prx.cpp @@ -0,0 +1,23 @@ +#include + +#define PRX_EXPORT extern "C" __declspec (dllexport) + +PRX_EXPORT SceKernelModule LoadLibrary(const char *filename) +{ + return sceKernelLoadStartModule(filename, 0, nullptr, 0, nullptr, nullptr); +} + +PRX_EXPORT bool FreeLibrary(SceKernelModule moduleHandle) +{ + return sceKernelStopUnloadModule(moduleHandle, 0, nullptr, 0, nullptr, nullptr) == 0; +} + +PRX_EXPORT void *GetProcAddress(SceKernelModule moduleHandle, const char *procedureName) +{ + void *result; + if (sceKernelDlsym(moduleHandle, procedureName, &result) != 0) + { + return nullptr; + } + return result; +}