summaryrefslogtreecommitdiffstats
path: root/src/hl2h.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/hl2h.h')
-rw-r--r--src/hl2h.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/hl2h.h b/src/hl2h.h
new file mode 100644
index 0000000..6d3ebe7
--- /dev/null
+++ b/src/hl2h.h
@@ -0,0 +1,133 @@
1#ifndef HL2H_H
2#define HL2H_H
3
4#include <cstdint>
5#include <cstdio>
6#include <cstring>
7#include <string>
8#include <vector>
9
10#include <dlfcn.h>
11#include <pthread.h>
12#include <unistd.h>
13
14// ---------------------------------------------------------------------------
15// logging
16// ---------------------------------------------------------------------------
17
18void logf(const char *fmt, ...);
19
20// ---------------------------------------------------------------------------
21// module discovery
22// ---------------------------------------------------------------------------
23
24struct Module {
25 struct Range {
26 uintptr_t lo, hi;
27 bool file;
28 };
29 std::vector<Range> ranges;
30 std::string path;
31 bool valid() const { return !ranges.empty(); }
32 bool contains(uintptr_t p) const {
33 for (auto &r : ranges)
34 if (p >= r.lo && p < r.hi)
35 return true;
36 return false;
37 }
38};
39extern Module g_client, g_engine;
40
41// ---------------------------------------------------------------------------
42// game interfaces
43// ---------------------------------------------------------------------------
44
45using CreateInterfaceFn = void *(*)(const char *, int *);
46
47struct GameInterfaces {
48 void *client = nullptr;
49 void *entitylist = nullptr;
50 void *engine = nullptr;
51};
52extern GameInterfaces g_iface;
53
54#define VTABLE(obj) (*(void ***)(obj))
55template <typename Fn> inline Fn vfunc(void *obj, size_t idx) {
56 return reinterpret_cast<Fn>(VTABLE(obj)[idx]);
57}
58
59// ---------------------------------------------------------------------------
60// netvars
61// ---------------------------------------------------------------------------
62
63struct NetVars {
64 int flags = -1;
65 int velocity = -1;
66 int movetype = -1;
67 bool ok() const { return flags >= 0 && velocity >= 0 && movetype >= 0; }
68};
69extern NetVars g_net;
70
71// ---------------------------------------------------------------------------
72// CInput
73// ---------------------------------------------------------------------------
74
75extern uintptr_t g_input;
76
77// ---------------------------------------------------------------------------
78// CUserCmd
79// ---------------------------------------------------------------------------
80
81struct CUserCmd {
82 void *vtable;
83 int command_number;
84 int tick_count;
85 float viewangles[3];
86 float forwardmove;
87 float sidemove;
88 float upmove;
89 int buttons;
90 uint8_t impulse;
91 int weaponselect;
92 int weaponsubtype;
93 int random_seed;
94 short mousedx;
95 short mousedy;
96 bool hasbeenpredicted;
97};
98
99// ---------------------------------------------------------------------------
100// engine constants
101// ---------------------------------------------------------------------------
102
103enum { IN_ATTACK = 1 << 0, IN_JUMP = 1 << 1, IN_DUCK = 1 << 2, IN_USE = 1 << 5 };
104enum { FL_ONGROUND = 1 << 0, FL_INWATER = 1 << 9 };
105enum { MOVETYPE_NOCLIP = 8, MOVETYPE_LADDER = 9 };
106
107// ---------------------------------------------------------------------------
108// vector math
109// ---------------------------------------------------------------------------
110
111struct Vector { float x, y, z; };
112struct QAngle { float x, y, z; };
113QAngle vector_angles(const Vector &forward);
114Vector angle_forward_vector(const QAngle &angles);
115float getfov(const QAngle &my_view, const QAngle &aim_ang);
116
117// ---------------------------------------------------------------------------
118// cross-file declarations
119// ---------------------------------------------------------------------------
120
121void note_modified(const CUserCmd *cmd, int flags, const float *vel);
122CUserCmd *get_usercmd(int seq);
123void fix_verified_crc(int seq, uint32_t crc);
124uint32_t usercmd_checksum(const CUserCmd *c);
125bool find_input_global();
126void resolve_netvars();
127void find_modules();
128void install_menu();
129void init_conmsg();
130void init_x11();
131bool middle_mouse_down();
132
133#endif