#define MAXLENGTH_PLAYERNAME 64
#define MAXLENGTH_MODELNAME 64
#define MAXLENGTH_MODELPATH 256
+typedef struct {
+ char model[MAXLENGTH_MODELPATH];
+ char bmp[MAXLENGTH_MODELPATH];
+} precache_paths;
+
typedef struct {
char playername[MAXLENGTH_PLAYERNAME];
char modelname[MAXLENGTH_MODELNAME];
- char modelpath[MAXLENGTH_MODELPATH];
+ precache_paths paths;
} precache_entry;
#define MAX_PRECACHE_COUNT 32
precache_entry precache_list[MAX_PRECACHE_COUNT];
unsigned short int precache_count = 0;
-bool playerModelFileExists(const char* path) {
- return access(path, R_OK) == 0;
+bool fileExists(const char* path) {
+ char fullpath[256];
+ snprintf(fullpath, sizeof(fullpath), "%s/%s", &gGamedir[0], path);
+ return access(fullpath, R_OK) == 0;
}
bool addPrecacheEntry(const char* playername, const char* model) {
if ((i == precache_count) && (i < MAX_PRECACHE_COUNT) && (streq != 0)) {
strncpy(precache_list[i].playername, playername, MAXLENGTH_PLAYERNAME - 1);
strncpy(precache_list[i].modelname, model, MAXLENGTH_MODELNAME - 1);
- snprintf(precache_list[i].modelpath, MAXLENGTH_MODELPATH, "models/player/%s/%s.mdl", model, model);
+ // Ensure null-termination
precache_list[i].playername[MAXLENGTH_PLAYERNAME - 1] = 0;
precache_list[i].modelname[MAXLENGTH_MODELNAME - 1] = 0;
+
+ snprintf(precache_list[i].paths.model, MAXLENGTH_MODELPATH, "models/player/%s/%s.mdl", model, model);
+ snprintf(precache_list[i].paths.bmp, MAXLENGTH_MODELPATH, "models/player/%s/%s.bmp", model, model);
+
precache_count++;
- LOG_MESSAGE(PLID, "Precache entry %d: playername=\"%s\" modelname=\"%s\" modelpath=\"%s\"", i, precache_list[i].playername, precache_list[i].modelname, precache_list[i].modelpath);
+ LOG_MESSAGE(PLID, "Precache entry %d: playername=\"%s\" modelname=\"%s\" paths.model=\"%s\" paths.bmp=\"%s\"", i, precache_list[i].playername, precache_list[i].modelname, precache_list[i].paths.model, precache_list[i].paths.bmp);
return true;
}
else
const char* playername = STRING(pEntity->v.netname);
char* modelname = g_engfuncs.pfnInfoKeyValue( g_engfuncs.pfnGetInfoKeyBuffer( pEntity ), "model" );
char modelfile[256];
- snprintf(modelfile, sizeof(modelfile), "%s/models/player/%s/%s.mdl", &gGamedir[0], modelname, modelname);
+ snprintf(modelfile, sizeof(modelfile), "models/player/%s/%s.mdl", modelname, modelname);
LOG_MESSAGE(PLID, "Player %s is using model %s", playername, modelname);
- if (playerModelFileExists( modelfile )) {
+ if (fileExists( modelfile )) {
LOG_MESSAGE(PLID, "Model %s is present on server", modelname);
SAY(pEntity, "Your model is present on the server, it will be precached for the next round!");
if (addPrecacheEntry( playername, modelname ))
LOG_MESSAGE(PLID, "Precaching %d player models", precache_count);
for (int i = 0; i < precache_count; i++) {
LOG_MESSAGE(PLID, "Precaching model: %s (contributed by %s)", precache_list[i].modelname, precache_list[i].playername);
- LOG_MESSAGE(PLID, "modelpath = %s", precache_list[i].modelpath);
- g_engfuncs.pfnPrecacheModel( precache_list[i].modelpath );
+ g_engfuncs.pfnPrecacheModel( precache_list[i].paths.model );
+ if (fileExists( precache_list[i].paths.bmp ))
+ {
+ LOG_MESSAGE(PLID, "Precaching bmp: %s", precache_list[i].paths.bmp);
+ g_engfuncs.pfnPrecacheGeneric( precache_list[i].paths.bmp );
+ }
+ else
+ LOG_MESSAGE(PLID, "File not found: %s", precache_list[i].paths.bmp);
}
precache_count = 0;
RETURN_META(MRES_HANDLED);