diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-04 17:59:49 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-04 17:59:49 +0100 |
| commit | 7cb73865108a9b18430df4c21e94246c159c2ffc (patch) | |
| tree | fcb42139efa5d6890d5cc43f2d50f033f5181cbf | |
| parent | Add chams (diff) | |
| download | hl2h-7cb73865108a9b18430df4c21e94246c159c2ffc.tar.gz hl2h-7cb73865108a9b18430df4c21e94246c159c2ffc.zip | |
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.
| -rw-r--r-- | src/world.cpp | 41 |
1 files changed, 31 insertions, 10 deletions
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) { | |||
| 1020 | InvalidFn invalid = (InvalidFn)vfunc<InvalidFn>(ms, 75); | 1020 | InvalidFn invalid = (InvalidFn)vfunc<InvalidFn>(ms, 75); |
| 1021 | GetFn get = (GetFn)vfunc<GetFn>(ms, 76); | 1021 | GetFn get = (GetFn)vfunc<GetFn>(ms, 76); |
| 1022 | CountFn count = (CountFn)vfunc<CountFn>(ms, 77); | 1022 | CountFn count = (CountFn)vfunc<CountFn>(ms, 77); |
| 1023 | const char *candidates[] = {name, | ||
| 1024 | "models/debug/debugwhite2", | ||
| 1025 | "models/debug/debugwhite3", | ||
| 1026 | "vgui/white", | ||
| 1027 | "debug/debugtranslucentsinglecolor", | ||
| 1028 | "debug/debugwireframevertexcolorignorez", | ||
| 1029 | nullptr}; | ||
| 1023 | int total = count ? count(ms) : 0; | 1030 | int total = count ? count(ms) : 0; |
| 1024 | if (total > 0 && total < 200000) { | 1031 | if (total > 0 && total < 200000) { |
| 1025 | unsigned short h = first(ms); | 1032 | unsigned short h = first(ms); |
| @@ -1029,20 +1036,34 @@ void *world_find_material(const char *name) { | |||
| 1029 | if (mat) { | 1036 | if (mat) { |
| 1030 | NameFn mat_name = (NameFn)vfunc<NameFn>(mat, 0); | 1037 | NameFn mat_name = (NameFn)vfunc<NameFn>(mat, 0); |
| 1031 | const char *n = mat_name(mat); | 1038 | const char *n = mat_name(mat); |
| 1032 | if (n && strcmp(n, name) == 0) | 1039 | if (n) { |
| 1033 | return mat; | 1040 | for (int c = 0; candidates[c]; c++) |
| 1041 | if (strcmp(n, candidates[c]) == 0) | ||
| 1042 | return mat; | ||
| 1043 | } | ||
| 1034 | } | 1044 | } |
| 1035 | h = next(ms, h); | 1045 | h = next(ms, h); |
| 1036 | } | 1046 | } |
| 1037 | } | 1047 | } |
| 1038 | // Not resident yet: let the material system load it. FindMaterial is slot | 1048 | // Not resident yet: let the material system load it. |
| 1039 | // 71 (IsMaterialLoaded is 72, FirstMaterial 73). | ||
| 1040 | using FindFn = void *(*)(void *, const char *, const char *, bool, | 1049 | using FindFn = void *(*)(void *, const char *, const char *, bool, |
| 1041 | const char *); | 1050 | const char *); |
| 1042 | void *mat = vfunc<FindFn>(ms, 71)(ms, name, "Model textures", false, nullptr); | 1051 | static const char *groups[] = {"Model textures", "Other textures", nullptr}; |
| 1043 | if (!mat) | 1052 | for (int c = 0; candidates[c]; c++) { |
| 1044 | return nullptr; | 1053 | for (int g = 0; groups[g]; g++) { |
| 1045 | NameFn mat_name = (NameFn)vfunc<NameFn>(mat, 0); | 1054 | void *mat = vfunc<FindFn>(ms, 71)(ms, candidates[c], groups[g], false, |
| 1046 | const char *n = mat_name(mat); | 1055 | nullptr); |
| 1047 | return (n && strcmp(n, name) == 0) ? mat : nullptr; | 1056 | if (!mat) { |
| 1057 | logf("chams: FindMaterial(%s, %s) -> null", candidates[c], groups[g]); | ||
| 1058 | continue; | ||
| 1059 | } | ||
| 1060 | NameFn mat_name = (NameFn)vfunc<NameFn>(mat, 0); | ||
| 1061 | const char *n = mat_name(mat); | ||
| 1062 | logf("chams: FindMaterial(%s, %s) -> %p name=%s", candidates[c], | ||
| 1063 | groups[g], mat, n ? n : "?"); | ||
| 1064 | if (n && strstr(n, "debugwhite")) | ||
| 1065 | return mat; | ||
| 1066 | } | ||
| 1067 | } | ||
| 1068 | return nullptr; | ||
| 1048 | } | 1069 | } |
