예제 #1
0
        private Target CreateLoaderTargetFromPath(string folder)
        {
            Assembly unityEngineAssembly = Assembly.LoadFrom(ModManager.GetFilePathInDirectory("UnityEngine.dll", gameFolder));
            Assembly levelLoader         = Assembly.LoadFrom(ModManager.GetFilePathInDirectory("DIMOWAModLoader.dll", folder));// ("LevelLoaderHandler");

            Instruction[] modLoaderInstructions =
            {
                Instruction.Create(OpCodes.Ldstr, "DIMOWA Level Loader Handler foi iniciado | was started"),
                Instruction.Create(OpCodes.Call,  patcher.BuildCall(unityEngineAssembly.GetType("UnityEngine.Debug"),         "Log",               typeof(void), new[] { typeof(object) })),
                Instruction.Create(OpCodes.Ldstr, "TitleMenu - Awake"),
                Instruction.Create(OpCodes.Call,  patcher.BuildCall(levelLoader.GetType("DIMOWAModLoader.LevelLoaderHandler"),"LevelLoaderInnit",  typeof(void), new[] { typeof(string) }))
            };

            Target ModLoaderInnitTarget = new Target
            {
                Namespace          = "",
                Class              = "MainMenuHandler",
                Method             = "Awake",
                Indices            = new int[] { 0, 1, 2, 3 },
                Instructions       = modLoaderInstructions,
                InsertInstructions = true,
            };

            loaderDependecies = ModDataGatherer.ParseReferences(levelLoader.GetReferencedAssemblies());

            return(ModLoaderInnitTarget);
        }
예제 #2
0
 public DIMOWALoaderInstaller(string gameFolder, string directoryOfLoader)
 {
     this.gameFolder = gameFolder;
     patcher         = new Patcher(ModManager.GetFilePathInDirectory("Assembly-CSharp.dll", gameFolder));
     LoaderTarget    = CreateLoaderTargetFromPath(directoryOfLoader);
     TargetIndex     = IMOWA.IndexOfInstalledMod(LoaderTarget, patcher);
 }
예제 #3
0
        //https://weblog.west-wind.com/posts/2016/Dec/12/Loading-NET-Assemblies-out-of-Seperate-Folders
        private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)

        {
            if (args.Name.Contains(".resources"))
            {
                return(null);
            }
            Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == args.Name);

            if (assembly != null)
            {
                return(assembly);
            }

            string filename = (args.Name.Split(',')[0] + ".dll").ToLower(), filePath = "";

            string[] possiblePathsForTheAssembly = { modFolder, gameFolder };
            foreach (string s in possiblePathsForTheAssembly)

            {
                try
                {
                    filePath = ModManager.GetFilePathInDirectory(filename, s);

                    break;
                }
                catch { }
            }
            try
            {
                if (filePath != "")
                {
                    return(Assembly.LoadFrom(filePath));
                }

                Console.WriteLine("Couldn't find the reference: " + filename);
                return(null);
            }
            catch
            {
                Console.WriteLine("Couldn't load the reference in : " + filePath);
                return(null);
            }
        }
예제 #4
0
        public static string CopyAndGetImportantFileToManaged(string file, string gameFolder)
        {
            string filePath = "";

            try
            {
                filePath = ModManager.GetFilePathInDirectory(file, gameFolder);
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(FileNotFoundException))
                {
                    try
                    {
                        filePath = ModManager.GetFilePathInDirectory(file, Directory.GetCurrentDirectory());
                        File.Copy(filePath, ModManager.GetDirectoryInDirectory("Managed", gameFolder) + "\\" + file);
                    }
                    catch (Exception e)
                    {
                        if (e.GetType() == typeof(FileNotFoundException))
                        {
                            Console.WriteLine("The file " + file + " isn't inside the game's folder nor the program folder. Check if you got all the files from the download.");
                        }

                        else if (e.GetType() == typeof(DirectoryNotFoundException))
                        {
                            Console.WriteLine("Couldn't find the Managed sub folder inside the game's folder, make sure you gave the correct folder by deleting config.json or by editing config.json");
                        }
                        else
                        {
                            Console.WriteLine("An unexpected exception occured: " + e.Message + "  " + ex.StackTrace + "  " + ex.Source);
                        }
                        Console.ReadLine();

                        return("");
                    }
                }
            }
            return(filePath);
        }
예제 #5
0
        static void CopyFileAndReferencesToFolder(MOWAP modData, string folderToCopy, params string[] originFolders)
        {
            string fileName = Path.GetFileName(modData.DllFilePath);

            if (Directory.GetFiles(folderToCopy, fileName).Length == 0)
            {
                Console.WriteLine(Path.GetFileName(modData.DllFilePath) + " wasn't in " + folderToCopy + ", copying it there");
                File.Copy(modData.DllFilePath, folderToCopy + '/' + fileName);
            }

            for (int i = 0; i < modData.Dependencies.Length; i++)
            {
                if (Directory.GetFiles(folderToCopy, modData.Dependencies[i]).Length == 0)
                {
                    Console.WriteLine("{0} wasn't in the folder, copying it there", modData.Dependencies[i]);
                    string filePath = "";

                    foreach (string origin in originFolders)
                    {
                        try
                        {
                            filePath = ModManager.GetFilePathInDirectory(modData.Dependencies[i], origin);
                        }
                        catch { }
                    }
                    if (filePath != "")
                    {
                        File.Copy(modData.DllFilePath, folderToCopy + '/' + modData.Dependencies[i]);
                    }
                    else
                    {
                        Console.WriteLine("Couldn't find the file {0}, a dependencie of {1}, in any folder, make sure that it is in there", modData.Dependencies[i], modData.ModName);
                    }
                }
            }
        }
예제 #6
0
 public void ResetLoaderInstaller()
 {
     patcher = new Patcher(ModManager.GetFilePathInDirectory("Assembly-CSharp.dll", gameFolder));
 }
예제 #7
0
        public MOWAP GenerateModMOWAPFromDll(string file, Type imowaModInnitType)

        {
            MOWAP    mowap       = new MOWAP();
            string   path        = ModManager.GetFilePathInDirectory(file, modFolder);
            Assembly modAssembly = Assembly.LoadFrom(path);

            Type[] classesNoDll = modAssembly.GetTypes();

            //Ir em cada classe
            foreach (Type classeDoDll in classesNoDll)
            {
                //Ir em cada método de cada classe
                foreach (MethodInfo mInfo in classeDoDll.GetMethods())
                {
                    //Ir em cada atributo de cada método
                    foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo))
                    {
                        // Ver se é o atributo que queremos
                        if (attr.GetType() == imowaModInnitType)
                        {
                            string      modName = "";
                            int         modLoadingPlace = 0, modPriority = 0;
                            FieldInfo[] fields = attr.GetType().GetFields();

                            foreach (FieldInfo f in fields)
                            {
                                if (f.Name == "modName")
                                {
                                    modName = (string)f.GetValue(attr);
                                }
                                else if (f.Name == "modLoadingPlace")
                                {
                                    modLoadingPlace = (int)f.GetValue(attr);
                                }
                                else if (f.Name == "modPriority")
                                {
                                    modPriority = (int)f.GetValue(attr);
                                }
                            }

                            mowap = new MOWAP()
                            {
                                ModType         = classeDoDll,
                                ModInnitMethod  = mInfo.Name,
                                ModName         = modName,
                                ModLoadingPlace = modLoadingPlace,
                                ModPriority     = modPriority,
                                DllFilePath     = path,
                                Dependencies    = ParseReferences(modAssembly.GetReferencedAssemblies())
                            };
                            break;
                        }
                    }
                    if (mowap.ModInnitMethod == mInfo.Name)
                    {
                        break;
                    }
                }
                if (mowap.ModType == classeDoDll)
                {
                    break;
                }
            }
            return(mowap);
        }
예제 #8
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();
        }