Example #1
0
        public MovieClip(MovieClip mv)
        {
            _scFile   = mv.GetStorageObject();
            _dataType = mv.GetMovieClipDataType();
            _shapes   = new List <ScObject>();

            this.SetOffset(-Math.Abs(mv.GetOffset()));

            //Duplicate MovieClip
            using (FileStream input = new FileStream(_scFile.GetInfoFileName(), FileMode.Open))
            {
                input.Seek(Math.Abs(mv.GetOffset()), SeekOrigin.Begin);
                using (var br = new BinaryReader(input))
                {
                    var packetId   = br.ReadByte().ToString("X2");
                    var packetSize = br.ReadUInt32();
                    this.Read(br, packetId);
                }
            }

            //Set new clip id
            ushort maxMovieClipId = this.Id;

            foreach (MovieClip clip in _scFile.GetMovieClips())
            {
                if (clip.Id > maxMovieClipId)
                {
                    maxMovieClipId = clip.Id;
                }
            }
            maxMovieClipId++;
            this.SetId(maxMovieClipId);

            //Get max shape id
            ushort maxShapeId = 30000; //avoid collision with other objects in MovieClips

            foreach (Shape shape in _scFile.GetShapes())
            {
                if (shape.Id > maxShapeId)
                {
                    maxShapeId = shape.Id;
                }
            }
            maxShapeId++;

            //Duplicate shapes associated to clip
            List <ScObject> newShapes = new List <ScObject>();

            foreach (Shape s in _shapes)
            {
                Shape newShape = new Shape(s);
                newShape.SetId(maxShapeId);
                maxShapeId++;
                newShapes.Add(newShape);

                _scFile.AddShape(newShape); //Add to global shapelist
                _scFile.AddChange(newShape);
            }
            this._shapes = newShapes;
        }
Example #2
0
        public void Load()
        {
            var sw = Stopwatch.StartNew();

            while (true)
            {
                using (var texReader = new BinaryReader(File.OpenRead(_textureFile)))
                {
                    Byte[] IsCompressed = texReader.ReadBytes(2);
                    if (BitConverter.ToString(IsCompressed) == "53-43")
                    {
                        texReader.BaseStream.Seek(26, SeekOrigin.Begin);
                        DialogResult result =
                            MessageBox.Show("The tool detected that you have load a compressed file.\nWould you like to decompress and load it?\nPlease note,Choosing to decompressed will override the compressed file with a new one",
                                            "SC File Is Compresed", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                        if (result == DialogResult.Yes)
                        {
                            string IsSc = BitConverter.ToString(texReader.ReadBytes(2));
                            texReader.Close();
                            if (IsSc == "53-43")
                            {
                                Lzham.DecompressSc(_textureFile);
                            }
                            else
                            {
                                Lzma.Decompress(_textureFile);
                            }
                            continue;
                        }
                        break;
                    }

                    Console.WriteLine(texReader.BaseStream.Length);
                    texReader.BaseStream.Seek(0, SeekOrigin.Begin);
                    while (true)
                    {
                        long texoffset  = texReader.BaseStream.Position;
                        var  packetId   = texReader.ReadByte();
                        var  packetSize = texReader.ReadUInt32();
                        if (packetSize > 0)
                        {
                            var tex = new Texture(this);
                            tex.SetOffset(texoffset);
                            tex.Read(packetId, packetSize, texReader);
                            this._textures.Add(tex);
                            if (texReader.BaseStream.Position != texReader.BaseStream.Length)
                            {
                                continue;
                            }
                        }
                        _eofTexOffset = texoffset;
                        break;
                    }
                }
                break;
            }

            while (true)
            {
                using (var reader = new BinaryReader(File.OpenRead(_infoFile)))
                {
                    Byte[] IsCompressed = reader.ReadBytes(2);
                    Console.WriteLine(BitConverter.ToString(IsCompressed) == "53-43");
                    if (BitConverter.ToString(IsCompressed) == "53-43")
                    {
                        reader.BaseStream.Seek(26, SeekOrigin.Begin);
                        DialogResult result = MessageBox.Show("The tool detected that you have load a compressed file.\nWould you like to decompress and load it?\nPlease note,Choosing to decompressed will override the compressed file with a new one",
                                                              @"SC File Is Compresed", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2);

                        if (result == DialogResult.Yes)
                        {
                            string IsSc = BitConverter.ToString(reader.ReadBytes(2));
                            reader.Close();
                            if (IsSc == "53-43")
                            {
                                Lzham.DecompressSc(_infoFile);
                            }
                            else
                            {
                                Lzma.Decompress(_infoFile);
                            }
                            continue;
                        }
                        break;
                    }

                    reader.BaseStream.Seek(0, SeekOrigin.Begin);
                    var shapeCount          = reader.ReadUInt16(); // a1 + 8
                    var movieClipCount      = reader.ReadUInt16(); // a1 + 12
                    var textureCount        = reader.ReadUInt16(); // a1 + 16
                    var textFieldCount      = reader.ReadUInt16(); // a1 + 24
                    var matrixCount         = reader.ReadUInt16(); // a1 + 28
                    var colorTransformCount = reader.ReadUInt16(); // a1 + 32

                    int colorTransfromID = 0;

#if DEBUG
                    Console.WriteLine(@"ShapeCount: " + shapeCount);
                    Console.WriteLine(@"MovieClipCount: " + movieClipCount);
                    Console.WriteLine(@"TextureCount: " + textureCount);
                    Console.WriteLine(@"TextFieldCount: " + textFieldCount);
                    Console.WriteLine(@"Matrix2x3Count: " + matrixCount);
                    Console.WriteLine(@"ColorTransformCount: " + colorTransformCount);
#endif
                    // 5 useless bytes, not even used by Supercell
                    reader.ReadByte();   // 1 octet
                    reader.ReadUInt16(); // 2 octets
                    reader.ReadUInt16(); // 2 octets

                    _exportStartOffset = reader.BaseStream.Position;
                    _exportCount       = reader.ReadUInt16(); // a1 + 20
                    Console.WriteLine(@"ExportCount: " + _exportCount);

                    // Reads the Export IDs.
                    for (int i = 0; i < _exportCount; i++)
                    {
                        var export = new Export(this);
                        export.SetId(reader.ReadUInt16());
                        _exports.Add(export);
                    }

                    // Reads the Export names.
                    for (int i = 0; i < _exportCount; i++)
                    {
                        var nameLength = reader.ReadByte();
                        var name       = Encoding.UTF8.GetString(reader.ReadBytes(nameLength));
                        var export     = (Export)_exports[i];
                        export.SetExportName(name);
                    }

                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        long offset = reader.BaseStream.Position;

                        var datatag = reader.ReadByte();
                        var tag     = datatag.ToString("X2"); //Block type
                        var tagSize = reader.ReadUInt32();    //Size in bytes
#if DEBUG
                        //Console.WriteLine("dataBlockTag: " + tag);
                        //Console.WriteLine("dataBlockSize: " + tagSize);
#endif
                        switch (tag)
                        {
                        default:
                            //Console.WriteLine("dataBlockTag: " + tag);
                            //Console.WriteLine("dataBlockSize: " + tagSize);
                            var defaultDataBlockContent = reader.ReadBytes(Convert.ToInt32(tagSize));
                            defaultDataBlockContent = null;
                            break;

                        case "00":
                            _eofOffset = offset;
                            foreach (ScObject t in _exports)
                            {
                                int index = _movieClips.FindIndex(movie => movie.Id == t.Id);
                                if (index != -1)
                                {
                                    ((Export)t).SetDataObject((MovieClip)_movieClips[index]);
                                }
                            }
                            break;

                        case "01":
                        case "18":
                            if (tagSize > 6)
                            {
                                var texture = new Texture(this);
                                texture.SetOffset(offset);
                                texture.Read(UInt32.Parse(tag), tagSize, reader);
                                //_eofTexOffset = reader.BaseStream.Position;
                                this._textures.Add(texture);
                            }
                            else
                            {
                                var pixelFormat = reader.ReadByte();
                                var width       = reader.ReadUInt16();
                                var height      = reader.ReadUInt16();

                                Console.WriteLine("pixelFormat: " + pixelFormat);
                                Console.WriteLine("width: " + width);
                                Console.WriteLine("height: " + height);
                            }
                            break;

                        case "02":
                        case "12":
                            var shape = new Shape(this);
                            shape.SetOffset(offset);
                            shape.Read(reader, tag);
                            this._shapes.Add(shape);
                            break;

                        case "03":
                        case "0C":
                            var movieClip = new MovieClip(this, datatag);
                            movieClip.SetOffset(offset);
                            movieClip.Read(reader, tag);
                            _movieClips.Add(movieClip);
                            break;

                        case "08":
                            float[] Points = new float[6];
                            for (int Index = 0; Index < 6; Index++)
                            {
                                Points[Index] = reader.ReadInt32();
                            }
                            Matrix _Matrix = new Matrix(Points[0] / 1024, Points[1] / 1024, Points[2] / 1024,
                                                        Points[3] / 1024, Points[4] / -20, Points[5] / -20);
                            this._matrixs.Add(_Matrix);
                            //Console.WriteLine("\t matrixVal: " + Points[0] / 1024 + "\n\t matrixVal: " + Points[1] / 1024 + "\n\t matrixVal: " + Points[2] / 1024 + "\n\t matrixVal: " + Points[3] / 1024 + "\n\t matrixVal: " + Points[4] / -20 + "\n\t matrixVal: " + Points[5] / -20);
                            break;

                        case "09":
                            var ra = reader.ReadByte();
                            var ga = reader.ReadByte();
                            var ba = reader.ReadByte();
                            var am = reader.ReadByte();
                            var rm = reader.ReadByte();
                            var gm = reader.ReadByte();
                            var bm = reader.ReadByte();
                            this._colors.Add(new Tuple <Color, byte, Color>(Color.FromArgb(ra, ga, ba), am, Color.FromArgb(rm, gm, bm)));
                            //int id = this._colors.Count - 1;
                            //Console.WriteLine("\t -ct-" + id + "--ColorA: rgb(" + this._colors[id].Item1.R + "," + this._colors[id].Item1.G + "," + this._colors[id].Item1.B + ") & " + this._colors[id].Item2 + " & rgb(" + this._colors[id].Item3.R + "," + this._colors[id].Item3.G + "," + this._colors[id].Item3.B + ")");
                            break;
                        }
                    }

                    sw.Stop();
                    Program.Interface.Text = $@"Royale Editor :  {Path.GetFileNameWithoutExtension(_textureFile)}";
                    Program.Interface.Update();
                    Console.WriteLine(@"SC File loading finished in {0}ms", sw.Elapsed.TotalMilliseconds);
                }
                break;
            }
        }
Example #3
0
 public void AddMovieClip(MovieClip movieClip)
 {
     _movieClips.Add(movieClip);
 }
Example #4
0
 public void SetDataObject(MovieClip sd)
 {
     _dataObject = sd;
 }