コード例 #1
0
        public byte[] Rebuild(int pos)
        {
            FileOutput f = new FileOutput();

            f.endian = Endianness.Big;

            f.WriteInt(pos + f.Pos() + 0x20);
            f.WriteInt(matHash);
            f.WriteInt(properties.Count);
            int nameOffset = pos + f.Pos() + 0x15 + name.Length;

            while (nameOffset % 4 != 0)
            {
                nameOffset++;
            }
            f.WriteInt(nameOffset);
            f.WriteFlag(hasPat);
            f.WriteBytes(new byte[3]);
            //Write all the mat data into a buffer (g) then write pat offset
            int        pos2 = pos + f.Pos() + 4;
            FileOutput g    = new FileOutput();

            g.endian = Endianness.Big;

            if (matHash2 != 0)
            {
                g.WriteInt(pos2 + g.Pos() + 0x8);
                g.WriteInt(matHash);
            }
            else
            {
                g.WriteBytes(new byte[8]);
            }

            g.WriteString(name);
            g.WriteByte(0);
            while ((pos2 + g.Pos()) % 0x10 != 0)
            {
                g.WriteByte(0);
            }

            int position = pos2 + g.Pos() + properties.Count * 4;

            while (position % 16 != 0)
            {
                position++;
            }

            List <byte[]> builtProperties = new List <byte[]>();

            foreach (MatData prop in properties)
            {
                g.WriteInt(position);
                byte[] b = prop.Rebuild(position);
                builtProperties.Add(b);
                position += b.Length;
                while (position % 16 != 0)
                {
                    position++;
                }
            }

            while ((pos2 + g.Pos()) % 16 != 0)
            {
                g.WriteByte(0);
            }

            foreach (byte[] b in builtProperties)
            {
                g.WriteBytes(b);
                while ((pos2 + g.Pos()) % 16 != 0)
                {
                    g.WriteByte(0);
                }
            }

            f.WriteInt(pos2 + g.Pos());
            f.WriteBytes(g.GetBytes());
            if (hasPat)
            {
                f.WriteBytes(pat0.Rebuild(f.Pos()));
            }

            return(f.GetBytes());
        }