Ejemplo 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;
                            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"));
            }
        }
Ejemplo n.º 2
0
        private void addTextureButton_Click(object sender, EventArgs e)
        {
            string defext = null;
            string filter = null;

            switch (format)
            {
            case TextureFormat.PVM:
                defext = "pvr";
                filter = "Texture Files|*.prs;*.pvm;*.pvr;*.png;*.jpg;*.jpeg;*.gif;*.bmp";
                break;

            case TextureFormat.GVM:
                defext = "gvr";
                filter = "Texture Files|*.prs;*.gvm;*.gvr;*.png;*.jpg;*.jpeg;*.gif;*.bmp";
                break;
            }
            using (OpenFileDialog dlg = new OpenFileDialog()
            {
                DefaultExt = defext, Filter = filter, Multiselect = true
            })
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    uint gbix = textures.Count == 0 ? 0 : textures.Max((item) => item.GlobalIndex);
                    if (gbix != uint.MaxValue)
                    {
                        gbix++;
                    }
                    listBox1.BeginUpdate();
                    foreach (string file in dlg.FileNames)
                    {
                        switch (Path.GetExtension(file).ToLowerInvariant())
                        {
                        case ".prs":
                        case ".pvm":
                        case ".gvm":
                            byte[] pvmdata = File.ReadAllBytes(file);
                            if (Path.GetExtension(file).Equals(".prs", StringComparison.OrdinalIgnoreCase))
                            {
                                pvmdata = FraGag.Compression.Prs.Decompress(pvmdata);
                            }
                            ArchiveBase pvmfile = null;
                            switch (format)
                            {
                            case TextureFormat.PVM:
                                pvmfile = new PvmArchive();
                                break;

                            case TextureFormat.GVM:
                                pvmfile = new GvmArchive();
                                break;
                            }
                            if (!pvmfile.Is(pvmdata, file))
                            {
                                MessageBox.Show(this, "Could not open file \"" + file + "\".", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                continue;
                            }
                            ArchiveEntryCollection pvmentries  = pvmfile.Open(pvmdata).Entries;
                            List <PvrTextureInfo>  newtextures = new List <PvrTextureInfo>(pvmentries.Count);
                            switch (format)
                            {
                            case TextureFormat.PVM:
                                PvpPalette pvp = null;
                                foreach (ArchiveEntry entry in pvmentries)
                                {
                                    PvrTexture vrfile = new PvrTexture(entry.Open());
                                    if (vrfile.NeedsExternalPalette)
                                    {
                                        if (pvp == null)
                                        {
                                            using (OpenFileDialog a = new OpenFileDialog
                                            {
                                                DefaultExt = "pvp",
                                                Filter = "PVP Files|*.pvp",
                                                InitialDirectory = Path.GetDirectoryName(file),
                                                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);
                                                    continue;
                                                }
                                        }
                                        vrfile.SetPalette(pvp);
                                    }
                                    string name = Path.GetFileNameWithoutExtension(entry.Name);
                                    textures.Add(new PvrTextureInfo(name, vrfile));
                                    listBox1.Items.Add(name);
                                }
                                break;

                            case TextureFormat.GVM:
                                GvpPalette gvp = null;
                                foreach (ArchiveEntry entry in pvmentries)
                                {
                                    GvrTexture vrfile = new GvrTexture(entry.Open());
                                    if (vrfile.NeedsExternalPalette)
                                    {
                                        if (gvp == null)
                                        {
                                            using (OpenFileDialog a = new OpenFileDialog
                                            {
                                                DefaultExt = "gvp",
                                                Filter = "GVP Files|*.gvp",
                                                InitialDirectory = Path.GetDirectoryName(file),
                                                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);
                                                    continue;
                                                }
                                        }
                                        vrfile.SetPalette(gvp);
                                    }
                                    string name = Path.GetFileNameWithoutExtension(entry.Name);
                                    textures.Add(new GvrTextureInfo(name, vrfile));
                                    listBox1.Items.Add(name);
                                }
                                break;
                            }
                            break;

                        default:
                        {
                            string name = Path.GetFileNameWithoutExtension(file);
                            if (format == TextureFormat.PVM && PvrTexture.Is(file))
                            {
                                textures.Add(new PvrTextureInfo(name, new PvrTexture(file)));
                            }
                            else if (format == TextureFormat.GVM && GvrTexture.Is(file))
                            {
                                textures.Add(new GvrTextureInfo(name, new GvrTexture(file)));
                            }
                            else
                            {
                                switch (format)
                                {
                                case TextureFormat.PVM:
                                    textures.Add(new PvrTextureInfo(name, gbix, new Bitmap(dlg.FileName)));
                                    break;

                                case TextureFormat.GVM:
                                    textures.Add(new GvrTextureInfo(name, gbix, new Bitmap(dlg.FileName)));
                                    break;
                                }
                                if (gbix != uint.MaxValue)
                                {
                                    gbix++;
                                }
                            }
                            listBox1.Items.Add(name);
                        }
                        break;
                        }
                    }
                    listBox1.EndUpdate();
                    listBox1.SelectedIndex = textures.Count - 1;
                    UpdateTextureCount();
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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))
            {
                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;
            List <TextureInfo>     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);
        }