Ejemplo n.º 1
0
        public byte[] Rebuild()
        {
            FileOutput f = new FileOutput();

            f.byteOrder = byteOrder;

            f.WriteString("SARC");
            f.WriteShort(0x14);
            f.byteOrder = byteOrder;
            f.WriteShort(65279);

            byte[] sfat = RebuildSFATArchive();

            f.WriteInt(sfat.Length + 0x14);
            f.WriteInt(sfatStartOffset + 0x14);
            f.WriteInt(0x1000000);
            f.WriteBytes(sfat);

            return(f.GetBytes());
        }
Ejemplo n.º 2
0
        private byte[] RebuildSFATArchive()
        {
            FileOutput f = new FileOutput();

            f.byteOrder = byteOrder;

            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.Position() % 4 != 0)
                    {
                        f.WriteByte(0);
                    }
                }
            }
            if (padding == -1 || padding < f.Position())
            {
                while ((f.Position() + 0x14) % 0x100 != 0)
                {
                    f.WriteByte(0);
                }
            }
            else
            {
                f.WriteBytes(new byte[padding - (f.Position() + 0x14)]);
            }

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

            foreach (string filename in files.Keys)
            {
                f.WriteIntAt(f.Position() - sfatStartOffset, 0x14 + (cur * 0x10));
                f.WriteBytes(files[filename]);
                f.WriteIntAt(f.Position() - sfatStartOffset, 0x18 + (cur * 0x10));
                while ((f.Position() + 0x14) % padding != 0)
                {
                    f.WriteByte(0);
                }

                cur++;
            }

            return(f.GetBytes());
        }