public static MapNpc Serdes(int _, MapNpc existing, MapType mapType, AssetMapping mapping, ISerializer s) { if (s == null) { throw new ArgumentNullException(nameof(s)); } var npc = existing ?? new MapNpc(); byte id = (byte)npc.Id.ToDisk(mapping); id = s.UInt8(nameof(Id), id); // npc.Sound = (SampleId?)Tweak.Serdes(nameof(Sound), (byte?)npc.Sound, s.UInt8); npc.Sound = s.UInt8(nameof(Sound), npc.Sound); ushort?eventNumber = MaxToNullConverter.Serdes(nameof(npc.Node), npc.Node?.Id, s.UInt16); if (eventNumber != null && npc.Node == null) { npc.Node = new DummyEventNode(eventNumber.Value); } switch (mapType) { case MapType.ThreeD: npc.SpriteOrGroup = AssetId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.ObjectGroup, mapping, s); break; case MapType.TwoD: npc.SpriteOrGroup = SpriteId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.BigNpcGraphics, mapping, s); break; case MapType.TwoDOutdoors: npc.SpriteOrGroup = SpriteId.SerdesU16(nameof(SpriteOrGroup), npc.SpriteOrGroup, AssetType.SmallNpcGraphics, mapping, s); break; default: throw new ArgumentOutOfRangeException(nameof(mapType), mapType, null); } npc.Flags = s.EnumU8(nameof(Flags), npc.Flags); npc.Movement = s.EnumU8(nameof(Movement), npc.Movement); npc.Unk8 = s.UInt8(nameof(Unk8), npc.Unk8); npc.Unk9 = s.UInt8(nameof(Unk9), npc.Unk9); var assetType = (npc.Flags & NpcFlags.IsMonster) != 0 ? AssetType.MonsterGroup : AssetType.Npc; npc.Id = AssetId.FromDisk(assetType, id, mapping); return(npc); }
public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } var map = existing ?? new MapData3D { Id = info.AssetId }; map.Flags = s.EnumU8(nameof(Flags), map.Flags); // 0 map.OriginalNpcCount = s.UInt8(nameof(OriginalNpcCount), map.OriginalNpcCount); // 1 int npcCount = NpcCountTransform.Instance.FromNumeric(map.OriginalNpcCount); var _ = s.UInt8("MapType", (byte)map.MapType); // 2 map.SongId = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s); // 3 map.Width = s.UInt8(nameof(Width), map.Width); // 4 map.Height = s.UInt8(nameof(Height), map.Height); // 5 map.LabDataId = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s); // 6 map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background map.PaletteId = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s); map.AmbientSongId = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s); map.Npcs = s.List( nameof(Npcs), map.Npcs, npcCount, (n, x, s2) => MapNpc.Serdes(n, x, map.MapType, mapping, s2)).ToArray(); map.Contents ??= new byte[map.Width * map.Height]; map.Floors ??= new byte[map.Width * map.Height]; map.Ceilings ??= new byte[map.Width * map.Height]; for (int i = 0; i < map.Width * map.Height; i++) { map.Contents[i] = s.UInt8(null, map.Contents[i]); map.Floors[i] = s.UInt8(null, map.Floors[i]); map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]); } s.Check(); map.SerdesZones(s); if (s.IsReading() && s.IsComplete() || s.IsWriting() && map.AutomapGraphics == null) { ApiUtil.Assert(map.Zones.Count == 0); foreach (var npc in map.Npcs) { npc.Waypoints = new NpcWaypoint[1]; } return(map); } map.SerdesEvents(mapping, s); map.SerdesNpcWaypoints(s); map.SerdesAutomap(s); map.SerdesChains(s, 64); if (s.IsReading()) { map.Unswizzle(); } return(map); }
public static MapData3D Serdes(AssetInfo info, MapData3D existing, AssetMapping mapping, ISerializer s) { if (info == null) { throw new ArgumentNullException(nameof(info)); } if (s == null) { throw new ArgumentNullException(nameof(s)); } var map = existing ?? new MapData3D(info.AssetId); map.Flags = s.EnumU8(nameof(Flags), map.Flags); // 0 int npcCount = s.Transform("NpcCount", map.Npcs.Count, S.UInt8, NpcCountTransform.Instance); // 1 var _ = s.UInt8("MapType", (byte)map.MapType); // 2 map.SongId = SongId.SerdesU8(nameof(SongId), map.SongId, mapping, s); // 3 map.Width = s.UInt8(nameof(Width), map.Width); // 4 map.Height = s.UInt8(nameof(Height), map.Height); // 5 map.LabDataId = LabyrinthId.SerdesU8(nameof(LabDataId), map.LabDataId, mapping, s); // 6 map.CombatBackgroundId = SpriteId.SerdesU8(nameof(CombatBackgroundId), map.CombatBackgroundId, AssetType.CombatBackground, mapping, s); // 7 TODO: Verify this is combat background map.PaletteId = PaletteId.SerdesU8(nameof(PaletteId), map.PaletteId, mapping, s); map.AmbientSongId = SongId.SerdesU8(nameof(AmbientSongId), map.AmbientSongId, mapping, s); for (int i = 0; i < npcCount; i++) { map.Npcs.TryGetValue(i, out var npc); npc = MapNpc.Serdes(i, npc, MapType.ThreeD, mapping, s); if (!npc.Id.IsNone) { map.Npcs[i] = npc; } } s.Check(); map.Contents ??= new byte[map.Width * map.Height]; map.Floors ??= new byte[map.Width * map.Height]; map.Ceilings ??= new byte[map.Width * map.Height]; for (int i = 0; i < map.Width * map.Height; i++) { map.Contents[i] = s.UInt8(null, map.Contents[i]); map.Floors[i] = s.UInt8(null, map.Floors[i]); map.Ceilings[i] = s.UInt8(null, map.Ceilings[i]); } s.Check(); map.SerdesZones(s); if (s.Mode == SerializerMode.Reading && s.IsComplete() || s.Mode != SerializerMode.Reading && map.AutomapGraphics == null) { ApiUtil.Assert(map.Zones.Count == 0); return(map); } map.SerdesEvents(mapping, s); map.SerdesNpcWaypoints(s); map.SerdesAutomap(s); map.SerdesChains(s, 64); if (s.Mode == SerializerMode.Reading) { map.Unswizzle(); } return(map); }