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"); }
public static PropertyCollection getDefaultStructValue(string className, bool stripTransients) { bool isImmutable = UnrealObjectInfo.IsImmutable(className, Mod.MEGame.ME2); if (Structs.ContainsKey(className)) { ClassInfo info = Structs[className]; try { PropertyCollection structProps = new PropertyCollection(); ClassInfo tempInfo = info; while (tempInfo != null) { foreach ((string propName, PropertyInfo propInfo) in tempInfo.properties) { if (stripTransients && propInfo.Transient) { continue; } if (getDefaultProperty(propName, propInfo, stripTransients, isImmutable) is UProperty uProp) { structProps.Add(uProp); } } if (!Structs.TryGetValue(tempInfo.baseClass, out tempInfo)) { tempInfo = null; } } structProps.Add(new NoneProperty()); string filepath = Path.Combine(ME2Directory.gamePath, "BioGame", info.pccPath); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } if (File.Exists(filepath)) { IMEPackage importPCC = MEPackageHandler.OpenMEPackage(filepath); var exportToRead = importPCC.getUExport(info.exportIndex); byte[] buff = exportToRead.Data.Skip(0x30).ToArray(); PropertyCollection defaults = PropertyCollection.ReadProps(exportToRead, new MemoryStream(buff), className); foreach (var prop in defaults) { structProps.TryReplaceProp(prop); } } return(structProps); } catch { return(null); } } return(null); }
public EnumProperty(NameReference value, NameReference enumType, IMEPackage pcc, NameReference?name = null) : base(name) { EnumType = enumType; NameReference enumVal = value; Value = enumVal; EnumValues = UnrealObjectInfo.GetEnumValues(pcc.Game, enumType, true); PropType = PropertyType.ByteProperty; }
public EnumProperty(MemoryStream stream, IMEPackage pcc, NameReference enumType, NameReference?name = null) : base(name) { Offset = stream.Position; EnumType = enumType; NameReference enumVal = new NameReference { Name = pcc.getNameEntry(stream.ReadValueS32()), Number = stream.ReadValueS32() }; Value = enumVal; EnumValues = UnrealObjectInfo.GetEnumValues(pcc.Game, enumType, true); PropType = PropertyType.ByteProperty; }
public static void ImportProperty(IMEPackage pcc, IMEPackage importpcc, Property p, string className, MemoryStream m, bool inStruct = false) { string name = importpcc.getNameEntry(p.Name); int idxname = pcc.FindNameOrAdd(name); m.Write(BitConverter.GetBytes(idxname), 0, 4); m.Write(new byte[4], 0, 4); if (name == "None") { return; } string type = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 8)); int idxtype = pcc.FindNameOrAdd(type); m.Write(BitConverter.GetBytes(idxtype), 0, 4); m.Write(new byte[4], 0, 4); string name2; int idxname2; int size, count, pos; List <Property> Props; switch (type) { case "IntProperty": case "FloatProperty": case "ObjectProperty": case "StringRefProperty": m.Write(BitConverter.GetBytes(4), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(p.Value.IntValue), 0, 4); break; case "NameProperty": m.Write(BitConverter.GetBytes(8), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4); //preserve index or whatever the second part of a namereference is m.Write(p.raw, 28, 4); break; case "BoolProperty": m.Write(new byte[8], 0, 8); m.WriteByte((byte)p.Value.IntValue); if (pcc.Game != MEGame.ME3) { m.Write(new byte[3], 0, 3); } break; case "BioMask4Property": m.Write(BitConverter.GetBytes(p.Size), 0, 4); m.Write(new byte[4], 0, 4); m.WriteByte((byte)p.Value.IntValue); break; case "ByteProperty": m.Write(BitConverter.GetBytes(p.Size), 0, 4); m.Write(new byte[4], 0, 4); if (pcc.Game == MEGame.ME3) { name2 = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24)); idxname2 = pcc.FindNameOrAdd(name2); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); } if (p.Size != 1) { m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(importpcc.getNameEntry(p.Value.IntValue))), 0, 4); m.Write(new byte[4], 0, 4); } else { m.WriteByte(Convert.ToByte(p.Value.IntValue)); } break; case "DelegateProperty": size = BitConverter.ToInt32(p.raw, 16); if (size == 0xC) { name2 = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 28)); idxname2 = pcc.FindNameOrAdd(name2); m.Write(BitConverter.GetBytes(0xC), 0, 4); m.Write(new byte[4], 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); } else { m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); for (int i = 0; i < size; i++) { m.WriteByte(p.raw[24 + i]); } } break; case "StrProperty": name2 = p.Value.StringValue; if (p.Value.StringValue.Length > 0) { name2 += '\0'; } if (p.Value.len < 0) { //unicode m.Write(BitConverter.GetBytes(4 + name2.Length * 2), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(-name2.Length), 0, 4); foreach (char c in name2) { m.WriteByte((byte)c); m.WriteByte(0); } } else { //ascii m.Write(BitConverter.GetBytes(4 + name2.Length), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(name2.Length), 0, 4); foreach (char c in name2) { m.WriteByte((byte)c); } } break; case "StructProperty": size = BitConverter.ToInt32(p.raw, 16); name2 = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 24)); idxname2 = pcc.FindNameOrAdd(name2); pos = 32; Props = new List <Property>(); try { Props = ReadProp(importpcc, p.raw, pos); } catch (Exception) { } m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(idxname2), 0, 4); m.Write(new byte[4], 0, 4); if (Props.Count == 0 || Props[0].TypeVal == PropertyType.Unknown) { for (int i = 0; i < size; i++) { m.WriteByte(p.raw[32 + i]); } } else { foreach (Property pp in Props) { ImportProperty(pcc, importpcc, pp, className, m, inStruct); } } break; case "ArrayProperty": size = BitConverter.ToInt32(p.raw, 16); count = BitConverter.ToInt32(p.raw, 24); PropertyInfo info = ME3UnrealObjectInfo.getPropertyInfo(className, name, inStruct); ArrayType arrayType = ME3UnrealObjectInfo.getArrayType(info); pos = 28; List <Property> AllProps = new List <Property>(); if (arrayType == ArrayType.Struct) { for (int i = 0; i < count; i++) { Props = new List <Property>(); try { Props = ReadProp(importpcc, p.raw, pos); } catch (Exception) { } AllProps.AddRange(Props); if (Props.Count != 0) { pos = Props[Props.Count - 1].offend; } } } m.Write(BitConverter.GetBytes(size), 0, 4); m.Write(new byte[4], 0, 4); m.Write(BitConverter.GetBytes(count), 0, 4); if (AllProps.Count != 0 && (info == null || !UnrealObjectInfo.isImmutable(info.reference, pcc.Game))) { foreach (Property pp in AllProps) { ImportProperty(pcc, importpcc, pp, className, m, inStruct); } } else if (arrayType == ArrayType.Name) { for (int i = 0; i < count; i++) { string s = importpcc.getNameEntry(BitConverter.ToInt32(p.raw, 28 + i * 8)); m.Write(BitConverter.GetBytes(pcc.FindNameOrAdd(s)), 0, 4); //preserve index or whatever the second part of a namereference is m.Write(p.raw, 32 + i * 8, 4); } } else { m.Write(p.raw, 28, size - 4); } break; default: throw new Exception(type); } }
public static UProperty getDefaultProperty(string propName, PropertyInfo propInfo, bool stripTransients = true, bool isImmutable = false) { switch (propInfo.Type) { case PropertyType.IntProperty: return(new IntProperty(0, propName)); case PropertyType.FloatProperty: return(new FloatProperty(0f, propName)); case PropertyType.DelegateProperty: return(new DelegateProperty(0, "None")); case PropertyType.ObjectProperty: return(new ObjectProperty(0, propName)); case PropertyType.NameProperty: return(new NameProperty("None", propName)); case PropertyType.BoolProperty: return(new BoolProperty(false, propName)); case PropertyType.ByteProperty when propInfo.IsEnumProp(): return(new EnumProperty(propInfo.Reference, Mod.MEGame.ME2, propName)); case PropertyType.ByteProperty: return(new ByteProperty(0, propName)); case PropertyType.StrProperty: return(new StrProperty("", propName)); case PropertyType.StringRefProperty: return(new StringRefProperty(propName)); case PropertyType.BioMask4Property: return(new BioMask4Property(0, propName)); case PropertyType.ArrayProperty: switch (getArrayType(propInfo)) { case ArrayType.Object: return(new ArrayProperty <ObjectProperty>(propName)); case ArrayType.Name: return(new ArrayProperty <NameProperty>(propName)); case ArrayType.Enum: return(new ArrayProperty <EnumProperty>(propName)); case ArrayType.Struct: return(new ArrayProperty <StructProperty>(propName)); case ArrayType.Bool: return(new ArrayProperty <BoolProperty>(propName)); case ArrayType.String: return(new ArrayProperty <StrProperty>(propName)); case ArrayType.Float: return(new ArrayProperty <FloatProperty>(propName)); case ArrayType.Int: return(new ArrayProperty <IntProperty>(propName)); case ArrayType.Byte: return(new ArrayProperty <ByteProperty>(propName)); default: return(null); } case PropertyType.StructProperty: isImmutable = isImmutable || UnrealObjectInfo.IsImmutable(propInfo.Reference, Mod.MEGame.ME2); return(new StructProperty(propInfo.Reference, getDefaultStructValue(propInfo.Reference, stripTransients), propName, isImmutable)); case PropertyType.None: case PropertyType.Unknown: default: return(null); } }
public static PropertyCollection getDefaultStructValue(string className, bool stripTransients) { if (Structs.ContainsKey(className)) { bool immutable = UnrealObjectInfo.isImmutable(className, MEGame.ME3); ClassInfo info = Structs[className]; try { string filepath = (Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath)); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } using (ME3Package importPCC = MEPackageHandler.OpenME3Package(filepath)) { byte[] buff; //Plane and CoverReference inherit from other structs, meaning they don't have default values (who knows why) //thus, I have hardcoded what those default values should be if (className == "Plane") { buff = PlaneDefault; } else if (className == "CoverReference") { buff = CoverReferenceDefault; } else { var exportToRead = importPCC.Exports[info.exportIndex]; buff = exportToRead.Data.Skip(0x24).ToArray(); } PropertyCollection props = PropertyCollection.ReadProps(importPCC, new MemoryStream(buff), className); if (stripTransients) { List <UProperty> toRemove = new List <UProperty>(); foreach (var prop in props) { //remove transient props if (info.properties.TryGetValue(prop.Name, out PropertyInfo propInfo)) { if (propInfo.transient) { toRemove.Add(prop); } } //if (!info.properties.ContainsKey(prop.Name) && info.baseClass == "Class") //{ // toRemove.Add(prop); //} } foreach (var prop in toRemove) { Debug.WriteLine($"ME3: Get Default Struct value ({className}) - removing transient prop: {prop.Name}"); props.Remove(prop); } } return(props); } } catch { return(null); } } return(null); }
public static byte[] getDefaultClassValue(ME3Package pcc, string className, bool fullProps = false) { if (Structs.ContainsKey(className)) { bool immutable = UnrealObjectInfo.isImmutable(className, MEGame.ME3); ClassInfo info = Structs[className]; try { string filepath = (Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath)); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } using (ME3Package importPCC = MEPackageHandler.OpenME3Package(filepath)) { byte[] buff; //Plane and CoverReference inherit from other structs, meaning they don't have default values (who knows why) //thus, I have hardcoded what those default values should be if (className == "Plane") { buff = PlaneDefault; } else if (className == "CoverReference") { buff = CoverReferenceDefault; } else { buff = importPCC.Exports[info.exportIndex].Data.Skip(0x24).ToArray(); } List <PropertyReader.Property> Props = PropertyReader.ReadProp(importPCC, buff, 0); MemoryStream m = new MemoryStream(); foreach (PropertyReader.Property p in Props) { string propName = importPCC.getNameEntry(p.Name); //check if property is transient, if so, skip (neither of the structs that inherit have transient props) if (info.properties.ContainsKey(propName) || propName == "None" || info.baseClass != "Class") { if (immutable && !fullProps) { PropertyReader.ImportImmutableProperty(pcc, importPCC, p, className, m, true); } else { PropertyReader.ImportProperty(pcc, importPCC, p, className, m, true); } } } return(m.ToArray()); } } catch (Exception) { return(null); } } else if (Classes.ContainsKey(className)) { ClassInfo info = Structs[className]; try { string filepath = (Path.Combine(ME3Directory.gamePath, @"BIOGame\" + info.pccPath)); if (File.Exists(info.pccPath)) { filepath = info.pccPath; //Used for dynamic lookup } using (ME3Package importPCC = MEPackageHandler.OpenME3Package(filepath)) { IExportEntry entry = pcc.Exports[info.exportIndex + 1]; List <PropertyReader.Property> Props = PropertyReader.getPropList(entry); MemoryStream m = new MemoryStream(entry.DataSize - 4); foreach (PropertyReader.Property p in Props) { if (!info.properties.ContainsKey(importPCC.getNameEntry(p.Name))) { //property is transient continue; } PropertyReader.ImportProperty(pcc, importPCC, p, className, m); } return(m.ToArray()); } } catch (Exception) { return(null); } } return(null); }
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); }
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); }