/// <summary>
 /// 
 /// </summary>
 /// <param name="data"></param>
 /// <param name="path"></param>
 private static void DumpRawData(DataBuffer data, string path)
 {
     if (File.Exists(path))
         File.Delete(path);
     using (BinaryWriter bw = new BinaryWriter(File.Create(path, data.Length, FileOptions.SequentialScan)))
     {
         data.WriteData(bw);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="info"></param>
        /// <param name="data"></param>
        /// <param name="compressed"></param>
        /// <returns>True if something was inserted, false if not</returns>
        private static bool InsertRawData(WriteInfo info, byte[] data, DataBuffer originalData, int originalOffset, bool compressed)
        {
            if (info.import)
            {
                if (compressed)
                    data = LZ77.Compress(data);

                if (info.offset == originalOffset && info.abortIfBigger)
                {
                    int orgLength;
                    if (compressed)
                        orgLength = ROM.LZ77CompressedDataLength(originalOffset);
                    else
                        orgLength = originalData.Length;

                    if (orgLength < data.Length)
                    {
                        MessageBox.Show("New data larger than old. Aborting.");
                        return false;
                    }
                }

                ROM.InsertData(info.offset, data);

                if (originalOffset != info.offset && info.repoint)
                {
                    int[] offsets = ROM.ReplacePointers(originalOffset, info.offset);
                    string text;
                    if (offsets.Length > 0)
                    {
                        text = "Pointers changed at:";
                        for (int i = 0; i < offsets.Length; i++)
                            text += "\n" + Convert.ToString(offsets[i], 16);
                    }
                    else
                        text = "No pointers were found.";
                    MessageBox.Show(text);
                }
            }
            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        private static void BeginningStuff()
        {
            datas = new List<GraphicsData>(2048);

            rawGraphics = new DataBuffer(0x8000);
            rawPalette = new DataBuffer(0x100);
            rawTSA = new DataBuffer(0x200);

            imageForm = new ImageForm();
            paletteForm = new PaletteForm();
            colorForm = new ColourForm(rawPalette);
            tileForm = new TileForm(rawTSA);

            imageForm.ImageIndexUD.ValueChanged += new EventHandler(ImageIndexUD_ValueChanged);
            imageForm.OffsetUD.ValueChanged += new EventHandler(OffsetUD_ValueChanged);
            paletteForm.ROMPALoffsetUD.ValueChanged += new EventHandler(ROMPALoffsetUD_ValueChanged);
            paletteForm.compROMPalette.CheckedChanged += new EventHandler(compROMPalette_CheckedChanged);

            GUI = new MainForm(new ToolForm[]{imageForm, paletteForm, colorForm, tileForm});
            ROM = new GBAROM();

            grayScalePalette = new Color[0x100];
            for (int x = 0; x < 0x10; x++)
            {
                for (int y = 0; y < 0x10; y++)
                {
                    int value = x * 0x10 + y;
                    grayScalePalette[x + y * 0x10] = Color.FromArgb(value, value, value);
                }
            }
        }