From: MegaBrutal Date: Sun, 31 Dec 2023 03:00:30 +0000 (+0100) Subject: Precache *t.mdl if exists X-Git-Url: http://git.megabrutal.com/?a=commitdiff_plain;h=2ee322ae3b066ced604ec2e9a22ebe89770127f1;p=pmprecache.git Precache *t.mdl if exists --- diff --git a/dllapi.cpp b/dllapi.cpp index 75e920c..ae296dc 100644 --- a/dllapi.cpp +++ b/dllapi.cpp @@ -53,6 +53,7 @@ int gmsgSayText; typedef struct { char model[MAXLENGTH_MODELPATH]; char bmp[MAXLENGTH_MODELPATH]; + char tmdl[MAXLENGTH_MODELPATH]; } precache_paths; typedef struct { @@ -82,9 +83,21 @@ bool addPrecacheEntry(const char* playername, const char* model) { 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); + snprintf(precache_list[i].paths.tmdl, MAXLENGTH_MODELPATH, "models/player/%s/%st.mdl", model, model); + + // Check if BMP exists + if (!fileExists(precache_list[i].paths.bmp)) + precache_list[i].paths.bmp[0] = 0; + + // Check if t.mdl exists, also try alternative path + if (!fileExists(precache_list[i].paths.tmdl)) { + snprintf(precache_list[i].paths.tmdl, MAXLENGTH_MODELPATH, "models/player/%s/%sT.mdl", model, model); + if (!fileExists(precache_list[i].paths.tmdl)) + precache_list[i].paths.tmdl[0] = 0; + } precache_count++; - 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); + LOG_MESSAGE(PLID, "Precache entry %d: playername=\"%s\" modelname=\"%s\" paths.model=\"%s\" paths.bmp=\"%s\" paths.tmdl=\"%s\"", i, precache_list[i].playername, precache_list[i].modelname, precache_list[i].paths.model, precache_list[i].paths.bmp, precache_list[i].paths.tmdl); return true; } else @@ -113,16 +126,33 @@ void ClientPutInServer( edict_t *pEntity ) { } void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) { - bool hasBMP; + bool hasBMP, hasTMDL; LOG_MESSAGE(PLID, "Precaching %d player models", precache_count); for (int i = 0; i < precache_count; i++) { - hasBMP = fileExists(precache_list[i].paths.bmp); + hasBMP = strlen(precache_list[i].paths.bmp) != 0; + hasTMDL = strlen(precache_list[i].paths.tmdl) != 0; + + const char* indicator; + if (hasBMP && hasTMDL) + indicator = "(with bmp+tmdl)"; + else if (hasBMP) + indicator = "(with bmp)"; + else if (hasTMDL) + indicator = "(with tmdl)"; + else + indicator = "(without bmp)"; + LOG_MESSAGE(PLID, "Precaching model %s: %s (contributed by %s)", - hasBMP ? "(with bmp)" : "(without bmp)", + indicator, precache_list[i].modelname, precache_list[i].playername); + g_engfuncs.pfnPrecacheModel(precache_list[i].paths.model); + if (hasBMP) g_engfuncs.pfnPrecacheGeneric(precache_list[i].paths.bmp); + + if (hasTMDL) + g_engfuncs.pfnPrecacheGeneric(precache_list[i].paths.tmdl); } precache_count = 0; RETURN_META(MRES_HANDLED);