private void filesTV_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = filesTV.SelectedNode; if (node.Tag is PackedFile) { PackedFile file = node.Tag as PackedFile; switch (file.GetFileType()) { case TRFileType.GEO: showGEO(file); break; case TRFileType.DDS: case TRFileType.TGA: case TRFileType.JPG: showImage(file); break; default: Console.WriteLine("No handling available for {0} files", file.GetFileType()); break; } } }
private void buttonExtract_Click(object sender, EventArgs e) { TreeNode node = filesTV.SelectedNode; if (node == null) { return; } if (node.Tag is PackedFile) { PackedFile file = node.Tag as PackedFile; saveDialog.FileName = System.IO.Path.GetFileName(file.Filename); DialogResult ret = saveDialog.ShowDialog(); if ((ret == DialogResult.OK) && (saveDialog.FileName != "")) { byte[] buffer = file.GetContents(); using (BinaryWriter writer = new BinaryWriter(File.Open(saveDialog.FileName, FileMode.Create, FileAccess.Write))) { writer.Write(buffer); } MessageBox.Show("Resource extracted!"); } } }
private void showGEO(PackedFile geoFile) { if (geoFile.GetFileType() != TRFileType.GEO) { return; } using (MemoryStream memory = new MemoryStream(geoFile.GetContents())) { try { ChunkFile chunkie = new ChunkFile(); if (chunkie.Load(memory)) { GBODChunk gbod = chunkie.Chunks[0] as GBODChunk; var meshes = Viewer.ModelCreator.Generate(gbod, viewer3D.DX); viewer3D.DisplayMeshes(meshes); return; } } catch (Exception) { } MessageBox.Show("Failed to load geometry file"); } }
public TRData(string path) { Path = path; Filesystem = new SortedDictionary <string, PackedFile>(); // find GLM files in the specified path and subfolders string[] foundFiles = System.IO.Directory.GetFiles(path, "*.glm", System.IO.SearchOption.AllDirectories); GLMFiles = new List <GLMFile>(foundFiles.Length); foreach (string file in foundFiles) { GLMFile glmFile = new GLMFile(path, file); GLMFiles.Add(glmFile); } // put all the files into a hash for faster access foreach (GLMFile glm in GLMFiles) { foreach (PackedFile file in glm.Files) { PackedFile currentFile = null; Filesystem.TryGetValue(file.Filename, out currentFile); if (currentFile != null) { FastConsole.WriteLine(String.Format("Duplicated filename {0} in archives {1} and {2}", file.Filename, currentFile.Parent.Filename, glm.Filename)); continue; } Filesystem.Add(file.Filename, file); } } }
private void btnTest_Click(object sender, EventArgs e) { TreeNode node = filesTV.SelectedNode; if (node.Tag is PackedFile) { PackedFile file = node.Tag as PackedFile; using (MemoryStream memory = new MemoryStream(file.GetContents())) { ChunkFile chunkie = new ChunkFile(); if (chunkie.Load(memory)) { MessageBox.Show("SUCCESS"); } else { MessageBox.Show("FAIL"); } } } }
private void showImage(PackedFile imageFile) { viewer3D.DisplayTexture(imageFile.GetContents()); }
public GLMFile(string root, string path) { BinaryReader file = new BinaryReader(File.Open(path, FileMode.Open, FileAccess.Read)); Size = (UInt32)file.BaseStream.Length; file.BaseStream.Seek(Size - 4, SeekOrigin.Begin); HeaderOffset = file.ReadUInt32(); file.BaseStream.Seek(HeaderOffset, SeekOrigin.Begin); // C H N K B L X X // 43 48 4E 4B 42 4C 58 58 UInt64 header = file.ReadUInt64(); if (header != 0x58584C424B4E4843) { Debug.Fail("Header doesnt match!\nWrong file?"); return; } Path = path; Filename = path.Replace(root, ""); FileTableOffset = file.ReadUInt32(); FileTableLength = file.ReadUInt32(); FilesCount = file.ReadUInt32(); // retrieve inner files Files = new List <PackedFile>(); for (int i = 0; i < FilesCount; i++) { PackedFile trFile = new PackedFile(this) { Offset = file.ReadUInt32(), Size = file.ReadUInt32(), SizeUncompressed = file.ReadUInt32(), FilenameOffset = file.ReadUInt32(), Flags = file.ReadUInt16(), Timestamp = file.ReadUInt32() }; Files.Add(trFile); } // retrieve inner filenames foreach (PackedFile trFile in Files) { file.BaseStream.Seek(trFile.FilenameOffset + FileTableOffset, SeekOrigin.Begin); List <byte> bytes = new List <byte>(); while (true) { byte last = file.ReadByte(); if (last == 0x00) { break; } bytes.Add(last); } System.Text.Encoding enc = System.Text.Encoding.ASCII; trFile.Filename = enc.GetString(bytes.ToArray()); } file.Close(); }