Пример #1
0
        public static void InitModDir(string dir)
        {
            Debug.Log("Initializing mod directory " + dir + " with Mods.txt is bad");
            if (!Directory.Exists(dir))
            {
                dir = Path.Combine(ETGMod.ModsDirectory, dir);
            }
            ETGModuleMetadata etgmoduleMetadata = new ETGModuleMetadata
            {
                Name    = Path.GetFileName(dir),
                Version = new Version(0, 0),
                DLL     = "mod.dll"
            };
            Assembly assembly = null;
            string   path     = Path.Combine(dir, "metadata.txt");

            if (File.Exists(path))
            {
                using (FileStream fileStream = File.OpenRead(path))
                {
                    etgmoduleMetadata = (ETGModuleMetadata)parseMethod.Invoke(null, new object[] { "", dir, fileStream });
                }
            }
            foreach (ETGModuleMetadata etgmoduleMetadata2 in etgmoduleMetadata.Dependencies)
            {
                if (!ETGMod.DependencyLoaded(etgmoduleMetadata2))
                {
                    Debug.LogWarning(string.Concat(new object[]
                    {
                        "DEPENDENCY ",
                        etgmoduleMetadata2,
                        " OF ",
                        etgmoduleMetadata,
                        " NOT LOADED with Mods.txt is bad!"
                    }));
                    return;
                }
            }
            AppDomain.CurrentDomain.AssemblyResolve += (ResolveEventHandler)generateModAssemblyMethod.Invoke(null, new object[] { etgmoduleMetadata });
            if (!File.Exists(etgmoduleMetadata.DLL))
            {
                return;
            }
            if (etgmoduleMetadata.Prelinked)
            {
                assembly = Assembly.LoadFrom(etgmoduleMetadata.DLL);
            }
            else
            {
                using (FileStream fileStream2 = File.OpenRead(etgmoduleMetadata.DLL))
                {
                    assembly = etgmoduleMetadata.GetRelinkedAssembly(fileStream2);
                }
            }
            assembly.MapAssets();
            ETGMod.Assets.Crawl(dir, null);
            foreach (Type type in assembly.GetTypes())
            {
                if (typeof(ETGModule).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    ETGModule etgmodule = (ETGModule)type.GetConstructor((Type[])emptyTypeArrayInfo.GetValue(null)).Invoke((object[])emptyObjectArrayInfo.GetValue(null));
                    if (!ETGMod.AllMods.Contains(etgmodule))
                    {
                        etgmodule.Metadata = etgmoduleMetadata;
                        ETGMod.GameMods.Add(etgmodule);
                        ETGMod.AllMods.Add(etgmodule);
                        loadedMods.Add(etgmodule);
                        addedModuleTypes.Add(type);
                        addedModuleMethods.Add(new Dictionary <string, MethodInfo>());
                    }
                }
            }
            Debug.Log("Mod " + etgmoduleMetadata.Name + " initialized with Mods.txt is bad.");
        }
Пример #2
0
        public static void InitModZIP(string archive)
        {
            Debug.Log("Initializing mod ZIP " + archive + " with Mods.txt is bad.");
            if (!File.Exists(archive))
            {
                archive = Path.Combine(ETGMod.ModsDirectory, archive);
            }
            ETGModuleMetadata etgmoduleMetadata = new ETGModuleMetadata
            {
                Name    = Path.GetFileNameWithoutExtension(archive),
                Version = new Version(0, 0),
                DLL     = "mod.dll"
            };
            Assembly assembly = null;

            using (ZipFile zipFile = ZipFile.Read(archive))
            {
                Texture2D texture2D = null;
                foreach (ZipEntry zipEntry in zipFile.Entries)
                {
                    if (zipEntry.FileName == "metadata.txt")
                    {
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            zipEntry.Extract(memoryStream);
                            memoryStream.Seek(0L, SeekOrigin.Begin);
                            etgmoduleMetadata = (ETGModuleMetadata)parseMethod.Invoke(null, new object[] { archive, "", memoryStream });
                            continue;
                        }
                    }
                    if (zipEntry.FileName == "icon.png")
                    {
                        texture2D      = new Texture2D(2, 2);
                        texture2D.name = "icon";
                        using (MemoryStream memoryStream2 = new MemoryStream())
                        {
                            zipEntry.Extract(memoryStream2);
                            memoryStream2.Seek(0L, SeekOrigin.Begin);
                            texture2D.LoadImage(memoryStream2.GetBuffer());
                        }
                        texture2D.filterMode = FilterMode.Point;
                    }
                }
                if (texture2D != null)
                {
                    etgmoduleMetadata.Icon = texture2D;
                }
                if (!etgmoduleMetadata.Profile.RunsOn(ETGMod.BaseProfile))
                {
                    return;
                }
                foreach (ETGModuleMetadata etgmoduleMetadata2 in etgmoduleMetadata.Dependencies)
                {
                    if (!ETGMod.DependencyLoaded(etgmoduleMetadata2))
                    {
                        Debug.LogWarning(string.Concat(new object[]
                        {
                            "DEPENDENCY ",
                            etgmoduleMetadata2,
                            " OF ",
                            etgmoduleMetadata,
                            " NOT LOADED with Mods.txt is bad!"
                        }));
                        return;
                    }
                }
                AppDomain.CurrentDomain.AssemblyResolve += (ResolveEventHandler)generateModAssemblyMethod.Invoke(null, new object[] { etgmoduleMetadata });
                foreach (ZipEntry zipEntry2 in zipFile.Entries)
                {
                    string text = zipEntry2.FileName.Replace("\\", "/");
                    if (text == etgmoduleMetadata.DLL)
                    {
                        using (MemoryStream memoryStream3 = new MemoryStream())
                        {
                            zipEntry2.Extract(memoryStream3);
                            memoryStream3.Seek(0L, SeekOrigin.Begin);
                            if (etgmoduleMetadata.Prelinked)
                            {
                                assembly = Assembly.Load(memoryStream3.GetBuffer());
                                continue;
                            }
                            assembly = etgmoduleMetadata.GetRelinkedAssembly(memoryStream3);
                            continue;
                        }
                    }
                    ETGMod.Assets.AddMapping(text, new AssetMetadata(archive, text)
                    {
                        AssetType = (zipEntry2.IsDirectory ? ETGMod.Assets.t_AssetDirectory : null)
                    });
                }
            }
            if (assembly == null)
            {
                return;
            }
            assembly.MapAssets();
            foreach (Type type in assembly.GetTypes())
            {
                if (typeof(ETGModule).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    ETGModule etgmodule = (ETGModule)type.GetConstructor((Type[])emptyTypeArrayInfo.GetValue(null)).Invoke((object[])emptyObjectArrayInfo.GetValue(null));
                    if (!ETGMod.AllMods.Contains(etgmodule))
                    {
                        etgmodule.Metadata = etgmoduleMetadata;
                        ETGMod.GameMods.Add(etgmodule);
                        ETGMod.AllMods.Add(etgmodule);
                        loadedMods.Add(etgmodule);
                        addedModuleTypes.Add(type);
                        addedModuleMethods.Add(new Dictionary <string, MethodInfo>());
                    }
                }
            }
            Debug.Log("Mod " + etgmoduleMetadata.Name + " initialized with Mods.txt is bad.");
        }