Exemplo n.º 1
0
        private void readBase5()
        {
            int classID = a_Stream.ReadInt32();

            if (fileGen > 15)//5.5.0 and up
            {
                a_Stream.ReadByte();
                int type1;
                if ((type1 = a_Stream.ReadInt16()) >= 0)
                {
                    type1 = -1 - type1;
                }
                else
                {
                    type1 = classID;
                }
                classIDs.Add(new[] { type1, classID });
                classID = type1;

                /*TODO 替换?
                 * if(classID == 114)
                 * {
                 *  a_Stream.Position += 16;
                 * }*/
                var temp = a_Stream.ReadInt32();
                if (temp == 0)
                {
                    a_Stream.Position += 16;
                }
                a_Stream.Position -= 4;
                if (type1 < 0)
                {
                    a_Stream.Position += 16;
                }
            }
            else if (classID < 0)
            {
                a_Stream.Position += 16;
            }
            a_Stream.Position += 16;

            if (baseDefinitions)
            {
                int varCount   = a_Stream.ReadInt32();
                int stringSize = a_Stream.ReadInt32();

                a_Stream.Position += varCount * 24;
                string varStrings = Encoding.UTF8.GetString(a_Stream.ReadBytes(stringSize));
                string className  = "";
                var    classVar   = new List <ClassMember>();
                //build Class Structures
                a_Stream.Position -= varCount * 24 + stringSize;
                for (int i = 0; i < varCount; i++)
                {
                    ushort num0    = a_Stream.ReadUInt16();
                    byte   level   = a_Stream.ReadByte();
                    bool   isArray = a_Stream.ReadBoolean();

                    ushort varTypeIndex = a_Stream.ReadUInt16();
                    ushort test         = a_Stream.ReadUInt16();
                    string varTypeStr;
                    if (test == 0) //varType is an offset in the string block
                    {
                        varTypeStr = varStrings.Substring(varTypeIndex, varStrings.IndexOf('\0', varTypeIndex) - varTypeIndex);
                    }                                                                                                          //substringToNull
                    else //varType is an index in an internal strig array
                    {
                        varTypeStr = baseStrings.ContainsKey(varTypeIndex) ? baseStrings[varTypeIndex] : varTypeIndex.ToString();
                    }

                    ushort varNameIndex = a_Stream.ReadUInt16();
                    test = a_Stream.ReadUInt16();
                    string varNameStr;
                    if (test == 0)
                    {
                        varNameStr = varStrings.Substring(varNameIndex, varStrings.IndexOf('\0', varNameIndex) - varNameIndex);
                    }
                    else
                    {
                        varNameStr = baseStrings.ContainsKey(varNameIndex) ? baseStrings[varNameIndex] : varNameIndex.ToString();
                    }

                    int size  = a_Stream.ReadInt32();
                    int index = a_Stream.ReadInt32();
                    int flag  = a_Stream.ReadInt32();

                    if (index == 0)
                    {
                        className = varTypeStr + " " + varNameStr;
                    }
                    else
                    {
                        classVar.Add(new ClassMember()
                        {
                            Level = level - 1,
                            Type  = varTypeStr,
                            Name  = varNameStr,
                            Size  = size,
                            Flag  = flag
                        });
                    }

                    //for (int t = 0; t < level; t++) { Debug.Write("\t"); }
                    //Debug.WriteLine(varTypeStr + " " + varNameStr + " " + size);
                }
                a_Stream.Position += stringSize;

                var aClass = new ClassStruct()
                {
                    ID = classID, Text = className, members = classVar
                };
                aClass.SubItems.Add(classID.ToString());
                ClassStructures.Add(classID, aClass);
            }
        }
Exemplo n.º 2
0
        private static byte[] ReadSerializedShader(List <ClassMember> members, EndianStream a_Stream)
        {
            var offsets             = new List <uint>();
            var compressedLengths   = new List <uint>();
            var decompressedLengths = new List <uint>();

            for (int i = 0; i < members.Count; i++)
            {
                var member     = members[i];
                var level      = member.Level;
                var varTypeStr = member.Type;
                if (member.Name == "offsets")
                {
                    var offsets_size = a_Stream.ReadInt32();
                    for (int j = 0; j < offsets_size; j++)
                    {
                        offsets.Add(a_Stream.ReadUInt32());
                    }
                    var compressedLengths_size = a_Stream.ReadInt32();
                    for (int j = 0; j < compressedLengths_size; j++)
                    {
                        compressedLengths.Add(a_Stream.ReadUInt32());
                    }
                    var decompressedLengths_size = a_Stream.ReadInt32();
                    for (int j = 0; j < decompressedLengths_size; j++)
                    {
                        decompressedLengths.Add(a_Stream.ReadUInt32());
                    }
                    var compressedBlob     = a_Stream.ReadBytes(a_Stream.ReadInt32());
                    var decompressedStream = new MemoryStream();
                    for (int j = 0; j < offsets.Count; j++)
                    {
                        var compressedBytes = new byte[compressedLengths[j]];
                        Array.Copy(compressedBlob, offsets[j], compressedBytes, 0, compressedLengths[j]);
                        var decompressedBytes = new byte[decompressedLengths[j]];
                        using (var mstream = new MemoryStream(compressedBytes))
                        {
                            var decoder = new Lz4DecoderStream(mstream);
                            decoder.Read(decompressedBytes, 0, (int)decompressedLengths[j]);
                            decoder.Dispose();
                        }
                        decompressedStream.Write(decompressedBytes, 0, decompressedBytes.Length);
                    }
                    var decompressedBlob = decompressedStream.ToArray();
                    return(decompressedBlob);
                }
                var align = (member.Flag & 0x4000) != 0;
                if (varTypeStr == "SInt8")//sbyte
                {
                    a_Stream.ReadSByte();
                }
                else if (varTypeStr == "UInt8")//byte
                {
                    a_Stream.ReadByte();
                }
                else if (varTypeStr == "short" || varTypeStr == "SInt16")//Int16
                {
                    a_Stream.ReadInt16();
                }
                else if (varTypeStr == "UInt16" || varTypeStr == "unsigned short")//UInt16
                {
                    a_Stream.ReadUInt16();
                }
                else if (varTypeStr == "int" || varTypeStr == "SInt32")//Int32
                {
                    a_Stream.ReadInt32();
                }
                else if (varTypeStr == "UInt32" || varTypeStr == "unsigned int")//UInt32
                {
                    a_Stream.ReadUInt32();
                }
                else if (varTypeStr == "long long" || varTypeStr == "SInt64")//Int64
                {
                    a_Stream.ReadInt64();
                }
                else if (varTypeStr == "UInt64" || varTypeStr == "unsigned long long")//UInt64
                {
                    a_Stream.ReadUInt64();
                }
                else if (varTypeStr == "float")//float
                {
                    a_Stream.ReadSingle();
                }
                else if (varTypeStr == "double")//double
                {
                    a_Stream.ReadDouble();
                }
                else if (varTypeStr == "bool")//bool
                {
                    a_Stream.ReadBoolean();
                }
                else if (varTypeStr == "string")//string
                {
                    a_Stream.ReadAlignedString(a_Stream.ReadInt32());
                    i += 3;                     //skip
                }
                else if (varTypeStr == "Array") //Array
                {
                    if ((members[i - 1].Flag & 0x4000) != 0)
                    {
                        align = true;
                    }
                    var size  = a_Stream.ReadInt32();
                    var array = AssetPreloadData.ReadArray(members, level, i);
                    for (int j = 0; j < size; j++)
                    {
                        ReadSerializedShader(array, a_Stream);
                    }
                    i += array.Count + 1;//skip
                }
                else
                {
                    align = false;
                }
                if (align)
                {
                    a_Stream.AlignStream(4);
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        private void ReadFormat6(EndianStream b_Stream, bool padding = false)
        {
            var bundleSize       = b_Stream.ReadInt64();
            int compressedSize   = b_Stream.ReadInt32();
            int uncompressedSize = b_Stream.ReadInt32();
            int flag             = b_Stream.ReadInt32();

            if (padding)
            {
                b_Stream.ReadByte();
            }
            byte[] blocksInfoBytes;
            if ((flag & 0x80) != 0)//at end of file
            {
                var position = b_Stream.Position;
                b_Stream.Position = b_Stream.BaseStream.Length - compressedSize;
                blocksInfoBytes   = b_Stream.ReadBytes(compressedSize);
                b_Stream.Position = position;
            }
            else
            {
                blocksInfoBytes = b_Stream.ReadBytes(compressedSize);
            }
            EndianStream blocksInfo;

            switch (flag & 0x3F)
            {
            default:    //None
            {
                blocksInfo = new EndianStream(new MemoryStream(blocksInfoBytes), EndianType.BigEndian);
                break;
            }

            case 1:    //LZMA
            {
                blocksInfo = new EndianStream(SevenZipHelper.StreamDecompress(new MemoryStream(blocksInfoBytes)), EndianType.BigEndian);
                break;
            }

            case 2:    //LZ4
            case 3:    //LZ4HC
            {
                byte[] uncompressedBytes = new byte[uncompressedSize];
                using (var mstream = new MemoryStream(blocksInfoBytes))
                {
                    var decoder = new Lz4DecoderStream(mstream);
                    decoder.Read(uncompressedBytes, 0, uncompressedSize);
                    decoder.Dispose();
                }
                blocksInfo = new EndianStream(new MemoryStream(uncompressedBytes), EndianType.BigEndian);
                break;
            }
                //case 4:LZHAM?
            }
            using (blocksInfo)
            {
                blocksInfo.Position = 0x10;
                int          blockcount = blocksInfo.ReadInt32();
                EndianStream assetsData;
                var          assetsDataStream = new MemoryStream();
                for (int i = 0; i < blockcount; i++)
                {
                    uncompressedSize = blocksInfo.ReadInt32();
                    compressedSize   = blocksInfo.ReadInt32();
                    flag             = blocksInfo.ReadInt16();
                    var compressedBytes = b_Stream.ReadBytes(compressedSize);
                    switch (flag & 0x3F)
                    {
                    default:    //None
                    {
                        assetsDataStream.Write(compressedBytes, 0, compressedSize);
                        break;
                    }

                    case 1:    //LZMA
                    {
                        var uncompressedBytes = new byte[uncompressedSize];
                        using (var mstream = new MemoryStream(compressedBytes))
                        {
                            var decoder = SevenZipHelper.StreamDecompress(mstream, uncompressedSize);
                            decoder.Read(uncompressedBytes, 0, uncompressedSize);
                            decoder.Dispose();
                        }
                        assetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
                        break;
                    }

                    case 2:    //LZ4
                    case 3:    //LZ4HC
                    {
                        var uncompressedBytes = new byte[uncompressedSize];
                        using (var mstream = new MemoryStream(compressedBytes))
                        {
                            var decoder = new Lz4DecoderStream(mstream);
                            decoder.Read(uncompressedBytes, 0, uncompressedSize);
                            decoder.Dispose();
                        }
                        assetsDataStream.Write(uncompressedBytes, 0, uncompressedSize);
                        break;
                    }
                        //case 4:LZHAM?
                    }
                }
                assetsData = new EndianStream(assetsDataStream, EndianType.BigEndian);
                using (assetsData)
                {
                    var entryinfo_count = blocksInfo.ReadInt32();
                    for (int i = 0; i < entryinfo_count; i++)
                    {
                        var memFile          = new MemoryAssetsFile();
                        var entryinfo_offset = blocksInfo.ReadInt64();
                        var entryinfo_size   = blocksInfo.ReadInt64();
                        var unknown          = blocksInfo.ReadInt32();
                        memFile.fileName    = blocksInfo.ReadStringToNull();
                        assetsData.Position = entryinfo_offset;
                        var buffer = new byte[entryinfo_size];
                        assetsData.Read(buffer, 0, (int)entryinfo_size);
                        memFile.memStream = new MemoryStream(buffer);
                        MemoryAssetsFileList.Add(memFile);
                    }
                }
            }
        }