@@ -35,7 +35,7 @@ internal static unsafe class InjectorHelpers
3535 internal static IntPtr Il2CppHandle = NativeLibrary . Load ( "GameAssembly" , typeof ( InjectorHelpers ) . Assembly , null ) ;
3636 internal static IntPtr UnityPlayerHandle = NativeLibrary . Load ( "UnityPlayer" , typeof ( InjectorHelpers ) . Assembly , null ) ;
3737 internal static AssemblyIATHooker UnityPlayerIATHooker ;
38- internal static string NewAssemblyListFile ;
38+ internal static IAssemblyListFile AssemblyListFile ;
3939
4040 internal static readonly Dictionary < Type , OpCode > StIndOpcodes = new ( )
4141 {
@@ -124,8 +124,8 @@ internal static void Setup()
124124 FromNameHook . ApplyHook ( ) ;
125125 RunFinalizerPatch . ApplyHook ( ) ;
126126
127- AssemblyGetLoadedAssemblyHook . ApplyHook ( ) ;
128- AppDomainGetAssembliesHook . ApplyHook ( ) ;
127+ // AssemblyGetLoadedAssemblyHook.ApplyHook();
128+ // AppDomainGetAssembliesHook.ApplyHook();
129129 }
130130
131131 [ StructLayout ( LayoutKind . Sequential ) ]
@@ -160,21 +160,19 @@ public static extern IntPtr CreateFile(
160160 private static int GetFileAttributesExDetour ( IntPtr lpFileName , int fInfoLevelId , IntPtr lpFileInformation )
161161 {
162162 var filePath = Marshal . PtrToStringUni ( lpFileName ) ;
163+ filePath = filePath . Replace ( @"\\?\" , "" ) ;
163164
164- if ( filePath . Contains ( "ScriptingAssemblies.json" ) )
165+ if ( AssemblyListFile . IsTargetFile ( filePath ) )
165166 {
166- filePath = filePath . Replace ( @"\\?\" , "" ) ;
167-
168- var assemblyList = new AssemblyListFile ( filePath ) ;
169-
167+ AssemblyListFile . Setup ( filePath ) ;
170168 foreach ( var assemblyName in InjectedImages . Keys )
171169 {
172- assemblyList . AddAssembly ( assemblyName ) ;
170+ AssemblyListFile . AddAssembly ( assemblyName ) ;
173171 }
174172
175- NewAssemblyListFile = assemblyList . GetTmpFile ( ) ;
176- Logger . Instance . LogInformation ( $ "Forcing unity to read assembly list from { NewAssemblyListFile } ") ;
177- var newlpFileName = Marshal . StringToHGlobalUni ( NewAssemblyListFile ) ;
173+ var newFile = AssemblyListFile . GetOrCreateNewFile ( ) ;
174+ Logger . Instance . LogInformation ( $ "Forcing unity to read assembly list from { newFile } ") ;
175+ var newlpFileName = Marshal . StringToHGlobalUni ( newFile ) ;
178176
179177 var result = GetFileAttributesEx ( newlpFileName , fInfoLevelId , lpFileInformation ) ;
180178 Marshal . FreeHGlobal ( newlpFileName ) ;
@@ -197,22 +195,24 @@ private static int ReadFileDetour(IntPtr handle, IntPtr bytes, uint numBytesToRe
197195 if ( res != 0 )
198196 {
199197 var filePath = sb . ToString ( ) ;
200- if ( filePath . Contains ( "ScriptingAssemblies.json" ) )
198+ if ( AssemblyListFile . IsTargetFile ( filePath ) )
201199 {
202- IntPtr newHandle = CreateFile ( NewAssemblyListFile , FileAccess . Read , FileShare . Read , IntPtr . Zero , FileMode . Open , FileAttributes . Normal , IntPtr . Zero ) ;
203- UnpatchIATHooks ( ) ;
200+ IntPtr newHandle = CreateFile ( AssemblyListFile . GetOrCreateNewFile ( ) , FileAccess . Read , FileShare . Read , IntPtr . Zero , FileMode . Open , FileAttributes . Normal , IntPtr . Zero ) ;
204201 return ReadFile ( newHandle , bytes , numBytesToRead , numBytesRead , overlapped ) ;
205202 }
206203 }
207204
208205 return ReadFile ( handle , bytes , numBytesToRead , numBytesRead , overlapped ) ;
209206 }
210207
211- private static void UnpatchIATHooks ( )
208+ internal static void UnpatchIATHooks ( )
212209 {
210+ if ( UnityPlayerIATHooker == null ) return ;
211+
213212 Logger . Instance . LogInformation ( "Unpatching UnityPlayer IAT hooks" ) ;
214213 UnityPlayerIATHooker . UnpatchIATHook ( "KERNEL32.dll" , "ReadFile" ) ;
215214 UnityPlayerIATHooker . UnpatchIATHook ( "KERNEL32.dll" , "GetFileAttributesExW" ) ;
215+ UnityPlayerIATHooker = null ;
216216 }
217217
218218 // Setup before unity loads assembly list
@@ -231,6 +231,8 @@ internal static void EarlySetup()
231231 }
232232 }
233233
234+ AssemblyListFile = UnityVersionHandler . GetAssemblyListFile ( ) ;
235+
234236 UnityPlayerIATHooker = new AssemblyIATHooker ( UnityPlayerHandle ) ;
235237 UnityPlayerIATHooker . CreateIATHook ( "KERNEL32.dll" , "ReadFile" , thunk =>
236238 {
0 commit comments