Skip to content

Commit

Permalink
Complete overhaul of the console input system, re-added UI button key…
Browse files Browse the repository at this point in the history
…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
Shockfire committed Aug 15, 2015
1 parent a7b6d5c commit f4bbc1a
Show file tree
Hide file tree
Showing 19 changed files with 710 additions and 667 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ link_directories(${CMAKE_SOURCE_DIR}/libs/libwebsockets/lib)
add_library(ElDorito SHARED
src/Blam/BitStream.cpp
src/Blam/BitStream.hpp
src/Blam/BlamInput.cpp
src/Blam/BlamInput.hpp
src/Blam/BlamNetwork.cpp
src/Blam/BlamNetwork.hpp
src/Blam/BlamTypes.hpp
Expand Down Expand Up @@ -111,8 +113,8 @@ add_library(ElDorito SHARED
src/Patches/Core.hpp
src/Patches/Forge.cpp
src/Patches/Forge.hpp
src/Patches/KeyboardInput.cpp
src/Patches/KeyboardInput.hpp
src/Patches/Input.cpp
src/Patches/Input.hpp
src/Patches/Logging.cpp
src/Patches/Logging.hpp
src/Patches/Mouse.cpp
Expand Down Expand Up @@ -163,8 +165,6 @@ add_library(ElDorito SHARED
src/Menu.cpp
src/Menu.hpp
src/Settings.hpp
src/KeyboardHook.cpp
src/KeyboardHook.hpp
src/CommandMap.cpp
src/CommandMap.hpp
src/ElDorito.cpp
Expand Down
35 changes: 35 additions & 0 deletions src/Blam/BlamInput.cpp
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);
}
}
}
206 changes: 206 additions & 0 deletions src/Blam/BlamInput.hpp
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);
}
}
1 change: 1 addition & 0 deletions src/Blam/BlamNetwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include "BlamTypes.hpp"
#include "BitStream.hpp"

namespace Blam
{
Expand Down

0 comments on commit f4bbc1a

Please sign in to comment.