コード例 #1
0
            internal static void ReloadModAssembly(object source, FileSystemEventArgs e, bool retrying = false)
            {
                if (!File.Exists(e.FullPath))
                {
                    return;
                }

                Logger.Log(LogLevel.Info, "loader", $"Reloading mod assembly: {e.FullPath}");
                QueuedTaskHelper.Do("ReloadModAssembly:" + e.FullPath, () => {
                    EverestModule module = _Modules.FirstOrDefault(m => m.Metadata.DLL == e.FullPath);
                    if (module == null)
                    {
                        return;
                    }

                    AssetReloadHelper.Do($"{Dialog.Clean("ASSETRELOADHELPER_RELOADINGMODASSEMBLY")} {Path.GetFileName(e.FullPath)}", () => {
                        Assembly asm = null;
                        using (FileStream stream = File.OpenRead(e.FullPath))
                            asm = Relinker.GetRelinkedAssembly(module.Metadata, Path.GetFileNameWithoutExtension(e.FullPath), stream);

                        if (asm == null)
                        {
                            if (!retrying)
                            {
                                // Retry.
                                QueuedTaskHelper.Do("ReloadModAssembly:" + e.FullPath, () => {
                                    ReloadModAssembly(source, e, true);
                                });
                            }
                            return;
                        }

                        ((FileSystemWatcher)source).Dispose();

                        // be sure to save this module's save data and session before reloading it, so that they are not lost.
                        if (SaveData.Instance != null)
                        {
                            Logger.Log("core", $"Saving save data slot {SaveData.Instance.FileSlot} for {module.Metadata} before reloading");
                            module.SaveSaveData(SaveData.Instance.FileSlot);

                            if (SaveData.Instance.CurrentSession?.InArea ?? false)
                            {
                                Logger.Log("core", $"Saving session slot {SaveData.Instance.FileSlot} for {module.Metadata} before reloading");
                                module.SaveSession(SaveData.Instance.FileSlot);
                            }
                        }

                        Unregister(module);
                        LoadModAssembly(module.Metadata, asm);
                    });
                    AssetReloadHelper.ReloadLevel();
                });
            }
コード例 #2
0
            private static void LoadAutoUpdated(object source, FileSystemEventArgs e)
            {
                if (!AutoLoadNewMods)
                {
                    return;
                }

                Logger.Log(LogLevel.Info, "loader", $"Possible new mod container: {e.FullPath}");
                QueuedTaskHelper.Do("LoadAutoUpdated:" + e.FullPath, () => AssetReloadHelper.Do($"{Dialog.Clean("ASSETRELOADHELPER_LOADINGNEWMOD")} {Path.GetFileName(e.FullPath)}", () => MainThreadHelper.Do(() => {
                    if (Directory.Exists(e.FullPath))
                    {
                        LoadDir(e.FullPath);
                    }
                    else if (e.FullPath.EndsWith(".zip"))
                    {
                        LoadZip(e.FullPath);
                    }
                    ((patch_OuiMainMenu)(AssetReloadHelper.ReturnToScene as Overworld)?.GetUI <OuiMainMenu>())?.RebuildMainAndTitle();
                })));
            }
コード例 #3
0
            internal static void ReloadModAssembly(object source, FileSystemEventArgs e, bool retrying = false)
            {
                if (!File.Exists(e.FullPath))
                {
                    return;
                }

                Logger.Log(LogLevel.Info, "loader", $"Reloading mod assembly: {e.FullPath}");
                QueuedTaskHelper.Do("ReloadModAssembly:" + e.FullPath, () => {
                    EverestModule module = _Modules.FirstOrDefault(m => m.Metadata.DLL == e.FullPath);
                    if (module == null)
                    {
                        return;
                    }

                    AssetReloadHelper.Do($"Reloading mod assembly: {Path.GetFileName(e.FullPath)}", () => {
                        Assembly asm = null;
                        using (FileStream stream = File.OpenRead(e.FullPath))
                            asm = Relinker.GetRelinkedAssembly(module.Metadata, stream);

                        if (asm == null)
                        {
                            if (!retrying)
                            {
                                // Retry.
                                QueuedTaskHelper.Do("ReloadModAssembly:" + e.FullPath, () => {
                                    ReloadModAssembly(source, e, true);
                                });
                            }
                            return;
                        }

                        ((FileSystemWatcher)source).Dispose();
                        Unregister(module);
                        LoadModAssembly(module.Metadata, asm);
                    });
                    AssetReloadHelper.ReloadLevel();
                });
            }