Dynamic Detector

Dynamic Detector

A mod dedicated to detecting game states so mod authors can hook into it for their own mod's functions.

[size=5][b]Dynamic Detector[/b][/size]

A master game-state detector for Kingdom Come: Deliverance II. It runs the whole UI / menu / trade / dialogue / cutscene / reading / scripted-scene detection [b]once per frame[/b] and publishes the result on a shared global Lua table, [font=Courier New]DynamicDetector[/font]. Instead of every mod hooking [font=Courier New]Player.OnAction[/font], registering element listeners, and polling CVars for itself, mods just read the flags. Pure Lua — no HUD, no settings, no performance cost worth mentioning.

[b][size=5]Installation instructions:[/size][/b]
[b]Copy into your \KingdomComeDeliverance2\Mods\ like any other mods.
Install it and let it load before any mod that depends on it.[/b] 
It does nothing on its own — it's a shared library other mods read. No configuration.

[b]Requirements:[/b] none.

[size=4][b]For mod authors — how to hook in[/b][/size]

Read the flags from your own per-frame tick. No registration, no callbacks — just poll. Gate on [font=Courier New]apiVersion[/font] so your mod falls back cleanly when Dynamic Detector isn't installed.

[code]
if DynamicDetector and DynamicDetector.apiVersion then
    -- Detector is present. Read any flag you care about.
    -- All are plain booleans, current as of this frame:
    local d = DynamicDetector

    -- d.uiOpen    -- a fullscreen Apse UI or the pause menu is open
    --                (map / inventory / player / questlog / codex / crafting),
    --                sub-prompt-corrected (fast-travel / drop-item confirms)
    -- d.apseInv    -- Apse inventory is open == merchant TRADE / barter book
    -- d.dialog    -- an NPC dialogue scene is running (0.4s release grace)
    -- d.reading    -- reading a book/sign, a movie, or the HUD is toggled off
    -- d.cutscene  -- a cutscene is playing (2s release grace)
    -- d.scripted  -- a scripted scene took control away from the player
    --                (Easy-Riders horse ride for example)
    -- d.hudHidden  -- the engine hid the vanilla "hud" element (scenes)

    if d.anyHudHide then
        -- Convenience aggregate: TRUE if ANY of the flags above is set.
        -- Use this when all you want is "is the player in a non-gameplay
        -- state right now?" -- e.g. to hide a custom overlay or gate input.
    end
else
    -- Dynamic Detector isn't installed. Detect natively, or just treat
    -- everything as "not active".
end[/code]
[size=4][b]Notes[/b][/size]

[list]
[][b]No load-order dance.[/b] The table and its default-false fields exist the moment the mod loads, so the [font=Courier New]if DynamicDetector and ...[/font] guard is all you need.[/]
[][b]anyHudHide[/b] is the one-line answer for "is the player in any non-gameplay state?". The individual flags are there when you want finer control.[/]
[][b]apiVersion[/b] is the stable "I am present" contract; it bumps if the public field set ever changes. Gate on it — don't reach into internal fields.[/]
[][b]Read only.[/b] Never write to the table; you're one of many readers.[/]
[][b]Console:[/b] [font=Courier New]dd_status[/font] dumps the current flags to the log; [font=Courier New]dd_agency <N>[/font] tunes the scripted-scene sensitivity (default 4, 0 = off).[/]
[/list]
[size=4][b]The flags in one line each[/b][/size]

[list]
[][b]uiOpen[/b] — fullscreen menu / map / inventory / pause open[/]
[][b]apseInv[/b] — merchant trade / barter book open[/]
[][b]dialog[/b] — NPC conversation scene[/]
[][b]reading[/b] — book / sign / movie / HUD toggled off[/]
[][b]cutscene[/b] — cinematic playing[/]
[][b]scripted[/b] — a scripted scene has taken control from the player[/]
[][b]hudHidden[/b] — the engine hid the vanilla HUD[/]
[][b]anyHudHide[/b] — TRUE if any of the above is set[/]
[/list]