public TileMatrix(Map map, int fileIndex, int mapID, int width, int height) { _map = map; lock (_instances) { for (var i = 0; i < _instances.Count; ++i) { var tileMatrix = _instances[i]; if (tileMatrix._fileIndex == fileIndex) { lock (_fileShare) { lock (tileMatrix._fileShare) { tileMatrix._fileShare.Add(this); _fileShare.Add(tileMatrix); } } } } _instances.Add(this); } MapDirectory = _map.Directory; _fileIndex = fileIndex; BlockWidth = width >> 3; BlockHeight = height >> 3; _map = map; if (fileIndex != 0x7F) { var mapPath = Path.Combine(_map.Directory, $"map{fileIndex}LegacyMUL.uop"); if (File.Exists(mapPath)) { _mapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _mapIndex = new UOPIndex(_mapStream); } else { mapPath = Path.Combine(_map.Directory, $"map{fileIndex}.mul"); if (File.Exists(mapPath)) { _mapStream = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } } var staticsIndexPath = Path.Combine(_map.Directory, $"staidx{fileIndex}.mul"); if (File.Exists(staticsIndexPath)) { StaticsIndexStream = new FileStream(staticsIndexPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); _staticsIndexReader = new BinaryReader(StaticsIndexStream); } var staticsPath = Path.Combine(_map.Directory, $"statics{fileIndex}.mul"); if (File.Exists(staticsPath)) { StaticsDataStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } } EmptyStaticBlock = new StaticTile[8][][]; for (var i = 0; i < 8; ++i) { EmptyStaticBlock[i] = new StaticTile[8][]; for (var j = 0; j < 8; ++j) { EmptyStaticBlock[i][j] = Array.Empty <StaticTile>(); } } _invalidLandBlock = new LandTile[196]; _landTiles = new LandTile[BlockWidth][][]; _staticTiles = new StaticTile[BlockWidth][][][][]; _staticPatches = new int[BlockWidth][]; _landPatches = new int[BlockWidth][]; Patch = new TileMatrixPatch(this, mapID); }
private unsafe StaticTile[][][] ReadStaticBlock(int x, int y) { try { _staticsIndexReader.BaseStream.Seek((x * BlockHeight + y) * 12, SeekOrigin.Begin); var lookup = _staticsIndexReader.ReadInt32(); var length = _staticsIndexReader.ReadInt32(); if (lookup < 0 || length <= 0) { return(EmptyStaticBlock); } var count = length / 7; StaticsDataStream.Seek(lookup, SeekOrigin.Begin); if (_tileBuffer.Length < count) { _tileBuffer = new StaticTile[count]; } var staTiles = _tileBuffer; fixed(StaticTile *pTiles = staTiles) { NativeReader.Read(StaticsDataStream.SafeFileHandle !.DangerousGetHandle(), pTiles, length); if (_lists == null) { _lists = new TileList[8][]; for (var i = 0; i < 8; ++i) { _lists[i] = new TileList[8]; for (var j = 0; j < 8; ++j) { _lists[i][j] = new TileList(); } } } var lists = _lists; StaticTile *pCur = pTiles, pEnd = pTiles + count; while (pCur < pEnd) { lists[pCur->_x & 0x7][pCur->_y & 0x7].Add(pCur->_id, pCur->_z); pCur += 1; } var tiles = new StaticTile[8][][]; for (var i = 0; i < 8; ++i) { tiles[i] = new StaticTile[8][]; for (var j = 0; j < 8; ++j) { tiles[i][j] = lists[i][j].ToArray(); } } return(tiles); } } catch (EndOfStreamException) { return(EmptyStaticBlock); } }