Example #1
0
 private void MontarStart_Click(object sender, EventArgs e)
 {
     if (montador.LeituraDosArquivos())
     {
         montador.Montar();
         if (montador.ErrosDeMontagem.Count > 0)
         {
             MessageBox.Show("Erros na montagem");
             MensagemDoMontadoBox.Lines = montador.ErrosDeMontagem.ToArray();
         }
         else
         {
             if (MessageBox.Show("Sucesso! Deseja carrega o arquivo na memoria ?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
             {
                 PathTextInterpretado.Text = montador.Diretorio + ".mem";
                 Interpretador.Diretorio   = montador.Diretorio + ".mem";
                 InterpretaStart.Enabled   = true;
                 try
                 {
                     bv.SetFile(montador.Diretorio + ".mem"); // or SetBytes
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show("Não foi possivel abrir o arquivo:" + ex.Message, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
                 tabControl1.SelectedTab = tabPage2;
                 InterpretaStart_Click(null, null);
             }
         }
     }
     else
     {
         MessageBox.Show("Não foi possivel realizar a leitura dos arquivos!");
     }
 }
Example #2
0
        // Show a file selection dialog and cues the byte viewer to
        // load the data in a selected file.
        private void loadBytesFromFile(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            byteviewer.SetFile(ofd.FileName);
        }
Example #3
0
 public void ByteViewer_SetFile_InvokeNoBytes_Success()
 {
     using var control   = new ByteViewer();
     using TempFile file = TempFile.Create(new byte[] { 1, 2, 3 });
     control.SetFile(file.Path);
     Assert.Equal(new byte[] { 1, 2, 3, 0 }, control.GetBytes());
 }
Example #4
0
        public frmHex(String filename) : base(filename)
        {
            InitializeComponent();
            ByteViewer bv = new ByteViewer();

            bv.Dock = DockStyle.Fill;
            bv.SetFile(filename); // or SetBytes
            Controls.Add(bv);
        }
Example #5
0
        public HexViewer(string filename)
        {
            InitializeComponent();
            ByteViewer bv = new ByteViewer();

            bv.SetFile(filename);
            bv.Dock = DockStyle.Fill;
            bv.SetDisplayMode(DisplayMode.Hexdump);
            Controls.Add(bv);
        }
Example #6
0
        private void Hex_Viewer_Load(object sender, EventArgs e)
        {
            HEXtextBox1.Enabled = false;
            HEXtextBox1.Text    = dv.textOpen.Text;

            ByteViewer bv = new ByteViewer();

            bv.SetFile(HEXtextBox1.Text); // or SetBytes
            Controls.Add(bv);
        }
Example #7
0
        public MemoryView()
        {
            InitializeComponent();

            m_ByteViewer      = new ByteViewer();
            m_ByteViewer.Dock = DockStyle.Fill;
            m_ByteViewer.Left = 0;
            m_ByteViewer.Top  = 0;

            Controls.Add(m_ByteViewer);
            m_ByteViewer.SetFile(@"c:\windows\notepad.exe");
        }
            //TODO fix this.
            public override void Load(FileInfo file)
            {
                ByteViewer viewer = new ByteViewer();

                viewer.Dock = DockStyle.Fill;

                viewer.SetFile(file.FullName);
                viewer.BackColor = Color.White;
                viewer.ForeColor = Color.Black;
                viewer.SetDisplayMode(DisplayMode.Hexdump);
                Controls.Add(viewer);
            }
        private void btn_openfile_Click(object sender, EventArgs e)
        {
            byte[] buffer = new byte[40];
            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                label_openfilepath.Text = openFileDialog.FileName;
                openfile(openFileDialog.FileName);
                bv.SetFile(openFileDialog.FileName);
                bv.SetDisplayMode(DisplayMode.Auto);

                //bv.SetRow(10);
            }
        }
 private void CreateByteViewer(OpenFileDialog ofd, Form form)
 {
     panel           = new Panel();
     byteViewer      = new ByteViewer();
     byteViewer.Dock = DockStyle.Fill;
     byteViewer.SetBytes(new byte[] { });
     byteViewer.SetFile(ofd.FileName);
     panel.Location = new System.Drawing.Point(12, 54);
     panel.Name     = "panel";
     panel.Size     = new System.Drawing.Size(617, 330);
     panel.TabIndex = 2;
     form.Controls.Add(panel);
     panel.Controls.Add(byteViewer);
 }
Example #11
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)
            {
                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(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 || 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.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 glControl = new GLRenderControl();
                    glControl.Load += (_, __) =>
                    {
                        glControl.Camera.SetViewportSize(glControl.Control.Width, glControl.Control.Height);
                        glControl.Camera.SetLocation(new Vector3(200));
                        glControl.Camera.LookAt(new Vector3(0));

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

                        glControl.Paint += (sender, args) =>
                        {
                            particleGrid.Render(args.Camera);

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

                    var particleRendererTab = new TabPage("PARTICLE");
                    particleRendererTab.Controls.Add(glControl.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.EntityLump:
                    var entitiesTab = new TabPage("ENTITY LUMP");
                    var text        = new TextBox
                    {
                        Dock       = DockStyle.Fill,
                        ScrollBars = ScrollBars.Vertical,
                        Multiline  = true,
                        ReadOnly   = true,
                        Text       = new EntityLump(resource).ToString(),
                    };
                    entitiesTab.Controls.Add(text);
                    resTabs.TabPages.Add(entitiesTab);

                    break;

                case ResourceType.World:
                    var glWorldControl = new GLModelViewerControl();

                    glWorldControl.Load += (_, __) =>
                    {
                        var particleGrid = new ParticleGrid(20, 5, vrfGuiContext);
                        glWorldControl.AddRenderer(particleGrid);

                        var world         = new World(resource);
                        var worldRenderer = new WorldRenderer(world, vrfGuiContext);
                        glWorldControl.AddRenderer(worldRenderer);

                        vrfGuiContext.ClearCache();
                    };

                    var worldmeshTab = new TabPage("MAP");
                    worldmeshTab.Controls.Add(glWorldControl.Control);
                    resTabs.TabPages.Add(worldmeshTab);
                    break;

                case ResourceType.WorldNode:
                    var glWorldNodeControl = new GLModelViewerControl();

                    glWorldNodeControl.Load += (_, __) =>
                    {
                        var worldNode         = new WorldNode(resource);
                        var worldNodeRenderer = new WorldNodeRenderer(worldNode, vrfGuiContext, null);
                        glWorldNodeControl.AddRenderer(worldNodeRenderer);

                        vrfGuiContext.ClearCache();
                    };

                    var nodemeshTab = new TabPage("WORLD NODE");
                    nodemeshTab.Controls.Add(glWorldNodeControl.Control);
                    resTabs.TabPages.Add(nodemeshTab);
                    break;

                case ResourceType.Model:
                    var glModelControl = new GLModelViewerControl();

                    glModelControl.Load += (_, __) =>
                    {
                        var model         = new Model(resource);
                        var modelRenderer = new ModelRenderer(model, vrfGuiContext);

                        glModelControl.AddRenderer(modelRenderer);

                        vrfGuiContext.ClearCache();
                    };

                    var modelRendererTab = new TabPage("MODEL");
                    modelRendererTab.Controls.Add(glModelControl.Control);
                    resTabs.TabPages.Add(modelRendererTab);
                    break;

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

                    glModelControl       = new GLModelViewerControl();
                    glModelControl.Load += (_, __) =>
                    {
                        var mesh         = new Mesh(resource);
                        var meshRenderer = new MeshRenderer(mesh, vrfGuiContext);

                        glModelControl.AddRenderer(meshRenderer);

                        vrfGuiContext.ClearCache();

                        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(glModelControl.Control);
                    resTabs.TabPages.Add(meshRendererTab);
                    break;

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

                        glMaterialControl.Paint += (sender, e) =>
                        {
                            materialRenderer.Render(e.Camera);
                        };
                    };

                    var materialRendererTab = new TabPage("MATERIAL");
                    materialRendererTab.Controls.Add(glMaterialControl.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.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);
                }

                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);
        }
Example #12
0
 public void ByteViewer_SetFile_InvokeInvalidPath_ThrowsArgumentException(string path)
 {
     using var control = new ByteViewer();
     control.SetBytes(Array.Empty <byte>());
     Assert.Throws <ArgumentException>("path", () => control.SetFile(path));
 }
Example #13
0
 public void ByteViewer_SetFile_InvokeNullPath_ThrowsArgumentNullException()
 {
     using var control = new ByteViewer();
     control.SetBytes(Array.Empty <byte>());
     Assert.Throws <ArgumentNullException>("path", () => control.SetFile(null));
 }