From e339d1dc45b3113648552b0002e0c15f55e61cb2 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 6 Nov 2026 16:30:10 +0100 Subject: Config: generate save/load/reset from one settings table Every persisted setting now lives in a single descriptor table (config_table.cpp) with its section, key, type, default and clamp range. config_save(), config_load() and config_reset_defaults() iterate it, so the three functions can no longer disagree about defaults or bounds, and the old hand-written 350-line parser is gone. Section and key names are unchanged, so existing config files keep loading, and the duplicated [view] scalar clamp block is replaced by per-entry limits. --- src/config_table.cpp | 230 +++++++++++++++++++++++ src/features.h | 5 + src/menu.cpp | 513 +-------------------------------------------------- 3 files changed, 238 insertions(+), 510 deletions(-) create mode 100644 src/config_table.cpp (limited to 'src') diff --git a/src/config_table.cpp b/src/config_table.cpp new file mode 100644 index 0000000..f688d12 --- /dev/null +++ b/src/config_table.cpp @@ -0,0 +1,230 @@ +// config_table.cpp — every persisted setting in one descriptor table. +// +// config_save(), config_load() and config_reset_defaults() are generated from +// this table, so adding an option no longer means editing three functions (and +// getting the clamp bounds out of sync between them). +#include "hl2h.h" + +#include + +namespace { + +enum SettingType { S_BOOL, S_INT }; + +struct SettingDesc { + const char *section; + const char *key; + SettingType type; + void *ptr; + int def; + int lo; + int hi; +}; + +// A FeatureState is persisted as the usual active/bind pair. +#define FEAT(sec, state, def_active, def_bind) \ + {sec, "active", S_BOOL, &(state).active, def_active, 0, 1}, \ + {sec, "bind", S_INT, &(state).bind, def_bind, 0, 1000} + +const SettingDesc kSettings[] = { + // movement + FEAT("bhop", g_bhop, 1, 0), + {"bhop", "autostrafe", S_BOOL, &g_bhop_autostrafe, 1, 0, 1}, + FEAT("abh", g_abh, 1, 0), + FEAT("jumpbug", g_jumpbug, 1, 0), + {"jumpbug", "assist", S_BOOL, &g_jumpbug_assist, 0, 0, 1}, + FEAT("melee", g_melee, 1, 0), + {"movement", "crouchjump", S_BOOL, &g_auto_crouchjump, 0, 0, 1}, + {"movement", "edgejump", S_BOOL, &g_edge_jump, 0, 0, 1}, + + // spread + FEAT("spread", g_spread, 1, 0), + {"spread", "no_spread", S_BOOL, &g_spread_no_spread, 1, 0, 1}, + {"spread", "engine", S_BOOL, &g_spread_engine, 1, 0, 1}, + + // aim + FEAT("aimbot", g_aimbot, 1, 604), + {"aimbot", "smooth", S_INT, &g_aim_smooth, 5, 1, 45}, + {"aimbot", "vischeck", S_BOOL, &g_aim_vischeck, 1, 0, 1}, + {"aimbot", "fov", S_INT, &g_aim_fov, 60, 1, 180}, + {"aimbot", "fov_circle", S_BOOL, &g_aim_fov_circle, 1, 0, 1}, + {"aimbot", "punch", S_BOOL, &g_aim_punch, 1, 0, 1}, + {"aimbot", "bone_head", S_BOOL, &g_aim_bones[AIM_BONE_HEAD], 1, 0, 1}, + {"aimbot", "bone_torso", S_BOOL, &g_aim_bones[AIM_BONE_TORSO], 0, 0, 1}, + {"aimbot", "bone_larm", S_BOOL, &g_aim_bones[AIM_BONE_LARM], 0, 0, 1}, + {"aimbot", "bone_rarm", S_BOOL, &g_aim_bones[AIM_BONE_RARM], 0, 0, 1}, + {"aimbot", "bone_lleg", S_BOOL, &g_aim_bones[AIM_BONE_LLEG], 0, 0, 1}, + {"aimbot", "bone_rleg", S_BOOL, &g_aim_bones[AIM_BONE_RLEG], 0, 0, 1}, + FEAT("triggerbot", g_triggerbot, 1, 603), + FEAT("silentaim", g_silentaim, 1, 602), + + // view + {"view", "fov", S_INT, &g_fov_camera, 75, 40, 140}, + {"view", "vmfov", S_INT, &g_fov_viewmodel, 54, 20, 120}, + {"view", "tonemap", S_INT, &g_tonemap, 0, 0, 30}, + + // esp + FEAT("esp", g_esp, 1, 0), + {"esp", "neutral", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_NEUTRAL], 1, 0, 1}, + {"esp", "healthbar", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_HEALTHBAR], 1, 0, 1}, + {"esp", "healthnum", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_HEALTHNUM], 1, 0, 1}, + {"esp", "name", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_NAME], 1, 0, 1}, + {"esp", "skeleton", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_SKELETON], 1, 0, 1}, + {"esp", "box", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_BOX], 1, 0, 1}, + {"esp", "speedgraph", S_BOOL, &g_esp_opt[ESP_OPT_SHOW_SPEEDGRAPH], 1, 0, 1}, + {"esp", "dmg", S_BOOL, &g_esp_opt[ESP_OPT_DAMAGE_TAGS], 1, 0, 1}, + {"esp", "alert", S_BOOL, &g_esp_opt[ESP_OPT_ALERT], 1, 0, 1}, + {"esp", "weapon", S_BOOL, &g_esp_opt[ESP_OPT_WEAPON], 1, 0, 1}, + {"esp", "arrows", S_BOOL, &g_esp_opt[ESP_OPT_ARROWS], 1, 0, 1}, + {"esp", "hr", S_INT, &g_esp_col_hostile[0], 255, 0, 255}, + {"esp", "hg", S_INT, &g_esp_col_hostile[1], 60, 0, 255}, + {"esp", "hb", S_INT, &g_esp_col_hostile[2], 60, 0, 255}, + {"esp", "nr", S_INT, &g_esp_col_neutral[0], 220, 0, 255}, + {"esp", "ng", S_INT, &g_esp_col_neutral[1], 220, 0, 255}, + {"esp", "nb", S_INT, &g_esp_col_neutral[2], 220, 0, 255}, + {"esp", "fr", S_INT, &g_esp_col_friendly[0], 60, 0, 255}, + {"esp", "fg", S_INT, &g_esp_col_friendly[1], 255, 0, 255}, + {"esp", "fb", S_INT, &g_esp_col_friendly[2], 60, 0, 255}, + + // items + FEAT("items", g_item_esp, 1, 0), + {"items", "health", S_BOOL, &g_item_health, 1, 0, 1}, + {"items", "ammo", S_BOOL, &g_item_ammo, 1, 0, 1}, + {"items", "armor", S_BOOL, &g_item_armor, 1, 0, 1}, + {"items", "weapons", S_BOOL, &g_item_weapons, 1, 0, 1}, + {"items", "crates", S_BOOL, &g_item_crates, 1, 0, 1}, + {"items", "distance", S_BOOL, &g_item_distance, 1, 0, 1}, + {"items", "usable", S_BOOL, &g_item_usable, 1, 0, 1}, + {"items", "max_dist", S_INT, &g_item_max_dist, 5000, 0, 10000}, + + // projectiles + FEAT("projectiles", g_projectiles, 1, 0), + {"projectiles", "fuse", S_BOOL, &g_proj_fuse, 1, 0, 1}, + {"projectiles", "radius", S_BOOL, &g_proj_radius, 1, 0, 1}, + {"projectiles", "trajectory", S_BOOL, &g_proj_traj, 1, 0, 1}, + + // chams + FEAT("chams", g_chams, 0, 0), +#define CHAMS_GROUP(sec, grp, von, vr, vg, vb, ion, ir, ig, ib) \ + {sec, "vis", S_BOOL, &(grp).vis_on, von, 0, 1}, \ + {sec, "vis_mat", S_INT, &(grp).vis_mat, 3, 0, 6}, \ + {sec, "vis_r", S_INT, &(grp).vis_rgb[0], vr, 0, 255}, \ + {sec, "vis_g", S_INT, &(grp).vis_rgb[1], vg, 0, 255}, \ + {sec, "vis_b", S_INT, &(grp).vis_rgb[2], vb, 0, 255}, \ + {sec, "vis_a", S_INT, &(grp).vis_rgb[3], 255, 0, 255}, \ + {sec, "inv", S_BOOL, &(grp).inv_on, ion, 0, 1}, \ + {sec, "inv_mat", S_INT, &(grp).inv_mat, 3, 0, 6}, \ + {sec, "inv_r", S_INT, &(grp).inv_rgb[0], ir, 0, 255}, \ + {sec, "inv_g", S_INT, &(grp).inv_rgb[1], ig, 0, 255}, \ + {sec, "inv_b", S_INT, &(grp).inv_rgb[2], ib, 0, 255}, \ + {sec, "inv_a", S_INT, &(grp).inv_rgb[3], 255, 0, 255} + CHAMS_GROUP("chams_hostile", g_chams_hostile, 1, 255, 60, 60, 1, 255, 60, + 60), + CHAMS_GROUP("chams_neutral", g_chams_neutral, 1, 220, 220, 220, 0, 220, 220, + 220), + CHAMS_GROUP("chams_friendly", g_chams_friendly, 1, 60, 255, 60, 0, 60, 255, + 60), +#undef CHAMS_GROUP + {"chams_vm", "on", S_BOOL, &g_chams_viewmodel, 0, 0, 1}, + {"chams_vm", "mat", S_INT, &g_chams_vm_mat, 3, 0, 6}, + {"chams_vm", "r", S_INT, &g_chams_vm_rgb[0], 200, 0, 255}, + {"chams_vm", "g", S_INT, &g_chams_vm_rgb[1], 200, 0, 255}, + {"chams_vm", "b", S_INT, &g_chams_vm_rgb[2], 255, 0, 255}, + {"chams_vm", "a", S_INT, &g_chams_vm_rgb[3], 255, 0, 255}, + + // visuals + FEAT("fullbright", g_fullbright, 0, 0), + FEAT("worldtint", g_world_tint, 0, 0), + {"worldtint", "world", S_BOOL, &g_tint_world_on, 1, 0, 1}, + {"worldtint", "sky", S_BOOL, &g_tint_sky_on, 1, 0, 1}, + {"worldtint", "prop", S_BOOL, &g_tint_prop_on, 1, 0, 1}, + {"worldtint", "wr", S_INT, &g_tint_world_rgb[0], 255, 0, 255}, + {"worldtint", "wg", S_INT, &g_tint_world_rgb[1], 255, 0, 255}, + {"worldtint", "wb", S_INT, &g_tint_world_rgb[2], 255, 0, 255}, + {"worldtint", "sr", S_INT, &g_tint_sky_rgb[0], 255, 0, 255}, + {"worldtint", "sg", S_INT, &g_tint_sky_rgb[1], 255, 0, 255}, + {"worldtint", "sb", S_INT, &g_tint_sky_rgb[2], 255, 0, 255}, + {"worldtint", "pr", S_INT, &g_tint_prop_rgb[0], 255, 0, 255}, + {"worldtint", "pg", S_INT, &g_tint_prop_rgb[1], 255, 0, 255}, + {"worldtint", "pb", S_INT, &g_tint_prop_rgb[2], 255, 0, 255}, + FEAT("fog", g_fog, 0, 0), + {"fog", "r", S_INT, &g_fog_rgb[0], 160, 0, 255}, + {"fog", "g", S_INT, &g_fog_rgb[1], 170, 0, 255}, + {"fog", "b", S_INT, &g_fog_rgb[2], 190, 0, 255}, + {"fog", "start", S_INT, &g_fog_start, 200, 0, 8000}, + {"fog", "end", S_INT, &g_fog_end, 3000, 0, 20000}, + {"fog", "skybox", S_BOOL, &g_fog_skybox, 1, 0, 1}, + {"fog", "disable", S_BOOL, &g_fog_disable, 0, 0, 1}, + FEAT("skybox", g_skybox, 0, 0), +}; + +constexpr int kSettingCount = (int)(sizeof(kSettings) / sizeof(kSettings[0])); + +const SettingDesc *find_setting(const char *section, const char *key) { + for (int i = 0; i < kSettingCount; i++) { + if (strcmp(kSettings[i].section, section) == 0 && + strcmp(kSettings[i].key, key) == 0) + return &kSettings[i]; + } + return nullptr; +} + +} // namespace + +void settings_save(FILE *f) { + const char *section = nullptr; + for (int i = 0; i < kSettingCount; i++) { + const SettingDesc &s = kSettings[i]; + if (!section || strcmp(section, s.section) != 0) { + fprintf(f, "\n[%s]\n", s.section); + section = s.section; + } + int v = s.type == S_BOOL ? (*(bool *)s.ptr ? 1 : 0) : *(int *)s.ptr; + fprintf(f, "%s=%d\n", s.key, v); + } +} + +void settings_load(FILE *f) { + char line[256]; + char section[64] = ""; + while (fgets(line, sizeof(line), f)) { + line[strcspn(line, "\r\n")] = 0; + if (line[0] == '[') { + const char *end = strchr(line, ']'); + if (!end) + continue; + size_t n = (size_t)(end - line - 1); + if (n >= sizeof(section)) + n = sizeof(section) - 1; + memcpy(section, line + 1, n); + section[n] = 0; + continue; + } + char *eq = strchr(line, '='); + if (!eq) + continue; + *eq = 0; + const SettingDesc *d = find_setting(section, line); + if (!d) + continue; // [gui] and unknown keys belong to other readers + int v = atoi(eq + 1); + if (v < d->lo) + v = d->lo; + if (v > d->hi) + v = d->hi; + if (d->type == S_BOOL) + *(bool *)d->ptr = v != 0; + else + *(int *)d->ptr = v; + } +} + +void settings_reset_defaults() { + for (int i = 0; i < kSettingCount; i++) { + const SettingDesc &s = kSettings[i]; + if (s.type == S_BOOL) + *(bool *)s.ptr = s.def != 0; + else + *(int *)s.ptr = s.def; + } +} diff --git a/src/features.h b/src/features.h index 6890aa6..b4616a1 100644 --- a/src/features.h +++ b/src/features.h @@ -133,4 +133,9 @@ QAngle gui_frozen_view(); void gui_config_init(); void gui_config_write(FILE *f); +// Declarative settings persistence (config_table.cpp). +void settings_save(FILE *f); +void settings_load(FILE *f); +void settings_reset_defaults(); + #endif diff --git a/src/menu.cpp b/src/menu.cpp index f3a9bb9..d2f6787 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -203,91 +203,7 @@ void config_save() { toastf(TOAST_ERROR, "Config save failed: %s", path.c_str()); return; } - fprintf(f, "[bhop]\nactive=%d\nbind=%d\nautostrafe=%d\n", g_bhop.active, - g_bhop.bind, g_bhop_autostrafe); - fprintf(f, "[abh]\nactive=%d\nbind=%d\n", g_abh.active, g_abh.bind); - fprintf(f, "[jumpbug]\nactive=%d\nbind=%d\nassist=%d\n", - g_jumpbug.active, g_jumpbug.bind, (int)g_jumpbug_assist); - fprintf(f, "[melee]\nactive=%d\nbind=%d\n", g_melee.active, g_melee.bind); - fprintf(f, "[spread]\nactive=%d\nbind=%d\nno_spread=%d\nengine=%d\n", - g_spread.active, g_spread.bind, (int)g_spread_no_spread, - (int)g_spread_engine); - fprintf(f, "[aimbot]\nactive=%d\nbind=%d\nsmooth=%d\nvischeck=%d\n" - "fov=%d\nfov_circle=%d\npunch=%d\n" - "bone_head=%d\nbone_torso=%d\nbone_larm=%d\nbone_rarm=%d\n" - "bone_lleg=%d\nbone_rleg=%d\n", - g_aimbot.active, g_aimbot.bind, g_aim_smooth, - (int)g_aim_vischeck, g_aim_fov, (int)g_aim_fov_circle, - (int)g_aim_punch, g_aim_bones[AIM_BONE_HEAD], - g_aim_bones[AIM_BONE_TORSO], g_aim_bones[AIM_BONE_LARM], - g_aim_bones[AIM_BONE_RARM], g_aim_bones[AIM_BONE_LLEG], - g_aim_bones[AIM_BONE_RLEG]); - fprintf(f, "[triggerbot]\nactive=%d\nbind=%d\n", g_triggerbot.active, - g_triggerbot.bind); - fprintf(f, "[silentaim]\nactive=%d\nbind=%d\n", g_silentaim.active, - g_silentaim.bind); - fprintf(f, "[fullbright]\nactive=%d\nbind=%d\n", g_fullbright.active, - g_fullbright.bind); - fprintf(f, "[worldtint]\nactive=%d\nbind=%d\nworld=%d\nsky=%d\n" - "prop=%d\nwr=%d\nwg=%d\nwb=%d\nsr=%d\nsg=%d\nsb=%d\n" - "pr=%d\npg=%d\npb=%d\n", - g_world_tint.active, g_world_tint.bind, (int)g_tint_world_on, - (int)g_tint_sky_on, (int)g_tint_prop_on, g_tint_world_rgb[0], - g_tint_world_rgb[1], g_tint_world_rgb[2], g_tint_sky_rgb[0], - g_tint_sky_rgb[1], g_tint_sky_rgb[2], g_tint_prop_rgb[0], - g_tint_prop_rgb[1], g_tint_prop_rgb[2]); - fprintf(f, "[fog]\nactive=%d\nbind=%d\nr=%d\ng=%d\nb=%d\n" - "start=%d\nend=%d\nskybox=%d\ndisable=%d\n", - g_fog.active, g_fog.bind, g_fog_rgb[0], g_fog_rgb[1], g_fog_rgb[2], - g_fog_start, g_fog_end, (int)g_fog_skybox, (int)g_fog_disable); - fprintf(f, "[skybox]\nactive=%d\nbind=%d\n", g_skybox.active, - g_skybox.bind); - fprintf(f, "[projectiles]\nactive=%d\nbind=%d\nfuse=%d\nradius=%d\n" - "trajectory=%d\n", - g_projectiles.active, g_projectiles.bind, (int)g_proj_fuse, - (int)g_proj_radius, (int)g_proj_traj); - fprintf(f, "[chams]\nactive=%d\nbind=%d\n", g_chams.active, g_chams.bind); - auto save_chams = [&](const char *name, const ChamsGroup &g) { - fprintf(f, "[%s]\nvis=%d\nvis_mat=%d\nvis_r=%d\nvis_g=%d\nvis_b=%d\n" - "vis_a=%d\ninv=%d\ninv_mat=%d\ninv_r=%d\ninv_g=%d\ninv_b=%d\n" - "inv_a=%d\n", - name, (int)g.vis_on, g.vis_mat, g.vis_rgb[0], g.vis_rgb[1], - g.vis_rgb[2], g.vis_rgb[3], (int)g.inv_on, g.inv_mat, - g.inv_rgb[0], g.inv_rgb[1], g.inv_rgb[2], g.inv_rgb[3]); - }; - save_chams("chams_hostile", g_chams_hostile); - save_chams("chams_neutral", g_chams_neutral); - save_chams("chams_friendly", g_chams_friendly); - fprintf(f, "[chams_vm]\non=%d\nmat=%d\nr=%d\ng=%d\nb=%d\na=%d\n", - (int)g_chams_viewmodel, g_chams_vm_mat, g_chams_vm_rgb[0], - g_chams_vm_rgb[1], g_chams_vm_rgb[2], g_chams_vm_rgb[3]); - fprintf(f, "[items]\nactive=%d\nbind=%d\nhealth=%d\nammo=%d\n" - "armor=%d\nweapons=%d\ncrates=%d\ndistance=%d\nmax_dist=%d\n" - "usable=%d\n", - g_item_esp.active, g_item_esp.bind, (int)g_item_health, - (int)g_item_ammo, (int)g_item_armor, (int)g_item_weapons, - (int)g_item_crates, (int)g_item_distance, g_item_max_dist, - (int)g_item_usable); - fprintf(f, "[esp]\nactive=%d\nbind=%d\nneutral=%d\nhealthbar=%d\n" - "healthnum=%d\nname=%d\nskeleton=%d\nbox=%d\nspeedgraph=%d\n" - "dmg=%d\nalert=%d\nweapon=%d\narrows=%d\n" - "hr=%d\nhg=%d\nhb=%d\nnr=%d\nng=%d\nnb=%d\n" - "fr=%d\nfg=%d\nfb=%d\n", - g_esp.active, g_esp.bind, g_esp_opt[ESP_OPT_SHOW_NEUTRAL], - g_esp_opt[ESP_OPT_SHOW_HEALTHBAR], - g_esp_opt[ESP_OPT_SHOW_HEALTHNUM], g_esp_opt[ESP_OPT_SHOW_NAME], - g_esp_opt[ESP_OPT_SHOW_SKELETON], g_esp_opt[ESP_OPT_SHOW_BOX], - g_esp_opt[ESP_OPT_SHOW_SPEEDGRAPH], - g_esp_opt[ESP_OPT_DAMAGE_TAGS], g_esp_opt[ESP_OPT_ALERT], - g_esp_opt[ESP_OPT_WEAPON], g_esp_opt[ESP_OPT_ARROWS], - g_esp_col_hostile[0], g_esp_col_hostile[1], g_esp_col_hostile[2], - g_esp_col_neutral[0], g_esp_col_neutral[1], g_esp_col_neutral[2], - g_esp_col_friendly[0], g_esp_col_friendly[1], - g_esp_col_friendly[2]); - fprintf(f, "[view]\nfov=%d\nvmfov=%d\ntonemap=%d\n", g_fov_camera, - g_fov_viewmodel, g_tonemap); - fprintf(f, "[movement]\ncrouchjump=%d\nedgejump=%d\n", - (int)g_auto_crouchjump, (int)g_edge_jump); + settings_save(f); gui_config_write(f); bool ok = ferror(f) == 0; if (fflush(f) != 0) @@ -306,351 +222,7 @@ static bool config_load() { FILE *f = fopen(config_path().c_str(), "r"); if (!f) return false; - char line[256]; - FeatureState *cur = nullptr; - bool in_esp = false, in_bhop = false, in_aim = false, - in_jumpbug = false, in_spread = false, in_items = false, - in_tint = false, in_fog = false, in_view = false, in_movement = false, - in_proj = false; - ChamsGroup *chams_grp = nullptr; - bool in_chams_vm = false; - while (fgets(line, sizeof(line), f)) { - line[strcspn(line, "\r\n")] = 0; - if (line[0] == '[') { - chams_grp = nullptr; - in_chams_vm = false; - if (strstr(line, "[bhop]")) - cur = &g_bhop; - else if (strstr(line, "[abh]")) - cur = &g_abh; - else if (strstr(line, "[jumpbug]")) - cur = &g_jumpbug; - else if (strstr(line, "[melee]")) - cur = &g_melee; - else if (strstr(line, "[spread]")) - cur = &g_spread; - else if (strstr(line, "[esp]")) - cur = &g_esp; - else if (strstr(line, "[items]")) - cur = &g_item_esp; - else if (strstr(line, "[fullbright]")) - cur = &g_fullbright; - else if (strstr(line, "[worldtint]")) - cur = &g_world_tint; - else if (strstr(line, "[fog]")) - cur = &g_fog; - else if (strstr(line, "[skybox]")) - cur = &g_skybox; - else if (strstr(line, "[projectiles]")) - cur = &g_projectiles; - else if (strstr(line, "[chams]")) - cur = &g_chams; - else if (strstr(line, "[chams_hostile]")) { - cur = nullptr; - chams_grp = &g_chams_hostile; - } else if (strstr(line, "[chams_neutral]")) { - cur = nullptr; - chams_grp = &g_chams_neutral; - } else if (strstr(line, "[chams_friendly]")) { - cur = nullptr; - chams_grp = &g_chams_friendly; - } else if (strstr(line, "[chams_vm]")) { - cur = nullptr; - in_chams_vm = true; - } - else if (strstr(line, "[aimbot]")) - cur = &g_aimbot; - else if (strstr(line, "[triggerbot]")) - cur = &g_triggerbot; - else if (strstr(line, "[silentaim]")) - cur = &g_silentaim; - else if (strstr(line, "[view]")) - cur = nullptr; - else if (strstr(line, "[movement]")) - cur = nullptr; - else - cur = nullptr; - in_esp = (cur == &g_esp); - in_bhop = (cur == &g_bhop); - in_aim = (cur == &g_aimbot); - in_jumpbug = (cur == &g_jumpbug); - in_spread = (cur == &g_spread); - in_items = (cur == &g_item_esp); - in_tint = (cur == &g_world_tint); - in_fog = (cur == &g_fog); - in_view = strstr(line, "[view]") != nullptr; - in_movement = strstr(line, "[movement]") != nullptr; - in_proj = (cur == &g_projectiles); - } else if (cur || in_view || in_movement || chams_grp || - in_chams_vm) { - char *eq = strchr(line, '='); - if (!eq) - continue; - *eq = 0; - const char *key = line, *val = eq + 1; - if (in_bhop && strcmp(key, "autostrafe") == 0) { - g_bhop_autostrafe = atoi(val) != 0; - } - if (in_jumpbug && strcmp(key, "assist") == 0) { - g_jumpbug_assist = atoi(val) != 0; - } - if (in_spread) { - if (strcmp(key, "no_spread") == 0) - g_spread_no_spread = atoi(val) != 0; - else if (strcmp(key, "engine") == 0) - g_spread_engine = atoi(val) != 0; - } - if (in_items) { - if (strcmp(key, "health") == 0) - g_item_health = atoi(val) != 0; - else if (strcmp(key, "ammo") == 0) - g_item_ammo = atoi(val) != 0; - else if (strcmp(key, "armor") == 0) - g_item_armor = atoi(val) != 0; - else if (strcmp(key, "weapons") == 0) - g_item_weapons = atoi(val) != 0; - else if (strcmp(key, "crates") == 0) - g_item_crates = atoi(val) != 0; - else if (strcmp(key, "distance") == 0) - g_item_distance = atoi(val) != 0; - else if (strcmp(key, "usable") == 0) - g_item_usable = atoi(val) != 0; - else if (strcmp(key, "max_dist") == 0) { - int v = atoi(val); - if (v < 0) v = 0; // 0 = unlimited - if (v > 10000) v = 10000; - g_item_max_dist = v; - } - } - if (in_proj) { - if (strcmp(key, "fuse") == 0) - g_proj_fuse = atoi(val) != 0; - else if (strcmp(key, "radius") == 0) - g_proj_radius = atoi(val) != 0; - else if (strcmp(key, "trajectory") == 0) - g_proj_traj = atoi(val) != 0; - } - if (chams_grp) { - ChamsGroup &g = *chams_grp; - if (strcmp(key, "vis") == 0) - g.vis_on = atoi(val) != 0; - else if (strcmp(key, "vis_mat") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 6) v = 6; - g.vis_mat = v; - } else if (strcmp(key, "vis_r") == 0 || strcmp(key, "vis_g") == 0 || - strcmp(key, "vis_b") == 0 || strcmp(key, "vis_a") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - int idx = key[4] == 'r' ? 0 : key[4] == 'g' ? 1 - : key[4] == 'b' ? 2 : 3; - g.vis_rgb[idx] = v; - } else if (strcmp(key, "inv") == 0) - g.inv_on = atoi(val) != 0; - else if (strcmp(key, "inv_mat") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 6) v = 6; - g.inv_mat = v; - } else if (strcmp(key, "inv_r") == 0 || strcmp(key, "inv_g") == 0 || - strcmp(key, "inv_b") == 0 || strcmp(key, "inv_a") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - int idx = key[4] == 'r' ? 0 : key[4] == 'g' ? 1 - : key[4] == 'b' ? 2 : 3; - g.inv_rgb[idx] = v; - } - } - if (in_chams_vm) { - if (strcmp(key, "on") == 0) - g_chams_viewmodel = atoi(val) != 0; - else if (strcmp(key, "mat") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 6) v = 6; - g_chams_vm_mat = v; - } else if (strcmp(key, "r") == 0 || strcmp(key, "g") == 0 || - strcmp(key, "b") == 0 || strcmp(key, "a") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - int idx = key[0] == 'r' ? 0 : key[0] == 'g' ? 1 - : key[0] == 'b' ? 2 : 3; - g_chams_vm_rgb[idx] = v; - } - } - if (in_aim) { - if (strcmp(key, "smooth") == 0) { - int v = atoi(val); - if (v < 1) v = 1; - if (v > 45) v = 45; - g_aim_smooth = v; - } else if (strcmp(key, "bone_head") == 0) { - g_aim_bones[AIM_BONE_HEAD] = atoi(val) != 0; - } else if (strcmp(key, "bone_torso") == 0) { - g_aim_bones[AIM_BONE_TORSO] = atoi(val) != 0; - } else if (strcmp(key, "bone_larm") == 0) { - g_aim_bones[AIM_BONE_LARM] = atoi(val) != 0; - } else if (strcmp(key, "bone_rarm") == 0) { - g_aim_bones[AIM_BONE_RARM] = atoi(val) != 0; - } else if (strcmp(key, "bone_lleg") == 0) { - g_aim_bones[AIM_BONE_LLEG] = atoi(val) != 0; - } else if (strcmp(key, "bone_rleg") == 0) { - g_aim_bones[AIM_BONE_RLEG] = atoi(val) != 0; - } else if (strcmp(key, "vischeck") == 0) { - g_aim_vischeck = atoi(val) != 0; - } else if (strcmp(key, "fov") == 0) { - int v = atoi(val); - if (v < 1) v = 1; - if (v > 180) v = 180; - g_aim_fov = v; - } else if (strcmp(key, "fov_circle") == 0) { - g_aim_fov_circle = atoi(val) != 0; - } else if (strcmp(key, "punch") == 0) { - g_aim_punch = atoi(val) != 0; - } - } - if (in_view) { - int *dst = nullptr; - int lo = 0, hi = 0, stock = 0; - if (strcmp(key, "fov") == 0) { - dst = &g_fov_camera; - lo = 40; - hi = 140; - stock = 75; - } else if (strcmp(key, "vmfov") == 0) { - dst = &g_fov_viewmodel; - lo = 20; - hi = 120; - stock = 54; - } else if (strcmp(key, "tonemap") == 0) { - dst = &g_tonemap; - lo = 0; - hi = 30; - stock = 0; - } - if (dst) { - int v = atoi(val); - if (v <= 0) - v = stock; // old configs used 0 as "off" - if (v < lo) v = lo; - if (v > hi) v = hi; - *dst = v; - } - } - if (in_movement) { - if (strcmp(key, "crouchjump") == 0) - g_auto_crouchjump = atoi(val) != 0; - else if (strcmp(key, "edgejump") == 0) - g_edge_jump = atoi(val) != 0; - } - if (in_tint) { - if (strcmp(key, "world") == 0) - g_tint_world_on = atoi(val) != 0; - else if (strcmp(key, "sky") == 0) - g_tint_sky_on = atoi(val) != 0; - else if (strcmp(key, "prop") == 0) - g_tint_prop_on = atoi(val) != 0; - else if (strcmp(key, "wr") == 0 || strcmp(key, "wg") == 0 || - strcmp(key, "wb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_tint_world_rgb[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } else if (strcmp(key, "sr") == 0 || strcmp(key, "sg") == 0 || - strcmp(key, "sb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_tint_sky_rgb[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } else if (strcmp(key, "pr") == 0 || strcmp(key, "pg") == 0 || - strcmp(key, "pb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_tint_prop_rgb[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } - } - if (in_fog) { - if (strcmp(key, "r") == 0 || strcmp(key, "g") == 0 || - strcmp(key, "b") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_fog_rgb[key[0] == 'r' ? 0 : key[0] == 'g' ? 1 : 2] = v; - } else if (strcmp(key, "start") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 8000) v = 8000; - g_fog_start = v; - } else if (strcmp(key, "end") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 20000) v = 20000; - g_fog_end = v; - } else if (strcmp(key, "skybox") == 0) { - g_fog_skybox = atoi(val) != 0; - } else if (strcmp(key, "disable") == 0) { - g_fog_disable = atoi(val) != 0; - } - } - if (in_esp) { - if (strcmp(key, "neutral") == 0) - g_esp_opt[ESP_OPT_SHOW_NEUTRAL] = atoi(val) != 0; - else if (strcmp(key, "healthbar") == 0) - g_esp_opt[ESP_OPT_SHOW_HEALTHBAR] = atoi(val) != 0; - else if (strcmp(key, "healthnum") == 0) - g_esp_opt[ESP_OPT_SHOW_HEALTHNUM] = atoi(val) != 0; - else if (strcmp(key, "name") == 0) - g_esp_opt[ESP_OPT_SHOW_NAME] = atoi(val) != 0; - else if (strcmp(key, "skeleton") == 0) - g_esp_opt[ESP_OPT_SHOW_SKELETON] = atoi(val) != 0; - else if (strcmp(key, "box") == 0) - g_esp_opt[ESP_OPT_SHOW_BOX] = atoi(val) != 0; - else if (strcmp(key, "speedgraph") == 0) - g_esp_opt[ESP_OPT_SHOW_SPEEDGRAPH] = atoi(val) != 0; - else if (strcmp(key, "dmg") == 0) - g_esp_opt[ESP_OPT_DAMAGE_TAGS] = atoi(val) != 0; - else if (strcmp(key, "alert") == 0) - g_esp_opt[ESP_OPT_ALERT] = atoi(val) != 0; - else if (strcmp(key, "weapon") == 0) - g_esp_opt[ESP_OPT_WEAPON] = atoi(val) != 0; - else if (strcmp(key, "arrows") == 0) - g_esp_opt[ESP_OPT_ARROWS] = atoi(val) != 0; - else if (strcmp(key, "hr") == 0 || strcmp(key, "hg") == 0 || - strcmp(key, "hb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_esp_col_hostile[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } else if (strcmp(key, "nr") == 0 || strcmp(key, "ng") == 0 || - strcmp(key, "nb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_esp_col_neutral[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } else if (strcmp(key, "fr") == 0 || strcmp(key, "fg") == 0 || - strcmp(key, "fb") == 0) { - int v = atoi(val); - if (v < 0) v = 0; - if (v > 255) v = 255; - g_esp_col_friendly[key[1] == 'r' ? 0 : key[1] == 'g' ? 1 : 2] = v; - } - } - // Scalar-only sections ([view], [movement], [chams_*]) intentionally - // leave cur == nullptr. A stray active=/bind= line in one of them must - // not be dereferenced (hand-edited or corrupt config). - if (!cur) - continue; - if (strcmp(key, "active") == 0) - cur->active = atoi(val) != 0; - else if (strcmp(key, "bind") == 0) - cur->bind = atoi(val); - } - } + settings_load(f); fclose(f); return true; } @@ -679,86 +251,7 @@ const char *config_file_cstr(const char *name) { } void config_reset_defaults() { - g_bhop = {true, 0}; - g_bhop_autostrafe = true; - g_abh = {true, 0}; - g_jumpbug = {true, 0}; - g_jumpbug_assist = false; - g_melee = {true, 0}; - g_spread = {true, 0}; - g_spread_no_spread = true; - g_esp = {true, 0}; - for (int i = 0; i < ESP_OPT_COUNT; i++) - g_esp_opt[i] = true; - g_item_esp = {true, 0}; - g_fullbright = {false, 0}; - g_world_tint = {false, 0}; - g_tint_world_on = true; - g_tint_sky_on = true; - g_tint_prop_on = true; - g_tint_world_rgb[0] = g_tint_world_rgb[1] = g_tint_world_rgb[2] = 255; - g_tint_sky_rgb[0] = g_tint_sky_rgb[1] = g_tint_sky_rgb[2] = 255; - g_tint_prop_rgb[0] = g_tint_prop_rgb[1] = g_tint_prop_rgb[2] = 255; - g_fog = {false, 0}; - g_fog_skybox = true; - g_fog_disable = false; - g_fog_rgb[0] = 160; - g_fog_rgb[1] = 170; - g_fog_rgb[2] = 190; - g_fog_start = 200; - g_fog_end = 3000; - g_skybox = {false, 0}; - g_projectiles = {true, 0}; - g_proj_fuse = true; - g_proj_radius = true; - g_proj_traj = true; - g_chams = {false, 0}; - g_chams_hostile = {true, 3, {255, 60, 60, 255}, true, 3, - {255, 60, 60, 255}}; - g_chams_neutral = {true, 3, {220, 220, 220, 255}, false, 3, - {220, 220, 220, 255}}; - g_chams_friendly = {true, 3, {60, 255, 60, 255}, false, 3, - {60, 255, 60, 255}}; - g_chams_viewmodel = false; - g_chams_vm_mat = 3; - g_chams_vm_rgb[0] = 200; - g_chams_vm_rgb[1] = 200; - g_chams_vm_rgb[2] = 255; - g_chams_vm_rgb[3] = 255; - g_item_health = true; - g_item_ammo = true; - g_item_armor = true; - g_item_weapons = true; - g_item_crates = true; - g_item_distance = true; - g_item_usable = true; - g_item_max_dist = 5000; - g_aimbot = {true, 604}; - g_triggerbot = {true, 603}; - g_silentaim = {true, 602}; - for (int i = 0; i < AIM_BONE_COUNT; i++) - g_aim_bones[i] = false; - g_aim_bones[AIM_BONE_HEAD] = true; - g_aim_smooth = 5; - g_aim_vischeck = true; - g_aim_fov = 60; - g_aim_fov_circle = true; - g_aim_punch = true; - g_spread_engine = true; - g_auto_crouchjump = false; - g_edge_jump = false; - g_fov_camera = 75; - g_fov_viewmodel = 54; - g_tonemap = 0; - g_esp_col_hostile[0] = 255; - g_esp_col_hostile[1] = 60; - g_esp_col_hostile[2] = 60; - g_esp_col_neutral[0] = 220; - g_esp_col_neutral[1] = 220; - g_esp_col_neutral[2] = 220; - g_esp_col_friendly[0] = 60; - g_esp_col_friendly[1] = 255; - g_esp_col_friendly[2] = 60; + settings_reset_defaults(); config_save(); } -- cgit v1.2.3