From 2abfd728bf7a582bf8bedd667e7c644883e29bf4 Mon Sep 17 00:00:00 2001 From: Mark Olsen Date: Wed, 22 Feb 2006 02:38:48 +0000 Subject: [PATCH] First bunch of endian fixes... At least bsp loading doesn't crash&burn anymore :) git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1989 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- fteqtv/bsp.c | 30 +++++++++++++++--------------- fteqtv/parse.c | 2 +- fteqtv/qtv.h | 8 +++++++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/fteqtv/bsp.c b/fteqtv/bsp.c index 612e20f4e..96dda2d88 100644 --- a/fteqtv/bsp.c +++ b/fteqtv/bsp.c @@ -230,19 +230,19 @@ bsp_t *BSP_LoadModel(cluster_t *cluster, char *gamedir, char *bspname) header = (dheader_t*)data; if (data[0] != 29) { - Sys_Printf(cluster, "BSP not version 29\n", bspname, gamedir); free(data); + Sys_Printf(cluster, "BSP not version 29\n", bspname, gamedir); return NULL; } - planes = (dplane_t*)(data+header->lumps[LUMP_PLANES].fileofs); - nodes = (dnode_t*)(data+header->lumps[LUMP_NODES].fileofs); - leaf = (dleaf_t*)(data+header->lumps[LUMP_LEAFS].fileofs); + planes = (dplane_t*)(data+LittleLong(header->lumps[LUMP_PLANES].fileofs)); + nodes = (dnode_t*)(data+LittleLong(header->lumps[LUMP_NODES].fileofs)); + leaf = (dleaf_t*)(data+LittleLong(header->lumps[LUMP_LEAFS].fileofs)); - numnodes = header->lumps[LUMP_NODES].filelen/sizeof(dnode_t); - numleafs = header->lumps[LUMP_LEAFS].filelen/sizeof(dleaf_t); + numnodes = LittleLong(header->lumps[LUMP_NODES].filelen)/sizeof(dnode_t); + numleafs = LittleLong(header->lumps[LUMP_LEAFS].filelen)/sizeof(dleaf_t); - bsp = malloc(sizeof(bsp_t) + sizeof(node_t)*numnodes + header->lumps[LUMP_VISIBILITY].filelen + sizeof(unsigned char *)*numleafs); + bsp = malloc(sizeof(bsp_t) + sizeof(node_t)*numnodes + LittleLong(header->lumps[LUMP_VISIBILITY].filelen) + sizeof(unsigned char *)*numleafs); if (bsp) { bsp->fullchecksum = 0; @@ -252,7 +252,7 @@ bsp_t *BSP_LoadModel(cluster_t *cluster, char *gamedir, char *bspname) if (i == LUMP_ENTITIES) continue; //entities never appear in any checksums - chksum = Com_BlockChecksum(data + header->lumps[i].fileofs, header->lumps[i].filelen); + chksum = Com_BlockChecksum(data + LittleLong(header->lumps[i].fileofs), LittleLong(header->lumps[i].filelen)); bsp->fullchecksum ^= chksum; if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES) continue; @@ -266,14 +266,14 @@ bsp_t *BSP_LoadModel(cluster_t *cluster, char *gamedir, char *bspname) for (i = 0; i < numnodes; i++) { - bsp->nodes[i].child[0] = nodes[i].children[0]; - bsp->nodes[i].child[1] = nodes[i].children[1]; - bsp->nodes[i].planedist = planes[nodes[i].planenum].dist; - bsp->nodes[i].planen[0] = planes[nodes[i].planenum].normal[0]; - bsp->nodes[i].planen[1] = planes[nodes[i].planenum].normal[1]; - bsp->nodes[i].planen[2] = planes[nodes[i].planenum].normal[2]; + bsp->nodes[i].child[0] = LittleShort(nodes[i].children[0]); + bsp->nodes[i].child[1] = LittleShort(nodes[i].children[1]); + bsp->nodes[i].planedist = planes[LittleLong(nodes[i].planenum)].dist; + bsp->nodes[i].planen[0] = planes[LittleLong(nodes[i].planenum)].normal[0]; + bsp->nodes[i].planen[1] = planes[LittleLong(nodes[i].planenum)].normal[1]; + bsp->nodes[i].planen[2] = planes[LittleLong(nodes[i].planenum)].normal[2]; } - memcpy(bsp->pvslump, data+header->lumps[LUMP_VISIBILITY].fileofs, header->lumps[LUMP_VISIBILITY].filelen); + memcpy(bsp->pvslump, data+LittleLong(header->lumps[LUMP_VISIBILITY].fileofs), LittleLong(header->lumps[LUMP_VISIBILITY].filelen)); for (i = 0; i < numleafs; i++) { diff --git a/fteqtv/parse.c b/fteqtv/parse.c index eeeda6e22..c2b7ec534 100644 --- a/fteqtv/parse.c +++ b/fteqtv/parse.c @@ -1251,7 +1251,7 @@ void ParseMessage(sv_t *tv, char *buffer, int length, int to, int mask) if (i) SendClientCommand(tv, "modellist %i %i\n", tv->clservercount, i); else - SendClientCommand(tv, "prespawn %i 0 %i\n", tv->clservercount, BSP_Checksum(tv->bsp)); + SendClientCommand(tv, "prespawn %i 0 %i\n", tv->clservercount, LittleLong(BSP_Checksum(tv->bsp))); } break; case svc_soundlist: diff --git a/fteqtv/qtv.h b/fteqtv/qtv.h index 9002ea488..114850f3b 100644 --- a/fteqtv/qtv.h +++ b/fteqtv/qtv.h @@ -17,7 +17,13 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +#ifdef __GNUC__ +#define LittleLong(x) ({ typeof(x) _x = (x); _x = (((unsigned char *)&_x)[0]|(((unsigned char *)&_x)[1]<<8)|(((unsigned char *)&_x)[2]<<16)|(((unsigned char *)&_x)[3]<<24)); _x; }) +#define LittleShort(x) ({ typeof(x) _x = (x); _x = (((unsigned char *)&_x)[0]|(((unsigned char *)&_x)[1]<<8)); _x; }) +#else +#define LittleLong(x) (x) +#define LittleShort(x) (x) +#endif //each server that we are connected to has it's own state. //it should be easy enough to use one thread per server.