public void loadClientMap(bool readTile) { MapSet mapSet = null; foreach (DirectoryInfo di in _mapFolderInfo) { mapSet = new MapSet(int.Parse(di.Name)); readMap(di, ref mapSet, readTile); _mapSets.Add(int.Parse(di.Name), mapSet); _mapIdList.Add(int.Parse(di.Name)); } loadMapSets(ref _mapSets); _mapIdList.Sort(new myComparer()); }
private int[,] readTile(MapSet ms) { int[,] bufTile; byte[] decrypt; bufTile = new int[ms.lengthX, ms.lengthY]; FileSystemInfo[] _mapFileInfo; string bufFileName = null; string index = null; _mapFileInfo = ms.mapFolder.GetFileSystemInfos(); int bufx, bufy; // 讀取地圖檔內容 foreach (FileSystemInfo fi in _mapFileInfo) { //取得地圖名稱 bufFileName = fi.Name.ToLower(); index = bufFileName.Substring(0, 8).ToLower(); if (_bufTable.ContainsKey(index)) { bufx = Convert.ToInt32(index.Substring(0, 4), 16); bufy = Convert.ToInt32(index.Substring(4, 4), 16); decrypt = File.ReadAllBytes(fi.FullName); if (bufFileName.EndsWith(".s32")) { readS32(decrypt, bufx - ms.minAreaX, bufy - ms.minAreaY, ref bufTile); } else if (bufFileName.EndsWith(".seg")) { readSeg(decrypt, bufx - ms.minAreaX, bufy - ms.minAreaY, ref bufTile); } _bufTable.Remove(index); } } //ms.tile = bufTile; //bufTile = null; return bufTile; }
private void readMap(DirectoryInfo di, ref MapSet ms, bool isReadTile) { int min_areax = 65535; int max_areax = 0; int min_areay = 65535; int max_areay = 0; int area_x = 0; int area_y = 0; FileSystemInfo[] _mapFileInfo; string bufFileName = null; string index = null; _bufTable = new Hashtable(); _mapFileInfo = di.GetFileSystemInfos(); // 先取得地圖的大小 foreach (FileSystemInfo fi in _mapFileInfo) { // 轉換成小寫 bufFileName = fi.Name.ToLower(); if (bufFileName.Length == 12 && !bufFileName.EndsWith("ini")) { index = bufFileName.Substring(0, 8).ToLower(); if (!_bufTable.ContainsKey(index)) { _bufTable.Add(index, bufFileName); area_x = Convert.ToInt32(bufFileName.Substring(0, 4), 16); area_y = Convert.ToInt32(bufFileName.Substring(4, 4), 16); min_areax = Math.Min(min_areax, area_x); min_areay = Math.Min(min_areay, area_y); max_areax = Math.Max(max_areax, area_x); max_areay = Math.Max(max_areay, area_y); } } } if (_bufTable.Count == 0) { return; } // 借用 area_x 和 area_y 來當作 length_x 和 length_y area_x = (max_areax - min_areax + 1) * 64; area_y = (max_areay - min_areay + 1) * 64; ms.lengthX = (max_areax - min_areax + 1) * 64; ms.lengthY = (max_areay - min_areay + 1) * 64; ms.endX = (max_areax - 0x7fff) * 64 + 32767; ms.endY = (max_areay - 0x7fff) * 64 + 32767; ms.startX = ms.endX - area_x + 1; ms.startY = ms.endY - area_y + 1; ms.mapFolder = di; ms.minAreaX = min_areax; ms.minAreaY = min_areay; if (!isReadTile) { return; } ms.tile = readTile(ms); }