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