DSprtn / GTFO_VR_Plugin

A plugin to add full roomscale Virtual Reality support to your favorite game!
MIT License
143 stars 13 forks source link

Fix terminal audio log prompt not responding to terminal keyboard input #33

Closed Nordskog closed 2 years ago

Nordskog commented 2 years ago

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 using UnityEngine.Input.GetKeyDown(KeyCode keycode), and is therefore not triggered.

This has been fixed by patching GetKeyDown() in the same way InjectInput does for GetActionDown() 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 a KeyCode. All the letters and numbers have been assigned their respective KeyCodes. When pressed, TerminalKeyboardInterface will store the KeyCode for one frame, and the new GetKeyDown() patch can query it via GetKeycodeDown()

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 until LateUpdate 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.

DSprtn commented 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.