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 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("------------------------------"); }