public override void Read(BinaryReader br, string packetId) { //Console.WriteLine(@"MovieClip data type: " + _dataType); /*StringBuilder hex = new StringBuilder(data.Length * 2); * foreach (byte b in data) * hex.AppendFormat("{0:x2}", b); * Console.WriteLine(hex.ToString());*/ _clipId = br.ReadUInt16(); br.ReadByte(); //a1 + 34 _frameCount = br.ReadInt16(); //Console.WriteLine("ClipID: " + _clipId + " -> ExportName: " + exportName); int cnt1 = br.ReadInt32(); ushort[] sa1 = new ushort[cnt1 * 3]; for (int i = 0; i < cnt1; i++) { sa1[3 * i] = br.ReadUInt16(); sa1[3 * i + 1] = br.ReadUInt16(); sa1[3 * i + 2] = br.ReadUInt16(); } int cnt2 = br.ReadInt16(); ushort[] sa2 = new ushort[cnt2]; //a1 + 8 for (int i = 0; i < cnt2; i++) { sa2[i] = br.ReadUInt16(); int index = _scFile.GetShapes().FindIndex(shape => shape.Id == sa2[i]); if (index != -1) { _shapes.Add(_scFile.GetShapes()[index]); } ; } for (int i = 0; i < cnt2; i++) { var cnt2Opacity = br.ReadByte(); //Opacity or blend mode? } //read ascii for (int i = 0; i < cnt2; i++) { byte stringLength = br.ReadByte(); if (stringLength < 255) { br.ReadBytes(stringLength); } } while (true) { byte v26; while (true) { int lenght; while (true) { v26 = br.ReadByte(); lenght = br.ReadInt32(); if (v26 != 5) { break; } } if (v26 == 11) { short frameId = br.ReadInt16(); byte frameNameLength = br.ReadByte(); if (frameNameLength < 255) { var unk2 = Encoding.UTF8.GetString(br.ReadBytes(frameNameLength)); //Console.WriteLine("\t frameid : "+ frameId + " -> unk2: " + unk2); } } else if (v26 == 31) { var type31 = br.ReadBytes(lenght); //Console.WriteLine("Type 31 " + BitConverter.ToString(type31)); } else { break; } } if (v26 == 0) { break; } // Console.WriteLine("Left " + BitConverter.ToString(br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)))); Console.WriteLine("Unknown tag " + v26.ToString()); //break; } }
public override void Write(FileStream input) { input.Seek(0, SeekOrigin.Begin); byte[] file = new byte[input.Length]; input.Read(file, 0, file.Length); int cursor = (int)_scFile.GetStartExportsOffset(); input.Seek(_scFile.GetStartExportsOffset(), SeekOrigin.Begin); ushort exportCount = BitConverter.ToUInt16(file, cursor); input.Write(BitConverter.GetBytes((ushort)(exportCount + 1)), 0, 2); cursor += 2; input.Seek(exportCount * 2, SeekOrigin.Current); cursor += exportCount * 2; input.Write(BitConverter.GetBytes(_exportId), 0, 2); for (int i = 0; i < exportCount; i++) { byte nameLength = file[cursor]; cursor++; byte[] exportName = new byte[nameLength]; Array.Copy(file, cursor, exportName, 0, nameLength); input.WriteByte(nameLength); input.Write(exportName, 0, nameLength); cursor += nameLength; } input.WriteByte((byte)_exportName.Length); input.Write(Encoding.UTF8.GetBytes(_exportName), 0, (byte)_exportName.Length); while (cursor < file.Length) { input.WriteByte(file[cursor]); cursor++; } //refresh all offsets foreach (Texture t in _scFile.GetTextures()) { long offset = t.GetOffset(); if (offset > 0) { offset += 2 + 1 + _exportName.Length; } else { offset = offset - 2 - 1 - _exportName.Length; } t.SetOffset(offset); } foreach (Shape s in _scFile.GetShapes()) { long offset = s.GetOffset(); if (offset > 0) { offset += 2 + 1 + _exportName.Length; } else { offset = offset - 2 - 1 - _exportName.Length; } s.SetOffset(offset); foreach (ShapeChunk sc in s.GetChunks()) { long chunkOffset = sc.GetOffset(); if (chunkOffset > 0) { chunkOffset += 2 + 1 + _exportName.Length; } else { chunkOffset = chunkOffset - 2 - 1 - _exportName.Length; } sc.SetOffset(chunkOffset); } } foreach (MovieClip mc in _scFile.GetMovieClips()) { long offset = mc.GetOffset(); if (offset > 0) { offset += 2 + 1 + _exportName.Length; } else { offset = offset - 2 - 1 - _exportName.Length; } mc.SetOffset(offset); } _scFile.SetEofOffset(_scFile.GetEofOffset() + 2 + 1 + _exportName.Length); //ne pas oublier eofoffset }