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); }
private static void Read(StringBuilder sb, List <ClassMember> members, EndianStream a_Stream) { for (int i = 0; i < members.Count; i++) { var member = members[i]; var level = member.Level; var varTypeStr = member.Type; var varNameStr = member.Name; object value = null; var align = (member.Flag & 0x4000) != 0; var append = true; if (varTypeStr == "SInt8")//sbyte { value = a_Stream.ReadSByte(); } else if (varTypeStr == "UInt8")//byte { value = a_Stream.ReadByte(); } else if (varTypeStr == "short" || varTypeStr == "SInt16")//Int16 { value = a_Stream.ReadInt16(); } else if (varTypeStr == "UInt16" || varTypeStr == "unsigned short")//UInt16 { value = a_Stream.ReadUInt16(); } else if (varTypeStr == "int" || varTypeStr == "SInt32")//Int32 { value = a_Stream.ReadInt32(); } else if (varTypeStr == "UInt32" || varTypeStr == "unsigned int")//UInt32 { value = a_Stream.ReadUInt32(); } else if (varTypeStr == "long long" || varTypeStr == "SInt64")//Int64 { value = a_Stream.ReadInt64(); } else if (varTypeStr == "UInt64" || varTypeStr == "unsigned long long")//UInt64 { value = a_Stream.ReadUInt64(); } else if (varTypeStr == "float")//float { value = a_Stream.ReadSingle(); } else if (varTypeStr == "double")//double { value = a_Stream.ReadDouble(); } else if (varTypeStr == "bool")//bool { value = a_Stream.ReadBoolean(); } else if (varTypeStr == "string")//string { append = false; var str = a_Stream.ReadAlignedString(a_Stream.ReadInt32()); sb.AppendFormat("{0}{1} {2} = \"{3}\"\r\n", (new string('\t', level)), varTypeStr, varNameStr, str); i += 3; //skip } else if (varTypeStr == "Array") //Array { append = false; if ((members[i - 1].Flag & 0x4000) != 0) { align = true; } sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr); var size = a_Stream.ReadInt32(); sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), "int", "size", size); var array = ReadArray(members, level, i); for (int j = 0; j < size; j++) { sb.AppendFormat("{0}[{1}]\r\n", (new string('\t', level + 1)), j); Read(sb, array, a_Stream); } i += array.Count + 1;//skip } else { append = false; align = false; sb.AppendFormat("{0}{1} {2}\r\n", (new string('\t', level)), varTypeStr, varNameStr); } if (append) { sb.AppendFormat("{0}{1} {2} = {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, value); } if (align) { a_Stream.AlignStream(4); } } }