コード例 #1
0
        /// <summary>
        /// Parses the object table.
        /// </summary>
        /// <param name="indexBytes">The index file to read.</param>
        private void zobjParser(byte[] indexBytes)
        {
            int index = 8;

            while (index < indexBytes.Length)
            {
                string chunkType      = "";
                byte[] chunkType_byte = new byte[4];
                byte[] chunkSize      = new byte[4];
                int    chunkSize_int;

                // Get the chunk type
                int i = index;
                for (; index < i + 4; index++)
                {
                    chunkType_byte[index - i] = indexBytes[index];
                }

                chunkType = System.Text.Encoding.Default.GetString(chunkType_byte.Reverse().ToArray());

                // Get the chunk size
                i = index;
                for (; index < i + 4; index++)
                {
                    chunkSize[index - i] = indexBytes[index];
                }

                chunkSize_int = BitConverter.ToInt32(chunkSize.Reverse().ToArray(), 0);

                // Get the raw data
                byte[] chunkRawData = new byte[chunkSize_int];
                i = index;

                for (; index < i + chunkSize_int; index++)
                {
                    chunkRawData[index - i] = indexBytes[index];
                }

                switch (chunkType)
                {
                case "ZOBJ":
                    zobject = new IndexObject();
                    zobjHelper(chunkRawData);
                    break;

                default:
                    break;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructor for the class.  Sets the in-class parser information.
        /// </summary>
        /// <param name="parser"></param>
        public IndexWriter(IndexParser parser)
        {
            engTable    = parser.engParser;
            freTable    = parser.freParser;
            japTable    = parser.japParser;
            gerTable    = parser.gerParser;
            itaTable    = parser.itaParser;
            espTable    = parser.espParser;
            indexObject = parser.zobject;

            // Initialize all lists.
            engTable_keys_byte = new List <byte>();
            japTable_keys_byte = new List <byte>();
            itaTable_keys_byte = new List <byte>();
            freTable_keys_byte = new List <byte>();
            espTable_keys_byte = new List <byte>();
            gerTable_keys_byte = new List <byte>();

            engTable_strings_byte = new List <byte>();
            japTable_strings_byte = new List <byte>();
            itaTable_strings_byte = new List <byte>();
            freTable_strings_byte = new List <byte>();
            espTable_strings_byte = new List <byte>();
            gerTable_strings_byte = new List <byte>();

            index_byte = new List <byte>();

            // Write out all string tables.
            engTable_byte = WriteTable(engTable, 0);
            freTable_byte = WriteTable(freTable, 1);
            japTable_byte = WriteTable(japTable, 2);
            gerTable_byte = WriteTable(gerTable, 3);
            itaTable_byte = WriteTable(itaTable, 4);
            espTable_byte = WriteTable(espTable, 5);

            // Write out the ZOBJ section.
            zobject_final = WriteObject(indexObject);

            // Write the index section of the file.
            WriteIndex();

            // Write the final goddamn file
            WriteFile();
        }
コード例 #3
0
        /// <summary>
        /// Writes out the object section of the index file.
        /// </summary>
        /// <param name="indexObject">The struct representation of the object.</param>
        private List <byte> WriteObject(IndexObject indexObject)
        {
            List <byte> zobject_byte     = new List <byte>();
            List <byte> zobject_24entry  = new List <byte>();
            List <byte> zobject_filepath = new List <byte>();

            // Add header bytes
            zobject_byte.Add(BitConverter.GetBytes('J')[0]);
            zobject_byte.Add(BitConverter.GetBytes('B')[0]);
            zobject_byte.Add(BitConverter.GetBytes('O')[0]);
            zobject_byte.Add(BitConverter.GetBytes('Z')[0]);

            // Add zeroed data, fill it later
            for (int i = 0; i < 4; i++)
            {
                zobject_byte.Add(0x0);
            }

            // Add the index key
            byte[] indexKey_byte = BitConverter.GetBytes(indexObject.indexKey).Reverse().ToArray();
            for (int i = 0; i < indexKey_byte.Length; i++)
            {
                zobject_byte.Add(indexKey_byte[i]);
            }

            // Add the object key
            byte[] objectKey_byte = BitConverter.GetBytes(indexObject.objectKey).Reverse().ToArray();
            for (int i = 0; i < objectKey_byte.Length; i++)
            {
                zobject_byte.Add(objectKey_byte[i]);
            }

            // Add the type string key
            byte[] typeStringKey_byte = BitConverter.GetBytes(indexObject.typeStringKey).Reverse().ToArray();
            for (int i = 0; i < typeStringKey_byte.Length; i++)
            {
                zobject_byte.Add(typeStringKey_byte[i]);
            }

            // Add zeroed data
            for (int i = 0; i < 8; i++)
            {
                zobject_byte.Add(0x0);
            }

            // Add the DLC Number
            byte[] dlcNum_byte = BitConverter.GetBytes(indexObject.dlcNum).Reverse().ToArray();
            for (int i = 0; i < dlcNum_byte.Length; i++)
            {
                zobject_byte.Add(dlcNum_byte[i]);
            }

            // Add the number of entries to write
            byte[] numEntries_byte = BitConverter.GetBytes(indexObject.numEntries).Reverse().ToArray();
            for (int i = 0; i < numEntries_byte.Length; i++)
            {
                zobject_byte.Add(numEntries_byte[i]);
            }

            // Add the constant value
            for (int i = 0; i < 4; i++)
            {
                switch (i)
                {
                case 3:
                    zobject_byte.Add(0x4);
                    break;

                default:
                    zobject_byte.Add(0x0);
                    break;
                }
            }

            // Add all entries.
            int counter  = indexObject.numEntries - 1;
            int entryNum = 0;

            foreach (IndexEntry entry in indexObject.entryList)
            {
                // Write tag
                byte[] tagKey_byte = BitConverter.GetBytes(entry.tagKey).Reverse().ToArray();
                for (int i = 0; i < tagKey_byte.Length; i++)
                {
                    zobject_24entry.Add(tagKey_byte[i]);
                }

                // Write second key
                byte[] regularKey_byte = BitConverter.GetBytes(entry.regularKey).Reverse().ToArray();
                for (int i = 0; i < regularKey_byte.Length; i++)
                {
                    zobject_24entry.Add(regularKey_byte[i]);
                }

                // Add decimal
                for (int i = 0; i < 4; i++)
                {
                    switch (i)
                    {
                    case 3:
                        if (counter == 0)
                        {
                            zobject_24entry.Add(0x2);
                        }
                        else
                        {
                            zobject_24entry.Add(0x1);
                        }
                        break;

                    default:
                        zobject_24entry.Add(0x0);
                        break;
                    }
                }

                // Calculate offset
                int offset = (counter * 24) + (entryNum * 248) + 4;

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

                // Write data to entry list
                byte[] stringKey_byte = BitConverter.GetBytes(entry.stringKey).Reverse().ToArray();
                for (int i = 0; i < stringKey_byte.Length; i++)
                {
                    zobject_filepath.Add(stringKey_byte[i]);
                }

                // Write filepath to entry list
                byte[] filePath_byte = System.Text.Encoding.Unicode.GetBytes(entry.filepath);
                for (int i = 0; i < filePath_byte.Length; i += 2)
                {
                    zobject_filepath.Add(filePath_byte[i]);
                }

                // Write zeroed data
                for (int i = 0; i < (248 - entry.filepath.Length - 8); i++)
                {
                    zobject_filepath.Add(0x0);
                }

                counter--;
            }

            // Concatenate the lists
            foreach (byte entry in zobject_24entry)
            {
                zobject_byte.Add(entry);
            }

            foreach (byte entry in zobject_filepath)
            {
                zobject_byte.Add(entry);
            }

            byte[] realSize = BitConverter.GetBytes(zobject_byte.Count - 8).Reverse().ToArray();
            zobject_byte[4] = realSize[0];
            zobject_byte[5] = realSize[1];
            zobject_byte[6] = realSize[2];
            zobject_byte[7] = realSize[3];

            return(zobject_byte);
        }