public ExceptionLogger(Mod m, Repo r) { this.version = m.version; this.url = r.url; this.id = m.id; this.type = ExceptionType.MOD; }
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 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); } }