public Patch(TypeDefinitionCollection scrolls) { assembly = scrolls; foreach (MethodDefinition def in this.patchedMethods()) { ScrollsFilter.AddHook(def); } }
public bool patchAssembly(String installPath) { if (installPath == null) { return(false); } //"weave" the assembly Console.WriteLine("------------------------------"); Console.WriteLine("ModLoader Hooks:"); ScrollsFilter.Log(); Console.WriteLine("------------------------------"); if (!weaveAssembly(installPath + "Assembly-CSharp.dll")) { return(false); } Console.WriteLine("Weaved Assembly"); /* * add init hack */ try { //load assembly Hooks.loadBaseAssembly(installPath + "Assembly-CSharp.dll"); //load self Hooks.loadInjectAssembly(installPath + "ScrollsModLoader.dll"); } catch (Exception exp) { //something must be gone horribly wrong if it crashes here Console.WriteLine(exp); return(false); } //add hooks if (!Hooks.hookStaticVoidMethodAtEnd("App.Awake", "ModLoader.Init")) { return(false); } try { //save assembly Console.WriteLine("Write back patched bytecode..."); Hooks.savePatchedAssembly(); Console.WriteLine("Platform specific patches..."); Platform.PlatformPatches(installPath); } catch (Exception exp) { //also very unlikely, but for safety Console.WriteLine(exp); return(false); } return(true); }
public void addPatchHooks() { foreach (Patch patch in patches) { try { foreach (MethodDefinition definition in patch.patchedMethods()) { ScrollsFilter.AddHook(definition); } } catch {} } }
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 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 PatchScrollsWindows() { String URL; if (Platform.getOS() == Platform.OS.Win) { URL = "http://download.scrolls.com/client/windows.zip"; } else { URL = "http://download.scrolls.com/client/mac.zip"; } String gameFolder = Path.GetFullPath(Directory.GetParent(Platform.getGlobalScrollsInstallPath()).Parent.Parent.Parent.FullName) + Path.DirectorySeparatorChar; //wait WebClientTimeOut webClient = new WebClientTimeOut(); if (File.Exists(gameFolder + "game.zip")) { File.Delete(gameFolder + "game.zip"); } try { webClient.DownloadFile(URL, gameFolder + "game.zip"); } catch (WebException) { App.Popups.KillCurrentPopup(); App.Popups.ShowOk(null, "info", "Error", "And error occured while downloading the update.", "OK"); return; } //backup assembly String backupPath = gameFolder + "ScrollsModLoader.dll"; if (File.Exists(backupPath)) { File.Delete(backupPath); } File.Copy(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll", backupPath); //backup modloader folder String modBackupPath = gameFolder + "ModLoader" + Path.DirectorySeparatorChar; if (Directory.Exists(modBackupPath)) { Extensions.DeleteDirectory(modBackupPath); } Directory.Move(Platform.getGlobalScrollsInstallPath() + "ModLoader", modBackupPath); File.Delete(modBackupPath + "mods.ini"); File.Delete(modBackupPath + "Assembly-CSharp.dll"); if (Platform.getOS() == Platform.OS.Win) { Extensions.DeleteDirectory(gameFolder + "game"); } else { Extensions.DeleteDirectory(gameFolder + "MacScrolls.app"); } //extract ZipFile zip = ZipFile.Read(gameFolder + "game.zip"); foreach (ZipEntry e in zip) { e.Extract(gameFolder + "game"); } //move assembly File.Copy(backupPath, Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll"); // File.Delete(backupPath); //move modloader folder back Directory.Move(modBackupPath, Platform.getGlobalScrollsInstallPath() + "ModLoader"); //make new repatch backup File.Copy(Platform.getGlobalScrollsInstallPath() + "Assembly-CSharp.dll", Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "Assembly-CSharp.dll"); //make sure mods get hooks set with new version File.Delete(Platform.getGlobalScrollsInstallPath() + "ModLoader" + Path.DirectorySeparatorChar + "mods.ini"); ScrollsFilter.clearHooks(); Console.WriteLine("Cleared Hooks"); //repatch Patcher patcher = new Patcher(); if (!patcher.patchAssembly(Platform.getGlobalScrollsInstallPath())) { if (!patcher.safeModePatchAssembly()) { Dialogs.showNotification("Summoner patch failed", "Summoner failed in patch itself into the updated files. It will uninstall itself. For more informations visit scrollsguide.com/summoner"); File.Delete(Platform.getGlobalScrollsInstallPath() + "ScrollsModLoader.dll"); Extensions.DeleteDirectory(Platform.getGlobalScrollsInstallPath() + "ModLoader"); } } Console.WriteLine("Now restarting the game..."); //restart the game Platform.RestartGame(); }
private Mod _loadModStatic(TypeDefinitionCollection types, String filepath) { ResolveEventHandler resolver = new ResolveEventHandler(CurrentDomainOnAssemblyResolve); AppDomain.CurrentDomain.AssemblyResolve += resolver; Assembly modAsm = null; try { modAsm = Assembly.LoadFile(filepath); } catch (BadImageFormatException) { AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } Type modClass = (from _modClass in modAsm.GetTypes() where _modClass.InheritsFrom(typeof(ScrollsModLoader.Interfaces.BaseMod)) select _modClass).First(); //no mod classes?? if (modClass == null) { AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } //get hooks MethodDefinition[] hooks = null; try { hooks = (MethodDefinition[])modClass.GetMethod("GetHooks").Invoke(null, new object[] { types, SharedConstants.getExeVersionInt() }); } catch (Exception e) { Console.WriteLine("Error executing GetHooks for mod: " + filepath); Console.WriteLine(e); AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } TypeDefinition[] typeDefs = new TypeDefinition[types.Count]; types.CopyTo(typeDefs, 0); //check hooks foreach (MethodDefinition hook in hooks) { //type/method does not exists if (hook == null) { Console.WriteLine("ERROR: GetHooks contains 'null'! "); Console.WriteLine("=> Disabling " + filepath); AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } if ((from type in typeDefs where type.Equals(hook.DeclaringType) //Code above avoids NullReferenceException when hook is null. select type).Count() == 0) { //disable mod Console.WriteLine("ERROR: Mod hooks unexistant method! " + filepath); AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } } //add hooks foreach (MethodDefinition hook in hooks) { ScrollsFilter.AddHook(hook); } //mod object for local mods on ModManager Mod mod = new Mod(); try { mod.id = "00000000000000000000000000000000"; mod.name = (String)modClass.GetMethod("GetName").Invoke(null, null); mod.version = (int)modClass.GetMethod("GetVersion").Invoke(null, null); mod.versionCode = "" + mod.version; mod.description = ""; } catch (Exception e) { Console.WriteLine("Error getting Name or Version: "); Console.WriteLine(e); AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(null); } AppDomain.CurrentDomain.AssemblyResolve -= resolver; return(mod); }
public ModLoader() { modLoaderPath = Platform.getGlobalScrollsInstallPath() + System.IO.Path.DirectorySeparatorChar + "ModLoader" + System.IO.Path.DirectorySeparatorChar; //load installed mods modManager = new ModManager(this); //load order list if (!File.Exists(modLoaderPath + "mods.ini")) { File.CreateText(modLoaderPath + "mods.ini").Close(); //first launch, set hooks for patches this.queueRepatch(); } modOrder = File.ReadAllLines(modLoaderPath + "mods.ini").ToList(); //match order with installed mods foreach (LocalMod mod in modManager.installedMods) { if (mod.enabled) { if (!modOrder.Contains(mod.localId)) { modOrder.Add(mod.localId); } } } //clean up not available mods foreach (String id in modOrder.ToArray()) { if (modManager.installedMods.Find(delegate(Item mod) { return((mod as LocalMod).localId.Equals(id)); }) == null) { modOrder.Remove(id); } } //get Scrolls Types list TypeDefinitionCollection types = AssemblyFactory.GetAssembly(modLoaderPath + "Assembly-CSharp.dll").MainModule.Types; //get ModAPI publicAPI = new APIHandler(this); //loadPatches this.loadPatches(types); //loadModsStatic this.loadModsStatic(types); //repatch this.repatchIfNeeded(); Console.WriteLine("------------------------------"); Console.WriteLine("ModLoader Hooks:"); ScrollsFilter.Log(); Console.WriteLine("------------------------------"); }