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