private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPath) { using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (FileStream fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader indexReader = new BinaryReader(fsIndex); int count = (int)(indexReader.BaseStream.Length / 4); for (int i = 0; i < count; ++i) { int blockID = indexReader.ReadInt32(); int x = blockID / matrix.BlockHeight; int y = blockID % matrix.BlockHeight; fsData.Seek(4, SeekOrigin.Current); Tile[] tiles = new Tile[64]; fixed(Tile *pTiles = tiles) { NativeMethods._lread(fsData.SafeFileHandle, pTiles, 192); } matrix.SetLandBlock(x, y, tiles); } return(count); } } }
private unsafe Tile[] ReadLandBlock(int x, int y) { m_Map.Seek(((x * m_BlockHeight) + y) * 196 + 4, SeekOrigin.Begin); Tile[] tiles = new Tile[64]; fixed(Tile *pTiles = tiles) { NativeMethods._lread(m_Map.SafeFileHandle, pTiles, 192); } return(tiles); }
/*public unsafe void GetImage( int x, int y, int width, int height, Bitmap bmp ) * { * if ( m_Colors == null ) * LoadColors(); * * TileMatrix matrix = Tiles; * * BitmapData bd = bmp.LockBits( new Rectangle( 0, 0, width<<3, height<<3 ), ImageLockMode.WriteOnly, PixelFormat.Format16bppRgb555 ); * * int scanDelta = bd.Stride >> 1; * * short *pvDest = (short *)bd.Scan0; * * fixed ( short *pColors = m_Colors ) * { * fixed ( int *pHeight = TileData.HeightTable ) * { * for ( int i = 0; i < width; ++i ) * { * pvDest = ((short *)bd.Scan0) + (i << 3); * * for ( int j = 0; j < height; ++j ) * { * Tile[] tiles = matrix.GetLandBlock( x + i, y + j ); * HuedTile[][][] statics = matrix.GetStaticBlock( x + i, y + j ); * * for ( int k = 0, v = 0; k < 8; ++k, v += 8 ) * { * for ( int p = 0; p < 8; ++p ) * { * int highTop = -255; * int highZ = -255; * int highID = 0; * int highHue = 0; * int z, top; * * HuedTile[] curStatics = statics[p][k]; * * if ( curStatics.Length > 0 ) * { * fixed ( HuedTile *phtStatics = curStatics ) * { * HuedTile *pStatics = phtStatics; * HuedTile *pStaticsEnd = pStatics + curStatics.Length; * * while ( pStatics < pStaticsEnd ) * { * z = pStatics->m_Z; * top = z + pHeight[pStatics->m_ID & 0x3FFF]; * * if ( top > highTop || (z > highZ && top >= highTop) ) * { * highTop = top; * highZ = z; * highID = pStatics->m_ID; * highHue = pStatics->m_Hue; * } * ++pStatics; * } * } * } * * top = tiles[v + p].Z; * * if ( top > highTop ) * { * highID = tiles[v + p].ID; * highHue = 0; * } * * if ( highHue == 0 ) * pvDest[p] = pColors[highID]; * else * pvDest[p] = Hues.GetHue( highHue - 1 ).Colors[(pColors[highID] >> 10) & 0x1F]; * } * * pvDest += scanDelta; * } * } * } * } * } * * bmp.UnlockBits(bd); * }*/ private unsafe static void LoadColors() { m_Colors = new short[0x8000]; string path = Client.GetFilePath("radarcol.mul"); if (path == null) return; fixed(short *pColors = m_Colors) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) NativeMethods._lread(fs.SafeFileHandle, pColors, 0x10000); } }
private unsafe HuedTile[][][] ReadStaticBlock(int x, int y) { m_IndexReader.BaseStream.Seek(((x * m_BlockHeight) + y) * 12, SeekOrigin.Begin); int lookup = m_IndexReader.ReadInt32(); int length = m_IndexReader.ReadInt32(); if (lookup < 0 || length <= 0) { return(m_EmptyStaticBlock); } else { int count = length / 7; m_Statics.Seek(lookup, SeekOrigin.Begin); StaticTile[] staTiles = new StaticTile[count]; fixed(StaticTile *pTiles = staTiles) { NativeMethods._lread(m_Statics.SafeFileHandle, pTiles, length); if (m_Lists == null) { m_Lists = new HuedTileList[8][]; for (int i = 0; i < 8; ++i) { m_Lists[i] = new HuedTileList[8]; for (int j = 0; j < 8; ++j) { m_Lists[i][j] = new HuedTileList(); } } } HuedTileList[][] lists = m_Lists; StaticTile *pCur = pTiles, pEnd = pTiles + count; while (pCur < pEnd) { lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z); ++pCur; } HuedTile[][][] tiles = new HuedTile[8][][]; for (int i = 0; i < 8; ++i) { tiles[i] = new HuedTile[8][]; for (int j = 0; j < 8; ++j) { tiles[i][j] = lists[i][j].ToArray(); } } return(tiles); } } }
private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string indexPath, string lookupPath) { using (FileStream fsData = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (FileStream fsIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (FileStream fsLookup = new FileStream(lookupPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader indexReader = new BinaryReader(fsIndex); BinaryReader lookupReader = new BinaryReader(fsLookup); int count = (int)(indexReader.BaseStream.Length / 4); HuedTileList[][] lists = new HuedTileList[8][]; for (int x = 0; x < 8; ++x) { lists[x] = new HuedTileList[8]; for (int y = 0; y < 8; ++y) { lists[x][y] = new HuedTileList(); } } for (int i = 0; i < count; ++i) { int blockID = indexReader.ReadInt32(); int blockX = blockID / matrix.BlockHeight; int blockY = blockID % matrix.BlockHeight; int offset = lookupReader.ReadInt32(); int length = lookupReader.ReadInt32(); lookupReader.ReadInt32(); // Extra if (offset < 0 || length <= 0) { matrix.SetStaticBlock(blockX, blockY, matrix.EmptyStaticBlock); continue; } fsData.Seek(offset, SeekOrigin.Begin); int tileCount = length / 7; StaticTile[] staTiles = new StaticTile[tileCount]; fixed(StaticTile *pTiles = staTiles) { NativeMethods._lread(fsData.SafeFileHandle, pTiles, length); StaticTile *pCur = pTiles, pEnd = pTiles + tileCount; while (pCur < pEnd) { lists[pCur->m_X & 0x7][pCur->m_Y & 0x7].Add((short)((pCur->m_ID & 0x3FFF) + 0x4000), pCur->m_Hue, pCur->m_Z); ++pCur; } HuedTile[][][] tiles = new HuedTile[8][][]; for (int x = 0; x < 8; ++x) { tiles[x] = new HuedTile[8][]; for (int y = 0; y < 8; ++y) { tiles[x][y] = lists[x][y].ToArray(); } } matrix.SetStaticBlock(blockX, blockY, tiles); } } return(count); } } } }