Пример #1
0
        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);
        }
Пример #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();
                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;
                            if (!pvmfile.Is(pvmdata, filename))
                            {
                                Console.WriteLine("{0} is not a valid file.", filename);
                                continue;
                            }
                        }
                        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"));
            }
        }
Пример #3
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());
        }
Пример #4
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;
                    }
                }
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error - please specify a texture list (.txt), or a PRS/PVM/GVM archive.");
                Console.WriteLine("Press ENTER to exit.");
                Console.ReadLine();
                return;
            }
            string filePath = args[0];
            bool   IsPRS    = false;

            if (args.Length > 1 && args[1] == "-prs")
            {
                IsPRS = true;
            }
            string directoryName = Path.GetDirectoryName(filePath);
            string extension     = Path.GetExtension(filePath).ToLowerInvariant();

            switch (extension)
            {
            case ".txt":
                string archiveName = Path.GetFileNameWithoutExtension(filePath);
                if (File.Exists(filePath))
                {
                    List <string> textureNames = new List <string>(File.ReadAllLines(filePath).Where(a => !string.IsNullOrEmpty(a)));
                    ArchiveBase   pvmArchive;
                    string        ext = Path.GetExtension(textureNames[0]).ToLowerInvariant();
                    if (textureNames.Any(a => !Path.GetExtension(a).Equals(ext, StringComparison.OrdinalIgnoreCase)))
                    {
                        Console.WriteLine("Cannot create archive from mixed file types.");
                        return;
                    }
                    switch (ext)
                    {
                    case ".pvr":
                        pvmArchive = new PvmArchive();
                        break;

                    case ".gvr":
                        pvmArchive = new GvmArchive();
                        break;

                    default:
                        Console.WriteLine("Unknown file type \"{0}\".", ext);
                        return;
                    }
                    using (Stream pvmStream = File.Open(Path.ChangeExtension(filePath, ".pvm"), FileMode.Create))
                    {
                        ArchiveWriter pvmWriter = pvmArchive.Create(pvmStream);
                        // Reading in textures
                        foreach (string tex in textureNames)
                        {
                            pvmWriter.CreateEntryFromFile(Path.Combine(directoryName, Path.ChangeExtension(tex, ".pvr")));
                        }
                        pvmWriter.Flush();
                    }
                    if (IsPRS == true)
                    {
                        byte[] pvmdata = File.ReadAllBytes(Path.ChangeExtension(filePath, ".pvm"));
                        pvmdata = FraGag.Compression.Prs.Compress(pvmdata);
                        File.WriteAllBytes(Path.ChangeExtension(filePath, ".prs"), pvmdata);
                        File.Delete(Path.ChangeExtension(filePath, ".pvm"));
                    }
                    Console.WriteLine("Archive was compiled successfully!");
                }
                else                         // error, supplied path is invalid
                {
                    Console.WriteLine("Supplied archive/texture list does not exist!");
                    Console.WriteLine("Press ENTER to exit.");
                    Console.ReadLine();
                }
                break;

            case ".prs":
            case ".pvm":
            case ".gvm":
                string path = Path.Combine(directoryName, Path.GetFileNameWithoutExtension(filePath));
                Directory.CreateDirectory(path);
                byte[] filedata = File.ReadAllBytes(filePath);
                using (TextWriter texList = File.CreateText(Path.Combine(path, Path.ChangeExtension(filePath, ".txt"))))
                {
                    try
                    {
                        ArchiveBase pvmfile = null;
                        byte[]      pvmdata = File.ReadAllBytes(filePath);
                        if (extension == ".prs")
                        {
                            pvmdata = FraGag.Compression.Prs.Decompress(pvmdata);
                        }
                        pvmfile = new PvmArchive();
                        if (!pvmfile.Is(pvmdata, filePath))
                        {
                            pvmfile = new GvmArchive();
                        }
                        ArchiveReader pvmReader = pvmfile.Open(pvmdata);
                        foreach (ArchiveEntry file in pvmReader.Entries)
                        {
                            texList.WriteLine(file.Name);
                            pvmReader.ExtractToFile(file, Path.Combine(path, file.Name));
                        }
                        Console.WriteLine("Archive extracted!");
                    }
                    catch
                    {
                        Console.WriteLine("Exception thrown. Canceling conversion.");
                        Directory.Delete(path, true);
                        throw;
                    }
                }
                break;

            default:
                Console.WriteLine("Unknown extension \"{0}\".", extension);
                break;
            }
        }
Пример #6
0
        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();
            List <TextureInfo> newtextures;

            if (PvmxArchive.Is(pvmdata))
            {
                format      = TextureFormat.PVMX;
                newtextures = new List <TextureInfo>(PvmxArchive.GetTextures(pvmdata).Cast <TextureInfo>());
            }
            else if (PAKFile.Is(filename))
            {
                format = TextureFormat.PAK;
                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;
                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.First((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 PakTextureInfo(sb.ToString(), BitConverter.ToUInt32(inf, i + 0x1C), new Bitmap(bmp)));
                }
            }
            else
            {
                if (pvmfile.Is(pvmdata, filename))
                {
                    format = TextureFormat.PVM;
                }
                else
                {
                    pvmfile = new GvmArchive();
                    if (!pvmfile.Is(pvmdata, filename))
                    {
                        MessageBox.Show(this, "Could not open file \"" + filename + "\".", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return(false);
                    }
                    format = TextureFormat.GVM;
                }
                ArchiveEntryCollection pvmentries = pvmfile.Open(pvmdata).Entries;
                newtextures = new List <TextureInfo>(pvmentries.Count);
                switch (format)
                {
                case TextureFormat.PVM:
                    PvpPalette pvp = null;
                    foreach (ArchiveEntry file in pvmentries)
                    {
                        PvrTexture vrfile = new PvrTexture(file.Open());
                        if (vrfile.NeedsExternalPalette)
                        {
                            if (pvp == null)
                            {
                                using (OpenFileDialog a = new 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 PvrTextureInfo(Path.GetFileNameWithoutExtension(file.Name), vrfile));
                    }
                    break;

                case TextureFormat.GVM:
                    GvpPalette gvp = null;
                    foreach (ArchiveEntry file in pvmentries)
                    {
                        GvrTexture vrfile = new GvrTexture(file.Open());
                        if (vrfile.NeedsExternalPalette)
                        {
                            if (gvp == null)
                            {
                                using (OpenFileDialog a = new OpenFileDialog
                                {
                                    DefaultExt = "gvp",
                                    Filter = "GVP Files|*.gvp",
                                    InitialDirectory = Path.GetDirectoryName(filename),
                                    Title = "External palette file"
                                })
                                    if (a.ShowDialog(this) == DialogResult.OK)
                                    {
                                        gvp = new GvpPalette(a.FileName);
                                    }
                                    else
                                    {
                                        MessageBox.Show(this, "Could not open file \"" + Program.Arguments[0] + "\".", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        return(false);
                                    }
                            }
                            vrfile.SetPalette(gvp);
                        }
                        newtextures.Add(new GvrTextureInfo(Path.GetFileNameWithoutExtension(file.Name), vrfile));
                    }
                    break;
                }
            }
            textures.Clear();
            textures.AddRange(newtextures);
            listBox1.Items.Clear();
            listBox1.Items.AddRange(textures.Select((item) => item.Name).ToArray());
            UpdateTextureCount();
            SetFilename(Path.GetFullPath(filename));
            return(true);
        }