Example #1
0
        public CompiledMetafile(Metafile file)
        {
            Name = file.Name;
            Source = file;

            byte[] buffer;

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.GetEncoding(949)))
                {
                    writer.Write((byte)(file.Nodes.Count / 256));
                    writer.Write((byte)(file.Nodes.Count % 256));
                    foreach (var node in file.Nodes)
                    {
                        buffer = Encoding.GetEncoding(949).GetBytes(node.Text);
                        writer.Write((byte)buffer.Length);
                        writer.Write(buffer);
                        writer.Write((byte)(node.Properties.Count / 256));
                        writer.Write((byte)(node.Properties.Count % 256));
                        foreach (var property in node.Properties)
                        {
                            buffer = Encoding.GetEncoding(949).GetBytes(property);
                            writer.Write((byte)(buffer.Length / 256));
                            writer.Write((byte)(buffer.Length % 256));
                            writer.Write(buffer);
                        }
                    }
                    writer.Flush();
                }

                buffer = stream.ToArray();
                Checksum = ~Crc32.Calculate(buffer);
            }

            using (var stream = new MemoryStream(buffer))
            {
                Data = Zlib.Compress(stream).ToArray();
            }
        }
Example #2
0
        private void LoadMetafiles()
        {
            // these might be better suited in LoadData as the database is being read, but only items are in database atm

            #region ItemInfo

            var iteminfo0 = new Metafile("ItemInfo0");
            // TODO: split items into multiple ItemInfo files (DA does ~700 each)
            foreach (var item in Items.Values)
            {
                iteminfo0.Nodes.Add(new MetafileNode(item.name, item.level, (int) item.class_type, item.weight,
                    string.Empty /* shop tab */, string.Empty /* shop description */));
            }
            Metafiles.Add(iteminfo0.Name, iteminfo0.Compile());

            #endregion

            #region SClass

            for (int i = 1; i <= 5; ++i)
            {
                var sclass = new Metafile("SClass" + i);
                sclass.Nodes.Add("Skill");
                foreach (var skill in Skills.Values)
                    // placeholder; change to skills where class == i, are learnable from trainer, and sort by level
                {
                    sclass.Nodes.Add(new MetafileNode(skill.Name,
                        string.Format("{0}/{1}/{2}", 0, 0, 0), // req level, master (0/1), req ab
                        string.Format("{0}/{1}/{2}", 0, 0, 0), // skill icon, x position (defunct), y position (defunct)
                        string.Format("{0}/{1}/{2}/{3}/{4}", 3, 3, 3, 3, 3),
                        // str, dex, int, wis, con (not a typo, dex after str)
                        string.Format("{0}/{1}", 0, 0), // req skill 1 (skill name or 0 for none), req skill 1 level
                        string.Format("{0}/{1}", 0, 0) // req skill 2 (skill name or 0 for none), req skill 2 level
                        ));
                }
                sclass.Nodes.Add("Skill_End");
                sclass.Nodes.Add("Spell");
                foreach (var spell in Spells.Values)
                    // placeholder; change to skills where class == i, are learnable from trainer, and sort by level
                {
                    sclass.Nodes.Add(new MetafileNode(spell.Name,
                        string.Format("{0}/{1}/{2}", 0, 0, 0), // req level, master (0/1), req ab
                        string.Format("{0}/{1}/{2}", 0, 0, 0), // spell icon, x position (defunct), y position (defunct)
                        string.Format("{0}/{1}/{2}/{3}/{4}", 3, 3, 3, 3, 3),
                        // str, dex, int, wis, con (not a typo, dex after str)
                        string.Format("{0}/{1}", 0, 0), // req spell 1 (spell name or 0 for none), req spell 1 level
                        string.Format("{0}/{1}", 0, 0) // req spell 2 (spell name or 0 for none), req spell 2 level
                        ));
                }
                sclass.Nodes.Add("Spell_End");
                Metafiles.Add(sclass.Name, sclass.Compile());
            }

            #endregion

            #region NPCIllust

            var npcillust = new Metafile("NPCIllust");
            foreach (var kvp in Portraits) // change to merchants that have a portrait rather than all
            {
                npcillust.Nodes.Add(new MetafileNode(kvp.Key, kvp.Value /* portrait filename */));
            }
            Metafiles.Add(npcillust.Name, npcillust.Compile());

            #endregion

            #region NationDesc

            var nationdesc = new Metafile("NationDesc");
            foreach (var nation in Nations.Values)
            {
                Logger.DebugFormat("Adding flag {0} for nation {1}", nation.flag, nation.name);
                nationdesc.Nodes.Add(new MetafileNode("nation_" + nation.flag, nation.name));
            }
            Metafiles.Add(nationdesc.Name, nationdesc.Compile());

            #endregion
        }