示例#1
0
void W_LoadWadFile(int8* Filename)
{
    int32 FileOffsetCount = 0;

    int Length = 0;
    WadFile = COM_FindFile(Filename, &Length);

    if (!WadFile)
    {
        assert(0);
    }

    wadinfo_t *WadHeader = (wadinfo_t*)WadFile;

    if (WadHeader->Magic[0] != 'W'
        || WadHeader->Magic[1] != 'A'
        || WadHeader->Magic[2] != 'D'
        || WadHeader->Magic[3] != '2')
    {
        assert(0);
    }

    LumpCount = WadHeader->NumberOfLumps;
    FileOffsetCount = WadHeader->DirectoryOffset;
    Lumps = (lumpinfo_t*)(WadFile + FileOffsetCount);

    lumpinfo_t *LumpWalker = Lumps;
    for (int i = 0; i < LumpCount; i++)
    {
        W_CleanupName(LumpWalker->Name, LumpWalker->Name);
        LumpWalker++;
    }
}
示例#2
0
/*
====================
W_LoadWadFile
====================
*/
void W_LoadWadFile (char *filename)
{
	lumpinfo_t		*lump_p;
	wadinfo_t		*header;
	unsigned		i;
	int				infotableofs;
	
	wad_base = COM_LoadHunkFile (filename);
	if (!wad_base)
		Sys_Error ("W_LoadWadFile: couldn't load %s", filename);

	header = (wadinfo_t *)wad_base;
	
	if (header->identification[0] != 'W'
	|| header->identification[1] != 'A'
	|| header->identification[2] != 'D'
	|| header->identification[3] != '2')
		Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
		
	wad_numlumps = LittleLong(header->numlumps);
	infotableofs = LittleLong(header->infotableofs);
	wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
	
	for (i=0, lump_p = wad_lumps ; i<wad_numlumps ; i++,lump_p++)
	{
		lump_p->filepos = LittleLong(lump_p->filepos);
		lump_p->size = LittleLong(lump_p->size);
		W_CleanupName (lump_p->name, lump_p->name);
		if (lump_p->type == TYP_QPIC)
			SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));
	}
}
示例#3
0
static void W_SwapLumps(int numlumps, lumpinfo_t *lumps)
{
	int i;
	for (i = 0;i < numlumps;i++)
	{
		lumps[i].filepos = LittleLong(lumps[i].filepos);
		lumps[i].disksize = LittleLong(lumps[i].disksize);
		lumps[i].size = LittleLong(lumps[i].size);
		W_CleanupName(lumps[i].name, lumps[i].name);
	}
}
示例#4
0
/*
=============
W_GetLumpinfo
=============
*/
lumpinfo_t	*W_GetLumpinfo (char *name)
{
	int		i;
	lumpinfo_t	*lump_p;
	char	clean[16];
	
	W_CleanupName (name, clean);
	
	for (lump_p=wad_lumps, i=0 ; i<wad_numlumps ; i++,lump_p++)
	{
		if (!strcmp(clean, lump_p->name))
			return lump_p;
	}
	
	Sys_Error ("W_GetLumpinfo: %s not found", name);
	return NULL;
}
示例#5
0
unsigned char *W_GetLumpName(const char *name, fs_offset_t *returnfilesize)
{
	int i;
	fs_offset_t filesize;
	lumpinfo_t *lump;
	char clean[16];
	wadinfo_t *header;
	int infotableofs;

	W_CleanupName (name, clean);

	if (!wad.gfx_base)
	{
		if ((wad.gfx_base = FS_LoadFile ("gfx.wad", cls.permanentmempool, false, &filesize)))
		{
			if (memcmp(wad.gfx_base, "WAD2", 4))
			{
				Con_Print("gfx.wad doesn't have WAD2 id\n");
				Mem_Free(wad.gfx_base);
				wad.gfx_base = NULL;
			}
			else
			{
				header = (wadinfo_t *)wad.gfx_base;
				wad.gfx.numlumps = LittleLong(header->numlumps);
				infotableofs = LittleLong(header->infotableofs);
				wad.gfx.lumps = (lumpinfo_t *)(wad.gfx_base + infotableofs);

				// byteswap the gfx.wad lumps in place
				W_SwapLumps(wad.gfx.numlumps, wad.gfx.lumps);
			}
		}
	}

	for (lump = wad.gfx.lumps, i = 0;i < wad.gfx.numlumps;i++, lump++)
	{
		if (!strcmp(clean, lump->name))
		{
			if (returnfilesize)
				*returnfilesize = lump->size;
			return (wad.gfx_base + lump->filepos);
		}
	}
	return NULL;
}
示例#6
0
static lumpinfo_t *W_GetLumpInfo(int8 *Name)
{
    int8 CleanName[16];

    W_CleanupName(Name, CleanName);

    lumpinfo_t* LumpWalker = Lumps;
    for (int i = 0; i < LumpCount; i++)
    {
        if (!Q_strcmp(CleanName, LumpWalker->Name))
            return LumpWalker;

        LumpWalker++;
    }

    assert(0);
    return NULL;
}
示例#7
0
unsigned char *W_GetTextureBGRA(char *name)
{
	unsigned int i, k;
	sizebuf_t sb;
	unsigned char *data;
	mwad_t *w;
	char texname[17];
	size_t range;

	texname[16] = 0;
	W_CleanupName(name, texname);
	if (!wad.hlwads.mempool)
		Mem_ExpandableArray_NewArray(&wad.hlwads, cls.permanentmempool, sizeof(mwad_t), 16);
	range = Mem_ExpandableArray_IndexRange(&wad.hlwads);
	for (k = 0;k < range;k++)
	{
		w = (mwad_t *)Mem_ExpandableArray_RecordAtIndex(&wad.hlwads, k);
		if (!w)
			continue;
		for (i = 0;i < (unsigned int)w->numlumps;i++)
		{
			if (!strcmp(texname, w->lumps[i].name)) // found it
			{
				if (FS_Seek(w->file, w->lumps[i].filepos, SEEK_SET))
				{Con_Print("W_GetTexture: corrupt WAD3 file\n");return NULL;}

				MSG_InitReadBuffer(&sb, (unsigned char *)Mem_Alloc(tempmempool, w->lumps[i].disksize), w->lumps[i].disksize);
				if (!sb.data)
					return NULL;
				if (FS_Read(w->file, sb.data, w->lumps[i].size) < w->lumps[i].disksize)
				{Con_Print("W_GetTexture: corrupt WAD3 file\n");return NULL;}

				data = W_ConvertWAD3TextureBGRA(&sb);
				Mem_Free(sb.data);
				return data;
			}
		}
	}
	image_width = image_height = 0;
	return NULL;
}