From 7cb73865108a9b18430df4c21e94246c159c2ffc Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 17:59:49 +0100 Subject: Chams: material fallbacks and FindMaterial diagnostics models/debug/debugwhite is not resident and FindMaterial did not return it. Log each FindMaterial attempt and fall back to debugwhite2/3, vgui/white, debug/debugtranslucentsinglecolor and the ignorez debug wireframe material so chams can still render. --- src/world.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/world.cpp b/src/world.cpp index ab0c134..15a93ec 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1020,6 +1020,13 @@ void *world_find_material(const char *name) { InvalidFn invalid = (InvalidFn)vfunc(ms, 75); GetFn get = (GetFn)vfunc(ms, 76); CountFn count = (CountFn)vfunc(ms, 77); + const char *candidates[] = {name, + "models/debug/debugwhite2", + "models/debug/debugwhite3", + "vgui/white", + "debug/debugtranslucentsinglecolor", + "debug/debugwireframevertexcolorignorez", + nullptr}; int total = count ? count(ms) : 0; if (total > 0 && total < 200000) { unsigned short h = first(ms); @@ -1029,20 +1036,34 @@ void *world_find_material(const char *name) { if (mat) { NameFn mat_name = (NameFn)vfunc(mat, 0); const char *n = mat_name(mat); - if (n && strcmp(n, name) == 0) - return mat; + if (n) { + for (int c = 0; candidates[c]; c++) + if (strcmp(n, candidates[c]) == 0) + return mat; + } } h = next(ms, h); } } - // Not resident yet: let the material system load it. FindMaterial is slot - // 71 (IsMaterialLoaded is 72, FirstMaterial 73). + // Not resident yet: let the material system load it. using FindFn = void *(*)(void *, const char *, const char *, bool, const char *); - void *mat = vfunc(ms, 71)(ms, name, "Model textures", false, nullptr); - if (!mat) - return nullptr; - NameFn mat_name = (NameFn)vfunc(mat, 0); - const char *n = mat_name(mat); - return (n && strcmp(n, name) == 0) ? mat : nullptr; + static const char *groups[] = {"Model textures", "Other textures", nullptr}; + for (int c = 0; candidates[c]; c++) { + for (int g = 0; groups[g]; g++) { + void *mat = vfunc(ms, 71)(ms, candidates[c], groups[g], false, + nullptr); + if (!mat) { + logf("chams: FindMaterial(%s, %s) -> null", candidates[c], groups[g]); + continue; + } + NameFn mat_name = (NameFn)vfunc(mat, 0); + const char *n = mat_name(mat); + logf("chams: FindMaterial(%s, %s) -> %p name=%s", candidates[c], + groups[g], mat, n ? n : "?"); + if (n && strstr(n, "debugwhite")) + return mat; + } + } + return nullptr; } -- cgit v1.2.3