void Awake() { Debug.Log("No awake de mod loader"); gameObject.AddComponent <ClientDebuggerSide>(); DontDestroyOnLoad(gameObject); try { //MainMenuMods = new ModPriorityOrganizer(); //GameSceneMods = new ModPriorityOrganizer(); SpecificSceneMods = new Dictionary <int, ModPriorityOrganizer>(); //AllScenesMods = new ModPriorityOrganizer(); string dllExecutingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string modListFilePath = DirectorySearchTools.GetFilePathInDirectory(ModListOWFileName, dllExecutingPath); ModFolderAndList list = new ModFolderAndList(); ClassSerializer.ReadFromFile(modListFilePath, list); MOWAP[] mods = SearchMods.GetModsMOWAPS(dllExecutingPath, list); SeparateModsMethod(mods); } catch (Exception ex) { Debug.Log(string.Format("Something went wrong while loading the mods: {0} - {1} - {2}", ex.Message, ex.Source, ex.StackTrace)); } }
public ModDataHandler(string caminhoDoJogo, string caminhoDaPastaDeMods, string caminhoDaPastaDeManifestos) { string loaderModOWPath = ""; try { loaderModOWPath = DirectorySearchTools.GetFilePathInDirectory(loaderModOWFile, caminhoDoJogo); } catch { ConsoleWindowHelper.Warning(string.Format("{0} couldn't be found, the mod loader probrabilly hasn't been installed yet.", loaderModOWFile)); } ModEnabledList = new ModFolderAndList() { ModFolder = "", ModList = new string[] { } }; try { ClassSerializer.ReadFromFile(loaderModOWPath, ModEnabledList); } catch { ConsoleWindowHelper.Exception(string.Format("{0} couldn't be read, the problem can be fixed by pressing save.", loaderModOWFile)); } string[] todosOsJsons = Directory.GetFiles(caminhoDaPastaDeManifestos, "*manifest.json", SearchOption.AllDirectories); List <ModManifestJson> manifests = new List <ModManifestJson>(); for (int i = 0; i < todosOsJsons.Length; i++) { var modData = JsonReader.ReadFromJson <ModManifestJson>(todosOsJsons[i]); if (modData.FileName != dimowaModLoaderFile) { manifests.Add(modData); } else { ManifestDoLoader = modData; } } if (string.IsNullOrEmpty(ManifestDoLoader.FileName)) { ConsoleWindowHelper.FatalException("DIMOWAModLoader.dll needs to be inside the mods folder with its manifest.json, make sure that it is in there."); } ManifestsDosMods = manifests.ToArray(); DIMOWALoaderInstaller = new DIMOWALoaderInstaller(caminhoDoJogo, caminhoDaPastaDeMods); }
private void SaveModsButton_Click(object sender, EventArgs e) { try { for (int i = 0; i < ModEnableElement.ModEnableElements.Count; i++) { if (ModEnableElement.ModEnableElements[i].json.FileName != ModDataHandler.dimowaModLoaderFile) { if (ModEnableElement.ModEnableElements[i].IsEnabled && allEnabledMods.IndexOf(ModEnableElement.ModEnableElements[i].json.FileName) < 0) { allEnabledMods.Add(ModEnableElement.ModEnableElements[i].json.FileName); } else if (!ModEnableElement.ModEnableElements[i].IsEnabled && allEnabledMods.IndexOf(ModEnableElement.ModEnableElements[i].json.FileName) > -1) { allEnabledMods.Remove(ModEnableElement.ModEnableElements[i].json.FileName); } } } ModFolderAndList modList = new ModFolderAndList() { ModList = allEnabledMods.ToArray(), ModFolder = Config.ModsFolder }; ClassSerializer.WriteToFile(Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), ModDataHandler.loaderModOWFile), modList); if (ModEnableElement.ModEnableElements[0].IsEnabled) //Primeiro elemento é sempre do loader { //DIMOWALoaderInstaller.Install()/.Unistall() consomem bastante ram e cpu quanto chamados com o .Save() e continuam consumindo ele em seguida, parece ser algo relacionado com o tamanho do DLL (como se ele estivesse carregando todo ele para salvar mas não largando esse objeto) ; if (ModDataHandler.DIMOWALoaderInstaller.Install()) { string[] filesToCopy = { ModDataHandler.ManifestDoLoader.FileName }; foreach (string s in filesToCopy) { string fullPath = Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), s); if (!File.Exists(fullPath)) { File.Copy(DirectorySearchTools.GetFilePathInDirectory(ModDataHandler.ManifestDoLoader.FileName, Config.ModsFolder, Config.GameFolder), fullPath); } } ModDataHandler.DIMOWALoaderInstaller.SaveModifications(); ModDataHandler.DIMOWALoaderInstaller.ResetLoaderInstaller(); ConsoleWindowHelper.Log("DIMOWAModLoader has been successfully installed"); foreach (var element in ModEnableElement.ModEnableElements) { element.UnlockElement(); } } } else { if (ModDataHandler.DIMOWALoaderInstaller.Uninstall()) { ModDataHandler.DIMOWALoaderInstaller.SaveModifications(); ModDataHandler.DIMOWALoaderInstaller.ResetLoaderInstaller(); string[] filesToDelete = { ModDataHandler.ManifestDoLoader.FileName, ModDataHandler.loaderModOWFile }; foreach (string s in filesToDelete) { string fullPath = Path.Combine(DirectorySearchTools.GetDirectoryInDirectory("Managed", Config.GameFolder), s); if (File.Exists(fullPath)) { File.Delete(fullPath); } } ConsoleWindowHelper.Log("DIMOWAModLoader has been successfully uninstalled"); for (int i = 1; i < ModEnableElement.ModEnableElements.Count; i++) { ModEnableElement.ModEnableElements[i].LockElement(Color.Gray); } } } ConsoleWindowHelper.Log("All the changes have been performed and saved"); } catch (Exception ex) { ConsoleWindowHelper.FatalException("A Fatal Exception occured while saving: " + ex.Message + " check the Console Windows for more information."); ConsoleWindowHelper.Exception(string.Format("{0}: {1} {2}\nInner Exception Message: {3}", ex.Source, ex.Message, ex.StackTrace, ex.InnerException)); } }