/// <summary> /// Handle the level information packet /// </summary> /// <param name="pBuffer">Packet Data buffer</param> private void HandleLevelInfo(Byte[] pBuffer) { LevelInfoPacket packet = new LevelInfoPacket(); // Set the player weapon packet packet.Packet = pBuffer; // Load the file and initialize the security checksum string assemblyLoc = Assembly.GetExecutingAssembly().Location; string currentDirectory = assemblyLoc.Substring(0, assemblyLoc.LastIndexOf(Path.DirectorySeparatorChar) + 1); try { string levelDir = Path.Combine(currentDirectory, "maps" + Path.DirectorySeparatorChar); // Open the level file into a stream FileStream levelFile = new FileStream(levelDir + packet.FileName, FileMode.Open); Byte[] fileData = new Byte[levelFile.Length]; levelFile.Read(fileData, 0, (int)levelFile.Length); UInt32 diff = 0; // Skip the tileset (if present) if ((fileData[0] == 'B') && (fileData[1] == 'M')) { diff = BitConverter.ToUInt32(fileData, 2); } Byte[] mapData = new Byte[0x100000]; Byte[] psyMapData = new Byte[levelFile.Length - diff]; for (Int32 i = (Int32)diff; i < fileData.Length; i += 1) { psyMapData[i - diff] = fileData[i]; } // Fill map-tiles for (Int32 i = (Int32)diff; i < fileData.Length; i += 4) { UInt32 tileData = BitConverter.ToUInt32(fileData, i); UInt16 x = (UInt16)(tileData & 0xFFF); UInt16 y = (UInt16)((tileData >> 12) & 0xFFF); Byte type = (Byte)(tileData >> 24); if (x < 0 || x >= 0x400) { continue; } if (y < 0 || y >= 0x400) { continue; } mapData[(y << 10) | x] = type; } // Set the level file data m_securityChecksum.LevelData = mapData; m_securityChecksum.PsyLevelData = psyMapData; m_securityChecksum.MapFile = packet.FileName; } catch (Exception e) { // Write the exception message to the console Console.WriteLine(e.Message); } }
private void HandleMapInfo(Byte[] buffer) { LevelInfoPacket packet = new LevelInfoPacket(); packet.Packet = buffer; }