Skip to content

Commit

Permalink
Fix iOS/tvOS support in FNADllMap (FNA-XNA#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSpydog authored Dec 14, 2023
1 parent 6348746 commit 58b867a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/Utilities/FNADllMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#endregion

#if NET
#if NET7_0_OR_GREATER

#region Using Statements
using System;
Expand All @@ -33,13 +33,21 @@ private static Dictionary<string, string> mapDictionary

#region Private Static Methods

private static bool IsAppleAOTPlatform()
{
/* These platforms require a bit of special handling since
* they are the only platforms that compile via Mono AOT.
*/
return OperatingSystem.IsIOS() || OperatingSystem.IsTvOS();
}

private static string GetPlatformName()
{
if (OperatingSystem.IsWindows())
{
return "windows";
}
else if (OperatingSystem.IsMacOS())
else if (OperatingSystem.IsMacOS() || IsAppleAOTPlatform())
{
return "osx";
}
Expand Down Expand Up @@ -72,7 +80,10 @@ private static IntPtr MapAndLoad(
{
mappedName = libraryName;
}
return NativeLibrary.Load(mappedName, assembly, dllImportSearchPath);

return (mappedName == "__Internal") ?
NativeLibrary.GetMainProgramHandle() :
NativeLibrary.Load(mappedName, assembly, dllImportSearchPath);
}

#endregion
Expand All @@ -83,8 +94,7 @@ private static IntPtr MapAndLoad(
public static void Init()
{
// Ignore NativeAOT platforms since they don't perform dynamic loading.
// FIXME: Is the iOS check needed?
if (!RuntimeFeature.IsDynamicCodeSupported && !OperatingSystem.IsIOS())
if (!RuntimeFeature.IsDynamicCodeSupported && !IsAppleAOTPlatform())
{
return;
}
Expand Down Expand Up @@ -199,4 +209,4 @@ public static void Init()
}
}

#endif // NET
#endif // NET7_0_OR_GREATER

0 comments on commit 58b867a

Please sign in to comment.