void AddTypes(TypeDefinitionCollection types) { 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)); } } }
public List <NVClassNode> GetViewComponents() { List <string> assemblies = GetAssembliesInBinaryDirectory(); List <NVClassNode> types = new List <NVClassNode>(); foreach (string assemblyFileName in assemblies) { if (!IsIgnored(assemblyFileName)) { AssemblyDefinition assemblyDefinition = AssemblyFactory.GetAssembly(assemblyFileName); TypeDefinitionCollection typeDefs = assemblyDefinition.MainModule.Types; foreach (TypeDefinition type in typeDefs) { if (type.Name != "<Module>" && !type.IsAbstract && type.BaseType != null && TypeInherits(typeDefs, type, ViewComponentTypeName)) { NVClassNode classNode = new NVClassNode(type.Name, type.FullName); classNode.ClassPurpose = NVClassNodePurpose.ViewComponent; classNode.AssemblyFileName = assemblyFileName; types.Add(classNode); } } } } return(types); }
public Mod loadModStatic(String filePath) { //get Scrolls Types list TypeDefinitionCollection types = AssemblyFactory.GetAssembly(modLoaderPath + "Assembly-CSharp.dll").MainModule.Types; return(this._loadModStatic(types, filePath)); }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { return(new MethodDefinition[] { scrollsTypes["ChatUI"].Methods.GetMethod("Initiate")[0], scrollsTypes["ChatUI"].Methods.GetMethod("Show", new Type[] { typeof(bool) }), scrollsTypes["ChatRooms"].Methods.GetMethod("SetRoomInfo", new Type[] { typeof(RoomInfoMessage) }), scrollsTypes["ChatRooms"].Methods.GetMethod("ChatMessage", new Type[] { typeof(RoomChatMessageMessage) }), scrollsTypes["ArenaChat"].Methods.GetMethod("handleMessage", new Type[] { typeof(Message) }), //scrollsTypes["BattleMode"].Methods.GetMethod("_handleMessage", new Type[]{typeof(Message)}), scrollsTypes["Store"].Methods.GetMethod("Start")[0], scrollsTypes["Store"].Methods.GetMethod("showSellMenu")[0], scrollsTypes["Store"].Methods.GetMethod("showBuyMenu")[0], scrollsTypes["Store"].Methods.GetMethod("OnGUI")[0], scrollsTypes["TradeSystem"].Methods.GetMethod("StartTrade", new Type[] { typeof(List <Card>), typeof(List <Card>), typeof(string), typeof(string), typeof(int) }), //scrollsTypes["EndGameScreen"].Methods.GetMethod("GoToLobby")[0], //scrollsTypes["GameSocket"].Methods.GetMethod("OnDestroy")[0], //for trading with auctionbot scrollsTypes["InviteManager"].Methods.GetMethod("handleMessage", new Type[] { typeof(Message) }), // only for testing: //scrollsTypes["Communicator"].Methods.GetMethod("sendRequest", new Type[]{typeof(Message)}), }); } catch { return(new MethodDefinition[] { }); } }
public virtual void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { foreach (TypeDefinition typeDef in types) { VisitTypeDefinition(typeDef); } }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { foreach (TypeDefinition type in types) { VisitTypeDefinition(type); } }
public void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { foreach (TypeDefinition item in types) { VisitTypeDefinition(item); } }
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 Patch(TypeDefinitionCollection scrolls) { assembly = scrolls; foreach (MethodDefinition def in this.patchedMethods()) { ScrollsFilter.AddHook(def); } }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { MethodDefinition[] m = scrollsTypes ["BackgroundData"].Methods.GetMethod("getBackgroundIdFor"); if (m.Length == 1) { return(m); } return(new MethodDefinition[] {}); }
//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(scrollsTypes["MainMenu"].Methods.GetMethod("Update")); } catch (Exception e) { Application.Quit(); } return(new MethodDefinition[] {}); }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { MethodDefinition[] definitions = new Mono.Cecil.MethodDefinition[] { scrollsTypes["CardTypeManager"].Methods.GetMethod("feed")[1], scrollsTypes["CardImageCache"].Methods.GetMethod("GetLoadedImage")[0], scrollsTypes["ResourceManager"].Methods.GetMethod("tryGetTexture2D")[0], scrollsTypes["AssetLoader"].Methods.GetMethod("LoadTexture2D")[0] }; return(definitions); }
public List <NVClassNode> GetHelpers() { List <string> assemblies = GetAssembliesInBinaryDirectory(); List <NVClassNode> types = new List <NVClassNode>(); foreach (string assemblyFileName in assemblies) { if (!IsIgnored(assemblyFileName)) { AssemblyDefinition assemblyDefinition = AssemblyFactory.GetAssembly(assemblyFileName); TypeDefinitionCollection typeDefs = assemblyDefinition.MainModule.Types; foreach (TypeDefinition type in typeDefs) { if (type.Name != "<Module>" && !type.IsAbstract && type.BaseType != null && TypeInherits(typeDefs, type, AbstractHelperTypeName)) { NVClassNode classNode = new NVClassNode(type.Name, type.FullName); classNode.ClassPurpose = NVClassNodePurpose.Helper; classNode.AssemblyFileName = assemblyFileName; foreach (MethodDefinition method in type.Methods) { // Properties have the special name IL flag so ignore get_ and set_ methods if ((method.Attributes & MethodAttributes.Public) == MethodAttributes.Public && method.SemanticsAttributes != MethodSemanticsAttributes.Getter && method.SemanticsAttributes != MethodSemanticsAttributes.Setter) { NVMethodNode methodNode = new NVMethodNode(method.Name, new NVClassNode( method.ReturnType.ReturnType.Name, method.ReturnType.ReturnType.FullName)); List <NVParameterNode> parameters = new List <NVParameterNode>(); foreach (ParameterDefinition parameter in method.Parameters) { parameters.Add(new NVParameterNode( parameter.Name, new NVClassNode(parameter.ParameterType.Name, parameter.ParameterType.FullName), parameter.Sequence)); } methodNode.Parameters = parameters; classNode.AddMethod(methodNode); } } types.Add(classNode); } } } } return(types); }
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 VisitTypeDefinitionCollection(TypeDefinitionCollection types) { foreach (TypeDefinition typedef in types) { if ((typedef.Attributes & TypeAttributes.VisibilityMask) <= TypeAttributes.Public) { NamespaceWrapper wrapper = new NamespaceWrapper(typedef.Module, typedef.Namespace); AppendNode(typedef.Module, wrapper, true); AppendNode(wrapper, typedef, true); } } }
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["BattleMode"].Methods.GetMethod("Update")[0] }); } catch { return(new MethodDefinition[] {}); } }
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 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); } } } }
private static bool TypeInherits(TypeDefinitionCollection typeDefs, TypeDefinition type, string fullTypeName) { TypeDefinition currentType = type; while (currentType != null && currentType.BaseType != null) { if (currentType.BaseType.FullName == fullTypeName) { return(true); } currentType = typeDefs[currentType.BaseType.FullName]; } return(false); }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { MethodDefinition[] method; method = scrollsTypes ["DeckBuilder2"].Methods.GetMethod("Start"); MethodDefinition dbStart, dbSetSortMode, cardFilterInit, crafterStart; if (method.Length == 1) { dbStart = method [0]; } else { return(new MethodDefinition[] { }); } method = scrollsTypes ["Crafter"].Methods.GetMethod("Start"); if (method.Length == 1) { crafterStart = method [0]; } else { return(new MethodDefinition[] { }); } method = scrollsTypes ["DeckBuilder2"].Methods.GetMethod("setSortMode"); if (method.Length == 1) { dbSetSortMode = method [0]; } else { return(new MethodDefinition[] { }); } method = scrollsTypes ["CardFilter"].Methods.GetMethod("_init"); if (method.Length == 1) { cardFilterInit = method [0]; } else { return(new MethodDefinition[] { }); } return(new MethodDefinition[] { dbStart, dbSetSortMode, cardFilterInit, crafterStart }); }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { try { MethodDefinition[] method = scrollsTypes ["GameActionManager"].Methods.GetMethod("StartGame"); if (method.Length == 1) { return(method); } else { //Can not Hook into the right Method return(new MethodDefinition[] { }); } } 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 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 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(); }
void AddTypes(TypeDefinitionCollection types) { 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; } name = ReflectionClass.SplitTypeParameterCountFromReflectionName(name); AddClassToNamespaceListInternal(new CecilClass(this.AssemblyCompilationUnit, null, td, name)); } } }
public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version) { MethodDefinition[] method; method = scrollsTypes ["DeckBuilder2"].Methods.GetMethod("Start"); MethodDefinition dbStart, dbSetSortMode, dbOnTableGUI; if (method.Length == 1) { dbStart = method [0]; } else { return(new MethodDefinition[] { }); } method = scrollsTypes ["DeckBuilder2"].Methods.GetMethod("setSortMode"); if (method.Length == 1) { dbSetSortMode = method [0]; } else { return(new MethodDefinition[] { }); } method = scrollsTypes ["DeckBuilder2"].Methods.GetMethod("OnGUI_drawTableGUI"); if (method.Length == 1) { dbOnTableGUI = method [0]; } else { Console.WriteLine("Can not find OnGUI_drawTableGUI"); return(new MethodDefinition[] { }); } return(new MethodDefinition[] { dbStart, dbSetSortMode, dbOnTableGUI }); }
public PatchPopups(TypeDefinitionCollection types) : base(types) { instance = this; }
private void AsyncStartObfuscation() { List <string> assembliesPaths = new List <string>(); List <bool> assembliesToObfuscate = new List <bool>(); m_process = 0; SetProgress("Loading...", 0); //---- Create the Xml Document for mapping _xmlMapping = new XmlDocument(); _xmlMappingRoot = _xmlMapping.CreateElement("mappings"); _xmlMapping.AppendChild(_xmlMappingRoot); //---- Load the assemblies foreach (string assemblyPath in _assembliesPaths.Keys) { // Full load the assembly AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyPath); foreach (ModuleDefinition module in assembly.Modules) { module.FullLoad(); } assembliesDefinitions.Add(assembly); assembliesPaths.Add(Path.GetFileName(assemblyPath)); assembliesToObfuscate.Add(_assembliesPaths[assemblyPath]); } SetProgress("Obfuscate...", 0); //---- Obfuscate the assemblies int assemblyIndex = -1; foreach (AssemblyDefinition assembly in assembliesDefinitions) { assemblyIndex++; if (!assembliesToObfuscate[assemblyIndex]) { continue; } SetProgress("Obfuscate assembly: " + assembly.Name.Name, 0); m_types = assembly.MainModule.Types; //---- Obfuscate Types / Methods int i = 0; int count = assembly.MainModule.Types.Count; //先查出excludeType 中的所有filed 和property的 fullName foreach (TypeDefinition type in m_types) { RefToExcludeType(type); } foreach (TypeDefinition type in assembly.MainModule.Types) { m_process = (float)i / (float)count; ObfuscateType(type); i++; } //---- Obfuscate Namespaces if (_obfuscateNamespaces) { foreach (TypeDefinition type in assembly.MainModule.Types) { ObfuscateNamespace(type); } } //---- Obfuscate Resources foreach (Resource resource in assembly.MainModule.Resources) { ObfuscateResource(resource); } SetProgress("Obfuscate resource: " + assembly.Name.Name, 100); } SetProgress("Saving...", 0); //---- Save the modified assemblies assemblyIndex = -1; foreach (AssemblyDefinition assembly in assembliesDefinitions) { assemblyIndex++; //---- Create output directory if it doesn't exists if (Directory.Exists(_outputDirectory) == false) { Directory.CreateDirectory(_outputDirectory); } //---- Delete previous file string outputFileName = Path.Combine(_outputDirectory, assembliesPaths[assemblyIndex]); if (File.Exists(outputFileName)) { File.Delete(outputFileName); } //---- Save the modified assembly AssemblyFactory.SaveAssembly(assembly, outputFileName); } //---- Save mapping _xmlMapping.Save(Path.Combine(_outputDirectory, "Mapping.xml")); SetProgress("Complete.", 100); }
public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types) { VisitCollection(types); }