示例#1
0
        private void B_ImportPNG_Click(object sender, EventArgs e)
        {
            using var ofd = new OpenFileDialog
                  {
                      Filter   = "PNG File|*.png",
                      FileName = "Background.png",
                  };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);

            try
            {
                bg = CGearImage.GetCGearBackground(img);
                PB_Background.Image = CGearImage.GetBitmap(bg);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                WinFormsUtil.Error(ex.Message);
            }
        }
示例#2
0
        private void B_ImportCGB_Click(object sender, EventArgs e)
        {
            using var ofd = new OpenFileDialog
                  {
                      Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk"
                  };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var path = ofd.FileName;
            var len  = new FileInfo(path).Length;

            if (len != CGearBackground.SIZE_CGB)
            {
                WinFormsUtil.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
                return;
            }

            byte[] data = File.ReadAllBytes(path);
            bg = new CGearBackground(data);
            PB_Background.Image = CGearImage.GetBitmap(bg);
        }
示例#3
0
        private void B_ImportCGB_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var len = new FileInfo(ofd.FileName).Length;

            if (len != CGearBackground.SIZE_CGB)
            {
                WinFormsUtil.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
                return;
            }

            byte[] data = File.ReadAllBytes(ofd.FileName);
            if (!CGearBackground.getIsCGB(data))
            {
                bool B2W2 = data[0x2000] != 0x00;
                data = CGearBackground.PSKtoCGB(data, B2W2);
            }

            bg = new CGearBackground(data);
            PB_Background.Image = bg.GetImage();
        }
示例#4
0
        private void B_Save_Click(object sender, EventArgs e)
        {
            byte[] bgdata = bg.Write();
            if (bgdata.SequenceEqual(new byte[CGearBackground.SIZE_CGB]))
            {
                return;
            }

            // Data present

            bgdata = CGearBackground.CGBtoPSK(bgdata, SAV.B2W2);

            Array.Copy(bgdata, 0, SAV.Data, SAV.CGearDataOffset, bgdata.Length);
            ushort chk = SaveUtil.CRC16_CCITT(bgdata);

            BitConverter.GetBytes(chk).CopyTo(SAV.Data, SAV.CGearDataOffset + bgdata.Length + 2);
            BitConverter.GetBytes(chk).CopyTo(SAV.Data, SAV.CGearDataOffset + bgdata.Length + 0x100);

            ushort skinchkval = SaveUtil.CRC16_CCITT(SAV.Data, bgdata.Length + 0x100, 4);

            BitConverter.GetBytes(skinchkval).CopyTo(SAV.Data, SAV.CGearDataOffset + bgdata.Length + 0x112);

            // Indicate in the save file that data is present
            BitConverter.GetBytes((ushort)0xC21E).CopyTo(SAV.Data, 0x19438);

            SAV.Data[SAV.CGearInfoOffset + 0x26] = 1; // data present
            BitConverter.GetBytes(chk).CopyTo(SAV.Data, SAV.CGearInfoOffset + 0x24);

            Origin.SetData(SAV.Data, 0);
            Close();
        }
示例#5
0
        private void B_Save_Click(object sender, EventArgs e)
        {
            byte[] bgdata = bg.Write();
            if (bgdata.SequenceEqual(new byte[CGearBackground.SIZE_CGB]))
            {
                return;
            }

            // Data present

            bgdata = CGearBackground.CGBtoPSK(bgdata, SAV.B2W2);

            Array.Copy(bgdata, 0, Main.SAV.Data, SAV.CGearDataOffset, bgdata.Length);
            ushort chk = SaveUtil.ccitt16(bgdata);

            BitConverter.GetBytes(chk).CopyTo(Main.SAV.Data, SAV.CGearDataOffset + bgdata.Length + 2);
            BitConverter.GetBytes(chk).CopyTo(Main.SAV.Data, SAV.CGearDataOffset + bgdata.Length + 0x100);

            byte[] skinchkdata = Main.SAV.Data.Skip(SAV.CGearDataOffset + bgdata.Length + 0x100).Take(4).ToArray();
            ushort skinchkval  = SaveUtil.ccitt16(skinchkdata);

            BitConverter.GetBytes(skinchkval).CopyTo(Main.SAV.Data, SAV.CGearDataOffset + bgdata.Length + 0x112);

            // Indicate in the save file that data is present
            BitConverter.GetBytes((ushort)0xC21E).CopyTo(Main.SAV.Data, 0x19438);



            Main.SAV.Data[SAV.CGearInfoOffset + 0x26] = 1; // data present
            BitConverter.GetBytes(chk).CopyTo(Main.SAV.Data, SAV.CGearInfoOffset + 0x24);

            Main.SAV.Edited = true;
            Close();
        }
示例#6
0
        private void B_ImportPNG_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter   = "PNG File|*.png",
                FileName = "Background.png",
            };

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Bitmap img = (Bitmap)Image.FromFile(ofd.FileName);

            try
            {
                bg = CGearExtensions.GetCGearBackground(img);
                PB_Background.Image = CGearExtensions.GetBitmap(bg);
            }
            catch (Exception ex)
            {
                WinFormsUtil.Error(ex.Message);
            }
        }
示例#7
0
        public SAV_CGearSkin(SaveFile sav)
        {
            SAV = (SAV5)(Origin = sav).Clone();
            InitializeComponent();

            byte[] data = SAV.CGearSkinData;
            bg = new CGearBackground(data);

            PB_Background.Image = CGearExtensions.GetBitmap(bg);
        }
示例#8
0
        public SAV_CGearSkin(SaveFile sav)
        {
            InitializeComponent();
            WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
            SAV = (SAV5)(Origin = sav).Clone();

            byte[] data = SAV.CGearSkinData;
            bg = new CGearBackground(data);

            PB_Background.Image = CGearImage.GetBitmap(bg);
        }
示例#9
0
        public SAV_CGearSkin()
        {
            InitializeComponent();

            SAV = (SAV5)Main.SAV.Clone();

            bool cgearPresent = SAV.Data[SAV.CGearInfoOffset + 0x26] == 1;
            bg = new CGearBackground(cgearPresent ?
                CGearBackground.PSKtoCGB(SAV.Data.Skip(SAV.CGearDataOffset).Take(CGearBackground.SIZE_CGB).ToArray(), SAV.B2W2)
                : new byte[CGearBackground.SIZE_CGB]);

            PB_Background.Image = bg.GetImage();
        }
示例#10
0
        public SAV_CGearSkin()
        {
            InitializeComponent();

            SAV = (SAV5)Main.SAV.Clone();

            bool cgearPresent = SAV.Data[SAV.CGearInfoOffset + 0x26] == 1;

            bg = new CGearBackground(cgearPresent ?
                                     CGearBackground.PSKtoCGB(SAV.Data.Skip(SAV.CGearDataOffset).Take(CGearBackground.SIZE_CGB).ToArray(), SAV.B2W2)
                : new byte[CGearBackground.SIZE_CGB]);

            PB_Background.Image = bg.GetImage();
        }
示例#11
0
        public SAV_CGearSkin()
        {
            InitializeComponent();

            SAV = (SAV5)Main.SAV.Clone();

            bool cgearPresent = SAV.Data[SAV.CGearInfoOffset + 0x26] == 1;

            bg = new CGearBackground(cgearPresent ?
                                     CGearBackground.PSKtoCGB(SAV.Data.Skip(SAV.CGearDataOffset).Take(CGearBackground.SIZE_CGB).ToArray(), SAV.B2W2)
                : new byte[CGearBackground.SIZE_CGB]);

            PB_Background.Image = bg.GetImage();
            WinFormsUtil.Alert("Editor is incomplete.", "No guarantee of functionality.");
        }
示例#12
0
        public static Bitmap GetBitmap(CGearBackground bg)
        {
            const int Width  = CGearBackground.Width;
            const int Height = CGearBackground.Height;
            Bitmap    img    = new Bitmap(Width, Height, PixelFormat.Format32bppArgb);

            // Fill Data
            using (Graphics g = Graphics.FromImage(img))
                for (int i = 0; i < bg.Map.TileChoices.Length; i++)
                {
                    int    x        = (i * 8) % Width;
                    int    y        = 8 * ((i * 8) / Width);
                    var    tile     = bg.Tiles[bg.Map.TileChoices[i] % bg.Tiles.Length];
                    var    tileData = tile.Rotate(bg.Map.Rotations[i]);
                    Bitmap b        = ImageUtil.GetBitmap(tileData, 8, 8);
                    g.DrawImage(b, new Point(x, y));
                }
            return(img);
        }
示例#13
0
        public static CGearBackground GetCGearBackground(Bitmap img)
        {
            const int Width  = CGearBackground.Width;
            const int Height = CGearBackground.Height;

            if (img.Width != Width)
            {
                throw new ArgumentException($"Invalid image width. Expected {Width} pixels wide.");
            }
            if (img.Height != Height)
            {
                throw new ArgumentException($"Invalid image height. Expected {Height} pixels high.");
            }

            // get raw bytes of image
            byte[]    data = ImageUtil.GetPixelData(img);
            const int bpp  = 4;

            Debug.Assert(data.Length == Width * Height * bpp);

            return(CGearBackground.GetBackground(data, bpp));
        }
示例#14
0
        private void B_ImportCGB_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog
            {
                Filter = CGearBackground.Filter + "|PokeStock C-Gear Skin|*.psk"
            };

            if (ofd.ShowDialog() != DialogResult.OK)
                return;

            var len = new FileInfo(ofd.FileName).Length;
            if (len != CGearBackground.SIZE_CGB)
            {
                WinFormsUtil.Error($"Incorrect size, got {len} bytes, expected {CGearBackground.SIZE_CGB} bytes.");
                return;
            }

            byte[] data = File.ReadAllBytes(ofd.FileName);
            if (!CGearBackground.getIsCGB(data))
            {
                bool B2W2 = data[0x2000] != 0x00;
                data = CGearBackground.PSKtoCGB(data, B2W2);
            }

            bg = new CGearBackground(data);
            PB_Background.Image = bg.GetImage();
        }
示例#15
0
 public static Bitmap GetBitmap(CGearBackground bg)
 {
     return(ImageUtil.GetBitmap(bg.GetImageData(), CGearBackground.Width, CGearBackground.Height));
 }