1
0

Pawn.RakNet.inc 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2017-2019 urShadow
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #if !defined PAWNRAKNET_INC_
  25. #define PAWNRAKNET_INC_
  26. #define PAWNRAKNET_INCLUDE_VERSION 130
  27. #define PR_MAX_HANDLERS 255
  28. enum PR_EventType
  29. {
  30. PR_INCOMING_PACKET,
  31. PR_INCOMING_RPC,
  32. PR_OUTCOMING_PACKET,
  33. PR_OUTCOMING_RPC,
  34. PR_NUMBER_OF_EVENT_TYPES
  35. };
  36. enum PR_ValueType
  37. {
  38. PR_INT8,
  39. PR_INT16,
  40. PR_INT32,
  41. PR_UINT8,
  42. PR_UINT16,
  43. PR_UINT32,
  44. PR_FLOAT,
  45. PR_BOOL,
  46. PR_STRING,
  47. // compressed
  48. PR_CINT8,
  49. PR_CINT16,
  50. PR_CINT32,
  51. PR_CUINT8,
  52. PR_CUINT16,
  53. PR_CUINT32,
  54. PR_CFLOAT,
  55. PR_CBOOL,
  56. PR_CSTRING,
  57. PR_BITS,
  58. PR_FLOAT3,
  59. PR_FLOAT4,
  60. PR_VECTOR,
  61. PR_NORM_QUAT
  62. };
  63. enum PR_PacketPriority
  64. {
  65. PR_SYSTEM_PRIORITY,
  66. PR_HIGH_PRIORITY,
  67. PR_MEDIUM_PRIORITY,
  68. PR_LOW_PRIORITY
  69. };
  70. enum PR_PacketReliability
  71. {
  72. PR_UNRELIABLE = 6,
  73. PR_UNRELIABLE_SEQUENCED,
  74. PR_RELIABLE,
  75. PR_RELIABLE_ORDERED,
  76. PR_RELIABLE_SEQUENCED
  77. };
  78. #if !defined __cplusplus
  79. public _pawnraknet_version = PAWNRAKNET_INCLUDE_VERSION;
  80. #pragma unused _pawnraknet_version
  81. #define IRPC:%0(%1) \
  82. forward pr_rir_%0(); \
  83. public pr_rir_%0() \
  84. PR_RegHandler(%0, "pr_ir_"#%0, PR_INCOMING_RPC); \
  85. forward pr_ir_%0(%1); \
  86. public pr_ir_%0(%1)
  87. #define IPacket:%0(%1) \
  88. forward pr_rip_%0(); \
  89. public pr_rip_%0() \
  90. PR_RegHandler(%0, "pr_ip_"#%0, PR_INCOMING_PACKET); \
  91. forward pr_ip_%0(%1); \
  92. public pr_ip_%0(%1)
  93. #define ORPC:%0(%1) \
  94. forward pr_ror_%0(); \
  95. public pr_ror_%0() \
  96. PR_RegHandler(%0, "pr_or_"#%0, PR_OUTCOMING_RPC); \
  97. forward pr_or_%0(%1); \
  98. public pr_or_%0(%1)
  99. #define OPacket:%0(%1) \
  100. forward pr_rop_%0(); \
  101. public pr_rop_%0() \
  102. PR_RegHandler(%0, "pr_op_"#%0, PR_OUTCOMING_PACKET); \
  103. forward pr_op_%0(%1); \
  104. public pr_op_%0(%1)
  105. #define IncomingRPC IRPC
  106. #define OutcomingRPC ORPC
  107. #define IncomingPacket IPacket
  108. #define OutcomingPacket OPacket
  109. #define PR_MAX_WEAPON_SLOTS 13
  110. enum PR_OnFootSync
  111. {
  112. PR_lrKey,
  113. PR_udKey,
  114. PR_keys,
  115. Float:PR_position[3],
  116. Float:PR_quaternion[4],
  117. PR_health,
  118. PR_armour,
  119. PR_weaponId,
  120. PR_additionalKey,
  121. PR_specialAction,
  122. Float:PR_velocity[3],
  123. Float:PR_surfingOffsets[3],
  124. PR_surfingVehicleId,
  125. PR_animationId,
  126. PR_animationFlags
  127. };
  128. enum PR_InCarSync
  129. {
  130. PR_vehicleId,
  131. PR_lrKey,
  132. PR_udKey,
  133. PR_keys,
  134. Float:PR_quaternion[4],
  135. Float:PR_position[3],
  136. Float:PR_velocity[3],
  137. Float:PR_vehicleHealth,
  138. PR_playerHealth,
  139. PR_armour,
  140. PR_weaponId,
  141. PR_additionalKey,
  142. PR_sirenState,
  143. PR_landingGearState,
  144. PR_trailerId,
  145. Float:PR_trainSpeed
  146. };
  147. enum PR_TrailerSync
  148. {
  149. PR_trailerId,
  150. Float:PR_position[3],
  151. Float:PR_quaternion[4],
  152. Float:PR_velocity[3],
  153. Float:PR_angularVelocity[3]
  154. };
  155. enum PR_PassengerSync
  156. {
  157. PR_vehicleId,
  158. PR_seatId,
  159. PR_driveBy,
  160. PR_weaponId,
  161. PR_additionalKey,
  162. PR_playerHealth,
  163. PR_playerArmour,
  164. PR_lrKey,
  165. PR_udKey,
  166. PR_keys,
  167. Float:PR_position[3]
  168. };
  169. enum PR_UnoccupiedSync
  170. {
  171. PR_vehicleId,
  172. PR_seatId,
  173. Float:PR_roll[3],
  174. Float:PR_direction[3],
  175. Float:PR_position[3],
  176. Float:PR_velocity[3],
  177. Float:PR_angularVelocity[3],
  178. Float:PR_vehicleHealth
  179. };
  180. enum PR_AimSync
  181. {
  182. PR_camMode,
  183. Float:PR_camFrontVec[3],
  184. Float:PR_camPos[3],
  185. Float:PR_aimZ,
  186. PR_camZoom,
  187. PR_weaponState,
  188. PR_aspectRatio
  189. };
  190. enum PR_BulletSync
  191. {
  192. PR_hitType,
  193. PR_hitId,
  194. Float:PR_origin[3],
  195. Float:PR_hitPos[3],
  196. Float:PR_offsets[3],
  197. PR_weaponId
  198. };
  199. enum PR_SpectatingSync
  200. {
  201. PR_lrKey,
  202. PR_udKey,
  203. PR_keys,
  204. Float:PR_position[3]
  205. };
  206. enum PR_WeaponsUpdate
  207. {
  208. PR_targetId,
  209. PR_targetActorId,
  210. PR_slotWeaponId[PR_MAX_WEAPON_SLOTS],
  211. PR_slotWeaponAmmo[PR_MAX_WEAPON_SLOTS],
  212. PR_slotUpdated[PR_MAX_WEAPON_SLOTS] // helping field
  213. };
  214. native BS_Send(BitStream:bs, playerid, PR_PacketPriority:priority = PR_HIGH_PRIORITY, PR_PacketReliability:reliability = PR_RELIABLE_ORDERED);
  215. native BS_RPC(BitStream:bs, playerid, rpcid, PR_PacketPriority:priority = PR_HIGH_PRIORITY, PR_PacketReliability:reliability = PR_RELIABLE_ORDERED);
  216. native BS_EmulateIncomingPacket(BitStream:bs, playerid);
  217. native BS_EmulateIncomingRPC(BitStream:bs, playerid, rpcid);
  218. native BitStream:BS_New();
  219. native BS_Delete(&BitStream:bs);
  220. native BS_Reset(BitStream:bs);
  221. native BS_ResetReadPointer(BitStream:bs);
  222. native BS_ResetWritePointer(BitStream:bs);
  223. native BS_IgnoreBits(BitStream:bs, number_of_bits);
  224. native BS_SetWriteOffset(BitStream:bs, offset);
  225. native BS_GetWriteOffset(BitStream:bs, &offset);
  226. native BS_SetReadOffset(BitStream:bs, offset);
  227. native BS_GetReadOffset(BitStream:bs, &offset);
  228. native BS_GetNumberOfBitsUsed(BitStream:bs, &number);
  229. native BS_GetNumberOfBytesUsed(BitStream:bs, &number);
  230. native BS_GetNumberOfUnreadBits(BitStream:bs, &number);
  231. native BS_GetNumberOfBitsAllocated(BitStream:bs, &number);
  232. native BS_WriteValue(BitStream:bs, {PR_ValueType, Float, _}:...);
  233. native BS_ReadValue(BitStream:bs, {PR_ValueType, Float, _}:...);
  234. native PR_RegHandler(id, const publicname[], PR_EventType:type);
  235. native PR_Init(bool:is_gamemode);
  236. #define BS_ReadInt8(%0,%1) BS_ReadValue(%0,PR_INT8,%1)
  237. #define BS_ReadInt16(%0,%1) BS_ReadValue(%0,PR_INT16,%1)
  238. #define BS_ReadInt32(%0,%1) BS_ReadValue(%0,PR_INT32,%1)
  239. #define BS_ReadUint8(%0,%1) BS_ReadValue(%0,PR_UINT8,%1)
  240. #define BS_ReadUint16(%0,%1) BS_ReadValue(%0,PR_UINT16,%1)
  241. #define BS_ReadUint32(%0,%1) BS_ReadValue(%0,PR_UINT32,%1)
  242. #define BS_ReadFloat(%0,%1) BS_ReadValue(%0,PR_FLOAT,%1)
  243. #define BS_ReadBool(%0,%1) BS_ReadValue(%0,PR_BOOL,%1)
  244. #define BS_ReadString(%0,%1,%2) BS_ReadValue(%0,PR_STRING,%1,%2)
  245. #define BS_ReadCompressedInt8(%0,%1) BS_ReadValue(%0,PR_CINT8,%1)
  246. #define BS_ReadCompressedInt16(%0,%1) BS_ReadValue(%0,PR_CINT16,%1)
  247. #define BS_ReadCompressedInt32(%0,%1) BS_ReadValue(%0,PR_CINT32,%1)
  248. #define BS_ReadCompressedUint8(%0,%1) BS_ReadValue(%0,PR_CUINT8,%1)
  249. #define BS_ReadCompressedUint16(%0,%1) BS_ReadValue(%0,PR_CUINT16,%1)
  250. #define BS_ReadCompressedUint32(%0,%1) BS_ReadValue(%0,PR_CUINT32,%1)
  251. #define BS_ReadCompressedFloat(%0,%1) BS_ReadValue(%0,PR_CFLOAT,%1)
  252. #define BS_ReadCompressedBool(%0,%1) BS_ReadValue(%0,PR_CBOOL,%1)
  253. #define BS_ReadCompressedString(%0,%1,%2) BS_ReadValue(%0,PR_CSTRING,%1,%2)
  254. #define BS_ReadBits(%0,%1,%2) BS_ReadValue(%0,PR_BITS,%1,%2)
  255. #define BS_WriteInt8(%0,%1) BS_WriteValue(%0,PR_INT8,%1)
  256. #define BS_WriteInt16(%0,%1) BS_WriteValue(%0,PR_INT16,%1)
  257. #define BS_WriteInt32(%0,%1) BS_WriteValue(%0,PR_INT32,%1)
  258. #define BS_WriteUint8(%0,%1) BS_WriteValue(%0,PR_UINT8,%1)
  259. #define BS_WriteUint16(%0,%1) BS_WriteValue(%0,PR_UINT16,%1)
  260. #define BS_WriteUint32(%0,%1) BS_WriteValue(%0,PR_UINT32,%1)
  261. #define BS_WriteFloat(%0,%1) BS_WriteValue(%0,PR_FLOAT,%1)
  262. #define BS_WriteBool(%0,%1) BS_WriteValue(%0,PR_BOOL,%1)
  263. #define BS_WriteString(%0,%1) BS_WriteValue(%0,PR_STRING,%1)
  264. #define BS_WriteCompressedInt8(%0,%1) BS_WriteValue(%0,PR_CINT8,%1)
  265. #define BS_WriteCompressedInt16(%0,%1) BS_WriteValue(%0,PR_CINT16,%1)
  266. #define BS_WriteCompressedInt32(%0,%1) BS_WriteValue(%0,PR_CINT32,%1)
  267. #define BS_WriteCompressedUint8(%0,%1) BS_WriteValue(%0,PR_CUINT8,%1)
  268. #define BS_WriteCompressedUint16(%0,%1) BS_WriteValue(%0,PR_CUINT16,%1)
  269. #define BS_WriteCompressedUint32(%0,%1) BS_WriteValue(%0,PR_CUINT32,%1)
  270. #define BS_WriteCompressedFloat(%0,%1) BS_WriteValue(%0,PR_CFLOAT,%1)
  271. #define BS_WriteCompressedBool(%0,%1) BS_WriteValue(%0,PR_CBOOL,%1)
  272. #define BS_WriteCompressedString(%0,%1) BS_WriteValue(%0,PR_CSTRING,%1)
  273. #define BS_WriteBits(%0,%1,%2) BS_WriteValue(%0,PR_BITS,%1,%2)
  274. #define PR_EXPAND_ARR3(%0) %0[0],%0[1],%0[2]
  275. #define PR_EXPAND_ARR4(%0) %0[0],%0[1],%0[2],%0[3]
  276. stock BS_PackHealthArmour(health, armour, &healthArmour) {
  277. if (health > 0 && health < 100) {
  278. healthArmour = (health / 7) << 4;
  279. } else if (health >= 100) {
  280. healthArmour = 0xF << 4;
  281. }
  282. if (armour > 0 && armour < 100) {
  283. healthArmour |= (armour / 7);
  284. } else if (armour >= 100) {
  285. healthArmour |= 0xF;
  286. }
  287. }
  288. stock BS_UnpackHealthArmour(healthArmour, &health, &armour) {
  289. new armourTemp, healthTemp;
  290. armourTemp = (healthArmour & 0x0F);
  291. healthTemp = (healthArmour >> 4);
  292. if (armourTemp == 0xF) {
  293. armour = 100;
  294. } else if (armourTemp == 0) {
  295. armour = 0;
  296. } else {
  297. armour = armourTemp * 7;
  298. }
  299. if (healthTemp == 0xF) {
  300. health = 100;
  301. } else if (healthTemp == 0) {
  302. health = 0;
  303. } else {
  304. health = healthTemp * 7;
  305. }
  306. }
  307. stock BS_ReadOnFootSync(BitStream:bs, data[PR_OnFootSync], outcoming = false)
  308. {
  309. if (outcoming) {
  310. new hasLeftRight, hasUpDown, hasSurfInfo, hasAnimation, healthArmour;
  311. BS_ReadValue(bs, PR_BOOL, hasLeftRight);
  312. if (hasLeftRight) {
  313. BS_ReadValue(bs, PR_UINT16, data[PR_lrKey]);
  314. } else {
  315. data[PR_lrKey] = 0;
  316. }
  317. BS_ReadValue(bs, PR_BOOL, hasUpDown);
  318. if (hasUpDown) {
  319. BS_ReadValue(bs, PR_UINT16, data[PR_udKey]);
  320. } else {
  321. data[PR_udKey] = 0;
  322. }
  323. BS_ReadValue(
  324. bs,
  325. PR_UINT16, data[PR_keys],
  326. PR_FLOAT3, data[PR_position],
  327. PR_NORM_QUAT, data[PR_quaternion],
  328. PR_UINT8, healthArmour,
  329. PR_UINT8, data[PR_weaponId],
  330. PR_UINT8, data[PR_specialAction],
  331. PR_VECTOR, data[PR_velocity],
  332. PR_BOOL, hasSurfInfo
  333. );
  334. BS_UnpackHealthArmour(healthArmour, data[PR_health], data[PR_armour]);
  335. if (hasSurfInfo) {
  336. BS_ReadValue(
  337. bs,
  338. PR_UINT16, data[PR_surfingVehicleId],
  339. PR_FLOAT3, data[PR_surfingOffsets]
  340. );
  341. } else {
  342. data[PR_surfingVehicleId] = 0;
  343. }
  344. BS_ReadValue(bs, PR_BOOL, hasAnimation);
  345. if (hasAnimation) {
  346. BS_ReadValue(
  347. bs,
  348. PR_INT16, data[PR_animationId],
  349. PR_INT16, data[PR_animationFlags]
  350. );
  351. } else {
  352. data[PR_animationId] = 0;
  353. data[PR_animationFlags] = 0;
  354. }
  355. } else {
  356. BS_ReadValue(
  357. bs,
  358. PR_UINT16, data[PR_lrKey],
  359. PR_UINT16, data[PR_udKey],
  360. PR_UINT16, data[PR_keys],
  361. PR_FLOAT3, data[PR_position],
  362. PR_FLOAT4, data[PR_quaternion],
  363. PR_UINT8, data[PR_health],
  364. PR_UINT8, data[PR_armour],
  365. PR_BITS, data[PR_additionalKey], 2,
  366. PR_BITS, data[PR_weaponId], 6,
  367. PR_UINT8, data[PR_specialAction],
  368. PR_FLOAT3, data[PR_velocity],
  369. PR_FLOAT3, data[PR_surfingOffsets],
  370. PR_UINT16, data[PR_surfingVehicleId],
  371. PR_INT16, data[PR_animationId],
  372. PR_INT16, data[PR_animationFlags]
  373. );
  374. }
  375. }
  376. stock BS_ReadInCarSync(BitStream:bs, data[PR_InCarSync], outcoming = false)
  377. {
  378. if (outcoming) {
  379. new vehicleHealth, healthArmour;
  380. BS_ReadValue(
  381. bs,
  382. PR_UINT16, data[PR_vehicleId],
  383. PR_UINT16, data[PR_lrKey],
  384. PR_UINT16, data[PR_udKey],
  385. PR_UINT16, data[PR_keys],
  386. PR_NORM_QUAT, data[PR_quaternion],
  387. PR_FLOAT3, data[PR_position],
  388. PR_VECTOR, data[PR_velocity],
  389. PR_UINT16, vehicleHealth,
  390. PR_UINT8, healthArmour,
  391. PR_UINT8, data[PR_weaponId],
  392. PR_BOOL, data[PR_sirenState],
  393. PR_BOOL, data[PR_landingGearState]
  394. );
  395. data[PR_vehicleHealth] = float(vehicleHealth);
  396. BS_UnpackHealthArmour(healthArmour, data[PR_playerHealth], data[PR_armour]);
  397. new hasTrainSpeed, hasTrailer;
  398. BS_ReadValue(bs, PR_BOOL, hasTrainSpeed);
  399. if (hasTrainSpeed) {
  400. BS_ReadValue(bs, PR_FLOAT, data[PR_trainSpeed]);
  401. } else {
  402. data[PR_trainSpeed] = 0.0;
  403. }
  404. BS_ReadValue(bs, PR_BOOL, hasTrailer);
  405. if (hasTrailer) {
  406. BS_ReadValue(bs, PR_UINT16, data[PR_trailerId]);
  407. } else {
  408. data[PR_trailerId] = 0;
  409. }
  410. } else {
  411. BS_ReadValue(
  412. bs,
  413. PR_UINT16, data[PR_vehicleId],
  414. PR_UINT16, data[PR_lrKey],
  415. PR_UINT16, data[PR_udKey],
  416. PR_UINT16, data[PR_keys],
  417. PR_FLOAT4, data[PR_quaternion],
  418. PR_FLOAT3, data[PR_position],
  419. PR_FLOAT3, data[PR_velocity],
  420. PR_FLOAT, data[PR_vehicleHealth],
  421. PR_UINT8, data[PR_playerHealth],
  422. PR_UINT8, data[PR_armour],
  423. PR_BITS, data[PR_additionalKey], 2,
  424. PR_BITS, data[PR_weaponId], 6,
  425. PR_UINT8, data[PR_sirenState],
  426. PR_UINT8, data[PR_landingGearState],
  427. PR_UINT16, data[PR_trailerId],
  428. PR_FLOAT, data[PR_trainSpeed]
  429. );
  430. }
  431. }
  432. stock BS_ReadTrailerSync(BitStream:bs, data[PR_TrailerSync])
  433. {
  434. BS_ReadValue(
  435. bs,
  436. PR_UINT16, data[PR_trailerId],
  437. PR_FLOAT3, data[PR_position],
  438. PR_FLOAT4, data[PR_quaternion],
  439. PR_FLOAT3, data[PR_velocity],
  440. PR_FLOAT3, data[PR_angularVelocity]
  441. );
  442. }
  443. stock BS_ReadPassengerSync(BitStream:bs, data[PR_PassengerSync])
  444. {
  445. BS_ReadValue(
  446. bs,
  447. PR_UINT16, data[PR_vehicleId],
  448. PR_BITS, data[PR_driveBy], 2,
  449. PR_BITS, data[PR_seatId], 6,
  450. PR_BITS, data[PR_additionalKey], 2,
  451. PR_BITS, data[PR_weaponId], 6,
  452. PR_UINT8, data[PR_playerHealth],
  453. PR_UINT8, data[PR_playerArmour],
  454. PR_UINT16, data[PR_lrKey],
  455. PR_UINT16, data[PR_udKey],
  456. PR_UINT16, data[PR_keys],
  457. PR_FLOAT3, data[PR_position]
  458. );
  459. }
  460. stock BS_ReadUnoccupiedSync(BitStream:bs, data[PR_UnoccupiedSync])
  461. {
  462. BS_ReadValue(
  463. bs,
  464. PR_UINT16, data[PR_vehicleId],
  465. PR_UINT8, data[PR_seatId],
  466. PR_FLOAT3, data[PR_roll],
  467. PR_FLOAT3, data[PR_direction],
  468. PR_FLOAT3, data[PR_position],
  469. PR_FLOAT3, data[PR_velocity],
  470. PR_FLOAT3, data[PR_angularVelocity],
  471. PR_FLOAT, data[PR_vehicleHealth]
  472. );
  473. }
  474. stock BS_ReadAimSync(BitStream:bs, data[PR_AimSync])
  475. {
  476. BS_ReadValue(
  477. bs,
  478. PR_UINT8, data[PR_camMode],
  479. PR_FLOAT3, data[PR_camFrontVec],
  480. PR_FLOAT3, data[PR_camPos],
  481. PR_FLOAT, data[PR_aimZ],
  482. PR_BITS, data[PR_weaponState], 2,
  483. PR_BITS, data[PR_camZoom], 6,
  484. PR_UINT8, data[PR_aspectRatio]
  485. );
  486. }
  487. stock BS_ReadBulletSync(BitStream:bs, data[PR_BulletSync])
  488. {
  489. BS_ReadValue(
  490. bs,
  491. PR_UINT8, data[PR_hitType],
  492. PR_UINT16, data[PR_hitId],
  493. PR_FLOAT3, data[PR_origin],
  494. PR_FLOAT3, data[PR_hitPos],
  495. PR_FLOAT3, data[PR_offsets],
  496. PR_UINT8, data[PR_weaponId]
  497. );
  498. }
  499. stock BS_ReadSpectatingSync(BitStream:bs, data[PR_SpectatingSync])
  500. {
  501. BS_ReadValue(
  502. bs,
  503. PR_UINT16, data[PR_lrKey],
  504. PR_UINT16, data[PR_udKey],
  505. PR_UINT16, data[PR_keys],
  506. PR_FLOAT3, data[PR_position]
  507. );
  508. }
  509. stock BS_ReadWeaponsUpdate(BitStream:bs, data[PR_WeaponsUpdate])
  510. {
  511. new numberOfBytes, numberOfSlots;
  512. BS_GetNumberOfBytesUsed(bs, numberOfBytes);
  513. if (numberOfBytes > 5) {
  514. numberOfSlots = (numberOfBytes - 5) / 4;
  515. }
  516. BS_ReadValue(
  517. bs,
  518. PR_UINT16, data[PR_targetId],
  519. PR_UINT16, data[PR_targetActorId]
  520. );
  521. while (numberOfSlots--) {
  522. new slotId, weaponId, ammo;
  523. BS_ReadValue(
  524. bs,
  525. PR_UINT8, slotId,
  526. PR_UINT8, weaponId,
  527. PR_UINT16, ammo
  528. );
  529. if (slotId < PR_MAX_WEAPON_SLOTS) {
  530. data[PR_slotWeaponId][slotId] = weaponId;
  531. data[PR_slotWeaponAmmo][slotId] = ammo;
  532. data[PR_slotUpdated][slotId] = true;
  533. }
  534. }
  535. }
  536. stock BS_WriteOnFootSync(BitStream:bs, data[PR_OnFootSync], outcoming = false)
  537. {
  538. if (outcoming) {
  539. new healthArmour;
  540. if (data[PR_lrKey]) {
  541. BS_WriteValue(
  542. bs,
  543. PR_BOOL, true,
  544. PR_UINT16, data[PR_lrKey]
  545. );
  546. } else {
  547. BS_WriteValue(bs, PR_BOOL, false);
  548. }
  549. if (data[PR_udKey]) {
  550. BS_WriteValue(
  551. bs,
  552. PR_BOOL, true,
  553. PR_UINT16, data[PR_udKey]
  554. );
  555. } else {
  556. BS_WriteValue(bs, PR_BOOL, false);
  557. }
  558. BS_PackHealthArmour(data[PR_health], data[PR_armour], healthArmour);
  559. BS_WriteValue(
  560. bs,
  561. PR_UINT16, data[PR_keys],
  562. PR_FLOAT3, data[PR_position],
  563. PR_NORM_QUAT, data[PR_quaternion],
  564. PR_UINT8, healthArmour,
  565. PR_UINT8, data[PR_weaponId],
  566. PR_UINT8, data[PR_specialAction],
  567. PR_VECTOR, data[PR_velocity]
  568. );
  569. if (data[PR_surfingVehicleId]) {
  570. BS_WriteValue(
  571. bs,
  572. PR_BOOL, true,
  573. PR_UINT16, data[PR_surfingVehicleId],
  574. PR_FLOAT3, data[PR_surfingOffsets]
  575. );
  576. } else {
  577. BS_WriteValue(bs, PR_BOOL, false);
  578. }
  579. if (data[PR_animationId] || data[PR_animationFlags]) {
  580. BS_WriteValue(
  581. bs,
  582. PR_BOOL, true,
  583. PR_INT16, data[PR_animationId],
  584. PR_INT16, data[PR_animationFlags]
  585. );
  586. } else {
  587. BS_WriteValue(bs, PR_BOOL, false);
  588. }
  589. } else {
  590. BS_WriteValue(
  591. bs,
  592. PR_UINT16, data[PR_lrKey],
  593. PR_UINT16, data[PR_udKey],
  594. PR_UINT16, data[PR_keys],
  595. PR_FLOAT3, data[PR_position],
  596. PR_FLOAT4, data[PR_quaternion],
  597. PR_UINT8, data[PR_health],
  598. PR_UINT8, data[PR_armour],
  599. PR_BITS, data[PR_additionalKey], 2,
  600. PR_BITS, data[PR_weaponId], 6,
  601. PR_UINT8, data[PR_specialAction],
  602. PR_FLOAT3, data[PR_velocity],
  603. PR_FLOAT3, data[PR_surfingOffsets],
  604. PR_UINT16, data[PR_surfingVehicleId],
  605. PR_INT16, data[PR_animationId],
  606. PR_INT16, data[PR_animationFlags]
  607. );
  608. }
  609. }
  610. stock BS_WriteInCarSync(BitStream:bs, data[PR_InCarSync], outcoming = false)
  611. {
  612. if (outcoming) {
  613. new healthArmour;
  614. BS_PackHealthArmour(data[PR_playerHealth], data[PR_armour], healthArmour);
  615. BS_WriteValue(
  616. bs,
  617. PR_UINT16, data[PR_vehicleId],
  618. PR_UINT16, data[PR_lrKey],
  619. PR_UINT16, data[PR_udKey],
  620. PR_UINT16, data[PR_keys],
  621. PR_NORM_QUAT, data[PR_quaternion],
  622. PR_FLOAT3, data[PR_position],
  623. PR_VECTOR, data[PR_velocity],
  624. PR_UINT16, floatround(data[PR_vehicleHealth]),
  625. PR_UINT8, healthArmour,
  626. PR_UINT8, data[PR_weaponId],
  627. PR_BOOL, data[PR_sirenState],
  628. PR_BOOL, data[PR_landingGearState]
  629. );
  630. if (data[PR_trainSpeed]) {
  631. BS_WriteValue(bs,
  632. PR_BOOL, true,
  633. PR_FLOAT, data[PR_trainSpeed]
  634. );
  635. } else {
  636. BS_WriteValue(bs, PR_BOOL, false);
  637. }
  638. if (data[PR_trailerId]) {
  639. BS_WriteValue(bs,
  640. PR_BOOL, true,
  641. PR_UINT16, data[PR_trailerId]
  642. );
  643. } else {
  644. BS_WriteValue(bs, PR_BOOL, false);
  645. }
  646. } else {
  647. BS_WriteValue(
  648. bs,
  649. PR_UINT16, data[PR_vehicleId],
  650. PR_UINT16, data[PR_lrKey],
  651. PR_UINT16, data[PR_udKey],
  652. PR_UINT16, data[PR_keys],
  653. PR_FLOAT4, data[PR_quaternion],
  654. PR_FLOAT3, data[PR_position],
  655. PR_FLOAT3, data[PR_velocity],
  656. PR_FLOAT, data[PR_vehicleHealth],
  657. PR_UINT8, data[PR_playerHealth],
  658. PR_UINT8, data[PR_armour],
  659. PR_BITS, data[PR_additionalKey], 2,
  660. PR_BITS, data[PR_weaponId], 6,
  661. PR_UINT8, data[PR_sirenState],
  662. PR_UINT8, data[PR_landingGearState],
  663. PR_UINT16, data[PR_trailerId],
  664. PR_FLOAT, data[PR_trainSpeed]
  665. );
  666. }
  667. }
  668. stock BS_WriteTrailerSync(BitStream:bs, data[PR_TrailerSync])
  669. {
  670. BS_WriteValue(
  671. bs,
  672. PR_UINT16, data[PR_trailerId],
  673. PR_FLOAT3, data[PR_position],
  674. PR_FLOAT4, data[PR_quaternion],
  675. PR_FLOAT3, data[PR_velocity],
  676. PR_FLOAT3, data[PR_angularVelocity]
  677. );
  678. }
  679. stock BS_WritePassengerSync(BitStream:bs, data[PR_PassengerSync])
  680. {
  681. BS_WriteValue(
  682. bs,
  683. PR_UINT16, data[PR_vehicleId],
  684. PR_BITS, data[PR_driveBy], 2,
  685. PR_BITS, data[PR_seatId], 6,
  686. PR_BITS, data[PR_additionalKey], 2,
  687. PR_BITS, data[PR_weaponId], 6,
  688. PR_UINT8, data[PR_playerHealth],
  689. PR_UINT8, data[PR_playerArmour],
  690. PR_UINT16, data[PR_lrKey],
  691. PR_UINT16, data[PR_udKey],
  692. PR_UINT16, data[PR_keys],
  693. PR_FLOAT3, data[PR_position]
  694. );
  695. }
  696. stock BS_WriteUnoccupiedSync(BitStream:bs, data[PR_UnoccupiedSync])
  697. {
  698. BS_WriteValue(
  699. bs,
  700. PR_UINT16, data[PR_vehicleId],
  701. PR_UINT8, data[PR_seatId],
  702. PR_FLOAT3, data[PR_roll],
  703. PR_FLOAT3, data[PR_direction],
  704. PR_FLOAT3, data[PR_position],
  705. PR_FLOAT3, data[PR_velocity],
  706. PR_FLOAT3, data[PR_angularVelocity],
  707. PR_FLOAT, data[PR_vehicleHealth]
  708. );
  709. }
  710. stock BS_WriteAimSync(BitStream:bs, data[PR_AimSync])
  711. {
  712. BS_WriteValue(
  713. bs,
  714. PR_UINT8, data[PR_camMode],
  715. PR_FLOAT3, data[PR_camFrontVec],
  716. PR_FLOAT3, data[PR_camPos],
  717. PR_FLOAT, data[PR_aimZ],
  718. PR_BITS, data[PR_weaponState], 2,
  719. PR_BITS, data[PR_camZoom], 6,
  720. PR_UINT8, data[PR_aspectRatio]
  721. );
  722. }
  723. stock BS_WriteBulletSync(BitStream:bs, data[PR_BulletSync])
  724. {
  725. BS_WriteValue(
  726. bs,
  727. PR_UINT8, data[PR_hitType],
  728. PR_UINT16, data[PR_hitId],
  729. PR_FLOAT3, data[PR_origin],
  730. PR_FLOAT3, data[PR_hitPos],
  731. PR_FLOAT3, data[PR_offsets],
  732. PR_UINT8, data[PR_weaponId]
  733. );
  734. }
  735. stock BS_WriteSpectatingSync(BitStream:bs, data[PR_SpectatingSync])
  736. {
  737. BS_WriteValue(
  738. bs,
  739. PR_UINT16, data[PR_lrKey],
  740. PR_UINT16, data[PR_udKey],
  741. PR_UINT16, data[PR_keys],
  742. PR_FLOAT3, data[PR_position]
  743. );
  744. }
  745. stock BS_WriteWeaponsUpdate(BitStream:bs, data[PR_WeaponsUpdate])
  746. {
  747. BS_WriteValue(
  748. bs,
  749. PR_UINT16, data[PR_targetId],
  750. PR_UINT16, data[PR_targetActorId]
  751. );
  752. for (new slotId; slotId < PR_MAX_WEAPON_SLOTS; ++slotId) {
  753. if (!data[PR_slotUpdated][slotId]) {
  754. continue;
  755. }
  756. BS_WriteValue(
  757. bs,
  758. PR_UINT8, slotId,
  759. PR_UINT8, data[PR_slotWeaponId][slotId],
  760. PR_UINT16, data[PR_slotWeaponAmmo][slotId]
  761. );
  762. }
  763. }
  764. forward OnIncomingPacket(playerid, packetid, BitStream:bs);
  765. forward OnIncomingRPC(playerid, rpcid, BitStream:bs);
  766. forward OnOutcomingPacket(playerid, packetid, BitStream:bs);
  767. forward OnOutcomingRPC(playerid, rpcid, BitStream:bs);
  768. #if defined FILTERSCRIPT
  769. public OnFilterScriptInit()
  770. {
  771. PR_Init(false);
  772. #if defined PawnRakNet_OnFilterScriptInit
  773. PawnRakNet_OnFilterScriptInit();
  774. #endif
  775. return 1;
  776. }
  777. #if defined _ALS_OnFilterScriptInit
  778. #undef OnFilterScriptInit
  779. #else
  780. #define _ALS_OnFilterScriptInit
  781. #endif
  782. #define OnFilterScriptInit PawnRakNet_OnFilterScriptInit
  783. #if defined PawnRakNet_OnFilterScriptInit
  784. forward PawnRakNet_OnFilterScriptInit();
  785. #endif
  786. #else
  787. public OnGameModeInit()
  788. {
  789. PR_Init(true);
  790. #if defined PawnRakNet_OnGameModeInit
  791. PawnRakNet_OnGameModeInit();
  792. #endif
  793. return 1;
  794. }
  795. #if defined _ALS_OnGameModeInit
  796. #undef OnGameModeInit
  797. #else
  798. #define _ALS_OnGameModeInit
  799. #endif
  800. #define OnGameModeInit PawnRakNet_OnGameModeInit
  801. #if defined PawnRakNet_OnGameModeInit
  802. forward PawnRakNet_OnGameModeInit();
  803. #endif
  804. #endif
  805. #endif // !defined __cplusplus
  806. #endif // PAWNRAKNET_INC_