mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
1 changed files with 768360 additions and 0 deletions
48
brutal.openal/Brutal.OpenAl/Manual/NativeLoader.cs
Normal file
48
brutal.openal/Brutal.OpenAl/Manual/NativeLoader.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// Maps the logical library name "openal" (the `Dll` const in Al.cs / Alc.cs) onto openal-soft's
|
||||
// per-platform file name via a DllImportResolver.
|
||||
//
|
||||
// Registration MUST happen before the first P/Invoke. Accessing a nested type (Al.PInvoke) does
|
||||
// not trigger the containing type's static constructor, so a static ctor on Al/Alc would not fire
|
||||
// for a direct raw call; a [ModuleInitializer] runs at assembly load, before any managed access.
|
||||
|
||||
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";
|
||||
|
||||
// Deliberate despite CA2255 - see the file header for why module-init is the only correct hook.
|
||||
[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