コード例 #1
0
 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));
         }
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: ModLoader.cs プロジェクト: MaPePeR/ScrollsModLoader
        public Mod loadModStatic(String filePath)
        {
            //get Scrolls Types list
            TypeDefinitionCollection types = AssemblyFactory.GetAssembly(modLoaderPath + "Assembly-CSharp.dll").MainModule.Types;

            return(this._loadModStatic(types, filePath));
        }
コード例 #4
0
ファイル: AuctionMod.cs プロジェクト: noHero123/auction.mod
        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[] { });
            }
        }
コード例 #5
0
 public virtual void VisitTypeDefinitionCollection(TypeDefinitionCollection types)
 {
     foreach (TypeDefinition typeDef in types)
     {
         VisitTypeDefinition(typeDef);
     }
 }
コード例 #6
0
 public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types)
 {
     foreach (TypeDefinition type in types)
     {
         VisitTypeDefinition(type);
     }
 }
コード例 #7
0
ファイル: MethodFinder.cs プロジェクト: PlumpMath/csharpos
 public void VisitTypeDefinitionCollection(TypeDefinitionCollection types)
 {
     foreach (TypeDefinition item in types)
     {
         VisitTypeDefinition(item);
     }
 }
コード例 #8
0
 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();
 }
コード例 #9
0
ファイル: Patch.cs プロジェクト: tbs005/ScrollsModLoader
 public Patch(TypeDefinitionCollection scrolls)
 {
     assembly = scrolls;
     foreach (MethodDefinition def in this.patchedMethods())
     {
         ScrollsFilter.AddHook(def);
     }
 }
コード例 #10
0
 public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version)
 {
     MethodDefinition[] m = scrollsTypes ["BackgroundData"].Methods.GetMethod("getBackgroundIdFor");
     if (m.Length == 1)
     {
         return(m);
     }
     return(new MethodDefinition[] {});
 }
コード例 #11
0
ファイル: MyMod.cs プロジェクト: llovett/scrolls-miner
 //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[] {});
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
 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);
         }
     }
 }
コード例 #16
0
 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[] { });
     }
 }
コード例 #17
0
ファイル: StatsOn.cs プロジェクト: daemuth/StatsOn
 public static MethodDefinition[] GetHooks(TypeDefinitionCollection scrollsTypes, int version)
 {
     try
     {
         return(new MethodDefinition[]
         {
             scrollsTypes["BattleMode"].Methods.GetMethod("Update")[0]
         });
     }
     catch
     {
         return(new MethodDefinition[] {});
     }
 }
コード例 #18
0
 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();
     }
 }
コード例 #19
0
ファイル: ModLoader.cs プロジェクト: MaPePeR/ScrollsModLoader
 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);
             }
         }
     }
 }
コード例 #20
0
        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);
        }
コード例 #21
0
        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 });
        }
コード例 #22
0
 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[] {});
     }
 }
コード例 #23
0
 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);
 }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: ModLoader.cs プロジェクト: MaPePeR/ScrollsModLoader
        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();
        }
コード例 #26
0
 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));
         }
     }
 }
コード例 #27
0
        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 });
        }
コード例 #28
0
 public PatchPopups(TypeDefinitionCollection types) : base(types)
 {
     instance = this;
 }
コード例 #29
0
        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);
        }
コード例 #30
0
 public override void VisitTypeDefinitionCollection(TypeDefinitionCollection types)
 {
     VisitCollection(types);
 }