From dfdea820dc5d8824ec3f4a06b0220a4aac249b00 Mon Sep 17 00:00:00 2001 From: kreatordxx <> Date: Fri, 16 May 2008 11:20:33 +0000 Subject: [PATCH] fix remaining endian bugs in network code, now it works on the Mac --- CHANGELOG.txt | 4 + main/multi.c | 190 +++++++++++++++++++++++++++--------------------- main/multibot.c | 133 ++++++++++++++++++++------------- main/netpkt.c | 143 ++++++++++++++++++++++++++++++------ main/network.c | 46 +++++------- 5 files changed, 329 insertions(+), 187 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f9ba01472..df93538c1 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20080516 +-------- +main/multi.c, main/multibot.c, main/netpkt.c, main/network.c: fix remaining endian bugs in network code, now it works on the Mac + 20080510 -------- main/playsave.c: use atoi instead of sscanf for plx reading, so the setting for showing the reticle is read properly on big endian computers diff --git a/main/multi.c b/main/multi.c index 009ce9636..c3925eaf5 100644 --- a/main/multi.c +++ b/main/multi.c @@ -1190,8 +1190,8 @@ multi_do_fire(char *buf) pnum = buf[1]; weapon = (int)buf[2]; flags = buf[4]; - Network_laser_track = *(short *)(buf+6); - + Network_laser_track = GET_INTEL_SHORT(buf + 6); + Assert (pnum < N_players); //added on 03/05/99 Matt Mueller - add POS_FIRE capability @@ -1312,7 +1312,7 @@ multi_do_reappear(char *buf) { short objnum; - objnum = *(short *)(buf+1); + objnum = GET_INTEL_SHORT(buf + 1); Assert(objnum >= 0); @@ -1395,8 +1395,8 @@ multi_do_player_explode(char *buf) Players[pnum].secondary_ammo[SMART_INDEX] = buf[count]; count++; Players[pnum].secondary_ammo[MEGA_INDEX] = buf[count]; count++; Players[pnum].secondary_ammo[PROXIMITY_INDEX] = buf[count]; count++; - Players[pnum].primary_ammo[VULCAN_INDEX] = *(ushort *)(buf+count); count += 2; - Players[pnum].flags = *(uint *)(buf+count); count += 4; + Players[pnum].primary_ammo[VULCAN_INDEX] = GET_INTEL_SHORT(buf + count); count += 2; + Players[pnum].flags = GET_INTEL_INT(buf + count); count += 4; objp = Objects+Players[pnum].objnum; @@ -1426,9 +1426,12 @@ multi_do_player_explode(char *buf) for (i = 0; i < remote_created; i++) { - if ((i < Net_create_loc) && (*(short *)(buf+count) > 0) && + short s; + + s = GET_INTEL_SHORT(buf + count); + if ((i < Net_create_loc) && (s > 0) && (Net_create_objnums[i] > 0)) - map_objnum_local_to_remote((short)Net_create_objnums[i], *(short *)(buf+count), pnum); + map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum); count += 2; } for (i = remote_created; i < Net_create_loc; i++) { @@ -1473,7 +1476,7 @@ multi_do_kill(char *buf) killed = objnum_remote_to_local(*(short *)(buf+count), (sbyte)buf[count+2]); count += 3; #endif - killer = *(short *)(buf+count); + killer = GET_INTEL_SHORT(buf + count); if (killer > 0) killer = objnum_remote_to_local(killer, (sbyte)buf[count+2]); @@ -1497,7 +1500,7 @@ void multi_do_controlcen_destroy(char *buf) sbyte who; short objnum; - objnum = *(short *)(buf+1); + objnum = GET_INTEL_SHORT(buf + 1); who = buf[3]; if (Fuelcen_control_center_destroyed != 1) @@ -1559,7 +1562,7 @@ multi_do_remobj(char *buf) short local_objnum; sbyte obj_owner; // which remote list is it entered in - objnum = *(short *)(buf+1); + objnum = GET_INTEL_SHORT(buf + 1); obj_owner = buf[3]; Assert(objnum >= 0); @@ -1667,7 +1670,7 @@ multi_do_door_open(char *buf) segnum = *(int *)(buf+1); side = *(short *)(buf+5); #else - segnum = *(short *)(buf+1); + segnum = GET_INTEL_SHORT(buf + 1); side = buf[3]; #endif @@ -1726,8 +1729,8 @@ multi_do_controlcen_fire(char *buf) to_target.y = (fix)INTEL_INT((int)to_target.y); to_target.z = (fix)INTEL_INT((int)to_target.z); #endif - gun_num = buf[count]; count += 1; - objnum = *(short *)(buf+count); count += 2; + gun_num = buf[count]; count += 1; + objnum = GET_INTEL_SHORT(buf + count); count += 2; Laser_create_new_easy(&to_target, &Gun_pos[gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1); } @@ -1748,8 +1751,8 @@ multi_do_create_powerup(char *buf) pnum = buf[count++]; powerup_type = buf[count++]; - segnum = *(short *)(buf+count); count+=2; - objnum = *(short *)(buf+count); count+=2; + segnum = GET_INTEL_SHORT(buf + count); count += 2; + objnum = GET_INTEL_SHORT(buf + count); count += 2; if ((segnum < 0) || (segnum > Highest_segment_index)) { Int3(); @@ -1826,10 +1829,13 @@ multi_do_score(char *buf) return; } - if (Newdemo_state == ND_STATE_RECORDING) - newdemo_record_multi_score(pnum, *(int *)(buf+2)); + if (Newdemo_state == ND_STATE_RECORDING) { + int score; + score = GET_INTEL_INT(buf + 2); + newdemo_record_multi_score(pnum, score); + } - Players[pnum].score = *(int *)(buf+2); + Players[pnum].score = GET_INTEL_INT(buf + 2); multi_sort_kill_list(); } @@ -1861,8 +1867,8 @@ void multi_do_hostage_door_status(char *buf) int wallnum; fix hps; - wallnum = *(short *)(buf+count); count += 2; - hps = *(fix *)(buf+count); count += 4; + wallnum = GET_INTEL_SHORT(buf + count); count += 2; + hps = GET_INTEL_INT(buf + count); count += 4; if ((wallnum < 0) || (wallnum > Num_walls) || (hps < 0) || (Walls[wallnum].type != WALL_BLASTABLE)) { @@ -2121,7 +2127,7 @@ void multi_send_fire(int pl) multibuf[3] = (char)Network_laser_level; multibuf[4] = (char)Network_laser_flags; multibuf[5] = (char)Network_laser_fired; - *(short *)(multibuf+6) = Network_laser_track; + PUT_INTEL_SHORT(multibuf+6, Network_laser_track); multibuf[0] = (char)MULTI_FIRE; multi_send_data(multibuf, 8, 1); @@ -2140,7 +2146,7 @@ multi_send_destroy_controlcen(int objnum, int player) hud_message(MSGC_MULTI_INFO, TXT_CONTROL_DESTROYED); multibuf[0] = (char)MULTI_CONTROLCEN; - *(ushort *)(multibuf+1) = objnum; + PUT_INTEL_SHORT(multibuf+1, objnum); multibuf[3] = player; multi_send_data(multibuf, 4, 2); } @@ -2226,9 +2232,9 @@ multi_send_player_explode(char type) multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMART_INDEX]; multibuf[count++] = (char)Players[Player_num].secondary_ammo[MEGA_INDEX]; multibuf[count++] = (char)Players[Player_num].secondary_ammo[PROXIMITY_INDEX]; - *(ushort *)(multibuf+count) = (ushort)Players[Player_num].primary_ammo[VULCAN_INDEX]; + PUT_INTEL_SHORT(multibuf+count, Players[Player_num].primary_ammo[VULCAN_INDEX] ); count += 2; - *(uint *)(multibuf+count) = (uint)Players[Player_num].flags; + PUT_INTEL_INT(multibuf+count, Players[Player_num].flags ); count += 4; multibuf[count++] = Net_create_loc; @@ -2239,8 +2245,6 @@ multi_send_player_explode(char type) for (i = 0; i < Net_create_loc; i++) { - *(short *)(multibuf+count) = (short)Net_create_objnums[i]; count += 2; - if (Net_create_objnums[i] <= 0) { #if 0 // Now legal, happens if there are too much powerups in mine Int3(); // Illegal value in created egg object numbers @@ -2248,6 +2252,8 @@ multi_send_player_explode(char type) continue; } + PUT_INTEL_SHORT(multibuf+count, Net_create_objnums[i]); count += 2; + // We created these objs so our local number = the network number map_objnum_local_to_local((short)Net_create_objnums[i]); } @@ -2289,8 +2295,8 @@ void multi_send_reappear() { multibuf[0] = (char)MULTI_REAPPEAR; - *(short *)(multibuf+1) = Players[Player_num].objnum; - + PUT_INTEL_SHORT(multibuf+1, Players[Player_num].objnum); + multi_send_data(multibuf, 3, 3); } @@ -2339,11 +2345,15 @@ multi_send_kill(int objnum) Assert(Objects[objnum].id == Player_num); killer_objnum = Players[Player_num].killer_objnum; - if (killer_objnum > -1) - *(short *)(multibuf+count) = (short)objnum_local_to_remote(killer_objnum, (sbyte *)&multibuf[count+2]); + if (killer_objnum > -1) { + short s; // do it with variable since INTEL_SHORT won't work on return val from function. + + s = (short)objnum_local_to_remote(killer_objnum, (sbyte *)&multibuf[count+2]); + PUT_INTEL_SHORT(multibuf+count, s); + } else { - *(short *)(multibuf+count) = -1; + PUT_INTEL_SHORT(multibuf+count, -1); multibuf[count+2] = (char)-1; } count += 3; @@ -2369,7 +2379,7 @@ multi_send_remobj(int objnum) remote_objnum = objnum_local_to_remote((short)objnum, &obj_owner); - *(short *)(multibuf+1) = remote_objnum; // Map to network objnums + PUT_INTEL_SHORT(multibuf+1, remote_objnum); // Map to network objnums multibuf[3] = obj_owner; @@ -2429,7 +2439,7 @@ multi_send_door_open(int segnum, int side) *(short *)(multibuf+5) = (short)side; multi_send_data(multibuf, 7, 1); #else - *(short *)(multibuf+1) = (short)segnum; + PUT_INTEL_SHORT(multibuf+1, segnum ); multibuf[3] = (sbyte)side; multi_send_data(multibuf, 4, 1); #endif @@ -2573,7 +2583,7 @@ multi_send_score(void) multi_sort_kill_list(); multibuf[count] = MULTI_SCORE; count += 1; multibuf[count] = Player_num; count += 1; - *(int *)(multibuf+count) = Players[Player_num].score; count += 4; + PUT_INTEL_INT(multibuf+count, Players[Player_num].score); count += 4; multi_send_data(multibuf, count, 0); } } @@ -2616,9 +2626,9 @@ multi_send_hostage_door_status(int wallnum) Assert(Walls[wallnum].type == WALL_BLASTABLE); - multibuf[count] = MULTI_HOSTAGE_DOOR; count += 1; - *(short *)(multibuf+count) = wallnum; count += 2; - *(fix *)(multibuf+count) = Walls[wallnum].hps; count += 4; + multibuf[count] = MULTI_HOSTAGE_DOOR; count += 1; + PUT_INTEL_SHORT(multibuf+count, wallnum ); count += 2; + PUT_INTEL_INT(multibuf+count, Walls[wallnum].hps ); count += 4; multi_send_data(multibuf, count, 0); } @@ -2835,55 +2845,69 @@ void change_playernum_to( int new_Player_num ) void extract_netplayer_stats( netplayer_stats *ps, player * pd ) { - ps->flags = pd->flags; // Powerup flags, see below... - ps->energy = pd->energy; // Amount of energy remaining. - ps->shields = pd->shields; // shields remaining (protection) - ps->lives = pd->lives; // Lives remaining, 0 = game over. - ps->laser_level = pd->laser_level; // Current level of the laser. - ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon. - ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon. - memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type. - memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type. - ps->last_score=pd->last_score; // Score at beginning of current level. - ps->score=pd->score; // Current score. - ps->cloak_time=pd->cloak_time; // Time cloaked - ps->homing_object_dist=pd->homing_object_dist; // Distance of nearest homing object. - ps->invulnerable_time=pd->invulnerable_time; // Time invulnerable - ps->net_killed_total=pd->net_killed_total; // Number of times killed total - ps->net_kills_total=pd->net_kills_total; // Number of net kills total - ps->num_kills_level=pd->num_kills_level; // Number of kills this level - ps->num_kills_total=pd->num_kills_total; // Number of kills total - ps->num_robots_level=pd->num_robots_level; // Number of initial robots this level - ps->num_robots_total=pd->num_robots_total; // Number of robots total - ps->hostages_rescued_total=pd->hostages_rescued_total; // Total number of hostages rescued. - ps->hostages_total=pd->hostages_total; // Total number of hostages. - ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship. + int i; + + ps->flags = INTEL_INT(pd->flags); // Powerup flags, see below... + ps->energy = (fix)INTEL_INT(pd->energy); // Amount of energy remaining. + ps->shields = (fix)INTEL_INT(pd->shields); // shields remaining (protection) + ps->lives = pd->lives; // Lives remaining, 0 = game over. + ps->laser_level = pd->laser_level; // Current level of the laser. + ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon. + ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon. + for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) + ps->primary_ammo[i] = INTEL_SHORT(pd->primary_ammo[i]); + for (i = 0; i < MAX_SECONDARY_WEAPONS; i++) + ps->secondary_ammo[i] = INTEL_SHORT(pd->secondary_ammo[i]); + + //memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type. + //memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type. + + ps->last_score=INTEL_INT(pd->last_score); // Score at beginning of current level. + ps->score=INTEL_INT(pd->score); // Current score. + ps->cloak_time=(fix)INTEL_INT(pd->cloak_time); // Time cloaked + ps->homing_object_dist=(fix)INTEL_INT(pd->homing_object_dist); // Distance of nearest homing object. + ps->invulnerable_time=(fix)INTEL_INT(pd->invulnerable_time); // Time invulnerable + ps->net_killed_total=INTEL_SHORT(pd->net_killed_total); // Number of times killed total + ps->net_kills_total=INTEL_SHORT(pd->net_kills_total); // Number of net kills total + ps->num_kills_level=INTEL_SHORT(pd->num_kills_level); // Number of kills this level + ps->num_kills_total=INTEL_SHORT(pd->num_kills_total); // Number of kills total + ps->num_robots_level=INTEL_SHORT(pd->num_robots_level); // Number of initial robots this level + ps->num_robots_total=INTEL_SHORT(pd->num_robots_total); // Number of robots total + ps->hostages_rescued_total=INTEL_SHORT(pd->hostages_rescued_total); // Total number of hostages rescued. + ps->hostages_total=INTEL_SHORT(pd->hostages_total); // Total number of hostages. + ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship. } void use_netplayer_stats( player * ps, netplayer_stats *pd ) { - ps->flags = pd->flags; // Powerup flags, see below... - ps->energy = pd->energy; // Amount of energy remaining. - ps->shields = pd->shields; // shields remaining (protection) - ps->lives = pd->lives; // Lives remaining, 0 = game over. - ps->laser_level = pd->laser_level; // Current level of the laser. - ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon. - ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon. - memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type. - memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type. - ps->last_score=pd->last_score; // Score at beginning of current level. - ps->score=pd->score; // Current score. - ps->cloak_time=pd->cloak_time; // Time cloaked - ps->homing_object_dist=pd->homing_object_dist; // Distance of nearest homing object. - ps->invulnerable_time=pd->invulnerable_time; // Time invulnerable - ps->net_killed_total=pd->net_killed_total; // Number of times killed total - ps->net_kills_total=pd->net_kills_total; // Number of net kills total - ps->num_kills_level=pd->num_kills_level; // Number of kills this level - ps->num_kills_total=pd->num_kills_total; // Number of kills total - ps->num_robots_level=pd->num_robots_level; // Number of initial robots this level - ps->num_robots_total=pd->num_robots_total; // Number of robots total - ps->hostages_rescued_total=pd->hostages_rescued_total; // Total number of hostages rescued. - ps->hostages_total=pd->hostages_total; // Total number of hostages. - ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship. + int i; + + ps->flags = INTEL_INT(pd->flags); // Powerup flags, see below... + ps->energy = (fix)INTEL_INT((int)pd->energy); // Amount of energy remaining. + ps->shields = (fix)INTEL_INT((int)pd->shields); // shields remaining (protection) + ps->lives = pd->lives; // Lives remaining, 0 = game over. + ps->laser_level = pd->laser_level; // Current level of the laser. + ps->primary_weapon_flags=pd->primary_weapon_flags; // bit set indicates the player has this weapon. + ps->secondary_weapon_flags=pd->secondary_weapon_flags; // bit set indicates the player has this weapon. + for (i = 0; i < MAX_PRIMARY_WEAPONS; i++) + ps->primary_ammo[i] = INTEL_SHORT(pd->primary_ammo[i]); + for (i = 0; i < MAX_SECONDARY_WEAPONS; i++) + ps->secondary_ammo[i] = INTEL_SHORT(pd->secondary_ammo[i]); + //memcpy( ps->primary_ammo, pd->primary_ammo, MAX_PRIMARY_WEAPONS*sizeof(short) ); // How much ammo of each type. + //memcpy( ps->secondary_ammo, pd->secondary_ammo, MAX_SECONDARY_WEAPONS*sizeof(short) ); // How much ammo of each type. + ps->last_score = INTEL_INT(pd->last_score); // Score at beginning of current level. + ps->score = INTEL_INT(pd->score); // Current score. + ps->cloak_time = (fix)INTEL_INT((int)pd->cloak_time); // Time cloaked + ps->homing_object_dist = (fix)INTEL_INT((int)pd->homing_object_dist); // Distance of nearest homing object. + ps->invulnerable_time = (fix)INTEL_INT((int)pd->invulnerable_time); // Time invulnerable + ps->net_killed_total = INTEL_SHORT(pd->net_killed_total); // Number of times killed total + ps->net_kills_total = INTEL_SHORT(pd->net_kills_total); // Number of net kills total + ps->num_kills_level = INTEL_SHORT(pd->num_kills_level); // Number of kills this level + ps->num_kills_total = INTEL_SHORT(pd->num_kills_total); // Number of kills total + ps->num_robots_level = INTEL_SHORT(pd->num_robots_level); // Number of initial robots this level + ps->num_robots_total = INTEL_SHORT(pd->num_robots_total); // Number of robots total + ps->hostages_rescued_total = INTEL_SHORT(pd->hostages_rescued_total); // Total number of hostages rescued. + ps->hostages_total = INTEL_SHORT(pd->hostages_total); // Total number of hostages. + ps->hostages_on_board=pd->hostages_on_board; // Number of hostages on ship. } #endif diff --git a/main/multibot.c b/main/multibot.c index f91b335cf..815e26f60 100644 --- a/main/multibot.c +++ b/main/multibot.c @@ -301,6 +301,8 @@ multi_delete_controlled_robot(int objnum) void multi_send_claim_robot(int objnum) { + short s; + if ((objnum < 0) || (objnum > Highest_object_index)) { Int3(); // See rob @@ -317,7 +319,8 @@ multi_send_claim_robot(int objnum) multibuf[0] = (char)MULTI_ROBOT_CLAIM; multibuf[1] = Player_num; - *(short *)(multibuf+2) = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]); + s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]); + PUT_INTEL_SHORT(multibuf+2, s); multi_send_data(multibuf, 5, 1); } @@ -325,6 +328,8 @@ multi_send_claim_robot(int objnum) void multi_send_release_robot(int objnum) { + short s; + if ((objnum < 0) || (objnum > Highest_object_index)) { Int3(); // See rob @@ -341,7 +346,8 @@ multi_send_release_robot(int objnum) multibuf[0] = (char)MULTI_ROBOT_RELEASE; multibuf[1] = Player_num; - *(short *)(multibuf+2) = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]); + s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[4]); + PUT_INTEL_SHORT(multibuf+2, s); multi_send_data(multibuf, 5, 1); } @@ -388,13 +394,16 @@ void multi_send_robot_position_sub(int objnum) { int loc = 0; + short s; #ifdef WORDS_BIGENDIAN shortpos sp; #endif - multibuf[loc] = MULTI_ROBOT_POSITION; loc += 1; - multibuf[loc] = Player_num; loc += 1; - *(short *)(multibuf+loc) = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); + multibuf[loc] = MULTI_ROBOT_POSITION; loc += 1; + multibuf[loc] = Player_num; loc += 1; + s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); + PUT_INTEL_SHORT(multibuf+loc, s); + loc += 3; #ifndef WORDS_BIGENDIAN create_shortpos((shortpos *)(multibuf+loc), Objects+objnum,0); loc += sizeof(shortpos); @@ -448,13 +457,15 @@ multi_send_robot_fire(int objnum, int gun_num, vms_vector *fire) { // Send robot fire event int loc = 0; + short s; #ifdef WORDS_BIGENDIAN vms_vector swapped_vec; #endif multibuf[loc] = MULTI_ROBOT_FIRE; loc += 1; multibuf[loc] = Player_num; loc += 1; - *(short *)(multibuf+loc) = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); + s = objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); + PUT_INTEL_SHORT(multibuf+loc, s); loc += 3; multibuf[loc] = gun_num; loc += 1; #ifndef WORDS_BIGENDIAN @@ -489,13 +500,16 @@ multi_send_robot_explode(int objnum, int killer) // Send robot explosion event to the other players int loc = 0; + short s; multibuf[loc] = MULTI_ROBOT_EXPLODE; loc += 1; multibuf[loc] = Player_num; loc += 1; - *(short *)(multibuf+loc) = (short)objnum_local_to_remote(killer, (sbyte *)&multibuf[loc+2]); - loc += 3; - *(short *)(multibuf+loc) = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); - loc += 3; + s = (short)objnum_local_to_remote(killer, (sbyte *)&multibuf[loc+2]); + PUT_INTEL_SHORT(multibuf+loc, s); loc += 3; + + s = (short)objnum_local_to_remote(objnum, (sbyte *)&multibuf[loc+2]); + PUT_INTEL_SHORT(multibuf+loc, s); loc += 3; + multi_send_data(multibuf, loc, 1); multi_delete_controlled_robot(objnum); @@ -510,9 +524,9 @@ multi_send_create_robot(int station, int objnum, int type) multibuf[loc] = MULTI_CREATE_ROBOT; loc += 1; multibuf[loc] = Player_num; loc += 1; - multibuf[loc] = (sbyte)station; loc += 1; - *(short *)(multibuf+loc) = (short)objnum; loc += 2; - multibuf[loc] = type; loc += 1; + multibuf[loc] = (sbyte)station; loc += 1; + PUT_INTEL_SHORT(multibuf+loc, objnum); loc += 2; + multibuf[loc] = type; loc += 1; map_objnum_local_to_local((short)objnum); @@ -528,12 +542,12 @@ multi_send_boss_actions(int bossobjnum, int action, int secondary, int objnum) multibuf[loc] = MULTI_BOSS_ACTIONS; loc += 1; multibuf[loc] = Player_num; loc += 1; // Which player is controlling the boss - *(short *)(multibuf+loc) = bossobjnum; loc += 2; // We won't network map this objnum since its the boss - multibuf[loc] = (sbyte)action; loc += 1; // What is the boss doing? - multibuf[loc] = (sbyte)secondary; loc += 1; // More info for what he is doing - *(short *)(multibuf+loc) = objnum; loc += 2; // Objnum of object created by gate-in action + PUT_INTEL_SHORT(multibuf+loc, bossobjnum); loc += 2; // We won't network map this objnum since it's the boss + multibuf[loc] = (sbyte)action; loc += 1; // What is the boss doing? + multibuf[loc] = (sbyte)secondary; loc += 1; // More info for what he is doing + PUT_INTEL_SHORT(multibuf+loc, objnum); loc += 2; // Objnum of object created by gate-in action if (action == 3) { - *(short *)(multibuf+loc) = Objects[objnum].segnum; loc += 2; // Segment number object created in (for gate only) + PUT_INTEL_SHORT(multibuf+loc, Objects[objnum].segnum); loc += 2; // Segment number object created in (for gate only) } else loc += 2; // Dummy @@ -585,7 +599,7 @@ multi_send_create_robot_powerups(object *del_obj) } for (i = 0; i < Net_create_loc; i++) { - *(short *)(multibuf+loc) = Net_create_objnums[i]; + PUT_INTEL_SHORT(multibuf+loc, Net_create_objnums[i]); loc += 2; map_objnum_local_to_local(Net_create_objnums[i]); } @@ -604,7 +618,7 @@ multi_do_claim_robot(char *buf) pnum = buf[1]; - remote_botnum = *(short *)(buf+2); + remote_botnum = GET_INTEL_SHORT(buf + 2); botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[4]); if ((botnum > Highest_object_index) || (botnum < 0)) { @@ -635,12 +649,13 @@ multi_do_claim_robot(char *buf) void multi_do_release_robot(char *buf) { - short botnum; + short botnum, remote_botnum; char pnum; pnum = buf[1]; - botnum = (objnum_remote_to_local(*(short *)(buf+2), (sbyte)buf[4])); + remote_botnum = GET_INTEL_SHORT(buf + 2); + botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[4]); if ((botnum < 0) || (botnum > Highest_object_index)) { return; @@ -666,7 +681,7 @@ multi_do_robot_position(char *buf) { // Process robot movement sent by another player - short botnum; + short botnum, remote_botnum; char pnum; int loc = 1; #ifdef WORDS_BIGENDIAN @@ -675,8 +690,8 @@ multi_do_robot_position(char *buf) pnum = buf[loc]; loc += 1; - botnum = objnum_remote_to_local(*(short *)(buf+loc), (sbyte)buf[loc+2]); - loc += 3; + remote_botnum = GET_INTEL_SHORT(buf + loc); + botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3; if ((botnum < 0) || (botnum > Highest_object_index)) { return; @@ -721,15 +736,20 @@ multi_do_robot_fire(char *buf) { // Send robot fire event int loc = 1; - int botnum, pnum, gun_num; + int botnum; + short remote_botnum; + int pnum, gun_num; vms_vector fire, gun_point; robot_info *robptr; pnum = buf[loc]; loc += 1; - botnum = objnum_remote_to_local(*(short *)(buf+loc), (sbyte)buf[loc+2]); - loc += 3; - gun_num = (sbyte)buf[loc]; loc += 1; - fire = *(vms_vector *)(buf+loc); + remote_botnum = GET_INTEL_SHORT(buf + loc); + botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3; + gun_num = (sbyte)buf[loc]; loc += 1; + memcpy(&fire, buf+loc, sizeof(vms_vector)); + fire.x = (fix)INTEL_INT((int)fire.x); + fire.y = (fix)INTEL_INT((int)fire.y); + fire.z = (fix)INTEL_INT((int)fire.z); if ((botnum < 0) || (botnum > Highest_object_index) || (Objects[botnum].type != OBJ_ROBOT) || (Objects[botnum].flags & OF_EXPLODING)) { @@ -811,18 +831,17 @@ multi_do_robot_explode(char *buf) // Explode robot controlled by other player int botnum; + short remote_botnum; int loc = 1; - short killer; + short killer, remote_killer; int pnum; int rval; pnum = buf[loc]; loc += 1; - killer = objnum_remote_to_local(*(short *)(buf+loc), (sbyte)buf[loc+2]); - loc += 3; - botnum = objnum_remote_to_local(*(short *)(buf+loc), (sbyte)buf[loc+2]); - loc += 3; - -// Assert((botnum > -1) && (botnum <= Highest_object_index)); + remote_killer = GET_INTEL_SHORT(buf + loc); + killer = objnum_remote_to_local(remote_killer, (sbyte)buf[loc+2]); loc += 3; + remote_botnum = GET_INTEL_SHORT(buf + loc); + botnum = objnum_remote_to_local(remote_botnum, (sbyte)buf[loc+2]); loc += 3; if ((botnum < 0) || (botnum > Highest_object_index)) { return; @@ -843,13 +862,15 @@ multi_do_create_robot(char *buf) int fuelcen_num = buf[2]; int pnum = buf[1]; - short objnum = *(short *)(buf+3); + short objnum; int type = buf[5]; FuelCenter *robotcen; vms_vector cur_object_loc, direction; object *obj; + objnum = GET_INTEL_SHORT(buf + 3); + if ((pnum < 0) || (objnum < 0) || (fuelcen_num < 0) || (fuelcen_num >= Num_fuelcenters) || (pnum >= N_players)) { Int3(); // Bogus data @@ -900,12 +921,12 @@ multi_do_boss_actions(char *buf) int loc = 1; short remote_objnum, segnum; - pnum = buf[loc]; loc += 1; - boss_objnum = *(short *)(buf+loc); loc += 2; - action = buf[loc]; loc += 1; - secondary = buf[loc]; loc += 1; - remote_objnum = *(short *)(buf+loc);loc += 2; - segnum = *(short *)(buf+loc); loc += 2; + pnum = buf[loc]; loc += 1; + boss_objnum = GET_INTEL_SHORT(buf + loc); loc += 2; + action = buf[loc]; loc += 1; + secondary = buf[loc]; loc += 1; + remote_objnum = GET_INTEL_SHORT(buf + loc); loc += 2; + segnum = GET_INTEL_SHORT(buf + loc); loc += 2; if ((boss_objnum < 0) || (boss_objnum > Highest_object_index)) { @@ -1001,14 +1022,19 @@ multi_do_create_robot_powerups(char *buf) object del_obj; int pnum, egg_objnum, i; - pnum = buf[loc]; loc += 1; - del_obj.contains_count = buf[loc]; loc += 1; - del_obj.contains_type = buf[loc]; loc += 1; - del_obj.contains_id = buf[loc]; loc += 1; - del_obj.segnum = *(short *)(buf+loc); loc += 2; - del_obj.pos = *(vms_vector *)(buf+loc); loc += 12; + pnum = buf[loc]; loc += 1; + del_obj.contains_count = buf[loc]; loc += 1; + del_obj.contains_type = buf[loc]; loc += 1; + del_obj.contains_id = buf[loc]; loc += 1; + del_obj.segnum = GET_INTEL_SHORT(buf + loc); loc += 2; + memcpy(&del_obj.pos, buf+loc, sizeof(vms_vector)); loc += 12; + vm_vec_zero(&del_obj.mtype.phys_info.velocity); + del_obj.pos.x = (fix)INTEL_INT((int)del_obj.pos.x); + del_obj.pos.y = (fix)INTEL_INT((int)del_obj.pos.y); + del_obj.pos.z = (fix)INTEL_INT((int)del_obj.pos.z); + Assert((pnum >= 0) && (pnum < N_players)); Net_create_loc = 0; @@ -1026,8 +1052,11 @@ multi_do_create_robot_powerups(char *buf) for (i = 0; i < Net_create_loc; i++) { - if (*(short *)(buf+loc) != -1) - map_objnum_local_to_remote((short)Net_create_objnums[i], *(short *)(buf+loc), pnum); + short s; + + s = GET_INTEL_SHORT(buf + loc); + if ( s != -1) + map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum); else Objects[Net_create_objnums[i]].flags |= OF_SHOULD_BE_DEAD; // Delete objects other guy didn't create one of loc += 2; diff --git a/main/netpkt.c b/main/netpkt.c index b45768f50..d66728f55 100644 --- a/main/netpkt.c +++ b/main/netpkt.c @@ -17,6 +17,97 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include #include "pstypes.h" +//FIXME: Certain combinations of players having and not having the editor will cause the segment checksum code to fail. +#ifdef WORDS_BIGENDIAN + +#include "byteswap.h" +#include "segment.h" +#include "gameseg.h" + +// routine to calculate the checksum of the segments. We add these specialized routines +// since the current way is byte order dependent. + +void mac_do_checksum_calc(ubyte *b, int len, unsigned int *s1, unsigned int *s2) +{ + + while(len--) { + *s1 += *b++; + if (*s1 >= 255) *s1 -= 255; + *s2 += *s1; + } +} + +ushort mac_calc_segment_checksum() +{ + int i, j, k; + unsigned int sum1,sum2; + short s; + int t; + + sum1 = sum2 = 0; + for (i = 0; i < Highest_segment_index + 1; i++) { + for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) { + mac_do_checksum_calc((unsigned char *)&(Segments[i].sides[j].type), 1, &sum1, &sum2); + mac_do_checksum_calc(&(Segments[i].sides[j].pad), 1, &sum1, &sum2); + s = INTEL_SHORT(Segments[i].sides[j].wall_num); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + s = INTEL_SHORT(Segments[i].sides[j].tmap_num); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + s = INTEL_SHORT(Segments[i].sides[j].tmap_num2); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + for (k = 0; k < 4; k++) { + t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].u)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].v)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + t = INTEL_INT(((int)Segments[i].sides[j].uvls[k].l)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + } + for (k = 0; k < 2; k++) { + t = INTEL_INT(((int)Segments[i].sides[j].normals[k].x)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + t = INTEL_INT(((int)Segments[i].sides[j].normals[k].y)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + t = INTEL_INT(((int)Segments[i].sides[j].normals[k].z)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); + } + } + for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) { + s = INTEL_SHORT(Segments[i].children[j]); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + } + for (j = 0; j < MAX_VERTICES_PER_SEGMENT; j++) { + s = INTEL_SHORT(Segments[i].verts[j]); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + } + s = INTEL_SHORT(Segments[i].objects); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + mac_do_checksum_calc((unsigned char *)&(Segments[i].special), 1, &sum1, &sum2); + mac_do_checksum_calc((unsigned char *)&(Segments[i].matcen_num), 1, &sum1, &sum2); + s = INTEL_SHORT(Segments[i].value); + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); + t = INTEL_INT(((int)Segments[i].static_light)); + mac_do_checksum_calc((ubyte *)&t, 4, &sum1, &sum2); +#ifndef EDITOR + s = INTEL_SHORT(Segments[i].pad); // necessary? If this isn't set to 0 it won't work Intel-Intel anyway. + mac_do_checksum_calc((ubyte *)&s, 2, &sum1, &sum2); +#endif + } + sum2 %= 255; + return ((sum1<<8)+ sum2); +} + +// this routine totally and completely relies on the fact that the network +// checksum must be calculated on the segments!!!!! + +ushort netmisc_calc_checksum(void * vptr, int len) +{ + vptr = vptr; + len = len; + return mac_calc_segment_checksum(); +} +#endif + #include "multi.h" #include "network.h" #include "object.h" @@ -24,24 +115,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "error.h" #include "netpkt.h" -// Calculates the checksum of a block of memory. -unsigned short netmisc_calc_checksum( void * vptr, int len ) -{ - ubyte * ptr = (ubyte *)vptr; - unsigned int sum1,sum2; - - sum1 = sum2 = 0; - - while(len--) { - sum1 += *ptr++; - if (sum1 >= 255 ) sum1 -= 255; - sum2 += sum1; - } - sum2 %= 255; - - return ((sum1<<8)+ sum2); -} - void receive_netplayer_info(ubyte *data, netplayer_info *info, int d1x) { int loc = 0; @@ -580,19 +653,19 @@ void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short out_buffer[loc] = Player_num; loc++; out_buffer[loc] = pl_obj->render_type; loc++; out_buffer[loc] = Current_level_num; loc++; - create_shortpos((shortpos *)(out_buffer + loc), pl_obj,0); + create_shortpos((shortpos *)(out_buffer + loc), pl_obj,1); loc += 9+2*3+2+2*3; // go past shortpos structure - *(ushort *)(out_buffer + loc) = MySyncPack.data_size; loc += 2; + PUT_INTEL_SHORT(out_buffer + loc, MySyncPack.data_size); loc += 2; memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; } else if (short_packet == 2) { loc = 0; out_buffer[loc] = PID_PDATA_SHORT2; loc++; out_buffer[loc] = MySyncPack.numpackets & 255; loc++; - create_shortpos((shortpos *)(out_buffer + loc), pl_obj,0); + create_shortpos((shortpos *)(out_buffer + loc), pl_obj,1); loc += 9+2*3+2+2*3; // go past shortpos structure tmpus = MySyncPack.data_size | (Player_num << 12) | (pl_obj->render_type << 15); - *(ushort *)(out_buffer + loc) = tmpus; loc += 2; + PUT_INTEL_SHORT(out_buffer + loc, tmpus); loc += 2; out_buffer[loc] = Current_level_num; loc++; memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size); loc += MySyncPack.data_size; @@ -758,7 +831,7 @@ void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet) info->obj_render_type = data[loc]; loc++; info->level_num = data[loc]; loc++; loc += 9+2*3+2+2*3; // skip shortpos structure - info->data_size = *(ushort *)(data + loc); loc+=2; + info->data_size = GET_INTEL_SHORT(data + loc); loc+=2; memcpy(info->data, &(data[loc]), info->data_size); } else if (short_packet == 2) { ushort tmpus; @@ -767,7 +840,7 @@ void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet) info->type = data[loc]; loc++; info->numpackets = data[loc]; loc++; loc += 9+2*3+2+2*3; // skip shortpos structure - tmpus = *(ushort *)(data + loc); loc+=2; + tmpus = GET_INTEL_SHORT(data + loc); loc+=2; info->data_size = tmpus & 0xfff; info->playernum = (tmpus >> 12) & 7; info->obj_render_type = tmpus >> 15; @@ -1032,5 +1105,27 @@ void swap_object(object *obj) } +#ifndef WORDS_BIGENDIAN + + +// Calculates the checksum of a block of memory. +ushort netmisc_calc_checksum(void * vptr, int len) +{ + ubyte *ptr = (ubyte *)vptr; + unsigned int sum1,sum2; + + sum1 = sum2 = 0; + + while(len--) { + sum1 += *ptr++; + if (sum1 >= 255) sum1 -= 255; + sum2 += sum1; + } + sum2 %= 255; + + return ((sum1<<8)+ sum2); +} + +#endif /* WORDS_BIGENDIAN */ #endif //ifdef NETWORK diff --git a/main/network.c b/main/network.c index 604526c6b..c90f028cc 100644 --- a/main/network.c +++ b/main/network.c @@ -857,7 +857,7 @@ void network_send_objects(void) { obj_count = 0; Network_send_object_mode = 0; - *(short *)(object_buffer+loc) = -1; loc += 2; + *(short *)(object_buffer+loc) = INTEL_SHORT(-1); loc += 2; object_buffer[loc] = player_num; loc += 1; loc += 2; // Placeholder for remote_objnum, not used here Network_send_objnum = 0; @@ -885,10 +885,11 @@ void network_send_objects(void) remote_objnum = objnum_local_to_remote((short)i, &owner); Assert(owner == object_owner[i]); - *(short *)(object_buffer+loc) = i; loc += 2; + *(short *)(object_buffer+loc) = INTEL_SHORT(i); loc += 2; object_buffer[loc] = owner; loc += 1; - *(short *)(object_buffer+loc) = remote_objnum; loc += 2; + *(short *)(object_buffer+loc) = INTEL_SHORT(remote_objnum); loc += 2; memcpy(object_buffer+loc, &Objects[i], sizeof(object)); loc += sizeof(object); + swap_object((object *)&object_buffer[loc]); } if (obj_count_frame) // Send any objects we've buffered @@ -921,8 +922,8 @@ void network_send_objects(void) object_buffer[0] = PID_OBJECT_DATA; object_buffer[1] = 1; object_buffer[2] = frame_num; - *(short *)(object_buffer+3) = -2; - *(short *)(object_buffer+6) = obj_count; + *(short *)(object_buffer+3) = INTEL_SHORT(-2); + *(short *)(object_buffer+6) = INTEL_SHORT(obj_count); //OLD NetDrvSendPacketData(object_buffer, 8, &Network_player_rejoining.player.node); NetDrvSendInternetworkPacketData(object_buffer, 8, Network_player_rejoining.player.server, Network_player_rejoining.player.node); @@ -1149,8 +1150,8 @@ network_send_endlevel_sub(int player_num) end.type = PID_ENDLEVEL; end.player_num = player_num; end.connected = Players[player_num].connected; - end.kills = Players[player_num].net_kills_total; - end.killed = Players[player_num].net_killed_total; + end.kills = INTEL_SHORT(Players[player_num].net_kills_total); + end.killed = INTEL_SHORT(Players[player_num].net_killed_total); memcpy(end.kill_matrix, kill_matrix[player_num], MAX_PLAYERS*sizeof(short)); //added 05/18/99 Matt Mueller - it doesn't use the rest, but we should at least initialize it :) memset(end.kill_matrix[1], 0, (MAX_PLAYERS-1)*MAX_PLAYERS*sizeof(short)); @@ -1175,7 +1176,7 @@ network_send_endlevel_sub(int player_num) { if ((i != Player_num) && (i!=player_num) && (Players[i].connected)) { - send_endlevel_packet(&end, Netgame.players[i].server, Netgame.players[i].node, Players[i].net_address); + NetDrvSendPacketData((ubyte *)&end, sizeof(endlevel_info), Netgame.players[i].server, Netgame.players[i].node, Players[i].net_address); } } } @@ -1464,7 +1465,7 @@ network_read_endlevel_packet( ubyte *data ) // Special packet for end of level syncing int playernum; - endlevel_info *end; + endlevel_info *end = (endlevel_info *)data; #ifdef WORDS_BIGENDIAN int i, j; @@ -1475,10 +1476,6 @@ network_read_endlevel_packet( ubyte *data ) end->killed = INTEL_SHORT(end->killed); #endif - endlevel_info end_data; - end = &end_data; - receive_endlevel_packet(data, &end_data); - playernum = end->player_num; Assert(playernum != Player_num); @@ -1556,9 +1553,9 @@ network_read_object_packet( ubyte *data ) for (i = 0; i < nobj; i++) { - objnum = *(short *)(data+loc); loc += 2; - obj_owner = data[loc]; loc += 1; - remote_objnum = *(short *)(data+loc); loc += 2; + objnum = INTEL_SHORT(*(short *)(data+loc)); loc += 2; + obj_owner = data[loc]; loc += 1; + remote_objnum = INTEL_SHORT(*(short *)(data+loc)); loc += 2; if (objnum == -1) { @@ -1622,7 +1619,9 @@ network_read_object_packet( ubyte *data ) obj_unlink(objnum); Assert(obj->segnum == -1); Assert(objnum < MAX_OBJECTS); - memcpy(obj,data+loc,sizeof(object)); loc += sizeof(object); + memcpy(obj,data+loc,sizeof(object)); + swap_object(obj); + loc += sizeof(object); segnum = obj->segnum; obj->next = obj->prev = obj->segnum = -1; obj->attached_obj = -1; @@ -2139,15 +2138,6 @@ void network_read_sync_packet( ubyte * data, int d1x ) netgame_info *sp = &Netgame; char temp_callsign[CALLSIGN_LEN+1]; -#ifdef WORDS_BIGENDIAN - netgame_info tmp_info; - - if (data) - { - receive_d1x_netgame_packet((ubyte *)sp, &tmp_info); - sp = &tmp_info; - } -#endif // This function is now called by all people entering the netgame. @@ -3436,9 +3426,9 @@ void network_read_pdata_packet(ubyte *data, int short_packet) //------------ Read the player's ship's object info ---------------------- if (short_packet == 1) { - extract_shortpos(TheirObj, (shortpos *)(data + 4),0); + extract_shortpos(TheirObj, (shortpos *)(data + 4),1); } else if (short_packet == 2) { - extract_shortpos(TheirObj, (shortpos *)(data + 2),0); + extract_shortpos(TheirObj, (shortpos *)(data + 2),1); } else { TheirObj->pos = pd->obj_pos; TheirObj->orient = pd->obj_orient;