PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/simX/d2x-xl
C | 699 lines | 469 code | 69 blank | 161 comment | 47 complexity | 9167be05671b08484eb4f1063a010032 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. #ifdef NETWORK
  57. #include "network.h"
  58. #endif
  59. #include "object.h"
  60. #include "powerup.h"
  61. #include "netmisc.h"
  62. #include "error.h"
  63. static ubyte nmDataBuf [IPX_MAX_DATA_SIZE]; // used for tmp netgame packets as well as sending object data
  64. static ubyte *nmBufP = NULL;
  65. extern struct ipx_recv_data ipx_udpSrc;
  66. // if using the following macros in loops, the loop's body *must* be enclosed in curly braces,
  67. // or the macros won't work as intended, as the buffer pointer nmBufI will only be incremented
  68. // after the loop has been fully executed!
  69. #define BE_SET_INT(_src) *((int *) (nmBufP + nmBufI)) = INTEL_INT ((int) (_src)); nmBufI += 4
  70. #define BE_SET_SHORT(_src) *((short *) (nmBufP + nmBufI)) = INTEL_SHORT ((short) (_src)); nmBufI += 2
  71. #define BE_SET_BYTE(_src) nmBufP [nmBufI++] = (ubyte) (_src)
  72. #define BE_SET_BYTES(_src,_srcSize) memcpy (nmBufP + nmBufI, _src, _srcSize); nmBufI += (_srcSize)
  73. #define BE_GET_INT(_dest) (_dest) = INTEL_INT (*((int *) (nmBufP + nmBufI))); nmBufI += 4
  74. #define BE_GET_SHORT(_dest) (_dest) = INTEL_SHORT (*((short *) (nmBufP + nmBufI))); nmBufI += 2
  75. #define BE_GET_BYTE(_dest) (_dest) = nmBufP [nmBufI++]
  76. #define BE_GET_BYTES(_dest,_destSize) memcpy (_dest, nmBufP + nmBufI, _destSize); nmBufI += (_destSize)
  77. //------------------------------------------------------------------------------
  78. // routine to calculate the checksum of the segments. We add these specialized routines
  79. // since the current way is byte order dependent.
  80. void BEDoCheckSumCalc (ubyte *b, int len, unsigned int *ps1, unsigned int *ps2)
  81. {
  82. int s1 = *ps1;
  83. int s2 = *ps2;
  84. while(len--) {
  85. s1 += *b++;
  86. if (s1 >= 255)
  87. s1 -= 255;
  88. s2 += s1;
  89. }
  90. *ps1 = s1;
  91. *ps2 = s2;
  92. }
  93. //------------------------------------------------------------------------------
  94. ushort BECalcSegmentCheckSum (void)
  95. {
  96. int i, j, k;
  97. unsigned int sum1, sum2;
  98. short s;
  99. int t;
  100. sum1 = sum2 = 0;
  101. for (i = 0; i < gameData.segs.nLastSegment + 1; i++) {
  102. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  103. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].type), 1, &sum1, &sum2);
  104. BEDoCheckSumCalc (&(gameData.segs.segments [i].sides [j].frame_num), 1, &sum1, &sum2);
  105. s = INTEL_SHORT (WallNumI (i, j));
  106. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  107. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].tmap_num);
  108. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  109. s = INTEL_SHORT (gameData.segs.segments [i].sides [j].tmap_num2);
  110. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  111. for (k = 0; k < 4; k++) {
  112. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].u));
  113. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  114. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].v));
  115. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  116. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].uvls [k].l));
  117. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  118. }
  119. for (k = 0; k < 2; k++) {
  120. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].x));
  121. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  122. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].y));
  123. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  124. t = INTEL_INT (((int) gameData.segs.segments [i].sides [j].normals [k].z));
  125. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  126. }
  127. }
  128. for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
  129. s = INTEL_SHORT (gameData.segs.segments [i].children[j]);
  130. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  131. }
  132. for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
  133. s = INTEL_SHORT (gameData.segs.segments [i].verts [j]);
  134. BEDoCheckSumCalc ((ubyte *)&s, 2, &sum1, &sum2);
  135. }
  136. t = INTEL_INT (gameData.segs.segments [i].objects);
  137. BEDoCheckSumCalc ((ubyte *)&t, 4, &sum1, &sum2);
  138. }
  139. sum2 %= 255;
  140. return ((sum1 << 8) + sum2);
  141. }
  142. //------------------------------------------------------------------------------
  143. // following are routine for big endian hardware that will swap the elements of
  144. // structures send through the networking code. The structures and
  145. // this code must be kept in total sync
  146. void BEReceiveNetPlayerInfo (ubyte *data, netplayer_info *info)
  147. {
  148. int nmBufI = 0;
  149. nmBufP = data;
  150. BE_GET_BYTES (info->callsign, CALLSIGN_LEN + 1);
  151. BE_GET_BYTES (info->network.ipx.server, 4);
  152. BE_GET_BYTES (info->network.ipx.node, 6);
  153. BE_GET_BYTE (info->version_major);
  154. BE_GET_BYTE (info->version_minor);
  155. BE_GET_BYTE (info->computer_type);
  156. BE_GET_BYTE (info->connected);
  157. //BE_GET_SHORT (info->socket);
  158. info->socket = *((short *) (data + nmBufI)); //don't swap!
  159. BE_GET_BYTE (info->rank);
  160. }
  161. //------------------------------------------------------------------------------
  162. void BESendNetPlayersPacket (ubyte *server, ubyte *node)
  163. {
  164. int i;
  165. int nmBufI = 0;
  166. nmBufP = nmDataBuf;
  167. #ifdef _DEBUG
  168. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  169. #endif
  170. BE_SET_BYTE (netPlayers.type);
  171. BE_SET_INT (netPlayers.Security);
  172. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  173. BE_SET_BYTES (netPlayers.players [i].callsign, CALLSIGN_LEN + 1);
  174. BE_SET_BYTES (netPlayers.players [i].network.ipx.server, 4);
  175. BE_SET_BYTES (netPlayers.players [i].network.ipx.node, 6);
  176. BE_SET_BYTE (netPlayers.players [i].version_major);
  177. BE_SET_BYTE (netPlayers.players [i].version_minor);
  178. BE_SET_BYTE (netPlayers.players [i].computer_type);
  179. BE_SET_BYTE (netPlayers.players [i].connected);
  180. BE_SET_SHORT (netPlayers.players [i].socket);
  181. BE_SET_BYTE (netPlayers.players [i].rank);
  182. }
  183. if (!server && !node)
  184. IPXSendBroadcastData (nmBufP, nmBufI);
  185. else
  186. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  187. }
  188. //------------------------------------------------------------------------------
  189. void BEReceiveNetPlayersPacket (ubyte *data, allNetPlayers_info *pinfo)
  190. {
  191. int i, nmBufI = 0;
  192. nmBufP = data;
  193. BE_GET_BYTE (pinfo->type);
  194. BE_GET_INT (pinfo->Security);
  195. for (i = 0; i < MAX_PLAYERS + 4; i++) {
  196. BEReceiveNetPlayerInfo (data + nmBufI, pinfo->players + i);
  197. nmBufI += 26; // sizeof(netplayer_info) on the PC
  198. }
  199. }
  200. //------------------------------------------------------------------------------
  201. void BESendSequencePacket (sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address)
  202. {
  203. int nmBufI = 0;
  204. nmBufP = nmDataBuf;
  205. #ifdef _DEBUG
  206. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  207. #endif
  208. BE_SET_BYTE (seq.type);
  209. BE_SET_INT (seq.Security);
  210. nmBufI += 3;
  211. BE_SET_BYTES (seq.player.callsign, CALLSIGN_LEN + 1);
  212. BE_SET_BYTES (seq.player.network.ipx.server, 4);
  213. BE_SET_BYTES (seq.player.network.ipx.node, 6);
  214. BE_SET_BYTE (seq.player.version_major);
  215. BE_SET_BYTE (seq.player.version_minor);
  216. BE_SET_BYTE (seq.player.computer_type);
  217. BE_SET_BYTE (seq.player.connected);
  218. BE_SET_SHORT (seq.player.socket);
  219. BE_SET_BYTE (seq.player.rank);
  220. if (net_address)
  221. IPXSendPacketData (nmBufP, nmBufI, server, node, net_address);
  222. else if (!server && !node)
  223. IPXSendBroadcastData (nmBufP, nmBufI);
  224. else
  225. IPXSendInternetPacketData (nmBufP, nmBufI, server, node);
  226. }
  227. //------------------------------------------------------------------------------
  228. void BEReceiveSequencePacket (ubyte *data, sequence_packet *seq)
  229. {
  230. int nmBufI = 0;
  231. nmBufP = data;
  232. BE_GET_BYTE (seq->type);
  233. BE_GET_INT (seq->Security);
  234. nmBufI += 3; // +3 for pad bytes
  235. BEReceiveNetPlayerInfo (data + nmBufI, &(seq->player));
  236. }
  237. //------------------------------------------------------------------------------
  238. void BESendNetGamePacket (ubyte *server, ubyte *node, ubyte *net_address, int bLiteData)
  239. {
  240. int i;
  241. short *ps;
  242. int nmBufI = 0;
  243. nmBufP = nmDataBuf;
  244. #ifdef _DEBUG
  245. memset (nmBufP, 0, IPX_MAX_DATA_SIZE); //this takes time and shouldn't be necessary
  246. #endif
  247. BE_SET_BYTE (netGame.type);
  248. BE_SET_INT (netGame.Security);
  249. BE_SET_BYTES (netGame.game_name, NETGAME_NAME_LEN + 1);
  250. BE_SET_BYTES (netGame.mission_title, MISSION_NAME_LEN + 1);
  251. BE_SET_BYTES (netGame.mission_name, 9);
  252. BE_SET_INT (netGame.levelnum);
  253. BE_SET_BYTE (netGame.gamemode);
  254. BE_SET_BYTE (netGame.RefusePlayers);
  255. BE_SET_BYTE (netGame.difficulty);
  256. BE_SET_BYTE (netGame.game_status);
  257. BE_SET_BYTE (netGame.numplayers);
  258. BE_SET_BYTE (netGame.max_numplayers);
  259. BE_SET_BYTE (netGame.numconnected);
  260. BE_SET_BYTE (netGame.game_flags);
  261. BE_SET_BYTE (netGame.protocol_version);
  262. BE_SET_BYTE (netGame.version_major);
  263. BE_SET_BYTE (netGame.version_minor);
  264. BE_SET_BYTE (netGame.team_vector);
  265. if (bLiteData)
  266. goto do_send;
  267. BE_SET_SHORT (((ubyte *) &netGame.team_vector) + 1); // get the values for the first short bitfield
  268. BE_SET_SHORT (((ubyte *) &netGame.team_vector) + 3); // get the values for the first short bitfield
  269. BE_SET_BYTES (netGame.team_name, 2 * (CALLSIGN_LEN + 1));
  270. for (i = 0; i < MAX_PLAYERS; i++) {
  271. BE_SET_INT (netGame.locations [i]);
  272. }
  273. #if 1
  274. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netGame.kills [0][0]; i; i--, ps++) {
  275. BE_SET_SHORT (*ps);
  276. }
  277. #else
  278. {
  279. int j;
  280. for (i = 0; i < MAX_PLAYERS; i++) {
  281. for (j = 0; j < MAX_PLAYERS; j++) {
  282. BE_SET_SHORT (netGame.kills [i][j]);
  283. }
  284. }
  285. }
  286. #endif
  287. BE_SET_SHORT (netGame.segments_checksum);
  288. BE_SET_SHORT (netGame.team_kills [0]);
  289. BE_SET_SHORT (netGame.team_kills [1]);
  290. for (i = 0; i < MAX_PLAYERS; i++) {
  291. BE_SET_SHORT (netGame.killed [i]);
  292. }
  293. for (i = 0; i < MAX_PLAYERS; i++) {
  294. BE_SET_SHORT (netGame.player_kills [i]);
  295. }
  296. BE_SET_INT (netGame.KillGoal);
  297. BE_SET_INT (netGame.PlayTimeAllowed);
  298. BE_SET_INT (netGame.level_time);
  299. BE_SET_INT (netGame.control_invul_time);
  300. BE_SET_INT (netGame.monitor_vector);
  301. for (i = 0; i < MAX_PLAYERS; i++) {
  302. BE_SET_INT (netGame.player_score[i]);
  303. }
  304. BE_SET_BYTES (netGame.player_flags, MAX_PLAYERS);
  305. BE_SET_SHORT (netGame.nPacketsPerSec);
  306. BE_SET_BYTE (netGame.bShortPackets);
  307. do_send:
  308. if (net_address)
  309. IPXSendPacketData(nmBufP, nmBufI, server, node, net_address);
  310. else if (!server && !node)
  311. IPXSendBroadcastData(nmBufP, nmBufI);
  312. else
  313. IPXSendInternetPacketData(nmBufP, nmBufI, server, node);
  314. }
  315. //------------------------------------------------------------------------------
  316. void BEReceiveNetGamePacket (ubyte *data, netgame_info *netgame, int bLiteData)
  317. {
  318. int i;
  319. short *ps;
  320. int nmBufI = 0;
  321. nmBufP = data;
  322. BE_GET_BYTE (netgame->type);
  323. BE_GET_INT (netgame->Security);
  324. BE_GET_BYTES (netgame->game_name, NETGAME_NAME_LEN + 1);
  325. BE_GET_BYTES (netgame->mission_title, MISSION_NAME_LEN + 1);
  326. BE_GET_BYTES (netgame->mission_name, 9);
  327. BE_GET_INT (netgame->levelnum);
  328. BE_GET_BYTE (netgame->gamemode);
  329. BE_GET_BYTE (netgame->RefusePlayers);
  330. BE_GET_BYTE (netgame->difficulty);
  331. BE_GET_BYTE (netgame->game_status);
  332. BE_GET_BYTE (netgame->numplayers);
  333. BE_GET_BYTE (netgame->max_numplayers);
  334. BE_GET_BYTE (netgame->numconnected);
  335. BE_GET_BYTE (netgame->game_flags);
  336. BE_GET_BYTE (netgame->protocol_version);
  337. BE_GET_BYTE (netgame->version_major);
  338. BE_GET_BYTE (netgame->version_minor);
  339. BE_GET_BYTE (netgame->team_vector);
  340. if (bLiteData)
  341. return;
  342. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->team_vector) + 1)));
  343. BE_GET_SHORT (*((short *) (((ubyte *) &netgame->team_vector) + 3)));
  344. BE_GET_BYTES (netgame->team_name, CALLSIGN_LEN + 1);
  345. for (i = 0; i < MAX_PLAYERS; i++) {
  346. BE_GET_INT (netgame->locations [i]);
  347. }
  348. #if 1
  349. for (i = MAX_PLAYERS * MAX_PLAYERS, ps = &netgame->kills [0][0]; i; i--, ps++) {
  350. BE_GET_SHORT (*ps);
  351. }
  352. #else
  353. {
  354. int j;
  355. for (i = 0; i < MAX_PLAYERS; i++)
  356. for (j = 0; j < MAX_PLAYERS; j++) {
  357. BE_GET_SHORT (netgame->kills [i][j]);
  358. }
  359. }
  360. #endif
  361. BE_GET_SHORT (netgame->segments_checksum);
  362. BE_GET_SHORT (netgame->team_kills [0]);
  363. BE_GET_SHORT (netgame->team_kills [1]);
  364. for (i = 0; i < MAX_PLAYERS; i++) {
  365. BE_GET_SHORT (netgame->killed [i]);
  366. }
  367. for (i = 0; i < MAX_PLAYERS; i++) {
  368. BE_GET_SHORT (netgame->player_kills [i]);
  369. }
  370. BE_GET_INT (netgame->KillGoal);
  371. BE_GET_INT (netgame->PlayTimeAllowed);
  372. BE_GET_INT (netgame->level_time);
  373. BE_GET_INT (netgame->control_invul_time);
  374. BE_GET_INT (netgame->monitor_vector);
  375. for (i = 0; i < MAX_PLAYERS; i++) {
  376. BE_GET_INT (netgame->player_score [i]);
  377. }
  378. BE_GET_BYTES (netgame->player_flags, MAX_PLAYERS);
  379. BE_GET_SHORT (netgame->nPacketsPerSec);
  380. BE_GET_BYTE (netgame->bShortPackets);
  381. }
  382. //------------------------------------------------------------------------------
  383. #define EGI_INTEL_SHORT_2BUF(_m) \
  384. *((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_SHORT (extraGameInfo [1]._m);
  385. #define EGI_INTEL_INT_2BUF(_m) \
  386. *((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))) = INTEL_INT (extraGameInfo [1]._m);
  387. #define BUF2_EGI_INTEL_SHORT(_m) \
  388. extraGameInfo [1]._m = INTEL_SHORT (*((short *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  389. #define BUF2_EGI_INTEL_INT(_m) \
  390. extraGameInfo [1]._m = INTEL_INT (*((int *) (nmBufP + ((char *) &extraGameInfo [1]._m - (char *) &extraGameInfo [1]))));
  391. void BESendExtraGameInfo (ubyte *server, ubyte *node, ubyte *net_address)
  392. {
  393. nmBufP = nmDataBuf;
  394. memcpy (nmBufP, &extraGameInfo [1], sizeof (extraGameInfo [0]));
  395. EGI_INTEL_SHORT_2BUF (entropy.nMaxVirusCapacity);
  396. EGI_INTEL_SHORT_2BUF (entropy.nEnergyFillRate);
  397. EGI_INTEL_SHORT_2BUF (entropy.nShieldFillRate);
  398. EGI_INTEL_SHORT_2BUF (entropy.nShieldDamageRate);
  399. EGI_INTEL_INT_2BUF (nSpawnDelay);
  400. if (net_address)
  401. IPXSendPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node, net_address);
  402. else if (!server && !node)
  403. IPXSendBroadcastData (nmBufP, sizeof (extraGameInfo [0]));
  404. else
  405. IPXSendInternetPacketData (nmBufP, sizeof (extraGameInfo [0]), server, node);
  406. }
  407. //------------------------------------------------------------------------------
  408. void BEReceiveExtraGameInfo (ubyte *data, extra_gameinfo *extraGameInfo)
  409. {
  410. nmBufP = data;
  411. memcpy (&extraGameInfo [1], nmBufP, sizeof (extraGameInfo [0]));
  412. BUF2_EGI_INTEL_SHORT (entropy.nMaxVirusCapacity);
  413. BUF2_EGI_INTEL_SHORT (entropy.nEnergyFillRate);
  414. BUF2_EGI_INTEL_SHORT (entropy.nShieldFillRate);
  415. BUF2_EGI_INTEL_SHORT (entropy.nShieldDamageRate);
  416. BUF2_EGI_INTEL_INT (nSpawnDelay);
  417. }
  418. //------------------------------------------------------------------------------
  419. void BESwapObject ( object *objP)
  420. {
  421. // swap the short and int entries for this object
  422. objP->signature = INTEL_INT (objP->signature);
  423. objP->next = INTEL_SHORT (objP->next);
  424. objP->prev = INTEL_SHORT (objP->prev);
  425. objP->segnum = INTEL_SHORT (objP->segnum);
  426. INTEL_VECTOR (&objP->pos);
  427. INTEL_MATRIX (&objP->orient);
  428. objP->size = INTEL_INT (objP->size);
  429. objP->shields = INTEL_INT (objP->shields);
  430. INTEL_VECTOR (&objP->last_pos);
  431. objP->lifeleft = INTEL_INT (objP->lifeleft);
  432. switch (objP->movement_type) {
  433. case MT_PHYSICS:
  434. INTEL_VECTOR (&objP->mtype.phys_info.velocity);
  435. INTEL_VECTOR (&objP->mtype.phys_info.thrust);
  436. objP->mtype.phys_info.mass = INTEL_INT (objP->mtype.phys_info.mass);
  437. objP->mtype.phys_info.drag = INTEL_INT (objP->mtype.phys_info.drag);
  438. objP->mtype.phys_info.brakes = INTEL_INT (objP->mtype.phys_info.brakes);
  439. INTEL_VECTOR (&objP->mtype.phys_info.rotvel);
  440. INTEL_VECTOR (&objP->mtype.phys_info.rotthrust);
  441. objP->mtype.phys_info.turnroll = INTEL_INT (objP->mtype.phys_info.turnroll);
  442. objP->mtype.phys_info.flags = INTEL_SHORT (objP->mtype.phys_info.flags);
  443. break;
  444. case MT_SPINNING:
  445. INTEL_VECTOR (&objP->mtype.spin_rate);
  446. break;
  447. }
  448. switch (objP->control_type) {
  449. case CT_WEAPON:
  450. objP->ctype.laser_info.parent_type = INTEL_SHORT (objP->ctype.laser_info.parent_type);
  451. objP->ctype.laser_info.parent_num = INTEL_SHORT (objP->ctype.laser_info.parent_num);
  452. objP->ctype.laser_info.parent_signature = INTEL_INT (objP->ctype.laser_info.parent_signature);
  453. objP->ctype.laser_info.creation_time = INTEL_INT (objP->ctype.laser_info.creation_time);
  454. objP->ctype.laser_info.last_hitobj = INTEL_SHORT (objP->ctype.laser_info.last_hitobj);
  455. objP->ctype.laser_info.track_goal = INTEL_SHORT (objP->ctype.laser_info.track_goal);
  456. objP->ctype.laser_info.multiplier = INTEL_INT (objP->ctype.laser_info.multiplier);
  457. break;
  458. case CT_EXPLOSION:
  459. objP->ctype.expl_info.spawn_time = INTEL_INT (objP->ctype.expl_info.spawn_time);
  460. objP->ctype.expl_info.delete_time = INTEL_INT (objP->ctype.expl_info.delete_time);
  461. objP->ctype.expl_info.delete_objnum = INTEL_SHORT (objP->ctype.expl_info.delete_objnum);
  462. objP->ctype.expl_info.attach_parent = INTEL_SHORT (objP->ctype.expl_info.attach_parent);
  463. objP->ctype.expl_info.prev_attach = INTEL_SHORT (objP->ctype.expl_info.prev_attach);
  464. objP->ctype.expl_info.next_attach = INTEL_SHORT (objP->ctype.expl_info.next_attach);
  465. break;
  466. case CT_AI:
  467. objP->ctype.ai_info.hide_segment = INTEL_SHORT (objP->ctype.ai_info.hide_segment);
  468. objP->ctype.ai_info.hide_index = INTEL_SHORT (objP->ctype.ai_info.hide_index);
  469. objP->ctype.ai_info.path_length = INTEL_SHORT (objP->ctype.ai_info.path_length);
  470. objP->ctype.ai_info.danger_laser_num = INTEL_SHORT (objP->ctype.ai_info.danger_laser_num);
  471. objP->ctype.ai_info.danger_laser_signature = INTEL_INT (objP->ctype.ai_info.danger_laser_signature);
  472. objP->ctype.ai_info.dying_start_time = INTEL_INT (objP->ctype.ai_info.dying_start_time);
  473. break;
  474. case CT_LIGHT:
  475. objP->ctype.light_info.intensity = INTEL_INT (objP->ctype.light_info.intensity);
  476. break;
  477. case CT_POWERUP:
  478. objP->ctype.powerup_info.count = INTEL_INT (objP->ctype.powerup_info.count);
  479. objP->ctype.powerup_info.creation_time = INTEL_INT (objP->ctype.powerup_info.creation_time);
  480. break;
  481. }
  482. switch (objP->render_type) {
  483. case RT_MORPH:
  484. case RT_POLYOBJ: {
  485. int i;
  486. objP->rtype.pobj_info.model_num = INTEL_INT (objP->rtype.pobj_info.model_num);
  487. for (i = 0; i < MAX_SUBMODELS; i++)
  488. INTEL_ANGVEC (objP->rtype.pobj_info.anim_angles + i);
  489. objP->rtype.pobj_info.subobj_flags = INTEL_INT (objP->rtype.pobj_info.subobj_flags);
  490. objP->rtype.pobj_info.tmap_override = INTEL_INT (objP->rtype.pobj_info.tmap_override);
  491. objP->rtype.pobj_info.alt_textures = INTEL_INT (objP->rtype.pobj_info.alt_textures);
  492. break;
  493. }
  494. case RT_WEAPON_VCLIP:
  495. case RT_HOSTAGE:
  496. case RT_POWERUP:
  497. case RT_FIREBALL:
  498. case RT_THRUSTER:
  499. objP->rtype.vclip_info.nClipIndex = INTEL_INT (objP->rtype.vclip_info.nClipIndex);
  500. objP->rtype.vclip_info.xFrameTime = INTEL_INT (objP->rtype.vclip_info.xFrameTime);
  501. break;
  502. case RT_LASER:
  503. break;
  504. }
  505. }
  506. #endif /* WORDS_BIGENDIAN */
  507. //------------------------------------------------------------------------------
  508. // Calculates the checksum of a block of memory.
  509. ushort NetMiscCalcCheckSum (void * vptr, int len)
  510. {
  511. #if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
  512. return BECalcSegmentCheckSum ();
  513. #else
  514. ubyte *ptr = (ubyte *) vptr;
  515. unsigned int sum1, sum2;
  516. sum1 = sum2 = 0;
  517. for (; len; len--) {
  518. sum1 += *ptr++;
  519. #if 1
  520. sum1 %= 255;
  521. #else
  522. if (sum1 >= 255)
  523. sum1 -= 255;
  524. #endif
  525. sum2 += sum1;
  526. }
  527. return (sum1 * 256 + sum2 % 255);
  528. #endif
  529. }
  530. //------------------------------------------------------------------------------
  531. // needs to be recoded to actually work with big endian!
  532. //--unused-- //Finds the difference between block1 and block2. Fills in diff_buffer and
  533. //--unused-- //returns the size of diff_buffer.
  534. //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
  535. //--unused-- {
  536. //--unused-- int mode;
  537. //--unused-- ushort *c1, *c2, *diff_start, *c3;
  538. //--unused-- int i, j, size, diff, n , same;
  539. //--unused--
  540. //--unused-- size=(block_size+1)/sizeof(ushort);
  541. //--unused-- c1 = (ushort *)block1;
  542. //--unused-- c2 = (ushort *)block2;
  543. //--unused-- c3 = (ushort *)diff_buffer;
  544. //--unused--
  545. //--unused-- mode = same = diff = n = 0;
  546. //--unused--
  547. //--unused-- for (i=0; i<size; i++, c1++, c2++) {
  548. //--unused-- if (*c1 != *c2) {
  549. //--unused-- if (mode==0) {
  550. //--unused-- mode = 1;
  551. //--unused-- c3[n++] = same;
  552. //--unused-- same=0; diff=0;
  553. //--unused-- diff_start = c2;
  554. //--unused-- }
  555. //--unused-- *c1 = *c2;
  556. //--unused-- diff++;
  557. //--unused-- if (diff==65535) {
  558. //--unused-- mode = 0;
  559. //--unused-- // send how many diff ones.
  560. //--unused-- c3[n++]=diff;
  561. //--unused-- // send all the diff ones.
  562. //--unused-- for (j=0; j<diff; j++)
  563. //--unused-- c3[n++] = diff_start[j];
  564. //--unused-- same=0; diff=0;
  565. //--unused-- diff_start = c2;
  566. //--unused-- }
  567. //--unused-- } else {
  568. //--unused-- if (mode==1) {
  569. //--unused-- mode=0;
  570. //--unused-- // send how many diff ones.
  571. //--unused-- c3[n++]=diff;
  572. //--unused-- // send all the diff ones.
  573. //--unused-- for (j=0; j<diff; j++)
  574. //--unused-- c3[n++] = diff_start[j];
  575. //--unused-- same=0; diff=0;
  576. //--unused-- diff_start = c2;
  577. //--unused-- }
  578. //--unused-- same++;
  579. //--unused-- if (same==65535) {
  580. //--unused-- mode=1;
  581. //--unused-- // send how many the same
  582. //--unused-- c3[n++] = same;
  583. //--unused-- same=0; diff=0;
  584. //--unused-- diff_start = c2;
  585. //--unused-- }
  586. //--unused-- }
  587. //--unused--
  588. //--unused-- }
  589. //--unused-- if (mode==0) {
  590. //--unused-- // send how many the same
  591. //--unused-- c3[n++] = same;
  592. //--unused-- } else {
  593. //--unused-- // send how many diff ones.
  594. //--unused-- c3[n++]=diff;
  595. //--unused-- // send all the diff ones.
  596. //--unused-- for (j=0; j<diff; j++)
  597. //--unused-- c3[n++] = diff_start[j];
  598. //--unused-- }
  599. //--unused--
  600. //--unused-- return n*2;
  601. //--unused-- }
  602. //--unused-- //Applies diff_buffer to block1 to create a new block1. Returns the final
  603. //--unused-- //size of block1.
  604. //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
  605. //--unused-- {
  606. //--unused-- unsigned int i, j, n, size;
  607. //--unused-- ushort *c1, *c2;
  608. //--unused--
  609. //--unused-- c1 = (ushort *)diff_buffer;
  610. //--unused-- c2 = (ushort *)block1;
  611. //--unused--
  612. //--unused-- size = diff_size/2;
  613. //--unused--
  614. //--unused-- i=j=0;
  615. //--unused-- while (1) {
  616. //--unused-- j += c1[i]; // Same
  617. //--unused-- i++;
  618. //--unused-- if (i>=size) break;
  619. //--unused-- n = c1[i]; // ndiff
  620. //--unused-- i++;
  621. //--unused-- if (n>0) {
  622. //--unused-- //AsserT (n* < 256);
  623. //--unused-- memcpy(&c2[j], &c1[i], n*2);
  624. //--unused-- i += n;
  625. //--unused-- j += n;
  626. //--unused-- }
  627. //--unused-- if (i>=size) break;
  628. //--unused-- }
  629. //--unused-- return j*2;
  630. //--unused-- }