use safe strings in shaderInfo_s

turn ImageLoad() to expect extensionless path as input
This commit is contained in:
Garux 2021-01-19 18:58:18 +03:00
parent 9590d602d3
commit c3437b7833
3 changed files with 27 additions and 28 deletions

View File

@ -312,6 +312,7 @@ image_t *ImageFind( const char *name ){
/* /*
ImageLoad() ImageLoad()
loads an rgba image and returns a pointer to the image_t struct or NULL if not found loads an rgba image and returns a pointer to the image_t struct or NULL if not found
expects extensionless path as input
*/ */
image_t *ImageLoad( const char *filename ){ image_t *ImageLoad( const char *filename ){
@ -330,9 +331,7 @@ image_t *ImageLoad( const char *filename ){
return NULL; return NULL;
} }
/* strip file extension off name */
strcpy( name, filename ); strcpy( name, filename );
StripExtension( name );
/* try to find existing image */ /* try to find existing image */
image = ImageFind( name ); image = ImageFind( name );

View File

@ -767,12 +767,12 @@ typedef struct shaderInfo_s
String64 skyParmsImageBase; /* ydnar: for skies */ String64 skyParmsImageBase; /* ydnar: for skies */
char editorImagePath[ MAX_QPATH ]; /* use this image to generate texture coordinates */ String64 editorImagePath; /* use this image to generate texture coordinates */
char lightImagePath[ MAX_QPATH ]; /* use this image to generate color / averageColor */ String64 lightImagePath; /* use this image to generate color / averageColor */
char normalImagePath[ MAX_QPATH ]; /* ydnar: normalmap image for bumpmapping */ String64 normalImagePath; /* ydnar: normalmap image for bumpmapping */
implicitMap_t implicitMap; /* ydnar: enemy territory implicit shaders */ implicitMap_t implicitMap; /* ydnar: enemy territory implicit shaders */
char implicitImagePath[ MAX_QPATH ]; String64 implicitImagePath;
image_t *shaderImage; image_t *shaderImage;
image_t *lightImage; image_t *lightImage;

View File

@ -448,7 +448,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){
"\t\trgbGen identity\n" "\t\trgbGen identity\n"
"\t}\n" "\t}\n"
"}\n", "}\n",
si->implicitImagePath ); si->implicitImagePath.c_str() );
} }
/* et: implicitMask */ /* et: implicitMask */
@ -475,8 +475,8 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){
"\t\trgbGen identity\n" "\t\trgbGen identity\n"
"\t}\n" "\t}\n"
"}\n", "}\n",
si->implicitImagePath, si->implicitImagePath.c_str(),
si->implicitImagePath ); si->implicitImagePath.c_str() );
} }
/* et: implicitBlend */ /* et: implicitBlend */
@ -496,7 +496,7 @@ shaderInfo_t *CustomShader( shaderInfo_t *si, const char *find, char *replace ){
"\t}\n" "\t}\n"
"\tq3map_styleMarker\n" "\tq3map_styleMarker\n"
"}\n", "}\n",
si->implicitImagePath ); si->implicitImagePath.c_str() );
} }
/* default shader text */ /* default shader text */
@ -775,7 +775,7 @@ static void LoadShaderImages( shaderInfo_t *si ){
si->normalImage = ImageLoad( si->normalImagePath ); si->normalImage = ImageLoad( si->normalImagePath );
if ( si->normalImage != NULL ) { if ( si->normalImage != NULL ) {
Sys_FPrintf( SYS_VRB, "Shader %s has\n" Sys_FPrintf( SYS_VRB, "Shader %s has\n"
" NM %s\n", si->shader.c_str(), si->normalImagePath ); " NM %s\n", si->shader.c_str(), si->normalImagePath.c_str() );
} }
} }
@ -1046,7 +1046,7 @@ static void ParseShaderFile( const char *filename ){
} }
/* only care about images if we don't have a editor/light image */ /* only care about images if we don't have a editor/light image */
if ( strEmpty( si->editorImagePath ) && strEmpty( si->lightImagePath ) && strEmpty( si->implicitImagePath ) ) { if ( si->editorImagePath.empty() && si->lightImagePath.empty() && si->implicitImagePath.empty() ) {
/* digest any images */ /* digest any images */
if ( striEqual( token, "map" ) || if ( striEqual( token, "map" ) ||
striEqual( token, "clampMap" ) || striEqual( token, "clampMap" ) ||
@ -1062,8 +1062,8 @@ static void ParseShaderFile( const char *filename ){
/* get an image */ /* get an image */
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) { if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
strcpy( si->lightImagePath, token ); StripExtension( token );
DefaultExtension( si->lightImagePath, ".tga" ); si->lightImagePath = token;
/* debug code */ /* debug code */
//% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath ); //% Sys_FPrintf( SYS_VRB, "Deduced shader image: %s\n", si->lightImagePath );
@ -1178,10 +1178,10 @@ static void ParseShaderFile( const char *filename ){
si->implicitMap = IM_OPAQUE; si->implicitMap = IM_OPAQUE;
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
if ( strEqual( token, "-" ) ) { if ( strEqual( token, "-" ) ) {
sprintf( si->implicitImagePath, "%s.tga", si->shader.c_str() ); si->implicitImagePath = si->shader;
} }
else{ else{
strcpy( si->implicitImagePath, token ); si->implicitImagePath = token;
} }
} }
@ -1189,10 +1189,10 @@ static void ParseShaderFile( const char *filename ){
si->implicitMap = IM_MASKED; si->implicitMap = IM_MASKED;
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
if ( strEqual( token, "-" ) ) { if ( strEqual( token, "-" ) ) {
sprintf( si->implicitImagePath, "%s.tga", si->shader.c_str() ); si->implicitImagePath = si->shader;
} }
else{ else{
strcpy( si->implicitImagePath, token ); si->implicitImagePath = token;
} }
} }
@ -1200,10 +1200,10 @@ static void ParseShaderFile( const char *filename ){
si->implicitMap = IM_MASKED; si->implicitMap = IM_MASKED;
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
if ( strEqual( token, "-" ) ) { if ( strEqual( token, "-" ) ) {
sprintf( si->implicitImagePath, "%s.tga", si->shader.c_str() ); si->implicitImagePath = si->shader;
} }
else{ else{
strcpy( si->implicitImagePath, token ); si->implicitImagePath = token;
} }
} }
@ -1215,22 +1215,22 @@ static void ParseShaderFile( const char *filename ){
/* qer_editorimage <image> */ /* qer_editorimage <image> */
else if ( striEqual( token, "qer_editorImage" ) ) { else if ( striEqual( token, "qer_editorImage" ) ) {
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
strcpy( si->editorImagePath, token ); StripExtension( token );
DefaultExtension( si->editorImagePath, ".tga" ); si->editorImagePath = token;
} }
/* ydnar: q3map_normalimage <image> (bumpmapping normal map) */ /* ydnar: q3map_normalimage <image> (bumpmapping normal map) */
else if ( striEqual( token, "q3map_normalImage" ) ) { else if ( striEqual( token, "q3map_normalImage" ) ) {
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
strcpy( si->normalImagePath, token ); StripExtension( token );
DefaultExtension( si->normalImagePath, ".tga" ); si->normalImagePath = token;
} }
/* q3map_lightimage <image> */ /* q3map_lightimage <image> */
else if ( striEqual( token, "q3map_lightImage" ) ) { else if ( striEqual( token, "q3map_lightImage" ) ) {
GetTokenAppend( shaderText, false ); GetTokenAppend( shaderText, false );
strcpy( si->lightImagePath, token ); StripExtension( token );
DefaultExtension( si->lightImagePath, ".tga" ); si->lightImagePath = token;
} }
/* ydnar: skyparms <outer image> <cloud height> <inner image> */ /* ydnar: skyparms <outer image> <cloud height> <inner image> */
@ -1243,8 +1243,8 @@ static void ParseShaderFile( const char *filename ){
si->skyParmsImageBase = token; si->skyParmsImageBase = token;
/* use top image as sky light image */ /* use top image as sky light image */
if ( strEmpty( si->lightImagePath ) ) { if ( si->lightImagePath.empty() ) {
sprintf( si->lightImagePath, "%s_up.tga", si->skyParmsImageBase.c_str() ); si->lightImagePath( si->skyParmsImageBase, "_up" );
} }
} }