Example #1
0
        /// <summary>
        /// Writes out a chart with a provided parser.
        /// </summary>
        /// <param name="parser"></param>
        public ChartWriter(ChartParser parser)
        {
            zobj_bytes = new List <byte>();
            stbl_bytes = new List <byte>();
            index_byte = new List <byte>();
            rawTables  = new List <List <byte> >();

            generateZOBJ(parser.tempList);
            generateSTBL(parser.list_stringtable);
            generateINDX(parser);

            WriteFile();
        }
Example #2
0
        private void generateINDX(ChartParser parser)
        {
            // Write the header
            index_byte.Add(BitConverter.GetBytes('X')[0]);
            index_byte.Add(BitConverter.GetBytes('D')[0]);
            index_byte.Add(BitConverter.GetBytes('N')[0]);
            index_byte.Add(BitConverter.GetBytes('I')[0]);

            // Write the size
            int indx_size = (parser.tempList.Count + parser.list_stringtable.Count) * 16 + 8;

            byte[] indx_size_byte = BitConverter.GetBytes(indx_size).Reverse().ToArray();
            for (int i = 0; i < indx_size_byte.Length; i++)
            {
                index_byte.Add(indx_size_byte[i]);
            }

            // Write the number of entries
            int numEntries = parser.tempList.Count + parser.list_stringtable.Count;

            byte[] numEntries_byte = BitConverter.GetBytes(numEntries).Reverse().ToArray();
            for (int i = 0; i < numEntries_byte.Length; i++)
            {
                index_byte.Add(numEntries_byte[i]);
            }

            // Add the constant
            index_byte.Add(0x0);
            index_byte.Add(0x0);
            index_byte.Add(0x0);
            index_byte.Add(0x4);

            // Initial offset
            int offset = 16 * (numEntries) + 24;

            // Add information about all string tables first
            for (int k = 0; k < rawTables.Count; k++)
            {
                byte[] indexKey_byte = BitConverter.GetBytes(parser.list_stringtable[k].indexKey).Reverse().ToArray();
                for (int i = 0; i < indexKey_byte.Length; i++)
                {
                    index_byte.Add(indexKey_byte[i]);
                }

                byte[] offset_byte = BitConverter.GetBytes(offset).Reverse().ToArray();
                for (int i = 0; i < offset_byte.Length; i++)
                {
                    index_byte.Add(offset_byte[i]);
                }

                for (int i = 0; i < 4; i++)
                {
                    index_byte.Add(0x0);
                }

                offset += rawTables[k].Count;
            }

            // Add information about ZOBJ items
            for (int k = 0; k < parser.tempList.Count; k++)
            {
                byte[] indexKey_byte = BitConverter.GetBytes(parser.tempList[k].indexKey).Reverse().ToArray();
                for (int i = 0; i < indexKey_byte.Length; i++)
                {
                    index_byte.Add(indexKey_byte[i]);
                }

                byte[] offset_byte = BitConverter.GetBytes(offset).Reverse().ToArray();
                for (int i = 0; i < offset_byte.Length; i++)
                {
                    index_byte.Add(offset_byte[i]);
                }

                for (int i = 0; i < 4; i++)
                {
                    index_byte.Add(0x0);
                }

                offset += (parser.tempList[k].rawData.Length + 40);
            }
        }