Precache *t.mdl if exists
authorMegaBrutal <megabrutal+github@megabrutal.com>
Sun, 31 Dec 2023 03:00:30 +0000 (04:00 +0100)
committerMegaBrutal <megabrutal+github@megabrutal.com>
Sun, 31 Dec 2023 03:00:30 +0000 (04:00 +0100)
dllapi.cpp

index 75e920c16bb8aff499b31b1548a706f3ff164d46..ae296dc0eb86ccd9a0f74e56c9a7dd137f2764bb 100644 (file)
@@ -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);