public static UProperty ReadArrayProperty(MemoryStream stream, IMEPackage pcc, string enclosingType, NameReference name, bool IsInImmutable = false) { 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>(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>(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>(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++) { PropertyCollection structProps = ReadSpecialStruct(pcc, stream, arrayStructType, arraySize / count); props.Add(new StructProperty(arrayStructType, structProps, isImmutable: true)); } } else { for (int i = 0; i < count; i++) { PropertyCollection structProps = ReadProps(pcc, stream, arrayStructType); props.Add(new StructProperty(arrayStructType, structProps)); } } return(new ArrayProperty <StructProperty>(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>(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>(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>(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>(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>(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); }
public static PropertyCollection ReadSpecialStruct(IMEPackage pcc, MemoryStream stream, string structType, int size) { PropertyCollection props = new PropertyCollection(); if (pcc.Game == MEGame.ME3) { if (ME3UnrealObjectInfo.Structs.ContainsKey(structType)) { PropertyCollection defaultProps; //memoize if (defaultStructValues.ContainsKey(structType)) { defaultProps = defaultStructValues[structType]; } else { defaultProps = ME3UnrealObjectInfo.getDefaultStructValue(structType); if (defaultProps == null) { props.Add(new UnknownProperty(stream, size)); return(props); } defaultStructValues.Add(structType, defaultProps); } for (int i = 0; i < defaultProps.Count; i++) { UProperty uProperty = ReadSpecialStructProp(pcc, stream, defaultProps[i], structType); if (uProperty.PropType != PropertyType.None) { props.Add(uProperty); } } return(props); } } //TODO: implement getDefaultClassValue() for ME1 and ME2 so this isn't needed if (structType == "Rotator") { string[] labels = { "Pitch", "Yaw", "Roll" }; for (int i = 0; i < 3; i++) { props.Add(new IntProperty(stream, labels[i])); } } else if (structType == "Vector2d" || structType == "RwVector2") { string[] labels = { "X", "Y" }; for (int i = 0; i < 2; i++) { props.Add(new FloatProperty(stream, labels[i])); } } else if (structType == "Vector" || structType == "RwVector3") { string[] labels = { "X", "Y", "Z" }; for (int i = 0; i < 3; i++) { props.Add(new FloatProperty(stream, labels[i])); } } else if (structType == "Color") { string[] labels = { "B", "G", "R", "A" }; for (int i = 0; i < 4; i++) { props.Add(new ByteProperty(stream, labels[i])); } } else if (structType == "LinearColor") { string[] labels = { "R", "G", "B", "A" }; for (int i = 0; i < 4; i++) { props.Add(new FloatProperty(stream, labels[i])); } } //uses EndsWith to support RwQuat, RwVector4, and RwPlane else if (structType.EndsWith("Quat") || structType.EndsWith("Vector4") || structType.EndsWith("Plane")) { string[] labels = { "X", "Y", "Z", "W" }; for (int i = 0; i < 4; i++) { props.Add(new FloatProperty(stream, labels[i])); } } else if (structType == "TwoVectors") { string[] labels = { "X", "Y", "Z", "X", "Y", "Z" }; for (int i = 0; i < 6; i++) { props.Add(new FloatProperty(stream, labels[i])); } } else if (structType == "Matrix" || structType == "RwMatrix44") { string[] labels = { "X Plane", "Y Plane", "Z Plane", "W Plane" }; string[] labels2 = { "X", "Y", "Z", "W" }; for (int i = 0; i < 3; i++) { PropertyCollection structProps = new PropertyCollection(); for (int j = 0; j < 4; j++) { structProps.Add(new FloatProperty(stream, labels2[j])); } props.Add(new StructProperty("Plane", structProps, labels[i], true)); } } else if (structType == "Guid") { string[] labels = { "A", "B", "C", "D" }; for (int i = 0; i < 4; i++) { props.Add(new IntProperty(stream, labels[i])); } } else if (structType == "IntPoint") { string[] labels = { "X", "Y" }; for (int i = 0; i < 2; i++) { props.Add(new IntProperty(stream, labels[i])); } } else if (structType == "Box" || structType == "BioRwBox") { string[] labels = { "Min", "Max" }; string[] labels2 = { "X", "Y", "Z" }; for (int i = 0; i < 2; i++) { PropertyCollection structProps = new PropertyCollection(); for (int j = 0; j < 3; j++) { structProps.Add(new FloatProperty(stream, labels2[j])); } props.Add(new StructProperty("Vector", structProps, labels[i], true)); } props.Add(new ByteProperty(stream, "IsValid")); } else { props.Add(new UnknownProperty(stream, size)); } return(props); }