summaryrefslogtreecommitdiffstats
path: root/src/hl2h.h
blob: 34bf04f28d9e1990e81ae3c681cd2ad51ffd03a3 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#ifndef HL2H_H
#define HL2H_H

#include <cstdint>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>

#include <dlfcn.h>
#include <pthread.h>
#include <unistd.h>

// Shared float-precision constant. More digits than a float can hold are
// rounded at compile time and have no runtime cost; a coarse value would only
// hurt angular accuracy, never performance.
constexpr float PI_F = 3.14159265f;

// ---------------------------------------------------------------------------
// logging
// ---------------------------------------------------------------------------

void logf(const char *fmt, ...);
void logd(const char *fmt, ...); // debug-only (HL2H_DEBUG=1)

// ---------------------------------------------------------------------------
// on-screen toasts
// ---------------------------------------------------------------------------

enum ToastLevel { TOAST_INFO = 0, TOAST_WARN, TOAST_ERROR };
void toastf(int level, const char *fmt, ...);
bool gui_toasts_active();
void gui_draw_toasts();

// ---------------------------------------------------------------------------
// module discovery
// ---------------------------------------------------------------------------

struct Module {
  struct Range {
    uintptr_t lo, hi;
    bool file;
  };
  std::vector<Range> ranges;
  std::string path;
  bool valid() const { return !ranges.empty(); }
  bool contains(uintptr_t p) const {
    for (auto &r : ranges)
      if (p >= r.lo && p < r.hi)
        return true;
    return false;
  }
};
extern Module g_client, g_engine, g_server;

// ---------------------------------------------------------------------------
// game interfaces
// ---------------------------------------------------------------------------

using CreateInterfaceFn = void *(*)(const char *, int *);

struct GameInterfaces {
  void *client = nullptr;
  void *entitylist = nullptr;
  void *engine = nullptr;
  void *modelinfo = nullptr;    // IVModelInfoClient006 (model index -> model name)
  void *engineserver = nullptr; // IVEngineServer021 (edict access, incl. server entities)
  void *debugoverlay = nullptr; // IVDebugOverlay003 (engine-accurate world->screen)
  void *enginetrace = nullptr;  // EngineTraceClient003 (world vischeck)
  void *cvar = nullptr;         // VEngineCvar004 (mat_fullbright etc.)
  void *modelrender = nullptr;  // VEngineModel016 (chams)
  void *renderview = nullptr;   // VEngineRenderView014 (alpha/color modulation)
};
extern GameInterfaces g_iface;

#define VTABLE(obj) (*(void ***)(obj))
template <typename Fn> inline Fn vfunc(void *obj, size_t idx) {
  return reinterpret_cast<Fn>(VTABLE(obj)[idx]);
}

// ---------------------------------------------------------------------------
// netvars
// ---------------------------------------------------------------------------
struct NetVars {
  int flags = -1;
  int velocity = -1;
  int movetype = -1;
  int health = -1;
  int maxhealth = -1;
  int teamnum = -1;
  int origin = -1;
  int viewoffset = -1;
  int mins = -1;
  int maxs = -1;
  int lifestate = -1;
  int modelindex = -1;
  int absvelocity = -1; // client C_BaseEntity::m_vecAbsVelocity (prediction)
  int activeweapon = -1; // client m_hActiveWeapon handle
  int owner = -1;        // client m_hOwnerEntity handle
  int weapon_owner = -1; // client m_hOwner handle (C_BaseCombatWeapon)
  int clr_render = -1;   // client m_clrRender (entity render colour)
  int punch = -1;        // client m_vecPunchAngle (aim punch)
  int default_fov = -1;  // client m_iDefaultFOV (camera fov)
  int dmg_radius = -1;   // client C_BaseGrenade::m_DmgRadius
  int my_weapons = -1;   // client m_hMyWeapons[48] array base
  int ammo = -1;         // client m_iAmmo[] array base
  // ponytail: mins/maxs may be absent from some HL2 netvar tables; esp.cpp falls back to h=72
  bool ok() const { return flags >= 0 && velocity >= 0 && movetype >= 0; }
  // ponytail: m_iMaxHealth isn't a netvar in HL2 SP; esp.cpp falls back to 100.
  // m_iHealth only ever updates for players — NPCs are detected via m_lifeState.
  bool esp_ok() const { return ok() && health >= 0 && teamnum >= 0 && origin >= 0 && viewoffset >= 0; }
};
extern NetVars g_net;

// ---------------------------------------------------------------------------
// CInput
// ---------------------------------------------------------------------------

extern uintptr_t g_input;

// ---------------------------------------------------------------------------
// console output
// ---------------------------------------------------------------------------

extern void (*g_conmsg)(const char *, ...);

// ---------------------------------------------------------------------------
// CUserCmd
// ---------------------------------------------------------------------------

struct CUserCmd {
  void *vtable;
  int command_number;
  int tick_count;
  float viewangles[3];
  float forwardmove;
  float sidemove;
  float upmove;
  int buttons;
  uint8_t impulse;
  int weaponselect;
  int weaponsubtype;
  int random_seed;
  short mousedx;
  short mousedy;
  bool hasbeenpredicted;
};

// ---------------------------------------------------------------------------
// engine constants
// ---------------------------------------------------------------------------

enum { IN_ATTACK = 1 << 0, IN_JUMP = 1 << 1, IN_DUCK = 1 << 2, IN_USE = 1 << 5, IN_ATTACK2 = 1 << 11, IN_SPEED = 1 << 17 };
enum { FL_ONGROUND = 1 << 0, FL_DUCKING = 1 << 1, FL_INWATER = 1 << 9 };
enum { MOVETYPE_WALK = 2, MOVETYPE_NOCLIP = 8, MOVETYPE_LADDER = 9 };

// ---------------------------------------------------------------------------
// vector math
// ---------------------------------------------------------------------------

struct Vector { float x, y, z; };
struct QAngle { float x, y, z; };
// camera state captured each CreateMove (used by ESP / future aimbot)
extern Vector g_cam_eye;
extern Vector g_cam_view;
QAngle vector_angles(const Vector &forward);
Vector angle_forward_vector(const QAngle &angles);
float getfov(const QAngle &my_view, const QAngle &aim_ang);
bool aimbot_apply(CUserCmd *cmd);
bool triggerbot_apply(CUserCmd *cmd);
bool silent_aim_apply(CUserCmd *cmd);
bool melee_weapon_active(void *local_ent);
bool gravity_gun_active(void *local_ent);
bool melee_aimbot_apply(CUserCmd *cmd, bool gravity);
bool spread_control_apply(CUserCmd *cmd, void *local_ent);
int spread_best_seed(int pellets);
extern int g_spread_pellets;
enum FeatureId {
  FEAT_BHOP = 0,
  FEAT_ABH = 1,
  FEAT_ESP = 2,
  FEAT_AIMBOT = 3,
  FEAT_TRIGGERBOT = 4,
  FEAT_SILENTAIM = 5,
  FEAT_JUMPBUG = 6,
  FEAT_MELEE = 7,
  FEAT_SPREAD = 8,
  FEAT_ITEM_ESP = 9,
  FEAT_FULLBRIGHT = 10,
  FEAT_WORLD_TINT = 11,
  FEAT_FOG = 12,
  FEAT_SKYBOX = 13,
  FEAT_PROJECTILES = 14,
  FEAT_CHAMS = 15,
  FEAT_COUNT = 16
};
enum EspOption {
  ESP_OPT_SHOW_NEUTRAL = 0,
  ESP_OPT_SHOW_HEALTHBAR = 1,
  ESP_OPT_SHOW_HEALTHNUM = 2,
  ESP_OPT_SHOW_NAME = 3,
  ESP_OPT_SHOW_SKELETON = 4,
  ESP_OPT_SHOW_BOX = 5,
  ESP_OPT_SHOW_SPEEDGRAPH = 6,
  ESP_OPT_DAMAGE_TAGS = 7,
  ESP_OPT_ALERT = 8,
  ESP_OPT_WEAPON = 9,
  ESP_OPT_ARROWS = 10,
  ESP_OPT_COUNT = 11
};
enum AimBone {
  AIM_BONE_HEAD = 0,
  AIM_BONE_TORSO,
  AIM_BONE_LARM,
  AIM_BONE_RARM,
  AIM_BONE_LLEG,
  AIM_BONE_RLEG,
  AIM_BONE_COUNT
};

// ---------------------------------------------------------------------------
// feature state / settings (owned by menu.cpp alongside config)
// ---------------------------------------------------------------------------

struct FeatureState {
  bool active;
  int bind; // SDL scancode, 0 = none (always-on)
};

extern FeatureState g_bhop, g_abh, g_jumpbug, g_melee, g_spread, g_esp,
    g_aimbot, g_triggerbot, g_silentaim, g_item_esp, g_fullbright,
    g_world_tint, g_fog, g_skybox, g_projectiles, g_chams;
extern bool g_proj_fuse, g_proj_radius;

// Chams settings per relationship, and separate visible / through-wall
// (invisible) material and colour. The viewmodel has a single style.
struct ChamsGroup {
  bool vis_on;
  int vis_mat;
  int vis_rgb[4]; // r, g, b, a (0..255)
  bool inv_on;
  int inv_mat;
  int inv_rgb[4];
};
extern ChamsGroup g_chams_hostile, g_chams_neutral, g_chams_friendly;
extern bool g_chams_viewmodel;
extern int g_chams_vm_mat;
extern int g_chams_vm_rgb[4];
extern bool g_tint_world_on, g_tint_sky_on, g_tint_prop_on;
extern int g_tint_world_rgb[3], g_tint_sky_rgb[3], g_tint_prop_rgb[3];
extern bool g_fog_skybox, g_fog_disable;
extern int g_fog_rgb[3], g_fog_start, g_fog_end;
const char *config_file_cstr(const char *name);
extern bool g_bhop_autostrafe;
extern bool g_jumpbug_assist;
extern bool g_spread_no_spread;
extern bool g_item_health;
extern bool g_item_ammo;
extern bool g_item_armor;
extern bool g_item_weapons;
extern bool g_item_crates;
extern bool g_item_distance;
extern bool g_item_usable;
extern int g_item_max_dist;
extern bool g_aim_bones[AIM_BONE_COUNT];
extern int g_aim_smooth;
extern bool g_aim_vischeck;
extern int g_aim_fov;
extern bool g_aim_fov_circle;
extern bool g_aim_punch;
extern bool g_spread_engine;
extern bool g_auto_crouchjump;
extern bool g_edge_jump;
extern int g_fov_camera;
extern int g_fov_viewmodel;
extern int g_tonemap;
extern int g_esp_col_hostile[3];
extern int g_esp_col_neutral[3];
extern int g_esp_col_friendly[3];
extern bool g_esp_opt[ESP_OPT_COUNT];

const char *scancode_name(int sc);
void config_save();
void config_reload();
void config_reset_defaults();
const char *config_path_cstr();

// ---------------------------------------------------------------------------
// cross-file declarations
// ---------------------------------------------------------------------------
void note_modified(const CUserCmd *cmd, int flags, const float *vel);
CUserCmd *get_usercmd(int seq);
void input_clear_mouse_states();
void fix_verified_crc(int seq, uint32_t crc);
uint32_t usercmd_checksum(const CUserCmd *c);
bool find_input_global();
void resolve_netvars();
bool console_cmd(const char *cmd);
bool cvar_set_int(const char *name, int value);
void fullbright_update();
void fullbright_invalidate();
void world_tint_update();
void world_tint_invalidate();
void fog_update();
void fog_invalidate();
void skybox_update();
void skybox_invalidate();
void skybox_reload_image();
bool resolve_server_netvars();
int server_entity_health(int idx, int *maxhealth, int *lifestate, void **base_out);
bool server_set_velocity_z(int idx, float vz);
int server_active_weapon(int idx);
int server_npc_relation(int idx, int local_idx);
bool server_npc_has_follow_target(int idx);
int server_npc_state(int idx);
int server_npc_takedamage(int idx);
int server_player_armor(int idx);
int server_player_ammo(int idx, int type);
uint32_t server_player_weapon(int idx, int slot);
float server_grenade_detonate(int idx);
float server_grenade_radius(int idx);
int server_entity_count();
void *server_entity_base(int idx);
const char *server_entity_classname(int idx);
bool server_trigger_info(int idx, char *map, size_t mapn, Vector &mins,
                         Vector &maxs);
int server_npc_turret_flags(int idx);
int server_model_index(void *base);
void find_modules();
bool module_jump_slot(const char *path, const char *name, uintptr_t *vaddr,
                      uintptr_t *bias);
void init_conmsg();
bool feature_active(int feature);
bool feature_has_bind(int feature);
bool feature_bind_held(int feature);
bool esp_option(int opt);
bool bhop_autostrafe_enabled();
bool jumpbug_assist_enabled();
bool spread_no_spread_enabled();
bool spread_engine_enabled();
bool aim_punch_enabled();
unsigned aimbot_bone_mask();
int aimbot_smooth_step();
bool aimbot_vischeck_enabled();
int aimbot_fov();
bool aimbot_fov_circle();
void aimbot_reset_lock();
void silentaim_reset_lock();
void *entitylist_get(int idx);
bool esp_is_npc_index(int idx);
bool esp_is_viewmodel_index(int idx);
int esp_npc_relation(int idx);
void *world_find_material(const char *name);
void chams_init();
void chams_preload();
int engine_get_local_player();
void draw_text_col(int x, int y, const char *s, int r, int g, int b);
void draw_text_small_col(int x, int y, const char *s, int r, int g, int b);
void esp_draw();
void esp_draw_items();
void esp_draw_projectiles();
void prop_tint_update();
void studio_props_init();
bool world_to_screen(const Vector &w, float &sx, float &sy);
void set_silent_restore(const QAngle &angles);
bool is_visible(const Vector &eye, const Vector &point,
                void *self = nullptr, void *target = nullptr);
void *trace_entity(const Vector &start, const Vector &end, void *ignore);
float ground_distance(const Vector &origin, void *ignore, float max_dist);
bool point_ground(const Vector &point, void *ignore);

// bones.cpp — client-side animated skeleton / hitbox access (see there)
bool bones_update(int idx, void *ent);
int bones_count(int idx);
int bone_find(int idx, const char *name);
int bone_parent(int idx, int bone);
bool bone_pos(int idx, int bone, Vector &out);
bool bone_is_skeleton_core(int idx, int bone);
int bone_nearest_core_parent(int idx, int bone);
bool bones_is_humanoid(int idx);
bool hitbox_center(int idx, const char *hitbox_name, Vector &out);
void bones_clear();
bool head_position(int idx, Vector &out);
int aim_points(int idx, unsigned group_mask, Vector *out, int max);

void outer_draw();
void gui_handle_input();
void gui_draw();
bool gui_is_open();
bool gui_bind_capture_active();
QAngle gui_frozen_view();
void gui_config_init();
void gui_config_write(FILE *f);
// ISurface pointer (defined in menu.cpp, used for drawing tests)
struct ISurface;
extern ISurface *g_surface;
#endif