Esempio n. 1
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"));
     }
 }
Esempio n. 2
0
 static bool AddTexture(PAKFile pak, string filenoext, string longdir, bool gvm, List<byte> inf, Device d3ddevice, string filename, Stream data)
 {
     VrTexture vrfile = gvm ? (VrTexture)new GvrTexture(data) : (VrTexture)new PvrTexture(data);
     if (vrfile.NeedsExternalPalette)
     {
         Console.WriteLine("Cannot convert texture files which require external palettes!");
         return false;
     }
     Bitmap bmp;
     try { bmp = vrfile.ToBitmap(); }
     catch { bmp = new Bitmap(1, 1); }
     Stream tex = TextureLoader.SaveToStream(ImageFileFormat.Dds, Texture.FromBitmap(d3ddevice, bmp, Usage.SoftwareProcessing, Pool.Managed));
     byte[] tb = new byte[tex.Length];
     tex.Read(tb, 0, tb.Length);
     pak.Files.Add(new PAKFile.File(filenoext + '\\' + Path.ChangeExtension(filename, ".dds"), longdir + '\\' + Path.ChangeExtension(filename, ".dds"), tb));
     int i = inf.Count;
     inf.AddRange(Encoding.ASCII.GetBytes(Path.ChangeExtension(filename, null)));
     inf.AddRange(new byte[0x1C - (inf.Count - i)]);
     if (vrfile.HasGlobalIndex)
         inf.AddRange(BitConverter.GetBytes(vrfile.GlobalIndex));
     else
         inf.AddRange(BitConverter.GetBytes(-1));
     if (gvm)
     {
         GvrTexture gvr = (GvrTexture)vrfile;
         inf.AddRange(BitConverter.GetBytes((int)gvr.DataFormat));
         inf.AddRange(BitConverter.GetBytes((int)gvr.PixelFormat));
         inf.AddRange(BitConverter.GetBytes((int)gvr.DataFormat));
     }
     else
     {
         PvrTexture pvr = (PvrTexture)vrfile;
         inf.AddRange(BitConverter.GetBytes((int)pvr.DataFormat));
         inf.AddRange(BitConverter.GetBytes((int)pvr.PixelFormat));
         inf.AddRange(BitConverter.GetBytes((int)pvr.DataFormat));
     }
     inf.AddRange(BitConverter.GetBytes((int)vrfile.TextureWidth));
     inf.AddRange(BitConverter.GetBytes((int)vrfile.TextureHeight));
     inf.AddRange(BitConverter.GetBytes(vrfile.PvrtOffset));
     inf.AddRange(BitConverter.GetBytes(0x80000000));
     return true;
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string directoryName;
            UInt32 startingGBIX = 0;
            List<String> textureNames = new List<String>();

            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());

                string filenoext = Path.GetFileNameWithoutExtension(filePath).ToLowerInvariant();
                string longdir = "..\\..\\..\\sonic2\\resource\\gd_pc\\prs\\" + filenoext;
                PAKFile pak = new PAKFile();
                List<byte> inf = new List<byte>();
                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 } }))
                {
                    // 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."));
                        }

                        Stream tex = TextureLoader.SaveToStream(ImageFileFormat.Dds, Texture.FromBitmap(d3ddevice, tempTexture, Usage.SoftwareProcessing, Pool.Managed));
                        byte[] tb = new byte[tex.Length];
                        tex.Read(tb, 0, tb.Length);
                        pak.Files.Add(new PAKFile.File(filenoext + '\\' + Path.ChangeExtension(textureNames[(int)imgIndx], ".dds"), longdir + '\\' + Path.ChangeExtension(textureNames[(int)imgIndx], ".dds"), tb));
                        int i = inf.Count;
                        inf.AddRange(Encoding.ASCII.GetBytes(Path.ChangeExtension(textureNames[(int)imgIndx], null)));
                        inf.AddRange(new byte[0x1C - (inf.Count - i)]);
                        inf.AddRange(BitConverter.GetBytes(startingGBIX + imgIndx));
                        inf.AddRange(BitConverter.GetBytes(0));
                        inf.AddRange(BitConverter.GetBytes(0));
                        inf.AddRange(BitConverter.GetBytes(0));
                        inf.AddRange(BitConverter.GetBytes(tempTexture.Width));
                        inf.AddRange(BitConverter.GetBytes(tempTexture.Height));
                        inf.AddRange(BitConverter.GetBytes(0));
                        inf.AddRange(BitConverter.GetBytes(0x80000000));
                    }
                }
                pak.Files.Insert(0, new PAKFile.File(filenoext + '\\' + filenoext + ".inf", longdir + '\\' + filenoext + ".inf", inf.ToArray()));
                pak.Save(Path.ChangeExtension(filePath, "pak"));

                Console.WriteLine("PAK 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;
            }
        }
Esempio n. 4
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog fd = new OpenFileDialog() { DefaultExt = "ini", Filter = "INI Files|*.ini" })
         if (fd.ShowDialog(this) == DialogResult.OK)
         {
             IniData ini = IniSerializer.Deserialize<IniData>(fd.FileName);
             filename = Path.Combine(Path.GetDirectoryName(fd.FileName),
                 ini.Files.First((item) => item.Value.Type == "stageselectlist").Value.Filename);
             levels = new List<StageSelectLevel>(StageSelectLevelList.Load(filename));
             string resdir = Path.Combine(Path.GetDirectoryName(fd.FileName), ini.SystemFolder);
             using (Device d3ddevice = new Device(0, DeviceType.Hardware, dummyPanel.Handle, CreateFlags.SoftwareVertexProcessing, new PresentParameters[] { new PresentParameters() { Windowed = true, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = DepthFormat.D24X8 } }))
             {
                 using (Stream str = new MemoryStream(
                     new PAKFile(Path.Combine(resdir, @"SOC\stageMapBG.pak")).Files.Find(
                     (a) => a.Name.Equals(@"stagemapbg\stagemap.dds")).Data))
                     bgtex = LoadDDS(str, d3ddevice);
                 if (File.Exists(Path.Combine(resdir, @"PRS\stageMap.pak")))
                 {
                     List<PAKFile.File> files = new PAKFile(Path.Combine(resdir, @"PRS\stageMap.pak")).Files;
                     byte[] inf = files.Find((a) => a.Name.Equals(@"stagemap\stagemap.inf")).Data;
                     uitexs = new Bitmap[inf.Length / 0x3C];
                     for (int i = 0; i < uitexs.Length; i++)
                         using (Stream str = new MemoryStream(files.Find(
                             (a) => a.Name.Equals(@"stagemap\" + Encoding.ASCII.GetString(inf, i * 0x3C, 0x1c).TrimEnd('\0') + ".dds")).Data))
                             uitexs[i] = LoadDDS(str, d3ddevice);
                 }
                 else
                     uitexs = TextureArchive.GetTextures(Path.Combine(resdir, "stageMap.prs")).Select((tex) => tex.Image).ToArray();
             }
             saveToolStripMenuItem.Enabled = panel1.Enabled = panel2.Enabled = true;
             selected = 0;
             level.SelectedIndex = (int)levels[selected].Level;
             character.SelectedIndex = (int)levels[selected].Character;
             column.Value = levels[selected].Column;
             row.Value = levels[selected].Row;
             DrawLevel();
         }
 }
Esempio n. 5
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     if (args.Length == 0)
         args = new string[] { "/?" };
     switch (args[0].ToLowerInvariant())
     {
         case "/t":
             Main(ParseCommandLine(File.ReadAllText(args[1])));
             break;
         case "/u":
             try
             {
                 string fn = Path.Combine(Environment.CurrentDirectory, args[1]);
                 Environment.CurrentDirectory = Path.GetDirectoryName(fn);
                 PAKFile pak = new PAKFile(fn);
                 Dictionary<string, PAKInfo> list = new Dictionary<string, PAKInfo>(pak.Files.Count);
                 foreach (PAKFile.File item in pak.Files)
                 {
                     Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, item.Name)));
                     File.WriteAllBytes(item.Name, item.Data);
                     list.Add(item.Name, new PAKInfo(item.LongPath));
                 }
                 IniFile.Serialize(list, Path.ChangeExtension(fn, "ini"));
             }
             catch (Exception ex) { Console.WriteLine(ex.ToString()); }
             break;
         case "/p":
             try
             {
                 string fn = Path.Combine(Environment.CurrentDirectory, args[1]);
                 Environment.CurrentDirectory = Path.GetDirectoryName(fn);
                 Dictionary<string, PAKInfo> list = IniFile.Deserialize<Dictionary<string, PAKInfo>>(Path.ChangeExtension(fn, "ini"));
                 PAKFile pak = new PAKFile();
                 foreach (KeyValuePair<string, PAKInfo> item in list)
                     pak.Files.Add(new PAKFile.File(item.Key, item.Value.LongPath, File.ReadAllBytes(item.Key)));
                 pak.Save(Path.ChangeExtension(fn, "pak"));
             }
             catch (Exception ex) { Console.WriteLine(ex.ToString()); }
             break;
         case "/?":
             Console.WriteLine("Arguments:");
             Console.WriteLine();
             Console.WriteLine("/?\tShow this help.");
             Console.WriteLine();
             Console.WriteLine("/t filename\tReads text file filename as a commandline.");
             Console.WriteLine();
             Console.WriteLine("/u filename\tExtracts files from an archive.");
             Console.WriteLine();
             Console.WriteLine("/p filename\tPacks files into an archive.");
             Console.WriteLine();
             break;
         default:
             if (args.Length == 0) goto case "/?";
             char arg = '\0';
             while (arg != 'u' & arg != 'p')
             {
                 Console.Write("Type u to unpack or p to pack: ");
                 arg = Console.ReadKey().KeyChar;
                 Console.WriteLine();
             }
             Main(new string[] { "/" + arg, args[0] });
             break;
     }
 }
Esempio n. 6
0
 private void GetTextures(string filename)
 {
     PAKFile pak = new PAKFile(filename);
     string filenoext = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant();
     byte[] inf = pak.Files.Single((file) => file.Name.Equals(filenoext + '\\' + filenoext + ".inf", StringComparison.OrdinalIgnoreCase)).Data;
     List<TextureInfo> newtextures = new List<TextureInfo>(inf.Length / 0x3C);
     for (int i = 0; i < inf.Length; i += 0x3C)
     {
         StringBuilder sb = new StringBuilder(0x1C);
         for (int j = 0; j < 0x1C; j++)
             if (inf[i + j] != 0)
                 sb.Append((char)inf[i + j]);
             else
                 break;
         byte[] dds = pak.Files.Single((file) => file.Name.Equals(filenoext + '\\' + sb.ToString() + ".dds", StringComparison.OrdinalIgnoreCase)).Data;
         using (MemoryStream str = new MemoryStream(dds))
         using (Texture tex = TextureLoader.FromStream(d3ddevice, str))
         using (Stream bmp = TextureLoader.SaveToStream(ImageFileFormat.Png, tex))
             newtextures.Add(new TextureInfo(sb.ToString(), BitConverter.ToUInt32(inf, i + 0x1C), new Bitmap(bmp)));
     }
     textures.Clear();
     textures.AddRange(newtextures);
     listBox1.Items.Clear();
     listBox1.Items.AddRange(textures.Select((item) => item.Name).ToArray());
     SetFilename(Path.GetFullPath(filename));
 }
Esempio n. 7
0
 private void SaveTextures()
 {
     PAKFile pak = new PAKFile();
     string filenoext = Path.GetFileNameWithoutExtension(filename).ToLowerInvariant();
     string longdir = "..\\..\\..\\sonic2\\resource\\gd_pc\\prs\\" + filenoext;
     List<byte> inf = new List<byte>(textures.Count * 0x3C);
     foreach (TextureInfo item in textures)
     {
         Stream tex = TextureLoader.SaveToStream(ImageFileFormat.Dds, Texture.FromBitmap(d3ddevice, item.Image, Usage.SoftwareProcessing, Pool.Managed));
         byte[] tb = new byte[tex.Length];
         tex.Read(tb, 0, tb.Length);
         string name = item.Name;
         if (name.Length > 0x1C)
             name = name.Substring(0, 0x1C);
         pak.Files.Add(new PAKFile.File(filenoext + '\\' + name + ".dds", longdir + '\\' + name + ".dds", tb));
         inf.AddRange(Encoding.ASCII.GetBytes(name));
         if (name.Length != 0x1C)
             inf.AddRange(new byte[0x1C - name.Length]);
         inf.AddRange(BitConverter.GetBytes(item.GlobalIndex));
         inf.AddRange(new byte[0xC]);
         inf.AddRange(BitConverter.GetBytes(item.Image.Width));
         inf.AddRange(BitConverter.GetBytes(item.Image.Height));
         inf.AddRange(new byte[4]);
         inf.AddRange(BitConverter.GetBytes(0x80000000));
     }
     pak.Files.Insert(0, new PAKFile.File(filenoext + '\\' + filenoext + ".inf", longdir + '\\' + filenoext + ".inf", inf.ToArray()));
     pak.Save(filename);
 }