Пример #1
0
        public bool downloadMod(LocalMod mod, String location)
        {
            Console.WriteLine(mod.source.url + "download/mod/" + mod.id);
            WebClientTimeOut wc = new WebClientTimeOut();

            try {
                wc.DownloadFile(new Uri(mod.source.url + "download/mod/" + mod.id), location);
            } catch (WebException) {
                return(false);
            }

            // now check whether the downloaded file is actually a mod, and not an error
            String[] keys = wc.ResponseHeaders.AllKeys;

            String contentType = "";

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].Equals("Content-Type"))
                {
                    contentType = wc.ResponseHeaders.Get(i);
                }
            }

            if (contentType.Equals("application/x-msdos-program"))             // success
            {
                return(true);
            }
            else             // for example "application/json" or none at all, error
            {
                return(false);
            }
        }
Пример #2
0
        public void installMod(Repo repo, Mod mod)
        {
            String newID       = this.generateUniqueID();
            String installPath = modsPath + Path.DirectorySeparatorChar + newID + Path.DirectorySeparatorChar + mod.name + ".mod.dll";

            LocalMod lmod = new LocalMod(false, installPath, newID, mod.id, repo, false, mod.name, mod.description, mod.version, mod.versionCode);

            String folder = modsPath + Path.DirectorySeparatorChar + newID + Path.DirectorySeparatorChar;

            if (Directory.Exists(folder))
            {
                Directory.Delete(folder);
            }
            Directory.CreateDirectory(folder);

            if (this.updateMod(lmod))
            {
                this.installedMods.Add(lmod);

                //add hooks
                loader.loadModStatic(lmod.installPath);
            }
            else
            {
                Extensions.DeleteDirectory(folder);
            }
        }
Пример #3
0
        public void removeMod(LocalMod mod)
        {
            installedMods.Remove(mod);
            String folder = Path.GetDirectoryName(mod.installPath);

            if (Directory.Exists(folder))
            {
                Extensions.DeleteDirectory(folder);
            }
        }
Пример #4
0
 public bool updateMod(LocalMod mod)
 {
     if (this.updateFile(mod))
     {
         this.updateConfig(mod);
         loader.queueRepatch();
         return(true);
     }
     return(false);
 }
Пример #5
0
 public Mod getModOnRepo(Repo source, LocalMod localMod)
 {
     foreach (Repo repo in repositories)
     {
         if (repo.Equals(source))
         {
             return((Mod)modsPerRepo [repo].Find(localMod.Equals));
         }
     }
     return(null);
 }
Пример #6
0
        public void moveModUp(LocalMod mod)
        {
            int index = modOrder.IndexOf(mod.localId);

            if (index > 0)
            {
                modOrder.Remove(mod.localId);
                modOrder.Insert(index - 1, mod.localId);
            }
            modManager.sortInstalledMods();
        }
Пример #7
0
        public void moveModDown(LocalMod mod)
        {
            int index = modOrder.IndexOf(mod.localId);

            if (index + 1 < modOrder.Count)
            {
                modOrder.Remove(mod.localId);
                modOrder.Insert(index + 1, mod.localId);
            }
            modManager.sortInstalledMods();
        }
Пример #8
0
        public void enableMod(LocalMod mod)
        {
            mod.enabled = true;
            this.updateConfig(mod);
            ScrollsFilter.clearHooks();
            String modLoaderPath           = Platform.getGlobalScrollsInstallPath() + "ModLoader" + System.IO.Path.DirectorySeparatorChar;
            TypeDefinitionCollection types = AssemblyFactory.GetAssembly(modLoaderPath + "Assembly-CSharp.dll").MainModule.Types;

            loader.loadModsStatic(types);
            loader.addPatchHooks();
            loader.loadMod(mod);
        }
Пример #9
0
 public void loadMods()
 {
     BaseMod.Initialize(publicAPI);
     foreach (String id in modOrder)
     {
         LocalMod lmod = (LocalMod)modManager.installedMods.Find(delegate(Item mod) {
             return((mod as LocalMod).localId.Equals(id));
         });
         if (lmod.enabled)
         {
             this.loadMod(lmod);
         }
     }
 }
Пример #10
0
 public void disableMod(LocalMod mod, bool rebuild)
 {
     mod.enabled = false;
     this.updateConfig(mod);
     loader._unloadMod(mod);
     if (rebuild)
     {
         ScrollsFilter.clearHooks();
         String modLoaderPath           = Platform.getModLoaderPath() + System.IO.Path.DirectorySeparatorChar;
         TypeDefinitionCollection types = AssemblyFactory.GetAssembly(modLoaderPath + "Assembly-CSharp.dll").MainModule.Types;
         loader.loadModsStatic(types);
         loader.addPatchHooks();
     }
 }
Пример #11
0
        public void updateConfig(LocalMod mod)
        {
            //update config
            String folder = Path.GetDirectoryName(mod.installPath) + Path.DirectorySeparatorChar;

            if (File.Exists(folder + "config.json"))
            {
                File.Delete(folder + "config.json");
            }
            StreamWriter configFile = File.CreateText(folder + "config.json");

            configFile.Write(this.jsonConfigFromMod(mod));
            configFile.Flush();
            configFile.Close();
            this.sortInstalledMods();
        }
Пример #12
0
        public bool updateFile(LocalMod mod)
        {
            String folder   = modsPath + Path.DirectorySeparatorChar + mod.localId + Path.DirectorySeparatorChar;
            String filePath = folder + mod.name + ".mod.dll";

            return(this.downloadMod(mod, filePath));

            /*
             * byte[] modData = this.downloadMod(mod);
             *
             * File.Delete (filePath);
             * FileStream modFile = File.Create (filePath);
             * modFile.Write (modData, 0, modData.Length);
             * modFile.Flush ();
             * modFile.Close ();
             */
        }
Пример #13
0
        public void loadInstalledMods()
        {
            List <String> folderList = (from subdirectory in Directory.GetDirectories(modsPath)
                                        where Directory.GetFiles(subdirectory, "*.mod.dll").Length != 0
                                        select subdirectory).ToList();

            foreach (String folder in folderList)
            {
                LocalMod mod = null;
                if (File.Exists(folder + Path.DirectorySeparatorChar + "config.json"))
                {
                    JsonReader reader = new JsonReader();
                    mod = (LocalMod)reader.Read(File.ReadAllText(folder + Path.DirectorySeparatorChar + "config.json"), typeof(LocalMod));
                    if (mod.queueForUninstall)
                    {
                        removeMod(mod);
                        continue;
                    }
                }
                else
                {
                    //new local installed mod
                    Mod localMod = loader.loadModStatic(Directory.GetFiles(folder, "*.mod.dll") [0]);
                    if (localMod != null)
                    {
                        mod = new LocalMod(true, (Directory.GetFiles(folder, "*.mod.dll") [0]), this.generateUniqueID(), null, null, true, localMod.name, localMod.description, localMod.version, localMod.versionCode);
                        updateConfig(mod);
                        loader.queueRepatch();
                    }
                }
                if (mod != null)
                {
                    installedMods.Add(mod);
                }
            }
        }
Пример #14
0
 public void _unloadMod(LocalMod mod)
 {
     modOrder.Remove(mod.localId);
     modInstances.Remove(mod.localId);
 }
Пример #15
0
 public void unloadMod(LocalMod mod)
 {
     modManager.disableMod(mod, true);
     this._unloadMod(mod);
 }
Пример #16
0
        public bool updateFile(LocalMod mod)
        {
            String folder = modsPath + Path.DirectorySeparatorChar + mod.localId + Path.DirectorySeparatorChar;
            String filePath = folder + mod.name + ".mod.dll";

            return this.downloadMod(mod, filePath);

            /*
            byte[] modData = this.downloadMod(mod);

            File.Delete (filePath);
            FileStream modFile = File.Create (filePath);
            modFile.Write (modData, 0, modData.Length);
            modFile.Flush ();
            modFile.Close ();
            */
        }
Пример #17
0
 public void _unloadMod(LocalMod mod)
 {
     modOrder.Remove (mod.localId);
     modInstances.Remove (mod.localId);
 }
Пример #18
0
 public void moveModUp(LocalMod mod)
 {
     int index = modOrder.IndexOf (mod.localId);
     if (index > 0) {
         modOrder.Remove (mod.localId);
         modOrder.Insert (index - 1, mod.localId);
     }
     modManager.sortInstalledMods ();
 }
Пример #19
0
        public void loadMod(LocalMod mod)
        {
            ResolveEventHandler resolver = new ResolveEventHandler(CurrentDomainOnAssemblyResolve);
            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            Assembly modAsm = null;
            try {
                modAsm = Assembly.LoadFile(mod.installPath);
            } catch (BadImageFormatException) {
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }
            Type modClass = (from _modClass in modAsm.GetTypes ()
                             where _modClass.InheritsFrom (typeof(BaseMod))
                             select _modClass).First();

            //no mod classes??
            if (modClass == null) {
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }

            publicAPI.setCurrentlyLoading (mod);

            int countmods = modInstances.Count;
            int countlog = logger.Count;
            try {
                ConstructorInfo modConstructor = modClass.GetConstructor (Type.EmptyTypes);
                if (modConstructor == null) {
                    //GetConstructor did not find a public Constructor
                    Console.WriteLine("Could not find public 0-Argument Constructor for mod: "+mod.getName());
                    ConstructorInfo[] allConstructors = modClass.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    foreach(ConstructorInfo c in allConstructors) {
                        if (c.GetParameters().Length == 0) {
                            Console.WriteLine("Found alternative Constructor! Please use a public Constructor for your Mod");
                            modConstructor = c;
                            break;
                        }
                    }
                    if (modConstructor == null) {
                        throw new Exception("Could not find any 0-Argument-Constructors");
                    }
                }
                modInstances.Add(mod.localId, (BaseMod)(modConstructor.Invoke (new object[0])));
                if (!mod.localInstall)
                    logger.Add (mod.localId, new ExceptionLogger (mod, mod.source));
            } catch (Exception exp) {
                Console.WriteLine (exp);
                if (modInstances.Count > countmods)
                    modInstances.Remove (mod.localId);
                if (logger.Count > countlog)
                    logger.Remove (mod.localId);
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }

            publicAPI.setCurrentlyLoading (null);

            if (!modOrder.Contains (mod.localId))
                modOrder.Add (mod.localId);

            AppDomain.CurrentDomain.AssemblyResolve -= resolver;
        }
Пример #20
0
        public static void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs e)
        {
            if ((e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("UnityEngine") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("Assembly-CSharp") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.GetName().Name.Equals("ScrollsModLoader") ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.Location.ToLower().Equals(Platform.getGlobalScrollsInstallPath().ToLower()) ||
                (e.ExceptionObject as Exception).TargetSite.Module.Assembly.Location.Equals(""))                  //no location or Managed => mod loader crash

            //log
            {
                Console.WriteLine(e.ExceptionObject);
                new ExceptionLogger().logException((Exception)e.ExceptionObject);

                //unload ScrollsModLoader
                MethodBodyReplacementProviderRegistry.SetProvider(new NoMethodReplacementProvider());

                //check for frequent crashes
                if (!System.IO.File.Exists(Platform.getGlobalScrollsInstallPath() + System.IO.Path.DirectorySeparatorChar + "check.txt"))
                {
                    System.IO.File.CreateText(Platform.getGlobalScrollsInstallPath() + System.IO.Path.DirectorySeparatorChar + "check.txt");
                    Platform.RestartGame();
                }
                else
                {
                    try {
                        foreach (String id in instance.modOrder)
                        {
                            BaseMod mod = instance.modInstances [id];
                            if (mod != null)
                            {
                                try {
                                    instance.unloadMod((LocalMod)instance.modManager.installedMods.Find(delegate(Item lmod) {
                                        return((lmod as LocalMod).id.Equals(id));
                                    }));
                                } catch (Exception exp) {
                                    Console.WriteLine(exp);
                                }
                            }
                        }
                    } catch (Exception exp) {
                        Console.WriteLine(exp);
                    }
                    instance.repatch();
                }
            }
            else if (instance != null && logger != null && logger.Count > 0)
            {
                Console.WriteLine(e.ExceptionObject);

                Assembly asm      = (e.ExceptionObject as Exception).TargetSite.Module.Assembly;
                Type     modClass = (from _modClass in asm.GetTypes()
                                     where _modClass.InheritsFrom(typeof(BaseMod))
                                     select _modClass).First();

                //no mod classes??
                if (modClass == null)
                {
                    return;
                }

                foreach (String id in instance.modOrder)
                {
                    BaseMod mod = null;
                    try {
                        mod = instance.modInstances [id];
                    } catch (Exception exp) {
                        Console.WriteLine(exp);
                    }
                    if (mod != null)
                    {
                        if (modClass.Equals(mod.GetType()))
                        {
                            String folder = Path.GetDirectoryName(asm.Location);
                            if (File.Exists(folder + Path.DirectorySeparatorChar + "config.json"))
                            {
                                JsonReader reader = new JsonReader();
                                LocalMod   lmod   = (LocalMod)reader.Read(File.ReadAllText(folder + Path.DirectorySeparatorChar + "config.json"), typeof(LocalMod));
                                if (!lmod.localInstall)
                                {
                                    logger [lmod.localId].logException((Exception)e.ExceptionObject);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #21
0
 public String jsonConfigFromMod(LocalMod mod)
 {
     JsonWriter writer = new JsonWriter ();
     return writer.Write (mod);
 }
Пример #22
0
 public Mod getModOnRepo(Repo source, LocalMod localMod)
 {
     foreach (Repo repo in repositories)
         if (repo.Equals (source))
             return (Mod)modsPerRepo [repo].Find (localMod.Equals);
     return null;
 }
Пример #23
0
        public void loadInstalledMods()
        {
            List<String> folderList = (from subdirectory in Directory.GetDirectories(modsPath)
                                   where Directory.GetFiles(subdirectory, "*.mod.dll").Length != 0
                                   select subdirectory).ToList();

            foreach (String folder in folderList) {
                LocalMod mod = null;
                if (File.Exists (folder + Path.DirectorySeparatorChar + "config.json")) {
                    JsonReader reader = new JsonReader ();
                    mod = (LocalMod) reader.Read (File.ReadAllText (folder + Path.DirectorySeparatorChar + "config.json"), typeof(LocalMod));
                    if (mod.queueForUninstall) {
                        removeMod (mod);
                        continue;
                    }
                } else {
                    //new local installed mod
                    Mod localMod = loader.loadModStatic (Directory.GetFiles (folder, "*.mod.dll") [0]);
                    if (localMod != null) {
                        mod = new LocalMod(true, (Directory.GetFiles (folder, "*.mod.dll") [0]), this.generateUniqueID(), null, null, true, localMod.name, localMod.description, localMod.version, localMod.versionCode);
                        updateConfig(mod);
                        loader.queueRepatch ();
                    }
                }
                if (mod != null)
                    installedMods.Add (mod);
            }
        }
Пример #24
0
 public void removeMod(LocalMod mod)
 {
     installedMods.Remove (mod);
     String folder = Path.GetDirectoryName(mod.installPath);
     if (Directory.Exists (folder))
     {
         Extensions.DeleteDirectory(folder);
     }
 }
Пример #25
0
 public void deinstallMod(LocalMod mod)
 {
     loader.unloadMod(mod);
     mod.queueForUninstall = true;
     updateConfig(mod);
 }
Пример #26
0
 public void updateConfig(LocalMod mod)
 {
     //update config
     String folder = Path.GetDirectoryName (mod.installPath) + Path.DirectorySeparatorChar;
     if (File.Exists(folder + "config.json"))
         File.Delete (folder + "config.json");
     StreamWriter configFile = File.CreateText (folder + "config.json");
     configFile.Write (this.jsonConfigFromMod (mod));
     configFile.Flush ();
     configFile.Close ();
     this.sortInstalledMods ();
 }
Пример #27
0
        public void enableMod(LocalMod mod)
        {
            mod.enabled = true;
            this.updateConfig (mod);
            ScrollsFilter.clearHooks ();

            String modLoaderPath = Platform.getModLoaderPath() + System.IO.Path.DirectorySeparatorChar;

            TypeDefinitionCollection types = AssemblyFactory.GetAssembly (modLoaderPath+"Assembly-CSharp.dll").MainModule.Types;
            loader.loadModsStatic (types);
            loader.addPatchHooks ();
            loader.loadMod (mod);
        }
Пример #28
0
        public bool downloadMod(LocalMod mod, String location)
        {
            Console.WriteLine (mod.source.url + "download/mod/" + mod.id);
            WebClientTimeOut wc = new WebClientTimeOut();

            try {
                wc.DownloadFile (new Uri(mod.source.url + "download/mod/" + mod.id), location);
            } catch (WebException) {
                return false;
            }

            // now check whether the downloaded file is actually a mod, and not an error
            String[] keys = wc.ResponseHeaders.AllKeys;

            String contentType = "";
            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].Equals("Content-Type"))
                {
                    contentType = wc.ResponseHeaders.Get(i);
                }
            }

            if (contentType.Equals("application/x-msdos-program")) // success
            {
                return true;
            }
            else
            {   // from github its an text/plain file
                if (mod.source.url.StartsWith ("https://raw.github.com/") && (contentType.Equals("text/plain") || contentType.Equals("application/octet-stream")))
                {
                    return true;
                }
                else // for example "application/json" or none at all, error
                {
                    return false;
                }
            }
        }
Пример #29
0
 public void disableMod(LocalMod mod)
 {
     this.disableMod (mod, true);
 }
Пример #30
0
 public void setCurrentlyLoading(LocalMod mod)
 {
     currentlyLoading = mod;
 }
Пример #31
0
        public String jsonConfigFromMod(LocalMod mod)
        {
            JsonWriter writer = new JsonWriter();

            return(writer.Write(mod));
        }
Пример #32
0
 public void moveModDown(LocalMod mod)
 {
     int index = modOrder.IndexOf (mod.localId);
     if (index+1 < modOrder.Count) {
         modOrder.Remove (mod.localId);
         modOrder.Insert (index + 1, mod.localId);
     }
     modManager.sortInstalledMods ();
 }
Пример #33
0
        public void installMod(Repo repo, Mod mod)
        {
            String newID = this.generateUniqueID ();
            String installPath = modsPath + Path.DirectorySeparatorChar + newID + Path.DirectorySeparatorChar + mod.name + ".mod.dll";

            LocalMod lmod = new LocalMod (false, installPath, newID, mod.id, repo, false, mod.name, mod.description, mod.version, mod.versionCode);

            String folder = modsPath + Path.DirectorySeparatorChar + newID + Path.DirectorySeparatorChar;
            if (Directory.Exists (folder))
            {
                Directory.Delete (folder);
            }
            Directory.CreateDirectory (folder);

            if (this.updateMod (lmod)) {
                this.installedMods.Add (lmod);

                //add hooks
                loader.loadModStatic (lmod.installPath);
            } else {
                Extensions.DeleteDirectory (folder);
            }
        }
Пример #34
0
 public void unloadMod(LocalMod mod)
 {
     modManager.disableMod (mod, true);
     this._unloadMod (mod);
 }
Пример #35
0
        public void loadMod(LocalMod mod)
        {
            ResolveEventHandler resolver = new ResolveEventHandler(CurrentDomainOnAssemblyResolve);

            AppDomain.CurrentDomain.AssemblyResolve += resolver;

            Assembly modAsm = null;

            try {
                modAsm = Assembly.LoadFile(mod.installPath);
            } catch (BadImageFormatException) {
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }
            Type modClass = (from _modClass in modAsm.GetTypes()
                             where _modClass.InheritsFrom(typeof(BaseMod))
                             select _modClass).First();


            //no mod classes??
            if (modClass == null)
            {
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }

            publicAPI.setCurrentlyLoading(mod);

            int countmods = modInstances.Count;
            int countlog  = logger.Count;

            try {
                ConstructorInfo modConstructor = modClass.GetConstructor(Type.EmptyTypes);
                if (modConstructor == null)
                {
                    //GetConstructor did not find a public Constructor
                    Console.WriteLine("Could not find public 0-Argument Constructor for mod: " + mod.getName());
                    ConstructorInfo[] allConstructors = modClass.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
                    foreach (ConstructorInfo c in allConstructors)
                    {
                        if (c.GetParameters().Length == 0)
                        {
                            Console.WriteLine("Found alternative Constructor! Please use a public Constructor for your Mod");
                            modConstructor = c;
                            break;
                        }
                    }
                    if (modConstructor == null)
                    {
                        throw new Exception("Could not find any 0-Argument-Constructors");
                    }
                }
                modInstances.Add(mod.localId, (BaseMod)(modConstructor.Invoke(new object[0])));
                if (!mod.localInstall)
                {
                    logger.Add(mod.localId, new ExceptionLogger(mod, mod.source));
                }
            } catch (Exception exp) {
                Console.WriteLine(exp);
                if (modInstances.Count > countmods)
                {
                    modInstances.Remove(mod.localId);
                }
                if (logger.Count > countlog)
                {
                    logger.Remove(mod.localId);
                }
                AppDomain.CurrentDomain.AssemblyResolve -= resolver;
                return;
            }

            publicAPI.setCurrentlyLoading(null);

            if (!modOrder.Contains(mod.localId))
            {
                modOrder.Add(mod.localId);
            }

            AppDomain.CurrentDomain.AssemblyResolve -= resolver;
        }
Пример #36
0
 public void ItemCanceled(UIListPopup popup, Item card)
 {
     deinstallCache = (LocalMod)card;
     App.Popups.ShowOkCancel(this, "removeMod", "Uninstallation Warning", "Are you sure you want to remove " + card.getName() + "?", "Uninstall", "Cancel");
 }
Пример #37
0
 public bool updateMod(LocalMod mod)
 {
     if (this.updateFile(mod))
     {
         this.updateConfig (mod);
         loader.queueRepatch ();
         return true;
     }
     return false;
 }
Пример #38
0
 public void ItemCanceled(UIListPopup popup, Item card)
 {
     deinstallCache = (LocalMod)card;
     App.Popups.ShowOkCancel (this, "removeMod", "Uninstallation Warning", "Are you sure you want to remove " + card.getName () + "?", "Uninstall", "Cancel");
 }
Пример #39
0
 public void disableMod(LocalMod mod)
 {
     this.disableMod(mod, true);
 }
Пример #40
0
 public void setCurrentlyLoading(LocalMod mod)
 {
     currentlyLoading = mod;
 }
Пример #41
0
 public void deinstallMod(LocalMod mod)
 {
     loader.unloadMod (mod);
     mod.queueForUninstall = true;
     updateConfig (mod);
 }