PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/v1.9-final/main/netmisc-new.c

https://github.com/simX/d2x-xl
C | 703 lines | 473 code | 69 blank | 161 comment | 49 complexity | d69df62042388a5f7aad341ddced0d17 MD5 | raw file
Possible License(s): GPL-2.0
  1. /* $Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $ */
  2. /*
  3. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  4. SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
  5. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  6. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  7. IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  8. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  9. FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  10. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
  11. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  12. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
  13. */
  14. /*
  15. *
  16. * Misc routines for network.
  17. *
  18. * Old Log:
  19. * Revision 1.1 1995/05/16 15:28:41 allender
  20. * Initial revision
  21. *
  22. * Revision 2.0 1995/02/27 11:27:24 john
  23. * New version 2.0, which has no anonymous unions, builds with
  24. * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  25. *
  26. * Revision 1.3 1994/11/19 15:19:34 mike
  27. * rip out unused code and data.
  28. *
  29. * Revision 1.2 1994/08/09 19:31:53 john
  30. * Networking changes.
  31. *
  32. * Revision 1.1 1994/08/08 11:06:07 john
  33. * Initial revision
  34. *
  35. *
  36. */
  37. #ifdef HAVE_CONFIG_H
  38. #include <conf.h>
  39. #endif
  40. #ifdef RCS
  41. static char rcsid[] = "$Id: netmisc.c,v 1.9 2003/10/04 19:13:32 btb Exp $";
  42. #endif
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include "inferno.h"
  46. #include "pstypes.h"
  47. #include "mono.h"
  48. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  49. #include "byteswap.h"
  50. #include "segment.h"
  51. #include "gameseg.h"
  52. #include "network.h"
  53. #include "wall.h"
  54. #include "ipx.h"
  55. #include "multi.h"
  56. #include "network.h"
  57. #include "object.h"
  58. #include "powerup.h"
  59. #include "netmisc.h"
  60. #include "error.h"
  61. static ubyte nmDataBuf [IPX_MAX_DATA_SIZE]; // used for tmp netgame packets as well as sending tObject data
  62. static ubyte *nmBufP = NULL;
  63. extern struct ipx_recv_data ipx_udpSrc;
  64. // if using the following macros in loops, the loop's body *must* be enclosed in curly braces,
  65. // or the macros won't work as intended, as the buffer pointer nmBufI will only be incremented
  66. // after the loop has been fully executed!
  67. #define BE_SET_INT(_src) *((int *) (nmBufP + nmBufI)) = INTEL_INT ((int) (_src)); nmBufI += 4
  68. #define BE_SET_SHORT(_src) *((short *) (nmBufP + nmBufI)) = INTEL_SHORT ((short) (_src)); nmBufI += 2
  69. #define BE_SET_BYTE(_src) nmBufP [nmBufI++] = (ubyte) (_src)
  70. #define BE_SET_BYTES(_src,_srcSize) memcpy (nmBufP + nmBufI, _src, _srcSize); nmBufI += (_srcSize)
  71. #define BE_GET_INT(_dest) (_dest) = INTEL_INT (*((int *) (nmBufP + nmBufI))); nmBufI += 4
  72. #define BE_GET_SHORT(_dest) (_dest) = INTEL_SHORT (*((short *) (nmBufP + nmBufI))); nmBufI += 2
  73. #define BE_GET_BYTE(_dest) (_dest) = nmBufP [nmBufI++]
  74. #define BE_GET_BYTES(_dest,_destSize) memcpy (_dest, nmBufP + nmBufI, _destSize); nmBufI += (_destSize)
  75. //------------------------------------------------------------------------------
  76. // routine to calculate the checksum of the segments. We add these specialized routines
  77. // since the current way is byte order dependent.
  78. void BEDoCheckSumCalc (ubyte *b, int len, unsigned int *ps1, unsigned int *ps2)
  79. {
  80. int s1 = *ps1;
  81. int s2 = *ps2;
  82. while(len--) {
  83. s1 += *b++;
  84. if (s1 >= 255)
  85. s1 -= 255;
  86. s2 += s1;
  87. }
  88. *ps1 = s1;
  89. *ps2 = s2;
  90. }
  91. //------------------------------------------------------------------------------
  92. ushort BECalcSegmentCheckSum (void)
  93. {
  94. int i, j, k;
  95. unsigned int sum1, sum2;
  96. short s;
  97. int t;
  98. sum1 = sum2 = 0;
  99. for (i = 0; i < gameData.segs.nLastSegment + 1; i++) {
  100. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  101. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].nType), 1, &sum1, &sum2);
  102. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].nFrame), 1, &sum1, &sum2);
  103. s = INTEL_SHORT (WallNumI (i, j));
  104. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  105. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].nBaseTex);
  106. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  107. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].nOvlTex);
  108. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  109. for (k = 0; k < 4; k++) {
  110. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].u));
  111. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  112. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].v));
  113. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  114. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].l));
  115. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  116. }
  117. for (k = 0; k < 2; k++) {
  118. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].x));
  119. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  120. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].y));
  121. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  122. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].z));
  123. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  124. }
  125. }
  126. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  127. s = INTEL_SHORT (gameData.segs.segments [i].children[j]);
  128. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  129. }
  130. for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
  131. s = INTEL_SHORT (gameData.segs.segments [i].verts [j]);
  132. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  133. }
  134. t = INTEL_INT (gameData.segs.segments [i].objects);
  135. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  136. }
  137. sum2 %= 255;
  138. return ((sum1 << 8) + sum2);
  139. }
  140. //------------------------------------------------------------------------------
  141. // following are routine for big endian hardware that will swap the elements of
  142. // structures send through the networking code. The structures and
  143. // this code must be kept in total sync
  144. void BEReceiveNetPlayerInfo (ubyte *data, tNetPlayerInfo *info)
  145. {
  146. int nmBufI = 0;
  147. nmBufP = data;
  148. BE_GET_BYTES (info->callsign, CALLSIGN_LEN + 1);
  149. BE_GET_BYTES (info->network.ipx.server, 4);
  150. BE_GET_BYTES (info->network.ipx.node, 6);
  151. BE_GET_BYTE (info->version_major);
  152. BE_GET_BYTE (info->version_minor);
  153. BE_GET_BYTE (info->computerType);
  154. BE_GET_BYTE (info->connected);
  155. //BE_GET_SHORT (info->socket);
  156. info->socket = *((short *) (data + nmBufI)); //don't swap!
  157. BE_GET_BYTE (info->rank);
  158. }
  159. //------------------------------------------------------------------------------
  160. void BESendNetPlayersPacket (ubyte *server, ubyte *node)
  161. {
  162. int i;
  163. int nmBufI = 0;
  164. nmBufP = nmDataBuf;
  165. #ifdef _DEBUG
  166. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  167. #endif
  168. BE_SET_BYTE (netPlayers.nType);
  169. BE_SET_INT (netPlayers.nSecurity);
  170. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  171. BE_SET_BYTES (netPlayers.players [i].callsign, CALLSIGN_LEN + 1);
  172. BE_SET_BYTES (netPlayers.players [i].network.ipx.server, 4);
  173. BE_SET_BYTES (netPlayers.players [i].network.ipx.node, 6);
  174. BE_SET_BYTE (netPlayers.players [i].version_major);
  175. BE_SET_BYTE (netPlayers.players [i].version_minor);
  176. BE_SET_BYTE (netPlayers.players [i].computerType);
  177. BE_SET_BYTE (netPlayers.players [i].connected);
  178. BE_SET_SHORT (netPlayers.players [i].socket);
  179. BE_SET_BYTE (netPlayers.players [i].rank);
  180. }
  181. if (!server && !node)
  182. IPXSendBroadcastData (nmBufP, nmBufI);
  183. else
  184. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  185. }
  186. //------------------------------------------------------------------------------
  187. void BEReceiveNetPlayersPacket (ubyte *data, tAllNetPlayersInfo *pinfo)
  188. {
  189. int i, nmBufI = 0;
  190. nmBufP = data;
  191. BE_GET_BYTE (pinfo->nType);
  192. BE_GET_INT (pinfo->nSecurity);
  193. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  194. BEReceiveNetPlayerInfo (data + nmBufI, pinfo->players + i);
  195. nmBufI += 26; // sizeof(tNetPlayerInfo) on the PC
  196. }
  197. }
  198. //------------------------------------------------------------------------------
  199. void BESendSequencePacket (tSequencePacket seq, ubyte *server, ubyte *node, ubyte *netAddress)
  200. {
  201. int nmBufI = 0;
  202. nmBufP = nmDataBuf;
  203. #ifdef _DEBUG
  204. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  205. #endif
  206. BE_SET_BYTE (seq.nType);
  207. BE_SET_INT (seq.nSecurity);
  208. nmBufI += 3;
  209. BE_SET_BYTES (seq.player.callsign, CALLSIGN_LEN + 1);
  210. BE_SET_BYTES (seq.player.network.ipx.server, 4);
  211. BE_SET_BYTES (seq.player.network.ipx.node, 6);
  212. BE_SET_BYTE (seq.player.version_major);
  213. BE_SET_BYTE (seq.player.version_minor);
  214. BE_SET_BYTE (seq.player.computerType);
  215. BE_SET_BYTE (seq.player.connected);
  216. BE_SET_SHORT (seq.player.socket);
  217. BE_SET_BYTE (seq.player.rank);
  218. if (netAddress)
  219. IPXSendPacketData (nmBufP, nmBufI, server, node, netAddress);
  220. else if (!server && !node)
  221. IPXSendBroadcastData (nmBufP, nmBufI);
  222. else
  223. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  224. }
  225. //------------------------------------------------------------------------------
  226. void BEReceiveSequencePacket (ubyte *data, tSequencePacket *seq)
  227. {
  228. int nmBufI = 0;
  229. nmBufP = data;
  230. BE_GET_BYTE (seq->nType);
  231. BE_GET_INT (seq->nSecurity);
  232. nmBufI += 3; // +3 for pad bytes
  233. BEReceiveNetPlayerInfo (data + nmBufI, &(seq->player));
  234. }
  235. //------------------------------------------------------------------------------
  236. void BESendNetGamePacket (ubyte *server, ubyte *node, ubyte *netAddress, int bLiteData)
  237. {
  238. int i;
  239. short *ps;
  240. int nmBufI = 0;
  241. nmBufP = nmDataBuf;
  242. #ifdef _DEBUG
  243. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  244. #endif
  245. BE_SET_BYTE (netGame.nType);
  246. BE_SET_INT (netGame.nSecurity);
  247. BE_SET_BYTES (netGame.game_name, NETGAME_NAME_LEN + 1);
  248. BE_SET_BYTES (netGame.mission_title, MISSION_NAME_LEN + 1);
  249. BE_SET_BYTES (netGame.szMissionName, 9);
  250. BE_SET_INT (netGame.levelnum);
  251. BE_SET_BYTE (netGame.gameMode);
  252. BE_SET_BYTE (netGame.RefusePlayers);
  253. BE_SET_BYTE (netGame.difficulty);
  254. BE_SET_BYTE (netGame.gameStatus);
  255. BE_SET_BYTE (netGame.numplayers);
  256. BE_SET_BYTE (netGame.max_numplayers);
  257. BE_SET_BYTE (netGame.numconnected);
  258. BE_SET_BYTE (netGame.gameFlags);
  259. BE_SET_BYTE (netGame.protocol_version);
  260. BE_SET_BYTE (netGame.version_major);
  261. BE_SET_BYTE (netGame.version_minor);
  262. BE_SET_BYTE (netGame.teamVector);
  263. if (bLiteData)
  264. goto do_send;
  265. BE_SET_SHORT (((ubyte *) &netGame.teamVector) + 1); // get the values for the first short bitfield
  266. BE_SET_SHORT (((ubyte *) &netGame.teamVector) + 3); // get the values for the first short bitfield
  267. BE_SET_BYTES (netGame.team_name, 2 * (CALLSIGN_LEN + 1));
  268. for (i = 0; i < MAX_PLAYERS; i++) {
  269. BE_SET_INT (netGame.locations [i]);
  270. }
  271. #if 1
  272. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netGame.kills [0][0]; i; i--, ps++) {
  273. BE_SET_SHORT (*ps);
  274. }
  275. #else
  276. {
  277. int j;
  278. for (i = 0; i < MAX_PLAYERS; i++) {
  279. for (j = 0; j < MAX_PLAYERS; j++) {
  280. BE_SET_SHORT (netGame.kills [i][j]);
  281. }
  282. }
  283. }
  284. #endif
  285. BE_SET_SHORT (netGame.segments_checksum);
  286. BE_SET_SHORT (netGame.teamKills [0]);
  287. BE_SET_SHORT (netGame.teamKills [1]);
  288. for (i = 0; i < MAX_PLAYERS; i++) {
  289. BE_SET_SHORT (netGame.killed [i]);
  290. }
  291. for (i = 0; i < MAX_PLAYERS; i++) {
  292. BE_SET_SHORT (netGame.playerKills [i]);
  293. }
  294. BE_SET_INT (netGame.KillGoal);
  295. BE_SET_INT (netGame.xPlayTimeAllowed);
  296. BE_SET_INT (netGame.xLevelTime);
  297. BE_SET_INT (netGame.control_invulTime);
  298. BE_SET_INT (netGame.monitor_vector);
  299. for (i = 0; i < MAX_PLAYERS; i++) {
  300. BE_SET_INT (netGame.player_score[i]);
  301. }
  302. BE_SET_BYTES (netGame.playerFlags, MAX_PLAYERS);
  303. BE_SET_SHORT (netGame.nPacketsPerSec);
  304. BE_SET_BYTE (netGame.bShortPackets);
  305. do_send:
  306. if (netAddress)
  307. IPXSendPacketData(nmBufP, nmBufI, server, node, netAddress);
  308. else if (!server && !node)
  309. IPXSendBroadcastData(nmBufP, nmBufI);
  310. else
  311. IPXSendInternetPacketData(nmBufP, nmBufI, server, node);
  312. }
  313. //------------------------------------------------------------------------------
  314. void BEReceiveNetGamePacket (ubyte *data, tNetgameInfo *netgame, int bLiteData)
  315. {
  316. int i;
  317. short *ps;
  318. int nmBufI = 0;
  319. nmBufP = data;
  320. BE_GET_BYTE (netgame->nType);
  321. BE_GET_INT (netgame->nSecurity);
  322. BE_GET_BYTES (netgame->game_name, NETGAME_NAME_LEN + 1);
  323. BE_GET_BYTES (netgame->mission_title, MISSION_NAME_LEN + 1);
  324. BE_GET_BYTES (netgame->szMissionName, 9);
  325. BE_GET_INT (netgame->levelnum);
  326. BE_GET_BYTE (netgame->gameMode);
  327. BE_GET_BYTE (netgame->RefusePlayers);
  328. BE_GET_BYTE (netgame->difficulty);
  329. BE_GET_BYTE (netgame->gameStatus);
  330. BE_GET_BYTE (netgame->numplayers);
  331. BE_GET_BYTE (netgame->max_numplayers);
  332. BE_GET_BYTE (netgame->numconnected);
  333. BE_GET_BYTE (netgame->gameFlags);
  334. BE_GET_BYTE (netgame->protocol_version);
  335. BE_GET_BYTE (netgame->version_major);
  336. BE_GET_BYTE (netgame->version_minor);
  337. BE_GET_BYTE (netgame->teamVector);
  338. if (bLiteData)
  339. return;
  340. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->teamVector) + 1)));
  341. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->teamVector) + 3)));
  342. BE_GET_BYTES (netgame->team_name, CALLSIGN_LEN + 1);
  343. for (i = 0; i < MAX_PLAYERS; i++) {
  344. BE_GET_INT (netgame->locations [i]);
  345. }
  346. #if 1
  347. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netgame->kills [0][0]; i; i--, ps++) {
  348. BE_GET_SHORT (*ps);
  349. }
  350. #else
  351. {
  352. int j;
  353. for (i = 0; i < MAX_PLAYERS; i++)
  354. for (j = 0; j < MAX_PLAYERS; j++) {
  355. BE_GET_SHORT (netgame->kills [i][j]);
  356. }
  357. }
  358. #endif
  359. BE_GET_SHORT (netgame->segments_checksum);
  360. BE_GET_SHORT (netgame->teamKills [0]);
  361. BE_GET_SHORT (netgame->teamKills [1]);
  362. for (i = 0; i < MAX_PLAYERS; i++) {
  363. BE_GET_SHORT (netgame->killed [i]);
  364. }
  365. for (i = 0; i < MAX_PLAYERS; i++) {
  366. BE_GET_SHORT (netgame->playerKills [i]);
  367. }
  368. BE_GET_INT (netgame->KillGoal);
  369. BE_GET_INT (netgame->xPlayTimeAllowed);
  370. BE_GET_INT (netgame->xLevelTime);
  371. BE_GET_INT (netgame->control_invulTime);
  372. BE_GET_INT (netgame->monitor_vector);
  373. for (i = 0; i < MAX_PLAYERS; i++) {
  374. BE_GET_INT (netgame->player_score [i]);
  375. }
  376. BE_GET_BYTES (netgame->playerFlags, MAX_PLAYERS);
  377. BE_GET_SHORT (netgame->nPacketsPerSec);
  378. BE_GET_BYTE (netgame->bShortPackets);
  379. }
  380. //------------------------------------------------------------------------------
  381. #define EGI_INTEL_SHORT_2BUF(_m) \
  382. *((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_SHORT (extraGameInfo [1]._m);
  383. #define EGI_INTEL_INT_2BUF(_m) \
  384. *((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_INT (extraGameInfo [1]._m);
  385. #define BUF2_EGI_INTEL_SHORT(_m) \
  386. extraGameInfo [1]._m = INTEL_SHORT (*((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  387. #define BUF2_EGI_INTEL_INT(_m) \
  388. extraGameInfo [1]._m = INTEL_INT (*((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  389. void BESendExtraGameInfo (ubyte *server, ubyte *node, ubyte *netAddress)
  390. {
  391. nmBufP = nmDataBuf;
  392. memcpy (nmBufP, &extraGameInfo [1], sizeof (extraGameInfo [0]));
  393. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  394. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  395. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  396. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  397. EGI_INTEL_INT_2BUF (nSpawnDelay);
  398. if (netAddress)
  399. IPXSendPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node, netAddress);
  400. else if (!server && !node)
  401. IPXSendBroadcastData (nmBufP, sizeof (extraGameInfo [0]));
  402. else
  403. IPXSendInternetPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node);
  404. }
  405. //------------------------------------------------------------------------------
  406. void BEReceiveExtraGameInfo (ubyte *data, tExtraGameInfo *extraGameInfo)
  407. {
  408. nmBufP = data;
  409. memcpy (&extraGameInfo [1], nmBufP, sizeof (extraGameInfo [0]));
  410. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  411. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  412. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  413. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  414. BUF2_EGI_INTEL_INT (nSpawnDelay);
  415. }
  416. //------------------------------------------------------------------------------
  417. void BESwapObject ( tObject *objP)
  418. {
  419. // swap the short and int entries for this tObject
  420. objP->nSignature = INTEL_INT (objP->nSignature);
  421. objP->next = INTEL_SHORT (objP->next);
  422. objP->prev = INTEL_SHORT (objP->prev);
  423. objP->nSegment = INTEL_SHORT (objP->nSegment);
  424. INTEL_VECTOR (&objP->position.vPos);
  425. INTEL_MATRIX (&objP->position.mOrient);
  426. objP->size = INTEL_INT (objP->size);
  427. objP->shields = INTEL_INT (objP->shields);
  428. INTEL_VECTOR (&objP->vLastPos);
  429. objP->lifeleft = INTEL_INT (objP->lifeleft);
  430. switch (objP->movementType) {
  431. case MT_PHYSICS:
  432. INTEL_VECTOR (&objP->mType.physInfo.velocity);
  433. INTEL_VECTOR (&objP->mType.physInfo.thrust);
  434. objP->mType.physInfo.mass = INTEL_INT (objP->mType.physInfo.mass);
  435. objP->mType.physInfo.drag = INTEL_INT (objP->mType.physInfo.drag);
  436. objP->mType.physInfo.brakes = INTEL_INT (objP->mType.physInfo.brakes);
  437. INTEL_VECTOR (&objP->mType.physInfo.rotVel);
  438. INTEL_VECTOR (&objP->mType.physInfo.rotThrust);
  439. objP->mType.physInfo.turnRoll = INTEL_INT (objP->mType.physInfo.turnRoll);
  440. objP->mType.physInfo.flags = INTEL_SHORT (objP->mType.physInfo.flags);
  441. break;
  442. case MT_SPINNING:
  443. INTEL_VECTOR (&objP->mType.spinRate);
  444. break;
  445. }
  446. switch (objP->controlType) {
  447. case CT_WEAPON:
  448. objP->cType.laserInfo.parentType = INTEL_SHORT (objP->cType.laserInfo.parentType);
  449. objP->cType.laserInfo.nParentObj = INTEL_SHORT (objP->cType.laserInfo.nParentObj);
  450. objP->cType.laserInfo.nParentSig = INTEL_INT (objP->cType.laserInfo.nParentSig);
  451. objP->cType.laserInfo.creationTime = INTEL_INT (objP->cType.laserInfo.creationTime);
  452. objP->cType.laserInfo.nLastHitObj = INTEL_SHORT (objP->cType.laserInfo.nLastHitObj);
  453. if (objP->cType.laserInfo.nLastHitObj < 0)
  454. objP->cType.laserInfo.nLastHitObj = 0;
  455. else {
  456. gameData.objs.nHitObjects [OBJ_IDX (objP) * MAX_HIT_OBJECTS] = objP->cType.laserInfo.nLastHitObj;
  457. objP->cType.laserInfo.nLastHitObj = 1;
  458. }
  459. objP->cType.laserInfo.nMslLock = INTEL_SHORT (objP->cType.laserInfo.nMslLock);
  460. objP->cType.laserInfo.multiplier = INTEL_INT (objP->cType.laserInfo.multiplier);
  461. break;
  462. case CT_EXPLOSION:
  463. objP->cType.explInfo.nSpawnTime = INTEL_INT (objP->cType.explInfo.nSpawnTime);
  464. objP->cType.explInfo.nDeleteTime = INTEL_INT (objP->cType.explInfo.nDeleteTime);
  465. objP->cType.explInfo.nDeleteObj = INTEL_SHORT (objP->cType.explInfo.nDeleteObj);
  466. objP->cType.explInfo.nAttachParent = INTEL_SHORT (objP->cType.explInfo.nAttachParent);
  467. objP->cType.explInfo.nPrevAttach = INTEL_SHORT (objP->cType.explInfo.nPrevAttach);
  468. objP->cType.explInfo.nNextAttach = INTEL_SHORT (objP->cType.explInfo.nNextAttach);
  469. break;
  470. case CT_AI:
  471. objP->cType.aiInfo.nHideSegment = INTEL_SHORT (objP->cType.aiInfo.nHideSegment);
  472. objP->cType.aiInfo.nHideIndex = INTEL_SHORT (objP->cType.aiInfo.nHideIndex);
  473. objP->cType.aiInfo.nPathLength = INTEL_SHORT (objP->cType.aiInfo.nPathLength);
  474. objP->cType.aiInfo.nDangerLaser = INTEL_SHORT (objP->cType.aiInfo.nDangerLaser);
  475. objP->cType.aiInfo.nDangerLaserSig = INTEL_INT (objP->cType.aiInfo.nDangerLaserSig);
  476. objP->cType.aiInfo.xDyingStartTime = INTEL_INT (objP->cType.aiInfo.xDyingStartTime);
  477. break;
  478. case CT_LIGHT:
  479. objP->cType.lightInfo.intensity = INTEL_INT (objP->cType.lightInfo.intensity);
  480. break;
  481. case CT_POWERUP:
  482. objP->cType.powerupInfo.count = INTEL_INT (objP->cType.powerupInfo.count);
  483. objP->cType.powerupInfo.creationTime = INTEL_INT (objP->cType.powerupInfo.creationTime);
  484. break;
  485. }
  486. switch (objP->renderType) {
  487. case RT_MORPH:
  488. case RT_POLYOBJ: {
  489. int i;
  490. objP->rType.polyObjInfo.nModel = INTEL_INT (objP->rType.polyObjInfo.nModel);
  491. for (i = 0; i < MAX_SUBMODELS; i++)
  492. INTEL_ANGVEC (objP->rType.polyObjInfo.animAngles + i);
  493. objP->rType.polyObjInfo.nSubObjFlags = INTEL_INT (objP->rType.polyObjInfo.nSubObjFlags);
  494. objP->rType.polyObjInfo.nTexOverride = INTEL_INT (objP->rType.polyObjInfo.nTexOverride);
  495. objP->rType.polyObjInfo.nAltTextures = INTEL_INT (objP->rType.polyObjInfo.nAltTextures);
  496. break;
  497. }
  498. case RT_WEAPON_VCLIP:
  499. case RT_HOSTAGE:
  500. case RT_POWERUP:
  501. case RT_FIREBALL:
  502. case RT_THRUSTER:
  503. objP->rType.vClipInfo.nClipIndex = INTEL_INT (objP->rType.vClipInfo.nClipIndex);
  504. objP->rType.vClipInfo.xFrameTime = INTEL_INT (objP->rType.vClipInfo.xFrameTime);
  505. break;
  506. case RT_LASER:
  507. break;
  508. }
  509. }
  510. #endif /* WORDS_BIGENDIAN */
  511. //------------------------------------------------------------------------------
  512. // Calculates the checksum of a block of memory.
  513. ushort NetMiscCalcCheckSum (void * vptr, int len)
  514. {
  515. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  516. return BECalcSegmentCheckSum ();
  517. #else
  518. ubyte *ptr = (ubyte *) vptr;
  519. unsigned int sum1, sum2;
  520. sum1 = sum2 = 0;
  521. for (; len; len--) {
  522. sum1 += *ptr++;
  523. #if 1
  524. sum1 %= 255;
  525. #else
  526. if (sum1 >= 255)
  527. sum1 -= 255;
  528. #endif
  529. sum2 += sum1;
  530. }
  531. return (sum1 * 256 + sum2 % 255);
  532. #endif
  533. }
  534. //------------------------------------------------------------------------------
  535. // needs to be recoded to actually work with big endian!
  536. //--unused-- //Finds the difference between block1 and block2. Fills in diff_buffer and
  537. //--unused-- //returns the size of diff_buffer.
  538. //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
  539. //--unused-- {
  540. //--unused-- int mode;
  541. //--unused-- ushort *c1, *c2, *diff_start, *c3;
  542. //--unused-- int i, j, size, diff, n , same;
  543. //--unused--
  544. //--unused-- size=(block_size+1)/sizeof(ushort);
  545. //--unused-- c1 = (ushort *)block1;
  546. //--unused-- c2 = (ushort *)block2;
  547. //--unused-- c3 = (ushort *)diff_buffer;
  548. //--unused--
  549. //--unused-- mode = same = diff = n = 0;
  550. //--unused--
  551. //--unused-- for (i=0; i<size; i++, c1++, c2++) {
  552. //--unused-- if (*c1 != *c2) {
  553. //--unused-- if (mode==0) {
  554. //--unused-- mode = 1;
  555. //--unused-- c3[n++] = same;
  556. //--unused-- same=0; diff=0;
  557. //--unused-- diff_start = c2;
  558. //--unused-- }
  559. //--unused-- *c1 = *c2;
  560. //--unused-- diff++;
  561. //--unused-- if (diff==65535) {
  562. //--unused-- mode = 0;
  563. //--unused-- // send how many diff ones.
  564. //--unused-- c3[n++]=diff;
  565. //--unused-- // send all the diff ones.
  566. //--unused-- for (j=0; j<diff; j++)
  567. //--unused-- c3[n++] = diff_start[j];
  568. //--unused-- same=0; diff=0;
  569. //--unused-- diff_start = c2;
  570. //--unused-- }
  571. //--unused-- } else {
  572. //--unused-- if (mode==1) {
  573. //--unused-- mode=0;
  574. //--unused-- // send how many diff ones.
  575. //--unused-- c3[n++]=diff;
  576. //--unused-- // send all the diff ones.
  577. //--unused-- for (j=0; j<diff; j++)
  578. //--unused-- c3[n++] = diff_start[j];
  579. //--unused-- same=0; diff=0;
  580. //--unused-- diff_start = c2;
  581. //--unused-- }
  582. //--unused-- same++;
  583. //--unused-- if (same==65535) {
  584. //--unused-- mode=1;
  585. //--unused-- // send how many the same
  586. //--unused-- c3[n++] = same;
  587. //--unused-- same=0; diff=0;
  588. //--unused-- diff_start = c2;
  589. //--unused-- }
  590. //--unused-- }
  591. //--unused--
  592. //--unused-- }
  593. //--unused-- if (mode==0) {
  594. //--unused-- // send how many the same
  595. //--unused-- c3[n++] = same;
  596. //--unused-- } else {
  597. //--unused-- // send how many diff ones.
  598. //--unused-- c3[n++]=diff;
  599. //--unused-- // send all the diff ones.
  600. //--unused-- for (j=0; j<diff; j++)
  601. //--unused-- c3[n++] = diff_start[j];
  602. //--unused-- }
  603. //--unused--
  604. //--unused-- return n*2;
  605. //--unused-- }
  606. //--unused-- //Applies diff_buffer to block1 to create a new block1. Returns the final
  607. //--unused-- //size of block1.
  608. //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
  609. //--unused-- {
  610. //--unused-- unsigned int i, j, n, size;
  611. //--unused-- ushort *c1, *c2;
  612. //--unused--
  613. //--unused-- c1 = (ushort *)diff_buffer;
  614. //--unused-- c2 = (ushort *)block1;
  615. //--unused--
  616. //--unused-- size = diff_size/2;
  617. //--unused--
  618. //--unused-- i=j=0;
  619. //--unused-- while (1) {
  620. //--unused-- j += c1[i]; // Same
  621. //--unused-- i++;
  622. //--unused-- if (i>=size) break;
  623. //--unused-- n = c1[i]; // ndiff
  624. //--unused-- i++;
  625. //--unused-- if (n>0) {
  626. //--unused-- //AsserT (n* < 256);
  627. //--unused-- memcpy(&c2[j], &c1[i], n*2);
  628. //--unused-- i += n;
  629. //--unused-- j += n;
  630. //--unused-- }
  631. //--unused-- if (i>=size) break;
  632. //--unused-- }
  633. //--unused-- return j*2;
  634. //--unused-- }