private static void ParsePBin(string path) { lock (ConsoleWriterLock) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("--- Loading packed panorama file \"{0}\" ---", path); Console.ResetColor(); } var font = new PackedPanorama(); try { font.Read(path); } catch (Exception e) { lock (ConsoleWriterLock) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(e); Console.ResetColor(); } } }
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 if (fileName.EndsWith(".pbin", StringComparison.Ordinal)) { var panorama = new PackedPanorama(); var buffer = new StringWriter(); var oldOut = Console.Out; Console.SetOut(buffer); if (input != null) { panorama.Read(new MemoryStream(input)); } else { panorama.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); }