示例#1
0
        public byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.Endian = endian;

            f.writeString("SARC");
            f.writeShort(0x14);
            f.Endian = endian;
            f.writeShort(65279);

            byte[] sfat = RebuildSFATArchive();

            f.writeInt(sfat.Length + 0x14);
            f.writeInt(sfatStartOffset + 0x14);
            f.writeInt(0x1000000);
            f.writeBytes(sfat);

            return(f.getBytes());
        }
示例#2
0
        private byte[] RebuildSFATArchive()
        {
            FileOutput f = new FileOutput();

            f.Endian = endian;

            f.writeString("SFAT");
            f.writeShort(0xC);
            f.writeShort(files.Count);
            f.writeInt(0x65);

            int  stringPos = 0;
            int  dataPos   = 0;
            bool isString  = true;

            foreach (string filename in files.Keys)
            {
                if (filename.Contains("0x"))
                {
                    isString = false;
                    f.writeInt((int)Convert.ToInt32(filename, 16));
                    f.writeInt(0);
                }
                else
                {
                    f.writeInt((int)GetHash(filename.ToArray(), filename.Length, 0x65));
                    f.writeInt(stringPos + 0x1000000);
                    stringPos += GetSizeInChunks(filename.Length + 1, 4) / 4;
                }
                f.writeInt(dataPos);
                f.writeInt(dataPos + files[filename].Length);
                dataPos += files[filename].Length % padding == 0 ? files[filename].Length : files[filename].Length + (padding - files[filename].Length % padding);
            }

            f.writeHex("53464E5400080000");
            if (isString)
            {
                foreach (string filename in files.Keys)
                {
                    f.writeString(filename);
                    f.writeByte(0);
                    while (f.pos() % 4 != 0)
                    {
                        f.writeByte(0);
                    }
                }
            }
            if (padding == -1 || padding < f.pos())
            {
                while ((f.pos() + 0x14) % 0x100 != 0)
                {
                    f.writeByte(0);
                }
            }
            else
            {
                f.writeBytes(new byte[padding - (f.pos() + 0x14)]);
            }

            sfatStartOffset = f.pos();
            int cur = 0;

            foreach (string filename in files.Keys)
            {
                f.writeIntAt(f.pos() - sfatStartOffset, 0x14 + (cur * 0x10));
                f.writeBytes(files[filename]);
                f.writeIntAt(f.pos() - sfatStartOffset, 0x18 + (cur * 0x10));
                while ((f.pos() + 0x14) % padding != 0)
                {
                    f.writeByte(0);
                }

                cur++;
            }

            return(f.getBytes());
        }