Closed Nordskog closed 2 years ago
Patches on stuff like UnityEngine.Input.GetKeyDown used to not work due to limitations. Detours were a way to work around those limitations. I guess because we are not using an ancient version of BepInEx anymore those limitations no longer apply. Most likely all detours could be deprecated now and use patches instead.
What is this
This PR fixes the terminal not responding to single-key prompts from the terminal keyboard, such as when being asked to press Y or N when playing an audio log.
What does it do
Unlike the existing terminal text input, the audio log prompt looks for a specific
KeyCode
usingUnityEngine.Input.GetKeyDown(KeyCode keycode)
, and is therefore not triggered.This has been fixed by patching
GetKeyDown()
in the same wayInjectInput
does forGetActionDown()
and friends.I am a bit unclear on when one should use a detour instead of a patch ( like how the rest of the terminal input is handled in
TerminalInputDetours
), but from what I understand it is always preferable to use a patch if you can.A
KeyDefinition
can now be assigned aKeyCode
. All the letters and numbers have been assigned their respectiveKeyCodes
. When pressed,TerminalKeyboardInterface
will store the KeyCode for one frame, and the newGetKeyDown()
patch can query it viaGetKeycodeDown()
This means we are both adding text to the input, and triggering a key down event, at the same time. Luckily this is fine, and does not result in duplicate input or anything.
For both the text input and the
KeyCode
, the value is now first temporarily stored untilLateUpdate
and only then swapped into the variables queried by the patches and detours. This ensures that the value persists for a full frame, as it should.There was one report of the keyboard buttons ( input only, not the exit/backspace/arrows that rely on actions instead ) suddenly not working in D1. Unable to reproduce but the previous clear-text-input-on-read approach may have been the cause, so this will hopefully fix that too.
Notes
The terminal expects lower-case input, and always converts everything to upper-case before running comparisons, so we don't need to do that.
In addition to the easily accessible first terminal in CX with an audio log on it, I have tested the first 2 terminals in A1 ( audio buffer overflow press any key to continue ), first terminal in D2, passworded terminal in BX and the outside, DX outside ( uplink puzzle ) and D1 ( reactor startup), and nothing exploded.