Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

PlayerDescription.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "BinReader.h"
  19. #include "Core.h"
  20. #include "Log.h"
  21. #include "ObjectManager.h"
  22. #include "util.h"
  23. enum PlayerDescFlags
  24. {
  25. Packed_IntHashTable = 0x0001,
  26. Packed_BoolHashTable = 0x0002,
  27. Packed_FloatStats = 0x0004,
  28. Packed_DataIDHashTable = 0x0008,
  29. Packed_StringHashTable = 0x0010,
  30. Packed_PositionHashTable = 0x0020,
  31. Packed_InstanceIDHashTable = 0x0040,
  32. Packed_Int64HashTable = 0x0080
  33. };
  34. void handlePlayerDescription(BinReader& reader)
  35. {
  36. Object& player = Core::get().objectManager().player();
  37. uint32_t flags = reader.readInt();
  38. /*unknown1*/ reader.readInt();
  39. if(flags & Packed_IntHashTable)
  40. {
  41. uint16_t numInt = reader.readShort();
  42. /*unknown*/ reader.readShort();
  43. for(uint16_t i = 0; i < numInt; i++)
  44. {
  45. IntProperty property = IntProperty(reader.readInt());
  46. uint32_t value = reader.readInt();
  47. player.setProperty(property, value);
  48. }
  49. }
  50. if(flags & Packed_Int64HashTable)
  51. {
  52. uint16_t numInt64 = reader.readShort();
  53. /*unknown*/ reader.readShort();
  54. for(uint16_t i = 0; i < numInt64; i++)
  55. {
  56. Int64Property property = Int64Property(reader.readInt());
  57. uint64_t value = reader.readLong();
  58. player.setProperty(property, value);
  59. }
  60. }
  61. if(flags & Packed_BoolHashTable)
  62. {
  63. uint16_t numBool = reader.readShort();
  64. /*unknown*/ reader.readShort();
  65. for(uint16_t i = 0; i < numBool; i++)
  66. {
  67. BoolProperty property = BoolProperty(reader.readInt());
  68. uint32_t value = reader.readInt();
  69. player.setProperty(property, value != 0);
  70. }
  71. }
  72. if(flags & Packed_FloatStats)
  73. {
  74. uint16_t numFloat = reader.readShort();
  75. /*unknown*/ reader.readShort();
  76. for(uint16_t i = 0; i < numFloat; i++)
  77. {
  78. FloatProperty property = FloatProperty(reader.readInt());
  79. double value = reader.readDouble();
  80. player.setProperty(property, value);
  81. }
  82. }
  83. if(flags & Packed_StringHashTable)
  84. {
  85. uint16_t numString = reader.readShort();
  86. /*unknown*/ reader.readShort();
  87. for(uint16_t i = 0; i < numString; i++)
  88. {
  89. StringProperty property = StringProperty(reader.readInt());
  90. string value = reader.readString();
  91. player.setProperty(property, value);
  92. }
  93. }
  94. if(flags & Packed_DataIDHashTable)
  95. {
  96. uint16_t numDID = reader.readShort();
  97. /*unknown*/ reader.readShort();
  98. for(uint16_t i = 0; i < numDID; i++)
  99. {
  100. DIDProperty property = DIDProperty(reader.readInt());
  101. uint32_t value = reader.readInt();
  102. player.setProperty(property, value);
  103. }
  104. }
  105. if(flags & Packed_InstanceIDHashTable)
  106. {
  107. uint16_t numIID = reader.readShort();
  108. /*unknown*/ reader.readShort();
  109. for(uint16_t i = 0; i < numIID; i++)
  110. {
  111. IIDProperty property = IIDProperty(reader.readInt());
  112. uint32_t value = reader.readInt();
  113. player.setProperty(property, value);
  114. }
  115. }
  116. if(flags & Packed_PositionHashTable)
  117. {
  118. uint16_t numPosition = reader.readShort();
  119. /*unknown*/ reader.readShort();
  120. for(uint16_t i = 0; i < numPosition; i++)
  121. {
  122. PositionProperty property = PositionProperty(reader.readInt());
  123. Position value;
  124. value.landcell = LandcellId(reader.readInt());
  125. read(reader, value.position);
  126. read(reader, value.rotation);
  127. player.setProperty(property, value);
  128. }
  129. }
  130. // TODO more to do
  131. }