summaryrefslogtreecommitdiffstats
path: root/src/config_table.cpp
blob: f688d126937d57623c1be90d4b1e3483322555bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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 <cstdlib>

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;
  }
}