示例#1
0
 private void IOApplicationAccellerator_Load(object sender, EventArgs e)
 {
     _myByteViewer = new System.ComponentModel.Design.ByteViewer {
         Dock = DockStyle.Fill, Size = new System.Drawing.Size(715, 226), ClientSize = new System.Drawing.Size(715, 226), BorderStyle = BorderStyle.None
     };
     viewerPanel.Controls.Add(_myByteViewer);
 }
示例#2
0
        public HexForm()
        {
            InitializeComponent();

            // Initialize the ByteViewer.
            this.byteViewer          = new System.ComponentModel.Design.ByteViewer();
            this.byteViewer.Dock     = System.Windows.Forms.DockStyle.Fill;
            this.byteViewer.Location = new Point(0, 0);
            this.byteViewer.Size     = new Size(100, 100);
            this.byteViewer.SetBytes(new byte[] { });
            this.panel.Controls.Add(byteViewer);
        }
        public TabPage Create(VrfGuiContext vrfGuiContext, byte[] input)
        {
            var tab     = new TabPage();
            var resTabs = new TabControl
            {
                Dock = DockStyle.Fill,
            };

            tab.Controls.Add(resTabs);

            var bvTab = new TabPage("Hex");
            var bv    = new System.ComponentModel.Design.ByteViewer
            {
                Dock = DockStyle.Fill,
            };

            bvTab.Controls.Add(bv);
            resTabs.TabPages.Add(bvTab);

            if (input == null)
            {
                input = File.ReadAllBytes(vrfGuiContext.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       = Utils.Utils.NormalizeLineEndings(System.Text.Encoding.UTF8.GetString(input)),
                };
                textTab.Controls.Add(text);
                resTabs.TabPages.Add(textTab);
                resTabs.SelectedTab = textTab;
            }

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

            return(tab);
        }
示例#4
0
        public TabPage Create(VrfGuiContext vrfGuiContext, byte[] input)
        {
            var tab      = new TabPage();
            var resource = new ValveResourceFormat.Resource();

            if (input != null)
            {
                resource.Read(new MemoryStream(input));
            }
            else
            {
                resource.Read(vrfGuiContext.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(vrfGuiContext.FileName),
                                     tex.ActualWidth, tex.ActualHeight);

                    tab2.Controls.Add(control);
                    Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs,
                                            $"Export {Path.GetFileName(vrfGuiContext.FileName)} as an image", vrfGuiContext.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:
                Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs, $"Export {Path.GetFileName(vrfGuiContext.FileName)} as XML",
                                        vrfGuiContext.FileName, new ExportData {
                    Resource = resource
                });
                break;

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

            case ResourceType.PanoramaStyle:
                Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs, $"Export {Path.GetFileName(vrfGuiContext.FileName)} as CSS",
                                        vrfGuiContext.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.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);

                Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs,
                                        $"Export {Path.GetFileName(vrfGuiContext.FileName)} as {((Sound) resource.DataBlock).SoundType}", vrfGuiContext.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:
                Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs, $"Export {Path.GetFileName(vrfGuiContext.FileName)} as glTF",
                                        vrfGuiContext.FileName, new ExportData {
                    Resource = resource, VrfGuiContext = vrfGuiContext
                });

                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;
                }

                Program.MainForm.Invoke(new ExportDel(AddToExport), resTabs, $"Export {Path.GetFileName(vrfGuiContext.FileName)} as glTF",
                                        vrfGuiContext.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);

                    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 = Utils.Utils.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 =
                                    Utils.Utils.NormalizeLineEndings(blockKeyvalues.GetKV3File().ToString());
                            }
                            else if (block is NTRO blockNTRO)
                            {
                                control.Text = Utils.Utils.NormalizeLineEndings(blockNTRO.ToString());
                            }

                            break;

                        default:
                            control.Text = Utils.Utils.NormalizeLineEndings(block.ToString());
                            break;
                        }
                    }
                    else
                    {
                        control.Text = Utils.Utils.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 System.ComponentModel.Design.ByteViewer();
                    bv.Dock = DockStyle.Fill;
                    tab2.Controls.Add(bv);

                    Program.MainForm.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);

            return(tab);
        }