From c448c7b0b141b69087b583ac8083c3cf6371c4cd Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Wed, 22 Nov 2023 05:00:13 +0500 Subject: [PATCH] utils: mdldec: avoid double ".smd" extension output. --- utils/mdldec/mdldec.c | 22 ++++++++++++---------- utils/mdldec/utils.c | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/utils/mdldec/mdldec.c b/utils/mdldec/mdldec.c index 810184be..5cb5b8b1 100644 --- a/utils/mdldec/mdldec.c +++ b/utils/mdldec/mdldec.c @@ -75,11 +75,7 @@ static void TextureNameFix( void ) mstudiotexture_t *texture = (mstudiotexture_t *)( (byte *)texture_hdr + texture_hdr->textureindex ), *texture1; for( i = 0; i < texture_hdr->numtextures; ++i, ++texture ) - { ExtractFileName( texture->name, sizeof( texture->name )); - if( !Q_strchr( texture->name, '.' ) ) - Q_strncat( texture->name, ".bmp", sizeof( texture->name )); - } texture -= i; @@ -149,7 +145,10 @@ static void BodypartNameFix( void ) model = (mstudiomodel_t *)( (byte *)model_hdr + bodypart->modelindex ); for( j = 0; j < bodypart->nummodels; ++j, ++model ) + { ExtractFileName( model->name, sizeof( model->name )); + COM_StripExtension( model->name ); + } model -= j; @@ -207,7 +206,10 @@ static void SequenceNameFix( void ) mstudioseqdesc_t *seqdesc = (mstudioseqdesc_t *)( (byte *)model_hdr + model_hdr->seqindex ), *seqdesc1; for( i = 0; i < model_hdr->numseq; ++i, ++seqdesc ) + { ExtractFileName( seqdesc->label, sizeof( seqdesc->label )); + COM_StripExtension( seqdesc->label ); + } seqdesc -= i; @@ -313,18 +315,18 @@ static qboolean LoadMDL( const char *modelname ) model_hdr = (studiohdr_t *)LoadFile( modelname, &filesize ); - if( filesize < sizeof( studiohdr_t ) || filesize != model_hdr->length ) - { - fprintf( stderr, "ERROR: Wrong file size! File %s may be corrupted!\n", modelname ); - return false; - } - if( !model_hdr ) { fprintf( stderr, "ERROR: Can't open %s\n", modelname ); return false; } + if( filesize < sizeof( studiohdr_t ) || filesize != model_hdr->length ) + { + fprintf( stderr, "ERROR: Wrong file size! File %s may be corrupted!\n", modelname ); + return false; + } + if( memcmp( &model_hdr->ident, id_mdlhdr, sizeof( id_mdlhdr ) ) ) { if( !memcmp( &model_hdr->ident, id_seqhdr, sizeof( id_seqhdr ) ) ) diff --git a/utils/mdldec/utils.c b/utils/mdldec/utils.c index 6808e92a..6b851738 100644 --- a/utils/mdldec/utils.c +++ b/utils/mdldec/utils.c @@ -70,7 +70,7 @@ void ExtractFileName( char *name, size_t size ) if( Q_strpbrk( name, "/\\" )) { - COM_FileBase( name, tmp, sizeof( tmp )); + Q_strncpy( tmp, COM_FileWithoutPath( name ), sizeof( tmp )); Q_strncpy( name, tmp, size ); } }