Exemple #1
0
/*
================
idProgram::CalculateChecksum
================
*/
int idProgram::CalculateChecksum( void ) const
{
	int i, result;
	
	typedef struct
	{
		unsigned short	op;
		int				a;
		int				b;
		int				c;
		unsigned short	linenumber;
		unsigned short	file;
	} statementBlock_t;
	
	statementBlock_t	*statementList = new statementBlock_t[ statements.Num() ];
	
	memset( statementList, 0, ( sizeof( statementBlock_t ) * statements.Num() ) );
	
	// Copy info into new list, using the variable numbers instead of a pointer to the variable
	for( i = 0; i < statements.Num(); i++ )
	{
		statementList[i].op = statements[i].op;
		
		if( statements[i].a )
		{
			statementList[i].a = statements[i].a->num;
		}
		else
		{
			statementList[i].a = -1;
		}
		if( statements[i].b )
		{
			statementList[i].b = statements[i].b->num;
		}
		else
		{
			statementList[i].b = -1;
		}
		if( statements[i].c )
		{
			statementList[i].c = statements[i].c->num;
		}
		else
		{
			statementList[i].c = -1;
		}
		
		statementList[i].linenumber = statements[i].linenumber;
		statementList[i].file = statements[i].file;
	}
	
	result = MD4_BlockChecksum( statementList, ( sizeof( statementBlock_t ) * statements.Num() ) );
	
	delete [] statementList;
	
	return result;
}
Exemple #2
0
struct map *Model_MapLoad(struct server *server, char *filename)
{
	int size;
	struct map *map;
	char buffer[1024];
	char *file;
	int i;

	map = calloc(1, sizeof(*map));
	if (!map)
	{
		return NULL;
	}

	if (server->data_dir)
	{
		snprintf(buffer, sizeof(buffer), "%s/%s", server->data_dir, filename);
		file = buffer;
	}
	else
	{
		file = filename;
	}

	file = File_Read(file, &size);
	if (file == NULL)
	{
		return NULL;
	}

	map->data = (unsigned char *)file;

	map->header = (struct model_header *)file;

	map->mod_base = (unsigned char *)map->header;

	map->version = LittleLong(map->header->version);
	printf("%s - version: %i\n", filename, map->version);

	for (i=0;i<sizeof(struct model_header)/4;i++)
		((int *)map->header)[i] = LittleLong(((int *)map->header)[i]);

	for (i=0; i<HEADER_LUMPS; i++)
	{
		if (i == LUMP_ENTITIES)
			continue;

		map->checksum ^= LittleLong(MD4_BlockChecksum((void *)map->mod_base + map->header->lumps[i].fileofs, map->header->lumps[i].filelen));

		if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES)
			continue;

		map->checksum2 ^= LittleLong(MD4_BlockChecksum((void *)map->mod_base + map->header->lumps[i].fileofs, map->header->lumps[i].filelen));
	}

	memset(map->novis, 0xff, sizeof(map->novis));

	map->planes = Model_LoadPlanes(&map->header->lumps[LUMP_PLANES], map->mod_base, &map->planes_count);
	if (map->planes)
	{
		map->entity_string = strdup((char *)map->mod_base + map->header->lumps[LUMP_ENTITIES].fileofs);
		if (map->entity_string)
		{
			map->leafs = Model_LoadLeafs(&map->header->lumps[LUMP_LEAFS], map->mod_base, &map->leafs_count);
			if (map->leafs)
			{
				map->nodes = Model_LoadNodes(&map->header->lumps[LUMP_NODES], map->mod_base, &map->nodes_count, map->planes, map->leafs);
				if (map->nodes)
				{
					map->clipnodes = Model_LoadClipnodes(&map->header->lumps[LUMP_CLIPNODES], map->mod_base, &map->clipnodes_count);
					if (map->clipnodes)
					{
						if (Model_MapLoadSubmodels(map))
						{
							if (Model_MapCreateHulls(map))
							{
								if (Model_MapCreatePVS(map))
								{
									if (Model_MapCreatePHS(map))
									{
										free(map->data);
										map->data = NULL;
										return map;
									}
									else
										printf("Model_MapCreatePHS failed.\n");
								}
								else
									printf("Model_MapCreatePVS failed.\n");
							}
						}
						else
							printf("Model_LoadSubmodels failed. %i\n", map->submodels_count);
					}
					else
						printf("Model_LoadClipnodes failed.\n");
				}
			}
		}
	}
	Model_MapCleanup(map);
	return NULL;
}