Example #1
0
        // Token: 0x06000D5E RID: 3422 RVA: 0x0005B33C File Offset: 0x0005953C
        private static bool ValidateAssembly(ModInfo.AssemblyInfo info, out ModAssembly mAssembly)
        {
            List <Assembly> list = new List <Assembly>();

            if (!AssemblyScanner.Scan(info, list))
            {
                mAssembly = null;
                return(false);
            }
            mAssembly = new ModAssembly(info, list);
            if (info.Mod.Assemblies.Any((ModAssembly a) => a.Info.Path == info.Path))
            {
                MLog.Error("The same assmbly is listed in the manifest more than once!");
                mAssembly = null;
                return(false);
            }
            return(true);
        }
 // Token: 0x06000D74 RID: 3444 RVA: 0x0005C050 File Offset: 0x0005A250
 public ModAssembly(ModInfo.AssemblyInfo info, List <Assembly> additionalReferences)
 {
     this.Info = info;
     this.AdditionalReferences = additionalReferences;
 }
        // Token: 0x06000D69 RID: 3433 RVA: 0x0005B7EC File Offset: 0x000599EC
        public static bool Scan(ModInfo.AssemblyInfo info, List <Assembly> additionalRefs)
        {
            if (BesiegeLogFilter.logDev)
            {
                Console.WriteLine("[AssemblyScanner] Scanning {0}.", new object[]
                {
                    info.Path
                });
            }
            bool result;

            try
            {
                AssemblyScanner assemblyScanner = new AssemblyScanner();
                assemblyScanner.CurrentlyScanning = info;
                AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(info.Path);
                Assembly[]         assemblies         = AppDomain.CurrentDomain.GetAssemblies();
                if (BesiegeLogFilter.logDev)
                {
                    string   format = "[AssemblyScanner] Got loaded assembly list:\n{0}.";
                    object[] array  = new object[1];
                    array[0] = string.Join("\n", (from a in assemblies
                                                  select a.FullName + "(" + a.CodeBase + ")").ToArray <string>());
                    Debug.LogFormat(format, array);
                }
                foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
                {
                    AssemblyNameReference reference;
                    foreach (AssemblyNameReference reference2 in moduleDefinition.AssemblyReferences)
                    {
                        reference = reference2;
                        if (BesiegeLogFilter.logDev)
                        {
                            Debug.LogFormat("[AssemblyScanner] Checking if reference {0} is loaded.", new object[]
                            {
                                reference.FullName
                            });
                        }
                        if (assemblies.Any((Assembly a) => a.GetName().Name == reference.Name))
                        {
                            if (BesiegeLogFilter.logDev)
                            {
                                Debug.LogFormat("[AssemblyScanner] Found matching loaded assembly!", new object[0]);
                            }
                        }
                        else
                        {
                            if (BesiegeLogFilter.logDev)
                            {
                                Debug.LogFormat("[AssemblyScanner] Did not find matching loaded assembly!", new object[0]);
                            }
                            Assembly assembly;
                            try
                            {
                                assembly = Assembly.ReflectionOnlyLoad(reference.FullName);
                            }
                            catch (FileNotFoundException)
                            {
                                string text = Path.Combine(new FileInfo(info.Path).DirectoryName, reference.Name + ".dll");
                                if (!File.Exists(text))
                                {
                                    continue;
                                }
                                assembly = Assembly.ReflectionOnlyLoadFrom(text);
                            }
                            additionalRefs.Add(assembly);
                            ModInfo.AssemblyInfo info2 = new ModInfo.AssemblyInfo
                            {
                                Path = assembly.Location
                            };
                            if (!AssemblyScanner.Scan(info2, additionalRefs))
                            {
                                MLog.Error("Referenced assembly did not validate: " + reference.Name);
                                MLog.Error("Not loading " + assemblyDefinition.Name);
                                return(false);
                            }
                        }
                    }
                    foreach (TypeDefinition type in moduleDefinition.Types)
                    {
                        if (!assemblyScanner.ScanType(type))
                        {
                            return(false);
                        }
                    }
                }
                result = true;
            }
            catch (Exception exception)
            {
                Debug.LogError("Error scanning assembly, not loading!");
                Debug.LogException(exception);
                result = false;
            }
            return(result);
        }