summaryrefslogtreecommitdiffstats
path: root/src/cinput.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cinput.cpp')
-rw-r--r--src/cinput.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/cinput.cpp b/src/cinput.cpp
index a75cc4f..ad7face 100644
--- a/src/cinput.cpp
+++ b/src/cinput.cpp
@@ -85,12 +85,42 @@ void fix_verified_crc(int seq, uint32_t crc) {
85 85
86using InputCreateMoveFn = void (*)(void *, int, float, bool); 86using InputCreateMoveFn = void (*)(void *, int, float, bool);
87static InputCreateMoveFn oInputCreateMove = nullptr; 87static InputCreateMoveFn oInputCreateMove = nullptr;
88using InputExtraMouseFn = void (*)(void *, float, bool);
89static InputExtraMouseFn oInputExtraMouseSample = nullptr;
90
91// ExtraMouseSample runs AdjustAngles at render-frame rate, between movement
92// commands. While the GUI is open it must not touch the view; movement still
93// comes through CreateMove.
94static void hkdInputExtraMouseSample(void *self, float frametime, bool active) {
95 if (gui_is_open())
96 return;
97 if (oInputExtraMouseSample)
98 oInputExtraMouseSample(self, frametime, active);
99}
100
101void input_clear_mouse_states() {
102 if (!g_input)
103 return;
104 // CInput::ClearStates (IInput slot 20): zeros both the software mouse
105 // accumulator and the engine raw-input accumulator.
106 using Fn = void (*)(void *);
107 vfunc<Fn>((void *)g_input, 20)((void *)g_input);
108}
88 109
89static void hkdInputCreateMove(void *self, int seq, float frametime, 110static void hkdInputCreateMove(void *self, int seq, float frametime,
90 bool active) { 111 bool active) {
112 // Mouse deltas are accumulated between ticks. With the custom GUI open we
113 // must discard them before CInput::CreateMove applies mouse look, otherwise
114 // the view moves for one frame and snaps back when do_move freezes it.
115 if (gui_is_open())
116 input_clear_mouse_states();
91 if (oInputCreateMove) 117 if (oInputCreateMove)
92 oInputCreateMove(self, seq, frametime, active); 118 oInputCreateMove(self, seq, frametime, active);
93 119
120 // No combat features may modify the command while the GUI is open.
121 if (gui_is_open())
122 return;
123
94 CUserCmd *cmd = get_usercmd(seq); 124 CUserCmd *cmd = get_usercmd(seq);
95 if (!cmd) 125 if (!cmd)
96 return; 126 return;
@@ -125,8 +155,14 @@ static bool install_input_hook() {
125 memcpy(nvt, vt, N * sizeof(void *)); 155 memcpy(nvt, vt, N * sizeof(void *));
126 oInputCreateMove = (InputCreateMoveFn)vt[3]; 156 oInputCreateMove = (InputCreateMoveFn)vt[3];
127 nvt[3] = (void *)&hkdInputCreateMove; 157 nvt[3] = (void *)&hkdInputCreateMove;
158 if (N > 4) {
159 oInputExtraMouseSample = (InputExtraMouseFn)vt[4];
160 nvt[4] = (void *)&hkdInputExtraMouseSample;
161 }
128 VTABLE((void *)g_input) = nvt; 162 VTABLE((void *)g_input) = nvt;
129 logf("CInput CreateMove hooked: slot 3 orig=%p", (void *)oInputCreateMove); 163 logf("CInput CreateMove hooked: slot 3 orig=%p; ExtraMouseSample slot 4 "
164 "orig=%p",
165 (void *)oInputCreateMove, (void *)oInputExtraMouseSample);
130 return true; 166 return true;
131} 167}
132 168