LoginServerBasePacket.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network.loginserverpackets;
  16. import com.l2jserver.gameserver.TaskPriority;
  17. /**
  18. * @author -Wooden-
  19. *
  20. */
  21. public abstract class LoginServerBasePacket
  22. {
  23. private byte[] _decrypt;
  24. private int _off;
  25. public LoginServerBasePacket(byte[] decrypt)
  26. {
  27. _decrypt = decrypt;
  28. _off = 1; // skip packet type id
  29. }
  30. public int readD()
  31. {
  32. int result = _decrypt[_off++] &0xff;
  33. result |= _decrypt[_off++] << 8 &0xff00;
  34. result |= _decrypt[_off++] << 0x10 &0xff0000;
  35. result |= _decrypt[_off++] << 0x18 &0xff000000;
  36. return result;
  37. }
  38. public int readC()
  39. {
  40. int result = _decrypt[_off++] &0xff;
  41. return result;
  42. }
  43. public int readH()
  44. {
  45. int result = _decrypt[_off++] &0xff;
  46. result |= _decrypt[_off++] << 8 &0xff00;
  47. return result;
  48. }
  49. public double readF()
  50. {
  51. long result = _decrypt[_off++] &0xff;
  52. result |= _decrypt[_off++] << 8 &0xff00;
  53. result |= _decrypt[_off++] << 0x10 &0xff0000;
  54. result |= _decrypt[_off++] << 0x18 &0xff000000;
  55. result |= _decrypt[_off++] << 0x20 &0xff00000000l;
  56. result |= _decrypt[_off++] << 0x28 &0xff0000000000l;
  57. result |= _decrypt[_off++] << 0x30 &0xff000000000000l;
  58. result |= _decrypt[_off++] << 0x38 &0xff00000000000000l;
  59. return Double.longBitsToDouble(result);
  60. }
  61. public String readS()
  62. {
  63. String result = null;
  64. try
  65. {
  66. result = new String(_decrypt,_off,_decrypt.length-_off, "UTF-16LE");
  67. result = result.substring(0, result.indexOf(0x00));
  68. }
  69. catch (Exception e)
  70. {
  71. e.printStackTrace();
  72. }
  73. _off += result.length()*2 + 2;
  74. return result;
  75. }
  76. public final byte[] readB(int length)
  77. {
  78. byte[] result = new byte[length];
  79. for(int i = 0; i < length; i++)
  80. {
  81. result[i]=_decrypt[_off+i];
  82. }
  83. _off += length;
  84. return result;
  85. }
  86. public TaskPriority getPriority() { return TaskPriority.PR_HIGH; }
  87. }