Skip to content

Commit 3b61903

Browse files
committed
Add AfterFrameDispatcher hook for view angle override
- Call AfterFrameDispatcher after G_RunFrame in hooks.c - Register after_frame hook in plugin to override bot AI view angles - Bot AI runs in G_RunFrame, our hook runs after to override
1 parent 0ce1e9a commit 3b61903

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

minqlx-fork/hooks.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ void __cdecl My_G_RunFrame(int time) {
227227

228228
G_RunFrame(time);
229229

230-
// Agent usercmd is now applied via set_usercmd() in Python
231-
// The C functions check skipFrameDispatcher before accessing game state
230+
// Call AfterFrameDispatcher AFTER game logic (including bot AI) has run.
231+
// This allows Python to override view angles that bot AI may have set.
232+
if (!skipFrameDispatcher) {
233+
AfterFrameDispatcher();
234+
}
232235
}
233236

234237
char* __cdecl My_ClientConnect(int clientNum, qboolean firstTime, qboolean isBot) {

minqlx-plugin/ql_agent_plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ def __init__(self):
9797
if self.ENABLE_STATE_LOOP:
9898
self.add_hook("frame", self.handle_game_frame)
9999
minqlx.console_print("[ql_agent] Frame hook registered for state publishing")
100+
# Register after_frame hook for agent input control
101+
# This runs AFTER G_RunFrame (including bot AI), allowing us to override
102+
# any view angles the bot AI may have set
103+
self.add_hook("after_frame", self.handle_after_frame)
104+
minqlx.console_print("[ql_agent] After-frame hook registered for agent input override")
100105
# CRITICAL: Start DISABLED - only enable after confirming game is ready
101106
# This prevents crashes during initial server startup
102107
self._safe_to_run = False # Flag to pause state loop during transitions
103108
self._game_restarting = False # Flag to block commands during restart
104109
self._startup_check_count = 0 # Counter for startup safety checks
105-
# NOTE: after_frame Python hook disabled - inputs now applied directly in C
106-
# after G_RunFrame to avoid Python callback crashes during shutdown.
107-
# Python sets usercmd via set_usercmd(), C applies it after G_RunFrame.
108110

109111
# Track current input state for the agent (button simulation)
110112
# These persist across frames until changed

0 commit comments

Comments
 (0)