06 Jul 2017

This commit is contained in:
g-cont 2017-07-06 00:00:00 +03:00 committed by Alibek Omarov
parent e766096ba4
commit 320523bb7d
7 changed files with 274 additions and 237 deletions

View File

@ -467,44 +467,82 @@ void SCR_UpdateScreen( void )
V_PostRender();
}
void SCR_LoadCreditsFont( void )
qboolean SCR_LoadFixedWidthFont( const char *fontname )
{
int fontWidth;
int i, fontWidth;
if( cls.creditsFont.valid ) return; // already loaded
if( cls.creditsFont.valid )
return true; // already loaded
cls.creditsFont.hFontTexture = GL_LoadTexture( "gfx.wad/creditsfont.fnt", NULL, 0, TF_IMAGE, NULL );
if( !FS_FileExists( fontname, false ))
return false;
cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE, NULL );
R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture );
cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = fontWidth / 16;
cls.creditsFont.valid = true;
// build fixed rectangles
for( i = 0; i < 256; i++ )
{
cls.creditsFont.fontRc[i].left = (i * (fontWidth / 16)) % fontWidth;
cls.creditsFont.fontRc[i].right = cls.creditsFont.fontRc[i].left + fontWidth / 16;
cls.creditsFont.fontRc[i].top = (i / 16) * (fontWidth / 16);
cls.creditsFont.fontRc[i].bottom = cls.creditsFont.fontRc[i].top + fontWidth / 16;
cls.creditsFont.charWidths[i] = clgame.scrInfo.charWidths[i] = fontWidth / 16;
}
return true;
}
qboolean SCR_LoadVariableWidthFont( const char *fontname )
{
int i, fontWidth;
byte *buffer;
size_t length;
qfont_t *src;
if( cls.creditsFont.valid )
return true; // already loaded
if( !FS_FileExists( fontname, false ))
return false;
cls.creditsFont.hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_IMAGE, NULL );
R_GetTextureParms( &fontWidth, NULL, cls.creditsFont.hFontTexture );
// setup creditsfont
if( FS_FileExists( "gfx/creditsfont.fnt", false ))
// half-life font with variable chars witdh
buffer = FS_LoadFile( fontname, &length, false );
// setup creditsfont
if( buffer && length >= sizeof( qfont_t ))
{
byte *buffer;
size_t length;
qfont_t *src;
src = (qfont_t *)buffer;
cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = src->rowheight;
// half-life font with variable chars witdh
buffer = FS_LoadFile( "gfx/creditsfont.fnt", &length, false );
if( buffer && length >= sizeof( qfont_t ))
// build rectangles
for( i = 0; i < 256; i++ )
{
int i;
src = (qfont_t *)buffer;
cls.creditsFont.charHeight = clgame.scrInfo.iCharHeight = src->rowheight;
// build rectangles
for( i = 0; i < 256; i++ )
{
cls.creditsFont.fontRc[i].left = (word)src->fontinfo[i].startoffset % fontWidth;
cls.creditsFont.fontRc[i].right = cls.creditsFont.fontRc[i].left + src->fontinfo[i].charwidth;
cls.creditsFont.fontRc[i].top = (word)src->fontinfo[i].startoffset / fontWidth;
cls.creditsFont.fontRc[i].bottom = cls.creditsFont.fontRc[i].top + src->rowheight;
cls.creditsFont.charWidths[i] = clgame.scrInfo.charWidths[i] = src->fontinfo[i].charwidth;
}
cls.creditsFont.valid = true;
cls.creditsFont.fontRc[i].left = (word)src->fontinfo[i].startoffset % fontWidth;
cls.creditsFont.fontRc[i].right = cls.creditsFont.fontRc[i].left + src->fontinfo[i].charwidth;
cls.creditsFont.fontRc[i].top = (word)src->fontinfo[i].startoffset / fontWidth;
cls.creditsFont.fontRc[i].bottom = cls.creditsFont.fontRc[i].top + src->rowheight;
cls.creditsFont.charWidths[i] = clgame.scrInfo.charWidths[i] = src->fontinfo[i].charwidth;
}
if( buffer ) Mem_Free( buffer );
cls.creditsFont.valid = true;
}
if( buffer ) Mem_Free( buffer );
return true;
}
void SCR_LoadCreditsFont( void )
{
if( !SCR_LoadVariableWidthFont( "gfx.wad/creditsfont.fnt" ))
{
if( !SCR_LoadFixedWidthFont( "gfx/conchars" ))
MsgDev( D_ERROR, "failed to load HUD font\n" );
}
}
@ -564,7 +602,7 @@ void SCR_RegisterTextures( void )
else cls.loadingBar = GL_LoadTexture( "gfx/loading.lmp", NULL, 0, TF_IMAGE, NULL );
}
cls.tileImage = GL_LoadTexture( "gfx/backtile.lmp", NULL, 0, TF_IMAGE, NULL );
cls.tileImage = GL_LoadTexture( "gfx/backtile.lmp", NULL, 0, TF_UNCOMPRESSED|TF_NOMIPMAP, NULL );
}
/*

View File

@ -498,7 +498,7 @@ colorVec R_LightVec( const vec3_t start, const vec3_t end, vec3_t lspot )
int i, maxEnts = 1;
colorVec light, cv;
if( cl.worldmodel->lightdata )
if( cl.worldmodel && cl.worldmodel->lightdata )
{
light.r = light.g = light.b = light.a = 0;
last_fraction = 1.0f;

View File

@ -909,7 +909,7 @@ StudioCalcBonePosition
====================
*/
void R_StudioCalcBonePosition( int frame, float s, mstudiobone_t *pbone, mstudioanim_t *panim, vec3_t adj, vec3_t pos )
void R_StudioCalcBonePosition( int frame, float s, mstudiobone_t *pbone, mstudioanim_t *panim, float *adj, vec3_t pos )
{
vec3_t origin1;
vec3_t origin2;

View File

@ -610,12 +610,7 @@ void VOX_ReadSentenceFile( const char *psentenceFileName )
// load file
pFileData = (char *)FS_LoadFile( psentenceFileName, &fileSize, false );
if( !pFileData )
{
MsgDev( D_WARN, "couldn't load %s\n", psentenceFileName );
return;
}
if( !pFileData ) return; // this game just doesn't used vox sound system
pch = pFileData;
pchlast = pch + fileSize;

View File

@ -534,37 +534,62 @@ qboolean Con_Visible( void )
return (con.vislines > 0);
}
/*
================
Con_LoadConsoleFont
================
*/
static void Con_LoadConsoleFont( int fontNumber, cl_font_t *font )
static qboolean Con_LoadFixedWidthFont( const char *fontname, cl_font_t *font )
{
int fontWidth;
int i, fontWidth;
if( font->valid ) return; // already loaded
if( font->valid )
return true; // already loaded
// loading conchars
if( Sys_CheckParm( "-oldfont" )) font->hFontTexture = GL_LoadTexture( "gfx.wad/conchars", NULL, 0, TF_FONT|TF_NEAREST, NULL );
else font->hFontTexture = GL_LoadTexture( va( "fonts.wad/font%i", fontNumber ), NULL, 0, TF_FONT|TF_NEAREST, NULL );
if( !FS_FileExists( fontname, false ))
return false;
font->hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_NEAREST, NULL );
R_GetTextureParms( &fontWidth, NULL, font->hFontTexture );
// setup creditsfont
if( font->hFontTexture && fontWidth != 0 )
{
font->charHeight = fontWidth / 16;
// build fixed rectangles
for( i = 0; i < 256; i++ )
{
font->fontRc[i].left = (i * (fontWidth / 16)) % fontWidth;
font->fontRc[i].right = font->fontRc[i].left + fontWidth / 16;
font->fontRc[i].top = (i / 16) * (fontWidth / 16);
font->fontRc[i].bottom = font->fontRc[i].top + fontWidth / 16;
font->charWidths[i] = fontWidth / 16;
}
font->valid = true;
}
return true;
}
static qboolean Con_LoadVariableWidthFont( const char *fontname, cl_font_t *font )
{
int i, fontWidth;
byte *buffer;
size_t length;
qfont_t *src;
if( font->valid )
return true; // already loaded
if( !FS_FileExists( fontname, false ))
return false;
font->hFontTexture = GL_LoadTexture( fontname, NULL, 0, TF_FONT|TF_NEAREST, NULL );
R_GetTextureParms( &fontWidth, NULL, font->hFontTexture );
// setup consolefont
if( font->hFontTexture && fontWidth != 0 )
{
byte *buffer;
size_t length;
qfont_t *src;
// half-life font with variable chars witdh
if( Sys_CheckParm( "-oldfont" )) buffer = FS_LoadFile( "gfx.wad/conchars", &length, false );
else buffer = FS_LoadFile( va( "fonts.wad/font%i", fontNumber ), &length, false );
buffer = FS_LoadFile( fontname, &length, false );
if( buffer && length >= sizeof( qfont_t ))
{
int i;
src = (qfont_t *)buffer;
font->charHeight = src->rowheight;
@ -581,6 +606,26 @@ static void Con_LoadConsoleFont( int fontNumber, cl_font_t *font )
}
if( buffer ) Mem_Free( buffer );
}
return true;
}
/*
================
Con_LoadConsoleFont
================
*/
static void Con_LoadConsoleFont( int fontNumber, cl_font_t *font )
{
if( font->valid ) return; // already loaded
// loading conchars
if( Sys_CheckParm( "-oldfont" ))
Con_LoadVariableWidthFont( "gfx.wad/conchars.fnt", font );
else Con_LoadVariableWidthFont( va( "fonts.wad/font%i", fontNumber ), font );
// quake fixed font as fallback
if( !font->valid ) Con_LoadFixedWidthFont( "gfx/conchars", font );
}
/*

View File

@ -79,7 +79,7 @@ typedef struct wfile_s
byte *mempool; // W_ReadLump temp buffers
int numlumps;
int mode;
int handle;
file_t *handle;
dlumpinfo_t *lumps;
time_t filetime;
};
@ -513,109 +513,18 @@ pack_t *FS_LoadPackPAK( const char *packfile, int *error )
for( i = 0; i < numpackfiles; i++ )
FS_AddFileToPack( info[i].name, pack, info[i].filepos, info[i].filelen );
MsgDev( D_NOTE, "Adding packfile: %s (%i files)\n", packfile, numpackfiles );
if( error ) *error = PAK_LOAD_OK;
Mem_Free( info );
return pack;
}
/*
================
FS_AddPak_Fullpath
Adds the given pack to the search path.
The pack type is autodetected by the file extension.
Returns true if the file was successfully added to the
search path or if it was already included.
If keep_plain_dirs is set, the pack will be added AFTER the first sequence of
plain directories.
================
*/
static qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, qboolean keep_plain_dirs, int flags )
{
searchpath_t *search;
pack_t *pak = NULL;
const char *ext = FS_FileExtension( pakfile );
int errorcode = PAK_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->pack && !Q_stricmp( search->pack->filename, pakfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded ) *already_loaded = false;
if( !Q_stricmp( ext, "pak" )) pak = FS_LoadPackPAK( pakfile, &errorcode );
else MsgDev( D_ERROR, "\"%s\" does not have a pack extension\n", pakfile );
if( pak )
{
if( keep_plain_dirs )
{
// find the first item whose next one is a pack or NULL
searchpath_t *insertion_point = NULL;
if( fs_searchpaths && !fs_searchpaths->pack )
{
insertion_point = fs_searchpaths;
while( 1 )
{
if( !insertion_point->next ) break;
if( insertion_point->next->pack ) break;
insertion_point = insertion_point->next;
}
}
// if insertion_point is NULL, this means that either there is no
// item in the list yet, or that the very first item is a pack. In
// that case, we want to insert at the beginning...
if( !insertion_point )
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
}
else // otherwise we want to append directly after insertion_point.
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->next = insertion_point->next;
search->flags |= flags;
insertion_point->next = search;
}
}
else
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
}
return true;
}
else
{
if( errorcode != PAK_LOAD_NO_FILES )
MsgDev( D_ERROR, "FS_AddPak_Fullpath: unable to load pak \"%s\"\n", pakfile );
return false;
}
}
/*
====================
FS_AddWad_Fullpath
====================
*/
static qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, qboolean keep_plain_dirs, int flags )
static qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
wfile_t *wad = NULL;
@ -637,50 +546,13 @@ static qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loade
if( wad )
{
if( keep_plain_dirs )
{
// find the first item whose next one is a wad or NULL
searchpath_t *insertion_point = NULL;
if( fs_searchpaths && !fs_searchpaths->wad )
{
insertion_point = fs_searchpaths;
while( 1 )
{
if( !insertion_point->next ) break;
if( insertion_point->next->wad ) break;
insertion_point = insertion_point->next;
}
}
// if insertion_point is NULL, this means that either there is no
// item in the list yet, or that the very first item is a wad. In
// that case, we want to insert at the beginning...
if( !insertion_point )
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
}
else // otherwise we want to append directly after insertion_point.
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->next = insertion_point->next;
search->flags |= flags;
insertion_point->next = search;
}
}
else
{
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
}
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->wad = wad;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
MsgDev( D_NOTE, "Adding wadfile %s (%i files)\n", wadfile, wad->numlumps );
MsgDev( D_REPORT, "Adding wadfile: %s (%i files)\n", wadfile, wad->numlumps );
return true;
}
else
@ -691,6 +563,73 @@ static qboolean FS_AddWad_Fullpath( const char *wadfile, qboolean *already_loade
}
}
/*
================
FS_AddPak_Fullpath
Adds the given pack to the search path.
The pack type is autodetected by the file extension.
Returns true if the file was successfully added to the
search path or if it was already included.
If keep_plain_dirs is set, the pack will be added AFTER the first sequence of
plain directories.
================
*/
static qboolean FS_AddPak_Fullpath( const char *pakfile, qboolean *already_loaded, int flags )
{
searchpath_t *search;
pack_t *pak = NULL;
const char *ext = FS_FileExtension( pakfile );
int i, errorcode = PAK_LOAD_COULDNT_OPEN;
for( search = fs_searchpaths; search; search = search->next )
{
if( search->pack && !Q_stricmp( search->pack->filename, pakfile ))
{
if( already_loaded ) *already_loaded = true;
return true; // already loaded
}
}
if( already_loaded ) *already_loaded = false;
if( !Q_stricmp( ext, "pak" )) pak = FS_LoadPackPAK( pakfile, &errorcode );
else MsgDev( D_ERROR, "\"%s\" does not have a pack extension\n", pakfile );
if( pak )
{
string fullpath;
search = (searchpath_t *)Mem_Alloc( fs_mempool, sizeof( searchpath_t ));
search->pack = pak;
search->next = fs_searchpaths;
search->flags |= flags;
fs_searchpaths = search;
MsgDev( D_REPORT, "Adding pakfile: %s (%i files)\n", pakfile, pak->numfiles );
// time to add in search list all the wads that contains in current pakfile (if do)
for( i = 0; i < pak->numfiles; i++ )
{
if( !Q_stricmp( FS_FileExtension( pak->files[i].name ), "wad" ))
{
Q_sprintf( fullpath, "%s/%s", pakfile, pak->files[i].name );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
return true;
}
else
{
if( errorcode != PAK_LOAD_NO_FILES )
MsgDev( D_ERROR, "FS_AddPak_Fullpath: unable to load pak \"%s\"\n", pakfile );
return false;
}
}
/*
================
FS_AddGameDirectory
@ -719,21 +658,24 @@ void FS_AddGameDirectory( const char *dir, int flags )
if( !Q_stricmp( FS_FileExtension( list.strings[i] ), "pak" ))
{
Q_sprintf( fullpath, "%s%s", dir, list.strings[i] );
FS_AddPak_Fullpath( fullpath, NULL, false, flags );
FS_AddPak_Fullpath( fullpath, NULL, flags );
}
}
FS_AllowDirectPaths( true );
// add any WAD package in the directory
for( i = 0; i < list.numstrings; i++ )
{
if( !Q_stricmp( FS_FileExtension( list.strings[i] ), "wad" ))
{
Q_sprintf( fullpath, "%s%s", dir, list.strings[i] );
FS_AddWad_Fullpath( fullpath, NULL, false, flags );
FS_AddWad_Fullpath( fullpath, NULL, flags );
}
}
stringlistfreecontents( &list );
FS_AllowDirectPaths( false );
// add the directory to the search path
// (unpacked files have the priority over packed files)
@ -742,8 +684,6 @@ void FS_AddGameDirectory( const char *dir, int flags )
search->next = fs_searchpaths;
search->flags = flags;
fs_searchpaths = search;
}
/*
@ -3160,28 +3100,28 @@ byte *W_ReadLump( wfile_t *wad, dlumpinfo_t *lump, long *lumpsizeptr )
// no wads loaded
if( !wad || !lump ) return NULL;
oldpos = tell( wad->handle ); // don't forget restore original position
oldpos = FS_Tell( wad->handle ); // don't forget restore original position
if( lseek( wad->handle, lump->filepos, SEEK_SET ) == -1 )
if( FS_Seek( wad->handle, lump->filepos, SEEK_SET ) == -1 )
{
MsgDev( D_ERROR, "W_ReadLump: %s is corrupted\n", lump->name );
lseek( wad->handle, oldpos, SEEK_SET );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return NULL;
}
buf = (byte *)Mem_Alloc( wad->mempool, lump->disksize );
size = read( wad->handle, buf, lump->disksize );
size = FS_Read( wad->handle, buf, lump->disksize );
if( size < lump->disksize )
{
MsgDev( D_WARN, "W_ReadLump: %s is probably corrupted\n", lump->name );
lseek( wad->handle, oldpos, SEEK_SET );
FS_Seek( wad->handle, oldpos, SEEK_SET );
Mem_Free( buf );
return NULL;
}
if( lumpsizeptr ) *lumpsizeptr = lump->size;
lseek( wad->handle, oldpos, SEEK_SET );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return buf;
}
@ -3211,7 +3151,7 @@ qboolean W_WriteLump( wfile_t *wad, dlumpinfo_t *lump, const void *data, size_t
lump->size = lump->disksize = datasize;
if( write( wad->handle, data, datasize ) == datasize )
if( FS_Write( wad->handle, data, datasize ) == datasize )
return true;
return false;
}
@ -3275,9 +3215,11 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
}
}
wad->handle = open( filename, mod|opt, 0666 );
// NOTE: FS_Open is load wad file from the first pak in the list (while fs_ext_path is false)
if( fs_ext_path ) wad->handle = FS_Open( filename, mode, false );
else wad->handle = FS_Open( FS_FileWithoutPath( filename ), mode, false );
if( wad->handle < 0 )
if( wad->handle == NULL )
{
MsgDev( D_ERROR, "W_Open: couldn't open %s\n", filename );
if( error ) *error = WAD_LOAD_COULDNT_OPEN;
@ -3290,8 +3232,7 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
wad->filetime = FS_SysFileTime( filename );
wad->mempool = Mem_AllocPool( filename );
wadsize = lseek( wad->handle, 0, SEEK_END );
lseek( wad->handle, 0, SEEK_SET );
wadsize = FS_FileLength( wad->handle );
// if the file is opened in "write", "append", or "read/write" mode
if( mod == O_WRONLY || !wadsize )
@ -3306,9 +3247,9 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
hdr.ident = IDWAD3HEADER;
hdr.numlumps = wad->numlumps;
hdr.infotableofs = sizeof( dwadinfo_t );
write( wad->handle, &hdr, sizeof( hdr ));
write( wad->handle, comment, Q_strlen( comment ) + 1 );
wad->infotableofs = tell( wad->handle );
FS_Write( wad->handle, &hdr, sizeof( hdr ));
FS_Write( wad->handle, comment, Q_strlen( comment ) + 1 );
wad->infotableofs = FS_Tell( wad->handle );
}
else if( mod == O_RDWR || mod == O_RDONLY )
{
@ -3316,7 +3257,7 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
wad->mode = O_APPEND;
else wad->mode = O_RDONLY;
if( read( wad->handle, &header, sizeof( dwadinfo_t )) != sizeof( dwadinfo_t ))
if( FS_Read( wad->handle, &header, sizeof( dwadinfo_t )) != sizeof( dwadinfo_t ))
{
MsgDev( D_ERROR, "W_Open: %s can't read header\n", filename );
if( error ) *error = WAD_LOAD_BAD_HEADER;
@ -3351,7 +3292,7 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
wad->infotableofs = header.infotableofs; // save infotableofs position
if( lseek( wad->handle, wad->infotableofs, SEEK_SET ) == -1 )
if( FS_Seek( wad->handle, wad->infotableofs, SEEK_SET ) == -1 )
{
MsgDev( D_ERROR, "W_Open: %s can't find lump allocation table\n", filename );
if( error ) *error = WAD_LOAD_BAD_FOLDERS;
@ -3364,7 +3305,7 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
// NOTE: lumps table can be reallocated for O_APPEND mode
srclumps = (dlumpinfo_t *)Mem_Alloc( wad->mempool, lat_size );
if( read( wad->handle, srclumps, lat_size ) != lat_size )
if( FS_Read( wad->handle, srclumps, lat_size ) != lat_size )
{
MsgDev( D_ERROR, "W_ReadLumpTable: %s has corrupted lump allocation table\n", wad->filename );
if( error ) *error = WAD_LOAD_CORRUPTED;
@ -3390,6 +3331,10 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
k = Q_strlen( Q_strrchr( name, '*' ));
if( k ) name[Q_strlen( name ) - k] = '!';
// check for Quake 'conchars' issues (only lmp loader really allows to read this lame pic)
if( srclumps[i].type == 68 && !Q_stricmp( srclumps[i].name, "conchars" ))
srclumps[i].type = TYP_GFXPIC;
W_AddFileToWad( name, wad, &srclumps[i] );
}
@ -3399,7 +3344,7 @@ wfile_t *W_Open( const char *filename, const char *mode, int *error )
// if we are in append mode - we need started from infotableofs poisition
// overwrite lumptable as well, we have her copy in wad->lumps
if( wad->mode == O_APPEND )
lseek( wad->handle, wad->infotableofs, SEEK_SET );
FS_Seek( wad->handle, wad->infotableofs, SEEK_SET );
}
// and leave the file open
@ -3417,27 +3362,27 @@ void W_Close( wfile_t *wad )
{
if( !wad ) return;
if( wad->handle >= 0 && ( wad->mode == O_APPEND || wad->mode == O_WRONLY ))
if( wad->handle != NULL && ( wad->mode == O_APPEND || wad->mode == O_WRONLY ))
{
dwadinfo_t hdr;
long ofs;
// write the lumpinfo
ofs = tell( wad->handle );
write( wad->handle, wad->lumps, wad->numlumps * sizeof( dlumpinfo_t ));
ofs = FS_Tell( wad->handle );
FS_Write( wad->handle, wad->lumps, wad->numlumps * sizeof( dlumpinfo_t ));
// write the header
hdr.ident = IDWAD3HEADER;
hdr.numlumps = wad->numlumps;
hdr.infotableofs = ofs;
lseek( wad->handle, 0, SEEK_SET );
write( wad->handle, &hdr, sizeof( hdr ));
FS_Seek( wad->handle, 0, SEEK_SET );
FS_Write( wad->handle, &hdr, sizeof( hdr ));
}
Mem_FreePool( &wad->mempool );
if( wad->handle >= 0 )
close( wad->handle );
if( wad->handle != NULL )
FS_Close( wad->handle );
Mem_Free( wad ); // free himself
}
@ -3500,20 +3445,20 @@ size_t W_SaveFile( wfile_t *wad, const char *lump, const void *data, size_t data
return -1;
}
oldpos = tell( wad->handle ); // don't forget restore original position
oldpos = FS_Tell( wad->handle ); // don't forget restore original position
if( lseek( wad->handle, find->filepos, SEEK_SET ) == -1 )
if( FS_Seek( wad->handle, find->filepos, SEEK_SET ) == -1 )
{
MsgDev( D_ERROR, "W_ReplaceLump: %s is corrupted\n", find->name );
lseek( wad->handle, oldpos, SEEK_SET );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return -1;
}
if( write( wad->handle, data, datasize ) != find->disksize )
if( FS_Write( wad->handle, data, datasize ) != find->disksize )
MsgDev( D_WARN, "W_ReplaceLump: %s probably replaced with errors\n", find->name );
// restore old position
lseek( wad->handle, oldpos, SEEK_SET );
FS_Seek( wad->handle, oldpos, SEEK_SET );
return wad->numlumps;
}
@ -3548,7 +3493,7 @@ size_t W_SaveFile( wfile_t *wad, const char *lump, const void *data, size_t data
// write header
Q_strnupr( lumpname, newlump.name, WAD3_NAMELEN );
newlump.filepos = tell( wad->handle );
newlump.filepos = FS_Tell( wad->handle );
newlump.attribs = ATTR_NONE;
newlump.img_type = hint;
newlump.type = type;

View File

@ -245,7 +245,7 @@ qboolean Image_LoadLMP( const char *name, const byte *buffer, size_t filesize )
lmp_t lmp;
byte *fin, *pal;
int rendermode;
int pixels;
int i, pixels;
if( filesize < sizeof( lmp ))
{
@ -257,12 +257,26 @@ qboolean Image_LoadLMP( const char *name, const byte *buffer, size_t filesize )
if( Q_stristr( name, "palette.lmp" ))
return Image_LoadPAL( name, buffer, filesize );
fin = (byte *)buffer;
memcpy( &lmp, fin, sizeof( lmp ));
image.width = lmp.width;
image.height = lmp.height;
rendermode = LUMP_MASKED;
fin += sizeof( lmp );
// greatest hack from id software (image without header)
if( image.hint != IL_HINT_HL && Q_stristr( name, "conchars" ))
{
image.width = image.height = 128;
rendermode = LUMP_MASKED;
filesize += sizeof( lmp );
fin = (byte *)buffer;
// need to remap transparent color from first to last entry
for( i = 0; i < 16384; i++ ) if( !fin[i] ) fin[i] = 0xFF;
}
else
{
fin = (byte *)buffer;
memcpy( &lmp, fin, sizeof( lmp ));
image.width = lmp.width;
image.height = lmp.height;
rendermode = LUMP_MASKED;
fin += sizeof( lmp );
}
pixels = image.width * image.height;