public static object Load(Package package, BinaryReader reader, object current) { var info = new FieldInfo(reader); var u25 = new FieldInfo(0x25); if (info.Type == FieldTypeBase.Boolean) { return(info.IsArray); } if (info.IsArray) { switch (info.Type) { case FieldTypeBase.Str: return(LoadArrayElement(current, () => reader.ReadStringz(reader.ReadByte(), Encoding.ASCII))); case FieldTypeBase.Integer: return(LoadArrayElement(current, reader.ReadInt32)); case FieldTypeBase.Object: return(LoadArrayElement(current, () => package.ReadReference(reader))); case FieldTypeBase.Struct: return(LoadArrayElement(current, () => LoadSingle(package, reader, info))); default: throw new NotImplementedException(info.Type + " does not have an implementation for loading arrays (index " + info.ArrayIndex + ", size " + info.Size + ")"); } } else { return(LoadSingle(package, reader, info)); } }
/// <summary> /// Read the <see cref="PointRegion"/> from the <paramref name="reader"/>. /// </summary> /// <param name="reader">The <see cref="BinaryReader"/> to read the <see cref="Bounds"/> from.</param> /// <param name="package"></param> /// <returns>The new <see cref="PointRegion"/> object.</returns> public static PointRegion Read(BinaryReader reader, Package package) { return(new PointRegion() { ZoneReference = package.ReadReference(reader), Leaf = reader.ReadInt32(), ZoneNumber = reader.ReadByte() }); }
/// <summary></summary> public override object Read(object target, Package package, System.IO.BinaryReader reader, long end) { var count = reader.ReadInt32(); var list = new SCG.List <Reference>(count); while (count-- > 0) { list.Add(package.ReadReference(reader)); } return(list); }
internal void Load(BinaryReader reader) { ObjectClassReference = Package.ReadReference(reader); SuperClassReference = Package.ReadReference(reader); Group = reader.ReadInt32(); Name = Package.ReadNameValue(reader); Flags = (ExportFlag)reader.ReadUInt32(); Size = UIndex.Read(reader); if (Size != 0) { Offset = UIndex.Read(reader); } }
public override object Read(object target, Package package, BinaryReader reader, long end) { return package.ReadReference(reader); }
public override object Read(object target, Package package, BinaryReader reader, long end) { return reader.ReadIndexCountList(() => package.ReadReference(reader)); }
static object LoadSingle(Package package, BinaryReader reader, FieldInfo info, bool inArray = false) { if (info.Size < 1) { throw new Exception(); } switch (info.Type) { case FieldTypeBase.Byte: if (!inArray && info.Size != 1) { throw new Exception(); } return(reader.ReadByte()); case FieldTypeBase.Float: if (!inArray && info.Size != 4) { throw new Exception(); } return(reader.ReadSingle()); case FieldTypeBase.Integer: if (!inArray && info.Size != 4) { throw new Exception(); } return(reader.ReadInt32()); case FieldTypeBase.Name: return(package.ReadNameIndex(reader).Value); case FieldTypeBase.Object: return(package.ReadReference(reader)); case FieldTypeBase.Str: var stringLength = reader.ReadByte(); if (stringLength != info.Size - 1) { throw new Exception("String length isn't the field size minus 1."); } return(reader.ReadStringz(stringLength, Encoding.ASCII)); case FieldTypeBase.Struct: string name; if (info.IsLiteralSizeForm) { name = package.Names[info.Size].Value; info.Size = UIndex.Read(reader); } else { name = package.ReadNameIndex(reader).Value; } var end = reader.BaseStream.Position + info.Size; object result; switch (name) { case "InitialAllianceInfo": result = InitialAllianceInfo.Read(reader, package); break; case "PointRegion": if (!inArray && info.Size < 6) { throw new Exception("PointRegion structure size must be at least 6 bytes."); } result = PointRegion.Read(reader, package); break; case "Rotator": result = Rotator.Read(reader); break; case "Scale": if (!inArray && info.Size != 17) { throw new Exception("Scale structure size is a constant 17 bytes."); } result = Scale.Read(reader); break; case "Vector": if (!inArray && info.Size != 12) { throw new Exception("Vector structure size is a constant 12 bytes."); } result = reader.ReadVector3f(); break; default: throw new Exception("Unhandled or unknown struct type " + name + "."); } if (!inArray && reader.BaseStream.Position != end) { throw new Exception("Structure wasn't fully devoured or was overconsumed."); } return(result); default: throw new Exception("Unknown or unhandled type " + info.Type + "."); } }
/// <summary> /// Read the <see cref="PointRegion"/> from the <paramref name="reader"/>. /// </summary> /// <param name="reader">The <see cref="BinaryReader"/> to read the <see cref="Bounds"/> from.</param> /// <param name="package"></param> /// <returns>The new <see cref="PointRegion"/> object.</returns> public static PointRegion Read(BinaryReader reader, Package package) { return new PointRegion() { ZoneReference = package.ReadReference(reader), Leaf = reader.ReadInt32(), ZoneNumber = reader.ReadByte() }; }
public override object Read(object target, Package package, BinaryReader reader, long end) { return(reader.ReadIndexCountList(() => package.ReadReference(reader))); }
public override object Read(object target, Package package, BinaryReader reader, long end) { return(package.ReadReference(reader)); }