diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-03 23:58:59 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-03 23:58:59 +0100 |
| commit | 9c4455af43da34127864b09ad2a3d3e996c9dce1 (patch) | |
| tree | eb3754763db7c00fe664b900f9a560057bcb9955 /src/menu.cpp | |
| parent | World: add skybox changer (diff) | |
| download | hl2h-9c4455af43da34127864b09ad2a3d3e996c9dce1.tar.gz hl2h-9c4455af43da34127864b09ad2a3d3e996c9dce1.zip | |
World: replace skybox changer with a PNG skybox image
sv_skyname did not take effect at runtime in this build, so the Skybox card now
replaces the skybox materials' textures with <config dir>/skybox.png.
The PNG is decoded through libpng16's simplified API (dlopen'ed, so no new link
dependency) and uploaded with IMaterialSystem::CreateTextureFromBits as an
RGBA8888 texture. IMaterialVar::SetTextureValue assigns it to $basetexture and
the HDR variants for every material in the SkyBox textures group (all six
faces get the same image).
Original textures are recorded per material/var (texture pointer plus string
fallback) and restored when the feature is off. Records survive level changes
so a reused sky material is still restorable; the override is re-applied to a
new map automatically. The card shows the image path and has a Reload image
button; a missing/unreadable PNG raises an error toast.
Diffstat (limited to 'src/menu.cpp')
| -rw-r--r-- | src/menu.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/menu.cpp b/src/menu.cpp index dfd973d..92131d4 100644 --- a/src/menu.cpp +++ b/src/menu.cpp | |||
| @@ -59,8 +59,7 @@ bool g_fog_disable = false; | |||
| 59 | int g_fog_rgb[3] = {160, 170, 190}; | 59 | int g_fog_rgb[3] = {160, 170, 190}; |
| 60 | int g_fog_start = 200; | 60 | int g_fog_start = 200; |
| 61 | int g_fog_end = 3000; | 61 | int g_fog_end = 3000; |
| 62 | FeatureState g_skybox{false, 0}; // sv_skyname override | 62 | FeatureState g_skybox{false, 0}; // skybox.png image override |
| 63 | int g_skybox_choice = 0; // 0 = map default | ||
| 64 | bool g_item_health = true; | 63 | bool g_item_health = true; |
| 65 | bool g_item_ammo = true; | 64 | bool g_item_ammo = true; |
| 66 | bool g_item_armor = true; | 65 | bool g_item_armor = true; |
| @@ -214,8 +213,8 @@ void config_save() { | |||
| 214 | "start=%d\nend=%d\nskybox=%d\ndisable=%d\n", | 213 | "start=%d\nend=%d\nskybox=%d\ndisable=%d\n", |
| 215 | g_fog.active, g_fog.bind, g_fog_rgb[0], g_fog_rgb[1], g_fog_rgb[2], | 214 | g_fog.active, g_fog.bind, g_fog_rgb[0], g_fog_rgb[1], g_fog_rgb[2], |
| 216 | g_fog_start, g_fog_end, (int)g_fog_skybox, (int)g_fog_disable); | 215 | g_fog_start, g_fog_end, (int)g_fog_skybox, (int)g_fog_disable); |
| 217 | fprintf(f, "[skybox]\nactive=%d\nbind=%d\nchoice=%d\n", g_skybox.active, | 216 | fprintf(f, "[skybox]\nactive=%d\nbind=%d\n", g_skybox.active, |
| 218 | g_skybox.bind, g_skybox_choice); | 217 | g_skybox.bind); |
| 219 | fprintf(f, "[items]\nactive=%d\nbind=%d\nhealth=%d\nammo=%d\n" | 218 | fprintf(f, "[items]\nactive=%d\nbind=%d\nhealth=%d\nammo=%d\n" |
| 220 | "armor=%d\nweapons=%d\ncrates=%d\ndistance=%d\nmax_dist=%d\n", | 219 | "armor=%d\nweapons=%d\ncrates=%d\ndistance=%d\nmax_dist=%d\n", |
| 221 | g_item_esp.active, g_item_esp.bind, (int)g_item_health, | 220 | g_item_esp.active, g_item_esp.bind, (int)g_item_health, |
| @@ -250,7 +249,7 @@ static bool config_load() { | |||
| 250 | FeatureState *cur = nullptr; | 249 | FeatureState *cur = nullptr; |
| 251 | bool in_esp = false, in_bhop = false, in_aim = false, in_silent = false, | 250 | bool in_esp = false, in_bhop = false, in_aim = false, in_silent = false, |
| 252 | in_jumpbug = false, in_spread = false, in_items = false, | 251 | in_jumpbug = false, in_spread = false, in_items = false, |
| 253 | in_tint = false, in_fog = false, in_skybox = false; | 252 | in_tint = false, in_fog = false; |
| 254 | while (fgets(line, sizeof(line), f)) { | 253 | while (fgets(line, sizeof(line), f)) { |
| 255 | line[strcspn(line, "\r\n")] = 0; | 254 | line[strcspn(line, "\r\n")] = 0; |
| 256 | if (line[0] == '[') { | 255 | if (line[0] == '[') { |
| @@ -293,7 +292,6 @@ static bool config_load() { | |||
| 293 | in_items = (cur == &g_item_esp); | 292 | in_items = (cur == &g_item_esp); |
| 294 | in_tint = (cur == &g_world_tint); | 293 | in_tint = (cur == &g_world_tint); |
| 295 | in_fog = (cur == &g_fog); | 294 | in_fog = (cur == &g_fog); |
| 296 | in_skybox = (cur == &g_skybox); | ||
| 297 | } else if (cur) { | 295 | } else if (cur) { |
| 298 | char *eq = strchr(line, '='); | 296 | char *eq = strchr(line, '='); |
| 299 | if (!eq) | 297 | if (!eq) |
| @@ -414,12 +412,6 @@ static bool config_load() { | |||
| 414 | g_fog_disable = atoi(val) != 0; | 412 | g_fog_disable = atoi(val) != 0; |
| 415 | } | 413 | } |
| 416 | } | 414 | } |
| 417 | if (in_skybox && strcmp(key, "choice") == 0) { | ||
| 418 | int v = atoi(val); | ||
| 419 | if (v < 0) v = 0; | ||
| 420 | if (v >= skybox_option_count()) v = 0; | ||
| 421 | g_skybox_choice = v; | ||
| 422 | } | ||
| 423 | if (in_esp) { | 415 | if (in_esp) { |
| 424 | if (strcmp(key, "neutral") == 0) | 416 | if (strcmp(key, "neutral") == 0) |
| 425 | g_esp_opt[ESP_OPT_SHOW_NEUTRAL] = atoi(val) != 0; | 417 | g_esp_opt[ESP_OPT_SHOW_NEUTRAL] = atoi(val) != 0; |
| @@ -459,6 +451,16 @@ const char *config_path_cstr() { | |||
| 459 | return path.c_str(); | 451 | return path.c_str(); |
| 460 | } | 452 | } |
| 461 | 453 | ||
| 454 | const char *config_file_cstr(const char *name) { | ||
| 455 | static std::string path; | ||
| 456 | std::string p = config_path(); | ||
| 457 | size_t slash = p.find_last_of('/'); | ||
| 458 | std::string dir = | ||
| 459 | slash == std::string::npos ? std::string(".") : p.substr(0, slash); | ||
| 460 | path = dir + "/" + (name ? name : ""); | ||
| 461 | return path.c_str(); | ||
| 462 | } | ||
| 463 | |||
| 462 | void config_reset_defaults() { | 464 | void config_reset_defaults() { |
| 463 | g_bhop = {true, 0}; | 465 | g_bhop = {true, 0}; |
| 464 | g_bhop_autostrafe = true; | 466 | g_bhop_autostrafe = true; |
| @@ -489,7 +491,6 @@ void config_reset_defaults() { | |||
| 489 | g_fog_start = 200; | 491 | g_fog_start = 200; |
| 490 | g_fog_end = 3000; | 492 | g_fog_end = 3000; |
| 491 | g_skybox = {false, 0}; | 493 | g_skybox = {false, 0}; |
| 492 | g_skybox_choice = 0; | ||
| 493 | g_item_health = true; | 494 | g_item_health = true; |
| 494 | g_item_ammo = true; | 495 | g_item_ammo = true; |
| 495 | g_item_armor = true; | 496 | g_item_armor = true; |
