public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{ typeof(Message) }), scrollsTypes["TradeSystem"].Methods.GetMethod("StartTrade", new Type[]{ typeof( List<Card>), typeof( List<Card>) ,typeof( string), typeof( string ), typeof( int) }), scrollsTypes["TradeSystem"].Methods.GetMethod("CloseTrade")[0], scrollsTypes["TradeSystem"].Methods.GetMethod("UpdateView", new Type[]{typeof(bool), typeof(TradeInfo), typeof(TradeInfo)}), scrollsTypes["CardView"].Methods.GetMethod("updateGraphics",new Type[]{typeof(Card)}), scrollsTypes["AnimPlayer"].Methods.GetMethod("UpdateOnly")[0], scrollsTypes["EndGameScreen"].Methods.GetMethod("GoToLobby")[0], scrollsTypes["BattleMode"].Methods.GetMethod("addDelay",new Type[]{typeof(float)}), scrollsTypes["iTween"].Methods.GetMethod("Launch",new Type[]{typeof(GameObject),typeof(Hashtable)}), scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("ShowEndTurn",new Type[]{typeof(bool)}), scrollsTypes["GUIBattleModeMenu"].Methods.GetMethod("toggleMenu")[0], scrollsTypes["DeckBuilder2"].Methods.GetMethod("OnGUI")[0], scrollsTypes["GameSocket"].Methods.GetMethod("Init", new Type[]{ typeof(ISocketListener) }), //scrollsTypes["ProfileMenu"].Methods.GetMethod("Start")[0], }; } catch( Exception ex ) { Console.WriteLine("****** HOOK FAILURE {0}", ex.ToString()); return new MethodDefinition[] { }; } }
public PatchModsMenu(TypeDefinitionCollection types, ModLoader loader) : base(types) { this.loader = loader; this.modManager = this.loader.modManager; this.repoManager = modManager.repoManager; }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{ typeof(Message) }), scrollsTypes["TradeSystem"].Methods.GetMethod("StartTrade")[0], scrollsTypes["TradeSystem"].Methods.GetMethod("CloseTrade")[0], scrollsTypes["TradeSystem"].Methods.GetMethod("UpdateView")[0], scrollsTypes["CardView"].Methods.GetMethod("updateGraphics")[0], scrollsTypes["AnimPlayer"].Methods.GetMethod("UpdateOnly")[0], scrollsTypes["Communicator"].Methods.GetMethod("handleNextMessage")[0], scrollsTypes["Communicator"].Methods.GetMethod("Update")[0], scrollsTypes["EndGameScreen"].Methods.GetMethod("GoToLobby")[0], scrollsTypes["BattleMode"].Methods.GetMethod("addDelay")[0], scrollsTypes["BattleMode"].Methods.GetMethod("effectDone")[0], scrollsTypes["iTween"].Methods.GetMethod("Launch")[0], scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("ShowEndTurn")[0], scrollsTypes["GUIBattleModeMenu"].Methods.GetMethod("toggleMenu")[0], scrollsTypes["DeckBuilder2"].Methods.GetMethod("OnGUI")[0] //scrollsTypes["ProfileMenu"].Methods.GetMethod("Start")[0], }; } catch( Exception ex ) { Console.WriteLine("****** HOOK FAILURE {0}", ex.ToString()); return new MethodDefinition[] { }; } }
public Patch(TypeDefinitionCollection scrolls) { assembly = scrolls; foreach (MethodDefinition def in this.patchedMethods()) { ScrollsFilter.AddHook (def); } }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["ChatRooms"].Methods.GetMethod("ChatMessage", new Type[]{typeof(RoomChatMessageMessage)}), scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{typeof(Message)}) }; } catch { return new MethodDefinition[] { }; } }
public static MethodDefinition[] GetPlayerHooks(TypeDefinitionCollection scrollsTypes, int version) { return new MethodDefinition[] { scrollsTypes["Communicator"].Methods.GetMethod("readNextMessage")[0], scrollsTypes["GUIBattleModeMenu"].Methods.GetMethod("toggleMenu")[0], scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("Start")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("Init")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("Raycast")[0], scrollsTypes["BattleModeUI"].Methods.GetMethod("ShowEndTurn")[0] }; }
//only return MethodDefinitions you obtained through the scrollsTypes object //safety first! surround with try/catch and return an empty array in case it fails public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { return new MethodDefinition[] { // unit speedup logic scrollsTypes["iTween"].Methods.GetMethod("Launch")[0], scrollsTypes["AnimPlayer"].Methods.GetMethod("UpdateOnly")[0], // configuration scrollsTypes["SettingsMenu"].Methods.GetMethod("OnGUI")[0], scrollsTypes["SceneLoader"].Methods.GetMethod("loadScene")[0], }; }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["DeckBuilder2"].Methods.GetMethod("OnGUI")[0] // to draw gui buttons on the deckbuilder screen }; } catch { return new MethodDefinition[] { }; } }
public TypeReference GetTypeDefinition (TypeDefinitionCollection members, TypeReference member) { foreach (TypeReference mr in members) { if ((mr.FullName == member.FullName) && ((mr.DeclaringType == null && member.DeclaringType == null) || (mr.DeclaringType != null && member.DeclaringType != null && mr.DeclaringType.FullName == member.DeclaringType.FullName ) ) ) return mr; } return null; }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { // hook handleMessage in battlemode for the GameInfo message for getting the opponent name scrollsTypes["BattleMode"].Methods.GetMethod("handleMessage", new Type[]{typeof(Message)}), }; } catch { return new MethodDefinition[] { }; } }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["MainMenu"].Methods.GetMethod("Start")[0], scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{typeof(Message)}), scrollsTypes["ArenaChat"].Methods.GetMethod("RoomEnter")[0], }; } catch { return new MethodDefinition[] { }; } }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["Login"].Methods.GetMethod("loadSettings")[0], scrollsTypes["Login"].Methods.GetMethod("saveSettings")[0], scrollsTypes["ApplicationController"].Methods.GetMethod("compareVersions", new Type[] { typeof(int) }) }; } catch { return new MethodDefinition[] {}; } }
public IAssembly CreateMockAssembly(params Type[] include) { IAssembly assembly = _mocks.DynamicMock<IAssembly>(); TypeDefinitionCollection mockTypes = new TypeDefinitionCollection(TestingAssembly.MainModule); foreach (TypeDefinition type in TestingAssembly.MainModule.Types) { foreach (Type reflected in include) { if (reflected.FullName == type.FullName) { mockTypes.Add(type.Clone()); } } } SetupResult.For(assembly.Types).Return(mockTypes); return assembly; }
public PatchModsMenu(TypeDefinitionCollection types) : base(types) { //get mod list //add mods repositories.Add (new Repo("ScrollsGuide", "http://Scrollsguide.com/repo")); downloadableMods.Add (new Mod("GameRecorder", "Record Games!", "v1.0")); downloadableMods.Add (new Mod("DeckSync", "Export/Import Decks!", "v1.0")); for (int i=0; i < 30; i++) downloadableMods.Add (new Mod("TestMod", "Fill that List!", "v2.0!")); installedMods.Add(new Mod("Logger", "Debug Network logging", "v0.1")); //downloadableMods.Add (new Mod("DeckSync")); }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["BattleMode"].Methods.GetMethod("handleInput")[0], scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0], scrollsTypes["EndGameScreen"].Methods.GetMethod("OnGUI")[0], scrollsTypes["LobbyMenu"].Methods.GetMethod("Update")[0], scrollsTypes["LobbyMenu"].Methods.GetMethod("OnGUI")[0], scrollsTypes["LobbyMenu"].Methods.GetMethod("fadeOutScene")[0], scrollsTypes["Login"].Methods.GetMethod("OnGUI")[0], scrollsTypes["Popups"].Methods.GetMethod("OnGUI")[0], scrollsTypes["SettingsMenu"].Methods.GetMethod("OnGUI")[0], //scrollsTypes["Tile"].Methods.GetMethod("FixedUpdate")[0], }; } catch { return new MethodDefinition[] { }; } }
internal ModuleDefinition(string name, AssemblyDefinition asm, StructureReader reader, bool main) : base(name) { if (asm == null) { throw new ArgumentNullException("asm"); } if (name == null || name.Length == 0) { throw new ArgumentNullException("name"); } m_asm = asm; m_main = main; #if !CF_1_0 m_mvid = Guid.NewGuid(); #endif if (reader != null) { m_image = reader.Image; m_imgReader = reader.ImageReader; m_manifestOnly = reader.ManifestOnly; } else { m_image = Image.CreateImage(); } m_modRefs = new ModuleReferenceCollection(this); m_asmRefs = new AssemblyNameReferenceCollection(this); m_res = new ResourceCollection(this); m_types = new TypeDefinitionCollection(this); m_types.OnTypeDefinitionAdded += new TypeDefinitionEventHandler(OnTypeDefinitionAdded); m_types.OnTypeDefinitionRemoved += new TypeDefinitionEventHandler(OnTypeDefinitionRemoved); m_refs = new TypeReferenceCollection(this); m_refs.OnTypeReferenceAdded += new TypeReferenceEventHandler(OnTypeReferenceAdded); m_refs.OnTypeReferenceRemoved += new TypeReferenceEventHandler(OnTypeReferenceRemoved); m_members = new MemberReferenceCollection(this); m_controller = new ReflectionController(this); }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { base.VisitTypeDefinitionCollection(types); ReadGenericParameterConstraints(); ReadClassLayoutInfos(); ReadFieldLayoutInfos(); ReadPInvokeInfos(); ReadProperties(); ReadEvents(); ReadSemantics(); ReadInterfaces(); ReadOverrides(); ReadSecurityDeclarations(); ReadCustomAttributes(); ReadConstants(); ReadExternTypes(); ReadMarshalSpecs(); ReadInitialValues(); m_events = null; m_properties = null; m_parameters = null; }
public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types) { base.VisitTypeDefinitionCollection (types); ReadGenericParameterConstraints (); ReadClassLayoutInfos (); ReadFieldLayoutInfos (); ReadPInvokeInfos (); ReadProperties (); ReadEvents (); ReadSemantics (); ReadInterfaces (); ReadOverrides (); ReadSecurityDeclarations (); ReadCustomAttributes (); ReadConstants (); ReadExternTypes (); ReadMarshalSpecs (); ReadInitialValues (); m_events = null; m_properties = null; m_parameters = null; }
public CecilProjectContent(string fullName, string fileName, AssemblyName[] referencedAssemblies, TypeDefinitionCollection types, ProjectContentRegistry registry) : base(fullName, fileName, referencedAssemblies, registry) { foreach (TypeDefinition td in types) { if ((td.Attributes & TypeAttributes.Public) == TypeAttributes.Public) { if ((td.Attributes & TypeAttributes.NestedAssembly) == TypeAttributes.NestedAssembly || (td.Attributes & TypeAttributes.NestedPrivate) == TypeAttributes.NestedPrivate || (td.Attributes & TypeAttributes.NestedFamANDAssem) == TypeAttributes.NestedFamANDAssem) { continue; } string name = td.FullName; if (name.Length == 0 || name[0] == '<') continue; if (name.Length > 2 && name[name.Length - 2] == '`') name = name.Substring(0, name.Length - 2); AddClassToNamespaceListInternal(new CecilClass(this.AssemblyCompilationUnit, null, td, name)); } } InitializeSpecialClasses(); }
public override void VisitTypeDefinitionCollection (TypeDefinitionCollection types) { VisitCollection (types); }
public virtual void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { foreach (TypeDefinition typeDef in types) { VisitTypeDefinition(typeDef); } }
/*public void handleMessage(Message msg) { if (msg is RoomInfoMessage) { JsonReader jsonReader = new JsonReader(); Dictionary<string, object> dictionary = (Dictionary<string, object>)jsonReader.Read(msg.getRawText()); Dictionary<string, object>[] d = (Dictionary<string, object>[])dictionary["profiles"]; string tmpid = ""; string tmpname = ""; for (int i = 0; i < d.GetLength(0); i++) { tmpid=d[i]["id"].ToString(); tmpname = d[i]["name"].ToString(); playerinfo tmpplayer = new playerinfo(); tmpplayer.name = tmpname; tmpplayer.ID = tmpid; if (!liplayerinfo.Contains(tmpplayer)) { liplayerinfo.Add(tmpplayer); } } } return; } public void onReconnect() { return; // don't care }*/ //only return MethodDefinitions you obtained through the scrollsTypes object //safety first! surround with try/catch and return an empty array in case it fails public static MethodDefinition[] GetHooks (TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["BattleMode"].Methods.GetMethod("sendBattleRequest", new Type[]{typeof(Message)}), scrollsTypes["BattleMode"].Methods.GetMethod("OnGUI")[0], scrollsTypes["BattleMode"].Methods.GetMethod("Update")[0], scrollsTypes["BattleMode"].Methods.GetMethod("tileOver", new Type[]{typeof(TilePosition)} ), scrollsTypes["BattleMode"].Methods.GetMethod("tileOut", new Type[]{typeof(GameObject),typeof(int),typeof(int)} ), scrollsTypes["BattleMode"].Methods.GetMethod("toggleUnitStats")[0], scrollsTypes["Unit"].Methods.GetMethod("renderUnit")[0], scrollsTypes["BattleMode"].Methods.GetMethod("markMoveTile", new Type[]{typeof(TilePosition),typeof(TilePosition)} ), scrollsTypes["Tile"].Methods.GetMethod("markInternal", new Type[]{typeof(Tile.SelectionType),typeof(float)} ), scrollsTypes["BattleMode"].Methods.GetMethod("forceRunEffect", new Type[]{typeof(EffectMessage)}), // scrollsTypes["BattlemodeUI"].Methods.GetMethod("Update")[0], //scrollsTypes["Tile"].Methods.GetMethod("updateMoveAnim")[0], //scrollsTypes["ChatUI"].Methods.GetMethod("OnGUI")[0], }; } catch { return new MethodDefinition[] { }; } }
public void loadModsStatic(TypeDefinitionCollection types) { //get Mods foreach (LocalMod mod in modManager.installedMods) { if (mod.enabled) { if (this.loadModStatic (mod.installPath) == null) { modManager.disableMod(mod, false); modOrder.Remove (mod.localId); } } } }
public virtual void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { }
public void loadModStatic(TypeDefinitionCollection types, String filepath) { this._loadModStatic (types, filepath); }
public void loadPatches(TypeDefinitionCollection types) { //get Patches patches.Add (new PatchUpdater (types)); patches.Add (new PatchPopups (types)); //patches.Add(new PatchOffline(types)); PatchSettingsMenu settingsMenuHook = new PatchSettingsMenu (types); publicAPI.setSceneCallback (settingsMenuHook); patches.Add (settingsMenuHook); PatchModsMenu modMenuHook = new PatchModsMenu (types, this); modMenuHook.Initialize (publicAPI); patches.Add (modMenuHook); //add Hooks addPatchHooks (); }
internal ModuleDefinition(string name, AssemblyDefinition asm, StructureReader reader, bool main) : base(name) { if (asm == null) throw new ArgumentNullException ("asm"); if (name == null || name.Length == 0) throw new ArgumentNullException ("name"); m_asm = asm; m_main = main; #if !CF_1_0 m_mvid = Guid.NewGuid (); #endif if (reader != null) { m_image = reader.Image; m_imgReader = reader.ImageReader; m_manifestOnly = reader.ManifestOnly; } else m_image = Image.CreateImage (); m_modRefs = new ModuleReferenceCollection (this); m_asmRefs = new AssemblyNameReferenceCollection (this); m_res = new ResourceCollection (this); m_types = new TypeDefinitionCollection (this); m_types.OnTypeDefinitionAdded += new TypeDefinitionEventHandler (OnTypeDefinitionAdded); m_types.OnTypeDefinitionRemoved += new TypeDefinitionEventHandler (OnTypeDefinitionRemoved); m_refs = new TypeReferenceCollection (this); m_refs.OnTypeReferenceAdded += new TypeReferenceEventHandler (OnTypeReferenceAdded); m_refs.OnTypeReferenceRemoved += new TypeReferenceEventHandler (OnTypeReferenceRemoved); m_members = new MemberReferenceCollection (this); m_controller = new ReflectionController (this); }
public PatchPopups(TypeDefinitionCollection types) : base(types) { instance = this; }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { // type def reading TypeDefTable typesTable = m_tableReader.GetTypeDefTable(); m_typeDefs = new TypeDefinition [typesTable.Rows.Count]; for (int i = 0; i < typesTable.Rows.Count; i++) { TypeDefRow type = typesTable [i]; TypeDefinition t = new TypeDefinition( m_root.Streams.StringsHeap [type.Name], m_root.Streams.StringsHeap [type.Namespace], type.Flags); t.MetadataToken = MetadataToken.FromMetadataRow(TokenType.TypeDef, i); m_typeDefs [i] = t; } // nested types if (m_tHeap.HasTable(NestedClassTable.RId)) { NestedClassTable nested = m_tableReader.GetNestedClassTable(); for (int i = 0; i < nested.Rows.Count; i++) { NestedClassRow row = nested [i]; TypeDefinition parent = GetTypeDefAt(row.EnclosingClass); TypeDefinition child = GetTypeDefAt(row.NestedClass); parent.NestedTypes.Add(child); } } foreach (TypeDefinition type in m_typeDefs) { types.Add(type); } // type ref reading if (m_tHeap.HasTable(TypeRefTable.RId)) { TypeRefTable typesRef = m_tableReader.GetTypeRefTable(); m_typeRefs = new TypeReference [typesRef.Rows.Count]; for (int i = 0; i < typesRef.Rows.Count; i++) { AddTypeRef(typesRef, i); } } else { m_typeRefs = new TypeReference [0]; } ReadTypeSpecs(); ReadMethodSpecs(); ReadMethods(); ReadGenericParameters(); // set base types for (int i = 0; i < typesTable.Rows.Count; i++) { TypeDefRow type = typesTable [i]; TypeDefinition child = m_typeDefs [i]; child.BaseType = GetTypeDefOrRef(type.Extends, new GenericContext(child)); } CompleteMethods(); ReadAllFields(); ReadMemberReferences(); }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { // type def reading TypeDefTable typesTable = m_tableReader.GetTypeDefTable (); m_typeDefs = new TypeDefinition [typesTable.Rows.Count]; for (int i = 0; i < typesTable.Rows.Count; i++) { TypeDefRow type = typesTable [i]; TypeDefinition t = new TypeDefinition ( m_root.Streams.StringsHeap [type.Name], m_root.Streams.StringsHeap [type.Namespace], type.Flags); t.MetadataToken = MetadataToken.FromMetadataRow (TokenType.TypeDef, i); m_typeDefs [i] = t; } // nested types if (m_tHeap.HasTable (NestedClassTable.RId)) { NestedClassTable nested = m_tableReader.GetNestedClassTable (); for (int i = 0; i < nested.Rows.Count; i++) { NestedClassRow row = nested [i]; TypeDefinition parent = GetTypeDefAt (row.EnclosingClass); TypeDefinition child = GetTypeDefAt (row.NestedClass); if (!IsDeleted (child)) parent.NestedTypes.Add (child); } } foreach (TypeDefinition type in m_typeDefs) if (!IsDeleted (type)) types.Add (type); // type ref reading if (m_tHeap.HasTable (TypeRefTable.RId)) { TypeRefTable typesRef = m_tableReader.GetTypeRefTable (); m_typeRefs = new TypeReference [typesRef.Rows.Count]; for (int i = 0; i < typesRef.Rows.Count; i++) AddTypeRef (typesRef, i); } else m_typeRefs = new TypeReference [0]; ReadTypeSpecs (); ReadMethodSpecs (); ReadMethods (); ReadGenericParameters (); // set base types for (int i = 0; i < typesTable.Rows.Count; i++) { TypeDefRow type = typesTable [i]; TypeDefinition child = m_typeDefs [i]; child.BaseType = GetTypeDefOrRef (type.Extends, new GenericContext (child)); } CompleteMethods (); ReadAllFields (); ReadMemberReferences (); }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { TypeDefTable tdTable = m_tableWriter.GetTypeDefTable (); if (types [Constants.ModuleType] == null) types.Add (new TypeDefinition ( Constants.ModuleType, string.Empty, TypeAttributes.NotPublic)); foreach (TypeDefinition t in types) m_typeDefStack.Add (t); (m_typeDefStack as ArrayList).Sort (TableComparers.TypeDef.Instance); for (int i = 0; i < m_typeDefStack.Count; i++) { TypeDefinition t = (TypeDefinition) m_typeDefStack [i]; if (t.Module.Assembly != m_mod.Assembly) throw new ReflectionException ("A type as not been correctly imported"); t.MetadataToken = new MetadataToken (TokenType.TypeDef, (uint) (i + 1)); } foreach (TypeDefinition t in m_typeDefStack) { TypeDefRow tdRow = m_rowWriter.CreateTypeDefRow ( t.Attributes, m_mdWriter.AddString (t.Name), m_mdWriter.AddString (t.Namespace), GetTypeDefOrRefToken (t.BaseType), 0, 0); tdTable.Rows.Add (tdRow); } }
//only return MethodDefinitions you obtained through the scrollsTypes object //safety first! surround with try/catch and return an empty array in case it fails public static MethodDefinition[] GetHooks (TypeDefinitionCollection scrollsTypes, int version) { try { return new MethodDefinition[] { scrollsTypes["BattleMode"].Methods.GetMethod("sendBattleRequest", new Type[]{typeof(Message)}), scrollsTypes["ChatUI"].Methods.GetMethod("Initiate")[0], scrollsTypes["ChatUI"].Methods.GetMethod("Awake")[0], scrollsTypes["ChatUI"].Methods.GetMethod("OnGUI")[0], scrollsTypes["ChatUI"].Methods.GetMethod("Show", new Type[]{typeof(bool)}), scrollsTypes["ArenaChat"].Methods.GetMethod("handleMessage", new Type[]{typeof(Message)}), scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{typeof(Message)}), scrollsTypes["ChatUI"].Methods.GetMethod("OnSendMessage",new Type[]{typeof(Room), typeof(string)}), scrollsTypes["MainMenu"].Methods.GetMethod("OnGUI")[0], scrollsTypes["GameSocket"].Methods.GetMethod("OnDestroy")[0], }; } catch { return new MethodDefinition[] { }; } }
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; }