示例#1
0
        public static byte[] CreateBlankAssets(string engineVersion, List <Type_0D> types)
        {
            using (MemoryStream ms = new MemoryStream())
                using (AssetsFileWriter writer = new AssetsFileWriter(ms))
                {
                    AssetsFileHeader header = new AssetsFileHeader()
                    {
                        metadataSize   = 0,
                        fileSize       = 0x1000,
                        format         = 0x11,
                        offs_firstFile = 0x1000,
                        endianness     = 0,
                        unknown        = new byte[] { 0, 0, 0 }
                    };
                    TypeTree typeTree = new TypeTree()
                    {
                        unityVersion  = engineVersion,
                        version       = 0x5,
                        hasTypeTree   = true,
                        fieldCount    = (uint)types.Count(),
                        pTypes_Unity5 = types.ToArray()
                    };


                    header.Write(writer.Position, writer);
                    writer.bigEndian = false;
                    typeTree.Write(writer.Position, writer, 0x11);
                    writer.Write((uint)0);
                    writer.Align();
                    //preload table and dependencies
                    writer.Write((uint)0);
                    writer.Write((uint)0);

                    //due to a write bug in at.net we have to pad to 0x1000
                    while (ms.Position < 0x1000)
                    {
                        writer.Write((byte)0);
                    }

                    return(ms.ToArray());
                }
        }
示例#2
0
        public static void CreateBlankAssets(MemoryStream ms, string engineVersion, uint formatVersion, uint typeTreeVersion, bool hasTypeTree = false)
        {
            AssetsFileWriter writer = new AssetsFileWriter(ms);

            AssetsFileHeader header = new AssetsFileHeader()
            {
                metadataSize    = 0,
                fileSize        = -1,
                format          = formatVersion,
                firstFileOffset = -1,
                endianness      = 0,
                unknown         = new byte[] { 0, 0, 0 }
            };

            TypeTree typeTree = new TypeTree()
            {
                unityVersion = engineVersion,
                version      = typeTreeVersion,
                hasTypeTree  = hasTypeTree,
                fieldCount   = 0,
                unity5Types  = new List <Type_0D>()
            };

            header.Write(writer);
            typeTree.Write(writer, formatVersion);

            writer.Write((uint)0); //AssetCount
            writer.Align();

            //preload table and dependencies
            writer.Write((uint)0);
            writer.Write((uint)0);

            //secondaryTypeCount
            if (header.format >= 0x14)
            {
                writer.Write(0);
            }

            uint metadataSize = (uint)(writer.Position - 0x13);

            if (header.format >= 0x16)
            {
                metadataSize -= 0x1c;
            }

            if (writer.Position < 0x1000)
            {
                while (writer.Position < 0x1000)
                {
                    writer.Write((byte)0x00);
                }
            }
            else
            {
                if (writer.Position % 16 == 0)
                {
                    writer.Position += 16;
                }
                else
                {
                    writer.Align16();
                }
            }

            long endPosition = writer.Position;

            header.fileSize        = endPosition;
            header.firstFileOffset = endPosition;
            header.metadataSize    = metadataSize;

            writer.Position = 0;
            header.Write(writer);

            writer.Position = endPosition;
        }