} // Map length = 15 public static AutomapInfo Load(BinaryReader br) { var i = new AutomapInfo { X = br.ReadByte(), Y = br.ReadByte(), Unk2 = br.ReadByte(), Unk3 = br.ReadByte() }; var nameBytes = br.ReadBytes(15); bool done = false; // Verify that strings contain no embedded nulls. foreach (var t in nameBytes) { if (done) { Debug.Assert(t == 0); } else if (t == 0) { done = true; } } i.Name = Encoding.ASCII.GetString(nameBytes); return(i); }
} // name length = 15 public static AutomapInfo Serdes(int _, AutomapInfo existing, ISerializer s) { var info = existing ?? new AutomapInfo(); s.Begin(); info.X = s.UInt8(nameof(X), info.X); // 0 info.Y = s.UInt8(nameof(Y), info.Y); // 1 info.Unk2 = s.UInt8(nameof(Unk2), info.Unk2); // 2 info.Unk3 = s.UInt8(nameof(Unk3), info.Unk3); // 3 info.Name = s.FixedLengthString(nameof(Name), info.Name, 15); // 4 s.End(); return(info); }
} // name length = 15 public static AutomapInfo Serdes(int _, AutomapInfo existing, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var info = existing ?? new AutomapInfo(); info.X = s.UInt8(nameof(X), info.X); // 0 info.Y = s.UInt8(nameof(Y), info.Y); // 1 info.Unk2 = s.UInt8(nameof(Unk2), info.Unk2); // 2 info.Unk3 = s.UInt8(nameof(Unk3), info.Unk3); // 3 info.Name = s.FixedLengthString(nameof(Name), info.Name, 15); // 4 return(info); }
public static MapData3D Load(BinaryReader br, long streamLength, string name) { var startPosition = br.BaseStream.Position; var map = new MapData3D(); map.CeilingFlags = br.ReadByte(); // 0 int npcCount = br.ReadByte(); // 1 if (npcCount == 0) { npcCount = 0x20; } else if (npcCount == 0x40) { npcCount = 0x60; } var mapType = br.ReadByte(); // 2 Debug.Assert(1 == mapType); // 1 = 3D, 2 = 2D map.SongId = (SongId)br.ReadByte() - 1; // 3 map.Width = br.ReadByte(); // 4 map.Height = br.ReadByte(); // 5 byte labData = br.ReadByte(); // 6 map.LabDataId = (LabyrinthDataId)labData; map.Unk7 = br.ReadByte(); // 7 Possibly combat background?? map.PaletteId = (PaletteId)br.ReadByte() - 1; // 8 map.Sound = br.ReadByte() - 1; // 9 for (int i = 0; i < npcCount; i++) { var npc = MapNpc.Load(br); if (npc.Id == 0) { continue; } map.Npcs.Add(npc); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); map.Contents = new int[map.Width * map.Height]; map.Floors = new int[map.Width * map.Height]; map.Ceilings = new int[map.Width * map.Height]; for (int i = 0; i < map.Width * map.Height; i++) { map.Contents[i] = br.ReadByte(); map.Floors[i] = br.ReadByte(); map.Ceilings[i] = br.ReadByte(); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); int zoneCount = br.ReadUInt16(); for (int i = 0; i < zoneCount; i++) { map.Zones.Add(MapEventZone.LoadGlobalZone(br)); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); for (int j = 0; j < map.Height; j++) { zoneCount = br.ReadUInt16(); for (int i = 0; i < zoneCount; i++) { map.Zones.Add(MapEventZone.LoadZone(br, (ushort)j)); } } if (br.BaseStream.Position == startPosition + streamLength) { Debug.Assert(map.Zones.Count == 0); return(map); } int eventCount = br.ReadUInt16(); for (int i = 0; i < eventCount; i++) { map.Events.Add(EventNode.Load(br, i)); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); foreach (var npc in map.Npcs) { npc.LoadWaypoints(br); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); int automapInfoCount = br.ReadUInt16(); if (automapInfoCount != 0xffff) { for (int i = 0; i < automapInfoCount; i++) { map.Automap.Add(AutomapInfo.Load(br)); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); } map.AutomapGraphics = br.ReadBytes(0x40); for (int i = 0; i < 64; i++) { var eventId = br.ReadUInt16(); if (eventId == 0xffff) { continue; } map.ActiveMapEvents.Add(eventId); } Debug.Assert(br.BaseStream.Position <= startPosition + streamLength); return(map); }