public static Guid GetGuid(StructProperty guidProp) { int a = guidProp.GetProp <IntProperty>("A"); int b = guidProp.GetProp <IntProperty>("B"); int c = guidProp.GetProp <IntProperty>("C"); int d = guidProp.GetProp <IntProperty>("D"); var ms = new MemoryStream(16); ms.WriteInt32(a); ms.WriteInt32(b); ms.WriteInt32(c); ms.WriteInt32(d); return(new Guid(ms.ToArray())); }
public static Vector3 GetVector(StructProperty vecProp) => new Vector3(vecProp.GetProp <FloatProperty>("X"), vecProp.GetProp <FloatProperty>("Y"), vecProp.GetProp <FloatProperty>("Z"));
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)); } } }