Beispiel #1
0
        private void OpenFile()
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Program.FilePath = openFileDialog.FileName;
                E5FileData e5File = new E5FileData(Program.FilePath);
                var        count  = e5File.GetItemCount();
                lands         = new int[count, 40, 40];
                originalLands = new int[count, 40, 40];
                landSizes     = new Size[count];

                progress.Visible = true;
                progress.Maximum = count;
                progress.Value   = 0;

                for (int i = 0; i < count; ++i)
                {
                    var bytes = e5File.GetItemBytes(i);
                    landSizes[i] = new Size(bytes[0] / 3, bytes[1] / 3);

                    for (int j = 0; j < landSizes[i].Height; ++j)
                    {
                        for (int k = 0; k < landSizes[i].Width; ++k)
                        {
                            originalLands[i, j, k] = bytes[2 + k + j * landSizes[i].Width];
                            lands[i, j, k]         = originalLands[i, j, k];
                        }
                    }

                    listLand.Items.Add(i);
                    progress.Value++;
                }
                e5File.Dispose();

                listLand.SelectedIndex = 0;
                menuEdit.Enabled       = true;
                menuMap.Enabled        = true;
                progress.Visible       = false;
                pbLand.Visible         = true;
            }
        }
Beispiel #2
0
        private void SaveFile()
        {
            E5FileData e5File = new E5FileData(Program.FilePath);
            var        count  = listLand.Items.Count;
            var        temp   = e5File.ReadByteArr(0, 0x110);

            e5File.Dispose();

            /* Create new file */
            File.Delete(Program.FilePath);
            e5File = new E5FileData(Program.FilePath);
            e5File.WriteByteArr(0, temp);

            progress.Visible = true;
            progress.Maximum = count;
            progress.Value   = 0;


            for (int i = 0; i < count; ++i)
            {
                var bytes = e5File.GetItemBytes(i);
                landSizes[i] = new Size(bytes[0] / 3, bytes[1] / 3);

                for (int j = 0; j < landSizes[i].Height; ++j)
                {
                    for (int k = 0; k < landSizes[i].Width; ++k)
                    {
                        originalLands[i, j, k] = bytes[2 + k + j * landSizes[i].Width];
                        lands[i, j, k]         = originalLands[i, j, k];
                    }
                }

                progress.Value++;
            }
            e5File.Dispose();
        }
Beispiel #3
0
        private Bitmap GetMap(int index)
        {
            string directory  = Path.GetDirectoryName(Program.FilePath);
            string hmFileName = String.Format("HM{0:00}.E5", index);

            if (File.Exists(directory + "\\" + hmFileName))
            {
                E5FileData hmFile      = new E5FileData(directory + "\\" + hmFileName);
                E5FileData paletteFile = new E5FileData(directory + "\\SPALET.E5");

                int width  = landSizes[index].Width * 48;
                int height = landSizes[index].Height * 48;

                if (width != 0 && height != 0)
                {
                    var bytes  = new byte[hmFile.Length];
                    var pixels = new byte[48];
                    var offset = 0;
                    for (int i = 0; i < height / 48; ++i)
                    {
                        for (int j = 0; j < 48; ++j)
                        {
                            for (int k = i * (width / 48); k < (i + 1) * (width / 48); ++k)
                            {
                                pixels = hmFile.ReadByteArr(k * 0x900 + 48 * j, 48);
                                pixels.CopyTo(bytes, offset);
                                offset += 48;
                            }
                        }
                    }

                    GCHandle pinnedArray = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                    IntPtr   pointer     = pinnedArray.AddrOfPinnedObject();
                    Bitmap   bitmap24Bit = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                    using (Bitmap bitmap = new Bitmap(width, height, ((width - 1) / 4 + 1) * 4,
                                                      System.Drawing.Imaging.PixelFormat.Format8bppIndexed,
                                                      pointer))
                    {
                        ColorPalette palette      = bitmap.Palette;
                        Color[]      entries      = palette.Entries;
                        var          paletteBytes = paletteFile.GetItemBytes(index);
                        for (int i = 0; i < paletteBytes.Length / 3; ++i)
                        {
                            entries[i] = Color.FromArgb(paletteBytes[i * 3 + 1], paletteBytes[i * 3 + 2],
                                                        paletteBytes[i * 3]);
                        }
                        bitmap.Palette = palette;

                        using (Graphics g = Graphics.FromImage(bitmap24Bit))
                        {
                            g.DrawImage(bitmap, 0, 0, width, height);
                        }
                    }

                    pinnedArray.Free();
                    hmFile.Dispose();
                    paletteFile.Dispose();

                    return(bitmap24Bit);
                }
            }
            return(null);
        }