-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete overhaul of the console input system, re-added UI button key…
…bindings Console input now uses the engine's own input functions to handle keypresses instead of an ugly keyboard hook. To accomplish this, I introduced an "input context" system which lets us activate objects that override game input. Will probably be useful for the server browser once we get it integrated.
- Loading branch information
Showing
19 changed files
with
710 additions
and
667 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "BlamInput.hpp" | ||
|
||
namespace Blam | ||
{ | ||
namespace Input | ||
{ | ||
uint8_t GetKeyTicks(KeyCodes key, InputType type) | ||
{ | ||
typedef uint8_t(*EngineGetKeyTicksPtr)(KeyCodes, InputType); | ||
auto EngineGetKeyTicks = reinterpret_cast<EngineGetKeyTicksPtr>(0x511B60); | ||
return EngineGetKeyTicks(key, type); | ||
} | ||
|
||
uint16_t GetKeyMs(KeyCodes key, InputType type) | ||
{ | ||
typedef uint8_t(*EngineGetKeyMsPtr)(KeyCodes, InputType); | ||
auto EngineGetKeyMs = reinterpret_cast<EngineGetKeyMsPtr>(0x511CE0); | ||
return EngineGetKeyMs(key, type); | ||
} | ||
|
||
bool ReadKeyEvent(KeyEvent* result, InputType type) | ||
{ | ||
typedef bool(*EngineReadKeyEventPtr)(KeyEvent*, InputType); | ||
auto EngineReadKeyEvent = reinterpret_cast<EngineReadKeyEventPtr>(0x5118C0); | ||
return EngineReadKeyEvent(result, type); | ||
} | ||
|
||
void BlockInput(InputType type, bool block) | ||
{ | ||
typedef uint8_t(*EngineBlockInputPtr)(InputType, bool); | ||
auto EngineBlockInput = reinterpret_cast<EngineBlockInputPtr>(0x512530); | ||
EngineBlockInput(type, block); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace Blam | ||
{ | ||
namespace Input | ||
{ | ||
enum ButtonCodes : uint32_t | ||
{ | ||
eButtonCodesA = 0, | ||
eButtonCodesB, | ||
eButtonCodesX, | ||
eButtonCodesY, | ||
eButtonCodesRB, | ||
eButtonCodesLB, | ||
eButtonCodesLT, | ||
eButtonCodesRT, | ||
eButtonCodesDpadUp, | ||
eButtonCodesDpadDown, | ||
eButtonCodesDpadLeft, | ||
eButtonCodesDpadRight, | ||
eButtonCodesStart, | ||
eButtonCodesBack, | ||
eButtonCodesLS, | ||
eButtonCodesRS, | ||
eButtonCodesEmulatedInput, | ||
eButtonCodesUnk1, | ||
eButtonCodesLeft, // analog/arrow left | ||
eButtonCodesRight, // analog/arrow right | ||
eButtonCodesUp, // analog/arrow up | ||
eButtonCodesDown, // analog/arrow down | ||
eButtonCodesLSHorizontal = 0x1A, | ||
eButtonCodesLSVertical, | ||
eButtonCodesRSHorizontal, | ||
eButtonCodesRSVertical, | ||
}; | ||
|
||
enum KeyCodes : int16_t | ||
{ | ||
eKeyCodesEscape, | ||
eKeyCodesF1, | ||
eKeyCodesF2, | ||
eKeyCodesF3, | ||
eKeyCodesF4, | ||
eKeyCodesF5, | ||
eKeyCodesF6, | ||
eKeyCodesF7, | ||
eKeyCodesF8, | ||
eKeyCodesF9, | ||
eKeyCodesF10, | ||
eKeyCodesF11, | ||
eKeyCodesF12, | ||
eKeyCodesPrintScreen, | ||
eKeyCodesF14, | ||
eKeyCodesF15, | ||
eKeyCodesTilde, // VK_OEM_3 | ||
eKeyCodes1, | ||
eKeyCodes2, | ||
eKeyCodes3, | ||
eKeyCodes4, | ||
eKeyCodes5, | ||
eKeyCodes6, | ||
eKeyCodes7, | ||
eKeyCodes8, | ||
eKeyCodes9, | ||
eKeyCodes0, | ||
eKeyCodesMinus, | ||
eKeyCodesPlus, | ||
eKeyCodesBack, | ||
eKeyCodesTab, | ||
eKeyCodesQ, | ||
eKeyCodesW, | ||
eKeyCodesE, | ||
eKeyCodesR, | ||
eKeyCodesT, | ||
eKeyCodesY, | ||
eKeyCodesU, | ||
eKeyCodesI, | ||
eKeyCodesO, | ||
eKeyCodesP, | ||
eKeyCodesLBracket, // VK_OEM_4 | ||
eKeyCodesRBracket, // VK_OEM_6 | ||
eKeyCodesPipe, // VK_OEM_5 | ||
eKeyCodesCapital, | ||
eKeyCodesA, | ||
eKeyCodesS, | ||
eKeyCodesD, | ||
eKeyCodesF, | ||
eKeyCodesG, | ||
eKeyCodesH, | ||
eKeyCodesJ, | ||
eKeyCodesK, | ||
eKeyCodesL, | ||
eKeyCodesColon, // VK_OEM_1 | ||
eKeyCodesQuote, // VK_OEM_7 | ||
eKeyCodesEnter, | ||
eKeyCodesLShift, | ||
eKeyCodesZ, | ||
eKeyCodesX, | ||
eKeyCodesC, | ||
eKeyCodesV, | ||
eKeyCodesB, | ||
eKeyCodesN, | ||
eKeyCodesM, | ||
eKeyCodesComma, | ||
eKeyCodesPeriod, | ||
eKeyCodesQuestion, // VK_OEM_2 | ||
eKeyCodesRShift, | ||
eKeyCodesLControl, | ||
eKeyCodesUnused46, // Left Windows key, but will always fail | ||
eKeyCodesLAlt, | ||
eKeyCodesSpace, | ||
eKeyCodesRAlt, | ||
eKeyCodesUnused4A, // Right Windows key, but will always fail | ||
eKeyCodesApps, | ||
eKeyCodesRcontrol, | ||
eKeyCodesUp, | ||
eKeyCodesDown, | ||
eKeyCodesLeft, | ||
eKeyCodesRight, | ||
eKeyCodesInsert, | ||
eKeyCodesHome, | ||
eKeyCodesPageUp, | ||
eKeyCodesDelete, | ||
eKeyCodesEnd, | ||
eKeyCodesPageDown, | ||
eKeyCodesNumLock, | ||
eKeyCodesDivide, | ||
eKeyCodesMultiply, | ||
eKeyCodesNumpad0, | ||
eKeyCodesNumpad1, | ||
eKeyCodesNumpad2, | ||
eKeyCodesNumpad3, | ||
eKeyCodesNumpad4, | ||
eKeyCodesNumpad5, | ||
eKeyCodesNumpad6, | ||
eKeyCodesNumpad7, | ||
eKeyCodesNumpad8, | ||
eKeyCodesNumpad9, | ||
eKeyCodesSubtract, | ||
eKeyCodesAdd, | ||
eKeyCodesNumpadEnter, | ||
eKeyCodesDecimal, | ||
eKeyCodesUnused68, | ||
eKeyCodesShift, | ||
eKeyCodesCtrl, | ||
eKeyCodesUnused6B, // Windows key, but will always fail | ||
eKeyCodesAlt, | ||
|
||
eKeyCodes_Count // Not actually a key, just represents the number | ||
// of keys that the game scans | ||
}; | ||
|
||
enum InputType : uint32_t | ||
{ | ||
eInputTypeUi, // ABXY, mouse clicks, etc. | ||
eInputTypeGame, // All in-game actions (including camera) | ||
// Disabled when the pause menu is open | ||
eInputTypeSpecial, // Escape, tab, menu navigation | ||
}; | ||
|
||
enum KeyEventModifiers : uint8_t | ||
{ | ||
eKeyEventModifiersShift = 1 << 0, | ||
eKeyEventModifiersCtrl = 1 << 1, | ||
eKeyEventModifiersalt = 1 << 2, | ||
}; | ||
|
||
enum KeyEventType : uint32_t | ||
{ | ||
eKeyEventTypeDown, // A key was pressed. | ||
eKeyEventTypeUp, // A key was released. | ||
eKeyEventTypeChar // A character was typed. | ||
}; | ||
|
||
struct KeyEvent | ||
{ | ||
KeyEventModifiers Modifiers; // Bitfield of modifier keys that are down | ||
KeyEventType Type; // Event type | ||
KeyCodes Code; // The key code, or -1 if unavailable | ||
char16_t Char; // For eKeyEventTypeChar events, the character that was typed, or -1 if unavailable | ||
bool PreviousState; // If true, the key was down before this event happened | ||
}; | ||
static_assert(sizeof(KeyEvent) == 0x10, "Invalid KeyEvent size"); | ||
|
||
// Gets the number of ticks that a key has been held down for. | ||
// Will always be nonzero if the key is down. | ||
uint8_t GetKeyTicks(KeyCodes key, InputType type); | ||
|
||
// Gets the number of milliseconds that a key has been held down for. | ||
// Will always be nonzero if the key is down. | ||
uint16_t GetKeyMs(KeyCodes key, InputType type); | ||
|
||
// Reads a raw keyboard input event. Returns false if nothing is | ||
// available. You should call this in a loop to ensure that you process | ||
// all available events. NOTE THAT THIS IS ONLY GUARANTEED TO WORK | ||
// AFTER WINDOWS MESSAGES HAVE BEEN PUMPED IN THE UPDATE CYCLE. ALSO, | ||
// THIS WILL NOT WORK IF UI INPUT IS DISABLED, REGARDLESS OF THE INPUT | ||
// TYPE YOU SPECIFY. | ||
bool ReadKeyEvent(KeyEvent* result, InputType type); | ||
|
||
// Blocks or unblocks an input type. | ||
void BlockInput(InputType type, bool block); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
#include <cstdint> | ||
#include "BlamTypes.hpp" | ||
#include "BitStream.hpp" | ||
|
||
namespace Blam | ||
{ | ||
|
Oops, something went wrong.