コード例 #1
0
        private void SetProperty(GenericUnknownStruct.BaseClassEntry cls, string propertyName, object value)
        {
            foreach (var prop in cls.GetType().GetProperties())
            {
                var attrName = GetRealName(prop);
                if (attrName != null && attrName == propertyName)
                {
                    MappingHelper.GetPropertyHelper(prop).Set(cls, value);
                    return;
                }
            }

            throw new PropertyNotFoundException(cls.GetType().Name, propertyName);
        }
コード例 #2
0
        private void SetProperty(GenericUnknownStruct.BaseClassEntry cls, string propertyName, object value)
        {
            foreach (var prop in cls.GetType().GetProperties())
            {
                var attrName = GetRealName(prop);
                if (attrName != null && attrName == propertyName)
                {
                    if (MappingHelper.GetPropertyHelper(prop).IsDefault(value))
                    {
                        var ignore = OnWrongDefaultValue(new WrongDefaultValueEventArgs(cls.GetType().Name, propertyName, value));
                        if (!ignore)
                        {
                            throw new WrongDefaultValueException(cls.GetType().Name, propertyName, value);
                        }
                        _defaultValueOverride.Add(new DefaultValueOverrideEntry(cls, prop));
                    }

                    MappingHelper.GetPropertyHelper(prop).Set(cls, value);
                    return;
                }
            }

            throw new PropertyNotFoundException(cls.GetType().Name, propertyName);
        }
コード例 #3
0
        private string[] GenerateStringList(GenericUnknownStruct.BaseClassEntry cls)
        {
            var result = new HashSet <string>();

            if (_doMapping)
            {
                result.Add(GetRealName(cls.GetType()));
                GenerateStringListFromMappedFields(cls, ref result);
            }
            else
            {
                result.Add(((GenericUnknownStruct.ClassEntry)cls).Name);
                GenerateStringListFromUnmappedFields(((GenericUnknownStruct.ClassEntry)cls).Fields, ref result);
            }

            return(result.ToArray());
        }
コード例 #4
0
        private void GenerateStringListFromMappedFields(GenericUnknownStruct.BaseClassEntry cls, ref HashSet <string> strings)
        {
            var props = new List <KeyValuePair <PropertyInfo, object> >();

            foreach (var prop in cls.GetType().GetProperties())
            {
                var propValue = MappingHelper.GetPropertyHelper(prop).Get(cls);
                if (CanBeIgnored(cls, prop, propValue))
                {
                    continue;
                }

                props.Add(new KeyValuePair <PropertyInfo, object>(prop, propValue));
            }

            props = props
                    .GroupBy(p => p.Key.DeclaringType)
                    .Reverse()
                    .SelectMany(g => g)
                    .ToList();

            for (int i = 0; i < props.Count; i++)
            {
                var prop      = props[i].Key;
                var propValue = props[i].Value;
                var(typeString, baseType) = GetTypeStringFromProperty(prop, propValue);

                strings.Add(GetRealName(prop));
                strings.Add(typeString);

                if (prop.PropertyType.IsArray)
                {
                    var eleType = prop.PropertyType.GetElementType();
                    foreach (var val in (IList)propValue)
                    {
                        GetStringValueFromPropValue(eleType, val, baseType, ref strings);
                    }
                }
                else
                {
                    GetStringValueFromPropValue(prop.PropertyType, propValue, baseType, ref strings);
                }
            }
        }
コード例 #5
0
        private byte[] GenerateDataFromMappedFields(GenericUnknownStruct.BaseClassEntry cls)
        {
            byte[] result;

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII))
                {
                    var props = new List <KeyValuePair <PropertyInfo, object> >();

                    foreach (var prop in cls.GetType().GetProperties())
                    {
                        var propValue = MappingHelper.GetPropertyHelper(prop).Get(cls);
                        if (CanBeIgnored(prop, propValue))
                        {
                            continue;
                        }

                        props.Add(new KeyValuePair <PropertyInfo, object>(prop, propValue));
                    }

                    props = props
                            .GroupBy(p => p.Key.DeclaringType)
                            .Reverse()
                            .SelectMany(g => g)
                            .ToList();

                    writer.Write((ushort)props.Count);
                    foreach (var prop in props)
                    {
                        writer.Write((ushort)_stringList.IndexOf(GetRealName(prop.Key)));
                        var typeString = GetTypeStringFromProperty(prop.Key, cls);
                        writer.Write((ushort)_stringList.IndexOf(typeString));
                        writer.Write(new byte[4]); // offset
                    }

                    for (int i = 0; i < props.Count; i++)
                    {
                        var pos = writer.BaseStream.Position;
                        writer.BaseStream.Position = 6 + (i * 8);
                        writer.Write((uint)pos);
                        writer.BaseStream.Position = pos;

                        if (props[i].Key.PropertyType.IsArray)
                        {
                            var arr = (IList)props[i].Value;

                            writer.Write(arr.Count);
                            foreach (var val in arr)
                            {
                                WriteValueFromPropValue(writer, val);
                            }
                        }
                        else
                        {
                            WriteValueFromPropValue(writer, props[i].Value);
                        }
                    }
                }

                result = stream.ToArray();
            }

            return(result);
        }