コード例 #1
0
        static CoreRedirects()
        {
            Assembly[] currentAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            IEnumerable <Type> netFields = currentAssemblies.SelectMany(x => x.GetTypes()).Where(x => x.GetCustomAttribute <NetFieldExportGroupAttribute>() != null);

            foreach (Type type in netFields)
            {
                NetFieldExportGroupAttribute             exportGroupAttribute = type.GetCustomAttribute <NetFieldExportGroupAttribute>();
                IEnumerable <PartialNetFieldExportGroup> partialAttributes    = type.GetCustomAttributes <PartialNetFieldExportGroup>();
                IEnumerable <RedirectPathAttribute>      redirectAttributes   = type.GetCustomAttributes <RedirectPathAttribute>();

                foreach (PartialNetFieldExportGroup partialAttribute in partialAttributes)
                {
                    PartialRedirects.Add(partialAttribute.PartialPath, exportGroupAttribute.Path);
                }

                if (redirectAttributes != null)
                {
                    foreach (RedirectPathAttribute redirectAttribute in redirectAttributes)
                    {
                        _redirects.TryAdd(redirectAttribute.Path, exportGroupAttribute.Path);
                    }
                }
            }
        }
コード例 #2
0
        public void SetParseType(ParsingGroup group, ParseType type)
        {
            switch (group)
            {
            case ParsingGroup.PlayerPawn:
                SetParseType(typeof(PlayerPawnC), type);                      //Normal player locations
                SetParseType(GetInheritedClasses(typeof(PlayerPawnC)), type); //Bot locations
                SetParseType(GetInheritedClasses(typeof(BaseVehicle)), type); //Vehicle locations (required for players in them)
                break;
            }

            List <Type> GetInheritedClasses(Type type)
            {
                List <Type> inheritedTypes = new List <Type>();

                IEnumerable <Type> allTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes());

                foreach (Type checkType in allTypes)
                {
                    if (checkType.IsSubclassOf(type))
                    {
                        NetFieldExportGroupAttribute netFieldExport = (NetFieldExportGroupAttribute)checkType.GetCustomAttributes(typeof(NetFieldExportGroupAttribute), true).FirstOrDefault();

                        if (netFieldExport != null)
                        {
                            inheritedTypes.Add(checkType);
                        }
                    }
                }

                return(inheritedTypes);
            }
        }
コード例 #3
0
        static NetFieldParser()
        {
            IEnumerable <Type> netFields = Assembly.GetExecutingAssembly().GetTypes().Where(x => x.GetCustomAttribute <NetFieldExportGroupAttribute>() != null);

            foreach (Type type in netFields)
            {
                NetFieldExportGroupAttribute attribute = type.GetCustomAttribute <NetFieldExportGroupAttribute>();

                if (attribute != null)
                {
                    _netFieldGroups[attribute.Path] = type;
                }

                NetFieldGroupInfo info = new NetFieldGroupInfo();

                _netFieldGroupInfo[type] = info;

                foreach (PropertyInfo property in type.GetProperties())
                {
                    NetFieldExportAttribute netFieldExportAttribute = property.GetCustomAttribute <NetFieldExportAttribute>();

                    if (netFieldExportAttribute == null)
                    {
                        continue;
                    }

                    info.Properties[netFieldExportAttribute.Name] = new NetFieldInfo
                    {
                        Attribute    = netFieldExportAttribute,
                        PropertyInfo = property
                    };
                }
            }

            //Type layout for dynamic arrays
            _primitiveTypeLayout.Add(typeof(bool), RepLayoutCmdType.PropertyBool);
            _primitiveTypeLayout.Add(typeof(byte), RepLayoutCmdType.PropertyByte);
            _primitiveTypeLayout.Add(typeof(ushort), RepLayoutCmdType.PropertyUInt16);
            _primitiveTypeLayout.Add(typeof(int), RepLayoutCmdType.PropertyInt);
            _primitiveTypeLayout.Add(typeof(uint), RepLayoutCmdType.PropertyUInt32);
            _primitiveTypeLayout.Add(typeof(ulong), RepLayoutCmdType.PropertyUInt64);
            _primitiveTypeLayout.Add(typeof(float), RepLayoutCmdType.PropertyFloat);
            _primitiveTypeLayout.Add(typeof(string), RepLayoutCmdType.PropertyString);

            IEnumerable <Type> iPropertyTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
                                                .Where(x => typeof(IProperty).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);

            //Allows deserializing IProperty type arrays
            foreach (var iPropertyType in iPropertyTypes)
            {
                _primitiveTypeLayout.Add(iPropertyType, RepLayoutCmdType.Property);
            }

            _primitiveTypeLayout.Add(typeof(object), RepLayoutCmdType.Ignore);

            AddDefaultExportGroups();
        }