public RuleResult CheckAssembly(AssemblyDefinition assembly)
        {
            MethodDefinition entry_point = assembly.EntryPoint;

            if (entry_point != null)
            {
                // for EXE assemblies ignore the namespace of the entry point
                ignore.AddIfNew(entry_point.DeclaringType.Namespace);
            }

            // ignore assemblies with a single namespace
            int    count  = 0;
            string single = null;

            foreach (string ns in NamespaceEngine.NamespacesInside(assembly))
            {
                // no type inside the assembly
                if (ns == null)
                {
                    break;
                }

                // only count if there are some visible types inside the namespace
                bool visible = false;
                foreach (TypeDefinition type in NamespaceEngine.TypesInside(ns))
                {
                    if (type.IsVisible())
                    {
                        visible = true;
                        break;
                    }
                }

                if (visible)
                {
                    single = ns;
                    count++;
                }

                // no need to go more than 2
                if (count > 1)
                {
                    break;
                }
            }
            if (count == 1)
            {
                ignore.AddIfNew(single);
            }

            return(RuleResult.Success);
        }
Пример #2
0
        public void AccessedField(MosaField field)
        {
            if (!IsEnabled)
            {
                return;
            }

            if (!field.IsStatic)
            {
                return;
            }

            lock (accessedFields)
            {
                accessedFields.AddIfNew(field);
            }
        }
        private HashSet <Operand> CollectParamStores()
        {
            var paramSet = new HashSet <Operand>();

            foreach (var block in BasicBlocks)
            {
                for (var node = block.AfterFirst; !node.IsBlockEndInstruction; node = node.Next)
                {
                    if (node.IsEmptyOrNop)
                    {
                        continue;
                    }

                    if (node.Instruction.IsParameterStore)
                    {
                        paramSet.AddIfNew(node.Operand1);
                    }
                }
            }

            return(paramSet);
        }
        private static void EnrichItemsWithBestBaseTypeInformation(Dictionary <string, List <Dictionary <string, string> > > results, List <string> keys)
        {
            HashSet <string> resultingBases = new HashSet <string>();
            bool             apsRelevant    = false;

            foreach (var itemtype in results)
            {
                if (!FilterPolishUtil.FilterPolishConfig.GearClasses.Contains(itemtype.Key))
                {
                    continue;
                }

                if (FilterPolishUtil.FilterPolishConfig.BestBaseCheckIgnore.Contains(itemtype.Key.ToLower()))
                {
                    // rings, amulets and belts don't need any indication about the best base
                    continue;
                }

                if (!itemtype.Value.FirstOrDefault().ContainsKey("LevelSorting"))
                {
                    continue;
                }

                var itemgroups = new Dictionary <string, List <Dictionary <string, string> > >();

                if (itemtype.Key == "Boots" || itemtype.Key == "Body Armours" || itemtype.Key == "Helmets" || itemtype.Key == "Shields" || itemtype.Key == "Gloves")
                {
                    itemgroups = itemtype.Value.Subdivide(new List <Tuple <string, Func <Dictionary <string, string>, bool> > >()
                    {
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("ar", x => x["Game:Armour"] != "" && x["Game:Evasion"] == "" && x["Game:Energy Shield"] == ""),
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("ev", x => x["Game:Armour"] == "" && x["Game:Evasion"] != "" && x["Game:Energy Shield"] == ""),
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("es", x => x["Game:Armour"] == "" && x["Game:Evasion"] == "" && x["Game:Energy Shield"] != ""),
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("arev", x => x["Game:Armour"] != "" && x["Game:Evasion"] != "" && x["Game:Energy Shield"] == ""),
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("ares", x => x["Game:Armour"] != "" && x["Game:Evasion"] == "" && x["Game:Energy Shield"] != ""),
                        new Tuple <string, Func <Dictionary <string, string>, bool> >("eves", x => x["Game:Armour"] == "" && x["Game:Evasion"] != "" && x["Game:Energy Shield"] != "")
                    });
                }
                else
                {
                    itemgroups.Add("all", itemtype.Value);
                }

                foreach (var itemgroup in itemgroups)
                {
                    if (itemgroup.Value.FirstOrDefault().ContainsKey("ApsSorting"))
                    {
                        apsRelevant = true;
                    }

                    var rawingridients = itemgroup.Value
                                         .Where(x => !FilterPolishUtil.FilterPolishConfig.SpecialBases.Contains(x["BaseType"]))
                                         .Select(x => new { value = x, lvlSort = float.Parse(x["LevelSorting"]), apsSort = float.Parse(x["ApsSorting"]) });

                    var rawresults = rawingridients
                                     .MaxBy(x => x.lvlSort).ToList();

                    foreach (var item in rawresults)
                    {
                        resultingBases.AddIfNew(item.value["BaseType"]);
                    }

                    // get the best high speed weapons
                    if (itemtype.Key != "Rune Daggers" && itemtype.Key != "Staves")
                    {
                        var rawApsResults = rawingridients.Where(x => x.apsSort > 0.5f)
                                            .MaxBy(x => (x.apsSort * x.apsSort * x.apsSort) * x.lvlSort).ToList();

                        foreach (var item in rawApsResults)
                        {
                            resultingBases.AddIfNew(item.value["BaseType"]);
                        }
                    }
                }
            }

            foreach (var item in FilterPolishUtil.FilterPolishConfig.SpecialBases)
            {
                resultingBases.AddIfNew(item);
            }

            foreach (var item in FilterPolishUtil.FilterPolishConfig.ExtraBases)
            {
                resultingBases.AddIfNew(item);
            }

            FilterPolishUtil.FilterPolishConfig.TopBases = resultingBases;
        }
Пример #5
0
        protected HashSet <MosaUnit> GetIncluded(string value, out MosaUnit selected)
        {
            selected = null;

            value = value.Trim();

            if (string.IsNullOrWhiteSpace(value))
            {
                return(null);
            }

            if (value.Length < 1)
            {
                return(null);
            }

            var include = new HashSet <MosaUnit>();

            MosaUnit typeSelected   = null;
            MosaUnit methodSelected = null;

            foreach (var type in Compiler.TypeSystem.AllTypes)
            {
                bool typeIncluded = false;

                var typeMatch = type.FullName.Contains(value);

                if (typeMatch)
                {
                    include.Add(type);
                    include.AddIfNew(type.Module);

                    if (typeSelected == null)
                    {
                        typeSelected = type;
                    }
                }

                foreach (var method in type.Methods)
                {
                    bool methodMatch = method.FullName.Contains(value);

                    if (typeMatch || methodMatch)
                    {
                        include.Add(method);
                        include.AddIfNew(type);
                        include.AddIfNew(type.Module);

                        if (methodMatch && methodSelected == null)
                        {
                            methodSelected = method;
                        }
                    }
                }

                foreach (var property in type.Properties)
                {
                    if (typeIncluded || property.FullName.Contains(value))
                    {
                        include.Add(property);
                        include.AddIfNew(type);
                        include.AddIfNew(type.Module);
                    }
                }
            }

            selected = methodSelected ?? typeSelected;

            return(include);
        }