Clone of PhatAC @ https://github.com/floaterxk/PhatAC

PhysicsDesc.h 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #pragma once
  2. #include "BinaryReader.h"
  3. // All of this is temporary.
  4. class Vector3
  5. {
  6. public:
  7. float x;
  8. float y;
  9. float z;
  10. static Vector3 read(BinaryReader &binaryReader) {
  11. Vector3 newObj;
  12. newObj.x = binaryReader.ReadSingle();
  13. newObj.y = binaryReader.ReadSingle();
  14. newObj.z = binaryReader.ReadSingle();
  15. return newObj;
  16. }
  17. };
  18. class Frame
  19. {
  20. public:
  21. Vector3 m_fOrigin;
  22. float qw;
  23. float qx;
  24. float qy;
  25. float qz;
  26. static Frame read(BinaryReader &binaryReader) {
  27. Frame newObj;
  28. newObj.m_fOrigin = Vector3::read(binaryReader);
  29. newObj.qw = binaryReader.ReadSingle();
  30. newObj.qx = binaryReader.ReadSingle();
  31. newObj.qy = binaryReader.ReadSingle();
  32. newObj.qz = binaryReader.ReadSingle();
  33. return newObj;
  34. }
  35. };
  36. class Position
  37. {
  38. public:
  39. uint32_t objcell_id;
  40. Frame frame;
  41. static Position read(BinaryReader &binaryReader) {
  42. Position newObj;
  43. newObj.objcell_id = binaryReader.ReadUInt32();
  44. newObj.frame = Frame::read(binaryReader);
  45. return newObj;
  46. }
  47. static Position readOrigin(BinaryReader &binaryReader) {
  48. Position newObj;
  49. newObj.objcell_id = binaryReader.ReadUInt32();
  50. newObj.frame.m_fOrigin = Vector3::read(binaryReader);
  51. return newObj;
  52. }
  53. };
  54. class ChildInfo
  55. {
  56. public:
  57. uint32_t id;
  58. uint32_t location_id;
  59. static ChildInfo read(BinaryReader &binaryReader) {
  60. ChildInfo newObj;
  61. newObj.id = binaryReader.ReadUInt32();
  62. newObj.location_id = binaryReader.ReadUInt32();
  63. return newObj;
  64. }
  65. };
  66. class PhysicsDesc
  67. {
  68. public:
  69. enum PhysicsDescInfo {
  70. CSetup = (1 << 0), // 0x1
  71. MTABLE = (1 << 1), // 0x2
  72. VELOCITY = (1 << 2), // 0x4
  73. ACCELERATION = (1 << 3), // 0x8
  74. OMEGA = (1 << 4), // 0x10
  75. PARENT = (1 << 5), // 0x20
  76. CHILDREN = (1 << 6), // 0x40
  77. OBJSCALE = (1 << 7), // 0x80
  78. FRICTION = (1 << 8), // 0x100
  79. ELASTICITY = (1 << 9), // 0x200
  80. TIMESTAMPS = (1 << 10), // 0x400
  81. STABLE = (1 << 11), // 0x800
  82. PETABLE = (1 << 12), // 0x1000
  83. DEFAULT_SCRIPT = (1 << 13), // 0x2000
  84. DEFAULT_SCRIPT_INTENSITY = (1 << 14), // 0x4000
  85. POSITION = (1 << 15), // 0x8000
  86. MOVEMENT = (1 << 16), // 0x10000
  87. ANIMFRAME_ID = (1 << 17), // 0x20000
  88. TRANSLUCENCY = (1 << 18) // 0x40000
  89. };
  90. DWORD bitfield;
  91. PhysicsState state;
  92. BYTE *movement_buffer;
  93. DWORD movement_buffer_length;
  94. DWORD autonomous_movement;
  95. DWORD animframe_id;
  96. Position pos;
  97. DWORD mtable_id; // These are tag ids like animpartchange
  98. DWORD stable_id;
  99. DWORD phstable_id;
  100. DWORD setup_id;
  101. DWORD parent_id;
  102. DWORD location_id;
  103. std::list<ChildInfo> children;
  104. float object_scale;
  105. float friction;
  106. float elasticity;
  107. float translucency;
  108. Vector3 velocity;
  109. Vector3 acceleration;
  110. Vector3 omega;
  111. PScriptType default_script;
  112. float default_script_intensity;
  113. uint16_t timestamps[9];
  114. PhysicsDesc()
  115. {
  116. state = (PhysicsState)0;
  117. movement_buffer = NULL;
  118. movement_buffer_length = 0;
  119. autonomous_movement = 0;
  120. animframe_id = 0;
  121. mtable_id = 0;
  122. stable_id = 0;
  123. phstable_id = 0;
  124. setup_id = 0;
  125. parent_id = 0;
  126. location_id = 0;
  127. object_scale = 1.0f;
  128. friction = 0.0f;
  129. elasticity = 0.0f;
  130. translucency = 0.0f;
  131. default_script = (PScriptType)0;
  132. default_script_intensity = 0.0f;
  133. }
  134. ~PhysicsDesc()
  135. {
  136. freeData();
  137. }
  138. void freeData()
  139. {
  140. if (movement_buffer)
  141. {
  142. delete[] movement_buffer;
  143. movement_buffer = NULL;
  144. }
  145. }
  146. void Unpack(BinaryReader &binaryReader) {
  147. PhysicsDesc &newObj = *this;
  148. newObj.bitfield = binaryReader.ReadUInt32();
  149. newObj.state = (PhysicsState)binaryReader.ReadUInt32();
  150. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::MOVEMENT) != 0) {
  151. DWORD buff_length = binaryReader.ReadUInt32();
  152. if (buff_length > 0)
  153. {
  154. if (newObj.movement_buffer)
  155. delete[] newObj.movement_buffer;
  156. newObj.movement_buffer = new BYTE[buff_length];
  157. memcpy(newObj.movement_buffer, binaryReader.ReadArray((int)buff_length), buff_length);
  158. newObj.movement_buffer_length = buff_length;
  159. }
  160. newObj.autonomous_movement = binaryReader.ReadUInt32();
  161. }
  162. else if ((newObj.bitfield & (DWORD)PhysicsDescInfo::ANIMFRAME_ID) != 0) {
  163. newObj.animframe_id = binaryReader.ReadUInt32();
  164. }
  165. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::POSITION) != 0) {
  166. newObj.pos = Position::read(binaryReader);
  167. }
  168. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::MTABLE) != 0) {
  169. newObj.mtable_id = binaryReader.ReadUInt32();
  170. }
  171. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::STABLE) != 0) {
  172. newObj.stable_id = binaryReader.ReadUInt32();
  173. }
  174. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::PETABLE) != 0) {
  175. newObj.phstable_id = binaryReader.ReadUInt32();
  176. }
  177. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::CSetup) != 0) {
  178. newObj.setup_id = binaryReader.ReadUInt32();
  179. }
  180. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::PARENT) != 0) {
  181. newObj.parent_id = binaryReader.ReadUInt32();
  182. newObj.location_id = binaryReader.ReadUInt32();
  183. }
  184. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::CHILDREN) != 0) {
  185. DWORD num_children = binaryReader.ReadUInt32();
  186. for (DWORD i = 0; i < num_children; ++i) {
  187. newObj.children.push_back(ChildInfo::read(binaryReader));
  188. }
  189. }
  190. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::OBJSCALE) != 0) {
  191. newObj.object_scale = binaryReader.ReadSingle();
  192. }
  193. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::FRICTION) != 0) {
  194. newObj.friction = binaryReader.ReadSingle();
  195. }
  196. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::ELASTICITY) != 0) {
  197. newObj.elasticity = binaryReader.ReadSingle();
  198. }
  199. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::TRANSLUCENCY) != 0) {
  200. newObj.translucency = binaryReader.ReadSingle();
  201. }
  202. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::VELOCITY) != 0) {
  203. newObj.velocity.x = binaryReader.ReadSingle();
  204. newObj.velocity.y = binaryReader.ReadSingle();
  205. newObj.velocity.z = binaryReader.ReadSingle();
  206. }
  207. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::ACCELERATION) != 0) {
  208. newObj.acceleration.x = binaryReader.ReadSingle();
  209. newObj.acceleration.y = binaryReader.ReadSingle();
  210. newObj.acceleration.z = binaryReader.ReadSingle();
  211. }
  212. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::OMEGA) != 0) {
  213. newObj.omega.x = binaryReader.ReadSingle();
  214. newObj.omega.y = binaryReader.ReadSingle();
  215. newObj.omega.z = binaryReader.ReadSingle();
  216. }
  217. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::DEFAULT_SCRIPT) != 0) {
  218. newObj.default_script = (PScriptType)binaryReader.ReadUInt32();
  219. }
  220. if ((newObj.bitfield & (DWORD)PhysicsDescInfo::DEFAULT_SCRIPT_INTENSITY) != 0) {
  221. newObj.default_script_intensity = binaryReader.ReadSingle();
  222. }
  223. for (int i = 0; i < 9; ++i) {
  224. newObj.timestamps[i] = binaryReader.ReadUInt16();
  225. }
  226. binaryReader.ReadAlign();
  227. }
  228. };