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); } } } }
private void readBase5(int indexRef) { int classID = 0; classID = a_Stream.ReadInt32(); if (fileGen < 16) { if (classID < 0) { a_Stream.Position += 16; } a_Stream.Position += 16; } else { classIDLookup.Add(indexRef, (ushort)classID); if (classID == 114) { a_Stream.Position += 16; } a_Stream.Position += 19; } if (baseDefinitions) { #region cmmon string array string[] baseStrings = new string[1007]; baseStrings[0] = "AABB"; baseStrings[5] = "AnimationClip"; baseStrings[19] = "AnimationCurve"; baseStrings[49] = "Array"; baseStrings[55] = "Base"; baseStrings[60] = "BitField"; baseStrings[76] = "bool"; baseStrings[81] = "char"; baseStrings[86] = "ColorRGBA"; baseStrings[106] = "data"; baseStrings[138] = "FastPropertyName"; baseStrings[155] = "first"; baseStrings[161] = "float"; baseStrings[167] = "Font"; baseStrings[172] = "GameObject"; baseStrings[183] = "Generic Mono"; baseStrings[208] = "GUID"; baseStrings[222] = "int"; baseStrings[241] = "map"; baseStrings[245] = "Matrix4x4f"; baseStrings[262] = "NavMeshSettings"; baseStrings[263] = "MonoBehaviour"; baseStrings[277] = "MonoScript"; baseStrings[299] = "m_Curve"; baseStrings[349] = "m_Enabled"; baseStrings[374] = "m_GameObject"; baseStrings[427] = "m_Name"; baseStrings[490] = "m_Script"; baseStrings[519] = "m_Type"; baseStrings[526] = "m_Version"; baseStrings[543] = "pair"; baseStrings[548] = "PPtr<Component>"; baseStrings[564] = "PPtr<GameObject>"; baseStrings[581] = "PPtr<Material>"; baseStrings[616] = "PPtr<MonoScript>"; baseStrings[633] = "PPtr<Object>"; baseStrings[688] = "PPtr<Texture>"; baseStrings[702] = "PPtr<Texture2D>"; baseStrings[718] = "PPtr<Transform>"; baseStrings[741] = "Quaternionf"; baseStrings[753] = "Rectf"; baseStrings[778] = "second"; baseStrings[795] = "size"; baseStrings[800] = "SInt16"; baseStrings[814] = "int64"; baseStrings[840] = "string"; baseStrings[874] = "Texture2D"; baseStrings[884] = "Transform"; baseStrings[894] = "TypelessData"; baseStrings[907] = "UInt16"; baseStrings[928] = "UInt8"; baseStrings[934] = "unsigned int"; baseStrings[981] = "vector"; baseStrings[988] = "Vector2f"; baseStrings[997] = "Vector3f"; baseStrings[1006] = "Vector4f"; #endregion 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 = ""; StringBuilder classVarStr = new StringBuilder(); //build Class Structures a_Stream.Position -= varCount * 24 + stringSize; for (int i = 0; i < varCount; i++) { a_Stream.ReadUInt16(); byte level = a_Stream.ReadByte(); 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[varTypeIndex] != null ? 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[varNameIndex] != null ? baseStrings[varNameIndex] : varNameIndex.ToString(); } int size = a_Stream.ReadInt32(); int index = a_Stream.ReadInt32(); a_Stream.ReadInt32(); if (index == 0) { className = varTypeStr + " " + varNameStr; } else { classVarStr.AppendFormat("{0}{1} {2} {3}\r\n", (new string('\t', level)), varTypeStr, varNameStr, size); } //for (int t = 0; t < level; t++) { ValkyrieDebug.Write("\t"); } //ValkyrieDebug.WriteLine(varTypeStr + " " + varNameStr + " " + size); } a_Stream.Position += stringSize; var aClass = new ClassStrStruct() { ID = classID, Text = className, members = classVarStr.ToString() }; aClass.subItems.Add(classID.ToString()); ClassStructures.Add(classID, aClass); } }
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); } }
public static void WriteFile(Unity_Studio.EndianStream stream, string file, int offset, int size, Ogg ogg) { // Write to disk using (BinaryWriter writer = new BinaryWriter(File.Open(file, FileMode.Create))) { // Only support header CRC 3605052372 for now OggVorbisHeader head = new OggVorbisHeader(); HeaderPacketBuilder hpb = new HeaderPacketBuilder(); CodecSetup cSetup = new CodecSetup(null); cSetup.BlockSizes[0] = 256; cSetup.BlockSizes[1] = 2048; VorbisInfo info = new VorbisInfo(cSetup, (int)ogg.channels, (int)ogg.frequency, 0); OggPacket headerInfo = hpb.BuildInfoPacket(info); Comments comments = new Comments(); if (ogg.loopStart > 0 && ogg.loopEnd > 0) { comments.AddTag("LOOP_START", ogg.loopStart.ToString()); comments.AddTag("LOOP_END", ogg.loopEnd.ToString()); } OggPacket headerComment = hpb.BuildCommentsPacket(comments); OggPacket headerSetup = new OggPacket(OggVorbisHeader.GetHeader(ogg.crc32), false, 0, 2); OggStream output = new OggStream(1); output.PacketIn(headerInfo); output.PacketIn(headerComment); output.PacketIn(headerSetup); stream.Position = offset; UInt16 packetSize = stream.ReadUInt16(); int prevPacketNo = 2; int prevGranulePos = 0; while (packetSize > 0) { OggPacket packet = new OggPacket(stream.ReadBytes(packetSize), false, 0, prevPacketNo + 1); byte firstByte = packet.PacketData[0]; // OK for stereo int granuleSize = 128; if ((firstByte & 2) != 0) { granuleSize = 1024; } if (ogg.channels == 1) { granuleSize /= 4; } packet.GranulePosition = prevGranulePos + granuleSize; if (stream.Position + 2 < offset + size) { packetSize = stream.ReadUInt16(); } else { packetSize = 0; } packet.EndOfStream = packetSize == 0; prevGranulePos = packet.GranulePosition; prevPacketNo = packet.PacketNumber; output.PacketIn(packet); OggPage page = null; if (output.PageOut(out page, true)) { writer.Write(page.Header); writer.Write(page.Body); } } //float vorbis_quality = ((ogg.quality - 1) + (ogg.quality - 100) * 0.1f) / 99.0f; //VorbisInfo.InitVariableBitRate(ogg.channels, ogg.frequency, ogg.) //writer.Write(); writer.Close(); } }