コード例 #1
0
        public TabPage Create(VrfGuiContext vrfGuiContext, byte[] input)
        {
            var tab     = new TabPage();
            var package = new SteamDatabase.ValvePak.Package();

            if (input != null)
            {
                package.SetFileName(vrfGuiContext.FileName);
                package.Read(new MemoryStream(input));
            }
            else
            {
                package.Read(vrfGuiContext.FileName);
            }

            // create a TreeView with search capabilities, register its events, and add it to the tab
            var treeViewWithSearch = new TreeViewWithSearchResults(ImageList);

            treeViewWithSearch.InitializeTreeViewFromPackage(vrfGuiContext.FileName, new TreeViewWithSearchResults.TreeViewPackageTag
            {
                Package          = package,
                ParentFileLoader = vrfGuiContext.FileLoader,
            });
            treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile;
            treeViewWithSearch.TreeNodeRightClick       += VPK_OnClick;
            treeViewWithSearch.ListViewItemDoubleClick  += VPK_OpenFile;
            treeViewWithSearch.ListViewItemRightClick   += VPK_OnClick;
            treeViewWithSearch.Disposed += VPK_Disposed;
            tab.Controls.Add(treeViewWithSearch);

            return(tab);
        }
コード例 #2
0
        private TabPage ProcessFile(string fileName, byte[] input, TreeViewWithSearchResults.TreeViewPackageTag currentPackage)
        {
            var tab           = new TabPage();
            var vrfGuiContext = new VrfGuiContext(fileName, currentPackage);

            uint   magic = 0;
            ushort magicResourceVersion = 0;

            if (input != null)
            {
                if (input.Length >= 6)
                {
                    magic = BitConverter.ToUInt32(input, 0);
                    magicResourceVersion = BitConverter.ToUInt16(input, 4);
                }
            }
            else
            {
                var magicData = new byte[6];

                using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    fs.Read(magicData, 0, 6);
                }

                magic = BitConverter.ToUInt32(magicData, 0);
                magicResourceVersion = BitConverter.ToUInt16(magicData, 4);
            }

            if (magic != Package.MAGIC && input == null && Regex.IsMatch(fileName, @"_[0-9]{3}\.vpk$"))
            {
                // TODO: Update tab name
                fileName = $"{fileName.Substring(0, fileName.Length - 8)}_dir.vpk";
                magic    = Package.MAGIC;
            }

            if (magic == Package.MAGIC)
            {
                var package = new Package();

                if (input != null)
                {
                    package.SetFileName(fileName);
                    package.Read(new MemoryStream(input));
                }
                else
                {
                    package.Read(fileName);
                }

                // create a TreeView with search capabilities, register its events, and add it to the tab
                var treeViewWithSearch = new TreeViewWithSearchResults(ImageList);
                treeViewWithSearch.InitializeTreeViewFromPackage(fileName, new TreeViewWithSearchResults.TreeViewPackageTag
                {
                    Package       = package,
                    ParentPackage = currentPackage?.Package,
                });
                treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile;
                treeViewWithSearch.TreeNodeMouseClick       += VPK_OnClick;
                treeViewWithSearch.ListViewItemDoubleClick  += VPK_OpenFile;
                treeViewWithSearch.ListViewItemRightClick   += VPK_OnClick;
                treeViewWithSearch.Disposed += VPK_Disposed;
                tab.Controls.Add(treeViewWithSearch);

                // since we're in a separate thread, invoke to update the UI
                Invoke((MethodInvoker)(() => findToolStripButton.Enabled = true));
            }
            else if (magic == CompiledShader.MAGIC)
            {
                var shader = new CompiledShader();

                var buffer = new StringWriter();
                var oldOut = Console.Out;
                Console.SetOut(buffer);

                if (input != null)
                {
                    shader.Read(fileName, new MemoryStream(input));
                }
                else
                {
                    shader.Read(fileName);
                }

                Console.SetOut(oldOut);

                var control = new TextBox();
                control.Font       = new Font(FontFamily.GenericMonospace, control.Font.Size);
                control.Text       = NormalizeLineEndings(buffer.ToString());
                control.Dock       = DockStyle.Fill;
                control.Multiline  = true;
                control.ReadOnly   = true;
                control.ScrollBars = ScrollBars.Both;
                tab.Controls.Add(control);
            }
            else if (magic == ClosedCaptions.MAGIC)
            {
                var captions = new ClosedCaptions();
                if (input != null)
                {
                    captions.Read(fileName, new MemoryStream(input));
                }
                else
                {
                    captions.Read(fileName);
                }

                var control = new DataGridView
                {
                    Dock                = DockStyle.Fill,
                    AutoSize            = true,
                    ReadOnly            = true,
                    AllowUserToAddRows  = false,
                    AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                    DataSource          = new BindingSource(new BindingList <ClosedCaption>(captions.Captions), null),
                    ScrollBars          = ScrollBars.Both,
                };
                tab.Controls.Add(control);
            }
            else if (magic == ToolsAssetInfo.MAGIC)
            {
                var toolsAssetInfo = new ToolsAssetInfo();
                if (input != null)
                {
                    toolsAssetInfo.Read(new MemoryStream(input));
                }
                else
                {
                    toolsAssetInfo.Read(fileName);
                }

                var text = new TextBox
                {
                    Dock       = DockStyle.Fill,
                    ScrollBars = ScrollBars.Vertical,
                    Multiline  = true,
                    ReadOnly   = true,
                    Text       = NormalizeLineEndings(toolsAssetInfo.ToString()),
                };
                tab.Controls.Add(text);
            }
            else if (magic == BinaryKV3.MAGIC || magic == BinaryKV3.MAGIC2)
            {
                var    kv3 = new BinaryKV3();
                Stream kv3stream;

                if (input != null)
                {
                    kv3stream = new MemoryStream(input);
                }
                else
                {
                    kv3stream = File.OpenRead(fileName);
                }

                using (var binaryReader = new BinaryReader(kv3stream))
                {
                    kv3.Size = (uint)kv3stream.Length;
                    kv3.Read(binaryReader, null);
                }

                kv3stream.Close();

                var control = new TextBox();
                control.Font       = new Font(FontFamily.GenericMonospace, control.Font.Size);
                control.Text       = kv3.ToString();
                control.Dock       = DockStyle.Fill;
                control.Multiline  = true;
                control.ReadOnly   = true;
                control.ScrollBars = ScrollBars.Both;
                tab.Controls.Add(control);
            }
            else if (magicResourceVersion == Resource.KnownHeaderVersion)
            {
                var resource = new Resource();
                if (input != null)
                {
                    resource.Read(new MemoryStream(input));
                }
                else
                {
                    resource.Read(fileName);
                }

                var resTabs = new TabControl
                {
                    Dock = DockStyle.Fill,
                };

                switch (resource.ResourceType)
                {
                case ResourceType.Texture:
                    var tab2 = new TabPage("TEXTURE")
                    {
                        AutoScroll = true,
                    };

                    try
                    {
                        var tex = (Texture)resource.DataBlock;

                        var control = new Forms.Texture
                        {
                            BackColor = Color.Black,
                        };
                        control.SetImage(tex.GenerateBitmap().ToBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height);

                        tab2.Controls.Add(control);
                        Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as an image", fileName, new ExportData {
                            Resource = resource
                        });
                    }
                    catch (Exception e)
                    {
                        var control = new TextBox
                        {
                            Dock      = DockStyle.Fill,
                            Font      = new Font(FontFamily.GenericMonospace, 8),
                            Multiline = true,
                            ReadOnly  = true,
                            Text      = e.ToString(),
                        };

                        tab2.Controls.Add(control);
                    }

                    resTabs.TabPages.Add(tab2);
                    break;

                case ResourceType.Panorama:
                    if (((Panorama)resource.DataBlock).Names.Count > 0)
                    {
                        var nameTab     = new TabPage("PANORAMA NAMES");
                        var nameControl = new DataGridView
                        {
                            Dock                = DockStyle.Fill,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <Panorama.NameEntry>(((Panorama)resource.DataBlock).Names), null),
                        };
                        nameTab.Controls.Add(nameControl);
                        resTabs.TabPages.Add(nameTab);
                    }

                    break;

                case ResourceType.PanoramaLayout:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as XML", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaScript:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as JS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaStyle:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as CSS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.Particle:
                    var viewerControl = new GLParticleViewer(vrfGuiContext);
                    viewerControl.Load += (_, __) =>
                    {
                        var particleSystem   = (ParticleSystem)resource.DataBlock;
                        var particleRenderer = new ParticleRenderer(particleSystem, vrfGuiContext);

                        viewerControl.AddRenderer(particleRenderer);
                    };

                    var particleRendererTab = new TabPage("PARTICLE");
                    particleRendererTab.Controls.Add(viewerControl.Control);
                    resTabs.TabPages.Add(particleRendererTab);
                    break;

                case ResourceType.Sound:
                    var soundTab = new TabPage("SOUND");
                    var ap       = new AudioPlayer(resource, soundTab);
                    resTabs.TabPages.Add(soundTab);

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as {((Sound)resource.DataBlock).SoundType}", fileName, new ExportData {
                        Resource = resource
                    });

                    break;

                case ResourceType.World:
                    var worldmeshTab = new TabPage("MAP");
                    worldmeshTab.Controls.Add(new GLWorldViewer(vrfGuiContext, (World)resource.DataBlock).ViewerControl);
                    resTabs.TabPages.Add(worldmeshTab);
                    break;

                case ResourceType.WorldNode:
                    var nodemeshTab = new TabPage("WORLD NODE");
                    nodemeshTab.Controls.Add(new GLWorldViewer(vrfGuiContext, (WorldNode)resource.DataBlock).ViewerControl);
                    resTabs.TabPages.Add(nodemeshTab);
                    break;

                case ResourceType.Model:
                    var modelRendererTab = new TabPage("MODEL");
                    modelRendererTab.Controls.Add(new GLModelViewer(vrfGuiContext, (Model)resource.DataBlock).ViewerControl);
                    resTabs.TabPages.Add(modelRendererTab);
                    break;

                case ResourceType.Mesh:
                    if (!resource.ContainsBlockType(BlockType.VBIB))
                    {
                        Console.WriteLine("Old style model, no VBIB!");
                        break;
                    }

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as OBJ", fileName, new ExportData {
                        Resource = resource, VrfGuiContext = vrfGuiContext
                    });

                    var meshRendererTab = new TabPage("MESH");
                    meshRendererTab.Controls.Add(new GLModelViewer(vrfGuiContext, new Mesh(resource)).ViewerControl);
                    resTabs.TabPages.Add(meshRendererTab);
                    break;

                case ResourceType.Material:
                    var materialViewerControl = new GLMaterialViewer();
                    materialViewerControl.Load += (_, __) =>
                    {
                        var material         = vrfGuiContext.MaterialLoader.LoadMaterial(resource);
                        var materialRenderer = new MaterialRenderer(material, vrfGuiContext);

                        materialViewerControl.AddRenderer(materialRenderer);
                    };

                    var materialRendererTab = new TabPage("MATERIAL");
                    materialRendererTab.Controls.Add(materialViewerControl.Control);
                    resTabs.TabPages.Add(materialRendererTab);
                    break;
                }

                foreach (var block in resource.Blocks)
                {
                    if (block.Type == BlockType.RERL)
                    {
                        var externalRefsTab = new TabPage("External Refs");

                        var externalRefs = new DataGridView
                        {
                            Dock = DockStyle.Fill,
                            AutoGenerateColumns = true,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null),
                        };

                        externalRefsTab.Controls.Add(externalRefs);

                        resTabs.TabPages.Add(externalRefsTab);

                        continue;
                    }

                    if (block.Type == BlockType.NTRO)
                    {
                        if (((ResourceIntrospectionManifest)block).ReferencedStructs.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Structs");

                            var externalRefs = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block).ReferencedStructs), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        if (((ResourceIntrospectionManifest)block).ReferencedEnums.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Enums");
                            var externalRefs2   = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block).ReferencedEnums), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs2);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        //continue;
                    }

                    var tab2 = new TabPage(block.Type.ToString());
                    try
                    {
                        var control = new TextBox();
                        control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size);

                        if (block.Type == BlockType.DATA)
                        {
                            switch (resource.ResourceType)
                            {
                            case ResourceType.Sound:
                                control.Text = NormalizeLineEndings(((Sound)block).ToString());
                                break;

                            case ResourceType.Particle:
                            case ResourceType.Mesh:
                                if (block is BinaryKV3 blockKeyvalues)
                                {
                                    //Wrap it around a KV3File object to get the header.
                                    control.Text = NormalizeLineEndings(blockKeyvalues.GetKV3File().ToString());
                                }
                                else if (block is NTRO blockNTRO)
                                {
                                    control.Text = NormalizeLineEndings(blockNTRO.ToString());
                                }

                                break;

                            default:
                                control.Text = NormalizeLineEndings(block.ToString());
                                break;
                            }
                        }
                        else
                        {
                            control.Text = NormalizeLineEndings(block.ToString());
                        }

                        control.Dock       = DockStyle.Fill;
                        control.Multiline  = true;
                        control.ReadOnly   = true;
                        control.ScrollBars = ScrollBars.Both;
                        tab2.Controls.Add(control);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);

                        var bv = new ByteViewer();
                        bv.Dock = DockStyle.Fill;
                        tab2.Controls.Add(bv);

                        Invoke((MethodInvoker)(() =>
                        {
                            resource.Reader.BaseStream.Position = block.Offset;
                            bv.SetBytes(resource.Reader.ReadBytes((int)block.Size));
                        }));
                    }

                    resTabs.TabPages.Add(tab2);
                }

                if (resource.ResourceType == ResourceType.PanoramaLayout ||
                    resource.ResourceType == ResourceType.PanoramaScript ||
                    resource.ResourceType == ResourceType.PanoramaStyle ||
                    resource.ResourceType == ResourceType.SoundEventScript ||
                    resource.ResourceType == ResourceType.SoundStackScript ||
                    resource.ResourceType == ResourceType.EntityLump)
                {
                    resTabs.SelectTab(resTabs.TabCount - 1);
                }

                tab.Controls.Add(resTabs);
            }
            else
            {
                var resTabs = new TabControl
                {
                    Dock = DockStyle.Fill,
                };
                tab.Controls.Add(resTabs);

                var bvTab = new TabPage("Hex");
                var bv    = new ByteViewer
                {
                    Dock = DockStyle.Fill,
                };
                bvTab.Controls.Add(bv);
                resTabs.TabPages.Add(bvTab);

                if (input == null)
                {
                    input = File.ReadAllBytes(fileName);
                }

                if (!input.Contains <byte>(0x00))
                {
                    var textTab = new TabPage("Text");
                    var text    = new TextBox
                    {
                        Dock       = DockStyle.Fill,
                        ScrollBars = ScrollBars.Vertical,
                        Multiline  = true,
                        ReadOnly   = true,
                        Text       = System.Text.Encoding.UTF8.GetString(input),
                    };
                    textTab.Controls.Add(text);
                    resTabs.TabPages.Add(textTab);
                    resTabs.SelectedTab = textTab;
                }

                Invoke((MethodInvoker)(() =>
                {
                    bv.SetBytes(input);
                }));
            }

            return(tab);
        }
コード例 #3
0
        private TabPage ProcessFile(string fileName, byte[] input, Package currentPackage)
        {
            var tab           = new TabPage();
            var vrfGuiContext = new VrfGuiContext
            {
                FileName       = fileName,
                CurrentPackage = currentPackage,
            };

            uint   magic = 0;
            ushort magicResourceVersion = 0;

            if (input != null)
            {
                magic = BitConverter.ToUInt32(input, 0);
                magicResourceVersion = BitConverter.ToUInt16(input, 4);
            }
            else
            {
                var magicData = new byte[6];

                using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    fs.Read(magicData, 0, 6);
                }

                magic = BitConverter.ToUInt32(magicData, 0);
                magicResourceVersion = BitConverter.ToUInt16(magicData, 4);
            }

            if (magic != Package.MAGIC && input == null && Regex.IsMatch(fileName, @"_[0-9]{3}\.vpk$"))
            {
                // TODO: Update tab name
                fileName = $"{fileName.Substring(0, fileName.Length - 8)}_dir.vpk";
                magic    = Package.MAGIC;
            }

            if (magic == Package.MAGIC || fileName.EndsWith(".vpk", StringComparison.Ordinal))
            {
                var package = new Package();

                if (input != null)
                {
                    package.SetFileName(fileName);
                    package.Read(new MemoryStream(input));
                }
                else
                {
                    package.Read(fileName);
                }

                // create a TreeView with search capabilities, register its events, and add it to the tab
                var treeViewWithSearch = new TreeViewWithSearchResults(ImageList)
                {
                    Dock = DockStyle.Fill,
                };
                treeViewWithSearch.InitializeTreeViewFromPackage("treeViewVpk", package);
                treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile;
                treeViewWithSearch.TreeNodeMouseClick       += VPK_OnClick;
                treeViewWithSearch.ListViewItemDoubleClick  += VPK_OpenFile;
                treeViewWithSearch.ListViewItemRightClick   += VPK_OnClick;
                tab.Controls.Add(treeViewWithSearch);

                // since we're in a separate thread, invoke to update the UI
                Invoke((MethodInvoker)(() => findToolStripButton.Enabled = true));
            }
            else if (magic == CompiledShader.MAGIC || fileName.EndsWith(".vcs", StringComparison.Ordinal))
            {
                var shader = new CompiledShader();

                var buffer = new StringWriter();
                var oldOut = Console.Out;
                Console.SetOut(buffer);

                if (input != null)
                {
                    shader.Read(fileName, new MemoryStream(input));
                }
                else
                {
                    shader.Read(fileName);
                }

                Console.SetOut(oldOut);

                var control = new TextBox();
                control.Font       = new Font(FontFamily.GenericMonospace, control.Font.Size);
                control.Text       = NormalizeLineEndings(buffer.ToString());
                control.Dock       = DockStyle.Fill;
                control.Multiline  = true;
                control.ReadOnly   = true;
                control.ScrollBars = ScrollBars.Both;
                tab.Controls.Add(control);
            }
            else if (magic == ClosedCaptions.MAGIC || fileName.EndsWith(".dat", StringComparison.Ordinal))
            {
                var captions = new ClosedCaptions();
                if (input != null)
                {
                    captions.Read(fileName, new MemoryStream(input));
                }
                else
                {
                    captions.Read(fileName);
                }

                var control = new DataGridView
                {
                    Dock                = DockStyle.Fill,
                    AutoSize            = true,
                    ReadOnly            = true,
                    AllowUserToAddRows  = false,
                    AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                    DataSource          = new BindingSource(new BindingList <ClosedCaption>(captions.Captions), null),
                    ScrollBars          = ScrollBars.Both,
                };
                tab.Controls.Add(control);
            }
            else if (magic == BinaryKV3.MAGIC || magic == BinaryKV3.MAGIC2)
            {
                var kv3 = new BinaryKV3();

                using (var file = File.OpenRead(fileName))
                    using (var binaryReader = new BinaryReader(file))
                    {
                        kv3.Size = (uint)file.Length;
                        kv3.Read(binaryReader, null);
                    }

                var control = new TextBox();
                control.Font       = new Font(FontFamily.GenericMonospace, control.Font.Size);
                control.Text       = kv3.ToString();
                control.Dock       = DockStyle.Fill;
                control.Multiline  = true;
                control.ReadOnly   = true;
                control.ScrollBars = ScrollBars.Both;
                tab.Controls.Add(control);
            }
            else if (magicResourceVersion == Resource.KnownHeaderVersion || fileName.EndsWith("_c", StringComparison.Ordinal))
            {
                var resource = new Resource();
                if (input != null)
                {
                    resource.Read(new MemoryStream(input));
                }
                else
                {
                    resource.Read(fileName);
                }

                var resTabs = new TabControl
                {
                    Dock = DockStyle.Fill,
                };

                switch (resource.ResourceType)
                {
                case ResourceType.Texture:
                    var tab2 = new TabPage("TEXTURE")
                    {
                        AutoScroll = true,
                    };

                    try
                    {
                        var tex = (Texture)resource.Blocks[BlockType.DATA];

                        var control = new Forms.Texture
                        {
                            BackColor = Color.Black,
                        };
                        control.SetImage(tex.GenerateBitmap().ToBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height);

                        tab2.Controls.Add(control);
                        Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as an image", fileName, new ExportData {
                            Resource = resource
                        });
                    }
                    catch (Exception e)
                    {
                        var control = new TextBox
                        {
                            Dock      = DockStyle.Fill,
                            Font      = new Font(FontFamily.GenericMonospace, 8),
                            Multiline = true,
                            ReadOnly  = true,
                            Text      = e.ToString(),
                        };

                        tab2.Controls.Add(control);
                    }

                    resTabs.TabPages.Add(tab2);
                    break;

                case ResourceType.Panorama:
                    if (((Panorama)resource.Blocks[BlockType.DATA]).Names.Count > 0)
                    {
                        var nameTab     = new TabPage("PANORAMA NAMES");
                        var nameControl = new DataGridView
                        {
                            Dock                = DockStyle.Fill,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <Panorama.NameEntry>(((Panorama)resource.Blocks[BlockType.DATA]).Names), null),
                        };
                        nameTab.Controls.Add(nameControl);
                        resTabs.TabPages.Add(nameTab);
                    }

                    break;

                case ResourceType.PanoramaLayout:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as XML", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaScript:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as JS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaStyle:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as CSS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.Particle:
                    var particleGLControl = new GLRenderControl();
                    particleGLControl.Load += (_, __) =>
                    {
                        particleGLControl.Camera.SetViewportSize(particleGLControl.Control.Width, particleGLControl.Control.Height);
                        particleGLControl.Camera.SetLocation(new Vector3(200));
                        particleGLControl.Camera.LookAt(new Vector3(0));

                        var particleSystem   = new ParticleSystem(resource);
                        var particleGrid     = new ParticleGrid(20, 5);
                        var particleRenderer = new ParticleRenderer(particleSystem, vrfGuiContext);

                        particleGLControl.Paint += (sender, args) =>
                        {
                            particleGrid.Render(args.Camera.ProjectionMatrix, args.Camera.CameraViewMatrix);

                            // Updating FPS-coupled dynamic step
                            particleRenderer.Update(args.FrameTime);
                            particleRenderer.Render(args.Camera);
                        };
                    };

                    var particleRendererTab = new TabPage("PARTICLE");
                    particleRendererTab.Controls.Add(particleGLControl.Control);
                    resTabs.TabPages.Add(particleRendererTab);
                    break;

                case ResourceType.Sound:
                    var soundTab = new TabPage("SOUND");
                    var ap       = new AudioPlayer(resource, soundTab);
                    resTabs.TabPages.Add(soundTab);

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as {((Sound)resource.Blocks[BlockType.DATA]).Type}", fileName, new ExportData {
                        Resource = resource
                    });

                    break;

                case ResourceType.World:
                    var world       = new World(resource);
                    var renderWorld = new RenderWorld(world);
                    var worldmv     = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.World);
                    renderWorld.AddObjects(worldmv, fileName, currentPackage);

                    var worldmeshTab   = new TabPage("MAP");
                    var worldglControl = worldmv.CreateGL();
                    worldmeshTab.Controls.Add(worldglControl);
                    resTabs.TabPages.Add(worldmeshTab);
                    break;

                case ResourceType.WorldNode:
                    var node   = new RenderWorldNode(resource);
                    var nodemv = new Renderer(mainTabs, fileName, currentPackage);
                    node.AddMeshes(nodemv, fileName, currentPackage);

                    var nodemeshTab   = new TabPage("MAP");
                    var nodeglControl = nodemv.CreateGL();
                    nodemeshTab.Controls.Add(nodeglControl);
                    resTabs.TabPages.Add(nodemeshTab);
                    break;

                case ResourceType.Model:
                    // Create model
                    var model       = new Model(resource);
                    var renderModel = new RenderModel(model);

                    // Create skeleton
                    var skeleton = model.GetSkeleton();

                    // Create tab
                    var modelmeshTab = new TabPage("MESH");
                    var modelmv      = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.Model);
                    renderModel.LoadMeshes(modelmv, fileName, Matrix4.Identity, Vector4.One, currentPackage);

                    // Add skeleton to renderer
                    modelmv.SetSkeleton(skeleton);

                    // Add animations if available
                    var animGroupPaths = renderModel.GetAnimationGroups();
                    foreach (var animGroupPath in animGroupPaths)
                    {
                        var animGroup = FileExtensions.LoadFileByAnyMeansNecessary(animGroupPath + "_c", fileName, currentPackage);

                        modelmv.AddAnimations(AnimationGroupLoader.LoadAnimationGroup(animGroup, fileName));
                    }

                    //Initialise OpenGL
                    var modelglControl = modelmv.CreateGL();
                    modelmeshTab.Controls.Add(modelglControl);
                    resTabs.TabPages.Add(modelmeshTab);
                    break;

                case ResourceType.Mesh:
                    if (!resource.Blocks.ContainsKey(BlockType.VBIB))
                    {
                        Console.WriteLine("Old style model, no VBIB!");
                        break;
                    }

                    var meshTab = new TabPage("MESH");
                    var mv      = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.Model);

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as OBJ", fileName, new ExportData {
                        Resource = resource, Renderer = mv
                    });

                    mv.AddMeshObject(new MeshObject {
                        Resource = resource
                    });
                    var glControl = mv.CreateGL();
                    meshTab.Controls.Add(glControl);
                    resTabs.TabPages.Add(meshTab);
                    break;
                }

                foreach (var block in resource.Blocks)
                {
                    if (block.Key == BlockType.RERL)
                    {
                        var externalRefsTab = new TabPage("External Refs");

                        var externalRefs = new DataGridView
                        {
                            Dock = DockStyle.Fill,
                            AutoGenerateColumns = true,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null),
                        };

                        externalRefsTab.Controls.Add(externalRefs);

                        resTabs.TabPages.Add(externalRefsTab);

                        continue;
                    }

                    if (block.Key == BlockType.NTRO)
                    {
                        if (((ResourceIntrospectionManifest)block.Value).ReferencedStructs.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Structs");

                            var externalRefs = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block.Value).ReferencedStructs), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        if (((ResourceIntrospectionManifest)block.Value).ReferencedEnums.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Enums");
                            var externalRefs2   = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block.Value).ReferencedEnums), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs2);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        //continue;
                    }

                    var tab2 = new TabPage(block.Key.ToString());
                    try
                    {
                        var control = new TextBox();
                        control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size);

                        if (block.Key == BlockType.DATA)
                        {
                            switch (resource.ResourceType)
                            {
                            case ResourceType.Particle:
                            case ResourceType.Mesh:
                                //Wrap it around a KV3File object to get the header.
                                control.Text = NormalizeLineEndings(((BinaryKV3)block.Value).GetKV3File().ToString());
                                break;

                            default:
                                control.Text = NormalizeLineEndings(block.Value.ToString());
                                break;
                            }
                        }
                        else
                        {
                            control.Text = NormalizeLineEndings(block.Value.ToString());
                        }

                        control.Dock       = DockStyle.Fill;
                        control.Multiline  = true;
                        control.ReadOnly   = true;
                        control.ScrollBars = ScrollBars.Both;
                        tab2.Controls.Add(control);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);

                        var bv = new ByteViewer();
                        bv.Dock = DockStyle.Fill;
                        tab2.Controls.Add(bv);

                        Invoke((MethodInvoker)(() =>
                        {
                            resource.Reader.BaseStream.Position = block.Value.Offset;
                            bv.SetBytes(resource.Reader.ReadBytes((int)block.Value.Size));
                        }));
                    }

                    resTabs.TabPages.Add(tab2);
                }

                tab.Controls.Add(resTabs);
            }
            else
            {
                var resTabs = new TabControl
                {
                    Dock = DockStyle.Fill,
                };
                tab.Controls.Add(resTabs);

                var bvTab = new TabPage("Hex");
                var bv    = new ByteViewer
                {
                    Dock = DockStyle.Fill,
                };
                bvTab.Controls.Add(bv);
                resTabs.TabPages.Add(bvTab);

                if (input != null && !input.Contains <byte>(0x00))
                {
                    var textTab = new TabPage("Text");
                    var text    = new TextBox
                    {
                        Dock       = DockStyle.Fill,
                        ScrollBars = ScrollBars.Vertical,
                        Multiline  = true,
                        ReadOnly   = true,
                        Text       = System.Text.Encoding.UTF8.GetString(input),
                    };
                    textTab.Controls.Add(text);
                    resTabs.TabPages.Add(textTab);
                    resTabs.SelectedTab = textTab;
                }

                Invoke((MethodInvoker)(() =>
                {
                    if (input != null)
                    {
                        bv.SetBytes(input);
                    }
                    else
                    {
                        bv.SetFile(fileName);
                    }
                }));
            }

            return(tab);
        }
コード例 #4
0
        private TabPage ProcessFile(string fileName, byte[] input, Package currentPackage)
        {
            var tab = new TabPage();

            if (fileName.EndsWith(".vpk", StringComparison.Ordinal))
            {
                var package = new Package();

                try
                {
                    if (input != null)
                    {
                        package.SetFileName(fileName);
                        package.Read(new MemoryStream(input));
                    }
                    else
                    {
                        package.Read(fileName);
                    }
                }
                catch (InvalidDataException) when(input == null && Regex.IsMatch(fileName, @"_[0-9]{3}\.vpk$"))
                {
                    // TODO: Update tab name
                    fileName = $"{fileName.Substring(0, fileName.Length - 8)}_dir.vpk";

                    package.Read(fileName);
                }

                // create a TreeView with search capabilities, register its events, and add it to the tab
                var treeViewWithSearch = new TreeViewWithSearchResults(ImageList)
                {
                    Dock = DockStyle.Fill,
                };
                treeViewWithSearch.InitializeTreeViewFromPackage("treeViewVpk", package);
                treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile;
                treeViewWithSearch.TreeNodeMouseClick       += VPK_OnClick;
                treeViewWithSearch.ListViewItemDoubleClick  += VPK_OpenFile;
                treeViewWithSearch.ListViewItemRightClick   += VPK_OnClick;
                tab.Controls.Add(treeViewWithSearch);

                // since we're in a separate thread, invoke to update the UI
                Invoke((MethodInvoker)(() => findToolStripButton.Enabled = true));
            }
            else if (fileName.EndsWith(".vcs", StringComparison.Ordinal))
            {
                var shader = new CompiledShader();

                var buffer = new StringWriter();
                var oldOut = Console.Out;
                Console.SetOut(buffer);

                if (input != null)
                {
                    shader.Read(fileName, new MemoryStream(input));
                }
                else
                {
                    shader.Read(fileName);
                }

                Console.SetOut(oldOut);

                var control = new TextBox();
                control.Font       = new Font(FontFamily.GenericMonospace, control.Font.Size);
                control.Text       = NormalizeLineEndings(buffer.ToString());
                control.Dock       = DockStyle.Fill;
                control.Multiline  = true;
                control.ReadOnly   = true;
                control.ScrollBars = ScrollBars.Both;
                tab.Controls.Add(control);
            }
            else
            {
                var resource = new Resource();
                if (input != null)
                {
                    resource.Read(new MemoryStream(input));
                }
                else
                {
                    resource.Read(fileName);
                }

                var resTabs = new TabControl
                {
                    Dock = DockStyle.Fill,
                };

                switch (resource.ResourceType)
                {
                case ResourceType.Texture:
                    var tab2 = new TabPage("TEXTURE")
                    {
                        AutoScroll = true,
                    };

                    try
                    {
                        var tex = (Texture)resource.Blocks[BlockType.DATA];

                        var control = new Forms.Texture
                        {
                            BackColor = Color.Black,
                        };
                        control.SetImage(tex.GenerateBitmap().ToBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height);

                        tab2.Controls.Add(control);
                        Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as an image", fileName, new ExportData {
                            Resource = resource
                        });
                    }
                    catch (Exception e)
                    {
                        var control = new TextBox
                        {
                            Dock      = DockStyle.Fill,
                            Font      = new Font(FontFamily.GenericMonospace, 8),
                            Multiline = true,
                            ReadOnly  = true,
                            Text      = e.ToString(),
                        };

                        tab2.Controls.Add(control);
                    }

                    resTabs.TabPages.Add(tab2);
                    break;

                case ResourceType.Panorama:
                    if (((Panorama)resource.Blocks[BlockType.DATA]).Names.Count > 0)
                    {
                        var nameTab     = new TabPage("PANORAMA NAMES");
                        var nameControl = new DataGridView
                        {
                            Dock                = DockStyle.Fill,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <Panorama.NameEntry>(((Panorama)resource.Blocks[BlockType.DATA]).Names), null),
                        };
                        nameTab.Controls.Add(nameControl);
                        resTabs.TabPages.Add(nameTab);
                    }

                    break;

                case ResourceType.PanoramaLayout:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as XML", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaScript:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as JS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.PanoramaStyle:
                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as CSS", fileName, new ExportData {
                        Resource = resource
                    });
                    break;

                case ResourceType.Sound:
                    var soundTab = new TabPage("SOUND");
                    var ap       = new AudioPlayer(resource, soundTab);
                    resTabs.TabPages.Add(soundTab);

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as {((Sound)resource.Blocks[BlockType.DATA]).Type}", fileName, new ExportData {
                        Resource = resource
                    });

                    break;

                case ResourceType.World:
                    var world   = new World(resource);
                    var worldmv = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.World);
                    world.AddObjects(worldmv, fileName, currentPackage);

                    var worldmeshTab   = new TabPage("MAP");
                    var worldglControl = worldmv.CreateGL();
                    worldmeshTab.Controls.Add(worldglControl);
                    resTabs.TabPages.Add(worldmeshTab);
                    break;

                case ResourceType.WorldNode:
                    var node   = new WorldNode(resource);
                    var nodemv = new Renderer(mainTabs, fileName, currentPackage);
                    node.AddMeshes(nodemv, fileName, currentPackage);

                    var nodemeshTab   = new TabPage("MAP");
                    var nodeglControl = nodemv.CreateGL();
                    nodemeshTab.Controls.Add(nodeglControl);
                    resTabs.TabPages.Add(nodemeshTab);
                    break;

                case ResourceType.Model:
                    // Create model
                    var model = new Model(resource);

                    // Create skeleton
                    var skeleton = new Skeleton(resource);

                    // Create tab
                    var modelmeshTab = new TabPage("MESH");
                    var modelmv      = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.Model);
                    model.LoadMeshes(modelmv, fileName, Matrix4.Identity, Vector4.One, currentPackage);

                    // Add skeleton to renderer
                    modelmv.SetSkeleton(skeleton);

                    // Add animations if available
                    var animGroupPaths = model.GetAnimationGroups();
                    foreach (var animGroupPath in animGroupPaths)
                    {
                        var animGroup = FileExtensions.LoadFileByAnyMeansNecessary(animGroupPath + "_c", fileName, currentPackage);

                        modelmv.AddAnimations(AnimationGroupLoader.LoadAnimationGroup(animGroup, fileName));
                    }

                    //Initialise OpenGL
                    var modelglControl = modelmv.CreateGL();
                    modelmeshTab.Controls.Add(modelglControl);
                    resTabs.TabPages.Add(modelmeshTab);
                    break;

                case ResourceType.Mesh:
                    if (!resource.Blocks.ContainsKey(BlockType.VBIB))
                    {
                        Console.WriteLine("Old style model, no VBIB!");
                        break;
                    }

                    var meshTab = new TabPage("MESH");
                    var mv      = new Renderer(mainTabs, fileName, currentPackage, RenderSubject.Model);

                    Invoke(new ExportDel(AddToExport), $"Export {Path.GetFileName(fileName)} as OBJ", fileName, new ExportData {
                        Resource = resource, Renderer = mv
                    });

                    mv.AddMeshObject(new MeshObject {
                        Resource = resource
                    });
                    var glControl = mv.CreateGL();
                    meshTab.Controls.Add(glControl);
                    resTabs.TabPages.Add(meshTab);
                    break;
                }

                foreach (var block in resource.Blocks)
                {
                    if (block.Key == BlockType.RERL)
                    {
                        var externalRefsTab = new TabPage("External Refs");

                        var externalRefs = new DataGridView
                        {
                            Dock = DockStyle.Fill,
                            AutoGenerateColumns = true,
                            AutoSize            = true,
                            ReadOnly            = true,
                            AllowUserToAddRows  = false,
                            AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                            DataSource          = new BindingSource(new BindingList <ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null),
                        };

                        externalRefsTab.Controls.Add(externalRefs);

                        resTabs.TabPages.Add(externalRefsTab);

                        continue;
                    }

                    if (block.Key == BlockType.NTRO)
                    {
                        if (((ResourceIntrospectionManifest)block.Value).ReferencedStructs.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Structs");

                            var externalRefs = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block.Value).ReferencedStructs), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        if (((ResourceIntrospectionManifest)block.Value).ReferencedEnums.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Enums");
                            var externalRefs2   = new DataGridView
                            {
                                Dock = DockStyle.Fill,
                                AutoGenerateColumns = true,
                                AutoSize            = true,
                                ReadOnly            = true,
                                AllowUserToAddRows  = false,
                                AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
                                DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block.Value).ReferencedEnums), null),
                            };

                            externalRefsTab.Controls.Add(externalRefs2);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        //continue;
                    }

                    var tab2    = new TabPage(block.Key.ToString());
                    var control = new TextBox();
                    control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size);
                    try
                    {
                        if (block.Key == BlockType.DATA)
                        {
                            switch (resource.ResourceType)
                            {
                            case ResourceType.Particle:
                            case ResourceType.Mesh:
                                //Wrap it around a KV3File object to get the header.
                                control.Text = NormalizeLineEndings(new KV3File(((BinaryKV3)block.Value).Data).ToString());
                                break;

                            default:
                                control.Text = NormalizeLineEndings(block.Value.ToString());
                                break;
                            }
                        }
                        else
                        {
                            control.Text = NormalizeLineEndings(block.Value.ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        control.Text = e.ToString();
                    }

                    control.Dock       = DockStyle.Fill;
                    control.Multiline  = true;
                    control.ReadOnly   = true;
                    control.ScrollBars = ScrollBars.Both;
                    tab2.Controls.Add(control);
                    resTabs.TabPages.Add(tab2);
                }

                tab.Controls.Add(resTabs);
            }

            return(tab);
        }
コード例 #5
0
        private TabPage ProcessFile(string fileName, byte[] input, Package currentPackage)
        {
            var tab = new TabPage();

            if (fileName.EndsWith(".vpk", StringComparison.Ordinal))
            {
                var package = new Package();
                if (input != null)
                {
                    package.SetFileName(fileName);
                    package.Read(new MemoryStream(input));
                }
                else
                {
                    package.Read(fileName);
                }

                // create a TreeView with search capabilities, register its events, and add it to the tab
                var treeViewWithSearch = new TreeViewWithSearchResults(ImageList);
                treeViewWithSearch.Dock = DockStyle.Fill;
                treeViewWithSearch.InitializeTreeViewFromPackage("treeViewVpk", package);
                treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile;
                treeViewWithSearch.TreeNodeMouseClick       += VPK_OnClick;
                treeViewWithSearch.ListViewItemDoubleClick  += VPK_OpenFile;
                treeViewWithSearch.ListViewItemRightClick   += VPK_OnClick;
                tab.Controls.Add(treeViewWithSearch);

                // since we're in a separate thread, invoke to update the UI
                Invoke((MethodInvoker)(() => findToolStripButton.Enabled = true));
            }
            else
            {
                var resource = new Resource();
                if (input != null)
                {
                    resource.Read(new MemoryStream(input));
                }
                else
                {
                    resource.Read(fileName);
                }

                var resTabs = new TabControl();
                resTabs.Dock = DockStyle.Fill;

                switch (resource.ResourceType)
                {
                case ResourceType.Texture:
                    var tab2 = new TabPage("TEXTURE");
                    tab2.AutoScroll = true;

                    try
                    {
                        var tex = (Texture)resource.Blocks[BlockType.DATA];

                        var control = new Forms.Texture();
                        control.BackColor = Color.Black;
                        control.SetImage(tex.GenerateBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height);

                        tab2.Controls.Add(control);
                        Invoke(new ExportDel(AddToExport), new object[] { $"Export {Path.GetFileName(fileName)} as an image", fileName, resource });
                    }
                    catch (Exception e)
                    {
                        var control = new TextBox
                        {
                            Dock      = DockStyle.Fill,
                            Font      = new Font(FontFamily.GenericMonospace, 8),
                            Multiline = true,
                            ReadOnly  = true,
                            Text      = e.ToString()
                        };

                        tab2.Controls.Add(control);
                    }

                    resTabs.TabPages.Add(tab2);
                    break;

                case ResourceType.Panorama:
                    if (((Panorama)resource.Blocks[BlockType.DATA]).Names.Count > 0)
                    {
                        var nameTab     = new TabPage("PANORAMA NAMES");
                        var nameControl = new DataGridView();
                        nameControl.Dock                = DockStyle.Fill;
                        nameControl.AutoSize            = true;
                        nameControl.ReadOnly            = true;
                        nameControl.AllowUserToAddRows  = false;
                        nameControl.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                        nameControl.DataSource          = new BindingSource(new BindingList <Panorama.NameEntry>(((Panorama)resource.Blocks[BlockType.DATA]).Names), null);
                        nameTab.Controls.Add(nameControl);
                        resTabs.TabPages.Add(nameTab);
                    }

                    break;

                case ResourceType.PanoramaLayout:
                    Invoke(new ExportDel(AddToExport), new object[] { $"Export {Path.GetFileName(fileName)} as XML", fileName, resource });
                    break;

                case ResourceType.PanoramaScript:
                    Invoke(new ExportDel(AddToExport), new object[] { $"Export {Path.GetFileName(fileName)} as JS", fileName, resource });
                    break;

                case ResourceType.PanoramaStyle:
                    Invoke(new ExportDel(AddToExport), new object[] { $"Export {Path.GetFileName(fileName)} as CSS", fileName, resource });
                    break;

                case ResourceType.Sound:
                    var soundTab = new TabPage("SOUND");
                    var ap       = new AudioPlayer(resource, soundTab);
                    resTabs.TabPages.Add(soundTab);

                    Invoke(new ExportDel(AddToExport), new object[] { $"Export {Path.GetFileName(fileName)} as {((Sound)resource.Blocks[BlockType.DATA]).Type}", fileName, resource });

                    break;

                case ResourceType.Model:
                    var model = new Model(resource);

                    var animGroupPath = model.GetAnimationGroup();
                    if (!string.IsNullOrEmpty(animGroupPath))
                    {
                        var animGroup = new Resource();
                        animGroup.Read(animGroupPath);

                        var animGroupLoader = new AnimationGroupLoader(animGroup, fileName);
                    }

                    var resourceMesh = new Resource();
                    model.GetMesh(resourceMesh, currentPackage);

                    if (!resourceMesh.Blocks.ContainsKey(BlockType.VBIB))
                    {
                        Console.WriteLine("Old style model, no VBIB!");
                        break;
                    }

                    var modelmeshTab   = new TabPage("MESH");
                    var modelmv        = new Renderer(resourceMesh, mainTabs, fileName, currentPackage);
                    var modelglControl = modelmv.CreateGL();
                    modelmeshTab.Controls.Add(modelglControl);
                    resTabs.TabPages.Add(modelmeshTab);
                    break;

                case ResourceType.Mesh:
                    if (!resource.Blocks.ContainsKey(BlockType.VBIB))
                    {
                        Console.WriteLine("Old style model, no VBIB!");
                        break;
                    }

                    var meshTab   = new TabPage("MESH");
                    var mv        = new Renderer(resource, mainTabs, fileName, currentPackage);
                    var glControl = mv.CreateGL();
                    meshTab.Controls.Add(glControl);
                    resTabs.TabPages.Add(meshTab);
                    break;
                }

                foreach (var block in resource.Blocks)
                {
                    if (block.Key == BlockType.RERL)
                    {
                        var externalRefsTab = new TabPage("External Refs");

                        var externalRefs = new DataGridView();
                        externalRefs.Dock = DockStyle.Fill;
                        externalRefs.AutoGenerateColumns = true;
                        externalRefs.AutoSize            = true;
                        externalRefs.ReadOnly            = true;
                        externalRefs.AllowUserToAddRows  = false;
                        externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                        externalRefs.DataSource          = new BindingSource(new BindingList <ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null);

                        externalRefsTab.Controls.Add(externalRefs);

                        resTabs.TabPages.Add(externalRefsTab);

                        continue;
                    }

                    if (block.Key == BlockType.NTRO)
                    {
                        if (((ResourceIntrospectionManifest)block.Value).ReferencedStructs.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Structs");

                            var externalRefs = new DataGridView();
                            externalRefs.Dock = DockStyle.Fill;
                            externalRefs.AutoGenerateColumns = true;
                            externalRefs.AutoSize            = true;
                            externalRefs.ReadOnly            = true;
                            externalRefs.AllowUserToAddRows  = false;
                            externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                            externalRefs.DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block.Value).ReferencedStructs), null);

                            externalRefsTab.Controls.Add(externalRefs);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        if (((ResourceIntrospectionManifest)block.Value).ReferencedEnums.Count > 0)
                        {
                            var externalRefsTab = new TabPage("Introspection Manifest: Enums");
                            var externalRefs2   = new DataGridView();
                            externalRefs2.Dock = DockStyle.Fill;
                            externalRefs2.AutoGenerateColumns = true;
                            externalRefs2.AutoSize            = true;
                            externalRefs2.ReadOnly            = true;
                            externalRefs2.AllowUserToAddRows  = false;
                            externalRefs2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                            externalRefs2.DataSource          = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block.Value).ReferencedEnums), null);

                            externalRefsTab.Controls.Add(externalRefs2);
                            resTabs.TabPages.Add(externalRefsTab);
                        }

                        //continue;
                    }

                    var tab2    = new TabPage(block.Key.ToString());
                    var control = new TextBox();
                    control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size);
                    try
                    {
                        if (block.Key == BlockType.DATA)
                        {
                            switch (resource.ResourceType)
                            {
                            case ResourceType.Particle:
                            case ResourceType.Mesh:
                                //Wrap it around a KV3File object to get the header.
                                control.Text = NormalizeLineEndings(new KV3File(((BinaryKV3)block.Value).Data).ToString());
                                break;

                            default:
                                control.Text = NormalizeLineEndings(block.Value.ToString());
                                break;
                            }
                        }
                        else
                        {
                            control.Text = NormalizeLineEndings(block.Value.ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        control.Text = e.ToString();
                    }

                    control.Dock       = DockStyle.Fill;
                    control.Multiline  = true;
                    control.ReadOnly   = true;
                    control.ScrollBars = ScrollBars.Both;
                    tab2.Controls.Add(control);
                    resTabs.TabPages.Add(tab2);
                }

                tab.Controls.Add(resTabs);
            }

            return(tab);
        }