public void LoadPortalDat_NoExceptions() { string portaldatfile = @"C:\Turbine\client_portal.dat"; DatDatabase dat = new DatDatabase(portaldatfile, DatDatabaseType.Portal); int count = dat.AllFiles.Count(); Assert.AreEqual(79694, count); }
public void LoadPortalDat_NoExceptions() { DatDatabase dat = new DatDatabase(portalDatLocation); int count = dat.AllFiles.Count; //Assert.AreEqual(expectedPortalDatFileCount, count); Assert.IsTrue(expectedPortalDatFileCount <= count, $"Insufficient files parsed from .dat. Expected: >= {expectedPortalDatFileCount}, Actual: {count}"); }
public void LoadCellDat_NoExceptions() { string celldat = @"C:\Turbine\client_cell_1.dat"; DatDatabase dat = new DatDatabase(celldat, DatDatabaseType.Cell); int count = dat.AllFiles.Count(); Assert.AreEqual(805348, count); }
public void LoadPortalDat_NoExceptions() { // Init our text encoding options. This will allow us to use more than standard ANSI text, which the client also supports. System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); DatDatabase dat = new DatDatabase(portalDatLocation); int count = dat.AllFiles.Count; //Assert.AreEqual(expectedPortalDatFileCount, count); Assert.IsTrue(expectedPortalDatFileCount <= count, $"Insufficient files parsed from .dat. Expected: >= {expectedPortalDatFileCount}, Actual: {count}"); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var result = openFileDialog.ShowDialog(); Application.DoEvents(); if (result == DialogResult.OK) { _database = new DatDatabase(openFileDialog.FileName); LoadTree(); } }
public static bool ExportRaw(DatType datType, uint fileID, string outFilename) { DatDatabase datDatabase = null; switch (datType) { case DatType.Cell: datDatabase = DatManager.CellDat; break; case DatType.Portal: datDatabase = DatManager.PortalDat; break; case DatType.HighRes: datDatabase = DatManager.HighResDat; break; case DatType.Language: datDatabase = DatManager.LanguageDat; break; } if (datDatabase == null) { return(false); } var datReader = datDatabase.GetReaderForFile(fileID); if (datReader == null) { return(false); } var maxFileSize = 10000000; using (var memoryStream = new MemoryStream(datReader.Buffer)) { using (var reader = new BinaryReader(memoryStream)) { var bytes = reader.ReadBytes(maxFileSize); Console.WriteLine($"Read {bytes.Length} bytes"); File.WriteAllBytes(outFilename, bytes); } } MainWindow.Instance.AddStatusText($"Wrote {outFilename}"); return(true); }
private void Clear() { tvDatViewer.Nodes.Clear(); _database = null; }
public void UnpackCellDatFiles_NoExceptions() { var assembly = typeof(DatDatabase).GetTypeInfo().Assembly; var types = assembly.GetTypes().Where(t => t.GetCustomAttributes(typeof(DatFileTypeAttribute), false).Length > 0).ToList(); if (types.Count == 0) { throw new Exception("Failed to locate any types with DatFileTypeAttribute."); } DatDatabase dat = new DatDatabase(cellDatLocation); foreach (var kvp in dat.AllFiles) { if (kvp.Value.FileSize == 0) // DatFileType.LandBlock files can be empty { continue; } var fileType = kvp.Value.GetFileType(DatDatabaseType.Cell); if ((kvp.Key & 0xFFFF) == 0xFFFE) { fileType = DatFileType.LandBlockInfo; } if ((kvp.Key & 0xFFFF) == 0xFFFF) { fileType = DatFileType.LandBlock; } if (fileType == null) // What are these? { continue; } //Assert.IsNotNull(fileType, $"Key: 0x{kvp.Key:X8}, ObjectID: 0x{kvp.Value.ObjectId:X8}, FileSize: {kvp.Value.FileSize}, BitFlags:, 0x{kvp.Value.BitFlags:X8}"); var type = types .SelectMany(m => m.GetCustomAttributes(typeof(DatFileTypeAttribute), false), (m, a) => new { m, a }) .Where(t => ((DatFileTypeAttribute)t.a).FileType == fileType) .Select(t => t.m); var first = type.FirstOrDefault(); if (first == null) { throw new Exception($"Failed to Unpack fileType: {fileType}"); } var obj = Activator.CreateInstance(first); var unpackable = obj as IUnpackable; if (unpackable == null) { throw new Exception($"Class for fileType: {fileType} does not implement IUnpackable."); } var datReader = new DatReader(cellDatLocation, kvp.Value.FileOffset, kvp.Value.FileSize, dat.Header.BlockSize); using (var memoryStream = new MemoryStream(datReader.Buffer)) using (var reader = new BinaryReader(memoryStream)) { unpackable.Unpack(reader); if (memoryStream.Position != kvp.Value.FileSize) { throw new Exception($"Failed to parse all bytes for fileType: {fileType}, ObjectId: 0x{kvp.Value.ObjectId:X8}. Bytes parsed: {memoryStream.Position} of {kvp.Value.FileSize}"); } } } }
public void UnpackPortalDatFiles_NoExceptions() { var assembly = typeof(DatDatabase).GetTypeInfo().Assembly; var types = assembly.GetTypes().Where(t => t.GetCustomAttributes(typeof(DatFileTypeAttribute), false).Length > 0).ToList(); if (types.Count == 0) { throw new Exception("Failed to locate any types with DatFileTypeAttribute."); } DatDatabase dat = new DatDatabase(portalDatLocation); foreach (var kvp in dat.AllFiles) { if (kvp.Key == 0xFFFF0001) // Not sure what this is, EOF record maybe? { continue; } var fileType = kvp.Value.GetFileType(DatDatabaseType.Portal); Assert.IsNotNull(fileType, $"Key: 0x{kvp.Key:X8}, ObjectID: 0x{kvp.Value.ObjectId:X8}, FileSize: {kvp.Value.FileSize}, BitFlags:, 0x{kvp.Value.BitFlags:X8}"); // These file types aren't converted yet if (fileType == DatFileType.SurfaceTexture) { continue; } if (fileType == DatFileType.RenderSurface) { continue; } if (fileType == DatFileType.SecondaryAttributeTable) { continue; } if (fileType == DatFileType.SkillTable) { continue; } if (fileType == DatFileType.ChatPoseTable) { continue; } if (fileType == DatFileType.BadData) { continue; } if (fileType == DatFileType.NameFilterTable) { continue; } if (fileType == DatFileType.QualityFilter) { continue; } if (fileType == DatFileType.STable) { continue; } if (fileType == DatFileType.EnumMapper) { continue; } if (fileType == DatFileType.String) { continue; } if (fileType == DatFileType.KeyMap) { continue; } if (fileType == DatFileType.RenderTexture) { continue; } if (fileType == DatFileType.RenderMaterial) { continue; } if (fileType == DatFileType.MaterialModifier) { continue; } if (fileType == DatFileType.MaterialInstance) { continue; } if (fileType == DatFileType.DidMapper) { continue; } if (fileType == DatFileType.ActionMap) { continue; } if (fileType == DatFileType.DualDidMapper) { continue; } if (fileType == DatFileType.Font) { continue; } if (fileType == DatFileType.MasterProperty) { continue; } if (fileType == DatFileType.DbProperties) { continue; } // These have bugs if (fileType == DatFileType.Animation && kvp.Value.ObjectId == 0x0300055b) { continue; // This one seems corrupt } var type = types .SelectMany(m => m.GetCustomAttributes(typeof(DatFileTypeAttribute), false), (m, a) => new { m, a }) .Where(t => ((DatFileTypeAttribute)t.a).FileType == fileType) .Select(t => t.m); var first = type.FirstOrDefault(); if (first == null) { throw new Exception($"Failed to Unpack fileType: {fileType}"); } var obj = Activator.CreateInstance(first); var unpackable = obj as IUnpackable; if (unpackable == null) { throw new Exception($"Class for fileType: {fileType} does not implement IUnpackable."); } var datReader = new DatReader(portalDatLocation, kvp.Value.FileOffset, kvp.Value.FileSize, dat.Header.BlockSize); using (var memoryStream = new MemoryStream(datReader.Buffer)) using (var reader = new BinaryReader(memoryStream)) { unpackable.Unpack(reader); if (memoryStream.Position != kvp.Value.FileSize) { throw new Exception($"Failed to parse all bytes for fileType: {fileType}, ObjectId: 0x{kvp.Value.ObjectId:X8}. Bytes parsed: {memoryStream.Position} of {kvp.Value.FileSize}"); } } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { var result = openFileDialog.ShowDialog(); Application.DoEvents(); if (result == DialogResult.OK) { // could check for opening of the same file, but while we're debugging this // that's probably not the most helpful idea var lastCursor = this.Cursor; this.Cursor = Cursors.WaitCursor; tvDatViewer.Enabled = false; tvDatViewer.Nodes.Clear(); tsProgress.Visible = true; tsProgress.Text = "Loading " + openFileDialog.FileName + " and scanning structures..."; // forces the UI thread to finish its work and update the status strip text Application.DoEvents(); _database = new DatDatabase(openFileDialog.FileName); tsProgress.Text = $"Creating tree structure... (0 of {_database.AllFiles.Count})"; tsProgress.Maximum = _database.AllFiles.Count; tsProgress.Minimum = 0; tsProgress.Value = 0; tsProgress.Width = this.Width - 50; this.Text = "Dat Explorer - " + Path.GetFileName(_database.FileName); Dictionary <byte, TreeNode> rootNodes = new Dictionary <byte, TreeNode>(); _database.AllFiles.ForEach(df => { byte idSegment = (byte)(df.FileId >> 24); TreeNode parentNode = null; if (!rootNodes.ContainsKey(idSegment)) { parentNode = new TreeNode("0x" + idSegment.ToString("X2")); tvDatViewer.Nodes.Add(parentNode); rootNodes.Add(idSegment, parentNode); } else { parentNode = rootNodes[idSegment]; } TreeNode thisNode = new TreeNode(df.FileId.ToString("X8")); if (!string.IsNullOrWhiteSpace(df.UserDefinedName)) { thisNode.Text += " - " + df.UserDefinedName; } thisNode.Tag = df; // copy the dat file into the node // build child nodes of the properties thisNode.Nodes.Add("File Address: " + df.FileOffset); thisNode.Nodes.Add("Internal Type: 0x" + df.FileType.ToString("X8")); thisNode.Nodes.Add("File Modified: " + df.FileDate); thisNode.Nodes.Add("File Size 1: " + df.Size1); thisNode.Nodes.Add("File Size 2: " + df.Size2); thisNode.Nodes.Add("File Version: " + df.Version); thisNode.Nodes.Add("Unknown 1: 0x" + df.Unknown1.ToString("X8")); thisNode.Nodes.Add("Unknown 2: 0x" + df.Unknown2.ToString("X8")); thisNode.ContextMenuStrip = cmsNode; // TODO: implement sorting parentNode.Nodes.Add(thisNode); tsProgress.Value++; tsProgress.Text = $"Creating tree structure... ({tsProgress.Value} of {_database.AllFiles.Count})"; // Application.DoEvents(); }); tsProgress.Visible = false; tvDatViewer.Enabled = true; this.Cursor = lastCursor; } }
public override void Unpack(BinaryReader reader) { Id = reader.ReadInt32(); Unknown = reader.ReadInt32(); UnknownByte = reader.ReadByte(); TextureCount = reader.ReadInt32(); if (TextureCount > 0) { TextureFileIds.Add(reader.ReadUInt32()); if (TextureCount > 1) { TextureFileIds.Add(reader.ReadUInt32()); } } if (ConfigManager.Config == null) { ConfigManager.Initialize(Path.GetFullPath(@"..\..\..\..\..\ACE.Server\bin\x64\Debug\netcoreapp2.0\Config.json")); // weak } var dataFiles = new string[] { Path.Combine(ConfigManager.Config.Server.DatFilesDirectory, "client_portal.dat"), Path.Combine(ConfigManager.Config.Server.DatFilesDirectory, "client_highres.dat") }; foreach (uint fileId in TextureFileIds) { foreach (var datFilPth in dataFiles) { DatDatabase dat = new DatDatabase(datFilPth); // expensive! var texFil = dat.AllFiles.FirstOrDefault(k => k.Key == fileId); if (texFil.Value != null) { var datReader = new DatReader(datFilPth, texFil.Value.FileOffset, texFil.Value.FileSize, dat.Header.BlockSize); var bytes = datReader.Buffer; using (var ms = new MemoryStream(bytes)) { var texReader = new BinaryReader(ms); Texture tex = new Texture(); tex.Unpack(texReader); Textures.Add(tex); } break; } } } if (Textures.Count != TextureCount) { throw new Exception($"Found only {Textures.Count} of {TextureCount} surface textures for SurfaceTexture {Id}"); } //// not using datmanager because highres is still unimplemented //if (DatManager.PortalDat == null) // DatManager.Initialize(ConfigManager.Config.Server.DatFilesDirectory); //var allDatabases = new DatDatabase[] { DatManager.PortalDat, DatManager.CellDat }; //foreach (uint fileId in TextureFileIds) //{ // foreach (var datDb in allDatabases) // { // //DatDatabase dat = new DatDatabase(datFilPth); // var texFil = datDb.AllFiles.FirstOrDefault(k => k.Key == fileId); // if (texFil.Value != null) // { // var datReader = datDb.GetReaderForFile(fileId); // //var datReader = new DatReader(datFilPth, texFil.Value.FileOffset, texFil.Value.FileSize, dat.Header.BlockSize); // var bytes = datReader.Buffer; // using (var ms = new MemoryStream(bytes)) // { // var texReader = new BinaryReader(ms); // Texture tex = new Texture(); // tex.Unpack(texReader); // Textures.Add(tex); // } // break; // } // } //} }
public void DirectoryLoading() { DatDatabase dd = new DatDatabase(@"C:\Turbine\DDO\client_sound.dat"); }