protected void ReadPrototypeEntry(BinaryStream stream) { long uid = 0; if (Use64Bit) { uid = stream.ReadInt64(); } else { uid = stream.ReadUInt32(); } var buffer = (Use64Bit) ? BitConverter.GetBytes(uid) : BitConverter.GetBytes((uint)uid); var lookup = new EntityPrototypeInfo(stream, 8); var obj = Context.GetRefByPtr(lookup.Offset) as NomadObject; if (obj == null) { throw new InvalidDataException($"Couldn't find library '{uid:X8}' at offset {lookup.Offset:X8}!"); } // remove before writing var libId = new NomadValue("UID", DataType.BinHex, buffer); obj.Attributes.Add(libId); Prototypes.Add(uid, obj); }
public override void Serialize(Stream stream, NomadObject _unused) { Context.Begin(); var bs = (stream as BinaryStream) ?? new BinaryStream(stream); byte[] buffer = null; using (var nb = new BinaryStream(1024)) { base.Serialize(nb, Root); buffer = nb.ToArray(); } var count = Prototypes.Count; bs.Write(buffer.Length + 8); bs.Write(count); bs.Write(buffer); // todo: prototype entries Context.Log("Writing prototypes..."); foreach (var kv in Prototypes) { var uid = kv.Key; var obj = kv.Value; // fail-safe var reference = new NomadReference(obj); var cached = reference.Get(); var ptr = (int)Context.GetPtr(cached); if (ptr == -1) { throw new InvalidDataException("Couldn't get the pointer to a prototype!"); } var info = new EntityPrototypeInfo(obj, ptr); var uidBuffer = (Use64Bit) ? BitConverter.GetBytes(uid) : BitConverter.GetBytes((uint)uid); bs.Write(uidBuffer); info.Serialize(bs); } Context.End(); }