示例#1
0
        private void SaveTileset_Click(object sender, EventArgs e)
        {
            Button SaveTilesetButton = (Button)sender;

            if (SaveTilesetButton.Name == "cmdSaveMajor")
            {
                MajorTileset.LZ77Compressed = (chkLZ771.Checked == true) ? (byte)1 : (byte)0;
                MajorTileset.MajorTileset   = (chkMajorTileset1.Checked == true) ? (byte)0 : (byte)1;
                MajorTileset.Image          = Convert.ToUInt32(txtImage1.Text, HEX);
                MajorTileset.Palette        = Convert.ToUInt32(txtPalette1.Text, HEX);
                MajorTileset.BlockData      = Convert.ToUInt32(txtBlocks1.Text, HEX);
                MajorTileset.BehaviourData  = Convert.ToUInt32(txtBehaviours1.Text, HEX);
                MajorTileset.Animation      = Convert.ToUInt32(txtAnimation1.Text, HEX);

                Tilesets.Save(CurrentROM, CurrentMap.MajorTileset - 0x8000000, MajorTileset);
            }
            else
            {
                MinorTileset.LZ77Compressed = (chkLZ772.Checked == true) ? (byte)1 : (byte)0;
                MinorTileset.MajorTileset   = (chkMajorTileset2.Checked == true) ? (byte)0 : (byte)1;
                MinorTileset.Image          = Convert.ToUInt32(txtImage2.Text, HEX);
                MinorTileset.Palette        = Convert.ToUInt32(txtPalette2.Text, HEX);
                MinorTileset.BlockData      = Convert.ToUInt32(txtBlocks2.Text, HEX);
                MinorTileset.BehaviourData  = Convert.ToUInt32(txtBehaviours2.Text, HEX);
                MinorTileset.Animation      = Convert.ToUInt32(txtAnimation2.Text, HEX);

                Tilesets.Save(CurrentROM, CurrentMap.MinorTileset - 0x8000000, MinorTileset);
            }

            // Refresh tileset and map
            DrawMap();
        }
示例#2
0
        private void DrawMap()
        {
            int Width  = (int)CurrentMap.Width * 16;
            int Height = (int)CurrentMap.Height * 16;

            TilesetImage     = Tilesets.Render(CurrentROM, MajorTileset, MinorTileset, CurrentMap);
            picTileset.Image = TilesetImage;

            MapImage      = new Bitmap(Width, Height);
            AttributeMap  = new Bitmap(Width, Height);
            FinalMapImage = new Bitmap(Width, Height);

            MapGraphics       = Graphics.FromImage(MapImage);
            AttributeGraphics = Graphics.FromImage(AttributeMap);
            FinalGraphics     = Graphics.FromImage(FinalMapImage);

            CurrentMap.MapTileData = Maps.RenderMap(CurrentROM, MapImage, TilesetImage, AttributeMap, AttributeBlocks, CurrentMap);
            //Maps.RenderAttributes(AttributeMap, AttributeBlocks, CurrentMap);
            picMap.Image = MapImage;

            BorderImage    = new Bitmap(CurrentMap.BorderWidth * 16, CurrentMap.BorderHeight * 16);
            BorderGraphics = Graphics.FromImage(BorderImage);

            CurrentMap.BorderData = Maps.RenderBorder(CurrentROM, BorderGraphics, TilesetImage, CurrentMap);
            picBorder.Image       = BorderImage;
        }
示例#3
0
        private static Bitmap RenderMap(ROM CurrentROM, Map map)
        {
            int Width  = (int)map.Width * 16;
            int Height = (int)map.Height * 16;

            Tileset majorTileset = Tilesets.Load(CurrentROM, map.MajorTileset - 0x8000000, CurrentROM.TilesetHeader);
            Tileset minorTileset = Tilesets.Load(CurrentROM, map.MinorTileset - 0x8000000, CurrentROM.TilesetHeader);
            Bitmap  TilesetImage = Tilesets.Render(CurrentROM, majorTileset, minorTileset, map);

            Bitmap MapImage      = new Bitmap(Width, Height);
            Bitmap AttributeMap  = new Bitmap(Width, Height);
            Bitmap FinalMapImage = new Bitmap(Width, Height);

            map.MapTileData = Maps.RenderMap(CurrentROM, MapImage, TilesetImage, map);
            return(MapImage);
        }
示例#4
0
        private void LoadHeader()
        {
            txtBank.Text      = Convert.ToString(CurrentMap.MapBankOffset, HEX);
            txtMapHeader.Text = Convert.ToString(CurrentMap.MapHeaderOffset, HEX);

            txtMapData.Text     = Convert.ToString(CurrentMap.LayoutData, HEX);
            txtEvents.Text      = Convert.ToString(CurrentMap.EventData, HEX);
            txtMapScripts.Text  = Convert.ToString(CurrentMap.MapScripts, HEX);
            txtConnections.Text = Convert.ToString(CurrentMap.ConnectionData, HEX);

            txtBorderData.Text   = Convert.ToString(CurrentMap.Border, HEX);
            txtMapTileData.Text  = Convert.ToString(CurrentMap.MapData, HEX);
            txtMajorTileset.Text = Convert.ToString(CurrentMap.MajorTileset, HEX);
            txtMinorTileset.Text = Convert.ToString(CurrentMap.MinorTileset, HEX);

            MajorTileset             = Tilesets.Load(CurrentROM, CurrentMap.MajorTileset - 0x8000000, CurrentROM.TilesetHeader); // Load major tileset
            MinorTileset             = Tilesets.Load(CurrentROM, CurrentMap.MinorTileset - 0x8000000, CurrentROM.TilesetHeader); // Load minor tileset
            chkLZ771.Checked         = (MajorTileset.LZ77Compressed == 1);
            chkLZ772.Checked         = (MinorTileset.LZ77Compressed == 1);
            chkMajorTileset1.Checked = (MajorTileset.MajorTileset == 0);
            chkMajorTileset2.Checked = (MinorTileset.MajorTileset == 0);
            txtImage1.Text           = Convert.ToString(MajorTileset.Image, HEX);
            txtImage2.Text           = Convert.ToString(MinorTileset.Image, HEX);
            txtPalette1.Text         = Convert.ToString(MajorTileset.Palette, HEX);
            txtPalette2.Text         = Convert.ToString(MinorTileset.Palette, HEX);
            txtBlocks1.Text          = Convert.ToString(MajorTileset.BlockData, HEX);
            txtBlocks2.Text          = Convert.ToString(MinorTileset.BlockData, HEX);
            txtBehaviours1.Text      = Convert.ToString(MajorTileset.BehaviourData, HEX);
            txtBehaviours2.Text      = Convert.ToString(MinorTileset.BehaviourData, HEX);
            txtAnimation1.Text       = Convert.ToString(MajorTileset.Animation, HEX);
            txtAnimation2.Text       = Convert.ToString(MinorTileset.Animation, HEX);

            bool BorderSupport = (CurrentROM.GameCode.Substring(0, 3) == "BPR" || CurrentROM.GameCode.Substring(0, 3) == "BPG");

            fraBorder.Visible = BorderSupport;
            if (BorderSupport)
            {
                txtBorderWidth.Text  = CurrentMap.BorderWidth.ToString();
                txtBorderHeight.Text = CurrentMap.BorderHeight.ToString();
            }
        }
示例#5
0
        private void cmdChange_Click(object sender, EventArgs e)
        {
            uint[] TilesetNumber = new uint[2];

            try
            {
                TilesetNumber[0] = Convert.ToUInt32(txtMajor.Text, DEC);
                TilesetNumber[1] = Convert.ToUInt32(txtMinor.Text, DEC);
            }
            catch (OverflowException) // Catch overflow exception
            {
                if (TaskDialogSupported)
                {
                    TaskDialog.Show(this, "The tileset number you have entered is invalid.\nThis is because the tileset number is either too big or too small.", "Overflow error - Invalid tileset number!", Application.ProductName, TaskDialogButtons.OK, TaskDialogIcon.Warning);
                }
                else
                {
                    MessageBox.Show("Overflow error - Invalid tileset number!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                txtMajor.Text = MajorTileset.Number.ToString(); // Default values
                txtMinor.Text = MinorTileset.Number.ToString();
                return;
            }

            for (int i = 0; i < 2; i++)
            {
                TilesetNumber[i] = (TilesetNumber[i] * 0x18) + CurrentROM.TilesetHeader;

                if (TilesetNumber[i] > 0xFFFFFF && CurrentROM.EnlargedROM == false)
                {
                    if (TaskDialogSupported)
                    {
                        TaskDialog.Show(this, "The tileset number you have entered is invalid.\nThis means it is pointing at a location that is beyond the size of this ROM.", "End of file error - Invalid tileset number!", Application.ProductName, TaskDialogButtons.OK, TaskDialogIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show("End of file error - Invalid tileset number!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    txtMajor.Text = MajorTileset.Number.ToString(); // Default values
                    txtMinor.Text = MinorTileset.Number.ToString();
                    return;
                }

                BinaryReader ReadROM = new BinaryReader(File.Open(CurrentROM.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));
                ReadROM.BaseStream.Position = TilesetNumber[i] + 2;

                ushort Filler  = ReadROM.ReadUInt16();
                uint   Image   = ReadROM.ReadUInt32();
                uint   Palette = ReadROM.ReadUInt32();
                uint   Block   = ReadROM.ReadUInt32();

                ReadROM.Close();

                if (Filler != 0 || Image < 0x8000000 || Palette < 0x8000000 || Block < 0x8000000) // Check if valid tileset
                {
                    if (TaskDialogSupported)
                    {
                        TaskDialog.Show(this, "The tileset number you have entered is invalid. This means at that location there are no tileset data to read from or the structure is incorrect.", "Error - Invalid tileset number!", Application.ProductName, TaskDialogButtons.OK, TaskDialogIcon.Warning);
                    }
                    else
                    {
                        MessageBox.Show("Error - Invalid tileset number!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    txtMajor.Text = MajorTileset.Number.ToString(); // Default values
                    txtMinor.Text = MinorTileset.Number.ToString();
                    return;
                }
            }

            BinaryWriter WriteROM = new BinaryWriter(File.Open(CurrentROM.FilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite));

            WriteROM.BaseStream.Position = CurrentMap.LayoutData + 16 - 0x8000000; // Write to ROM
            WriteROM.Write(TilesetNumber[0] + 0x8000000);
            WriteROM.Write(TilesetNumber[1] + 0x8000000);
            WriteROM.Close();

            CurrentMap.MajorTileset = TilesetNumber[0] + 0x8000000; // Assign new tilesets to the current map
            CurrentMap.MinorTileset = TilesetNumber[1] + 0x8000000;

            MajorTileset = Tilesets.Load(CurrentROM, TilesetNumber[0], CurrentROM.TilesetHeader); // Load new tilesets
            MinorTileset = Tilesets.Load(CurrentROM, TilesetNumber[1], CurrentROM.TilesetHeader);

            DrawMap(); // Redraw map
        }