public void Decode() { using (var br = new BinaryReader(File.Open(m_vFileName, FileMode.Open))) { ushort m_vShapeCount = br.ReadUInt16(); //a1 + 8 ushort m_vMovieClipCount = br.ReadUInt16(); //a1 + 12 ushort m_vTextureCount = br.ReadUInt16(); //a1 + 16 ushort m_vTextFieldCount = br.ReadUInt16(); //a1 + 24 ushort m_vMatrix2x3Count = br.ReadUInt16(); //a1 + 28 ushort m_vColorTransformCount = br.ReadUInt16(); //a1 + 32 Debug.WriteLine("ShapeCount: " + m_vShapeCount); Debug.WriteLine("MovieClipCount: " + m_vMovieClipCount); Debug.WriteLine("TextureCount: " + m_vTextureCount); Debug.WriteLine("TextFieldCount: " + m_vTextFieldCount); Debug.WriteLine("Matrix2x3Count: " + m_vMatrix2x3Count); Debug.WriteLine("ColorTransformCount: " + m_vColorTransformCount); //5 useless bytes, not even used by Supercell br.ReadByte(); //1 octet br.ReadUInt16(); //2 octets br.ReadUInt16(); //2 octets m_vStartExportsOffset = br.BaseStream.Position; m_vExportCount = br.ReadUInt16();//a1 + 20 Debug.WriteLine("ExportCount: " + m_vExportCount); for (int i = 0; i < m_vExportCount; i++) { var sce = new Export(this); sce.SetId(br.ReadInt16()); m_vExports.Add(sce); } //m_vExportNames = new string[m_vExportCount]; for (int i = 0; i < m_vExportCount; i++) { //((Export)m_vExports[i]).SetOffset(br.BaseStream.Position); byte nameLength = br.ReadByte(); ((Export)m_vExports[i]).SetExportName(Encoding.UTF8.GetString(br.ReadBytes(nameLength))); } do { long offset = br.BaseStream.Position; byte dataType = br.ReadByte(); int dataLength = br.ReadInt32(); switch (dataType) { case 1: case 16: case 19: { var texture = new Texture(this); texture.SetOffset(offset); texture.ParseData(br); m_vTextures.Add(texture); continue; } case 2: case 18: { var shape = new Shape(this); shape.SetOffset(offset); m_vShapes.Add(shape); shape.ParseData(br); continue; } case 3: case 10: case 12: case 14: { var movieClip = new MovieClip(this, dataType); movieClip.SetOffset(offset); movieClip.ParseData(br); m_vMovieClips.Add(movieClip); continue; } case 7: case 15: case 20: { //textFields break; } case 8: { //matrix2x3 break; } case 9: { //colorTransform break; } case 13: { break; } default: { Debug.WriteLine("Unkown data type " + dataType.ToString()); break; } case 0: { m_vEofOffset = offset; for (int i = 0; i < m_vExports.Count; i++) { int index = m_vMovieClips.FindIndex(movie => movie.GetId() == m_vExports[i].GetId()); if (index != -1) { ((Export)m_vExports[i]).SetDataObject((MovieClip)m_vMovieClips[index]); } } return; } } if (dataLength >= 1) { br.ReadBytes(dataLength); } }while (true); } }
public void Decode() { using (var br2 = new BinaryReader(File.Open(m_vFileName + "_tex", FileMode.Open))) { try { while (true) { byte fileType = br2.ReadByte(); uint fileSize = br2.ReadUInt32(); var texture = new Texture(this); texture.SetOffset(0); texture.ParseData2(br2, fileType); m_vTextures.Add(texture); } } catch (EndOfStreamException e) { } } using (var br = new BinaryReader(File.Open(m_vFileName, FileMode.Open))) { ushort shapeCount = br.ReadUInt16(); //a1 + 8 ushort movieClipCount = br.ReadUInt16(); //a1 + 12 ushort textureCount = br.ReadUInt16(); //a1 + 16 ushort textFieldCount = br.ReadUInt16(); //a1 + 24 ushort matrix2x3Count = br.ReadUInt16(); //a1 + 28 ushort colorTransformCount = br.ReadUInt16(); //a1 + 32 Log("ShapeCount: " + shapeCount); Log("MovieClipCount: " + movieClipCount); Log("TextureCount: " + textureCount + " -- " + m_vTextures.Count); Log("TextFieldCount: " + textFieldCount); Log("Matrix2x3Count: " + matrix2x3Count); Log("ColorTransformCount: " + colorTransformCount); //5 useless bytes, not even used by Supercell br.ReadByte(); //1 octet br.ReadUInt16(); //2 octets br.ReadUInt16(); //2 octets m_vStartExportsOffset = br.BaseStream.Position; m_vExportCount = br.ReadUInt16();//a1 + 20 Log("ExportCount: " + m_vExportCount); for (int i = 0; i < m_vExportCount; i++) { var sce = new Export(this); sce.SetId(br.ReadInt16()); m_vExports.Add(sce); } //m_vExportNames = new string[m_vExportCount]; for (int i = 0; i < m_vExportCount; i++) { //((Export)m_vExports[i]).SetOffset(br.BaseStream.Position); byte nameLength = br.ReadByte(); ((Export)m_vExports[i]).SetExportName(Encoding.UTF8.GetString(br.ReadBytes(nameLength))); } while (0x1A != br.ReadByte()) { br.ReadInt32(); } br.ReadInt32(); do { long offset = br.BaseStream.Position; byte dataType = br.ReadByte(); int dataLength = br.ReadInt32(); switch (dataType) { case 1: case 16: case 19: { var texture = new Texture(this); texture.SetOffset(offset); texture.ParseData(br); //m_vTextures.Add(texture); textureCount--; continue; } case 24: { var texture = new Texture(this); texture.SetOffset(offset); texture.ParseData(br); //m_vTextures.Add(texture); textureCount--; continue; } case 2: case 18: { var shape = new Shape(this); shape.SetOffset(offset); m_vShapes.Add(shape); shape.ParseData(br); shapeCount--; continue; } case 3: case 10: case 12: case 14: { var movieClip = new MovieClip(this, dataType); movieClip.SetOffset(offset); movieClip.ParseData(br); m_vMovieClips.Add(movieClip); movieClipCount--; continue; } case 7: case 15: case 20: case 25: { //textFields textFieldCount--; break; } case 8: { //matrix2x3 matrix2x3Count--; break; } case 9: { //colorTransform colorTransformCount--; break; } case 13: { Log("*** data type " + dataType.ToString()); break; } default: { Log("Unkown data type " + dataType.ToString()); break; } case 0: { m_vEofOffset = offset; for (int i = 0; i < m_vExports.Count; i++) { int index = m_vMovieClips.FindIndex(movie => movie.GetId() == m_vExports[i].GetId()); if (index != -1) { ((Export)m_vExports[i]).SetDataObject((MovieClip)m_vMovieClips[index]); } } Log("-----------------------------------"); Log("ShapeCount: " + shapeCount); Log("MovieClipCount: " + movieClipCount); Log("TextureCount: " + textureCount); Log("TextFieldCount: " + textFieldCount); Log("Matrix2x3Count: " + matrix2x3Count); Log("ColorTransformCount: " + colorTransformCount); return; } } //Log("Unhandled data type " + dataType.ToString()); if (dataLength >= 1) { br.ReadBytes(dataLength); } }while (true); } }
public void Decode() { using (var br = new BinaryReader(File.Open(m_vFileName, FileMode.Open))) { ushort m_vShapeCount = br.ReadUInt16();//a1 + 8 ushort m_vMovieClipCount = br.ReadUInt16();//a1 + 12 ushort m_vTextureCount = br.ReadUInt16();//a1 + 16 ushort m_vTextFieldCount = br.ReadUInt16();//a1 + 24 ushort m_vMatrix2x3Count = br.ReadUInt16();//a1 + 28 ushort m_vColorTransformCount = br.ReadUInt16();//a1 + 32 Debug.WriteLine("ShapeCount: " + m_vShapeCount); Debug.WriteLine("MovieClipCount: " + m_vMovieClipCount); Debug.WriteLine("TextureCount: " + m_vTextureCount); Debug.WriteLine("TextFieldCount: " + m_vTextFieldCount); Debug.WriteLine("Matrix2x3Count: " + m_vMatrix2x3Count); Debug.WriteLine("ColorTransformCount: " + m_vColorTransformCount); //5 useless bytes, not even used by Supercell br.ReadByte();//1 octet br.ReadUInt16();//2 octets br.ReadUInt16();//2 octets m_vStartExportsOffset = br.BaseStream.Position; m_vExportCount = br.ReadUInt16();//a1 + 20 Debug.WriteLine("ExportCount: " + m_vExportCount); for (int i = 0; i < m_vExportCount; i++) { var sce = new Export(this); sce.SetId(br.ReadInt16()); m_vExports.Add(sce); } //m_vExportNames = new string[m_vExportCount]; for (int i = 0; i < m_vExportCount; i++) { //((Export)m_vExports[i]).SetOffset(br.BaseStream.Position); byte nameLength = br.ReadByte(); ((Export)m_vExports[i]).SetExportName(Encoding.UTF8.GetString(br.ReadBytes(nameLength))); } do { long offset = br.BaseStream.Position; byte dataType = br.ReadByte(); int dataLength = br.ReadInt32(); switch (dataType) { case 1: case 16: case 19: { var texture = new Texture(this); texture.SetOffset(offset); texture.ParseData(br); m_vTextures.Add(texture); continue; } case 2: case 18: { var shape = new Shape(this); shape.SetOffset(offset); m_vShapes.Add(shape); shape.ParseData(br); continue; } case 3: case 10: case 12: case 14: { var movieClip = new MovieClip(this, dataType); movieClip.SetOffset(offset); movieClip.ParseData(br); m_vMovieClips.Add(movieClip); continue; } case 7: case 15: case 20: { //textFields break; } case 8: { //matrix2x3 break; } case 9: { //colorTransform break; } case 13: { break; } default: { Debug.WriteLine("Unkown data type " + dataType.ToString()); break; } case 0: { m_vEofOffset = offset; for (int i = 0; i < m_vExports.Count; i++) { int index = m_vMovieClips.FindIndex(movie => movie.GetId() == m_vExports[i].GetId()); if (index != -1) ((Export)m_vExports[i]).SetDataObject((MovieClip)m_vMovieClips[index]); } return; } } if (dataLength >= 1) { br.ReadBytes(dataLength); } } while (true); } }