Ejemplo n.º 1
0
        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            dsig = new sDSIG();

            dsig.id   = br.ReadChars(4);
            dsig.type = br.ReadByte();
            if (dsig.type != 0x02)
            {
                dsig.unk4 = br.ReadByte();
            }
            dsig.num_colors = br.ReadByte(); // Number of palettes of 16 colors
            dsig.unk1       = br.ReadByte();
            dsig.unk2       = br.ReadUInt16();
            dsig.unk3       = br.ReadUInt16();

            ColorFormat depth = (dsig.unk1 == 0 ? ColorFormat.colors16 : ColorFormat.colors256);

            if (dsig.unk1 != 0)
            {
                System.Windows.Forms.MessageBox.Show("Found different depth!");
            }
            TileForm form = (dsig.unk4 == 0x10 ? TileForm.Horizontal : TileForm.Lineal);

            Color[] colors = Actions.BGR555ToColor(br.ReadBytes(dsig.num_colors * 2));
            palette = new RawPalette(colors, false, depth, FileName);

            byte[] tiles = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
            Set_Tiles(tiles, 0x100, 0xc0, depth, form, false);

            br.Close();
        }
Ejemplo n.º 2
0
 public RawImage(byte[] tiles, TileForm form, ColorFormat format, int width, int height,
     bool editable, string fileName = "")
     : base()
 {
     this.fileName = fileName;
     Set_Tiles(tiles, width, height, format, form, editable);
 }
Ejemplo n.º 3
0
        private void btnExtract_Click(object sender, EventArgs e)
        {
            string folder;
            FolderBrowserDialog o = new FolderBrowserDialog();

            o.Description         = "Select the folder where you want\nto extract all the images.";
            o.ShowNewFolderButton = true;
            if (o.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            folder = o.SelectedPath + Path.DirectorySeparatorChar;

            SpriteBase sprite = pluginHost.Get_Sprite();

            this.Cursor = Cursors.WaitCursor;
            for (int i = 0; i < infos.Length; i++)
            {
                int      offset = (int)infos[i].offset;
                int      size   = (int)infos[i].size;
                TileForm form   = (images.EndsWith("Tex.dat") ? TileForm.Lineal : TileForm.Horizontal);

                RawImage image = new RawImage(images, -1, form, ColorFormat.colors256, false,
                                              offset + 0x220, size - 0x220);

                RawPalette palette = new RawPalette(images, -1, false,
                                                    offset + 0x20, 0x200);

                sprite.Get_Image(image, palette, 0, 512, 256, false, false, false, true, true).Save(folder + "Image" + i.ToString() + ".png");
            }
            this.Cursor = Cursors.Default;
        }
Ejemplo n.º 4
0
 public RawImage(byte[] tiles, TileForm form, ColorFormat format, int width, int height,
                 bool editable, string fileName = "")
     : base()
 {
     this.fileName = fileName;
     Set_Tiles(tiles, width, height, format, form, editable);
 }
Ejemplo n.º 5
0
 int GetRequireAPFromTileType(TileForm type)
 {
     if (type == TileForm.Flatland)
     {
         // USING ONLY TEST
         return(EditInfo.RequireApAtFlatland);
         // return 3;
     }
     else if (type == TileForm.Hill)
     {
         // USING ONLY TEST
         return(EditInfo.RequireApAtHill);
         // return 5;
     }
     else if (type == TileForm.Water)
     {
         return(9999);
     }
     else if (type == TileForm.HigherHill)
     {
         return(EditInfo.RequireApAtHigherHill);
     }
     else if (type == TileForm.Cliff)
     {
         return(9999);
     }
     else
     {
         Debug.Log("Invaild tiletype : " + type.ToString());
         return(1);
     }
 }
Ejemplo n.º 6
0
                public Header(BinaryReader br)
                {
                    var magicNumber = br.ReadMagicNumber();

                    if (magicNumber != MagicNumber)
                    {
                        throw new InvalidDataException($"Unexpected magic number '{magicNumber}'. (expected: {MagicNumber})");
                    }

                    TotalLength    = br.ReadUInt32();
                    TilesPerColumn = br.ReadUInt16();
                    TilesPerRow    = br.ReadUInt16();
                    BitsPerPixel   = (BitsPerPixel)br.ReadUInt32();
                    Unknown1       = br.ReadUInt16();
                    Unknown2       = br.ReadUInt16();
                    TiledFlag      = br.ReadUInt32();
                    if ((TiledFlag & 0xFF) == 0x0)
                    {
                        Order = TileForm.Horizontal;
                    }
                    else
                    {
                        Order = TileForm.Lineal;
                    }
                    DataLength = br.ReadInt32();
                    Unknown3   = br.ReadUInt32();
                }
Ejemplo n.º 7
0
    public void SetTileInfo(TileForm form, Element element)
    {
        string imageName = form.ToString() + "_" + element.ToString();
        string imagePath = "TileImage/" + imageName;

        GetComponent <SpriteRenderer>().sprite = Resources.Load(imagePath, typeof(Sprite)) as Sprite;

        SetTileForm(form);
        SetTileElement(element);
    }
Ejemplo n.º 8
0
        public RawImage(String file, int id, TileForm form, ColorFormat format,
            bool editable, int offset, int size, string fileName = "")
            : base()
        {
            this.id = id;
            if (fileName == "")
                this.fileName = Path.GetFileName(file);
            else
                this.fileName = fileName;

            Read(file, form, format, editable, offset, size);
        }
Ejemplo n.º 9
0
        public RawImage(String file, int id, TileForm form, ColorFormat format,
                        bool editable, int offset, int size, string fileName = "") : base()
        {
            this.id = id;
            if (fileName == "")
            {
                this.fileName = Path.GetFileName(file);
            }
            else
            {
                this.fileName = fileName;
            }

            Read(file, form, format, editable, offset, size);
        }
Ejemplo n.º 10
0
        public void Set_Tiles(Byte[] tiles, int width, int height, ColorFormat format,
                              TileForm form, bool editable, int tile_size = 8)
        {
            this.tiles     = tiles;
            this.format    = format;
            this.tileForm  = form;
            this.canEdit   = editable;
            this.tile_size = tile_size;

            Width  = width;
            Height = height;

            zoom = 1;
            //startByte = 0;
            loaded = true;

            bpp = 8;
            if (format == Images.ColorFormat.colors16)
            {
                bpp = 4;
            }
            else if (format == Images.ColorFormat.colors2)
            {
                bpp = 1;
            }
            else if (format == Images.ColorFormat.colors4)
            {
                bpp = 2;
            }
            else if (format == Images.ColorFormat.direct)
            {
                bpp = 16;
            }
            else if (format == Images.ColorFormat.BGRA32 || format == Images.ColorFormat.ABGR32)
            {
                bpp = 32;
            }

            tilePal = new byte[tiles.Length * (tile_size / bpp)];

            // Get the original data for changes in startByte
            original = (byte[])tiles.Clone();
        }
Ejemplo n.º 11
0
        private void numImg_ValueChanged(object sender, EventArgs e)
        {
            int      offset = (int)infos[(int)numImg.Value].offset;
            int      size   = (int)infos[(int)numImg.Value].size;
            TileForm form   = (images.EndsWith("Tex.dat") ? TileForm.Lineal : TileForm.Horizontal);

            RawImage image = new RawImage(images, -1, form, ColorFormat.colors256, false,
                                          offset + 0x220, size - 0x220);

            pluginHost.Set_Image(image);

            RawPalette palette = new RawPalette(images, -1, false,
                                                offset + 0x20, 0x200);

            pluginHost.Set_Palette(palette);

            this.Controls.Remove(spriteControl1);
            spriteControl1 = new SpriteControl(pluginHost);
            this.Controls.Add(spriteControl1);
        }
Ejemplo n.º 12
0
        public void Set_Tiles(ImageBase new_img)
        {
            this.tiles     = new_img.Tiles;
            this.format    = new_img.FormatColor;
            this.tileForm  = new_img.FormTile;
            this.tile_size = new_img.tile_size;

            Width  = new_img.Width;
            Height = new_img.Height;

            zoom      = 1;
            startByte = 0;
            loaded    = true;

            bpp = 8;
            if (format == Images.ColorFormat.colors16)
            {
                bpp = 4;
            }
            else if (format == Images.ColorFormat.colors2)
            {
                bpp = 1;
            }
            else if (format == Images.ColorFormat.colors4)
            {
                bpp = 2;
            }
            else if (format == Images.ColorFormat.direct)
            {
                bpp = 16;
            }
            else if (format == Images.ColorFormat.BGRA32 || format == Images.ColorFormat.ABGR32)
            {
                bpp = 32;
            }

            tilePal = new byte[tiles.Length * (tile_size / bpp)];

            // Get the original data for changes in startByte
            original = (byte[])tiles.Clone();
        }
Ejemplo n.º 13
0
    void GenerateTile(TileInfo tileInfo)
    {
        if (tileInfo.IsEmptyTile())
        {
            return;
        }

        Vector2  tilePosition = tileInfo.GetTilePosition();
        TileForm tileForm     = tileInfo.GetTileForm();
        Element  tileElement  = tileInfo.GetTileElement();

        int j = (int)tilePosition.y;
        int i = (int)tilePosition.x;

        GameObject tile = Instantiate(tilePrefab, new Vector3(tileWidth * (j + i) * 0.5f, tileHeight * (j - i) * 0.5f, (j - i) * 0.1f), Quaternion.identity) as GameObject;

        tile.GetComponent <Tile>().SetTilePos(i, j);
        tile.GetComponent <Tile>().SetTileInfo(tileForm, tileElement);

        tiles.Add(new Vector2(i, j), tile);
    }
Ejemplo n.º 14
0
        public void Read(string fileIn, TileForm form, ColorFormat format, bool editable,
                         int offset, int fileSize)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));

            prev_data = br.ReadBytes(offset);

            if (fileSize <= offset)
            {
                fileSize = (int)br.BaseStream.Length;
            }
            if (fileSize + offset >= br.BaseStream.Length)
            {
                offset = (int)br.BaseStream.Length - fileSize;
            }
            if (fileSize <= offset)
            {
                fileSize = (int)br.BaseStream.Length;
            }

            ori_data  = br.ReadBytes(fileSize);
            post_data = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));

            br.BaseStream.Position = offset;

            // Read the tiles
            Byte[] tiles = br.ReadBytes(fileSize);
            br.Close();

            Set_Tiles(tiles, 0x0100, 0x00C0, format, form, editable);

            Size size = Actions.Get_Size(fileSize, BPP);

            Width  = size.Width;
            Height = size.Height;
        }
Ejemplo n.º 15
0
 public ImageBase(Byte[] tiles, int width, int height, ColorFormat format,
     TileForm tileForm, bool editable, string fileName = "")
 {
     this.fileName = fileName;
     Set_Tiles(tiles, width, height, format, tileForm, editable);
 }
Ejemplo n.º 16
0
        public void Set_Tiles(ImageBase new_img)
        {
            this.tiles = new_img.Tiles;
            this.format = new_img.FormatColor;
            this.tileForm = new_img.FormTile;
            this.tile_size = new_img.tile_size;

            Width = new_img.Width;
            Height = new_img.Height;

            zoom = 1;
            startByte = 0;
            loaded = true;

            bpp = 8;
            if (format == Images.ColorFormat.colors16)
                bpp = 4;
            else if (format == Images.ColorFormat.colors2)
                bpp = 1;
            else if (format == Images.ColorFormat.colors4)
                bpp = 2;
            else if (format == Images.ColorFormat.direct)
                bpp = 16;
            else if (format == Images.ColorFormat.BGRA32 || format == Images.ColorFormat.ABGR32)
                bpp = 32;

            tilePal = new byte[tiles.Length * (tile_size / bpp)];

            // Get the original data for changes in startByte
            original = (byte[])tiles.Clone();
        }
Ejemplo n.º 17
0
        public void Set_Tiles(Byte[] tiles, int width, int height, ColorFormat format,
            TileForm form, bool editable, int tile_size = 8)
        {
            this.tiles = tiles;
            this.format = format;
            this.tileForm = form;
            this.canEdit = editable;
            this.tile_size = tile_size;

            Width = width;
            Height = height;

            zoom = 1;
            //startByte = 0;
            loaded = true;

            bpp = 8;
            if (format == Images.ColorFormat.colors16)
                bpp = 4;
            else if (format == Images.ColorFormat.colors2)
                bpp = 1;
            else if (format == Images.ColorFormat.colors4)
                bpp = 2;
            else if (format == Images.ColorFormat.direct)
                bpp = 16;
            else if (format == Images.ColorFormat.BGRA32 || format == Images.ColorFormat.ABGR32)
                bpp = 32;

            tilePal = new byte[tiles.Length * (tile_size / bpp)];

            // Get the original data for changes in startByte
            original = (byte[])tiles.Clone();
        }
Ejemplo n.º 18
0
 public void SetTileForm(TileForm form)
 {
     this.form = form;
 }
Ejemplo n.º 19
0
    public TileInfo(Vector2 tilePosition, string tileInfoString)
    {
        if (tileInfoString[0] == '-')
        {
            this.isEmptyTile = true;
            return;
        }

        this.isEmptyTile = false;

        char tileFormChar = tileInfoString[0];

        this.tilePosition = tilePosition;

        if (tileFormChar == 'F')
        {
            this.tileForm = TileForm.Flatland;
        }
        else if (tileFormChar == 'H')
        {
            this.tileForm = TileForm.Hill;
        }
        else if (tileFormChar == 'C')
        {
            this.tileForm = TileForm.Cliff;
        }
        else if (tileFormChar == 'I')
        {
            this.tileForm = TileForm.HigherHill;
        }
        else if (tileFormChar == 'W')
        {
            this.tileForm = TileForm.Water;
        }
        else
        {
            Debug.LogError("Undefined tileForm: <" + tileFormChar + ">" + " at " + tilePosition);
        }

        if (tileInfoString.Length < 2)
        {
            this.tileElement = Element.None;
            return;
        }

        char tileElementChar = tileInfoString[1];

        if (tileElementChar == 'F')
        {
            this.tileElement = Element.Fire;
        }
        else if (tileElementChar == 'W')
        {
            this.tileElement = Element.Water;
        }
        else if (tileElementChar == 'P')
        {
            this.tileElement = Element.Plant;
        }
        else if (tileElementChar == 'M')
        {
            this.tileElement = Element.Metal;
        }
        else
        {
            Debug.LogError("Undefined tileType: <" + tileElement + ">" + " at " + tilePosition);
        }
    }
Ejemplo n.º 20
0
 public ImageBase(Byte[] tiles, int width, int height, ColorFormat format,
                  TileForm tileForm, bool editable, string fileName = "")
 {
     this.fileName = fileName;
     Set_Tiles(tiles, width, height, format, tileForm, editable);
 }
Ejemplo n.º 21
0
        public void Read(string fileIn, TileForm form, ColorFormat format, bool editable,
            int offset, int fileSize)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            prev_data = br.ReadBytes(offset);

            if (fileSize <= offset)
                fileSize = (int)br.BaseStream.Length;
            if (fileSize + offset >= br.BaseStream.Length)
                offset = (int)br.BaseStream.Length - fileSize;
            if (fileSize <= offset)
                fileSize = (int)br.BaseStream.Length;

            ori_data = br.ReadBytes(fileSize);
            post_data = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));

            br.BaseStream.Position = offset;

            // Read the tiles
            Byte[] tiles = br.ReadBytes(fileSize);
            br.Close();

            Set_Tiles(tiles, 0x0100, 0x00C0, format, form, editable);

            Size size = Actions.Get_Size(fileSize, BPP);
            Width = size.Width;
            Height = size.Height;
        }