Beispiel #1
0
            public static void LoadMod(EverestModuleMetadata meta, Assembly asm)
            {
                Content.Crawl(null, asm);

                Type[] types;
                try {
                    types = asm.GetTypes();
                } catch (Exception e) {
                    Logger.Log("loader", $"Failed reading assembly: {e}");
                    e.LogDetailed();
                    return;
                }
                for (int i = 0; i < types.Length; i++)
                {
                    Type type = types[i];
                    if (!typeof(EverestModule).IsAssignableFrom(type) || type.IsAbstract)
                    {
                        continue;
                    }

                    EverestModule mod = (EverestModule)type.GetConstructor(_EmptyTypeArray).Invoke(_EmptyObjectArray);
                    mod.Metadata = meta;
                    mod.Register();
                }
            }
Beispiel #2
0
            /// <summary>
            /// Find and load all EverestModules in the given assembly.
            /// </summary>
            /// <param name="meta">The mod metadata, preferably from the mod metadata.yaml file.</param>
            /// <param name="asm">The mod assembly, preferably relinked.</param>
            public static void LoadModAssembly(EverestModuleMetadata meta, Assembly asm) {
                if (Flags.IsDisabled || !Flags.SupportRuntimeMods) {
                    Logger.Log(LogLevel.Warn, "loader", "Loader disabled!");
                    return;
                }

                Content.Crawl(new AssemblyModContent(asm) {
                    Mod = meta,
                    Name = meta.Name
                });

                Type[] types;
                try {
                    types = asm.GetTypes();
                } catch (Exception e) {
                    Logger.Log(LogLevel.Warn, "loader", $"Failed reading assembly: {e}");
                    e.LogDetailed();
                    return;
                }

                for (int i = 0; i < types.Length; i++) {
                    Type type = types[i];

                    if (typeof(EverestModule).IsAssignableFrom(type) && !type.IsAbstract && !typeof(NullModule).IsAssignableFrom(type)) {
                        EverestModule mod = (EverestModule) type.GetConstructor(_EmptyTypeArray).Invoke(_EmptyObjectArray);
                        mod.Metadata = meta;
                        mod.Register();
                    }
                }
            }
Beispiel #3
0
            /// <summary>
            /// Find and load all EverestModules in the given assembly.
            /// </summary>
            /// <param name="meta">The mod metadata, preferably from the mod metadata.yaml file.</param>
            /// <param name="asm">The mod assembly, preferably relinked.</param>
            public static void LoadModAssembly(EverestModuleMetadata meta, Assembly asm)
            {
                if (Flags.IsDisabled || !Flags.SupportRuntimeMods)
                {
                    Logger.Log(LogLevel.Warn, "loader", "Loader disabled!");
                    return;
                }

                if (string.IsNullOrEmpty(meta.PathArchive) && File.Exists(meta.DLL) && meta.SupportsCodeReload && CoreModule.Settings.CodeReload)
                {
                    FileSystemWatcher watcher = meta.DevWatcher = new FileSystemWatcher {
                        Path         = Path.GetDirectoryName(meta.DLL),
                        NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite,
                    };

                    watcher.Changed += (s, e) => {
                        if (e.FullPath != meta.DLL)
                        {
                            return;
                        }
                        ReloadModAssembly(s, e);
                    };

                    watcher.EnableRaisingEvents = true;
                }

                ApplyModHackfixes(meta, asm);

                Content.Crawl(new AssemblyModContent(asm)
                {
                    Mod  = meta,
                    Name = meta.Name
                });

                Type[] types;
                try {
                    types = asm.GetTypes();
                } catch (Exception e) {
                    Logger.Log(LogLevel.Warn, "loader", $"Failed reading assembly: {e}");
                    e.LogDetailed();
                    return;
                }

                for (int i = 0; i < types.Length; i++)
                {
                    Type type = types[i];

                    if (typeof(EverestModule).IsAssignableFrom(type) && !type.IsAbstract && !typeof(NullModule).IsAssignableFrom(type))
                    {
                        EverestModule mod = (EverestModule)type.GetConstructor(_EmptyTypeArray).Invoke(_EmptyObjectArray);
                        mod.Metadata = meta;
                        mod.Register();
                    }
                }
            }
Beispiel #4
0
            /// <summary>
            /// Find and load all EverestModules in the given assembly.
            /// </summary>
            /// <param name="meta">The mod metadata, preferably from the mod metadata.yaml file.</param>
            /// <param name="asm">The mod assembly, preferably relinked.</param>
            public static void LoadModAssembly(EverestModuleMetadata meta, Assembly asm)
            {
                if (!Flags.SupportRuntimeMods)
                {
                    Logger.Log(LogLevel.Warn, "loader", "Loader disabled!");
                    return;
                }

                if (string.IsNullOrEmpty(meta.PathArchive) && File.Exists(meta.DLL) && meta.SupportsCodeReload && CoreModule.Settings.CodeReload)
                {
                    try {
                        FileSystemWatcher watcher = meta.DevWatcher = new FileSystemWatcher {
                            Path         = Path.GetDirectoryName(meta.DLL),
                            NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite,
                        };

                        watcher.Changed += (s, e) => {
                            if (e.FullPath != meta.DLL)
                            {
                                return;
                            }
                            ReloadModAssembly(s, e);
                            // FIXME: Should we dispose the old .dll watcher?
                        };

                        watcher.EnableRaisingEvents = true;
                    } catch (Exception e) {
                        Logger.Log(LogLevel.Warn, "loader", $"Failed watching folder: {Path.GetDirectoryName(meta.DLL)}");
                        e.LogDetailed();
                        meta.DevWatcher?.Dispose();
                        meta.DevWatcher = null;
                    }
                }

                ApplyModHackfixes(meta, asm);

                Content.Crawl(new AssemblyModContent(asm)
                {
                    Mod  = meta,
                    Name = meta.Name
                });

                Type[] types;
                try {
                    types = asm.GetTypesSafe();
                } catch (Exception e) {
                    Logger.Log(LogLevel.Warn, "loader", $"Failed reading assembly: {e}");
                    e.LogDetailed();
                    return;
                }

                bool foundModule = false;

                for (int i = 0; i < types.Length; i++)
                {
                    Type type = types[i];

                    if (typeof(EverestModule).IsAssignableFrom(type) && !type.IsAbstract)
                    {
                        foundModule = true;
                        if (!typeof(NullModule).IsAssignableFrom(type))
                        {
                            EverestModule mod = (EverestModule)type.GetConstructor(_EmptyTypeArray).Invoke(_EmptyObjectArray);
                            mod.Metadata = meta;
                            mod.Register();
                        }
                    }
                }

                // Warn if we didn't find a module, as that could indicate an oversight from the developer
                if (!foundModule)
                {
                    Logger.Log(LogLevel.Warn, "loader", "Assembly doesn't contain an EverestModule!");
                }
            }