public static BMPInfo[] GetTextures(string filename) { List<BMPInfo> functionReturnValue = new List<BMPInfo>(); bool gvm = false; ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); pvmfile = new PvmArchive(); if (!pvmfile.Is(pvmdata, filename)) { pvmfile = new GvmArchive(); gvm = true; } VrSharp.VpPalette pvp = null; ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; foreach (ArchiveEntry file in pvmentries) { VrTexture vrfile = gvm ? (VrTexture)new GvrTexture(file.Open()) : (VrTexture)new PvrTexture(file.Open()); if (vrfile.NeedsExternalPalette) { using (System.Windows.Forms.OpenFileDialog a = new System.Windows.Forms.OpenFileDialog { DefaultExt = gvm ? "gvp" : "pvp", Filter = gvm ? "GVP Files|*.gvp" : "PVP Files|*.pvp", InitialDirectory = System.IO.Path.GetDirectoryName(filename), Title = "External palette file" }) { if (pvp == null) if (a.ShowDialog() == System.Windows.Forms.DialogResult.OK) pvp = gvm ? (VpPalette)new GvpPalette(a.FileName) : (VpPalette)new PvpPalette(a.FileName); else return new BMPInfo[0]; } if (gvm) ((GvrTexture)vrfile).SetPalette((GvpPalette)pvp); else ((PvrTexture)vrfile).SetPalette((PvpPalette)pvp); } try { functionReturnValue.Add(new BMPInfo(Path.GetFileNameWithoutExtension(file.Name), vrfile.ToBitmap())); } catch { functionReturnValue.Add(new BMPInfo(Path.GetFileNameWithoutExtension(file.Name), new Bitmap(1, 1))); } } return functionReturnValue.ToArray(); }
static void Main(string[] args) { Queue<string> files = new Queue<string>(args); if (files.Count == 0) { Console.Write("File: "); files.Enqueue(Console.ReadLine()); } while (files.Count > 0) { string filename = files.Dequeue(); string path = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(filename)), Path.GetFileNameWithoutExtension(filename)); Directory.CreateDirectory(path); byte[] filedata = File.ReadAllBytes(filename); using (TextWriter texList = File.CreateText(Path.Combine(path, "index.txt"))) { try { if (PvrTexture.Is(filedata)) { if (!AddTexture(false, path, Path.GetFileName(filename), new MemoryStream(filedata), texList)) { texList.Close(); Directory.Delete(path, true); } continue; } else if (GvrTexture.Is(filedata)) { if (!AddTexture(true, path, Path.GetFileName(filename), new MemoryStream(filedata), texList)) { texList.Close(); Directory.Delete(path, true); } continue; } bool gvm = false; ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); pvmfile = new PvmArchive(); if (!pvmfile.Is(pvmdata, filename)) { pvmfile = new GvmArchive(); gvm = true; } ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; bool fail = false; foreach (ArchiveEntry file in pvmentries) if (!AddTexture(gvm, path, file.Name, file.Open(), texList)) { texList.Close(); Directory.Delete(path, true); fail = true; break; } if (fail) continue; } catch { Console.WriteLine("Exception thrown. Canceling conversion."); Directory.Delete(path, true); throw; } } } }
private bool GetTextures(string filename) { byte[] pvmdata = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); ArchiveBase pvmfile = new PvmArchive(); if (!pvmfile.Is(pvmdata, filename)) { MessageBox.Show(this, "Could not open file \"" + filename + "\".", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } PvpPalette pvp = null; ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; List<TextureInfo> newtextures = new List<TextureInfo>(pvmentries.Count); foreach (ArchiveEntry file in pvmentries) { PvrTexture vrfile = new PvrTexture(file.Open()); if (vrfile.NeedsExternalPalette) { if (pvp == null) using (System.Windows.Forms.OpenFileDialog a = new System.Windows.Forms.OpenFileDialog { DefaultExt = "pvp", Filter = "PVP Files|*.pvp", InitialDirectory = Path.GetDirectoryName(filename), Title = "External palette file" }) if (a.ShowDialog(this) == DialogResult.OK) pvp = new PvpPalette(a.FileName); else { MessageBox.Show(this, "Could not open file \"" + Program.Arguments[0] + "\".", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } vrfile.SetPalette(pvp); } newtextures.Add(new TextureInfo(Path.GetFileNameWithoutExtension(file.Name), vrfile)); } textures.Clear(); textures.AddRange(newtextures); listBox1.Items.Clear(); listBox1.Items.AddRange(textures.Select((item) => item.Name).ToArray()); SetFilename(Path.GetFullPath(filename)); return true; }
static void Main(string[] args) { Queue<string> files = new Queue<string>(args); if (files.Count == 0) { Console.Write("File: "); files.Enqueue(Console.ReadLine()); } while (files.Count > 0) { string filename = files.Dequeue(); PAKFile pak = new PAKFile(); List<byte> inf = new List<byte>(); string filenoext = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant(); string longdir = "..\\..\\..\\sonic2\\resource\\gd_pc\\prs\\" + filenoext; byte[] filedata = File.ReadAllBytes(filename); using (System.Windows.Forms.Panel panel1 = new System.Windows.Forms.Panel()) using (Device d3ddevice = new Device(0, DeviceType.Hardware, panel1, CreateFlags.SoftwareVertexProcessing, new PresentParameters[] { new PresentParameters() { Windowed = true, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = DepthFormat.D24X8 } })) { if (PvrTexture.Is(filedata)) { if (!AddTexture(pak, filenoext, longdir, false, inf, d3ddevice, filename, new MemoryStream(filedata))) continue; goto end; } else if (GvrTexture.Is(filedata)) { if (!AddTexture(pak, filenoext, longdir, true, inf, d3ddevice, filename, new MemoryStream(filedata))) continue; goto end; } bool gvm = false; ArchiveBase pvmfile = null; byte[] pvmdata = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) pvmdata = FraGag.Compression.Prs.Decompress(pvmdata); pvmfile = new PvmArchive(); if (!pvmfile.Is(pvmdata, filename)) { pvmfile = new GvmArchive(); gvm = true; } ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries; bool fail = false; foreach (ArchiveEntry file in pvmentries) if (!AddTexture(pak, filenoext, longdir, gvm, inf, d3ddevice, file.Name, file.Open())) { fail = true; break; } if (fail) continue; } end: pak.Files.Insert(0, new PAKFile.File(filenoext + '\\' + filenoext + ".inf", longdir + '\\' + filenoext + ".inf", inf.ToArray())); pak.Save(Path.ChangeExtension(filename, "pak")); } }
static void Main(string[] args) { string directoryName; UInt32 startingGBIX = 0; List<String> textureNames = new List<String>(); List<PvrTexture> finalTextureList = new List<PvrTexture>(); if (args.Length == 0) { Console.WriteLine("Error - no texturelist provided. Provide a path to a texturelist as your first command line argument"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); return; } String filePath = args[0]; directoryName = Path.GetDirectoryName(filePath); string archiveName = Path.GetFileNameWithoutExtension(filePath); if (File.Exists(filePath)) { StreamReader texlistStream = File.OpenText(filePath); startingGBIX = UInt32.Parse(texlistStream.ReadLine()); while (!texlistStream.EndOfStream) textureNames.Add(texlistStream.ReadLine()); PvmArchive pvmArchive = new PvmArchive(); Stream pvmStream = File.Open(Path.ChangeExtension(filePath, ".pvm"), FileMode.Create); PvmArchiveWriter pvmWriter = (PvmArchiveWriter)pvmArchive.Create(pvmStream); // Reading in textures for (uint imgIndx = 0; imgIndx < textureNames.Count; imgIndx++) { Bitmap tempTexture = new Bitmap(8, 8); string texturePath = Path.Combine(directoryName, Path.ChangeExtension(textureNames[(int)imgIndx], ".png")); if (File.Exists(texturePath)) { tempTexture = (Bitmap)Bitmap.FromFile(texturePath); tempTexture = tempTexture.Clone(new Rectangle(Point.Empty, tempTexture.Size), System.Drawing.Imaging.PixelFormat.Format32bppArgb); } else { Console.WriteLine(String.Concat("Texture ", textureNames[(int)imgIndx], " not found. Generating a placeholder. Check your files.")); } System.Drawing.Imaging.BitmapData bmpd = tempTexture.LockBits(new Rectangle(Point.Empty, tempTexture.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); int stride = bmpd.Stride; byte[] bits = new byte[Math.Abs(stride) * bmpd.Height]; System.Runtime.InteropServices.Marshal.Copy(bmpd.Scan0, bits, 0, bits.Length); tempTexture.UnlockBits(bmpd); int tlevels = 0; for (int y = 0; y < tempTexture.Height; y++) { int srcaddr = y * Math.Abs(stride); for (int x = 0; x < tempTexture.Width; x++) { Color c = Color.FromArgb(BitConverter.ToInt32(bits, srcaddr + (x * 4))); if (c.A == 0) tlevels = 1; else if (c.A < 255) { tlevels = 2; break; } } if (tlevels == 2) break; } PvrPixelFormat ppf = PvrPixelFormat.Rgb565; if (tlevels == 1) ppf = PvrPixelFormat.Argb1555; else if (tlevels == 2) ppf = PvrPixelFormat.Argb4444; PvrDataFormat pdf = PvrDataFormat.Rectangle; if (tempTexture.Width == tempTexture.Height) pdf = PvrDataFormat.SquareTwiddled; PvrTextureEncoder encoder = new PvrTextureEncoder(tempTexture, ppf, pdf); encoder.GlobalIndex = startingGBIX + imgIndx; string pvrPath = Path.ChangeExtension(texturePath, ".pvr"); encoder.Save(pvrPath); pvmWriter.CreateEntryFromFile(pvrPath); } pvmWriter.Flush(); pvmStream.Close(); Console.WriteLine("PVM was compiled successfully!"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); return; } else // error, supplied path is invalid { Console.WriteLine("Supplied texturelist does not exist!"); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); return; } }