]> icculus.org git repositories - btb/d2x.git/blob - main/netmisc.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / main / netmisc.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Misc routines for network.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "inferno.h"
28 #include "mono.h"
29
30 #ifdef WORDS_BIGENDIAN
31
32 #include "byteswap.h"
33 #include "ipx.h"
34 #include "dxxerror.h"
35
36
37 // routine to calculate the checksum of the segments.  We add these specialized routines
38 // since the current way is byte order dependent.
39
40 void mac_do_checksum_calc(ubyte *b, int len, unsigned int *s1, unsigned int *s2)
41 {
42
43         while(len--) {
44                 *s1 += *b++;
45                 if (*s1 >= 255) *s1 -= 255;
46                 *s2 += *s1;
47         }
48 }
49
50 ushort mac_calc_segment_checksum()
51 {
52         int i, j, k;
53         unsigned int sum1,sum2;
54         short s;
55         int t;
56
57         sum1 = sum2 = 0;
58         for (i = 0; i < Highest_segment_index + 1; i++) {
59                 for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
60                         mac_do_checksum_calc((unsigned char *)&(Segments[i].sides[j].type), 1, &sum1, &sum2);
61                         mac_do_checksum_calc(&(Segments[i].sides[j].pad), 1, &sum1, &sum2);
62                         s = INTEL_SHORT(Segments[i].sides[j].wall_num);
63                         mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
64                         s = INTEL_SHORT(Segments[i].sides[j].tmap_num);
65                         mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
66                         s = INTEL_SHORT(Segments[i].sides[j].tmap_num2);
67                         mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
68                         for (k = 0; k < 4; k++) {
69                                 t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].u));
70                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
71                                 t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].v));
72                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
73                                 t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].l));
74                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
75                         }
76                         for (k = 0; k < 2; k++) {
77                                 t = INTEL_INT(((int)Segments[i].sides[j].normals[k].x));
78                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
79                                 t = INTEL_INT(((int)Segments[i].sides[j].normals[k].y));
80                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
81                                 t = INTEL_INT(((int)Segments[i].sides[j].normals[k].z));
82                                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
83                         }
84                 }
85                 for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
86                         s = INTEL_SHORT(Segments[i].children[j]);
87                         mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
88                 }
89                 for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) {
90                         s = INTEL_SHORT(Segments[i].verts[j]);
91                         mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2);
92                 }
93                 t = INTEL_INT(Segments[i].objects);
94                 mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2);
95         }
96         sum2 %= 255;
97         return ((sum1<<8)+ sum2);
98 }
99
100 // this routine totally and completely relies on the fact that the network
101 //  checksum must be calculated on the segments!!!!!
102
103 ushort netmisc_calc_checksum(void * vptr, int len)
104 {
105         vptr = vptr;
106         len = len;
107         return mac_calc_segment_checksum();
108 }
109
110 // following are routine for macintosh only that will swap the elements of
111 // structures send through the networking code.  The structures and
112 // this code must be kept in total sync
113
114 sbyte out_buffer[IPX_MAX_DATA_SIZE];    // used for tmp netgame packets as well as sending object data
115
116 void receive_netplayer_info(ubyte *data, netplayer_info *info)
117 {
118         int loc = 0;
119
120         memcpy(info->callsign, &(data[loc]), CALLSIGN_LEN+1);       loc += CALLSIGN_LEN+1;
121         memcpy(&(info->network.ipx.server), &(data[loc]), 4);       loc += 4;
122         memcpy(&(info->network.ipx.node), &(data[loc]), 6);         loc += 6;
123         info->version_major = data[loc];                            loc++;
124         info->version_minor = data[loc];                            loc++;
125         memcpy(&(info->computer_type), &(data[loc]), 1);            loc++;      // memcpy to avoid compile time warning about enum
126         info->connected = data[loc];                                loc++;
127         memcpy(&(info->socket), &(data[loc]), 2);                   loc += 2;
128         memcpy (&(info->rank),&(data[loc]),1);                      loc++;
129         // MWA don't think we need to swap this because we need it in high
130         // order  info->socket = INTEL_SHORT(info->socket);
131 }
132
133 void send_netplayers_packet(ubyte *server, ubyte *node)
134 {
135         int i, tmpi;
136         int loc = 0;
137         short tmps;
138
139         memset(out_buffer, 0, sizeof(out_buffer));
140         out_buffer[0] = NetPlayers.type;                            loc++;
141         tmpi = INTEL_INT(NetPlayers.Security);
142         memcpy(&(out_buffer[loc]), &tmpi, 4);                       loc += 4;
143         for (i = 0; i < MAX_PLAYERS+4; i++) {
144                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].callsign, CALLSIGN_LEN+1); loc += CALLSIGN_LEN+1;
145                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.server, 4);    loc += 4;
146                 memcpy(&(out_buffer[loc]), NetPlayers.players[i].network.ipx.node, 6);      loc += 6;
147                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].version_major), 1);      loc++;
148                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].version_minor), 1);      loc++;
149                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].computer_type), 1);      loc++;
150                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].connected), 1);          loc++;
151                 tmps = INTEL_SHORT(NetPlayers.players[i].socket);
152                 memcpy(&(out_buffer[loc]), &tmps, 2);                                       loc += 2;
153                 memcpy(&(out_buffer[loc]), &(NetPlayers.players[i].rank), 1);               loc++;
154         }
155
156         if ((server == NULL) && (node == NULL))
157                 ipx_send_broadcast_packet_data((unsigned char *)out_buffer, loc);
158         else
159                 ipx_send_internetwork_packet_data((unsigned char *)out_buffer, loc, server, node);
160
161 }
162
163 void receive_netplayers_packet(ubyte *data, AllNetPlayers_info *pinfo)
164 {
165         int i, loc = 0;
166
167         pinfo->type = data[loc];                            loc++;
168         memcpy(&(pinfo->Security), &(data[loc]), 4);        loc += 4;
169         pinfo->Security = INTEL_INT(pinfo->Security);
170         for (i = 0; i < MAX_PLAYERS+4; i++) {
171                 receive_netplayer_info(&(data[loc]), &(pinfo->players[i]));
172                 loc += 26;          // sizeof(netplayer_info) on the PC
173         }
174 }
175
176 void send_sequence_packet(sequence_packet seq, ubyte *server, ubyte *node, ubyte *net_address)
177 {
178         short tmps;
179         int loc, tmpi;
180
181         loc = 0;
182         memset(out_buffer, 0, sizeof(out_buffer));
183         out_buffer[0] = seq.type;                                       loc++;
184         tmpi = INTEL_INT(seq.Security);
185         memcpy(&(out_buffer[loc]), &tmpi, 4);                           loc += 4;       loc += 3;
186         memcpy(&(out_buffer[loc]), seq.player.callsign, CALLSIGN_LEN+1);loc += CALLSIGN_LEN+1;
187         memcpy(&(out_buffer[loc]), seq.player.network.ipx.server, 4);   loc += 4;
188         memcpy(&(out_buffer[loc]), seq.player.network.ipx.node, 6);     loc += 6;
189         out_buffer[loc] = seq.player.version_major;                     loc++;
190         out_buffer[loc] = seq.player.version_minor;                     loc++;
191         out_buffer[loc] = seq.player.computer_type;                     loc++;
192         out_buffer[loc] = seq.player.connected;                         loc++;
193         tmps = INTEL_SHORT(seq.player.socket);
194         memcpy(&(out_buffer[loc]), &tmps, 2);                           loc += 2;
195         out_buffer[loc]=seq.player.rank;                                loc++;      // for pad byte
196         if (net_address != NULL)
197                 ipx_send_packet_data((unsigned char *)out_buffer, loc, server, node, net_address);
198         else if ((server == NULL) && (node == NULL))
199                 ipx_send_broadcast_packet_data((unsigned char *)out_buffer, loc);
200         else
201                 ipx_send_internetwork_packet_data((unsigned char *)out_buffer, loc, server, node);
202 }
203
204 void receive_sequence_packet(ubyte *data, sequence_packet *seq)
205 {
206         int loc = 0;
207
208         seq->type = data[0];                        loc++;
209         memcpy(&(seq->Security), &(data[loc]), 4);  loc += 4;   loc += 3;   // +3 for pad byte
210         seq->Security = INTEL_INT(seq->Security);
211         receive_netplayer_info(&(data[loc]), &(seq->player));
212 }
213
214 void send_netgame_packet(ubyte *server, ubyte *node, ubyte *net_address, int lite_flag)     // lite says shorter netgame packets
215 {
216         uint tmpi;
217         ushort tmps; // p;
218         int i, j;
219         int loc = 0;
220
221         memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
222         memcpy(&(out_buffer[loc]), &(Netgame.type), 1);                 loc++;
223         tmpi = INTEL_INT(Netgame.Security);
224         memcpy(&(out_buffer[loc]), &tmpi, 4);                           loc += 4;
225         memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN+1);  loc += (NETGAME_NAME_LEN+1);
226         memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN+1);  loc += (MISSION_NAME_LEN+1);
227         memcpy(&(out_buffer[loc]), Netgame.mission_name, 9);            loc += 9;
228         tmpi = INTEL_INT(Netgame.levelnum);
229         memcpy(&(out_buffer[loc]), &tmpi, 4);                           loc += 4;
230         memcpy(&(out_buffer[loc]), &(Netgame.gamemode), 1);             loc++;
231         memcpy(&(out_buffer[loc]), &(Netgame.RefusePlayers), 1);        loc++;
232         memcpy(&(out_buffer[loc]), &(Netgame.difficulty), 1);           loc++;
233         memcpy(&(out_buffer[loc]), &(Netgame.game_status), 1);          loc++;
234         memcpy(&(out_buffer[loc]), &(Netgame.numplayers), 1);           loc++;
235         memcpy(&(out_buffer[loc]), &(Netgame.max_numplayers), 1);       loc++;
236         memcpy(&(out_buffer[loc]), &(Netgame.numconnected), 1);         loc++;
237         memcpy(&(out_buffer[loc]), &(Netgame.game_flags), 1);           loc++;
238         memcpy(&(out_buffer[loc]), &(Netgame.protocol_version), 1);     loc++;
239         memcpy(&(out_buffer[loc]), &(Netgame.version_major), 1);        loc++;
240         memcpy(&(out_buffer[loc]), &(Netgame.version_minor), 1);        loc++;
241         memcpy(&(out_buffer[loc]), &(Netgame.team_vector), 1);          loc++;
242
243         if (lite_flag)
244                 goto do_send;
245
246 // will this work -- damn bitfields -- totally bogus when trying to do
247 // this type of stuff
248 // Watcom makes bitfields from left to right.  CW7 on the mac goes
249 // from right to left.  then they are endian swapped
250
251         tmps = *(ushort *)((ubyte *)(&Netgame.team_vector) + 1);    // get the values for the first short bitfield
252         tmps = INTEL_SHORT(tmps);
253         memcpy(&(out_buffer[loc]), &tmps, 2);                           loc += 2;
254
255         tmps = *(ushort *)((ubyte *)(&Netgame.team_vector) + 3);    // get the values for the second short bitfield
256         tmps = INTEL_SHORT(tmps);
257         memcpy(&(out_buffer[loc]), &tmps, 2);                           loc += 2;
258
259 #if 0       // removed since I reordered bitfields on mac
260         p = *(ushort *)((ubyte *)(&Netgame.team_vector) + 1);       // get the values for the first short bitfield
261         tmps = 0;
262         for (i = 15; i >= 0; i--) {
263                 if (p & (1 << i))
264                         tmps |= (1 << (15 - i));
265         }
266         tmps = INTEL_SHORT(tmps);
267         memcpy(&(out_buffer[loc]), &tmps, 2);                           loc += 2;
268         p = *(ushort *)((ubyte *)(&Netgame.team_vector) + 3);       // get the values for the second short bitfield
269         tmps = 0;
270         for (i = 15; i >= 0; i--) {
271                 if (p & (1 << i))
272                         tmps |= (1 << (15 - i));
273         }
274         tmps = INTEL_SHORT(tmps);
275         memcpy(&(out_buffer[loc]), &tmps, 2);                           loc += 2;
276 #endif
277
278         memcpy(&(out_buffer[loc]), Netgame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
279         for (i = 0; i < MAX_PLAYERS; i++) {
280                 tmpi = INTEL_INT(Netgame.locations[i]);
281                 memcpy(&(out_buffer[loc]), &tmpi, 4);       loc += 4;   // SWAP HERE!!!
282         }
283
284         for (i = 0; i < MAX_PLAYERS; i++) {
285                 for (j = 0; j < MAX_PLAYERS; j++) {
286                         tmps = INTEL_SHORT(Netgame.kills[i][j]);
287                         memcpy(&(out_buffer[loc]), &tmps, 2);   loc += 2;   // SWAP HERE!!!
288                 }
289         }
290
291         tmps = INTEL_SHORT(Netgame.segments_checksum);
292         memcpy(&(out_buffer[loc]), &tmps, 2);           loc += 2;   // SWAP_HERE
293         tmps = INTEL_SHORT(Netgame.team_kills[0]);
294         memcpy(&(out_buffer[loc]), &tmps, 2);           loc += 2;   // SWAP_HERE
295         tmps = INTEL_SHORT(Netgame.team_kills[1]);
296         memcpy(&(out_buffer[loc]), &tmps, 2);           loc += 2;   // SWAP_HERE
297         for (i = 0; i < MAX_PLAYERS; i++) {
298                 tmps = INTEL_SHORT(Netgame.killed[i]);
299                 memcpy(&(out_buffer[loc]), &tmps, 2);       loc += 2;   // SWAP HERE!!!
300         }
301         for (i = 0; i < MAX_PLAYERS; i++) {
302                 tmps = INTEL_SHORT(Netgame.player_kills[i]);
303                 memcpy(&(out_buffer[loc]), &tmps, 2);       loc += 2;   // SWAP HERE!!!
304         }
305
306         tmpi = INTEL_INT(Netgame.KillGoal);
307         memcpy(&(out_buffer[loc]), &tmpi, 4);           loc += 4;   // SWAP_HERE
308         tmpi = INTEL_INT(Netgame.PlayTimeAllowed);
309         memcpy(&(out_buffer[loc]), &tmpi, 4);           loc += 4;   // SWAP_HERE
310         tmpi = INTEL_INT(Netgame.level_time);
311         memcpy(&(out_buffer[loc]), &tmpi, 4);           loc += 4;   // SWAP_HERE
312         tmpi = INTEL_INT(Netgame.control_invul_time);
313         memcpy(&(out_buffer[loc]), &tmpi, 4);           loc += 4;   // SWAP_HERE
314         tmpi = INTEL_INT(Netgame.monitor_vector);
315         memcpy(&(out_buffer[loc]), &tmpi, 4);           loc += 4;   // SWAP_HERE
316         for (i = 0; i < MAX_PLAYERS; i++) {
317                 tmpi = INTEL_INT(Netgame.player_score[i]);
318                 memcpy(&(out_buffer[loc]), &tmpi, 4);       loc += 4;   // SWAP_HERE
319         }
320         for (i = 0; i < MAX_PLAYERS; i++) {
321                 memcpy(&(out_buffer[loc]), &(Netgame.player_flags[i]), 1); loc++;
322         }
323         tmps = INTEL_SHORT(Netgame.PacketsPerSec);
324         memcpy(&(out_buffer[loc]), &tmps, 2);                   loc += 2;
325         memcpy(&(out_buffer[loc]), &(Netgame.ShortPackets), 1); loc ++;
326
327 do_send:
328         if (net_address != NULL)
329                 ipx_send_packet_data((unsigned char *)out_buffer, loc, server, node, net_address);
330         else if ((server == NULL) && (node == NULL))
331                 ipx_send_broadcast_packet_data((unsigned char *)out_buffer, loc);
332         else
333                 ipx_send_internetwork_packet_data((unsigned char *)out_buffer, loc, server, node);
334 }
335
336 void receive_netgame_packet(ubyte *data, netgame_info *netgame, int lite_flag)
337 {
338         int i, j;
339         int loc = 0;
340         short bitfield; // new_field;
341
342         memcpy(&(netgame->type), &(data[loc]), 1);                      loc++;
343         memcpy(&(netgame->Security), &(data[loc]), 4);                  loc += 4;
344         netgame->Security = INTEL_INT(netgame->Security);
345         memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1);   loc += (NETGAME_NAME_LEN+1);
346         memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1);
347         memcpy(netgame->mission_name, &(data[loc]), 9);                 loc += 9;
348         memcpy(&(netgame->levelnum), &(data[loc]), 4);                  loc += 4;
349         netgame->levelnum = INTEL_INT(netgame->levelnum);
350         memcpy(&(netgame->gamemode), &(data[loc]), 1);                  loc++;
351         memcpy(&(netgame->RefusePlayers), &(data[loc]), 1);             loc++;
352         memcpy(&(netgame->difficulty), &(data[loc]), 1);                loc++;
353         memcpy(&(netgame->game_status), &(data[loc]), 1);               loc++;
354         memcpy(&(netgame->numplayers), &(data[loc]), 1);                loc++;
355         memcpy(&(netgame->max_numplayers), &(data[loc]), 1);            loc++;
356         memcpy(&(netgame->numconnected), &(data[loc]), 1);              loc++;
357         memcpy(&(netgame->game_flags), &(data[loc]), 1);                loc++;
358         memcpy(&(netgame->protocol_version), &(data[loc]), 1);          loc++;
359         memcpy(&(netgame->version_major), &(data[loc]), 1);             loc++;
360         memcpy(&(netgame->version_minor), &(data[loc]), 1);             loc++;
361         memcpy(&(netgame->team_vector), &(data[loc]), 1);               loc++;
362
363         if (lite_flag)
364                 return;
365
366         memcpy(&bitfield, &(data[loc]), 2);                             loc += 2;
367         bitfield = INTEL_SHORT(bitfield);
368         memcpy(((ubyte *)(&netgame->team_vector) + 1), &bitfield, 2);
369
370         memcpy(&bitfield, &(data[loc]), 2);                             loc += 2;
371         bitfield = INTEL_SHORT(bitfield);
372         memcpy(((ubyte *)(&netgame->team_vector) + 3), &bitfield, 2);
373
374 #if 0       // not used since reordering mac bitfields
375         memcpy(&bitfield, &(data[loc]), 2);                             loc += 2;
376         new_field = 0;
377         for (i = 15; i >= 0; i--) {
378                 if (bitfield & (1 << i))
379                         new_field |= (1 << (15 - i));
380         }
381         new_field = INTEL_SHORT(new_field);
382         memcpy(((ubyte *)(&netgame->team_vector) + 1), &new_field, 2);
383
384         memcpy(&bitfield, &(data[loc]), 2);                             loc += 2;
385         new_field = 0;
386         for (i = 15; i >= 0; i--) {
387                 if (bitfield & (1 << i))
388                         new_field |= (1 << (15 - i));
389         }
390         new_field = INTEL_SHORT(new_field);
391         memcpy(((ubyte *)(&netgame->team_vector) + 3), &new_field, 2);
392 #endif
393
394         memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1));   loc += 2*(CALLSIGN_LEN+1);
395         for (i = 0; i < MAX_PLAYERS; i++) {
396                 memcpy(&(netgame->locations[i]), &(data[loc]), 4);          loc += 4;
397                 netgame->locations[i] = INTEL_INT(netgame->locations[i]);
398         }
399
400         for (i = 0; i < MAX_PLAYERS; i++) {
401                 for (j = 0; j < MAX_PLAYERS; j++) {
402                         memcpy(&(netgame->kills[i][j]), &(data[loc]), 2);       loc += 2;
403                         netgame->kills[i][j] = INTEL_SHORT(netgame->kills[i][j]);
404                 }
405         }
406
407         memcpy(&(netgame->segments_checksum), &(data[loc]), 2);         loc += 2;
408         netgame->segments_checksum = INTEL_SHORT(netgame->segments_checksum);
409         memcpy(&(netgame->team_kills[0]), &(data[loc]), 2);             loc += 2;
410         netgame->team_kills[0] = INTEL_SHORT(netgame->team_kills[0]);
411         memcpy(&(netgame->team_kills[1]), &(data[loc]), 2);             loc += 2;
412         netgame->team_kills[1] = INTEL_SHORT(netgame->team_kills[1]);
413         for (i = 0; i < MAX_PLAYERS; i++) {
414                 memcpy(&(netgame->killed[i]), &(data[loc]), 2);             loc += 2;
415                 netgame->killed[i] = INTEL_SHORT(netgame->killed[i]);
416         }
417         for (i = 0; i < MAX_PLAYERS; i++) {
418                 memcpy(&(netgame->player_kills[i]), &(data[loc]), 2);       loc += 2;
419                 netgame->player_kills[i] = INTEL_SHORT(netgame->player_kills[i]);
420         }
421         memcpy(&(netgame->KillGoal), &(data[loc]), 4);                  loc += 4;
422         netgame->KillGoal = INTEL_INT(netgame->KillGoal);
423         memcpy(&(netgame->PlayTimeAllowed), &(data[loc]), 4);           loc += 4;
424         netgame->PlayTimeAllowed = INTEL_INT(netgame->PlayTimeAllowed);
425
426         memcpy(&(netgame->level_time), &(data[loc]), 4);                loc += 4;
427         netgame->level_time = INTEL_INT(netgame->level_time);
428         memcpy(&(netgame->control_invul_time), &(data[loc]), 4);        loc += 4;
429         netgame->control_invul_time = INTEL_INT(netgame->control_invul_time);
430         memcpy(&(netgame->monitor_vector), &(data[loc]), 4);            loc += 4;
431         netgame->monitor_vector = INTEL_INT(netgame->monitor_vector);
432         for (i = 0; i < MAX_PLAYERS; i++) {
433                 memcpy(&(netgame->player_score[i]), &(data[loc]), 4);       loc += 4;
434                 netgame->player_score[i] = INTEL_INT(netgame->player_score[i]);
435         }
436         for (i = 0; i < MAX_PLAYERS; i++) {
437                 memcpy(&(netgame->player_flags[i]), &(data[loc]), 1);       loc++;
438         }
439         memcpy(&(netgame->PacketsPerSec), &(data[loc]), 2);             loc += 2;
440         netgame->PacketsPerSec = INTEL_SHORT(netgame->PacketsPerSec);
441         memcpy(&(netgame->ShortPackets), &(data[loc]), 1);              loc ++;
442
443 }
444
445 void swap_object(object *obj)
446 {
447         // swap the short and int entries for this object
448         obj->signature     = INTEL_INT(obj->signature);
449         obj->next          = INTEL_SHORT(obj->next);
450         obj->prev          = INTEL_SHORT(obj->prev);
451         obj->segnum        = INTEL_SHORT(obj->segnum);
452         obj->pos.x         = INTEL_INT(obj->pos.x);
453         obj->pos.y         = INTEL_INT(obj->pos.y);
454         obj->pos.z         = INTEL_INT(obj->pos.z);
455
456         obj->orient.rvec.x = INTEL_INT(obj->orient.rvec.x);
457         obj->orient.rvec.y = INTEL_INT(obj->orient.rvec.y);
458         obj->orient.rvec.z = INTEL_INT(obj->orient.rvec.z);
459         obj->orient.fvec.x = INTEL_INT(obj->orient.fvec.x);
460         obj->orient.fvec.y = INTEL_INT(obj->orient.fvec.y);
461         obj->orient.fvec.z = INTEL_INT(obj->orient.fvec.z);
462         obj->orient.uvec.x = INTEL_INT(obj->orient.uvec.x);
463         obj->orient.uvec.y = INTEL_INT(obj->orient.uvec.y);
464         obj->orient.uvec.z = INTEL_INT(obj->orient.uvec.z);
465
466         obj->size          = INTEL_INT(obj->size);
467         obj->shields       = INTEL_INT(obj->shields);
468
469         obj->last_pos.x    = INTEL_INT(obj->last_pos.x);
470         obj->last_pos.y    = INTEL_INT(obj->last_pos.y);
471         obj->last_pos.z    = INTEL_INT(obj->last_pos.z);
472
473         obj->lifeleft      = INTEL_INT(obj->lifeleft);
474
475         switch (obj->movement_type) {
476
477         case MT_PHYSICS:
478
479                 obj->mtype.phys_info.velocity.x = INTEL_INT(obj->mtype.phys_info.velocity.x);
480                 obj->mtype.phys_info.velocity.y = INTEL_INT(obj->mtype.phys_info.velocity.y);
481                 obj->mtype.phys_info.velocity.z = INTEL_INT(obj->mtype.phys_info.velocity.z);
482
483                 obj->mtype.phys_info.thrust.x   = INTEL_INT(obj->mtype.phys_info.thrust.x);
484                 obj->mtype.phys_info.thrust.y   = INTEL_INT(obj->mtype.phys_info.thrust.y);
485                 obj->mtype.phys_info.thrust.z   = INTEL_INT(obj->mtype.phys_info.thrust.z);
486
487                 obj->mtype.phys_info.mass       = INTEL_INT(obj->mtype.phys_info.mass);
488                 obj->mtype.phys_info.drag       = INTEL_INT(obj->mtype.phys_info.drag);
489                 obj->mtype.phys_info.brakes     = INTEL_INT(obj->mtype.phys_info.brakes);
490
491                 obj->mtype.phys_info.rotvel.x   = INTEL_INT(obj->mtype.phys_info.rotvel.x);
492                 obj->mtype.phys_info.rotvel.y   = INTEL_INT(obj->mtype.phys_info.rotvel.y);
493                 obj->mtype.phys_info.rotvel.z   = INTEL_INT(obj->mtype.phys_info.rotvel.z);
494
495                 obj->mtype.phys_info.rotthrust.x = INTEL_INT(obj->mtype.phys_info.rotthrust.x);
496                 obj->mtype.phys_info.rotthrust.y = INTEL_INT(obj->mtype.phys_info.rotthrust.y);
497                 obj->mtype.phys_info.rotthrust.z = INTEL_INT(obj->mtype.phys_info.rotthrust.z);
498
499                 obj->mtype.phys_info.turnroll   = INTEL_INT(obj->mtype.phys_info.turnroll);
500                 obj->mtype.phys_info.flags      = INTEL_SHORT(obj->mtype.phys_info.flags);
501
502                 break;
503
504         case MT_SPINNING:
505
506                 obj->mtype.spin_rate.x = INTEL_INT(obj->mtype.spin_rate.x);
507                 obj->mtype.spin_rate.y = INTEL_INT(obj->mtype.spin_rate.y);
508                 obj->mtype.spin_rate.z = INTEL_INT(obj->mtype.spin_rate.z);
509                 break;
510         }
511
512         switch (obj->control_type) {
513
514         case CT_WEAPON:
515                 obj->ctype.laser_info.parent_type       = INTEL_SHORT(obj->ctype.laser_info.parent_type);
516                 obj->ctype.laser_info.parent_num        = INTEL_SHORT(obj->ctype.laser_info.parent_num);
517                 obj->ctype.laser_info.parent_signature  = INTEL_INT(obj->ctype.laser_info.parent_signature);
518                 obj->ctype.laser_info.creation_time     = INTEL_INT(obj->ctype.laser_info.creation_time);
519                 obj->ctype.laser_info.last_hitobj       = INTEL_SHORT(obj->ctype.laser_info.last_hitobj);
520                 obj->ctype.laser_info.track_goal        = INTEL_SHORT(obj->ctype.laser_info.track_goal);
521                 obj->ctype.laser_info.multiplier        = INTEL_INT(obj->ctype.laser_info.multiplier);
522                 break;
523
524         case CT_EXPLOSION:
525                 obj->ctype.expl_info.spawn_time     = INTEL_INT(obj->ctype.expl_info.spawn_time);
526                 obj->ctype.expl_info.delete_time    = INTEL_INT(obj->ctype.expl_info.delete_time);
527                 obj->ctype.expl_info.delete_objnum  = INTEL_SHORT(obj->ctype.expl_info.delete_objnum);
528                 obj->ctype.expl_info.attach_parent  = INTEL_SHORT(obj->ctype.expl_info.attach_parent);
529                 obj->ctype.expl_info.prev_attach    = INTEL_SHORT(obj->ctype.expl_info.prev_attach);
530                 obj->ctype.expl_info.next_attach    = INTEL_SHORT(obj->ctype.expl_info.next_attach);
531                 break;
532
533         case CT_AI:
534                 obj->ctype.ai_info.hide_segment         = INTEL_SHORT(obj->ctype.ai_info.hide_segment);
535                 obj->ctype.ai_info.hide_index           = INTEL_SHORT(obj->ctype.ai_info.hide_index);
536                 obj->ctype.ai_info.path_length          = INTEL_SHORT(obj->ctype.ai_info.path_length);
537                 obj->ctype.ai_info.danger_laser_num     = INTEL_SHORT(obj->ctype.ai_info.danger_laser_num);
538                 obj->ctype.ai_info.danger_laser_signature = INTEL_INT(obj->ctype.ai_info.danger_laser_signature);
539                 obj->ctype.ai_info.dying_start_time     = INTEL_INT(obj->ctype.ai_info.dying_start_time);
540                 break;
541
542         case CT_LIGHT:
543                 obj->ctype.light_info.intensity = INTEL_INT(obj->ctype.light_info.intensity);
544                 break;
545
546         case CT_POWERUP:
547                 obj->ctype.powerup_info.count = INTEL_INT(obj->ctype.powerup_info.count);
548                 obj->ctype.powerup_info.creation_time = INTEL_INT(obj->ctype.powerup_info.creation_time);
549                 // Below commented out 5/2/96 by Matt.  I asked Allender why it was
550                 // here, and he didn't know, and it looks like it doesn't belong.
551                 // if (obj->id == POW_VULCAN_WEAPON)
552                 // obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
553                 break;
554
555         }
556
557         switch (obj->render_type) {
558
559         case RT_MORPH:
560         case RT_POLYOBJ: {
561                 int i;
562
563                 obj->rtype.pobj_info.model_num      = INTEL_INT(obj->rtype.pobj_info.model_num);
564
565                 for (i=0;i<MAX_SUBMODELS;i++) {
566                         obj->rtype.pobj_info.anim_angles[i].p = INTEL_INT(obj->rtype.pobj_info.anim_angles[i].p);
567                         obj->rtype.pobj_info.anim_angles[i].b = INTEL_INT(obj->rtype.pobj_info.anim_angles[i].b);
568                         obj->rtype.pobj_info.anim_angles[i].h = INTEL_INT(obj->rtype.pobj_info.anim_angles[i].h);
569                 }
570
571                 obj->rtype.pobj_info.subobj_flags   = INTEL_INT(obj->rtype.pobj_info.subobj_flags);
572                 obj->rtype.pobj_info.tmap_override  = INTEL_INT(obj->rtype.pobj_info.tmap_override);
573                 obj->rtype.pobj_info.alt_textures   = INTEL_INT(obj->rtype.pobj_info.alt_textures);
574                 break;
575         }
576
577         case RT_WEAPON_VCLIP:
578         case RT_HOSTAGE:
579         case RT_POWERUP:
580         case RT_FIREBALL:
581                 obj->rtype.vclip_info.vclip_num = INTEL_INT(obj->rtype.vclip_info.vclip_num);
582                 obj->rtype.vclip_info.frametime = INTEL_INT(obj->rtype.vclip_info.frametime);
583                 break;
584
585         case RT_LASER:
586                 break;
587
588         }
589 //  END OF SWAPPING OBJECT STRUCTURE
590
591 }
592
593 #else /* !WORDS_BIGENDIAN */
594
595
596 // Calculates the checksum of a block of memory.
597 ushort netmisc_calc_checksum(void * vptr, int len)
598 {
599         ubyte *ptr = (ubyte *)vptr;
600         unsigned int sum1,sum2;
601
602         sum1 = sum2 = 0;
603
604         while(len--) {
605                 sum1 += *ptr++;
606                 if (sum1 >= 255) sum1 -= 255;
607                 sum2 += sum1;
608         }
609         sum2 %= 255;
610
611         return ((sum1<<8)+ sum2);
612 }
613
614 #endif /* WORDS_BIGENDIAN */
615
616 //--unused-- //Finds the difference between block1 and block2.  Fills in diff_buffer and
617 //--unused-- //returns the size of diff_buffer.
618 //--unused-- int netmisc_find_diff(void *block1, void *block2, int block_size, void *diff_buffer)
619 //--unused-- {
620 //--unused--    int mode;
621 //--unused--    ushort *c1, *c2, *diff_start, *c3;
622 //--unused--    int i, j, size, diff, n , same;
623 //--unused--
624 //--unused--    size=(block_size+1)/sizeof(ushort);
625 //--unused--    c1 = (ushort *)block1;
626 //--unused--    c2 = (ushort *)block2;
627 //--unused--    c3 = (ushort *)diff_buffer;
628 //--unused--
629 //--unused--    mode = same = diff = n = 0;
630 //--unused--
631 //--unused--    //mprintf(0, "=================================\n");
632 //--unused--
633 //--unused--    for (i=0; i<size; i++, c1++, c2++) {
634 //--unused--            if (*c1 != *c2) {
635 //--unused--                    if (mode==0) {
636 //--unused--                            mode = 1;
637 //--unused--                            //mprintf(0, "%ds ", same);
638 //--unused--                            c3[n++] = same;
639 //--unused--                            same=0; diff=0;
640 //--unused--                            diff_start = c2;
641 //--unused--                    }
642 //--unused--                    *c1 = *c2;
643 //--unused--                    diff++;
644 //--unused--                    if (diff==65535) {
645 //--unused--                            mode = 0;
646 //--unused--                            // send how many diff ones.
647 //--unused--                            //mprintf(0, "%dd ", diff);
648 //--unused--                            c3[n++]=diff;
649 //--unused--                            // send all the diff ones.
650 //--unused--                            for (j=0; j<diff; j++)
651 //--unused--                                    c3[n++] = diff_start[j];
652 //--unused--                            same=0; diff=0;
653 //--unused--                            diff_start = c2;
654 //--unused--                    }
655 //--unused--            } else {
656 //--unused--                    if (mode==1) {
657 //--unused--                            mode=0;
658 //--unused--                            // send how many diff ones.
659 //--unused--                            //mprintf(0, "%dd ", diff);
660 //--unused--                            c3[n++]=diff;
661 //--unused--                            // send all the diff ones.
662 //--unused--                            for (j=0; j<diff; j++)
663 //--unused--                                    c3[n++] = diff_start[j];
664 //--unused--                            same=0; diff=0;
665 //--unused--                            diff_start = c2;
666 //--unused--                    }
667 //--unused--                    same++;
668 //--unused--                    if (same==65535) {
669 //--unused--                            mode=1;
670 //--unused--                            // send how many the same
671 //--unused--                            //mprintf(0, "%ds ", same);
672 //--unused--                            c3[n++] = same;
673 //--unused--                            same=0; diff=0;
674 //--unused--                            diff_start = c2;
675 //--unused--                    }
676 //--unused--            }
677 //--unused--
678 //--unused--    }
679 //--unused--    if (mode==0) {
680 //--unused--            // send how many the same
681 //--unused--            //mprintf(0, "%ds ", same);
682 //--unused--            c3[n++] = same;
683 //--unused--    } else {
684 //--unused--            // send how many diff ones.
685 //--unused--            //mprintf(0, "%dd ", diff);
686 //--unused--            c3[n++]=diff;
687 //--unused--            // send all the diff ones.
688 //--unused--            for (j=0; j<diff; j++)
689 //--unused--                    c3[n++] = diff_start[j];
690 //--unused--    }
691 //--unused--
692 //--unused--    //mprintf(0, "=================================\n");
693 //--unused--
694 //--unused--    return n*2;
695 //--unused-- }
696
697 //--unused-- //Applies diff_buffer to block1 to create a new block1.  Returns the final
698 //--unused-- //size of block1.
699 //--unused-- int netmisc_apply_diff(void *block1, void *diff_buffer, int diff_size)
700 //--unused-- {
701 //--unused--    unsigned int i, j, n, size;
702 //--unused--    ushort *c1, *c2;
703 //--unused--
704 //--unused--    //mprintf(0, "=================================\n");
705 //--unused--    c1 = (ushort *)diff_buffer;
706 //--unused--    c2 = (ushort *)block1;
707 //--unused--
708 //--unused--    size = diff_size/2;
709 //--unused--
710 //--unused--    i=j=0;
711 //--unused--    while (1) {
712 //--unused--            j += c1[i];         // Same
713 //--unused--            //mprintf(0, "%ds ", c1[i]);
714 //--unused--            i++;
715 //--unused--            if (i>=size) break;
716 //--unused--            n = c1[i];          // ndiff
717 //--unused--            //mprintf(0, "%dd ", c1[i]);
718 //--unused--            i++;
719 //--unused--            if (n>0) {
720 //--unused--                    //Assert(n* < 256);
721 //--unused--                    memcpy(&c2[j], &c1[i], n*2);
722 //--unused--                    i += n;
723 //--unused--                    j += n;
724 //--unused--            }
725 //--unused--            if (i>=size) break;
726 //--unused--    }
727 //--unused--    //mprintf(0, "=================================\n");
728 //--unused--
729 //--unused--    return j*2;
730 //--unused-- }