コード例 #1
0
        public void WritePssg(Stream fileStream)
        {
            using (PssgBinaryWriter writer = new PssgBinaryWriter(EndianBitConverter.Big, fileStream, true))
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    // make all ids -1
                    PssgSchema.ClearSchemaIds();

                    // Get the counts, and update ids of the nodes/attributes used in this file
                    GetNodeAttributeNameCount(this, out var nodeNameCount, out var attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);

                    // Update ids again to make sequential and save ones used in this file
                    PssgSchema.SaveToPssg(writer);

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }

                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);
            }
コード例 #2
0
        public void WritePssg(Stream fileStream, bool close)
        {
            PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream);

            try
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    int nodeNameCount      = 0;
                    int attributeNameCount = 0;
                    PssgSchema.ClearSchemaIds(); // make all ids -1
                    RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);
                    PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }
                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);

                if (close)
                {
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                throw ex;
            }
        }
コード例 #3
0
        public static void SaveToPssg(PssgBinaryWriter writer)
        {
            // Update Ids to make sequential, and Unique
            int currentId     = 0;
            int currentAttrId = 0;

            // Minimizing the attributes to unique names only seems to crash the game
            //Dictionary<string, int> unique = new Dictionary<string, int>();

            foreach (KeyValuePair <string, Node> entry in entries)
            {
                if (entry.Value.Id > 0)
                {
                    entry.Value.Id = ++currentId;
                    writer.Write(entry.Value.Id);
                    writer.WritePSSGString((string)entry.Key);

                    int pos            = (int)writer.BaseStream.Position;
                    int attributeCount = 0;
                    writer.Write(0); // attributeCount

                    foreach (Attribute attrEntry in entry.Value.Attributes)
                    {
                        if (attrEntry.Id > 0)
                        {
                            attrEntry.Id = ++currentAttrId;
                            writer.Write(attrEntry.Id);
                            writer.WritePSSGString(attrEntry.Name);
                            ++attributeCount;
                        }
                    }

                    writer.Seek(pos, SeekOrigin.Begin);
                    writer.Write(attributeCount);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
コード例 #4
0
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(size);
     writer.Write(attributeSize);
     if (Attributes != null)
     {
         foreach (PssgAttribute attr in Attributes)
         {
             attr.Write(writer);
         }
     }
     if (this.IsDataNode)
     {
         writer.WriteObject(data);
     }
     else
     {
         foreach (PssgNode node in ChildNodes)
         {
             node.Write(writer);
         }
     }
 }
コード例 #5
0
        public void WritePssg(Stream fileStream, bool close)
        {
            PssgBinaryWriter writer = new PssgBinaryWriter(new BigEndianBitConverter(), fileStream);
            try
            {
                writer.Write(Encoding.ASCII.GetBytes("PSSG"));
                writer.Write(0); // Length, filled in later

                if (RootNode != null)
                {
                    int nodeNameCount = 0;
                    int attributeNameCount = 0;
                    PssgSchema.ClearSchemaIds(); // make all ids -1
                    RootNode.UpdateId(ref nodeNameCount, ref attributeNameCount);
                    writer.Write(attributeNameCount);
                    writer.Write(nodeNameCount);
                    PssgSchema.SaveToPssg(writer); // Update Ids again, to make sequential

                    RootNode.UpdateSize();
                    RootNode.Write(writer);
                }
                writer.BaseStream.Position = 4;
                writer.Write((int)writer.BaseStream.Length - 8);

                if (close)
                {
                    writer.Close();
                }
            }
            catch (Exception ex)
            {
                if (writer != null)
                {
                    writer.Close();
                }
                throw ex;
            }
        }
コード例 #6
0
ファイル: PssgNode.cs プロジェクト: oomek/Ego-Engine-Modding
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(size);
     writer.Write(attributeSize);
     if (Attributes != null)
     {
         foreach (PssgAttribute attr in Attributes)
         {
             attr.Write(writer);
         }
     }
     if (this.IsDataNode)
     {
         writer.WriteObject(data);
     }
     else
     {
         foreach (PssgNode node in ChildNodes)
         {
             node.Write(writer);
         }
     }
 }
コード例 #7
0
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(this.size);
     writer.WriteObject(this.data);
 }
コード例 #8
0
        public static void SaveToPssg(PssgBinaryWriter writer)
        {
            // Update Ids to make sequential, and Unique
            int currentId = 0;
            int currentAttrId = 0;
            // Minimizing the attributes to unique names only seems to crash the game
            //Dictionary<string, int> unique = new Dictionary<string, int>();

            foreach (KeyValuePair<string, Node> entry in entries)
            {
                if (entry.Value.Id > 0)
                {
                    entry.Value.Id = ++currentId;
                    writer.Write(entry.Value.Id);
                    writer.WritePSSGString((string)entry.Key);

                    int pos = (int)writer.BaseStream.Position;
                    int attributeCount = 0;
                    writer.Write(0); // attributeCount

                    foreach (Attribute attrEntry in entry.Value.Attributes)
                    {
                        if (attrEntry.Id > 0)
                        {
                            attrEntry.Id = ++currentAttrId;
                            writer.Write(attrEntry.Id);
                            writer.WritePSSGString(attrEntry.Name);
                            ++attributeCount;
                        }
                    }

                    writer.Seek(pos, SeekOrigin.Begin);
                    writer.Write(attributeCount);
                    writer.Seek(0, SeekOrigin.End);
                }
            }
        }
コード例 #9
0
 public void Write(PssgBinaryWriter writer)
 {
     writer.Write(this.Id);
     writer.Write(this.size);
     writer.WriteObject(this.data);
 }