//public static cDatFileEntry newFrom(cDatFileEntry other) //{ // return newFrom(other, other.fileId); //} public static cDatFileEntry newFrom(cDatFileEntry other, uint newFileId) { cDatFileEntry newFile = other.Copy(); newFile.fileId = newFileId; return(newFile); }
public cDatFileNode buildBtreeStructure(Node node, cDatFileBlockCache blockCache) { cDatFileNode newFolder = new cDatFileNode(this, blockCache); foreach (uint entry in node.Entries) { cDatFileEntry file = fileCache[entry]; file.startBlockOffset = 0; file.listOfBlocks = new List <cDatFileBlock>(); //blockCache.dataToBlocks(file.listOfBlocks, file.fileContent); //file.startBlockOffset = file.listOfBlocks[0].blockOffset; newFolder.files.Add(file.fileId, file); } if (!node.IsLeaf) { foreach (Node child in node.Children) { cDatFileNode newSubFolder = buildBtreeStructure(child, blockCache); newFolder.subFolders.Add(newSubFolder); } } //newFolder.updateBlockData(this, blockCache); return(newFolder); }
public void copyFrom(cDatFileEntry other, uint newFileId) { fileFormat = other.fileFormat; bitFlags = other.bitFlags; fileSize = other.fileSize; startBlockOffset = other.startBlockOffset; timeStamp = other.timeStamp; version = other.version; fileId = newFileId; fileContent = other.fileContent; listOfBlocks = new List <cDatFileBlock>(); }
public cDatFileNode(StreamReader inputFile, cDatFileBlockCache blockCache, uint startBlockOffset, int blockSize, eDatFormat fileFormat) { this.startBlockOffset = startBlockOffset; this.blockSize = blockSize; int size; if (fileFormat == eDatFormat.ToD) { size = sizeToD; } else { size = sizeRetail; } listOfBlocks = new List <cDatFileBlock>(); MemoryStream memoryStream = blockCache.blocksToData(startBlockOffset, size, listOfBlocks); memoryStream.Position = 0; StreamReader reader = new StreamReader(memoryStream); files = new SortedDictionary <uint, cDatFileEntry>(); //max 61 subFolders = new List <cDatFileNode>(); //max 62 List <uint> subFolderOffsets = new List <uint>(); for (int i = 0; i < 62; i++) { subFolderOffsets.Add(Utils.readUInt32(reader)); } uint entryCount = Utils.readUInt32(reader); // folder is allowed to have (files + 1) subfolders if (subFolderOffsets[0] != 0) { for (int i = 0; i < entryCount + 1; i++) { cDatFileNode newDirectory = new cDatFileNode(inputFile, blockCache, subFolderOffsets[i], blockSize, fileFormat); subFolders.Add(newDirectory); } } for (uint i = 0; i < entryCount; i++) { cDatFileEntry file = new cDatFileEntry(reader, fileFormat); files.Add(file.fileId, file); } }
public void loadFilesAndAddToCache(SortedDictionary <uint, cDatFileEntry> fileCache, cDatFileBlockCache blockCache, StreamReader inputFile, int blockSize) { foreach (cDatFileNode entry in subFolders) { entry.loadFilesAndAddToCache(fileCache, blockCache, inputFile, blockSize); } foreach (KeyValuePair <uint, cDatFileEntry> entry in files) { cDatFileEntry fileEntry = entry.Value; fileEntry.listOfBlocks = new List <cDatFileBlock>(); fileEntry.fileContent = blockCache.blocksToData(fileEntry.startBlockOffset, fileEntry.fileSize, fileEntry.listOfBlocks); fileCache[fileEntry.fileId] = fileEntry; } }
private void exportSubDirTrees(cDatFileNode directory, int tabCount, StreamWriter outputFile) { string tab = ""; for (int i = 0; i < tabCount; i++) { tab += " "; } foreach (KeyValuePair <uint, cDatFileEntry> entry in directory.files) { cDatFileEntry file = entry.Value; //if ((file.fileId & 0x0000FFFF) == 0x0000FFFF) //{ // uint x = (uint)file.fileId >> 24; // uint y = (uint)(file.fileId & 0x00FF0000) >> 16; // outputFile.WriteLine($"{tab}file: {file.fileId.ToString("x8")} = cellLandblock {x},{y}"); //} //else if((file.fileId & 0x0000FFFE) == 0x0000FFFE) //{ // uint x = (uint)file.fileId >> 24; // uint y = (uint)(file.fileId & 0x00FF0000) >> 16; // outputFile.WriteLine($"{tab}file: {file.fileId.ToString("x8")} = landblockInfo {x},{y}"); //} //else //outputFile.WriteLine($"{tab}file: {file.fileId.ToString("x8")} bitFlags:{file.bitFlags.ToString("x8")}"); outputFile.WriteLine($"{tab}file: {file.fileId.ToString("x8")}"); } outputFile.Flush(); int subDirCount = 0; foreach (cDatFileNode subDirectory in directory.subFolders) { outputFile.WriteLine($"{tab}-- {tabCount} subDirectory {subDirCount} ({subDirectory.files.Count} files, {subDirectory.subFolders.Count} subDirectories)-- "); exportSubDirTrees(subDirectory, tabCount + 1, outputFile); subDirCount++; } outputFile.Flush(); }
public void updateFileContent(cDatFileEntry file) { file.listOfBlocks.Clear(); file.startBlockOffset = 0; file.timeStamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(); var baseStream = new MemoryStream(); StreamWriter writer = new StreamWriter(baseStream); writeToDat(writer); file.fileContent = new MemoryStream(); baseStream.WriteTo(file.fileContent); writer.Close(); file.fileContent.Seek(0, SeekOrigin.Begin); file.fileSize = (int)file.fileContent.Length; file.fileFormat = eDatFormat.ToD; //we only write int ToD format }
public void updateBlockData(cDatFile datFile, cDatFileBlockCache blockCache) { MemoryStream memoryStream = new MemoryStream(new byte[sizeToD]); StreamWriter writer = new StreamWriter(memoryStream); for (int i = 0; i < 62; i++) { if (i == 0 && subFolders.Count == 0) { Utils.writeUInt32(0, writer); } else if (i < subFolders.Count && i < files.Count + 1) //directory is allowed to have (files + 1) subdirectories { cDatFileNode subFolder = subFolders[i]; subFolder.updateBlockData(datFile, blockCache); Utils.writeUInt32(subFolder.startBlockOffset, writer); } else { Utils.writeUInt32(0xcdcdcdcd, writer); } } Utils.writeUInt32((uint)files.Count, writer); foreach (KeyValuePair <uint, cDatFileEntry> entry in files) { cDatFileEntry fileEntry = entry.Value; if (fileEntry.fileContent != null) { fileEntry.fileSize = (int)fileEntry.fileContent.Length; blockCache.dataToBlocks(fileEntry.listOfBlocks, fileEntry.fileContent); if (fileEntry.listOfBlocks.Count > 0) { fileEntry.startBlockOffset = fileEntry.listOfBlocks[0].blockOffset; } } else { fileEntry.fileSize = 0; } fileEntry.writeHeader(writer); } cDatFileEntry emptyFileEntry = new cDatFileEntry(0, datFile.fileFormat); for (int i = files.Count; i < 61; i++) { emptyFileEntry.writeHeader(writer); } writer.Flush(); blockCache.dataToBlocks(listOfBlocks, memoryStream); if (listOfBlocks.Count > 0) { startBlockOffset = listOfBlocks[0].blockOffset; } }
public cStab(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public sFrame(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public cCellLandblock(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { file.fileContent.Seek(0, SeekOrigin.Begin); }
public cEnvCell(cDatFileEntry file, bool translateTextureIds = true) : this(new StreamReader(file.fileContent), file.fileFormat, translateTextureIds) { file.fileContent.Seek(0, SeekOrigin.Begin); }
//public bool ExactMatch => (Bitfield & 1) != 0; //public bool PortalSide => (Bitfield & 2) == 0; public cCellPortal(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public cCBldPortal(cDatFileEntry file) : this(new StreamReader(file.fileContent), file.fileFormat) { file.fileContent.Seek(0, SeekOrigin.Begin); }
public sAngles(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public sOrigin(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public void copyFrom(cDatFileEntry other) { copyFrom(other, other.fileId); }
public sPosStat(cDatFileEntry file) : this(new StreamReader(file.fileContent)) { }
public cLandblockInfo(cDatFileEntry file) : this(new StreamReader(file.fileContent), file.fileFormat) { file.fileContent.Seek(0, SeekOrigin.Begin); }