Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
        public void removeMod(LocalMod mod)
        {
            installedMods.Remove(mod);
            String folder = Path.GetDirectoryName(mod.installPath);

            if (Directory.Exists(folder))
            {
                Extensions.DeleteDirectory(folder);
            }
        }
Exemplo n.º 4
0
 public bool updateMod(LocalMod mod)
 {
     if (this.updateFile(mod))
     {
         this.updateConfig(mod);
         loader.queueRepatch();
         return(true);
     }
     return(false);
 }
Exemplo n.º 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);
 }
Exemplo n.º 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();
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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();
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 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 ();
             */
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 14
0
 public void _unloadMod(LocalMod mod)
 {
     modOrder.Remove(mod.localId);
     modInstances.Remove(mod.localId);
 }
Exemplo n.º 15
0
 public void unloadMod(LocalMod mod)
 {
     modManager.disableMod(mod, true);
     this._unloadMod(mod);
 }
Exemplo n.º 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 ();
            */
        }
Exemplo n.º 17
0
 public void _unloadMod(LocalMod mod)
 {
     modOrder.Remove (mod.localId);
     modInstances.Remove (mod.localId);
 }
Exemplo n.º 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 ();
 }
Exemplo n.º 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;
        }
Exemplo n.º 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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
 public String jsonConfigFromMod(LocalMod mod)
 {
     JsonWriter writer = new JsonWriter ();
     return writer.Write (mod);
 }
Exemplo n.º 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;
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 24
0
 public void removeMod(LocalMod mod)
 {
     installedMods.Remove (mod);
     String folder = Path.GetDirectoryName(mod.installPath);
     if (Directory.Exists (folder))
     {
         Extensions.DeleteDirectory(folder);
     }
 }
Exemplo n.º 25
0
 public void deinstallMod(LocalMod mod)
 {
     loader.unloadMod(mod);
     mod.queueForUninstall = true;
     updateConfig(mod);
 }
Exemplo n.º 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 ();
 }
Exemplo n.º 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);
        }
Exemplo n.º 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;
                }
            }
        }
Exemplo n.º 29
0
 public void disableMod(LocalMod mod)
 {
     this.disableMod (mod, true);
 }
Exemplo n.º 30
0
 public void setCurrentlyLoading(LocalMod mod)
 {
     currentlyLoading = mod;
 }
Exemplo n.º 31
0
        public String jsonConfigFromMod(LocalMod mod)
        {
            JsonWriter writer = new JsonWriter();

            return(writer.Write(mod));
        }
Exemplo n.º 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 ();
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 34
0
 public void unloadMod(LocalMod mod)
 {
     modManager.disableMod (mod, true);
     this._unloadMod (mod);
 }
Exemplo n.º 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;
        }
Exemplo n.º 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");
 }
Exemplo n.º 37
0
 public bool updateMod(LocalMod mod)
 {
     if (this.updateFile(mod))
     {
         this.updateConfig (mod);
         loader.queueRepatch ();
         return true;
     }
     return false;
 }
Exemplo n.º 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");
 }
Exemplo n.º 39
0
 public void disableMod(LocalMod mod)
 {
     this.disableMod(mod, true);
 }
Exemplo n.º 40
0
 public void setCurrentlyLoading(LocalMod mod)
 {
     currentlyLoading = mod;
 }
Exemplo n.º 41
0
 public void deinstallMod(LocalMod mod)
 {
     loader.unloadMod (mod);
     mod.queueForUninstall = true;
     updateConfig (mod);
 }