| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- namespace Server.MirForms.VisualMapInfo.Class
- {
- public class ReadMap
- {
- public int Width, Height, MonsterCount;
- public Cell[,] Cells;
- public long LightningTime, FireTime;
- public Bitmap clippingZone;
- public string mapFormat, mapFile;
- private byte FindType(byte[] input)
- {
- if (input[0] == 0) // Mir 3 WeMade
- return 5;
- if ((input[0] == 0x0F) && (input[5] == 0x53) && (input[14] == 0x33)) // Mir 3 Shanda
- return 6;
- if ((input[0] == 0x15) && (input[4] == 0x32) && (input[6] == 0x41) && (input[19] == 0x31)) // Mir WeMade AntiHack
- return 4;
- if ((input[0] == 0x10) && (input[2] == 0x61) && (input[7] == 0x31) && (input[14] == 0x31)) // Mir 2010 WeMade
- return 1;
- if ((input[4] == 0x0F) && (input[18] == 0x0D) && (input[19] == 0x0A)) // Mir 2012 Shanda
- {
- int W = input[0] + (input[1] << 8),
- H = input[2] + (input[3] << 8);
- if (input.Length > (52 + (W * H * 14)))
- return 3;
- else
- return 2;
- }
- if ((input[0] == 0x0D) && (input[1] == 0x4C) && (input[7] == 0x20) && (input[11] == 0x6D)) // Mir 3/4 Heroes
- return 7;
- if ((input[0] == 0xC8) && (input[2] == 0xC8) && (input[4] == 0x0D)) // Shortys Map Save
- return 8;
- if ((input[2] == 0x43) && (input[3] == 0x23)) //C#
- return 100;
- return 0;
- }
- private void LoadMapCellsv0(byte[] fileBytes)
- {
- int offSet = 0;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 52;
- clippingZone = new Bitmap(Width, Height);
- LockBitmap BitLock = new LockBitmap(clippingZone);
- BitLock.LockBits();
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- BitLock.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- BitLock.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- BitLock.SetPixel(x, y, Color.Black);
- offSet += 10;
- }
- BitLock.UnlockBits();
- clippingZone.Dispose();
- }
- private void LoadMapCellsv1(byte[] fileBytes)
- {
- int offSet = 21;
- int w = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- int xor = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- int h = BitConverter.ToInt16(fileBytes, offSet);
- Width = w ^ xor;
- Height = h ^ xor;
- Cells = new Cell[Width, Height];
- offSet = 54;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if (((BitConverter.ToInt32(fileBytes, offSet) ^ 0xAA38AA38) & 0x20000000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 6;
- if (((BitConverter.ToInt16(fileBytes, offSet) ^ xor) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 9;
- }
- }
- private void LoadMapCellsv2(byte[] fileBytes)
- {
- int offSet = 0;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 52;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 12;
- }
- }
- private void LoadMapCellsv3(byte[] fileBytes)
- {
- int offSet = 0;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 52;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 34;
- }
- }
- private void LoadMapCellsv4(byte[] fileBytes)
- {
- int offSet = 31;
- int w = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- int xor = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- int h = BitConverter.ToInt16(fileBytes, offSet);
- Width = w ^ xor;
- Height = h ^ xor;
- Cells = new Cell[Width, Height];
- offSet = 64;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 10;
- }
- }
- private void LoadMapCellsv5(byte[] fileBytes)
- {
- int offSet = 22;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 28 + (3 * ((Width / 2) + (Width % 2)) * (Height / 2));
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if ((fileBytes[offSet] & 0x01) != 1)
- clippingZone.SetPixel(x, y, Color.Black);
- else if ((fileBytes[offSet] & 0x02) != 2)
- clippingZone.SetPixel(x, y, Color.Black);
- else
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- offSet += 14;
- }
- }
- private void LoadMapCellsv6(byte[] fileBytes)
- {
- int offSet = 16;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 40;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if ((fileBytes[offSet] & 0x01) != 1)
- clippingZone.SetPixel(x, y, Color.Black);
- else if ((fileBytes[offSet] & 0x02) != 2)
- clippingZone.SetPixel(x, y, Color.Black);
- else
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- offSet += 20;
- }
- }
- private void LoadMapCellsv7(byte[] fileBytes)
- {
- int offSet = 21;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 4;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 54;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- offSet += 13;
- }
- }
- private void LoadMapCellsv8(byte[] fileBytes)
- {
- int offSet = 0;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 52;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 2;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 10;
- }
- }
- private void LoadMapCellsv100(byte[] fileBytes)
- {
- int offSet = 4;
- if ((fileBytes[0] != 1) || (fileBytes[1] != 0)) return;//only support version 1 atm;
- Width = BitConverter.ToInt16(fileBytes, offSet);
- offSet += 2;
- Height = BitConverter.ToInt16(fileBytes, offSet);
- Cells = new Cell[Width, Height];
- offSet = 8;
- clippingZone = new Bitmap(Width, Height);
- for (int x = 0; x < Width; x++)
- for (int y = 0; y < Height; y++)
- {
- offSet += 2;
- if (Cells[x, y] == null)
- clippingZone.SetPixel(x, y, Color.WhiteSmoke);
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 10;
- if ((BitConverter.ToInt16(fileBytes, offSet) & 0x8000) != 0)
- clippingZone.SetPixel(x, y, Color.Black);
- offSet += 14;
- }
- }
- public void Load()
- {
- try
- {
- if (File.Exists(Path.Combine("Maps", mapFile + ".map")))
- {
- byte[] fileBytes = File.ReadAllBytes(Path.Combine("Maps", mapFile + ".map"));
- switch (FindType(fileBytes))
- {
- case 0:
- LoadMapCellsv0(fileBytes);
- mapFormat = "?";
- break;
- case 1:
- LoadMapCellsv1(fileBytes);
- mapFormat = "WEMADE 2010";
- break;
- case 2:
- LoadMapCellsv2(fileBytes);
- mapFormat = "Old SHANDA";
- break;
- case 3:
- LoadMapCellsv3(fileBytes);
- mapFormat = "SHANDA 2012";
- break;
- case 4:
- LoadMapCellsv4(fileBytes);
- mapFormat = "WEMADE Mir 2";
- break;
- case 5:
- LoadMapCellsv5(fileBytes);
- mapFormat = "WEMADE Mir 3";
- break;
- case 6:
- LoadMapCellsv6(fileBytes);
- mapFormat = "SHANDA Mir 3";
- break;
- case 7:
- LoadMapCellsv7(fileBytes);
- mapFormat = "Heroes";
- break;
- case 8:
- LoadMapCellsv8(fileBytes);
- mapFormat = "Shortys";
- break;
- case 100:
- LoadMapCellsv100(fileBytes);
- mapFormat = "C#";
- break;
- }
- }
- }
- catch (Exception) { }
- VisualizerGlobal.ClippingMap = clippingZone;
- }
- public Cell GetCell(Point location)
- {
- return Cells[location.X, location.Y];
- }
- public Cell GetCell(int x, int y)
- {
- return Cells[x, y];
- }
- }
- public class Cell
- {
- public static readonly Cell HighWall;
- public static readonly Cell LowWall;
- }
- }
|