diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5f5130896..9d43105e0 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -92,7 +92,13 @@ static void md2_freeModel (model_t *model) static model_t *md2_readModel(const char *filename) { //Filename checking fixed ~Monster Iestyn and Golden - return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC); + if (FIL_FileExists(va("%s"PATHSEP"%s", srb2home, filename))) + return LoadModel(va("%s"PATHSEP"%s", srb2home, filename), PU_STATIC); + + if (FIL_FileExists(va("%s"PATHSEP"%s", srb2path, filename))) + return LoadModel(va("%s"PATHSEP"%s", srb2path, filename), PU_STATIC); + + return NULL; } static inline void md2_printModelInfo (model_t *model) @@ -160,8 +166,12 @@ static GLTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ png_FILE = fopen(pngfilename, "rb"); if (!png_FILE) { + pngfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename); + FIL_ForceExtension(pngfilename, ".png"); + png_FILE = fopen(pngfilename, "rb"); //CONS_Debug(DBG_RENDER, "M_SavePNG: Error on opening %s for loading\n", filename); - return 0; + if (!png_FILE) + return 0; } png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, @@ -288,7 +298,13 @@ static GLTextureFormat_t PCX_Load(const char *filename, int *w, int *h, FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); if (!file) - return 0; + { + pcxfilename = va("%s"PATHSEP"models"PATHSEP"%s", srb2path, filename); + FIL_ForceExtension(pcxfilename, ".pcx"); + file = fopen(pcxfilename, "rb"); + if (!file) + return 0; + } if (fread(&header, sizeof (PcxHeader), 1, file) != 1) { @@ -493,11 +509,15 @@ void HWR_InitModels(void) if (!f) { - CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); - nomd2s = true; - return; + f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + if (!f) + { + CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); + nomd2s = true; + return; + } } - + // length of the player model prefix prefixlen = strlen(PLAYERMODELPREFIX); @@ -569,9 +589,13 @@ void HWR_AddPlayerModel(int skin) // For skins that were added after startup if (!f) { - CONS_Printf("Error while loading models.dat\n"); - nomd2s = true; - return; + f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + if (!f) + { + CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); + nomd2s = true; + return; + } } // length of the player model prefix @@ -624,9 +648,13 @@ void HWR_AddSpriteModel(size_t spritenum) // For sprites that were added after s if (!f) { - CONS_Printf("Error while loading models.dat\n"); - nomd2s = true; - return; + f = fopen(va("%s"PATHSEP"%s", srb2path, "models.dat"), "rt"); + if (!f) + { + CONS_Printf("%s %s\n", M_GetText("Error while loading models.dat:"), strerror(errno)); + nomd2s = true; + return; + } } // Check for any models that match the names of sprite names!