Browse Source

engine: common: make blue-shift map detect more robust

pull/2/head
Alibek Omarov 3 years ago committed by a1batross
parent
commit
771c359ed0
  1. 44
      engine/common/mod_bmodel.c

44
engine/common/mod_bmodel.c

@ -2736,6 +2736,42 @@ static void Mod_LoadLighting( dbspmodel_t *bmod )
} }
} }
/*
=================
Mod_LumpLooksLikePlanes
=================
*/
static qboolean Mod_LumpLooksLikePlanes( const byte *in, dlump_t *lump, qboolean fast )
{
int numplanes, i;
const dplane_t *planes;
if( lump->filelen < sizeof( dplane_t ) &&
lump->filelen % sizeof( dplane_t ) != 0 )
return false;
if( fast )
return true;
numplanes = lump->filelen / sizeof( dplane_t );
planes = (const dplane_t*)(in + lump->fileofs);
for( i = 0; i < numplanes; i++ )
{
if( IS_NAN( planes[i].dist ) )
return false;
if( VectorIsNAN( planes[i].normal ))
return false;
if( planes[i].type > 6 )
return false;
}
return true;
}
/* /*
================= =================
Mod_LoadBmodelLumps Mod_LoadBmodelLumps
@ -2785,8 +2821,8 @@ qboolean Mod_LoadBmodelLumps( const byte *mod_base, qboolean isworld )
if( header->version == HLBSP_VERSION ) if( header->version == HLBSP_VERSION )
{ {
// only relevant for half-life maps // only relevant for half-life maps
if( header->lumps[LUMP_ENTITIES].fileofs <= 1024 && if( !Mod_LumpLooksLikePlanes( mod_base, &header->lumps[LUMP_PLANES], false ) &&
(header->lumps[LUMP_ENTITIES].filelen % sizeof( dplane_t )) == 0 ) Mod_LumpLooksLikePlanes( mod_base, &header->lumps[LUMP_ENTITIES], false ))
{ {
// blue-shift swapped lumps // blue-shift swapped lumps
srclumps[0].lumpnumber = LUMP_PLANES; srclumps[0].lumpnumber = LUMP_PLANES;
@ -2913,8 +2949,8 @@ qboolean Mod_TestBmodelLumps( const char *name, const byte *mod_base, qboolean s
if( header->version == HLBSP_VERSION ) if( header->version == HLBSP_VERSION )
{ {
// only relevant for half-life maps // only relevant for half-life maps
if( header->lumps[LUMP_ENTITIES].fileofs <= 1024 && if( Mod_LumpLooksLikePlanes( mod_base, &header->lumps[LUMP_ENTITIES], true ) &&
(header->lumps[LUMP_ENTITIES].filelen % sizeof( dplane_t )) == 0 ) !Mod_LumpLooksLikePlanes( mod_base, &header->lumps[LUMP_PLANES], true ))
{ {
// blue-shift swapped lumps // blue-shift swapped lumps
srclumps[0].lumpnumber = LUMP_PLANES; srclumps[0].lumpnumber = LUMP_PLANES;

Loading…
Cancel
Save