private Palette getPaletteFrom(string pccName) { var pcx = new PCXFile(); if (pcx.Load(container.Entries[pccName].Data)) { Palette palette = new Palette(pcx.Palette); palette.Name = pccName; return(palette); } return(null); }
public static void LoadColormapFromPak() { colormap = new PCXFile(); byte[] rawdata; if (ResourceLoader.LoadFile("pics/colormap.pcx", out rawdata)) { Stream stream = new MemoryStream(rawdata); BinaryReader reader = new BinaryReader(stream); colormap.identifier = reader.ReadByte(); colormap.version = reader.ReadByte(); colormap.encoding = reader.ReadByte(); colormap.bitsPerPixel = reader.ReadByte(); colormap.xmin = reader.ReadInt16(); colormap.ymin = reader.ReadInt16(); colormap.xmax = reader.ReadInt16(); colormap.ymax = reader.ReadInt16(); colormap.xdpi = reader.ReadInt16(); colormap.ydpi = reader.ReadInt16(); colormap.hpalette = reader.ReadBytes(48); colormap.reserved = reader.ReadByte(); colormap.planes = reader.ReadByte(); colormap.bytesPerLine = reader.ReadInt16(); colormap.paletteType = reader.ReadInt16(); colormap.hScreenSize = reader.ReadInt16(); colormap.vScreenSize = reader.ReadInt16(); colormap.reserved2 = reader.ReadBytes(54); colormap.width = colormap.xmax - colormap.xmin + 1; colormap.height = colormap.ymax - colormap.ymin + 1; reader.BaseStream.Position = reader.BaseStream.Length - 768; colormap.qpalette = reader.ReadBytes(768); Color c; for (int i = 0; i < colormap.qpalette.Length; i += 3) { c = new Color( (float)colormap.qpalette[i] / 255f, (float)colormap.qpalette[i + 1] / 255f, (float)colormap.qpalette[i + 2] / 255f); colormap.colors.Add(c); } } }
private void fileSelected(TOCListItem item) { selectedItem = item; applyChangesButton.Visible = false; var hidePages = new TabPage[] { txtPage, imgPage, infoPage, mapPage, tfmxPage, tilesPage, entitiesPage }; foreach (TabPage page in hidePages) { if (previewTabs.TabPages.Contains(page)) { previewTabs.TabPages.Remove(page); } } currentBitmapIndex = 0; if (currentBitmaps != null) { foreach (Bitmap bmp in currentBitmaps) { bmp.Dispose(); } currentBitmaps = null; } mapMaker?.Cancel(); if (mapPictureBox.Image != null) { var img = mapPictureBox.Image; mapPictureBox.Image = null; img.Dispose(); } hexBox.ByteProvider = new DynamicByteProvider(item.Entry.Data); bool preview = true; Description description = game.Descriptions?.ByName(item.Entry.Name); if (description != null && description.NoPreview) { preview = false; } if (preview) { switch (item.Entry.Type) { case TOCEntryType.Text: case TOCEntryType.Language: txtOutput.Text = Encoding.GetEncoding("437").GetString(item.Entry.Data); previewTabs.TabPages.Add(txtPage); previewTabs.SelectedTab = txtPage; break; case TOCEntryType.StaticSprite: PCXFile img = new PCXFile(); img.Load(item.Entry.Data); currentImgZoom = 3; imgZoomInput.Value = currentImgZoom; currentBitmaps = new Bitmap[] { img.Bitmap }; imgPage.Text = "Sprite"; previewTabs.TabPages.Add(imgPage); previewTabs.SelectedTab = imgPage; bitmapControlsPanel.Visible = false; updateImagePreview(); break; case TOCEntryType.AnimatedSprite: BOBFile bobFile = new BOBFile(item.Entry.Data); BOBDecoder decoder = new BOBDecoder(); var vgaBitmaps = decoder.DecodeFrames(bobFile); currentBitmaps = new Bitmap[vgaBitmaps.Count]; imgPage.Text = "Sprite Animation"; for (int i = 0; i < vgaBitmaps.Count; i++) { currentBitmaps[i] = VGABitmapConverter.ToRGBA(vgaBitmaps[i]); } currentImgZoom = 10; imgZoomInput.Value = currentImgZoom; previewTabs.TabPages.Add(imgPage); previewTabs.SelectedTab = imgPage; bitmapControlsPanel.Visible = true; updateImagePreview(); break; case TOCEntryType.Palette: currentImgZoom = 14; imgZoomInput.Value = currentImgZoom; currentBitmaps = new Bitmap[] { Palette.ToBitmap(item.Entry.Data) }; imgPage.Text = "Palette"; previewTabs.TabPages.Add(imgPage); previewTabs.SelectedTab = imgPage; bitmapControlsPanel.Visible = false; updateImagePreview(); break; case TOCEntryType.Tileset: case TOCEntryType.CollisionInfo: tilesCollisionsCheckbox.Checked = item.Entry.Type == TOCEntryType.CollisionInfo; Bitmap tilesetBitmap = tilemapMaker.MakeTilesetBitmap(item.Entry, tilesCollisionsCheckbox.Checked); if (tilesetBitmap != null) { tilesPictureBox.Image = tilesetBitmap; previewTabs.TabPages.Add(tilesPage); previewTabs.SelectedTab = tilesPage; } else { MessageBox.Show("Error: Failed to generate tileset preview!"); } break; case TOCEntryType.Map: previewTabs.TabPages.Add(mapPage); previewTabs.SelectedTab = mapPage; mapMakerProgressBar.Value = 0; mapMakerProgressPanel.Visible = true; mapMaker = new MapMaker(game.Assets, mapProgress, mapComplete); if (!mapMaker.Make(item.Entry)) { MessageBox.Show("Error: " + mapMaker.Error, "Failed to generate preview!", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case TOCEntryType.Music: previewTabs.TabPages.Add(tfmxPage); previewTabs.SelectedTab = tfmxPage; playSelectedTFM(); break; case TOCEntryType.EntitiesList: previewTabs.TabPages.Add(entitiesPage); previewTabs.SelectedTab = entitiesPage; entitiesList.Items.Clear(); try { EIBFile eibFile = new EIBFile(item.Entry.Data); foreach (var entry in eibFile.Regions) { foreach (var point in entry.Points) { entitiesList.Items.Add(new EntityListItem(point)); } } entityFileInfo.Text = $"Unknown variables in file: D={eibFile.D}, E={eibFile.E}, F={eibFile.F}"; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; case TOCEntryType.PixelFont: case TOCEntryType.Sound: case TOCEntryType.DIR: case TOCEntryType.DAT: case TOCEntryType.Executable: case TOCEntryType.Unknown: default: break; } } if (description != null && !string.IsNullOrEmpty(description.Info)) { infoOutput.Text = description.Info; previewTabs.TabPages.Add(infoPage); if (previewTabs.TabPages.Count == 1) { previewTabs.SelectedTab = infoPage; } } sectionsPanel.Invalidate(); }
private void displayFileDetails(DATFileEntry entry) { Text = baseTitle + " - " + entry.Filename; savePNGButton.Visible = false; savePNGSButton.Visible = false; currentExportBitmap = null; currentExportBitmaps = null; switch (entry.Type) { case "MAP": MAPFile map = new MAPFile(entry); if (map.Error != "") { MessageBox.Show(map.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Palette palette = Palette.Default; Bitmap mapBitmap = null; // find matching ICO tileset and PCC for palette if (entry.Filename.StartsWith("W")) { string baseName = entry.Filename.Substring(0, 2); if (container.Entries.ContainsKey(baseName + ".ICO")) { palette = getPaletteFrom(baseName + ".PCC"); if (palette == null) { palette = Palette.Default; } else if (baseName != "W2") { addW2Palette(palette); } ICOFile icoFile = new ICOFile(container.Entries[baseName + ".ICO"], palette); int scale = 1; mapBitmap = MAPPainter.Paint(map, icoFile, scale); currentExportBitmap = scale == 1 ? mapBitmap : MAPPainter.Paint(map, icoFile, 1); } } imgPictureBox.Image = mapBitmap; setPaletteImage(palette); log($"MAP loaded: name={entry.Filename}, width={map.Width}, height={map.Height}, palette={palette.Name}"); break; case "ARE": AREFile area = new AREFile(entry); if (area.Error != "") { MessageBox.Show(area.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //imgPictureBox.Image = BitmapScaler.PixelScale(, 3); //palettePictureBox.Image = BitmapScaler.PixelScale(Palette.ToBitmap(Palette.Default), 6); break; case "BOB": string name = Path.GetFileNameWithoutExtension(entry.Filename); if (container.Entries.ContainsKey(name + ".PCC")) { palette = getPaletteFrom(name + ".PCC"); } else if (name.Length == 1) { palette = getPaletteFrom("ANTS.PCC"); // the ants have names like A.BOB to O.BOB } else { palette = getPaletteFrom("W2.PCC"); palette.Colors[0] = Color.Black; palette.Name += " (mod)"; } BOBFile b = new BOBFile(entry, palette); if (b.Error != "") { MessageBox.Show(b.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } log($"BOB contains {b.Elements.Count} images"); currentExportBitmaps = b.Elements.ToArray(); currentExportBitmap = BOBPainter.MakeSheet(b); imgPictureBox.Image = BitmapScaler.PixelScale(currentExportBitmap, 3); setPaletteImage(palette); break; case "ICO": // tileset / spritesheet string world = entry.Filename.Contains("W1") ? "W1" : (entry.Filename.Contains("W2") ? "W2" : "W3"); palette = getPaletteFrom(world + ".PCC"); if (palette == null) { palette = Palette.Default; } else if (world != "W2") { addW2Palette(palette); } ICOFile ico = new ICOFile(entry, palette); if (ico.Error != "") { MessageBox.Show("Failed to load ICO, sorry!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } log($"ICO contains {ico.Bitmaps.Length} tiles"); currentExportBitmaps = ico.Bitmaps; currentExportBitmap = ICOPainter.TileSetFromBitmaps(ico.Bitmaps); imgPictureBox.Image = BitmapScaler.PixelScale(currentExportBitmap, 3); setPaletteImage(palette); break; case "PCC": // these are actually PCX files, version 5, encoded, 8 bits per pixel PCXFile pcx = new PCXFile(); if (!pcx.Load(entry.Data)) { MessageBox.Show(pcx.Error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } currentExportBitmap = pcx.Bitmap; imgPictureBox.Image = BitmapScaler.PixelScale(pcx.Bitmap, 4); setPaletteImage(Palette.ToBitmap(pcx.Palette), "own"); log($"PCC loaded: name={entry.Filename}, width={pcx.Bitmap.Width}, height={pcx.Bitmap.Height}, palette=own"); break; default: break; } if (currentExportBitmap != null) { savePNGButton.Visible = true; } if (currentExportBitmaps != null && currentExportBitmaps.Length > 0) { savePNGSButton.Visible = true; } }