public List <NPC> CreateNPC() { XmlSerializer serializer = new XmlSerializer(typeof(List <NPC>), new XmlRootAttribute("NPCs")); using (XmlReader reader = XmlReader.Create(@"..\..\data\npc.xml")) { NPCs = (List <NPC>)serializer.Deserialize(reader); NPCs.ForEach(i => XMLReference <Item> .Link(i.Items, Items)); return(NPCs); } }
/// <summary> /// Saves the file to the specified stream. /// </summary> /// <param name="stream">The stream to save to.</param> public override void Save(Stream stream) { BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR")); writer.Write(BLOCK_COUNT); for (int i = 0; i < BLOCK_COUNT; i++) { writer.Write(0); writer.Write(0); } long[] offsets = new long[BLOCK_COUNT]; offsets[0] = stream.Position; writer.Write(MapPosition.X); writer.Write(MapPosition.Y); writer.Write(ZonePosition.X); writer.Write(ZonePosition.Y); writer.Write(World); writer.Write(Name); offsets[1] = stream.Position; writer.Write(Objects.Count); Objects.ForEach(@object => { @object.Write(writer); }); offsets[2] = stream.Position; writer.Write(NPCs.Count); NPCs.ForEach(npc => { npc.Write(writer); }); offsets[3] = stream.Position; writer.Write(Buildings.Count); Buildings.ForEach(building => { building.Write(writer); }); offsets[4] = stream.Position; writer.Write(Sounds.Count); Sounds.ForEach(sound => { sound.Write(writer); }); offsets[5] = stream.Position; writer.Write(Effects.Count); Effects.ForEach(effect => { effect.Write(writer); }); offsets[6] = stream.Position; writer.Write(Animations.Count); Animations.ForEach(animation => { animation.Write(writer); }); offsets[7] = stream.Position; WaterPatches.Write(writer); offsets[8] = stream.Position; writer.Write(MonsterSpawns.Count); MonsterSpawns.ForEach(monsterSpawn => { monsterSpawn.Write(writer); }); offsets[9] = stream.Position; writer.Write(WaterSize); writer.Write(WaterPlanes.Count); WaterPlanes.ForEach(waterPlane => { waterPlane.Write(writer); }); offsets[10] = stream.Position; writer.Write(WarpPoints.Count); WarpPoints.ForEach(warpPoint => { warpPoint.Write(writer); }); offsets[11] = stream.Position; writer.Write(CollisionObjects.Count); CollisionObjects.ForEach(collisionObject => { collisionObject.Write(writer); }); offsets[12] = stream.Position; writer.Write(EventObjects.Count); EventObjects.ForEach(eventObject => { eventObject.Write(writer); }); stream.Seek(4, SeekOrigin.Begin); for (int i = 0; i < BLOCK_COUNT; i++) { writer.Write(i); writer.Write((int)offsets[i]); } }
public void Serialize(string path) { BinaryWriter Binary = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)); Binary.Write((uint)(Interactable.Size * Interactables.Count + NPC.Size * NPCs.Count + Warp.Size * Warps.Count + Trigger.Size * Triggers.Count + 0x4)); Binary.Write((byte)Interactables.Count); Binary.Write((byte)NPCs.Count); Binary.Write((byte)Warps.Count); Binary.Write((byte)Triggers.Count); // Because BinaryFormatter is "unsafe"... Interactables.ForEach(x => { Binary.Write(x.Script); Binary.Write(x.Condition); Binary.Write(x.Interactibility); Binary.Write(x.RailIndex); Binary.Write(x.X); Binary.Write(x.Y); Binary.Write(x.Z * 0x10); }); NPCs.ForEach(x => { Binary.Write(x.ID); Binary.Write(x.ModelID); Binary.Write(x.MovementPermission); Binary.Write(x.Type); Binary.Write(x.SpawnFlag); Binary.Write(x.ScriptID); Binary.Write(x.FaceDirection); Binary.Write(x.SightRange); Binary.Write(x.Unknown); Binary.Write(x.Unknown2); Binary.Write(x.TraversalWidth); Binary.Write(x.TraversalHeight); Binary.Write(x.StartingX); Binary.Write(x.StartingY); Binary.Write(x.X); Binary.Write(x.Y); Binary.Write(x.Unknown3); Binary.Write(x.Z); }); Warps.ForEach(x => { Binary.Write(x.TargetZone); Binary.Write(x.TargetWarp); Binary.Write(x.ContactDirection); Binary.Write(x.TransitionType); Binary.Write(x.CoordinateType); Binary.Write(x.X); Binary.Write(x.Z); Binary.Write(x.Y); Binary.Write(x.W); Binary.Write(x.H); Binary.Write(x.Rail); }); Triggers.ForEach(x => { Binary.Write(x.Script); Binary.Write(x.ValueNeededForExecution); Binary.Write(x.Variable); Binary.Write(x.Unknown); Binary.Write(x.Unknown2); Binary.Write(x.X); Binary.Write(x.Y); Binary.Write(x.Z); Binary.Write(x.W); Binary.Write(x.H); Binary.Write(x.Unknown3); }); int SectionOffset = 0; LevelScripts.ForEach(x => { Binary.Write(x.Unknown); Binary.Write(x.Unknown2); Binary.Write(x.Unknown3); SectionOffset += 0x6; }); while (SectionOffset % 4 != 0) { Binary.Write((ushort)0x0); SectionOffset += 0x2; } LevelScripts.ForEach(x => { if (x.Data != null) { Binary.Write(x.Data.Unknown); Binary.Write(x.Data.Unknown2); Binary.Write(x.Data.Unknown3); SectionOffset += 0x6; } }); while (SectionOffset % 4 != 0) { Binary.Write((ushort)0x0); SectionOffset += 0x2; } Binary.Close(); }