GetEnumType() public static method

public static GetEnumType ( MEGame game, string propName, string typeName ) : string
game MEGame
propName string
typeName string
return string
Esempio n. 1
0
        static UProperty ReadSpecialStructProp(IMEPackage pcc, MemoryStream stream, UProperty template, string structType)
        {
            if (stream.Position + 1 >= stream.Length)
            {
                throw new EndOfStreamException("tried to read past bounds of Export Data");
            }
            switch (template.PropType)
            {
            case PropertyType.FloatProperty:
                return(new FloatProperty(stream, template.Name));

            case PropertyType.IntProperty:
                return(new IntProperty(stream, template.Name));

            case PropertyType.ObjectProperty:
                return(new ObjectProperty(stream, template.Name));

            case PropertyType.StringRefProperty:
                return(new StringRefProperty(stream, template.Name));

            case PropertyType.NameProperty:
                return(new NameProperty(stream, pcc, template.Name));

            case PropertyType.BoolProperty:
                return(new BoolProperty(stream, pcc.Game, template.Name));

            case PropertyType.ByteProperty:
                if (template is EnumProperty)
                {
                    string enumType = UnrealObjectInfo.GetEnumType(pcc.Game, template.Name, structType);
                    return(new EnumProperty(stream, pcc, enumType, template.Name));
                }
                return(new ByteProperty(stream, template.Name));

            case PropertyType.BioMask4Property:
                return(new BioMask4Property(stream, template.Name));

            case PropertyType.StrProperty:
                return(new StrProperty(stream, template.Name));

            case PropertyType.ArrayProperty:
                return(ReadArrayProperty(stream, pcc, structType, template.Name, true));

            case PropertyType.StructProperty:
                PropertyCollection structProps = ReadSpecialStruct(pcc, stream, UnrealObjectInfo.GetPropertyInfo(pcc.Game, template.Name, structType).reference, 0);
                return(new StructProperty(structType, structProps, template.Name, true));

            case PropertyType.None:
                return(new NoneProperty(template.Name));

            case PropertyType.DelegateProperty:
                throw new NotImplementedException("cannot read Delegate property of Immutable struct");

            case PropertyType.Unknown:
                throw new NotImplementedException("cannot read Unknown property of Immutable struct");
            }
            throw new NotImplementedException("cannot read Unknown property of Immutable struct");
        }
Esempio n. 2
0
        public static PropertyCollection ReadProps(IMEPackage pcc, MemoryStream stream, string typeName, bool includeNoneProperty = false)
        {
            //Uncomment this for debugging property engine

            /*DebugOutput.StartDebugger("Property Engine ReadProps() for "+typeName);
             * if (pcc.FileName == "C:\\Users\\Dev\\Downloads\\ME2_Placeables.upk")
             * {
             * //Debugger.Break();
             * }*/
            PropertyCollection props = new PropertyCollection();
            long startPosition       = stream.Position;

            while (stream.Position + 8 <= stream.Length)
            {
                int nameIdx = stream.ReadValueS32();
                if (!pcc.isName(nameIdx))
                {
                    stream.Seek(-4, SeekOrigin.Current);
                    break;
                }
                string name = pcc.getNameEntry(nameIdx);
                if (name == "None")
                {
                    props.Add(new NoneProperty(stream, "None"));
                    stream.Seek(4, SeekOrigin.Current);
                    break;
                }
                NameReference nameRef = new NameReference {
                    Name = name, Number = stream.ReadValueS32()
                };
                int typeIdx = stream.ReadValueS32();
                stream.Seek(4, SeekOrigin.Current);
                int size = stream.ReadValueS32();
                if (!pcc.isName(typeIdx) || size < 0 || size > stream.Length - stream.Position)
                {
                    stream.Seek(-16, SeekOrigin.Current);
                    break;
                }
                stream.Seek(4, SeekOrigin.Current);
                PropertyType type;
                string       namev = pcc.getNameEntry(typeIdx);
                if (Enum.IsDefined(typeof(PropertyType), namev))
                {
                    Enum.TryParse(namev, out type);
                }
                else
                {
                    type = PropertyType.Unknown;
                }
                switch (type)
                {
                case PropertyType.StructProperty:
                    string structType = pcc.getNameEntry(stream.ReadValueS32());
                    stream.Seek(4, SeekOrigin.Current);
                    if (ME3UnrealObjectInfo.isImmutable(structType))
                    {
                        PropertyCollection structProps = ReadSpecialStruct(pcc, stream, structType, size);
                        var structprop = new StructProperty(structType, structProps, nameRef, true);
                        structprop.Offset = stream.Position - 4;
                        props.Add(structprop);
                    }
                    else
                    {
                        PropertyCollection structProps = ReadProps(pcc, stream, structType, includeNoneProperty);
                        var structprop = new StructProperty(structType, structProps, nameRef);
                        structprop.Offset = stream.Position - 4;
                        props.Add(structprop);
                    }
                    break;

                case PropertyType.IntProperty:
                    props.Add(new IntProperty(stream, nameRef));
                    break;

                case PropertyType.FloatProperty:
                    props.Add(new FloatProperty(stream, nameRef));
                    break;

                case PropertyType.ObjectProperty:
                    props.Add(new ObjectProperty(stream, nameRef));
                    break;

                case PropertyType.NameProperty:
                    props.Add(new NameProperty(stream, pcc, nameRef));
                    break;

                case PropertyType.BoolProperty:
                    props.Add(new BoolProperty(stream, pcc.Game, nameRef));
                    break;

                case PropertyType.BioMask4Property:
                    props.Add(new BioMask4Property(stream, nameRef));
                    break;

                case PropertyType.ByteProperty:
                {
                    if (size != 1)
                    {
                        NameReference enumType = new NameReference();
                        if (pcc.Game == MEGame.ME3)
                        {
                            enumType.Name   = pcc.getNameEntry(stream.ReadValueS32());
                            enumType.Number = stream.ReadValueS32();
                        }
                        else
                        {
                            enumType.Name = UnrealObjectInfo.GetEnumType(pcc.Game, name, typeName);
                        }
                        props.Add(new EnumProperty(stream, pcc, enumType, nameRef));
                    }
                    else
                    {
                        if (pcc.Game == MEGame.ME3)
                        {
                            stream.Seek(8, SeekOrigin.Current);
                        }
                        props.Add(new ByteProperty(stream, nameRef));
                    }
                }
                break;

                case PropertyType.ArrayProperty:
                {
                    props.Add(ReadArrayProperty(stream, pcc, typeName, nameRef));
                }
                break;

                case PropertyType.StrProperty:
                {
                    props.Add(new StrProperty(stream, nameRef));
                }
                break;

                case PropertyType.StringRefProperty:
                    props.Add(new StringRefProperty(stream, nameRef));
                    break;

                case PropertyType.DelegateProperty:
                    props.Add(new DelegateProperty(stream, pcc, nameRef));
                    break;

                case PropertyType.Unknown:
                {
                    props.Add(new UnknownProperty(stream, size, pcc.getNameEntry(typeIdx), nameRef));
                }
                break;

                case PropertyType.None:
                    if (includeNoneProperty)
                    {
                        props.Add(new NoneProperty(stream, "None"));
                    }
                    break;

                default:
                    break;
                }
            }
            if (props.Count > 0)
            {
                //error reading props.
                if (props[props.Count - 1].PropType != PropertyType.None)
                {
                    stream.Seek(startPosition, SeekOrigin.Begin);
                    return(new PropertyCollection {
                        endOffset = (int)stream.Position
                    });
                }
                //remove None Property
                if (!includeNoneProperty)
                {
                    props.RemoveAt(props.Count - 1);
                }
            }
            props.endOffset = (int)stream.Position;
            return(props);
        }
Esempio n. 3
0
        public static UProperty ReadArrayProperty(MemoryStream stream, IMEPackage pcc, string enclosingType, NameReference name, bool IsInImmutable = false)
        {
            long      arrayOffset = IsInImmutable ? stream.Position : stream.Position - 24;
            ArrayType arrayType   = UnrealObjectInfo.GetArrayType(pcc.Game, name, enclosingType);
            int       count       = stream.ReadValueS32();

            switch (arrayType)
            {
            case ArrayType.Object:
            {
                var props = new List <ObjectProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new ObjectProperty(stream));
                }
                return(new ArrayProperty <ObjectProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Name:
            {
                var props = new List <NameProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new NameProperty(stream, pcc));
                }
                return(new ArrayProperty <NameProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Enum:
            {
                var           props    = new List <EnumProperty>();
                NameReference enumType = new NameReference {
                    Name = UnrealObjectInfo.GetEnumType(pcc.Game, name, enclosingType)
                };
                for (int i = 0; i < count; i++)
                {
                    props.Add(new EnumProperty(stream, pcc, enumType));
                }
                return(new ArrayProperty <EnumProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Struct:
            {
                var    props           = new List <StructProperty>();
                string arrayStructType = UnrealObjectInfo.GetPropertyInfo(pcc.Game, name, enclosingType)?.reference;
                if (IsInImmutable || ME3UnrealObjectInfo.isImmutable(arrayStructType))
                {
                    int arraySize = 0;
                    if (!IsInImmutable)
                    {
                        stream.Seek(-16, SeekOrigin.Current);
                        arraySize = stream.ReadValueS32();
                        stream.Seek(12, SeekOrigin.Current);
                    }
                    for (int i = 0; i < count; i++)
                    {
                        long offset = stream.Position;
                        PropertyCollection structProps = ReadSpecialStruct(pcc, stream, arrayStructType, arraySize / count);
                        StructProperty     structP     = new StructProperty(arrayStructType, structProps, isImmutable: true);
                        structP.Offset = offset;
                        props.Add(structP);
                    }
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        long structOffset = stream.Position;
                        PropertyCollection structProps = ReadProps(pcc, stream, arrayStructType);
                        StructProperty     structP     = new StructProperty(arrayStructType, structProps);
                        structP.Offset = structOffset;
                        props.Add(structP);
                    }
                }
                return(new ArrayProperty <StructProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Bool:
            {
                var props = new List <BoolProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new BoolProperty(stream, pcc.Game));
                }
                return(new ArrayProperty <BoolProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.String:
            {
                var props = new List <StrProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new StrProperty(stream));
                }
                return(new ArrayProperty <StrProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Float:
            {
                var props = new List <FloatProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new FloatProperty(stream));
                }
                return(new ArrayProperty <FloatProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Byte:
            {
                var props = new List <ByteProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new ByteProperty(stream));
                }
                return(new ArrayProperty <ByteProperty>(arrayOffset, props, arrayType, name));
            }

            case ArrayType.Int:
            default:
            {
                var props = new List <IntProperty>();
                for (int i = 0; i < count; i++)
                {
                    props.Add(new IntProperty(stream));
                }
                return(new ArrayProperty <IntProperty>(arrayOffset, props, arrayType, name));
            }
            }
        }
        public static PropertyCollection ReadProps(IMEPackage pcc, MemoryStream stream, string typeName)
        {
            PropertyCollection props = new PropertyCollection();
            long startPosition       = stream.Position;

            while (stream.Position + 8 <= stream.Length)
            {
                int nameIdx = stream.ReadValueS32();
                if (!pcc.isName(nameIdx))
                {
                    stream.Seek(-4, SeekOrigin.Current);
                    break;
                }
                string name = pcc.getNameEntry(nameIdx);
                if (name == "None")
                {
                    props.Add(new NoneProperty {
                        PropType = PropertyType.None
                    });
                    stream.Seek(4, SeekOrigin.Current);
                    break;
                }
                NameReference nameRef = new NameReference {
                    Name = name, count = stream.ReadValueS32()
                };
                int typeIdx = stream.ReadValueS32();
                stream.Seek(4, SeekOrigin.Current);
                int size = stream.ReadValueS32();
                if (!pcc.isName(typeIdx) || size < 0 || size > stream.Length - stream.Position)
                {
                    stream.Seek(-16, SeekOrigin.Current);
                    break;
                }
                stream.Seek(4, SeekOrigin.Current);
                PropertyType type;
                if (!Enum.TryParse(pcc.getNameEntry(typeIdx), out type))
                {
                    type = PropertyType.Unknown;
                }
                switch (type)
                {
                case PropertyType.StructProperty:
                    string structType = pcc.getNameEntry(stream.ReadValueS32());
                    stream.Seek(4, SeekOrigin.Current);
                    if (ME3UnrealObjectInfo.isImmutable(structType))
                    {
                        PropertyCollection structProps = ReadSpecialStruct(pcc, stream, structType, size);
                        props.Add(new StructProperty(structType, structProps, nameRef, true));
                    }
                    else
                    {
                        PropertyCollection structProps = ReadProps(pcc, stream, structType);
                        props.Add(new StructProperty(structType, structProps, nameRef));
                    }
                    break;

                case PropertyType.IntProperty:
                    props.Add(new IntProperty(stream, nameRef));
                    break;

                case PropertyType.FloatProperty:
                    props.Add(new FloatProperty(stream, nameRef));
                    break;

                case PropertyType.ObjectProperty:
                    props.Add(new ObjectProperty(stream, nameRef));
                    break;

                case PropertyType.NameProperty:
                    props.Add(new NameProperty(stream, pcc, nameRef));
                    break;

                case PropertyType.BoolProperty:
                    props.Add(new BoolProperty(stream, pcc.Game, nameRef));
                    break;

                case PropertyType.BioMask4Property:
                    props.Add(new BioMask4Property(stream, nameRef));
                    break;

                case PropertyType.ByteProperty:
                {
                    if (size != 1)
                    {
                        NameReference enumType = new NameReference();
                        if (pcc.Game == MEGame.ME3)
                        {
                            enumType.Name  = pcc.getNameEntry(stream.ReadValueS32());
                            enumType.count = stream.ReadValueS32();
                        }
                        else
                        {
                            enumType.Name = UnrealObjectInfo.GetEnumType(pcc.Game, name, typeName);
                        }
                        props.Add(new EnumProperty(stream, pcc, enumType, nameRef));
                    }
                    else
                    {
                        if (pcc.Game == MEGame.ME3)
                        {
                            stream.Seek(8, SeekOrigin.Current);
                        }
                        props.Add(new ByteProperty(stream, nameRef));
                    }
                }
                break;

                case PropertyType.ArrayProperty:
                {
                    props.Add(ReadArrayProperty(stream, pcc, typeName, nameRef));
                }
                break;

                case PropertyType.StrProperty:
                {
                    props.Add(new StrProperty(stream, nameRef));
                }
                break;

                case PropertyType.StringRefProperty:
                    props.Add(new StringRefProperty(stream, nameRef));
                    break;

                case PropertyType.DelegateProperty:
                    props.Add(new DelegateProperty(stream, pcc, nameRef));
                    break;

                case PropertyType.Unknown:
                {
                    props.Add(new UnknownProperty(stream, size, pcc.getNameEntry(typeIdx), nameRef));
                }
                break;

                case PropertyType.None:
                default:
                    break;
                }
            }
            if (props.Count > 0)
            {
                if (props[props.Count - 1].PropType != PropertyType.None)
                {
                    stream.Seek(startPosition, SeekOrigin.Begin);
                    return(new PropertyCollection {
                        endOffset = (int)stream.Position
                    });
                }
                //remove None Property
                props.RemoveAt(props.Count - 1);
            }
            props.endOffset = (int)stream.Position;
            return(props);
        }