Example #1
0
 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();
 }
Example #2
0
 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;
             }
         }
     }
 }
Example #3
0
 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"));
     }
 }