@@ -22,26 +22,19 @@ static XrefScanMethodDb()
2222
2323 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
2424 {
25- IntPtr errorPtr ;
25+ var errorPtr = IntPtr . Zero ;
2626 var libHandle = dlopen ( "GameAssembly.dylib" , 2 ) ;
2727
28- if ( libHandle == IntPtr . Zero )
28+ if ( libHandle == IntPtr . Zero
29+ && Process . GetCurrentProcess ( ) . MainModule ? . FileName is { } procPath
30+ && Directory . GetParent ( procPath ) ? . Parent ? . FullName is { } appContentsPath
31+ && Path . GetFileName ( appContentsPath ) == "Contents" )
2932 {
30- var currentProcessPath = Process . GetCurrentProcess ( ) . MainModule ? . FileName ;
33+ var gameAssemblyPath = Path . Combine ( appContentsPath , "Frameworks" , "GameAssembly.dylib" ) ;
3134
32- if ( ! string . IsNullOrEmpty ( currentProcessPath ) )
35+ if ( File . Exists ( gameAssemblyPath ) )
3336 {
34- var appContentsPath = Path . GetDirectoryName ( Path . GetDirectoryName ( currentProcessPath ) ) ;
35-
36- if ( ! string . IsNullOrEmpty ( appContentsPath ) && Path . GetFileName ( appContentsPath ) == "Contents" )
37- {
38- var gameAssemblyPath = Path . Combine ( appContentsPath , "Frameworks" , "GameAssembly.dylib" ) ;
39-
40- if ( File . Exists ( gameAssemblyPath ) )
41- {
42- libHandle = dlopen ( gameAssemblyPath , 2 ) ;
43- }
44- }
37+ libHandle = dlopen ( gameAssemblyPath , 2 ) ;
4538 }
4639 }
4740
@@ -54,7 +47,7 @@ static XrefScanMethodDb()
5447 : "Unknown dlopen failure" ;
5548
5649 throw new DllNotFoundException (
57- $ "Failed to load GameAssembly.dylib with error message: { errorMessage } ") ;
50+ $ "Failed to load \" GameAssembly.dylib\" with error message: { errorMessage } ") ;
5851 }
5952
6053 // Clear any previous error state.
@@ -134,19 +127,17 @@ private struct DlInfo
134127 public IntPtr dli_saddr ;
135128 }
136129
137- [ DllImport ( "libSystem.dylib" , EntryPoint = "dlopen" ,
138- CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi ) ]
130+ [ DllImport ( "libSystem.dylib" , EntryPoint = "dlopen" , CallingConvention = CallingConvention . Cdecl ,
131+ CharSet = CharSet . Ansi ) ]
139132 private static extern IntPtr dlopen ( string filename , int flags ) ;
140133
141- [ DllImport ( "libSystem.dylib" , EntryPoint = "dlerror" ,
142- CallingConvention = CallingConvention . Cdecl ) ]
134+ [ DllImport ( "libSystem.dylib" , EntryPoint = "dlerror" , CallingConvention = CallingConvention . Cdecl ) ]
143135 private static extern IntPtr dlerror ( ) ;
144136
145- [ DllImport ( "libSystem.dylib" , EntryPoint = "dlsym" ,
146- CallingConvention = CallingConvention . Cdecl , CharSet = CharSet . Ansi ) ]
137+ [ DllImport ( "libSystem.dylib" , EntryPoint = "dlsym" , CallingConvention = CallingConvention . Cdecl ,
138+ CharSet = CharSet . Ansi ) ]
147139 private static extern IntPtr dlsym ( IntPtr handle , string symbol ) ;
148140
149- [ DllImport ( "libSystem.dylib" , EntryPoint = "dladdr" ,
150- CallingConvention = CallingConvention . Cdecl ) ]
141+ [ DllImport ( "libSystem.dylib" , EntryPoint = "dladdr" , CallingConvention = CallingConvention . Cdecl ) ]
151142 private static extern int dladdr ( IntPtr addr , out DlInfo info ) ;
152143}
0 commit comments