public cDatFileEntry(byte[] buffer, StreamReader inputFile, eDatFormat fileFormat) { this.fileFormat = fileFormat; if (fileFormat == eDatFormat.ToD) { bitFlags = Utils.ReadUInt32(buffer, inputFile);//0x10000 = empty 0x20000 = has data fileId = Utils.ReadUInt32(buffer, inputFile); startBlockOffset = Utils.ReadUInt32(buffer, inputFile); fileSize = Utils.ReadInt32(buffer, inputFile); timeStamp = Utils.ReadUInt32(buffer, inputFile); version = Utils.ReadUInt32(buffer, inputFile); //DateTimeOffset convertedTimeStamp = DateTimeOffset.FromUnixTimeSeconds(timeStamp); } else { fileId = Utils.ReadUInt32(buffer, inputFile); startBlockOffset = Utils.ReadUInt32(buffer, inputFile); fileSize = Utils.ReadInt32(buffer, inputFile); bitFlags = 0x00020000; timeStamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(); version = 1; } fileContent = new MemoryStream(); }
public cLandblockInfo(byte[] buffer, StreamReader inputFile, eDatFormat format) { Id = Utils.ReadUInt32(buffer, inputFile); NumCells = Utils.ReadUInt32(buffer, inputFile); Objects = new List <cStab>(); int objectsCount = Utils.ReadInt32(buffer, inputFile); for (int i = 0; i < objectsCount; i++) { cStab newObject = new cStab(buffer, inputFile); Objects.Add(newObject); } ushort numBuildings = Utils.ReadUInt16(buffer, inputFile); buildingFlags = Utils.ReadUInt16(buffer, inputFile); Buildings = new List <cBuildInfo>(); for (int i = 0; i < numBuildings; i++) { cBuildInfo newBuilding = new cBuildInfo(buffer, inputFile, format); Buildings.Add(newBuilding); } if (format == eDatFormat.retail) { Utils.Align(inputFile); } RestrictionTables = new Dictionary <uint, uint>(); if ((buildingFlags & 1) == 1) { totalObjects = Utils.ReadUInt16(buffer, inputFile); bucketSize = Utils.ReadUInt16(buffer, inputFile); for (int i = 0; i < totalObjects; i++) { RestrictionTables.Add(Utils.ReadUInt32(buffer, inputFile), Utils.ReadUInt32(buffer, inputFile)); } } if (format == eDatFormat.retail) { Utils.Align(inputFile); } if (inputFile.BaseStream.Position != inputFile.BaseStream.Length) { throw new Exception(); } }
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 cDatFileEntry(uint fileId, eDatFormat fileFormat) { this.fileId = fileId; this.fileFormat = fileFormat; startBlockOffset = 0; fileSize = 0; bitFlags = 0x00020000; timeStamp = 1117234133; version = 1; fileContent = new MemoryStream(); listOfBlocks = new List <cDatFileBlock>(); }
public cDatFileEntry(uint fileId, eDatFormat fileFormat) { this.fileId = fileId; this.fileFormat = fileFormat; startBlockOffset = 0; fileSize = 0; bitFlags = 0x00020000; timeStamp = (uint)DateTimeOffset.Now.ToUnixTimeSeconds(); version = 1; fileContent = new MemoryStream(); listOfBlocks = new List <cDatFileBlock>(); }
public cCBldPortal(byte[] buffer, StreamReader inputFile, eDatFormat format) { Flags = Utils.ReadUInt16(buffer, inputFile); OtherCellId = Utils.ReadUInt16(buffer, inputFile); OtherPortalId = Utils.ReadUInt16(buffer, inputFile); visibleCells = new List <ushort>(); ushort visibleCellCount = Utils.ReadUInt16(buffer, inputFile); for (var i = 0; i < visibleCellCount; i++) { visibleCells.Add(Utils.ReadUInt16(buffer, inputFile)); } Utils.Align(inputFile); }
public cBuildInfo(byte[] buffer, StreamReader inputFile, eDatFormat format) { ModelId = Utils.ReadUInt32(buffer, inputFile); Frame = new sFrame(buffer, inputFile); NumLeaves = Utils.ReadUInt32(buffer, inputFile); int portalsCount = Utils.ReadInt32(buffer, inputFile); Portals = new List <cCBldPortal>(); for (int i = 0; i < portalsCount; i++) { cCBldPortal newPortal = new cCBldPortal(buffer, inputFile, format); Portals.Add(newPortal); } }
public void loadFromDat(string filename) { StreamReader inputFile = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)); if (inputFile.BaseStream.Length < 1024) { Console.WriteLine("{0} is too small to be a valid dat file", filename); return; } Console.WriteLine("Reading data from {0}...", filename); Stopwatch timer = new Stopwatch(); timer.Start(); inputFile.BaseStream.Seek(257, SeekOrigin.Begin); int format = Utils.readInt32(inputFile); if (format == 0x4C50) { inputFile.BaseStream.Seek(256, SeekOrigin.Begin); //skip acVersionStr which is empty acTransactionRecord = Utils.readBytes(inputFile, 64); for (int i = 4; i < 64; i++) { acTransactionRecord[i] = 0; } fileType = Utils.readUInt32(inputFile); if (fileType == 0x5442) { fileFormat = eDatFormat.ToD; } } else { acTransactionRecord = new byte[64]; acTransactionRecord[0] = 0x00; acTransactionRecord[1] = 0x50; acTransactionRecord[2] = 0x4C; acTransactionRecord[3] = 0x00; inputFile.BaseStream.Seek(300, SeekOrigin.Begin); fileType = Utils.readUInt32(inputFile); if (fileType == 0x5442) { fileFormat = eDatFormat.retail; } } if (fileFormat == eDatFormat.invalid) { Console.WriteLine("{0} is not a valid dat file.", filename); return; } blockSize = Utils.readInt32(inputFile); fileSize = Utils.readUInt32(inputFile); dataSet = Utils.readUInt32(inputFile); if (fileFormat == eDatFormat.ToD) { dataSubset = Utils.readUInt32(inputFile); } else { //dataSet = 0x00000043 for old cell.dat //dataSet = 0x0000082f for old portal.dat if (dataSet == 0x00000043) { dataSet = 0x00000002; dataSubset = 0x00000001; } else { dataSet = 0x00000001; dataSubset = 0x00000000; } } //dataSet = 0x00000001 - dataSubset = 0x00000000 for client_portal.dat //dataSet = 0x00000001 - dataSubset = 0x69466948 for client_highres.dat //dataSet = 0x00000002 - dataSubset = 0x00000001 for client_cell_1.dat //dataSet = 0x00000003 - dataSubset = 0x00000001 for client_local_English.dat freeHead = Utils.readUInt32(inputFile); freeTail = Utils.readUInt32(inputFile); freeCount = Utils.readUInt32(inputFile); rootDirectoryOffset = Utils.readUInt32(inputFile); if (fileFormat == eDatFormat.ToD) { youngLRU = Utils.readUInt32(inputFile); oldLRU = Utils.readUInt32(inputFile); useLRU = Utils.readUInt32(inputFile); masterMapId = Utils.readUInt32(inputFile); enginePackVersion = Utils.readUInt32(inputFile); gamePackVersion = Utils.readUInt32(inputFile); versionMajor = Utils.readBytes(inputFile, 16);//int data1, short data2, short data3, int64 data4 versionMinor = Utils.readUInt32(inputFile); } else { youngLRU = 0x00000000; oldLRU = 0x00000000; useLRU = 0xcdcdcd00; masterMapId = 0x00000000; enginePackVersion = 0x00000016; gamePackVersion = 0x00000000; versionMajor = new byte[] { 0xD2, 0xD7, 0xA7, 0x34, 0x2F, 0x72, 0x46, 0x4C, 0x8A, 0xB4, 0xEF, 0x51, 0x4F, 0x85, 0x6F, 0xFD }; versionMinor = 0x000000de; } inputBlockCache = new cDatFileBlockCache(fileSize, blockSize, freeHead, freeTail, freeCount); cDatFileBlock.loadBlocksAndAddToDictionary(inputBlockCache, inputFile, blockSize); rootDirectory = new cDatFileNode(inputFile, inputBlockCache, rootDirectoryOffset, blockSize, fileFormat); rootDirectory.loadFilesAndAddToCache(fileCache, inputBlockCache, inputFile, blockSize); timer.Stop(); Console.WriteLine("{0} blocks read in {1} seconds.", inputBlockCache.blocks.Count, timer.ElapsedMilliseconds / 1000f); }
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 cEnvCell(byte[] buffer, StreamReader inputFile, eDatFormat format, bool translateTextureIds = true) { if (format == eDatFormat.ToD) { Id = Utils.ReadUInt32(buffer, inputFile); Bitfield = Utils.ReadUInt32(buffer, inputFile); Utils.ReadUInt32(buffer, inputFile); //repeat id } else if (format == eDatFormat.retail) { Bitfield = Utils.ReadUInt32(buffer, inputFile); Id = Utils.ReadUInt32(buffer, inputFile); } byte numSurfaces = Utils.ReadByte(buffer, inputFile); byte numPortals = Utils.ReadByte(buffer, inputFile); // Note that "portal" in this context does not refer to the swirly pink/purple thing, its basically connecting cells ushort numCells = Utils.ReadUInt16(buffer, inputFile); // I believe this is what cells can be seen from this one. So the engine knows what else it needs to load/draw. Textures = new List <ushort>(); // Read what surfaces are used in this cell for (uint i = 0; i < numSurfaces; i++) { ushort texture = Utils.ReadUInt16(buffer, inputFile); if (translateTextureIds) { if (format == eDatFormat.ToD) { Textures.Add(texture); } else { Textures.Add(validPortalDatEntries.translateTextureId(texture)); } } else { Textures.Add(texture); } } if (format == eDatFormat.retail) { Utils.Align(inputFile); } EnvironmentId = Utils.ReadUInt16(buffer, inputFile); StructId = Utils.ReadUInt16(buffer, inputFile); Position = new sFrame(buffer, inputFile); Portals = new List <cCellPortal>(); for (int i = 0; i < numPortals; i++) { cCellPortal newPortal = new cCellPortal(buffer, inputFile); Portals.Add(newPortal); } if (format == eDatFormat.retail) { Utils.Align(inputFile); } Cells = new List <ushort>(); for (uint i = 0; i < numCells; i++) { Cells.Add(Utils.ReadUInt16(buffer, inputFile)); } if (format == eDatFormat.retail) { Utils.Align(inputFile); } Stabs = new List <cStab>(); if ((Bitfield & 2) != 0) { int numStabs = Utils.ReadInt32(buffer, inputFile); for (int i = 0; i < numStabs; i++) { //cStab Size is 32 cStab newStab = new cStab(buffer, inputFile); Stabs.Add(newStab); } } if (format == eDatFormat.retail) { Utils.Align(inputFile); } if ((Bitfield & 8) != 0) { RestrictionObj = Utils.ReadUInt32(buffer, inputFile); } if (inputFile.BaseStream.Position != inputFile.BaseStream.Length) { throw new Exception(); } }