Пример #1
0
        public void ReadData(string indexPath)
        {
            byte[] index = File.ReadAllBytes(indexPath);

            int sqPackHeaderLength = BitConverter.ToInt32(index, 0xc);

            SqPackHeader = new byte[sqPackHeaderLength];
            Array.Copy(index, 0, SqPackHeader, 0, sqPackHeaderLength);

            int indexHeaderLength = BitConverter.ToInt32(index, sqPackHeaderLength);

            IndexHeader = new byte[indexHeaderLength];
            Array.Copy(index, sqPackHeaderLength, IndexHeader, 0, indexHeaderLength);

            int directoryOffset = BitConverter.ToInt32(IndexHeader, 0xe4);
            int directorySize   = BitConverter.ToInt32(IndexHeader, 0xe8);

            byte[] directorySegment = new byte[directorySize];
            Array.Copy(index, directoryOffset, directorySegment, 0, directorySize);

            List <IndexDirectoryInfo> directories = new List <IndexDirectoryInfo>();

            for (int i = 0; i + 0xf < directorySize; i += 0x10)
            {
                IndexDirectoryInfo directory = new IndexDirectoryInfo();
                directory.Key = BitConverter.ToUInt32(directorySegment, i);

                int fileOffset = BitConverter.ToInt32(directorySegment, i + 0x4);
                int fileSize   = BitConverter.ToInt32(directorySegment, i + 0x8);

                byte[] fileSegment = new byte[fileSize];
                Array.Copy(index, fileOffset, fileSegment, 0, fileSize);

                List <IndexFileInfo> files = new List <IndexFileInfo>();

                for (int j = 0; j + 0xf < fileSize; j += 0x10)
                {
                    IndexFileInfo file = new IndexFileInfo();
                    file.Key = BitConverter.ToUInt32(fileSegment, j);

                    if (BitConverter.ToUInt32(fileSegment, j + 0x4) != directory.Key)
                    {
                        throw new Exception();
                    }

                    file.WrappedOffset = BitConverter.ToUInt32(fileSegment, j + 0x8);

                    files.Add(file);
                }

                directory.FileInfo = files.ToArray();

                directories.Add(directory);
            }

            DirectoryInfo = directories.ToArray();
        }
Пример #2
0
        static void Main(string[] args)
        {
            string baseDir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string inputDir = Path.Combine(baseDir, "input");

            string    indexPath = Path.Combine(inputDir, "000000.win32.index");
            IndexFile index     = new IndexFile();

            index.ReadData(indexPath);

            foreach (IndexDirectoryInfo directory in index.DirectoryInfo)
            {
                if (directory.Key != Hash.Compute("common/font"))
                {
                    continue;
                }

                List <IndexFileInfo> files = directory.FileInfo.ToList();
                IndexFileInfo        font1 = files.First(f => f.Key == Hash.Compute("font1.tex"));
                IndexFileInfo        font8 = new IndexFileInfo();
                font8.Key           = Hash.Compute("font8.tex");
                font8.DirectoryInfo = directory;
                font8.WrappedOffset = font1.WrappedOffset;
                files.Add(font8);
                directory.FileInfo = files.ToArray();
            }

            string outputDir = Path.Combine(baseDir, "output");

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            string outputPath = Path.Combine(outputDir, "000000.win32.index");

            File.WriteAllBytes(outputPath, index.RepackData(File.ReadAllBytes(indexPath)));
        }