Browse Source

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.

console
Nico de Poel 5 years ago
parent
commit
dfb083a800
  1. 2
      .gitignore
  2. BIN
      Assets/Plugins/orbis/SceKernelShim.prx
  3. 77
      Assets/Plugins/orbis/SceKernelShim.prx.meta
  4. 28
      Assets/Scripts/SystemLibrary.cs
  5. 31
      engine/SceKernelShim/SceKernelShim.sln
  6. 106
      engine/SceKernelShim/SceKernelShim.vcxproj
  7. 18
      engine/SceKernelShim/SceKernelShim.vcxproj.filters
  8. 23
      engine/SceKernelShim/prx.cpp

2
.gitignore

@ -15,3 +15,5 @@ mods/
*.orig
Debug Portable/
BuildPS4/
ORBIS_Debug/
Prospero_Debug/

BIN
Assets/Plugins/orbis/SceKernelShim.prx

77
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:

28
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
}

31
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

106
engine/SceKernelShim/SceKernelShim.vcxproj

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|ORBIS">
<Configuration>Debug</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|Prospero">
<Configuration>Debug</Configuration>
<Platform>Prospero</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ORBIS">
<Configuration>Release</Configuration>
<Platform>ORBIS</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Prospero">
<Configuration>Release</Configuration>
<Platform>Prospero</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{4587A77D-1FD8-4A92-9D11-26545047C1D1}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ORBIS'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Prospero'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ORBIS'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Prospero'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<PropertyGroup Condition="'$(DebuggerFlavor)'=='ORBISDebugger'" Label="OverrideDebuggerDefaults">
<!--LocalDebuggerCommand>$(TargetPath)</LocalDebuggerCommand-->
<!--LocalDebuggerCommandArguments></LocalDebuggerCommandArguments-->
<!--LocalDebuggerTarget></LocalDebuggerTarget-->
<!--LocalDebuggerWorkingDirectory>$(ProjectDir)</LocalDebuggerWorkingDirectory-->
<!--LocalRunCommandLine></LocalRunCommandLine-->
</PropertyGroup>
<ImportGroup Label="ExtensionSettings">
<Import Condition="Exists('$(VCTargetsPath)\BuildCustomizations\OrbisWavePsslc.props')" Project="$(VCTargetsPath)\BuildCustomizations\OrbisWavePsslc.props" />
<Import Condition="Exists('$(VCTargetsPath)\BuildCustomizations\SCU.props')" Project="$(VCTargetsPath)\BuildCustomizations\SCU.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|ORBIS'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Prospero'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|ORBIS'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Prospero'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ORBIS'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Prospero'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<GenerateDebugInformation>true</GenerateDebugInformation>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ORBIS'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Prospero'">
<ClCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions);</PreprocessorDefinitions>
<OptimizationLevel>Level2</OptimizationLevel>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="prx.cpp" />
</ItemGroup>
<Import Condition="'$(ConfigurationType)' == 'Makefile' and Exists('$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets')" Project="$(VCTargetsPath)\Platforms\$(Platform)\SCE.Makefile.$(Platform).targets" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Condition="Exists('$(VCTargetsPath)\BuildCustomizations\OrbisWavePsslc.targets')" Project="$(VCTargetsPath)\BuildCustomizations\OrbisWavePsslc.targets" />
<Import Condition="Exists('$(VCTargetsPath)\BuildCustomizations\SCU.targets')" Project="$(VCTargetsPath)\BuildCustomizations\SCU.targets" />
</ImportGroup>
</Project>

18
engine/SceKernelShim/SceKernelShim.vcxproj.filters

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cxx;cc;s;asm</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="prx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

23
engine/SceKernelShim/prx.cpp

@ -0,0 +1,23 @@
#include <kernel.h>
#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;
}
Loading…
Cancel
Save