MapCode.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. namespace Client.MirObjects
  2. {
  3. public class CellInfo
  4. {
  5. public short BackIndex;
  6. public int BackImage;
  7. public short MiddleIndex;
  8. public int MiddleImage;
  9. public short FrontIndex;
  10. public int FrontImage;
  11. public byte DoorIndex;
  12. public byte DoorOffset;
  13. public byte FrontAnimationFrame;
  14. public byte FrontAnimationTick;
  15. public byte MiddleAnimationFrame;
  16. public byte MiddleAnimationTick;
  17. public short TileAnimationImage;
  18. public short TileAnimationOffset;
  19. public byte TileAnimationFrames;
  20. public byte Light;
  21. public byte Unknown;
  22. public List<MapObject> CellObjects;
  23. public bool FishingCell;
  24. public void AddObject(MapObject ob)
  25. {
  26. if (CellObjects == null) CellObjects = new List<MapObject>();
  27. CellObjects.Insert(0, ob);
  28. Sort();
  29. }
  30. public void RemoveObject(MapObject ob)
  31. {
  32. if (CellObjects == null) return;
  33. CellObjects.Remove(ob);
  34. if (CellObjects.Count == 0) CellObjects = null;
  35. else Sort();
  36. }
  37. public MapObject FindObject(uint ObjectID)
  38. {
  39. return CellObjects.Find(
  40. delegate(MapObject mo)
  41. {
  42. return mo.ObjectID == ObjectID;
  43. });
  44. }
  45. public void DrawObjects()
  46. {
  47. if (CellObjects == null) return;
  48. for (int i = 0; i < CellObjects.Count; i++)
  49. {
  50. if (!CellObjects[i].Dead)
  51. {
  52. CellObjects[i].Draw();
  53. continue;
  54. }
  55. if(CellObjects[i].Race == ObjectType.Monster)
  56. {
  57. switch(((MonsterObject)CellObjects[i]).BaseImage)
  58. {
  59. case Monster.PalaceWallLeft:
  60. case Monster.PalaceWall1:
  61. case Monster.PalaceWall2:
  62. case Monster.SSabukWall1:
  63. case Monster.SSabukWall2:
  64. case Monster.SSabukWall3:
  65. case Monster.HellLord:
  66. CellObjects[i].Draw();
  67. break;
  68. default:
  69. continue;
  70. }
  71. }
  72. }
  73. }
  74. public void DrawDeadObjects()
  75. {
  76. if (CellObjects == null) return;
  77. for (int i = 0; i < CellObjects.Count; i++)
  78. {
  79. if (!CellObjects[i].Dead) continue;
  80. if (CellObjects[i].Race == ObjectType.Monster)
  81. {
  82. switch (((MonsterObject)CellObjects[i]).BaseImage)
  83. {
  84. case Monster.PalaceWallLeft:
  85. case Monster.PalaceWall1:
  86. case Monster.PalaceWall2:
  87. case Monster.SSabukWall1:
  88. case Monster.SSabukWall2:
  89. case Monster.SSabukWall3:
  90. case Monster.HellLord:
  91. continue;
  92. }
  93. }
  94. CellObjects[i].Draw();
  95. }
  96. }
  97. public void Sort()
  98. {
  99. CellObjects.Sort(delegate(MapObject ob1, MapObject ob2)
  100. {
  101. if (ob1.Race == ObjectType.Item && ob2.Race != ObjectType.Item)
  102. return -1;
  103. if (ob2.Race == ObjectType.Item && ob1.Race != ObjectType.Item)
  104. return 1;
  105. if (ob1.Race == ObjectType.Spell && ob2.Race != ObjectType.Spell)
  106. return -1;
  107. if (ob2.Race == ObjectType.Spell && ob1.Race != ObjectType.Spell)
  108. return 1;
  109. int i = ob2.Dead.CompareTo(ob1.Dead);
  110. return i == 0 ? ob1.ObjectID.CompareTo(ob2.ObjectID) : i;
  111. });
  112. }
  113. }
  114. class MapReader
  115. {
  116. public int Width, Height;
  117. public CellInfo[,] MapCells;
  118. private string FileName;
  119. private byte[] Bytes;
  120. public MapReader(string FileName)
  121. {
  122. this.FileName = FileName;
  123. initiate();
  124. }
  125. private void initiate()
  126. {
  127. if (File.Exists(FileName))
  128. {
  129. Bytes = File.ReadAllBytes(FileName);
  130. }
  131. else
  132. {
  133. Width = 1000;
  134. Height = 1000;
  135. MapCells = new CellInfo[Width, Height];
  136. for (int x = 0; x < Width; x++)
  137. for (int y = 0; y < Height; y++)
  138. {
  139. MapCells[x, y] = new CellInfo();
  140. }
  141. return;
  142. }
  143. //c# custom map format
  144. if ((Bytes[2] == 0x43) && (Bytes[3] == 0x23))
  145. {
  146. LoadMapType100();
  147. return;
  148. }
  149. //wemade mir3 maps have no title they just start with blank bytes
  150. if (Bytes[0] == 0)
  151. {
  152. LoadMapType5();
  153. return;
  154. }
  155. //shanda mir3 maps start with title: (C) SNDA, MIR3.
  156. if ((Bytes[0] == 0x0F) && (Bytes[5] == 0x53) && (Bytes[14] == 0x33))
  157. {
  158. LoadMapType6();
  159. return;
  160. }
  161. //wemades antihack map (laby maps) title start with: Mir2 AntiHack
  162. if ((Bytes[0] == 0x15) && (Bytes[4] == 0x32) && (Bytes[6] == 0x41) && (Bytes[19] == 0x31))
  163. {
  164. LoadMapType4();
  165. return;
  166. }
  167. //wemades 2010 map format i guess title starts with: Map 2010 Ver 1.0
  168. if ((Bytes[0] == 0x10) && (Bytes[2] == 0x61) && (Bytes[7] == 0x31) && (Bytes[14] == 0x31))
  169. {
  170. LoadMapType1();
  171. return;
  172. }
  173. //shanda's 2012 format and one of shandas(wemades) older formats share same header info, only difference is the filesize
  174. if ((Bytes[4] == 0x0F) || (Bytes[4] == 0x03) && (Bytes[18] == 0x0D) && (Bytes[19] == 0x0A))
  175. {
  176. int W = Bytes[0] + (Bytes[1] << 8);
  177. int H = Bytes[2] + (Bytes[3] << 8);
  178. if (Bytes.Length > (52 + (W*H*14)))
  179. {
  180. LoadMapType3();
  181. return;
  182. }
  183. else
  184. {
  185. LoadMapType2();
  186. return;
  187. }
  188. }
  189. //3/4 heroes map format (myth/lifcos i guess)
  190. if ((Bytes[0] == 0x0D) && (Bytes[1] == 0x4C) && (Bytes[7] == 0x20) && (Bytes[11] == 0x6D))
  191. {
  192. LoadMapType7();
  193. return;
  194. }
  195. //if it's none of the above load the default old school format
  196. LoadMapType0();
  197. }
  198. private void LoadMapType0()
  199. {
  200. try
  201. {
  202. int offset = 0;
  203. Width = BitConverter.ToInt16(Bytes, offset);
  204. offset += 2;
  205. Height = BitConverter.ToInt16(Bytes, offset);
  206. MapCells = new CellInfo[Width, Height];
  207. offset = 52;
  208. for (int x = 0; x < Width; x++)
  209. for (int y = 0; y < Height; y++)
  210. {//12
  211. MapCells[x, y] = new CellInfo();
  212. MapCells[x, y].BackIndex = 0;
  213. MapCells[x, y].MiddleIndex = 1;
  214. MapCells[x, y].BackImage = (short)BitConverter.ToInt16(Bytes, offset);
  215. offset += 2;
  216. MapCells[x, y].MiddleImage = (short)BitConverter.ToInt16(Bytes, offset);
  217. offset += 2;
  218. MapCells[x, y].FrontImage = (short)BitConverter.ToInt16(Bytes, offset);
  219. offset += 2;
  220. MapCells[x, y].DoorIndex = (byte)(Bytes[offset++] & 0x7F);
  221. MapCells[x, y].DoorOffset = Bytes[offset++];
  222. MapCells[x, y].FrontAnimationFrame = Bytes[offset++];
  223. MapCells[x, y].FrontAnimationTick = Bytes[offset++];
  224. MapCells[x, y].FrontIndex = (short)(Bytes[offset++]+ 2);
  225. MapCells[x, y].Light = Bytes[offset++];
  226. if ((MapCells[x, y].BackImage & 0x8000) != 0)
  227. MapCells[x, y].BackImage = (MapCells[x, y].BackImage & 0x7FFF) | 0x20000000;
  228. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  229. MapCells[x, y].FishingCell = true;
  230. }
  231. }
  232. catch (Exception ex)
  233. {
  234. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  235. }
  236. }
  237. private void LoadMapType1()
  238. {
  239. try
  240. {
  241. int offSet = 21;
  242. int w = BitConverter.ToInt16(Bytes, offSet);
  243. offSet += 2;
  244. int xor = BitConverter.ToInt16(Bytes, offSet);
  245. offSet += 2;
  246. int h = BitConverter.ToInt16(Bytes, offSet);
  247. Width = w ^ xor;
  248. Height = h ^ xor;
  249. MapCells = new CellInfo[Width, Height];
  250. offSet = 54;
  251. for (int x = 0; x < Width; x++)
  252. for (int y = 0; y < Height; y++)
  253. {
  254. MapCells[x, y] = new CellInfo
  255. {
  256. BackIndex = 0,
  257. BackImage = (int)(BitConverter.ToInt32(Bytes, offSet) ^ 0xAA38AA38),
  258. MiddleIndex = 1,
  259. MiddleImage = (short)(BitConverter.ToInt16(Bytes, offSet += 4) ^ xor),
  260. FrontImage = (short)(BitConverter.ToInt16(Bytes, offSet += 2) ^ xor),
  261. DoorIndex = (byte)(Bytes[offSet += 2] & 0x7F),
  262. DoorOffset = Bytes[++offSet],
  263. FrontAnimationFrame = Bytes[++offSet],
  264. FrontAnimationTick = Bytes[++offSet],
  265. FrontIndex = (short)(Bytes[++offSet] + 2),
  266. Light = Bytes[++offSet],
  267. Unknown = Bytes[++offSet],
  268. };
  269. offSet++;
  270. if (MapCells[x, y].FrontIndex == 102)
  271. MapCells[x, y].FrontIndex = 90;
  272. if (MapCells[x, y].FrontIndex >= 255)
  273. MapCells[x, y].FrontIndex = -1;
  274. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  275. MapCells[x, y].FishingCell = true;
  276. }
  277. }
  278. catch (Exception ex)
  279. {
  280. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  281. }
  282. }
  283. private void LoadMapType2()
  284. {
  285. try
  286. {
  287. int offset = 0;
  288. Width = BitConverter.ToInt16(Bytes, offset);
  289. offset += 2;
  290. Height = BitConverter.ToInt16(Bytes, offset);
  291. MapCells = new CellInfo[Width, Height];
  292. offset = 52;
  293. for (int x = 0; x < Width; x++)
  294. for (int y = 0; y < Height; y++)
  295. {//14
  296. MapCells[x, y] = new CellInfo();
  297. MapCells[x, y].BackImage = (short)BitConverter.ToInt16(Bytes, offset);
  298. offset += 2;
  299. MapCells[x, y].MiddleImage = (short)BitConverter.ToInt16(Bytes, offset);
  300. offset += 2;
  301. MapCells[x, y].FrontImage = (short)BitConverter.ToInt16(Bytes, offset);
  302. offset += 2;
  303. MapCells[x, y].DoorIndex = (byte)(Bytes[offset++] & 0x7F);
  304. MapCells[x, y].DoorOffset = Bytes[offset++];
  305. MapCells[x, y].FrontAnimationFrame = Bytes[offset++];
  306. MapCells[x, y].FrontAnimationTick = Bytes[offset++];
  307. MapCells[x, y].FrontIndex = (short)(Bytes[offset++] + 120);
  308. MapCells[x, y].Light = Bytes[offset++];
  309. MapCells[x, y].BackIndex = (short)(Bytes[offset++] + 100);
  310. MapCells[x, y].MiddleIndex = (short)(Bytes[offset++] + 110);
  311. if ((MapCells[x, y].BackImage & 0x8000) != 0)
  312. MapCells[x, y].BackImage = (MapCells[x, y].BackImage & 0x7FFF) | 0x20000000;
  313. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  314. MapCells[x, y].FishingCell = true;
  315. }
  316. }
  317. catch (Exception ex)
  318. {
  319. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  320. }
  321. }
  322. private void LoadMapType3()
  323. {
  324. try
  325. {
  326. int offset = 0;
  327. Width = BitConverter.ToInt16(Bytes, offset);
  328. offset += 2;
  329. Height = BitConverter.ToInt16(Bytes, offset);
  330. MapCells = new CellInfo[Width, Height];
  331. offset = 52;
  332. for (int x = 0; x < Width; x++)
  333. for (int y = 0; y < Height; y++)
  334. {//36
  335. MapCells[x, y] = new CellInfo();
  336. MapCells[x, y].BackImage = (short)BitConverter.ToInt16(Bytes, offset);
  337. offset += 2;
  338. MapCells[x, y].MiddleImage = (short)BitConverter.ToInt16(Bytes, offset);
  339. offset += 2;
  340. MapCells[x, y].FrontImage = (short)BitConverter.ToInt16(Bytes, offset);
  341. offset += 2;
  342. MapCells[x, y].DoorIndex = (byte)(Bytes[offset++] & 0x7F);
  343. MapCells[x, y].DoorOffset = Bytes[offset++];
  344. MapCells[x, y].FrontAnimationFrame = Bytes[offset++];
  345. MapCells[x, y].FrontAnimationTick = Bytes[offset++];
  346. MapCells[x, y].FrontIndex = (short)(Bytes[offset++] + 120);
  347. MapCells[x, y].Light = Bytes[offset++];
  348. MapCells[x, y].BackIndex = (short)(Bytes[offset++] + 100);
  349. MapCells[x, y].MiddleIndex = (short)(Bytes[offset++] + 110);
  350. MapCells[x, y].TileAnimationImage = (short)BitConverter.ToInt16(Bytes, offset);
  351. offset += 7;//2bytes from tileanimframe, 2 bytes always blank?, 2bytes potentialy 'backtiles index', 1byte fileindex for the backtiles?
  352. MapCells[x, y].TileAnimationFrames = Bytes[offset++];
  353. MapCells[x, y].TileAnimationOffset = (short)BitConverter.ToInt16(Bytes, offset);
  354. offset += 14; //tons of light, blending, .. related options i hope
  355. if ((MapCells[x, y].BackImage & 0x8000) != 0)
  356. MapCells[x, y].BackImage = (MapCells[x, y].BackImage & 0x7FFF) | 0x20000000;
  357. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  358. MapCells[x, y].FishingCell = true;
  359. }
  360. }
  361. catch (Exception ex)
  362. {
  363. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  364. }
  365. }
  366. private void LoadMapType4()
  367. {
  368. try
  369. {
  370. int offset = 31;
  371. int w = BitConverter.ToInt16(Bytes, offset);
  372. offset += 2;
  373. int xor = BitConverter.ToInt16(Bytes, offset);
  374. offset += 2;
  375. int h = BitConverter.ToInt16(Bytes, offset);
  376. Width = w ^ xor;
  377. Height = h ^ xor;
  378. MapCells = new CellInfo[Width, Height];
  379. offset = 64;
  380. for (int x = 0; x < Width; x++)
  381. for (int y = 0; y < Height; y++)
  382. {//12
  383. MapCells[x, y] = new CellInfo();
  384. MapCells[x, y].BackIndex = 0;
  385. MapCells[x, y].MiddleIndex = 1;
  386. MapCells[x, y].BackImage = (short)(BitConverter.ToInt16(Bytes, offset) ^ xor);
  387. offset += 2;
  388. MapCells[x, y].MiddleImage = (short)(BitConverter.ToInt16(Bytes, offset) ^ xor);
  389. offset += 2;
  390. MapCells[x, y].FrontImage = (short)(BitConverter.ToInt16(Bytes, offset) ^xor);
  391. offset += 2;
  392. MapCells[x, y].DoorIndex = (byte)(Bytes[offset++] & 0x7F);
  393. MapCells[x, y].DoorOffset = Bytes[offset++];
  394. MapCells[x, y].FrontAnimationFrame = Bytes[offset++];
  395. MapCells[x, y].FrontAnimationTick = Bytes[offset++];
  396. MapCells[x, y].FrontIndex = (short)(Bytes[offset++] + 2);
  397. MapCells[x, y].Light = Bytes[offset++];
  398. if ((MapCells[x, y].BackImage & 0x8000) != 0)
  399. MapCells[x, y].BackImage = (MapCells[x, y].BackImage & 0x7FFF) | 0x20000000;
  400. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  401. MapCells[x, y].FishingCell = true;
  402. }
  403. }
  404. catch (Exception ex)
  405. {
  406. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  407. }
  408. }
  409. private void LoadMapType5()
  410. {
  411. try
  412. {
  413. byte flag = 0;
  414. int offset = 20;
  415. short Attribute = (short)(BitConverter.ToInt16(Bytes,offset));
  416. Width = (int)(BitConverter.ToInt16(Bytes,offset+=2));
  417. Height = (int)(BitConverter.ToInt16(Bytes, offset += 2));
  418. //ignoring eventfile and fogcolor for now (seems unused in maps i checked)
  419. offset = 28;
  420. //initiate all cells
  421. MapCells = new CellInfo[Width, Height];
  422. for (int x = 0; x < Width; x++)
  423. for (int y = 0; y < Height; y++)
  424. MapCells[x, y] = new CellInfo();
  425. //read all back tiles
  426. for (int x = 0; x < (Width/2); x++)
  427. for (int y = 0; y < (Height/2); y++)
  428. {
  429. for (int i = 0; i < 4; i++)
  430. {
  431. MapCells[(x * 2) + (i % 2), (y * 2) + (i / 2)].BackIndex = (short)(Bytes[offset] != 255? Bytes[offset]+200 : -1);
  432. MapCells[(x*2) + (i % 2), (y*2) + (i / 2)].BackImage = (int)(BitConverter.ToUInt16(Bytes, offset + 1)+1);
  433. }
  434. offset += 3;
  435. }
  436. //read rest of data
  437. offset = 28 + (3 * ((Width /2) + (Width %2)) * (Height / 2));
  438. for (int x = 0; x < Width; x++)
  439. for (int y = 0; y < Height; y++)
  440. {
  441. flag = Bytes[offset++];
  442. MapCells[x, y].MiddleAnimationFrame = Bytes[offset++];
  443. MapCells[x, y].FrontAnimationFrame = Bytes[offset] == 255? (byte)0 : Bytes[offset];
  444. MapCells[x, y].FrontAnimationFrame &= 0x8F;
  445. offset++;
  446. MapCells[x, y].MiddleAnimationTick = 0;
  447. MapCells[x, y].FrontAnimationTick = 0;
  448. MapCells[x,y].FrontIndex = (short)(Bytes[offset] != 255 ? Bytes[offset] + 200 : -1);
  449. offset++;
  450. MapCells[x,y].MiddleIndex = (short)(Bytes[offset] != 255 ? Bytes[offset] + 200 : -1);
  451. offset++;
  452. MapCells[x,y].MiddleImage = (ushort)(BitConverter.ToUInt16(Bytes,offset)+1);
  453. offset += 2;
  454. MapCells[x, y].FrontImage = (ushort)(BitConverter.ToUInt16(Bytes, offset)+1);
  455. if ((MapCells[x, y].FrontImage == 1) && (MapCells[x, y].FrontIndex == 200))
  456. MapCells[x, y].FrontIndex = -1;
  457. offset += 2;
  458. offset += 3;//mir3 maps dont have doors so dont bother reading the info
  459. MapCells[x, y].Light = (byte)(Bytes[offset] & 0x0F);
  460. offset += 2;
  461. if ((flag & 0x01) != 1) MapCells[x, y].BackImage |= 0x20000000;
  462. if ((flag & 0x02) != 2) MapCells[x, y].FrontImage = (ushort)((UInt16)MapCells[x, y].FrontImage | 0x8000);
  463. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  464. MapCells[x, y].FishingCell = true;
  465. else
  466. MapCells[x, y].Light *= 2;//expand general mir3 lighting as default range is small. Might break new colour lights.
  467. }
  468. }
  469. catch (Exception ex)
  470. {
  471. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  472. }
  473. }
  474. private void LoadMapType6()
  475. {
  476. try
  477. {
  478. byte flag = 0;
  479. int offset = 16;
  480. Width = BitConverter.ToInt16(Bytes, offset);
  481. offset += 2;
  482. Height = BitConverter.ToInt16(Bytes, offset);
  483. MapCells = new CellInfo[Width, Height];
  484. offset = 40;
  485. for (int x = 0; x < Width; x++)
  486. for (int y = 0; y < Height; y++)
  487. {
  488. MapCells[x, y] = new CellInfo();
  489. flag = Bytes[offset++];
  490. MapCells[x,y].BackIndex = (short)(Bytes[offset] != 255 ? Bytes[offset]+ 300 : -1);
  491. offset++;
  492. MapCells[x, y].MiddleIndex = (short)(Bytes[offset] != 255 ? Bytes[offset] + 300 : -1);
  493. offset++;
  494. MapCells[x, y].FrontIndex = (short)(Bytes[offset] != 255 ? Bytes[offset] + 300 : -1);
  495. offset++;
  496. MapCells[x, y].BackImage = (short)(BitConverter.ToInt16(Bytes, offset) + 1);
  497. offset += 2;
  498. MapCells[x, y].MiddleImage = (short)(BitConverter.ToInt16(Bytes, offset) + 1);
  499. offset += 2;
  500. MapCells[x, y].FrontImage = (short)(BitConverter.ToInt16(Bytes, offset) + 1);
  501. offset += 2;
  502. if ((MapCells[x, y].FrontImage == 1) && (MapCells[x, y].FrontIndex == 200))
  503. MapCells[x, y].FrontIndex = -1;
  504. MapCells[x, y].MiddleAnimationFrame = Bytes[offset++];
  505. MapCells[x, y].FrontAnimationFrame = Bytes[offset] == 255 ? (byte)0 : Bytes[offset];
  506. if (MapCells[x, y].FrontAnimationFrame > 0x0F)//assuming shanda used same value not sure
  507. MapCells[x, y].FrontAnimationFrame = (byte)(/*0x80 ^*/ (MapCells[x, y].FrontAnimationFrame & 0x0F));
  508. offset++;
  509. MapCells[x, y].MiddleAnimationTick = 1;
  510. MapCells[x, y].FrontAnimationTick = 1;
  511. MapCells[x, y].Light = (byte)(Bytes[offset] & 0x0F);
  512. MapCells[x, y].Light *= 4;//far wants all light on mir3 maps to be maxed :p
  513. offset += 8;
  514. if ((flag & 0x01) != 1) MapCells[x, y].BackImage |= 0x20000000;
  515. if ((flag & 0x02) != 2) MapCells[x, y].FrontImage = (short)((UInt16)MapCells[x, y].FrontImage | 0x8000);
  516. }
  517. }
  518. catch (Exception ex)
  519. {
  520. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  521. }
  522. }
  523. private void LoadMapType7()
  524. {
  525. try
  526. {
  527. int offset = 21;
  528. Width = BitConverter.ToInt16(Bytes, offset);
  529. offset += 4;
  530. Height = BitConverter.ToInt16(Bytes, offset);
  531. MapCells = new CellInfo[Width, Height];
  532. offset = 54;
  533. for (int x = 0; x < Width; x++)
  534. for (int y = 0; y < Height; y++)
  535. {//total 15
  536. MapCells[x, y] = new CellInfo
  537. {
  538. BackIndex = 0,
  539. BackImage = (int)BitConverter.ToInt32(Bytes, offset),
  540. MiddleIndex = 1,
  541. MiddleImage = (short)BitConverter.ToInt16(Bytes, offset += 4),
  542. FrontImage = (short)BitConverter.ToInt16(Bytes, offset += 2),
  543. DoorIndex = (byte)(Bytes[offset += 2] & 0x7F),
  544. DoorOffset = Bytes[++offset],
  545. FrontAnimationFrame = Bytes[++offset],
  546. FrontAnimationTick = Bytes[++offset],
  547. FrontIndex = (short)(Bytes[++offset] + 2),
  548. Light = Bytes[++offset],
  549. Unknown = Bytes[++offset],
  550. };
  551. if ((MapCells[x, y].BackImage & 0x8000) != 0)
  552. MapCells[x, y].BackImage = (MapCells[x, y].BackImage & 0x7FFF) | 0x20000000;
  553. offset++;
  554. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  555. MapCells[x, y].FishingCell = true;
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  561. }
  562. }
  563. private void LoadMapType100()
  564. {
  565. try
  566. {
  567. int offset = 4;
  568. if ((Bytes[0]!= 1) || (Bytes[1] != 0)) return;//only support version 1 atm
  569. Width = BitConverter.ToInt16(Bytes, offset);
  570. offset += 2;
  571. Height = BitConverter.ToInt16(Bytes, offset);
  572. MapCells = new CellInfo[Width, Height];
  573. offset = 8;
  574. for (int x = 0; x < Width; x++)
  575. for (int y = 0; y < Height; y++)
  576. {
  577. MapCells[x, y] = new CellInfo();
  578. MapCells[x, y].BackIndex = (short)BitConverter.ToInt16(Bytes, offset);
  579. offset += 2;
  580. MapCells[x, y].BackImage = (int)BitConverter.ToInt32(Bytes, offset);
  581. offset += 4;
  582. MapCells[x, y].MiddleIndex = (short)BitConverter.ToInt16(Bytes, offset);
  583. offset += 2;
  584. MapCells[x, y].MiddleImage = (short)BitConverter.ToInt16(Bytes, offset);
  585. offset += 2;
  586. MapCells[x, y].FrontIndex = (short)BitConverter.ToInt16(Bytes, offset);
  587. offset += 2;
  588. MapCells[x, y].FrontImage = (short)BitConverter.ToInt16(Bytes, offset);
  589. offset += 2;
  590. MapCells[x, y].DoorIndex = (byte)(Bytes[offset++] & 0x7F);
  591. MapCells[x, y].DoorOffset = Bytes[offset++];
  592. MapCells[x, y].FrontAnimationFrame = Bytes[offset++];
  593. MapCells[x, y].FrontAnimationTick = Bytes[offset++];
  594. MapCells[x, y].MiddleAnimationFrame = Bytes[offset++];
  595. MapCells[x, y].MiddleAnimationTick = Bytes[offset++];
  596. MapCells[x, y].TileAnimationImage = (short)BitConverter.ToInt16(Bytes, offset);
  597. offset += 2;
  598. MapCells[x, y].TileAnimationOffset = (short)BitConverter.ToInt16(Bytes, offset);
  599. offset += 2;
  600. MapCells[x, y].TileAnimationFrames = Bytes[offset++];
  601. MapCells[x, y].Light = Bytes[offset++];
  602. if (MapCells[x, y].Light >= 100 && MapCells[x, y].Light <= 119)
  603. MapCells[x, y].FishingCell = true;
  604. }
  605. }
  606. catch (Exception ex)
  607. {
  608. if (Settings.LogErrors) CMain.SaveError(ex.ToString());
  609. }
  610. }
  611. }
  612. }