mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
40
Brutal.OpenAl/Manual/NativeLoader.cs
Normal file
40
Brutal.OpenAl/Manual/NativeLoader.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Brutal.OpenAlApi;
|
||||
|
||||
internal static class NativeLoader
|
||||
{
|
||||
// The logical name the generated [LibraryImport] entries request. Must match the `Dll` const.
|
||||
private const string LogicalName = "openal";
|
||||
|
||||
[SuppressMessage(
|
||||
"Usage",
|
||||
"CA2255:The 'ModuleInitializer' attribute should not be used in libraries",
|
||||
Justification = "Resolver must register before any nested-type P/Invoke; static ctor is not triggered by nested-type access."
|
||||
)]
|
||||
[ModuleInitializer]
|
||||
internal static void Register()
|
||||
{
|
||||
NativeLibrary.SetDllImportResolver(typeof(NativeLoader).Assembly, Resolve);
|
||||
}
|
||||
|
||||
private static nint Resolve(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
if (libraryName != LogicalName)
|
||||
return nint.Zero;
|
||||
|
||||
// openal-soft installed file names:
|
||||
// Windows : OpenAL32.dll
|
||||
// Linux : libopenal.so.1 (SONAME)
|
||||
// macOS : libopenal.1.dylib (install_name @rpath/libopenal.1.dylib)
|
||||
var fileName = Platform.CurrentFamily switch
|
||||
{
|
||||
Platform.Family.Windows => "OpenAL32.dll",
|
||||
Platform.Family.MacOS => "libopenal.1.dylib",
|
||||
_ => "libopenal.so.1",
|
||||
};
|
||||
|
||||
return NativeLibrary.Load(fileName, assembly, DllImportSearchPath.AssemblyDirectory);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue