Ejemplo n.º 1
0
void decompile_vertices(char *map, wadfile_t *wf, FILE *fp)
{
	void		*vertices;
	vertex_t	*v;
	int		size;
	int		i;

	if (verbose)
		printf("Decompiling vertices...\n");

	/* get the lump with the vertices for the map */
	if ((vertices =
		get_map_lump(wf, map, "VERTEXES", &size)) == (void *)0) {
		fprintf(stderr, "can't find VERTEXES lump for %s\n", map);
		exit(1);
	}
	
	/* write vertices start marker */
	fprintf(fp, " VERTEXES_START\n");

	/* loop over all vertices in the lump and decompile */
	v = (vertex_t *) vertices;
	for (i = 0; i < size / sizeof(vertex_t); i++) {
		swapint(&v->x);
		swapint(&v->y);
		fprintf(fp, "  V%d : %d %d\n", i, v->x, v->y);
		v++;
	}

	/* write vertices end marker */
	fprintf(fp, " VERTEXES_END\n\n");

	/* free memory */
	free(vertices);
}
Ejemplo n.º 2
0
int       _TreeRemoveNodesTags(void *dbid, int nid)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  NODE *node;
  NID *nid_ptr = (NID *)&nid;
  int tagidx, next_tag;

  int       status;
  
  if (!(IS_OPEN_FOR_EDIT(dblist)))
    return TreeNOEDIT;

/**********************************
 For every tag found for this node
   Remove it from tree
***********************************/

  status = TreeTNF;
  nid_to_node(dblist, nid_ptr, node);
  for (tagidx=swapint((char *)&node->tag_link); tagidx !=0; tagidx = next_tag) {
    next_tag = swapint((char *)&dblist->tree_info->tag_info[tagidx-1].tag_link);
    _RemoveTagIdx(dblist, tagidx);
  }
  return status;
}
Ejemplo n.º 3
0
void swaphead(PICTURE *pic)
{	pic->fileid = swapint(pic->fileid);
	pic->x = swapint(pic->x);
	pic->y = swapint(pic->y);
	pic->xorigin = swapfloat(pic->xorigin);
	pic->yorigin = swapfloat(pic->yorigin);
	pic->items = swapint(pic->items);
	pic->samples = swapint(pic->samples);
}
Ejemplo n.º 4
0
void swaptriangles(Mesh *m)
{
    int     nt=m->nt;
    int3D   *t=m->t;
    int     i;
    
    for(i=0;i<nt;i++)
    {
        swapint(&t[i].a);
        swapint(&t[i].b);
        swapint(&t[i].c);
    }
}
Ejemplo n.º 5
0
void hmp2mid(hmp_file *hmp, unsigned char **midbuf, unsigned int *midlen)
{
	int mi, i, j;
	short ms, time_div = 0xC0;
	
	*midlen = 0;
	time_div = hmp->tempo*1.6;
	
	// write MIDI-header
	*midbuf = (unsigned char *) malloc(4);
	memcpy(&(*midbuf)[*midlen], "MThd", 4);
	*midlen += 4;
	mi = swapint(6);
	*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(mi));
	memcpy(&(*midbuf)[*midlen], &mi, sizeof(mi));
	*midlen += sizeof(mi);
	ms = swapshort(1);
	*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms));
	memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms));
	*midlen += sizeof(ms);
	ms = swapshort(hmp->num_trks);
	*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms));
	memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms));
	*midlen += sizeof(ms);
	ms = swapshort(time_div);
	*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(ms));
	memcpy(&(*midbuf)[*midlen], &ms, sizeof(ms));
	*midlen += sizeof(ms);
	*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(tempo));
	memcpy(&(*midbuf)[*midlen], &tempo, sizeof(tempo));
	*midlen += sizeof(tempo);
	
	// tracks
	for (i = 1; i < hmp->num_trks; i++)
	{
		int midtrklenpos = 0;
		
		*midbuf = (unsigned char *) realloc(*midbuf, *midlen + 4);
		memcpy(&(*midbuf)[*midlen], "MTrk", 4);
		*midlen += 4;
		midtrklenpos = *midlen;
		mi = 0;
		*midbuf = (unsigned char *) realloc(*midbuf, *midlen + sizeof(mi));
		*midlen += sizeof(mi);
		mi = hmptrk2mid(hmp->trks[i].data, hmp->trks[i].len, midbuf, midlen, hmp->trks);
		mi = swapint(mi);
		memcpy(&(*midbuf)[midtrklenpos], &mi, 4);
	}
}
Ejemplo n.º 6
0
/* instantiates *(pic->data), swaps as needed, readhead called before */
int readdata(PICTURE *pic, FILE *fp)
{ 
int magic = pic->magic;
if ((pic->data) == NULL)
	{ if (newdata(pic)) return(-1); }
switch (magic) {
	case PGM_ASCI_MAGIC: case PPM_ASCI_MAGIC: case VISA_MAGIC: case VISA_SWMAGIC:
		readascidata(pic,fp); break;
	case VIS_MAGIC: case PGM_MAGIC: case PPM_MAGIC:
		if ( fread(pic->data,sizeofdata(pic),1,fp) == 0)
		{
		(void)fprintf(stderr,"readdata: failed to read binary data\n");
		return(-1);
		} break; 
	case VIS_SWMAGIC: /* now does endian swapping */
		{ 
		int x, sz = (pic->items)*(pic->samples);
		switch (pic->fileid) {
			case IMAGE_ID: break; /* no need to swap individual chars */
			case INT_ID: { 
				INT_TYPE *buf = (INT_TYPE *)(pic->data);
				for (x=0; x<sz; x++) { *buf = swapint(*buf); buf++; } }
				break;
			case FIMAGE_ID: { 
				FIMAGE_TYPE *buf = (FIMAGE_TYPE *)(pic->data);
				for (x=0; x<sz; x++) { *buf = swapfloat(*buf); buf++; } }
				break;
			default: (void)fprintf(stderr,
				"readdata: please recreate the input file on this architecture\n"); 
				return(-1);	}
		} break;
	default: (void)fprintf(stderr,"readdata: strange magic\n"); return(-1); }
return(0);
}
Ejemplo n.º 7
0
int FreeSurfer_load_mesh(char *path, Mesh *m)
{
    int     *np=&(m->np);
    int     *nt=&(m->nt);
    float3D **p=&(m->p);
    int3D   **t=&(m->t);
    FILE    *f;
    int     id,a,b,c;
    char    date[256],info[256];


    f=fopen(path,"r");
    
    if(f==NULL)
        return 1;

    // read triangle/quad identifier: 3 bytes
    a=((int)(u_int8_t)fgetc(f))<<16;
    b=((int)(u_int8_t)fgetc(f))<<8;
    c=(u_int8_t)fgetc(f);
    id=a+b+c;
    if(id==16777214)    // triangle mesh
    {
        fgets(date,256,f);
        fgets(info,256,f);
        fread(np,1,sizeof(int),f);    if(endianness==kINTEL) swapint(np);
        fread(nt,1,sizeof(int),f);    if(endianness==kINTEL) swapint(nt);
        // read vertices
        *p=(float3D*)calloc(*np,sizeof(float3D));
            if((*p)==NULL) printf("ERROR: Cannot allocate memory for points [FreeSurfer_load_mesh]\n");
            else
            {
        fread((char*)(*p),*np,3*sizeof(float),f);      if(endianness==kINTEL) swapvertices(m);
        // read triangles
        *t=(int3D*)calloc(*nt,sizeof(int3D));
            if((*t)==NULL) printf("ERROR: Cannot allocate memory for triangles [FreeSurfer_load_mesh]\n");
            else
            {
        fread((char*)(*t),*nt,3*sizeof(int),f);        if(endianness==kINTEL) swaptriangles(m);
            }
            }
    }
    fclose(f);
    
    return 0;
}
Ejemplo n.º 8
0
void bubbleSort1(int a[],int n){
	for(int i = n-1; i>0; i--){
		for(int j = 0; j<i; j++){
			if(a[j] > a[j+1]){
				swapint(&a[j],&a[j+1]);
			}
		}	
	}	
}
Ejemplo n.º 9
0
void bubbleSort2(int a[],int n){
	int flag = 1;
	for(int i = n-1; i>0&&flag; i--){
		flag = 0;
		for(int j = 0; j<i; j++){
			if(a[j] > a[j+1]){
				flag = 1;
				swapint(&a[j],&a[j+1]);
			}
		}	
	}
}
Ejemplo n.º 10
0
void decompile_sectors(char *map, wadfile_t *wf, FILE *fp)
{
	void		*sectors;
	sector_t	*s;
	int		size;
	int		i;

	if (verbose)
		printf("Decompiling sectors...\n");

	/* get the lump with the sectors for the map */
	if ((sectors = get_map_lump(wf, map, "SECTORS", &size)) == (void *)0) {
		fprintf(stderr, "can't find SECTORS lump for %s\n", map);
		exit(1);
	}
	
	/* write sectors start marker */
	fprintf(fp, " SECTORS_START\n");

	/* loop over all sectors in the lump and decompile */
	s = (sector_t *) sectors;
	for (i = 0; i < size / sizeof(sector_t); i++) {
		swapint(&s->f_height);
		swapint(&s->c_height);
		swapint(&s->light);
		swapint(&s->flags);
		swapint(&s->tag);
		fprintf(fp, "  S%d : %d %d", i, s->f_height, s->c_height);
		fprintf(fp, " %.8s", s->f_texture);
		fprintf(fp, " %.8s", s->c_texture);
		fprintf(fp, " %d %d %d\n", s->light, s->flags, s->tag);
		s++;
	}

	/* write sectors end marker */
	fprintf(fp, " SECTORS_END\n\n");

	/* free memory */
	free(sectors);
}
Ejemplo n.º 11
0
void bubbleSort3(int a[],int n){
	int flag = n;
	int k;
	for(int i = n-1; i>0&&flag; i--){
		k = flag;	
		flag = 0;
		for(int j = 0; j<i&&j<k; j++){
			if(a[j] > a[j+1]){
				flag = j;
				swapint(&a[j],&a[j+1]);
			}
		}	
	}
}
Ejemplo n.º 12
0
Archivo: netpkt.c Proyecto: btb/d1x
void receive_netgame_packet(ubyte *data, netgame_info *netgame, int d1x)
{
	int i, j;
	int loc = 0;
#ifndef SHAREWARE
	if (d1x) {
		receive_d1x_netgame_packet(data, netgame);
		return;
	}
#endif

	netgame->type = data[loc];	loc++;
	memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1);
	memcpy(netgame->team_name, &(data[loc]), 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
	netgame->gamemode = data[loc]; loc++;
	netgame->difficulty = data[loc]; loc++;
	netgame->game_status = data[loc]; loc++;
	netgame->numplayers = data[loc]; loc++;
	netgame->max_numplayers = data[loc]; loc++;
	netgame->game_flags = data[loc]; loc++;
	for (i = 0; i < MAX_PLAYERS; i++) {
		receive_netplayer_info(&(data[loc]), &(netgame->players[i]), 0);
		loc += NETPLAYER_ORIG_SIZE;
	}
#if 0
	if (d1x) {
		for (i = 0; i < MAX_PLAYERS; i++) {
			netgame->locations[i] = data[loc]; loc++;
		}
	} else
#endif
	{
		for (i = 0; i < MAX_PLAYERS; i++) {
			memcpy(&(netgame->locations[i]), &(data[loc]), 4); loc += 4;			// SWAP HERE!!!
			netgame->locations[i] = swapint(netgame->locations[i]);
		}
	}

	for (i = 0; i < MAX_PLAYERS; i++) {
		for (j = 0; j < MAX_PLAYERS; j++) {
			memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2;			// SWAP HERE!!!
			netgame->kills[i][j] = swapshort(netgame->kills[i][j]);
		}
	}

	memcpy(&(netgame->levelnum), &(data[loc]), 4); loc += 4;				// SWAP_HERE
	netgame->levelnum = swapint(netgame->levelnum);
	netgame->protocol_version = data[loc]; loc++;
	netgame->team_vector = data[loc]; loc++;
	memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2;				// SWAP_HERE
	netgame->segments_checksum = swapshort(netgame->segments_checksum);
	memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2;				// SWAP_HERE
	netgame->team_kills[0] = swapshort(netgame->team_kills[0]);
	memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2;				// SWAP_HERE
	netgame->team_kills[1] = swapshort(netgame->team_kills[1]);
	for (i = 0; i < MAX_PLAYERS; i++) {
		memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2;			// SWAP HERE!!!
		netgame->killed[i] = swapshort(netgame->killed[i]);
	}
	for (i = 0; i < MAX_PLAYERS; i++) {
		memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2;			// SWAP HERE!!!
		netgame->player_kills[i] = swapshort(netgame->player_kills[i]);
	}

#ifndef SHAREWARE
	memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4;				// SWAP_HERE
	netgame->level_time = swapint(netgame->level_time);
	memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4;				// SWAP_HERE
	netgame->control_invul_time = swapint(netgame->control_invul_time);
	memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4;				// SWAP_HERE
	netgame->monitor_vector = swapint(netgame->monitor_vector);
	for (i = 0; i < 8; i++) {
		memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4;				// SWAP_HERE
		netgame->player_score[i] = swapint(netgame->player_score[i]);
	}
	memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8;
#if 0
	for (i = 0; i < 8; i++) {
		memcpy(&(netgame->player_flags[i]), &(data[loc]), 1); loc++;
	}
#endif

	memcpy(netgame->mission_name, &(data[loc]), 9); loc += 9;
	memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1);
#if 0
	if (d1x && netgame->protocol_version == MULTI_PROTO_D1X_VER) {
	    netgame->packets_per_sec = data[loc]; loc++;
	    memcpy(&netgame->flags, &data[loc], 4); loc += 4;
	    netgame->flags = swapint(netgame->flags);
	}
#endif
#endif
}
Ejemplo n.º 13
0
void vms_vector_swap(vms_vector *v) {
	v->x = (fix)swapint((int)v->x);
	v->y = (fix)swapint((int)v->y);
	v->z = (fix)swapint((int)v->z);
}
Ejemplo n.º 14
0
Archivo: netpkt.c Proyecto: btb/d1x
void receive_d1x_netgame_packet(ubyte *data, netgame_info *netgame) {
	int i, j;
	int loc = 0;
	
	netgame->type = data[loc];	loc++;
	if (netgame->type == PID_D1X_GAME_LITE) {
		memset(netgame, 0, sizeof(netgame_info));
		netgame->type = PID_D1X_GAME_LITE;
	}
	netgame->protocol_version = data[loc]; loc++;
	netgame->subprotocol = data[loc]; loc++;
	netgame->required_subprotocol = data[loc]; loc++;
	memcpy(netgame->game_name, &(data[loc]), NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN;
	netgame->game_name[NETGAME_NAME_LEN] = 0;
	memcpy(netgame->mission_name, &(data[loc]), 8); loc += 8;
	netgame->mission_name[8] = 0;
	memcpy(netgame->mission_title, &(data[loc]), MISSION_NAME_LEN); loc += MISSION_NAME_LEN;
	netgame->mission_title[MISSION_NAME_LEN] = 0;
        netgame->levelnum = ((signed char *)data)[loc]; loc++;
	netgame->gamemode = data[loc]; loc++;
	netgame->difficulty = data[loc]; loc++;
	netgame->game_status = data[loc]; loc++;
	netgame->game_flags = data[loc]; loc++;
	netgame->max_numplayers = data[loc]; loc++;
	netgame->team_vector = data[loc]; loc++;
	if (netgame->type == PID_D1X_GAME_LITE) {
		j = netgame->numplayers = data[loc]; loc++;
		for (i = 0; i < j; i++)
			netgame->players[i].connected = 1;
		receive_netplayer_info(&(data[loc]), &(netgame->players[0]), 1);loc += NETPLAYER_D1X_SIZE;
		//added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them
		if (netgame->subprotocol>=1){
			memcpy(&netgame->flags, &data[loc], 4); loc += 4;
			netgame->flags = swapint(netgame->flags);
		}
		//end addition -MM
	} else {
		netgame->numplayers = data[loc]; loc++;
		j = data[loc]; loc++; // sizeof netplayer struct
		if (j > 29) { /* sanity: 304+29*8=536, just below IPX_MAX=542 */
		    netgame->protocol_version = 0; return;
		}
		for (i = 0; i < MAX_PLAYERS; i++) {
			receive_netplayer_info(&(data[loc]), &(netgame->players[i]), 1);
			loc += j;
		}
		memcpy(netgame->team_name[0], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN;
		netgame->team_name[0][CALLSIGN_LEN] = 0;
		memcpy(netgame->team_name[1], &(data[loc]), CALLSIGN_LEN); loc += CALLSIGN_LEN;
		netgame->team_name[1][CALLSIGN_LEN] = 0;
                for (i = 0; i < MAX_PLAYERS; i++) {
			netgame->locations[i] = data[loc]; loc++;
		}
		for (i = 0; i < MAX_PLAYERS; i++) {
			for (j = 0; j < MAX_PLAYERS; j++) {
				memcpy(&(netgame->kills[i][j]), &(data[loc]), 2); loc += 2;			// SWAP HERE!!!
				netgame->kills[i][j] = swapshort(netgame->kills[i][j]);
			}
		}
		memcpy(&(netgame->segments_checksum), &(data[loc]), 2); loc += 2;				// SWAP_HERE
		netgame->segments_checksum = swapshort(netgame->segments_checksum);
		memcpy(&(netgame->team_kills[0]), &(data[loc]), 2); loc += 2;				// SWAP_HERE
		netgame->team_kills[0] = swapshort(netgame->team_kills[0]);
		memcpy(&(netgame->team_kills[1]), &(data[loc]), 2); loc += 2;				// SWAP_HERE
		netgame->team_kills[1] = swapshort(netgame->team_kills[1]);
		for (i = 0; i < MAX_PLAYERS; i++) {
			memcpy(&(netgame->killed[i]), &(data[loc]), 2); loc += 2;			// SWAP HERE!!!
			netgame->killed[i] = swapshort(netgame->killed[i]);
		}
		for (i = 0; i < MAX_PLAYERS; i++) {
			memcpy(&(netgame->player_kills[i]), &(data[loc]), 2); loc += 2; 		// SWAP HERE!!!
			netgame->player_kills[i] = swapshort(netgame->player_kills[i]);
		}
		memcpy(&(netgame->level_time), &(data[loc]), 4); loc += 4;				// SWAP_HERE
		netgame->level_time = swapint(netgame->level_time);
		memcpy(&(netgame->control_invul_time), &(data[loc]), 4); loc += 4;				// SWAP_HERE
		netgame->control_invul_time = swapint(netgame->control_invul_time);
		memcpy(&(netgame->monitor_vector), &(data[loc]), 4); loc += 4;				// SWAP_HERE
		netgame->monitor_vector = swapint(netgame->monitor_vector);
		for (i = 0; i < 8; i++) {
			memcpy(&(netgame->player_score[i]), &(data[loc]), 4); loc += 4; 			// SWAP_HERE
			netgame->player_score[i] = swapint(netgame->player_score[i]);
		}
		memcpy(netgame->player_flags, &(data[loc]), 8); loc += 8;
		netgame->packets_per_sec = data[loc]; loc++;
		memcpy(&netgame->flags, &data[loc], 4); loc += 4;
		netgame->flags = swapint(netgame->flags);
	}
}
Ejemplo n.º 15
0
Archivo: netpkt.c Proyecto: btb/d1x
void send_d1x_netgame_packet(ubyte *server, ubyte *node)
{
	uint tmpi;
	ushort tmps;
	int i, j;
	int loc = 0;
	
	memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
	out_buffer[loc] = Netgame.type; loc++;
	out_buffer[loc] = MULTI_PROTO_D1X_VER; loc++;
	out_buffer[loc] = Netgame.subprotocol; loc++;
	out_buffer[loc] = Netgame.required_subprotocol; loc++;
	memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN); loc += NETGAME_NAME_LEN;
	memcpy(&(out_buffer[loc]), Netgame.mission_name, 8); loc += 8;
	memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN); loc += MISSION_NAME_LEN;
	out_buffer[loc] = Netgame.levelnum; loc++;
	out_buffer[loc] = Netgame.gamemode; loc++;
	out_buffer[loc] = Netgame.difficulty; loc++;
	out_buffer[loc] = Netgame.game_status; loc++;
	out_buffer[loc] = Netgame.game_flags; loc++;
	out_buffer[loc] = Netgame.max_numplayers; loc++;
	out_buffer[loc] = Netgame.team_vector; loc++;
	if (Netgame.type == PID_D1X_GAME_LITE) {
		int master = -1;
		j = 0;
		for (i = 0; i < Netgame.numplayers; i++)
			if (Players[i].connected) {
				if (master == -1)
					master = i;
				j++;
			}
		out_buffer[loc] = j; loc++; /* numconnected */
		if (master == -1)   /* should not happen, but... */
			master = Player_num; 
		store_netplayer_info(&(out_buffer[loc]), &Netgame.players[master], 1); loc += NETPLAYER_D1X_SIZE;
		//added 4/18/99 Matt Mueller - send .flags as well, so 'I' can show them
		tmpi = swapint(Netgame.flags);
		memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
		//end addition -MM
	} else {
		out_buffer[loc] = Netgame.numplayers; loc++;
		out_buffer[loc] = NETPLAYER_D1X_SIZE; loc++; // sizeof netplayer struct
		for (i = 0; i < MAX_PLAYERS; i++) {
			store_netplayer_info(&(out_buffer[loc]), &Netgame.players[i], 1);
			loc += NETPLAYER_D1X_SIZE;
		}
		memcpy(&(out_buffer[loc]), Netgame.team_name[0], CALLSIGN_LEN); loc += CALLSIGN_LEN;
		memcpy(&(out_buffer[loc]), Netgame.team_name[1], CALLSIGN_LEN); loc += CALLSIGN_LEN;
		for (i = 0; i < MAX_PLAYERS; i++) {
			out_buffer[loc] = Netgame.locations[i]; loc++;
		}
		for (i = 0; i < MAX_PLAYERS; i++) {
			for (j = 0; j < MAX_PLAYERS; j++) {
				tmps = swapshort(Netgame.kills[i][j]);
				memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 	// SWAP HERE!!!
			}
		}
		tmps = swapshort(Netgame.segments_checksum);
		memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 			// SWAP_HERE
		tmps = swapshort(Netgame.team_kills[0]);
		memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 			// SWAP_HERE
		tmps = swapshort(Netgame.team_kills[1]);
		memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 			// SWAP_HERE
		for (i = 0; i < MAX_PLAYERS; i++) {
			tmps = swapshort(Netgame.killed[i]);
			memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 		// SWAP HERE!!!
		}
		for (i = 0; i < MAX_PLAYERS; i++) {
			tmps = swapshort(Netgame.player_kills[i]);
			memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2; 		// SWAP HERE!!!
		}
		tmpi = swapint(Netgame.level_time);
		memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; 			// SWAP_HERE
		tmpi = swapint(Netgame.control_invul_time);
		memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; 			// SWAP_HERE
		tmpi = swapint(Netgame.monitor_vector);
		memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; 			// SWAP_HERE
		for (i = 0; i < 8; i++) {
			tmpi = swapint(Netgame.player_score[i]);
			memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; 			// SWAP_HERE
		}
		memcpy(&(out_buffer[loc]), Netgame.player_flags, MAX_PLAYERS); loc += MAX_PLAYERS;
		out_buffer[loc] = Netgame.packets_per_sec; loc++;
		tmpi = swapint(Netgame.flags);
		memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
	}

	if (server == NULL)
		ipx_send_broadcast_packet_data(out_buffer, loc);
	else
		ipx_send_internetwork_packet_data(out_buffer, loc, server, node);
}
Ejemplo n.º 16
0
void decompile_linedefs(char *map, wadfile_t *wf, FILE *fp)
{
	void		*lines;
	void		*sdefs;
	linedef_t	*l1;
	linedef2_t	*l2;
	sidedef_t	*s;
	int		size;
	int		size_sd;
	int		i;

	if (verbose)
		printf("Decompiling linedefs...\n");

	/* get the lump with the linedefs for the map */
	if ((lines = get_map_lump(wf, map, "LINEDEFS", &size)) == (void *)0) {
		fprintf(stderr, "can't find LINEDEFS lump for %s\n", map);
		exit(1);
	}

	/* and we need the sidedefs too... */
	if ((sdefs = get_map_lump(wf, map, "SIDEDEFS", &size_sd)) == (void *)0) {
		fprintf(stderr, "can't find SIDEDEFS lump for %s\n", map);
		exit(1);
	}
        
        /* 14 sep 99 Oliver Kraus */
        /* convert sidedefs before the linedef loop */
        /* this will fix a bug in the sparc port */

#ifdef BIGEND        
        s = (sidedef_t *)sdefs;
        for (i = 0; i < size_sd/sizeof(sidedef_t); i++, s++ )
        {
		swapint(&s->x);
		swapint(&s->y);
		swapint(&s->sector);
	}
#endif 
	
	/* write linedefs start marker */
	fprintf(fp, " LINEDEFS_START\n");

	if (!has_behavior)
	{
	    /* Doom or Doom2 map */

	    /* loop over all linedefs in the lump and decompile */
	    l1 = (linedef_t *) lines;
	    for (i = 0; i < size / sizeof(linedef_t); i++, l1++) {

		/* the linedef self */
		swapint(&l1->v_from);
		swapint(&l1->v_to);
		swapint(&l1->flags);
		swapint(&l1->type);
		swapint(&l1->tag);
		swapint(&l1->r_side);
		swapint(&l1->l_side);
		fprintf(fp, "  V%d V%d : %d %d %d\n", l1->v_from, l1->v_to,
			l1->flags, l1->type, l1->tag);

		/* right sidedef */
		s = (sidedef_t *)sdefs + l1->r_side;
                /* do NOT swap sidedef values here
		swapint(&s->x);
		swapint(&s->y);
		swapint(&s->sector);
                */
		fprintf(fp, "   S%d %d %d", s->sector, s->x, s->y);
		fprintf(fp, " %.8s", s->u_texture);
		fprintf(fp, " %.8s", s->l_texture);
		fprintf(fp, " %.8s\n", s->m_texture);

		/* left sidedef */
		if (l1->l_side == -1)
		  fprintf(fp, "   -\n");
		else {
		  s = (sidedef_t *)sdefs + l1->l_side;
                  /* do NOT swap sidedef values here
		  swapint(&s->x);
		  swapint(&s->y);
		  swapint(&s->sector);
                  */
		  fprintf(fp, "   S%d %d %d", s->sector, s->x, s->y);
		  fprintf(fp, " %.8s", s->u_texture);
		  fprintf(fp, " %.8s", s->l_texture);
		  fprintf(fp, " %.8s\n", s->m_texture);
		}
	    }

	}  else {

	    /* Hexen or ZDoom map */

	    /* loop over all linedefs in the lump and decompile */
	    l2 = (linedef2_t *) lines;
	    for (i = 0; i < size / sizeof(linedef2_t); i++, l2++) {

		/* the linedef self */
		swapint(&l2->v_from);
		swapint(&l2->v_to);
		swapint(&l2->flags);
		swapint(&l2->r_side);
		swapint(&l2->l_side);
		fprintf(fp, "  V%d V%d : %d %d %d %d %d %d %d\n",
			l2->v_from, l2->v_to, l2->flags, l2->type,
			l2->arg1, l2->arg2, l2->arg3, l2->arg4,
			l2->arg5);

		/* right sidedef */
		s = (sidedef_t *)sdefs + l2->r_side;
                /* do NOT swap sidedef values here
		swapint(&s->x);
		swapint(&s->y);
		swapint(&s->sector);
                */
		fprintf(fp, "   S%d %d %d", s->sector, s->x, s->y);
		fprintf(fp, " %.8s", s->u_texture);
		fprintf(fp, " %.8s", s->l_texture);
		fprintf(fp, " %.8s\n", s->m_texture);

		/* left sidedef */
		if (l2->l_side == -1)
		  fprintf(fp, "   -\n");
		else {
		  s = (sidedef_t *)sdefs + l2->l_side;
                  /* do NOT swap sidedef values here
		  swapint(&s->x);
		  swapint(&s->y);
		  swapint(&s->sector);
                  */
		  fprintf(fp, "   S%d %d %d", s->sector, s->x, s->y);
		  fprintf(fp, " %.8s", s->u_texture);
		  fprintf(fp, " %.8s", s->l_texture);
		  fprintf(fp, " %.8s\n", s->m_texture);
		}
	    }
	}

	/* write linedefs end marker */
	fprintf(fp, " LINEDEFS_END\n\n");

	/* free memory */
	free(lines);
	free(sdefs);
}
Ejemplo n.º 17
0
static	int	dolock( char *path, int lockopt )
{
   char	dirc[FILENAME_MAX];			/* the directory */
   char	name[FILENAME_MAX];			/* the name */
   int	close( );
   int	s;
   int	r;
   int	ibuf[3];				/* to server */
   int	obuf[2];				/* from server */

   r = split( path, dirc, name );		/* split */
   if ( r ) return( r );			/* error */
   s = contact( dirc );				/* contact lckserver */
   if ( s < 0 ) return( s );			/* error */
   ibuf[0] = 1; ibuf[1] = lockopt; ibuf[2] = strlen( name );
   if ( put( mylock[s].sock, ibuf, sizeof( ibuf ) ) ) {
      close( mylock[s].sock );			/* error */
      mylock[s].locks = 0;
      return( GLOCK_ERROR_SERVERDEAD );
   }
   if ( put( mylock[s].sock, name, strlen( name ) ) ) {
      close( mylock[s].sock );			/* error */
      mylock[s].locks = 0;
      return( GLOCK_ERROR_SERVERDEAD );
   }
   if ( get( mylock[s].sock, obuf, sizeof( obuf ) ) ) {
      close( mylock[s].sock );			/* error */
      mylock[s].locks = 0;
      return( GLOCK_ERROR_SERVERDEAD );
   }
   if ( obuf[0] != 1 ) swapint( obuf, 2 );	/* swap bytes */
   if ( obuf[0] != 1 ) {
      close( mylock[s].sock );			/* error */
      mylock[s].locks = 0;
      return( GLOCK_ERROR_SERVERBAD );
   }
   switch( obuf[1] ) {				/* what happened ? */
      case GLOCK_LOCK: {			/* we got a lock */
         mylock[s].locks += 1;
         break;
      }
      case GLOCK_NOLOCK: {			/* there was no lock */
         r = GLOCK_ERROR_NOTLOCKED;
         break;
      }
      case GLOCK_ONLOCK: {			/* was already locked */
         r = GLOCK_ERROR_WASLOCKED;
         break;
      }
      case GLOCK_UNLOCK: {			/* removed lock */
         mylock[s].locks -= 1;
         if ( !mylock[s].locks ) {		/* disconnect from server */
            ibuf[0] = 1; ibuf[1] = GLOCK_DISCONNECT; ibuf[2] = 0;
            put( mylock[s].sock, ibuf, sizeof( ibuf ) );
            close( mylock[s].sock );
         }
         break;
      }
      case GLOCK_ILLEGAL: {			/* we did something wrong */
         r = GLOCK_ERROR_CLIENTBAD;
         break;
      }
      default: {				/* ??? */
         r = GLOCK_ERROR_UNKNOWN;
         break;
      }
   }
   return( r );
}
Ejemplo n.º 18
0
/*
 *  Routine to remove a tag from the tree given its tag index
 */
static void _RemoveTagIdx(PINO_DATABASE  *dblist, int tagidx)
{
  TAG_INFO *info_ptr, *remove_info_ptr;
  NODE     *node_ptr;
  int      *tags_ptr, *this_tags_ptr;

  /****************************************
   First we must remove the linked list of
   tag info blocks connected to the node via
   tag links.
  *****************************************/

    remove_info_ptr = dblist->tree_info->tag_info + tagidx - 1;
    node_ptr = dblist->tree_info->node + swapint((char *)&remove_info_ptr->node_idx);
    if (swapint((char *)&node_ptr->tag_link) == tagidx)
      node_ptr->tag_link = remove_info_ptr->tag_link;
    else
    {
      int tag_link;
      for (tag_link = swapint((char *)&node_ptr->tag_link), info_ptr = dblist->tree_info->tag_info + tag_link - 1;
           (swapint((char *)&info_ptr->tag_link) != tagidx) && (swapint((char *)&info_ptr->tag_link) >= 0);
           info_ptr = dblist->tree_info->tag_info + swapint((char *)&info_ptr->tag_link) - 1);
      if (swapint((char *)&info_ptr->tag_link) == tagidx)
        info_ptr->tag_link = remove_info_ptr->tag_link;
    }

  /*********************************************
   Next we will fix up all the tag links in the
   tree. Those links pointing to tags following
   the tag to be removed will be decremented by
   one. Both node tag links and tag info tag links
   must be corrected.
  ************************************************/

  for (info_ptr = dblist->tree_info->tag_info;
       info_ptr < dblist->tree_info->tag_info + dblist->tree_info->header->tags; 
       info_ptr++)
      if (swapint((char *)&info_ptr->tag_link) >= tagidx)
      {
        int tmp = swapint((char *)&info_ptr->tag_link)-1;
	info_ptr->tag_link = swapint((char *)&tmp);
      }
    for (node_ptr = dblist->tree_info->node;
	 node_ptr < dblist->tree_info->node + dblist->tree_info->header->nodes; 
	 node_ptr++)
      if (swapint((char *)&node_ptr->tag_link) >= tagidx)
      {
        int tmp = swapint((char *)&node_ptr->tag_link) - 1;
	node_ptr->tag_link = swapint((char *)&tmp);
      }

  /*************************************************
    Next we must fix up all the tag index pointers
    much the same way as the tag links above.
  **************************************************/

    for (tags_ptr = dblist->tree_info->tags;
	 tags_ptr < dblist->tree_info->tags + dblist->tree_info->header->tags; 
	 tags_ptr++)
    {
      int tags = swapint((char *)tags_ptr);
      if (tags == (tagidx-1)) this_tags_ptr = tags_ptr;
      if (tags >= tagidx)
      {
        tags--;
        *tags_ptr = swapint((char *)&tags);
      }
    }

  /*******************************************
   Finally we need to move all the tag indexes
   and tag info blocks to fill in the hole left
   by the removed tag and then decrement the
   total tag count.
  ********************************************/
    if (dblist->tree_info->header->tags > 0) {
      int bytes;
      if( (bytes = (dblist->tree_info->header->tags - (this_tags_ptr - dblist->tree_info->tags)) * sizeof(int)) > 0) 
	memcpy(this_tags_ptr, this_tags_ptr+1, bytes);
      if( (bytes = (dblist->tree_info->header->tags - tagidx) * sizeof(TAG_INFO)) > 0) 
	memcpy(&dblist->tree_info->tag_info[tagidx-1], &dblist->tree_info->tag_info[tagidx], bytes);
    }
    dblist->tree_info->header->tags--;
    dblist->modified = 1;
}
Ejemplo n.º 19
0
int main( int argc, char **argv )
{
    int i;
    int retval = 0;
    int nread;
    ssize_t errval;
    ssize_t raster_offset;
    pixelval_t **raster;
    long long sum;
    ssize_t ix, iy;
    long long linesum;

    progname = argv[0];

    if( argc > 1 ) {
	for( i = 1; i < argc; i++ ) {
	    struct RigakuHeader header;
	    FILE *in = fopen( argv[i], "r" );
	    if( !in ) {
		fprintf( stderr, "%s: %s: ERROR, can not open file "
			 "'%s' for input - %s\n", progname, argv[i],
			 argv[i], strerror(errno) );
		retval = 1;
		continue;
	    }
	    nread = fread( &header, sizeof(header), 1, in );
	    if( nread != 1 ) {
		fprintf( stderr, "%s: %s: ERROR, failed to read "
			 "%d bytes from the file\n", progname, argv[i],
			 sizeof(header));
		retval = 2;
		fclose( in );
		continue;
	    }

	    swapint( &header.xpxl, 1 );
	    swapint( &header.zpxl, 1 );

	    printf( "X size = %d\n", header.xpxl );
	    printf( "Y size = %d\n", header.zpxl );

	    raster = alloc_matrix( header.xpxl, header.zpxl );

	    if( !raster ) {
		fprintf( stderr, "%s: %s: ERROR, failed to allocate "
			 "raster %d x %d\n", progname, argv[i],
			 header.xpxl, header.zpxl );
		retval = 3;
		fclose( in );
		continue;		
	    }

	    raster_offset = header.xpxl * 2;

	    if( (errval = load_raster( in, raster, header.xpxl, header.zpxl,
				       raster_offset )) != 0 ) {
		fprintf( stderr, "%s: %s: ERROR, could not read "
			 "raster %d x %d at line %d - %s\n", progname, argv[i],
			 header.xpxl, header.zpxl, errval,
			 errno == 0 ? "file too short" : strerror(errno));
		retval = 3;
		fclose( in );
		continue;		
	    }

	    printf( "%d %d %d\n", raster[0][0], raster[0][1], raster[0][2] );
	    printf( "%d %d %d\n",
		    raster[100][100], raster[100][101], raster[100][102] );

	    sum = 0;
	    for( ix = 0; ix < header.xpxl; ix ++ ) {
		linesum = 0;
		for( iy = 0; iy < header.zpxl; iy ++ ) {
		    linesum += (int)(raster[ix][iy]);
		}
		sum += linesum;
	    }
	    printf( "%s: pixel sum %lld\n", argv[i], sum );
	    printf( "%s: number of pixels %d\n", argv[i],
		    header.xpxl * header.zpxl );
	    printf( "%s: average pixel value %g\n", argv[i],
		    (double)sum / (double)(header.xpxl * header.zpxl) );

	    free_matrix( raster, header.xpxl );
	    fclose( in );
	}
    } else {
	fprintf( stderr, "%s: WARNING, no file names provided "
		 "on the command line\n", progname );
    }

    return retval;
}
Ejemplo n.º 20
0
void decompile(wadfile_t *wf, int num)
{
  	char		name[9];
	unsigned char	*sprite;
	short		width;
	short		height;
	short		xoff;
	short		yoff;
	short		*p1;
	int		*columns;
	unsigned char	*post;
	int		x;
	int		y;
	int		n;
	int		i;

	name[0] = '\0';
	strncat(name, wf->lp->lumps[num]->name, 8);

	/* get sprite lump */
	if ((sprite = (unsigned char *)get_lump_by_num(wf, num)) == NULL) {
		fprintf(stderr, "can't find sprite lump %s\n", name);
		exit(1);
	}

	/* clear the pixel buffer */
	memset(img_buf, 255, 320 * 200);

	/* get width, height and offsets from the lump header */
	p1 = (short *) sprite;
	width = *p1++;
	swapint(&width);
	height = *p1++;
	swapint(&height);
	xoff = *p1++;
	swapint(&xoff);
	yoff = *p1++;
	swapint(&yoff);
	
	printf("  got sprite %s, width=%d, height=%d\n", name,
		width, height);

	/* copy picture data into pixel buffer */
	columns = (int *) (sprite + 8);
	for (x = 0; x < width; x++) {
	  swaplong(&columns);
	  post = sprite + *columns++;
	  y = (int) *post++;
	  while (y != 255) {
	    n = (int) *post++;
	    post++;	/* first byte unused */
	    for (i = 0; i < n; i++) {
		img_buf[(y+i) * width + x] = *post;
		post++;
	    }
	    post++;	/* last byte unused */
	    y = (int) *post++;
	  }
	}

	/* free sprite lump memory */
	free(sprite);

	/* write image buffer into ppm file */
	write_ppm(name, width, height);
}
Ejemplo n.º 21
0
Archivo: netpkt.c Proyecto: btb/d1x
void send_frameinfo_packet(ubyte *server, ubyte *node, ubyte *address, int short_packet)
{
	int loc, tmpi;
	short tmps;
#ifndef SHAREWARE
	ushort tmpus;
#endif
	object *pl_obj = &Objects[Players[Player_num].objnum];
	
	loc = 0;
	memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
#ifdef SHAREWARE
	out_buffer[0] = PID_PDATA;		loc++;
	tmpi = swapint(MySyncPack.numpackets);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmps = swapshort(Players[Player_num].objnum);
	memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;
	out_buffer[loc] = Player_num; loc++;
	tmps = swapshort(pl_obj->segnum);
	memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;

	tmpi = swapint((int)pl_obj->pos.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->pos.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->pos.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	
	tmpi = swapint((int)pl_obj->orient.rvec.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.rvec.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.rvec.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.uvec.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.uvec.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.uvec.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.fvec.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.fvec.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->orient.fvec.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	
	tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.thrust.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.mass);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.drag);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.brakes);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.x);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.y);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmpi = swapint((int)pl_obj->mtype.phys_info.rotthrust.z);
	memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
	tmps = swapshort((short)pl_obj->mtype.phys_info.turnroll);
	memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;
	tmps = swapshort(pl_obj->mtype.phys_info.flags);
	memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;
	
	out_buffer[loc] = pl_obj->render_type; loc++;
	out_buffer[loc] = Current_level_num; loc++;
	tmps = swapshort(MySyncPack.data_size);
	memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;
	memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size);
	loc += MySyncPack.data_size;
#else
	if (short_packet == 1) {
		loc = 0;
		out_buffer[loc] = PID_SHORTPDATA; loc++;
		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);
                loc += 9+2*3+2+2*3; // go past shortpos structure
                *(ushort *)(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);
                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;
                out_buffer[loc] = Current_level_num; loc++;
                memcpy(out_buffer + loc, MySyncPack.data, MySyncPack.data_size);
                loc += MySyncPack.data_size;
	} else {
		out_buffer[0] = PID_PDATA;		loc++;	loc += 3;		// skip three for pad byte
		tmpi = swapint(MySyncPack.numpackets);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;

		tmpi = swapint((int)pl_obj->pos.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->pos.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->pos.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;

		tmpi = swapint((int)pl_obj->orient.rvec.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.rvec.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.rvec.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.uvec.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.uvec.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.uvec.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.fvec.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.fvec.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->orient.fvec.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;

		tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->mtype.phys_info.velocity.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;

		tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.x);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.y);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;
		tmpi = swapint((int)pl_obj->mtype.phys_info.rotvel.z);
		memcpy(&(out_buffer[loc]), &tmpi, 4);	loc += 4;

		tmps = swapshort(pl_obj->segnum);
		memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;
		tmps = swapshort(MySyncPack.data_size);
		memcpy(&(out_buffer[loc]), &tmps, 2);	loc += 2;

		out_buffer[loc] = Player_num; loc++;
		out_buffer[loc] = pl_obj->render_type; loc++;
		out_buffer[loc] = Current_level_num; loc++;
		memcpy(&(out_buffer[loc]), MySyncPack.data, MySyncPack.data_size);
		loc += MySyncPack.data_size;
	}
#endif
#if 0 // adb: not possible (always array passed)
	if (address == NULL)
                ipx_send_internetwork_packet_data( out_buffer, loc, server, node );
	else
#endif
		ipx_send_packet_data( out_buffer, loc, server, node, address);
}
Ejemplo n.º 22
0
char *_TreeFindTagWild(void *dbid, char *wild, int *nidout, void **ctx_inout)
{
    PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
    /***************************
      check that there is a tree
      open.
     ****************************/
    if (!IS_OPEN(dblist))
        return NULL;
    if (dblist->remote)
        return FindTagWildRemote(dblist,wild,nidout,ctx_inout);
    else
    {
        NID *nid_ptr = (NID *)nidout;
        TAG_SEARCH **ctx = (TAG_SEARCH **)ctx_inout;
        int       status = 1;
        unsigned char found,done;
        static char answer[128];

        /**********************************
        If this is the first time then
        allocate a context block and fill
        it in with a parse of the tagname.
        ***********************************/
        if (*ctx == (TAG_SEARCH *) 0)
        {
            *ctx = NewTagSearch(wild);
            if (*ctx == (TAG_SEARCH *) 0)
                status = TreeNMT;
            else
                status = NextTagTree(dblist, *ctx);
        }

        /*************************************
         Loop looking for a tag that matches
        **************************************/
        for (found = 0, done = 0; (status & 1) && !found && !done;)
        {

            /*************************************
              if out of tags in this tree then
              see if there is another one
            **************************************/
            if ((*ctx)->next_tag >= (*ctx)->this_tree_info->header->tags)
            {
                status = NextTagTree(dblist, *ctx);
                if (status & 1)
                    (*ctx)->next_tag = -1;
                else
                {
                    done = 1;
                    break;
                }
            }
            else
            {

                /**********************************************
                  else if this is the first time for this tree
                try to return the \TOP tag.
                otherwise - move on to next tag for next
                time through the loop.
                ***********************************************/
                if ((*ctx)->next_tag == -1)
                {
                    if ((*ctx)->top_match)
                    {
                        done = 1;
                        found = 1;
                    }
                    else
                        ((*ctx)->next_tag)++;
                }
                else
                {

                    /****************************************
                    Else
                       loop looking for a tag that matches
                        *****************************************/
                    for (; !done && ((*ctx)->next_tag < (*ctx)->this_tree_info->header->tags);)
                    {
                        unsigned short len;
                        static struct descriptor_s s_tag_dsc = { sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0};
                        static struct descriptor_d tag_dsc = {0, DTYPE_T, CLASS_D, 0};
                        s_tag_dsc.pointer =
                            (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name;
                        StrTrim(&tag_dsc, &s_tag_dsc,&len);
                        if (StrMatchWild(&tag_dsc, &((*ctx)->search_tag)) & 1)
                        {
                            done = 1;
                            found = 1;
                        }
                        else
                            ((*ctx)->next_tag)++;
                    }
                }
            }
        }
        /********************************************
          If done and found then fill in the answer
        *********************************************/
        if (found)
        {
            NODE     *nptr = (*ctx)->this_tree_info->node;
            static char tagname[sizeof(TAG_NAME)+1];
            if ((*ctx)->next_tag != -1)
            {
                static struct descriptor_s s_tag_name = {sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0};
                static struct descriptor_s tag_name =  {sizeof(TAG_NAME), DTYPE_T, CLASS_S, tagname};
                unsigned short len;
                s_tag_name.pointer =
                    (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name;
                StrTrim(&tag_name, &s_tag_name,&len);
                tagname[len]='\0';
                nptr += swapint(&(*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].node_idx);
            }
            else
                strcpy(tagname,"TOP");
            strcpy(answer,"\\");
            strcat(answer,(*ctx)->this_tree_info->treenam);
            strcat(answer,"::");
            strcat(answer,tagname);
            if (nid_ptr)
                node_to_nid(dblist, nptr, nid_ptr);
            ((*ctx)->next_tag)++;
            status = 1;
        }
        else
        {
            TreeFindTagEnd(ctx_inout);
            status = TreeNMT;
        }
        return (status & 1) ? answer : NULL;
    }
}
Ejemplo n.º 23
0
Archivo: netpkt.c Proyecto: btb/d1x
void receive_frameinfo_packet(ubyte *data, frame_info *info, int short_packet)
{
	int loc;
	
#ifdef SHAREWARE
	loc = 0;

	info->type = data[0];							loc++;
	memcpy(&(info->numpackets), &(data[loc]), 4);	loc += 4;
	info->numpackets = swapint(info->numpackets);
	memcpy(&(info->objnum), &(data[loc]), 2);		loc += 2;
	info->objnum = swapshort(info->objnum);
	info->playernum = data[loc];					loc++;

	memcpy(&(info->obj_segnum), &(data[loc]), 2);	loc += 2;
	info->obj_segnum = swapshort(info->obj_segnum);

	memcpy(&(info->obj_pos.x), &(data[loc]), 4);	loc += 4;
	info->obj_pos.x = (fix)swapint((int)info->obj_pos.x);
	memcpy(&(info->obj_pos.y), &(data[loc]), 4);	loc += 4;
	info->obj_pos.y = (fix)swapint((int)info->obj_pos.y);
	memcpy(&(info->obj_pos.z), &(data[loc]), 4);	loc += 4;
	info->obj_pos.z = (fix)swapint((int)info->obj_pos.z);

	memcpy(&(info->obj_orient.rvec.x), &(data[loc]), 4);	loc += 4;
	info->obj_orient.rvec.x = (fix)swapint((int)info->obj_orient.rvec.x);
	memcpy(&(info->obj_orient.rvec.y), &(data[loc]), 4);	loc += 4;
	info->obj_orient.rvec.y = (fix)swapint((int)info->obj_orient.rvec.y);
	memcpy(&(info->obj_orient.rvec.z), &(data[loc]), 4);	loc += 4;
	info->obj_orient.rvec.z = (fix)swapint((int)info->obj_orient.rvec.z);
	memcpy(&(info->obj_orient.uvec.x), &(data[loc]), 4);	loc += 4;
	info->obj_orient.uvec.x = (fix)swapint((int)info->obj_orient.uvec.x);
	memcpy(&(info->obj_orient.uvec.y), &(data[loc]), 4);	loc += 4;
	info->obj_orient.uvec.y = (fix)swapint((int)info->obj_orient.uvec.y);
	memcpy(&(info->obj_orient.uvec.z), &(data[loc]), 4);	loc += 4;
	info->obj_orient.uvec.z = (fix)swapint((int)info->obj_orient.uvec.z);
	memcpy(&(info->obj_orient.fvec.x), &(data[loc]), 4);	loc += 4;
	info->obj_orient.fvec.x = (fix)swapint((int)info->obj_orient.fvec.x);
	memcpy(&(info->obj_orient.fvec.y), &(data[loc]), 4);	loc += 4;
	info->obj_orient.fvec.y = (fix)swapint((int)info->obj_orient.fvec.y);
	memcpy(&(info->obj_orient.fvec.z), &(data[loc]), 4);	loc += 4;
	info->obj_orient.fvec.z = (fix)swapint((int)info->obj_orient.fvec.z);
	
	memcpy(&(info->obj_phys_info.velocity.x), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.velocity.x = (fix)swapint((int)info->obj_phys_info.velocity.x);
	memcpy(&(info->obj_phys_info.velocity.y), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.velocity.y = (fix)swapint((int)info->obj_phys_info.velocity.y);
	memcpy(&(info->obj_phys_info.velocity.z), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.velocity.z = (fix)swapint((int)info->obj_phys_info.velocity.z);

	memcpy(&(info->obj_phys_info.thrust.x), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.thrust.x = (fix)swapint((int)info->obj_phys_info.thrust.x);
	memcpy(&(info->obj_phys_info.thrust.y), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.thrust.y = (fix)swapint((int)info->obj_phys_info.thrust.y);
	memcpy(&(info->obj_phys_info.thrust.z), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.thrust.z = (fix)swapint((int)info->obj_phys_info.thrust.z);

	memcpy(&(info->obj_phys_info.mass), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.mass = (fix)swapint((int)info->obj_phys_info.mass);
	memcpy(&(info->obj_phys_info.drag), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.drag = (fix)swapint((int)info->obj_phys_info.drag);
	memcpy(&(info->obj_phys_info.brakes), &(data[loc]), 4); loc += 4;
	info->obj_phys_info.brakes = (fix)swapint((int)info->obj_phys_info.brakes);

	memcpy(&(info->obj_phys_info.rotvel.x), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotvel.x = (fix)swapint((int)info->obj_phys_info.rotvel.x);
	memcpy(&(info->obj_phys_info.rotvel.y), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotvel.y = (fix)swapint((int)info->obj_phys_info.rotvel.y);
	memcpy(&(info->obj_phys_info.rotvel.z), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotvel.z = (fix)swapint((int)info->obj_phys_info.rotvel.z);

	memcpy(&(info->obj_phys_info.rotthrust.x), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotthrust.x = (fix)swapint((int)info->obj_phys_info.rotthrust.x);
	memcpy(&(info->obj_phys_info.rotthrust.y), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotthrust.y = (fix)swapint((int)info->obj_phys_info.rotthrust.y);
	memcpy(&(info->obj_phys_info.rotthrust.z), &(data[loc]), 4);	loc += 4;
	info->obj_phys_info.rotthrust.z = (fix)swapint((int)info->obj_phys_info.rotthrust.z);

	memcpy(&(info->obj_phys_info.turnroll), &(data[loc]), 2);	loc += 2;
	info->obj_phys_info.turnroll = (fixang)swapshort((short)info->obj_phys_info.turnroll);

	memcpy(&(info->obj_phys_info.flags), &(data[loc]), 2);	loc += 2;
	info->obj_phys_info.flags = (ushort)swapshort(info->obj_phys_info.flags);

	info->obj_render_type = data[loc];		loc++;
	info->level_num = data[loc];			loc++;	
	memcpy( &(info->data_size), &(data[loc]), 2);	loc += 2;
	info->data_size = swapshort(info->data_size);
	memcpy(info->data, &(data[loc]), info->data_size);
#else
	if (short_packet == 1) {
		loc = 0;
                info->type = data[loc]; loc++;
                info->playernum = data[loc]; loc++;
                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;
                memcpy(info->data, &(data[loc]), info->data_size);
        } else if (short_packet == 2) {
		ushort tmpus;

                loc = 0;
                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;
                info->data_size = tmpus & 0xfff;
                info->playernum = (tmpus >> 12) & 7;
                info->obj_render_type = tmpus >> 15;
                info->numpackets |= Players[info->playernum].n_packets_got & (~255);
                if (info->numpackets - Players[info->playernum].n_packets_got > 224)
                        info->numpackets -= 256;
                else if (Players[info->playernum].n_packets_got - info->numpackets > 128)
                        info->numpackets += 256;
                info->level_num = data[loc];    loc++;
                memcpy(info->data, &(data[loc]), info->data_size);
	} else {
Ejemplo n.º 24
0
Archivo: netpkt.c Proyecto: btb/d1x
void send_netgame_packet(ubyte *server, ubyte *node)
{
	uint tmpi;
	ushort tmps;
	int i, j;
	int loc = 0;
	
#ifndef SHAREWARE
	if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) {
		send_d1x_netgame_packet(server, node);
		return;
	}
#endif
	memset(out_buffer, 0, IPX_MAX_DATA_SIZE);
	out_buffer[loc] = Netgame.type; loc++;
	memcpy(&(out_buffer[loc]), Netgame.game_name, NETGAME_NAME_LEN+1); loc += (NETGAME_NAME_LEN+1);
	memcpy(&(out_buffer[loc]), Netgame.team_name, 2*(CALLSIGN_LEN+1)); loc += 2*(CALLSIGN_LEN+1);
	out_buffer[loc] = Netgame.gamemode; loc++;
	out_buffer[loc] = Netgame.difficulty; loc++;
	out_buffer[loc] = Netgame.game_status; loc++;
	out_buffer[loc] = Netgame.numplayers; loc++;
	out_buffer[loc] = Netgame.max_numplayers; loc++;
	out_buffer[loc] = Netgame.game_flags; loc++;
	for (i = 0; i < MAX_PLAYERS; i++) {
		memcpy(&(out_buffer[loc]), Netgame.players[i].callsign, CALLSIGN_LEN+1);	loc += CALLSIGN_LEN+1;
		memcpy(&(out_buffer[loc]), Netgame.players[i].server, 4);				  loc += 4;
		memcpy(&(out_buffer[loc]), Netgame.players[i].node, 6); 					  loc += 6;
		memcpy(&(out_buffer[loc]), &(Netgame.players[i].socket), 2);				  loc += 2;
		memcpy(&(out_buffer[loc]), &(Netgame.players[i].connected), 1);				loc++;
	}
	if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) {
		for (i = 0; i < MAX_PLAYERS; i++) {
			out_buffer[loc] = Netgame.locations[i]; loc++;
		}
	} else {
		for (i = 0; i < MAX_PLAYERS; i++) {
			tmpi = swapint(Netgame.locations[i]);
			memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4; 		// SWAP HERE!!!
		}
	}

	for (i = 0; i < MAX_PLAYERS; i++) {
		for (j = 0; j < MAX_PLAYERS; j++) {
			tmps = swapshort(Netgame.kills[i][j]);
			memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;			// SWAP HERE!!!
		}
	}

	tmpi = swapint(Netgame.levelnum);
	memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;				// SWAP_HERE
	out_buffer[loc] = Netgame.protocol_version; loc++;
	out_buffer[loc] = Netgame.team_vector; loc++;
	tmps = swapshort(Netgame.segments_checksum);
	memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;				// SWAP_HERE
	tmps = swapshort(Netgame.team_kills[0]);
	memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;				// SWAP_HERE
	tmps = swapshort(Netgame.team_kills[1]);
	memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;				// SWAP_HERE
	for (i = 0; i < MAX_PLAYERS; i++) {
		tmps = swapshort(Netgame.killed[i]);
		memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;			// SWAP HERE!!!
	}
	for (i = 0; i < MAX_PLAYERS; i++) {
		tmps = swapshort(Netgame.player_kills[i]);
		memcpy(&(out_buffer[loc]), &tmps, 2); loc += 2;			// SWAP HERE!!!
	}

#ifndef SHAREWARE
	tmpi = swapint(Netgame.level_time);
	memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;				// SWAP_HERE
	tmpi = swapint(Netgame.control_invul_time);
	memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;				// SWAP_HERE
	tmpi = swapint(Netgame.monitor_vector);
	memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;				// SWAP_HERE
	for (i = 0; i < 8; i++) {
		tmpi = swapint(Netgame.player_score[i]);
		memcpy(&(out_buffer[loc]), &tmpi, 4); loc += 4;				// SWAP_HERE
	}
	for (i = 0; i < 8; i++) {
		memcpy(&(out_buffer[loc]), &(Netgame.player_flags[i]), 1); loc++;
	}
	memcpy(&(out_buffer[loc]), Netgame.mission_name, 9); loc += 9;
	memcpy(&(out_buffer[loc]), Netgame.mission_title, MISSION_NAME_LEN+1); loc += (MISSION_NAME_LEN+1);
	if (Netgame.protocol_version == MULTI_PROTO_D1X_VER) {
	    out_buffer[loc] = Netgame.packets_per_sec; loc++;
	    tmpi = swapint(Netgame.flags);
	    memcpy(&out_buffer[loc], &tmpi, 4); loc += 4;
        }
#endif

	if (server == NULL)
		ipx_send_broadcast_packet_data(out_buffer, loc);
	else
		ipx_send_internetwork_packet_data( out_buffer, loc, server, node );
}
Ejemplo n.º 25
0
void swap_polygon_model_data(ubyte *data) {
	int i;
	short n;
	g3s_uvl *uvl_val;
	ubyte *p = data;

	short_swap(wp(p));

	while (w(p) != OP_EOF) {
		switch (w(p)) {
		case OP_DEFPOINTS:
			short_swap(wp(p + 2));
			n = w(p + 2);
			for (i = 0; i < n; i++)
				vms_vector_swap(vp((p + 4) + (i * sizeof(vms_vector))));
			p += n*sizeof(struct vms_vector) + 4;
			break;

		case OP_DEFP_START:
			short_swap(wp(p + 2));
			short_swap(wp(p + 4));
			n = w(p + 2);
			for (i = 0; i < n; i++)
				vms_vector_swap(vp((p + 8) + (i * sizeof(vms_vector))));
			p += n*sizeof(struct vms_vector) + 8;
			break;

		case OP_FLATPOLY:
			short_swap(wp(p + 2));
			n = w(p + 2);
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			short_swap(wp(p + 28));
			// swap the colors 0 and 255 here!!!!
			if (w(p + 28) == 0)
				w(p + 28) = 255;
			else if (w(p + 28) == 255)
				w(p + 28) = 0;
			for (i = 0; i < n; i++)
				short_swap(wp(p + 30 + (i * 2)));
			p += 30 + ((n&~1) + 1) * 2;
			break;

		case OP_TMAPPOLY:
			short_swap(wp(p + 2));
			n = w(p + 2);
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			for (i = 0; i<n; i++) {
				uvl_val = (g3s_uvl *)((p + 30 + ((n&~1) + 1) * 2) + (i * sizeof(g3s_uvl)));
				uvl_val->u = (fix)swapint((int)uvl_val->u);
				uvl_val->v = (fix)swapint((int)uvl_val->v);
			}
			short_swap(wp(p + 28));
			for (i = 0; i<n; i++)
				short_swap(wp(p + 30 + (i * 2)));
			p += 30 + ((n&~1) + 1) * 2 + n * 12;
			break;

		case OP_SORTNORM:
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			short_swap(wp(p + 28));
			short_swap(wp(p + 30));
			swap_polygon_model_data(p + w(p + 28));
			swap_polygon_model_data(p + w(p + 30));
			p += 32;
			break;

		case OP_RODBM:
			vms_vector_swap(vp(p + 20));
			vms_vector_swap(vp(p + 4));
			short_swap(wp(p + 2));
			*((int *)(p + 16)) = swapint(*((int *)(p + 16)));
			*((int *)(p + 32)) = swapint(*((int *)(p + 32)));
			p += 36;
			break;

		case OP_SUBCALL:
			short_swap(wp(p + 2));
			vms_vector_swap(vp(p + 4));
			short_swap(wp(p + 16));
			swap_polygon_model_data(p + w(p + 16));
			p += 20;
			break;

		case OP_GLOW:
			short_swap(wp(p + 2));
			p += 4;
			break;

		default:
			Int3();
		}
		short_swap(wp(p));
	}
}
Ejemplo n.º 26
0
extern void       _TreeDeleteNodeExecute(void *dbid)
{
  PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
  static NID       nid;
  NODE     *node;
  NODE     *prevnode = 0;
  NODE     *parent;
  static NCI empty_nci;
  NODE     *firstempty = (dblist->tree_info->header->free == -1) ? (NODE *) 0 :
	  (NODE *) ((char *) dblist->tree_info->node + dblist->tree_info->header->free);

  TREE_EDIT *edit = dblist->tree_info->edit;
  static int zero = 0;
/*------------------------------------------------------------------------------

 Executable:                                                                  */

  nid.tree = 0;
  nid.node = 0;
  while (_TreeDeleteNodeGetNid(dbid, (int*)&nid) & 1)
  {
    int       found = 0;
    _TreeRemoveNodesTags(dbid, *(int *)&nid);
    _TreeSetNoSubtree(dbid, *(int *)&nid);
    nid_to_node(dblist, (&nid), node);
    parent = parent_of(node);
    if (child_of(parent) == node)
    {
      found = 1;
      if (node->INFO.TREE_INFO.brother)
      {
        link_it(parent->INFO.TREE_INFO.child,brother_of(node),parent);
      }
      else
	parent->INFO.TREE_INFO.child = 0;
    }
    else if (parent->INFO.TREE_INFO.child)
    {
      NODE     *bro;
      for (bro = child_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro));
      if (brother_of(bro) == node)
      {
	found = 1;
	if (node->INFO.TREE_INFO.brother)
	{
          link_it(bro->INFO.TREE_INFO.brother,brother_of(node),bro);
        }
	else
	  bro->INFO.TREE_INFO.brother = 0;
      }
    }
    if (!found)
    {
      if (member_of(parent) == node)
      {
	if (node->INFO.TREE_INFO.brother)
	{
	  link_it(parent->INFO.TREE_INFO.member,brother_of(node), parent);
        }
	else
	  parent->INFO.TREE_INFO.member = 0;
      }
      else if (parent->INFO.TREE_INFO.member)
      {
	NODE     *bro;
	for (bro = member_of(parent); bro->INFO.TREE_INFO.brother && (brother_of(bro) != node); bro = brother_of(bro));
	if (brother_of(bro) == node)
	{
	  found = 1;
	  if (node->INFO.TREE_INFO.brother)
	  {
	    link_it(bro->INFO.TREE_INFO.brother,brother_of(node), bro);
          }
	  else
	    bro->INFO.TREE_INFO.brother = 0;
	}
      }
    }
    if ((int)nid.node < edit->first_in_mem)
    {
      NCI       old_nci;
      int       nidx = nid.node;
      TreeGetNciLw(dblist->tree_info, nidx, &old_nci);
      TreePutNci(dblist->tree_info, nidx, &empty_nci, 1);
    }
    else
      memcpy(edit->nci + nid.node - edit->first_in_mem, &empty_nci, sizeof(struct nci));
    memcpy(node->name,"deleted node",sizeof(node->name));
    LoadShort(zero,&node->conglomerate_elt);
    node->INFO.TREE_INFO.member = 0;
    node->INFO.TREE_INFO.brother = 0;
    node->usage = 0;
    if (prevnode)
    {
      int tmp;
      link_it(prevnode->parent, node, prevnode);
      tmp = -swapint((char *)&prevnode->parent);
      node->INFO.TREE_INFO.child = swapint((char *)&tmp);
    }
    else
    {
      int tmp;
      link_it(tmp,node, dblist->tree_info->node);
      dblist->tree_info->header->free = swapint((char *)&tmp);
      node->INFO.TREE_INFO.child = 0;
    }
    if (firstempty)
    {
      int tmp;
      link_it(node->parent, firstempty, node);
      tmp = -swapint((char *)&node->parent);
      firstempty->INFO.TREE_INFO.child = swapint((char *)&tmp);
    }
    else
      node->parent = 0;
    prevnode = node;
  }
  dblist->modified = 1;
  _TreeDeleteNodeInitialize(dbid, 0, 0, 1);
}
Ejemplo n.º 27
0
void *pfm_readpfm_type(FILE *fp,
           int *cols,
           int *rows,
           float *minval,
           float *maxval,
           int storageType,
           PFMConvert *convFunc)
{
/*  int compressed;*/
  void *ret_val;
  char buffer[1024];
  char     *data=0;
  float    *floatbuffer=0;
  double   *doublebuffer=0;
  int      *intbuffer=0;
  uint16   *int16buffer=0;
  grey     *greybuffer=0;
  PFM3Byte *ppmbuffer=0;
  int       byte_order=BYTEORDER;
  int r,c;
  int type;
  int storage_size[]={
          sizeof(float),
          sizeof(signed int),
          sizeof(unsigned int),
          sizeof(sint16),
          sizeof(uint16),
          sizeof(grey),
          sizeof(unsigned char),
          sizeof(unsigned char),
          sizeof(double)
          };
  ConvertFunc* double2[]={
       double2float,
       double2sint,
       double2sint,
       double2uint16,
       double2uint16,
       0,0,0,
       double2double,
       0};
  ConvertFunc* float2[]={
       float2float,
       float2sint,
       float2sint,
       float2uint16,
       float2uint16,
       0,0,0,
       float2double,
       0};
  ConvertFunc* uint162[]={
        uint162float,
        uint162sint,
        uint162sint,
        uint162uint16,
        uint162uint16,
        0,0,0,
        uint162double,
        0};
  ConvertFunc* sint2[]={
      sint2float,
      sint2sint,
      sint2sint,
      sint2uint16,
      sint2uint16,
      0,0,0,
      sint2double,
      0};
  ConvertFunc* pgm2[]={
      pgm2float,
      pgm2sint,
      pgm2sint,
      pgm2uint16,
      pgm2uint16,
      pgm2pgm,
      0,0,
      pgm2double,
      0};
  ConvertFunc* pbm2[]={
  0,0,0,0,0,0,0,0,0,0
  };

  memset(buffer, 0, 1024);
  pfmGeoRead_=0;
  if (pfmCommentRead_) free(pfmCommentRead_);
  pfmCommentRead_=0;
  pfmGeoSet_=0;
  fp=check_compression(buffer,fp);
  
#ifdef DEBUG
  printf("pfm_readpfm: %s\n",buffer);
#endif
  switch (buffer[0]) {
  case 'F':
    switch (buffer[1]) {
    case '0':
      type=PFM_FLOAT_ASCII;
      break;
    case '1':
      type=PFM_INT_ASCII;
      break;
    case '2':
      type=PFM_INT16_ASCII;
      break;
    case '3':
      type=PFM_DOUBLE_ASCII;
      break;
    case '4':
      type=PFM_FLOAT_BIN;
      break;
    case '5':
      type=PFM_INT_BIN;
      break;
    case '6':
      type=PFM_INT16_BIN;
      break;
    case '7':
      type=PFM_DOUBLE_BIN;
      break;
    default:
      fprintf(stderr,"pfm_readpfm: Wrong fileformat!\n");
      ret_val=0;
      goto exit_read_pfm;
    }
    break;
  case 'P':
    switch (buffer[1]) {
    case '1':
      type=PFM_PBM_ASCII;
      break;
    case '2':
      type=PFM_PGM_ASCII;
      break;
    case '3':
      type=PFM_PPM_ASCII;
      break;
    case '4':
      type=PFM_PBM_BIN;
      break;
    case '5':
      type=PFM_PGM_BIN;
      break;
    case '6':
      type=PFM_PPM_BIN;
      break;
    default:
      fprintf(stderr,"pfm_readpfm: Wrong fileformat!\n");
      ret_val=0;
      goto exit_read_pfm;
    }
    break;
  default:
    {
      fprintf(stderr,"pfm_readpfm: Wrong fileformat!\n");
      ret_val=0;
      goto exit_read_pfm;
    }
  }
  if ((type>=PFM_FLOAT_BIN) && (type<=PFM_DOUBLE_BIN))
    {
      read_buffer(buffer,1023,fp);
#ifdef DEBUG
      printf("pfm_readpfm: %s\n",buffer);
#endif
      if (buffer[0] == 'L')  {
        byte_order=PFM_LittleEndian;
      }
      else {
        byte_order=PFM_BigEndian;
      }
    }
  read_buffer(buffer,1023,fp);
#ifdef DEBUG
  printf("pfm_readpfm: %s\n",buffer);
#endif
  sscanf(buffer,"%d %d",cols,rows);
  read_buffer(buffer,1023,fp);
#ifdef DEBUG
  printf("pfm_readpfm: %s\n",buffer);
#endif
  pfm_mult=0.0;
  pfm_offset=0.0;
  if (sscanf(buffer,"%f %f %f %f",minval,maxval,&pfm_mult,&pfm_offset)<2) {
    *maxval=*minval;
    *minval=0.0;
  }
  if (type==PFM_PGM_BIN && *maxval>255) {
    type=PFM_INT16_BIN;
    byte_order=PFM_BigEndian;
  }
  if (type==PFM_PGM_ASCII && *maxval>255 && *maxval<=65535) {
    type=PFM_INT16_ASCII;
    byte_order=PFM_BigEndian;
  }
  if (pfm_mult!=0.0) convFunc=StretchConvert;
#ifdef DEBUG
  printf("pfm_readpfm: cols=%d rows=%d min=%f max=%f byte_order=%s\n",
   *cols,*rows,*minval,*maxval,(byte_order==PFM_BigEndian ? "BE" : "LE"));
#endif
  if (type==PFM_PPM_BIN) {
    ppmbuffer=(PFM3Byte*)malloc(sizeof(PFM3Byte));
    ppmbuffer->r=(unsigned char*)calloc(*cols*(*rows),storage_size[storageType]);
    ppmbuffer->g=(unsigned char*)calloc(*cols*(*rows),storage_size[storageType]);
    ppmbuffer->b=(unsigned char*)calloc(*cols*(*rows),storage_size[storageType]);
    if (ppmbuffer && ppmbuffer->r && ppmbuffer->g && ppmbuffer->b)
      data=(void*)ppmbuffer;
  }
  else data =(void*)calloc(*cols*(*rows),storage_size[storageType]);

  if (!data)
    {
      fprintf(stderr,"pfm_readpfm: Out of memory while allocating input buffer!\n");
      ret_val=0;
      goto exit_read_pfm;
    }
  switch (type)
    {
    case PFM_FLOAT_ASCII:
      if (!float2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from float to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      floatbuffer=(float*)calloc(*cols,sizeof(float));
      if (!floatbuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary float buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++)  {
        for (c=0; c<*cols; c++) {
          fscanf(fp,"%f",&(floatbuffer[c]));
        }
        float2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            floatbuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
      }
      free(floatbuffer);
      break;
    case PFM_FLOAT_BIN:
      if (!float2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from float to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      floatbuffer=(float*)calloc(*cols,sizeof(float));
      if (!floatbuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary float buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++) {
        fread(floatbuffer,sizeof(float),*cols,fp);
        swapfloat(floatbuffer,*cols,byte_order);
        float2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            floatbuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
  
      }
      free(floatbuffer);
      break;      
    case PFM_DOUBLE_ASCII:
      if (!double2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from double to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      doublebuffer=(double*)calloc(*cols,sizeof(double));
      if (!doublebuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary double buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++)  {
        for (c=0; c<*cols; c++) {
          fscanf(fp,"%lf",&(doublebuffer[c]));
        }
        double2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            doublebuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
      }
      free(doublebuffer);
      break;
    case PFM_DOUBLE_BIN:
      if (!double2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from double to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      doublebuffer=(double*)calloc(*cols,sizeof(double));
      if (!doublebuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary double buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++) {
        fread(doublebuffer,sizeof(double),*cols,fp);
        swapdouble(doublebuffer,*cols,byte_order);
        double2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            doublebuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
  
      }
      free(doublebuffer);
      break;
    case PFM_INT_ASCII:
      
      if (!sint2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from int to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      intbuffer =(int*)calloc(*cols,sizeof(int));
      if (!intbuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary int buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++)  {
        for (c=0; c<*cols; c++) {
          fscanf(fp,"%d",&(intbuffer[c]));
        }
        sint2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            intbuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);

      }
      free(intbuffer);
      break;
    case PFM_INT_BIN:
      if (!sint2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from int to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      intbuffer =(int*)calloc(*cols,sizeof(int));
      if (!intbuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary int buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++)  {
        fread(intbuffer,sizeof(int),*cols,fp);
        swapint(intbuffer,*cols,byte_order);
        sint2[storageType](&data[r*(*cols)*storage_size[storageType]],
                          intbuffer,
                          *cols,
                          convFunc,
                          *minval,
                          *maxval);
      }
      free(intbuffer);
      break;
    case PFM_INT16_ASCII:
      if (!uint162[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from int16 to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      int16buffer =(uint16*)calloc(*cols,sizeof(uint16));
      if (!int16buffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary int16 buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++)  {
        for (c=0; c<*cols; c++) {
          fscanf(fp,"%hd",&(int16buffer[c])); /* "%d" -> "%hd" (T. Wiebesiek, 31.3.2005) */
        }
        uint162[storageType](&data[r*(*cols)*storage_size[storageType]],
                            int16buffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);

      }
      free(int16buffer);
      break;
    case PFM_INT16_BIN:
      if (!uint162[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from int16 to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      int16buffer =(uint16*)calloc(*cols,sizeof(uint16));
      if (!int16buffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary int16 buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++) {
        fread(int16buffer,sizeof(uint16),*cols,fp);
        swapint16(int16buffer,*cols,byte_order);
        uint162[storageType](&data[r*(*cols)*storage_size[storageType]],
                            int16buffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
      }
      free(int16buffer);
      break;
    case PFM_PGM_ASCII:
      fprintf(stderr,"pfm_readpfm: PGM ASCII not implemented!\n");
      ret_val=0;
      goto exit_read_pfm;
      break;
    case PFM_PGM_BIN:
      if (!pgm2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from pgm to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      greybuffer =(grey*)calloc(*cols,sizeof(grey));
      if (!greybuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary pgm buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++) {
        fread(greybuffer,sizeof(grey),*cols,fp);
        pgm2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            greybuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
      }
      free(greybuffer);
      break;
    case PFM_PBM_ASCII:
      fprintf(stderr,"pfm_readpfm: PBM ASCII not implented!\n");
      ret_val=0;
      goto exit_read_pfm;
      break;
    case PFM_PBM_BIN:
      fprintf(stderr,"pfm_readpfm: PBM BIN not implented!\n");
      ret_val=0;
      goto exit_read_pfm;
      if (!pbm2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from pgm to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
      greybuffer =(grey*)calloc(*cols,sizeof(grey));
      if (!greybuffer)  {
        fprintf(stderr,"pfm_readpfm: Out of memory (temporary pgm buffer)!\n");
        ret_val=0;
        goto exit_read_pfm;
      }
      for (r=0; r<*rows; r++) {
        fread(greybuffer,sizeof(grey),*cols,fp);
        pgm2[storageType](&data[r*(*cols)*storage_size[storageType]],
                            greybuffer,
                            *cols,
                            convFunc,
                            *minval,
                            *maxval);
      }
      free(greybuffer);
      break;
    case PFM_PPM_BIN:
      pfm_read_ppm(fp,*cols,*rows,ppmbuffer);
#if 0
      if (!pgm2[storageType]) {
        fprintf(stderr,"pfm_readpfm: conversion from pgm to type %d not implemented\n",storageType);
        ret_val=0;
        goto exit_read_pfm;
      }
#endif      
      break;
    }
exit_read_pfm:
  if (compressed_) fp=stop_decompression(fp);
  return data;
}
Ejemplo n.º 28
0
static	int	split( char *path, char *dirc, char *name )
{
   char	*s;				/* pointer */
   int	l1, l2;				/* length counters */

   l1 = strlen( path );			/* length of path */
   if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH );
   s = strrchr( path, '/' );		/* find last / */
   if ( s == NULL ) {			/* no directory, so use current */
#if	defined(__bsd__)		/* get current working directory */
      extern char	*getwd( );

      if ( getwd( dirc ) == NULL ) {
#else
      extern char	*getcwd( );

      if ( getcwd( dirc, FILENAME_MAX ) == NULL ) {
#endif
         return( GLOCK_ERROR_GETCWD );
      }
      strcpy( name, path );		/* we've got it */
   } else {				/* strip direcotry from path */
      s++;				/* after this, the filename */
      l2 = strlen( s );			/* length of filename */
      if ( l2 == 0 ) return( GLOCK_ERROR_NOPATH );
      strcpy( name, s );		/* save file name */
      strncpy( dirc, path, l1 - l2 );	/* now the directory */
      dirc[l1-l2] = 0;			/* add zero */
   }
   l1 = strlen( dirc );			/* length of directory */
   if ( dirc[l1-1] != '/' ) { dirc[l1] = '/'; dirc[l1+1] = 0; }
   return( 0 );				/* we're done */
}


/*
 * makeconnection( ) reads the .glock file and make the connection with
 * lckserver.
 */

static	int	makeconnection( FILE *file )
{
   char			hostname[STRINGLEN];	/* name of host */
   int			close( );		/* close */
   int			connect( );		/* connect */
   int			inet_addr( );		/* get inet address */
   int			port;			/* port number */
   int			r;			/* return value */
   int			socket( );		/* socket */
   int  		obuf[2];		/* data from lckserver */
   short		portnumber;		/* port number */
   struct hostent	*gethostbyname( );	/* gethostbyname */
   struct hostent	*hp;			/* host */
   struct sockaddr_in	server;			/* sock struct */

   if ( xscanf( file, "%s %d", hostname, &port ) != 2 ) {
      fclose( file );
      return( GLOCK_ERROR_FILEREAD );
   }
   fclose( file );				/* close .glock file */
   portnumber = port;				/* the port */
   r = socket( AF_INET, SOCK_STREAM, 0 );	/* create socket */
   if ( r == -1 ) return( GLOCK_ERROR_SOCKET );	/* error */
   hp = gethostbyname( hostname );		/* get host by name */
   if ( hp == NULL ) {				/* error */
      server.sin_addr.s_addr = inet_addr( hostname );
      if (server.sin_addr.s_addr == -1) {
         close( r );
         return( GLOCK_ERROR_GETHOSTBYNAME );
      }
   } else {
      server.sin_addr.s_addr = INADDR_ANY;	/* any address */
      memmove( (void *) &server.sin_addr, (void *) hp->h_addr, hp->h_length );
   }
   server.sin_family      = AF_INET;		/* inet */
   server.sin_port        = htons( portnumber );	/* the port */ 
   if ( connect( r, (void *) &server, sizeof( server ) ) == -1 ) {
      close( r );
      return( GLOCK_ERROR_CONNECT );
   } else {					/* connection okay */
      if ( get( r, obuf, sizeof( obuf ) ) ) {
         close( r );
         return( GLOCK_ERROR_CONNECT1 );	/* error */
      }
      if ( obuf[0] != 1 ) swapint( obuf, 2 );	/* swap bytes */
      if ( obuf[0] != 1 ) {			/* error */
         close( r );
         return( GLOCK_ERROR_CONNECT2 );
      } else if ( obuf[1] != GLOCK_CONNECT ) {	/* error */
         close( r );
         if ( obuf[1] == GLOCK_NOSOCK ) {
            return( GLOCK_ERROR_NOSOCKETS );
         } else {
            return( GLOCK_ERROR_SERVERBAD );
         }
      }
   }
   return( r );					/* we're done */
}
Ejemplo n.º 29
0
/*
 * returns 0 on success, non-zero if not all textures were properly extracted.
 */
int decompile(listitem_t *wadlist, char *section, void *texture, void *pnames)
{
	int	rc = 0;
	int	i, j;
	int	patches_found;
	int	*p1;
	char	*p2;
	short	*p3;
	int	num_tex;
	int	off_tex;
	short	dummy;
	short	width, height, num_pat;
	short	xoff, yoff, pnum;
	char	tname[9];
	FILE	*fp = NULL;
	char	fn[50];

	/* initialize */
	memset(&tname[0], 0, sizeof tname);

	/* get number of textures in texture lump */
	p1 = (int *) texture;
	num_tex = *p1;
	swaplong(&num_tex);
	printf("  found %d textures\n", num_tex);

	/* loop over all textures */
	for (i = 0; i < num_tex; i++) {
 
		/* offset for texture in lump */
		p1 = (int *) texture + i + 1;
		off_tex = *p1;
		swaplong(&off_tex);
		p2 = (char *) texture + off_tex;

		/* get name of texture */
		strncpy(&tname[0], p2, 8);
		{
		  int n;
		  for (n = 0; n < sizeof tname; n++)
			  tname[n] = toupper(((unsigned char *) tname)[n]);
		}
		if (wildcard != NULL && fnmatch(wildcard, tname, 0) != 0)
			continue;

		/* get texture composition */
		p3 = (short *) (p2 + 8);
		dummy = *p3++;		/* always 0 */
		dummy = *p3++;		/* always 0 */
		width = *p3++;
		swapint(&width);
		height = *p3++;
		swapint(&height);
		dummy = *p3++;		/* always 0 */
		dummy = *p3++;		/* always 0 */
		num_pat = *p3++;
		swapint(&num_pat);

		printf("  decompiling texture %s, %d patches, %dx%d\n",
		  &tname[0], num_pat, width, height);

		/* grow the texture buffer if necessary */
		{
		  unsigned long newsize = width * height;
		  if ((size_t) newsize != newsize) {
		    err("Texture too big, size_t overflow (%hd x %hd). Skipping.",
			width, height);
		    rc = 1;
		    continue;
		  }
		  if (newsize > img_buf_sz) {
		    unsigned char *newbuf = realloc(img_buf, newsize);
		    if (newbuf == NULL) {
		      err("Texture too big, not enough memory (%d x %d). Skipping.",
			  width, height);
		      rc = 1;
		      continue;
		    }
		    img_buf_sz = newsize;
		    img_buf    = newbuf;
		  }
		}

		/* want text file too? */
		if (tflag) {
		  strcpy(&fn[0], "textures/");
		  if (preserve_case)
		    strcat(&fn[0], &tname[0]);
		  else
		    strlcat(&fn[0], &tname[0]);
		  strcat(&fn[0], ".wgc");
		  if ((fp = fopen(&fn[0], "w")) == NULL) {
		    err("can't open %s for writing", &fn[0]);
		    exit(1);
		  }
		  fprintf(fp, "%s_START\n", section);
		  fprintf(fp, "  %s %d %d %d\n", &tname[0], width, height,
		      num_pat);
		}

		/* clear pixel buffer */
		memset(img_buf, 255, img_buf_sz);

		/* loop over all patches for the texture */
		patches_found = 0;
		for (j = 0; j < num_pat; j++) {
		  const char *patchname = NULL;
		  listitem_t *wad;

		  xoff = *p3++;
		  swapint(&xoff);
		  yoff = *p3++;
		  swapint(&yoff);
		  if (yoff < 0)
                    yoff = 0;
		  pnum = *p3++;
		  swapint(&pnum);
		  dummy = *p3++;	/* always 1, stepdir? what is that?? */
		  dummy = *p3++;	/* always 0 for colormap 0 */
		  for (wad = wadlist; wad != NULL; wad = wad->next) {
		    if (get_patch(wad->wf, fp, pnames, width, height,
			  xoff, yoff, pnum, &patchname) == 0) {
		      patches_found++;
		      break;
		    }
		  }
		  if (wad == NULL)
		    printf("    Warning: patch \"%.8s\" is missing\n",
			patchname);
		}

		if (patches_found == 0 && mpatch_policy != OIT_ALWAYS) {
		  printf("    Warning: skipping void texture \"%s\".\n", tname);
		  rc = 1;
		}
		else if (patches_found < num_pat && mpatch_policy == OIT_IF_ALL) {
		  printf("    Warning: skipping incomplete texture \"%s\".\n", tname);
		  rc = 1;
		}
		else
		  if (extract)
		    write_ppm(&tname[0], width, height);

		/* terminate and close the text file too */
		if (tflag) {
		  fprintf(fp, "%s_END\n", section);
		  if (fclose(fp)) {
		    err("%s: %s", fn, strerror(errno));
		    exit(1);
		  }
		}
	}
	return rc;
}
Ejemplo n.º 30
0
void decompile_things(char *map, wadfile_t *wf, FILE *fp)
{
	void		*things;
	things_t	*t1;
	things2_t	*t2;
	int		size;
	int		i;

	if (verbose)
		printf("Decompiling things...\n");

	/* get the lump with the things for the map */
	if ((things = get_map_lump(wf, map, "THINGS", &size)) == (void *)0) {
		fprintf(stderr, "can't find THINGS lump for %s\n", map);
		exit(1);
	}

	/* write things start marker */
	fprintf(fp, " THINGS_START\n");

	if (!has_behavior)
	{
	    /* Doom or Doom2 map */

	    /* loop over all things in the lump and decompile */
	    t1 = (things_t *) things;
	    for (i = 0; i < size / sizeof(things_t); i++, t1++) {
		swapint(&t1->x);
		swapint(&t1->y);
		swapint(&t1->angle);
		swapint(&t1->type);
		swapint(&t1->flags);
		fprintf(fp, "  %d : %d %d %d %d\n", t1->type, t1->x, t1->y,
				t1->angle, t1->flags);
	    }
	} else {
	    /* Hexen or ZDoom map */

	    /* loop over all things in the lump and decompile */
	    t2 = (things2_t *) things;
	    for (i = 0; i < size / sizeof(things2_t); i++, t2++) {
		swapint(&t2->thingid);
		swapint(&t2->x);
		swapint(&t2->y);
		swapint(&t2->z);
		swapint(&t2->angle);
		swapint(&t2->type);
		swapint(&t2->flags);
		fprintf(fp, "  %d : %d %d %d %d %d %d %d %d %d %d %d %d\n",
				t2->type, t2->thingid, t2->x, t2->y, t2->z,
				t2->angle, t2->flags, t2->special, t2->arg1,
				t2->arg2, t2->arg3, t2->arg4, t2->arg5);
	    }
	}

	/* write things end marker */
	fprintf(fp, " THINGS_END\n\n");

	/* free memory */
	free(things);
}