summaryrefslogtreecommitdiffstats
path: root/src/hl2h.h
blob: d6a005ea3e3d2a24a49ac04cfb7fe4a2fda59f27 (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
#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>

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

void logf(const char *fmt, ...);

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

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

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

struct GameInterfaces {
  void *client = nullptr;
  void *entitylist = nullptr;
  void *engine = nullptr;
};
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;
  // 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; }
  bool esp_ok() const { return ok() && health >= 0 && maxhealth >= 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 };
enum { FL_ONGROUND = 1 << 0, FL_INWATER = 1 << 9 };
enum { 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);
enum FeatureId { FEAT_BHOP = 0, FEAT_ABH = 1, FEAT_ESP = 2 };

// ---------------------------------------------------------------------------
// cross-file declarations
// ---------------------------------------------------------------------------
void note_modified(const CUserCmd *cmd, int flags, const float *vel);
CUserCmd *get_usercmd(int seq);
void fix_verified_crc(int seq, uint32_t crc);
uint32_t usercmd_checksum(const CUserCmd *c);
bool find_input_global();
void resolve_netvars();
void find_modules();
void init_conmsg();
bool feature_active(int feature);
void *entitylist_get(int idx);
int engine_get_local_player();
void draw_text_col(int x, int y, const char *s, int r, int g, int b);
void esp_draw();
bool world_to_screen(const Vector &w, float &sx, float &sy);

void outer_draw();
// raw ISurface slot calls used by the PaintTraverseEx hook (hl2h.cpp)
using SurfFn = void (*)(void *, ...);
long surf_call_slot(void *surf, int slot, long a1 = 0, long a2 = 0);

// ISurface pointer (defined in menu.cpp, used for drawing tests)
struct ISurface;
extern ISurface *g_surface;
#endif