diff options
Diffstat (limited to 'src/hl2h.h')
| -rw-r--r-- | src/hl2h.h | 133 |
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 | |||
| 18 | void logf(const char *fmt, ...); | ||
| 19 | |||
| 20 | // --------------------------------------------------------------------------- | ||
| 21 | // module discovery | ||
| 22 | // --------------------------------------------------------------------------- | ||
| 23 | |||
| 24 | struct 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 | }; | ||
| 39 | extern Module g_client, g_engine; | ||
| 40 | |||
| 41 | // --------------------------------------------------------------------------- | ||
| 42 | // game interfaces | ||
| 43 | // --------------------------------------------------------------------------- | ||
| 44 | |||
| 45 | using CreateInterfaceFn = void *(*)(const char *, int *); | ||
| 46 | |||
| 47 | struct GameInterfaces { | ||
| 48 | void *client = nullptr; | ||
| 49 | void *entitylist = nullptr; | ||
| 50 | void *engine = nullptr; | ||
| 51 | }; | ||
| 52 | extern GameInterfaces g_iface; | ||
| 53 | |||
| 54 | #define VTABLE(obj) (*(void ***)(obj)) | ||
| 55 | template <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 | |||
| 63 | struct 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 | }; | ||
| 69 | extern NetVars g_net; | ||
| 70 | |||
| 71 | // --------------------------------------------------------------------------- | ||
| 72 | // CInput | ||
| 73 | // --------------------------------------------------------------------------- | ||
| 74 | |||
| 75 | extern uintptr_t g_input; | ||
| 76 | |||
| 77 | // --------------------------------------------------------------------------- | ||
| 78 | // CUserCmd | ||
| 79 | // --------------------------------------------------------------------------- | ||
| 80 | |||
| 81 | struct 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 | |||
| 103 | enum { IN_ATTACK = 1 << 0, IN_JUMP = 1 << 1, IN_DUCK = 1 << 2, IN_USE = 1 << 5 }; | ||
| 104 | enum { FL_ONGROUND = 1 << 0, FL_INWATER = 1 << 9 }; | ||
| 105 | enum { MOVETYPE_NOCLIP = 8, MOVETYPE_LADDER = 9 }; | ||
| 106 | |||
| 107 | // --------------------------------------------------------------------------- | ||
| 108 | // vector math | ||
| 109 | // --------------------------------------------------------------------------- | ||
| 110 | |||
| 111 | struct Vector { float x, y, z; }; | ||
| 112 | struct QAngle { float x, y, z; }; | ||
| 113 | QAngle vector_angles(const Vector &forward); | ||
| 114 | Vector angle_forward_vector(const QAngle &angles); | ||
| 115 | float getfov(const QAngle &my_view, const QAngle &aim_ang); | ||
| 116 | |||
| 117 | // --------------------------------------------------------------------------- | ||
| 118 | // cross-file declarations | ||
| 119 | // --------------------------------------------------------------------------- | ||
| 120 | |||
| 121 | void note_modified(const CUserCmd *cmd, int flags, const float *vel); | ||
| 122 | CUserCmd *get_usercmd(int seq); | ||
| 123 | void fix_verified_crc(int seq, uint32_t crc); | ||
| 124 | uint32_t usercmd_checksum(const CUserCmd *c); | ||
| 125 | bool find_input_global(); | ||
| 126 | void resolve_netvars(); | ||
| 127 | void find_modules(); | ||
| 128 | void install_menu(); | ||
| 129 | void init_conmsg(); | ||
| 130 | void init_x11(); | ||
| 131 | bool middle_mouse_down(); | ||
| 132 | |||
| 133 | #endif | ||
