コード例 #1
0
ファイル: ModManifestHandler.cs プロジェクト: ShoosGun/DIMOWA
        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);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.Title = "IMOWA 1.4";

            string caminhoDoJogo = "", caminhoDaPastaDeMods = "", caminhoDaPastaDeManifestos = "";

            string[] possibleConfig = Directory.GetFiles(Directory.GetCurrentDirectory(), "*config.json");
            if (possibleConfig.Length < 1)
            {
                Console.WriteLine("Game Path (can be any path that has the 'Managed' folder inside it)");
                caminhoDoJogo = Console.ReadLine();
                Console.WriteLine("Mod folder path");
                caminhoDaPastaDeMods       = Console.ReadLine();
                caminhoDaPastaDeManifestos = caminhoDaPastaDeMods;

                StreamWriter writer = new StreamWriter(File.Create(Directory.GetCurrentDirectory() + "/config.json"));
                //Descobrir maneira de colocar a char " dentro da string de maneira, "mais bela"
                string json = "{\n  " + (char)34 + "gameFolder" + (char)34 + ": " + (char)34 + caminhoDoJogo.Replace("\\", "/") + (char)34
                              + ",\n  " + (char)34 + "modsFolder" + (char)34 + ": " + (char)34 + caminhoDaPastaDeMods.Replace("\\", "/") + (char)34
                              + "\n}";
                writer.Write(json);
                writer.Flush();
                writer.Close();
            }
            else
            {
                try
                {
                    JsonReader json = new JsonReader(possibleConfig[0]);
                    caminhoDoJogo              = json.GetJsonElementFromRoot("gameFolder").Value;
                    caminhoDaPastaDeMods       = json.GetJsonElementFromRoot("modsFolder").Value;
                    caminhoDaPastaDeManifestos = caminhoDaPastaDeMods;
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Something went wrong while reading the config.json file, try deleting it and running the program again");
                    Console.WriteLine("Exception Message: " + ex.Message + "  " + ex.StackTrace + "  " + ex.Source);
                    Console.ReadLine();
                    return;
                }
            }
            int indexOfTheLoader = -1;

            string[] todosOsJsons = Directory.GetFiles(caminhoDaPastaDeManifestos, "*manifest.json", SearchOption.AllDirectories);
            string[] dllsDosMods  = new string[todosOsJsons.Length];

            for (int i = 0; i < todosOsJsons.Length; i++)
            {
                JsonReader json = new JsonReader(todosOsJsons[i]);
                dllsDosMods[i] = json.GetJsonElementFromRoot("filename").Value;
                if (dllsDosMods[i] == "DIMOWAModLoader.dll")
                {
                    if (indexOfTheLoader < 0)
                    {
                        indexOfTheLoader = i;
                    }
                }
            }
            if (indexOfTheLoader < 0)
            {
                Console.WriteLine("DIMOWAModLoader.dll needs to be inside the mods folder with its manifest.json, make sure that it is in there.");
                Console.ReadLine();
                return;
            }

            string camowaPath = CopyAndGetImportantFileToManaged("CAMOWA.dll", caminhoDoJogo);

            Type     imowaModInnitType = Assembly.LoadFrom(camowaPath).GetType("CAMOWA.IMOWAModInnit");
            Assembly unityEngine       = Assembly.LoadFrom(ModManager.GetFilePathInDirectory("UnityEngine.dll", caminhoDoJogo));

            List <MOWAP>    listOfMods = new List <MOWAP>();
            ModDataGatherer gatherer   = new ModDataGatherer(caminhoDaPastaDeMods, caminhoDoJogo);

            foreach (string fileName in new HashSet <string>(dllsDosMods))
            {
                if (fileName != dllsDosMods[indexOfTheLoader])
                {
                    listOfMods.Add(gatherer.GenerateModMOWAPFromDll(fileName, imowaModInnitType));
                }
            }

            string dimowaModLoaderPath = CopyAndGetImportantFileToManaged("DIMOWAModLoader.dll", caminhoDoJogo);

            if (dimowaModLoaderPath == "")
            {
                dimowaModLoaderPath = ModManager.GetFilePathInDirectory("DIMOWAModLoader.dll", caminhoDaPastaDeMods);
                File.Copy(dimowaModLoaderPath, ModManager.GetDirectoryInDirectory("Managed", caminhoDoJogo) + "\\DIMOWAModLoader.dll");
            }

            //criar o patcher para o loader e verificar se ele esta instalado
            DIMOWALoaderInstaller loaderInstaller = new DIMOWALoaderInstaller(caminhoDoJogo, caminhoDaPastaDeMods);
            bool loaderStatus = loaderInstaller.IsLoaderInstalled;


            ModManager modManager = new ModManager(caminhoDoJogo, listOfMods, unityEngine);//Impedir selecionar os mods até que o loader esteja instalado

            //fazer a parte de instalar os mods, mas que ele não feche o programa ao salvar


            bool[] modStatus = new bool[listOfMods.Count];
            for (int i = 0; i < modStatus.Length; i++)
            {
                modStatus[i] = modManager.IsTheModInstalled(i);
            }
            while (true)
            {
                Console.Clear();
                Console.WriteLine($" {modManager.AmountOfMods()} Mods ");
                Console.WriteLine("Mod index | Mod Name | Mod Status");

                Console.WriteLine("0 - Is DIMOWAModLoader enabled? " + (loaderStatus ? "yes" : "no"));

                if (loaderInstaller.IsLoaderInstalled)
                {
                    for (int i = 0; i < modStatus.Length; i++)
                    {
                        Console.WriteLine($"{i + 1} - Is " + listOfMods[i].ModName + " enabled? " + (modStatus[i] ? "yes" : "no"));
                    }
                }

                Console.WriteLine("Write the mod index to have more options, and 'close' to close the program");
                string str = Console.ReadLine();
                try
                {
                    if (str == "close")
                    {
                        break;
                    }

                    int index = Convert.ToInt32(str) - 1;

                    if (index != -1 && loaderInstaller.IsLoaderInstalled)
                    {
                        Console.WriteLine("Do you want to enable or disable " + listOfMods[index].ModName + "? (enable/disable)");
                        str = Console.ReadLine();
                        if (str.ToLower() == "enable")
                        {
                            modStatus[index] = true;
                        }
                        else if (str.ToLower() == "disable")
                        {
                            modStatus[index] = false;
                        }
                    }
                    else if (index == -1)
                    {
                        Console.WriteLine("Do you want to enable or disable DIMOWAModLoader? (enable/disable)");
                        str = Console.ReadLine();
                        if (str.ToLower() == "enable")
                        {
                            loaderStatus = true;
                        }
                        else if (str.ToLower() == "disable")
                        {
                            loaderStatus = false;
                        }
                    }
                }
                catch
                {
                    Console.WriteLine("The value you gave isn't numeric or it isn't valid (ie: negative or above the size of the mod list)");
                    Console.ReadLine();
                }
            }
            Console.WriteLine("Perform the changes to the game?(yes/no)");
            string s = Console.ReadLine();

            if (s.ToLower() == "yes")
            {
                string managedDirectoryPath = Directory.GetDirectories(caminhoDoJogo, "*Managed", SearchOption.AllDirectories)[0];

                if (loaderInstaller.IsLoaderInstalled)
                {
                    for (int i = 0; i < modStatus.Length; i++)
                    {
                        int ind = i;
                        if (i >= indexOfTheLoader)
                        {
                            ind += 1;
                        }
                        string arquivoDoMod = dllsDosMods[ind];
                        if (modStatus[i])//Instalar == true
                        {
                            if (modManager.InstallMod(i))
                            {
                                Console.WriteLine(listOfMods[i].ModName + " has been successfully installed");
                                CopyFileAndReferencesToFolder(listOfMods[i], managedDirectoryPath, caminhoDaPastaDeMods, caminhoDoJogo);
                            }
                        }
                        else
                        {
                            if (modManager.UninstallMod(i))
                            {
                                Console.WriteLine(listOfMods[i].ModName + " has been successfully uninstalled");
                                if (Directory.GetFiles(managedDirectoryPath, arquivoDoMod).Length > 0)
                                {
                                    Console.WriteLine("{0} is still in the folder, removing it from there", arquivoDoMod);
                                    File.Delete(managedDirectoryPath + '/' + arquivoDoMod);
                                }
                            }
                        }
                    }
                    modManager.SaveModifications();
                }

                if (loaderStatus)
                {
                    if (loaderInstaller.Install())
                    {
                        Console.WriteLine("DIMOWAModLoader has been successfully installed");

                        CopyFileAndReferencesToFolder(new MOWAP {
                            Dependencies = loaderInstaller.loaderDependecies, DllFilePath = dimowaModLoaderPath
                        }, managedDirectoryPath, caminhoDaPastaDeMods, caminhoDoJogo);
                    }
                }
                else
                {
                    loaderInstaller.Uninstall();
                }

                loaderInstaller.SaveModifications();

                Console.WriteLine("All the changes have been performed and saved");
            }

            Console.WriteLine("Press ENTER to close the window. . .");
            Console.ReadLine();
        }