Permalink
Browse files

WINTERMUTE: Add FoxTail key codes mapping

FoxTail code is hacked to use key codes from different from usual WME.
Got correct mapping using script decompiling, verified with sample game.
  • Loading branch information...
lolbot-iichan committed Aug 26, 2018
1 parent 0806ffd commit db07aad8cbf0b7cc65396e4d730cb56733571e2b
Showing with 220 additions and 0 deletions.
  1. +220 −0 engines/wintermute/base/base_keyboard_state.cpp
@@ -26,6 +26,7 @@
* Copyright (c) 2011 Jan Nedoma
*/

#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_keyboard_state.h"
#include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
@@ -213,6 +214,11 @@ bool BaseKeyboardState::readKey(Common::Event *event) {
else if (code > Common::KEYCODE_SPACE && code < Common::KEYCODE_DELETE) {
_currentCharCode = event->kbd.ascii;
_currentPrintable = true;
#ifdef ENABLE_FOXTAIL
if (BaseEngine::instance().getGameId() == "foxtail") {
_currentCharCode = tolower(_currentCharCode);
}
#endif
}

// use ASCII value for numpad '/', '*', '-', '+'
@@ -238,6 +244,11 @@ bool BaseKeyboardState::readKey(Common::Event *event) {
code == Common::KEYCODE_KP_ENTER ||
code == Common::KEYCODE_ESCAPE ||
code == Common::KEYCODE_SPACE;
#ifdef ENABLE_FOXTAIL
if (BaseEngine::instance().getGameId() == "foxtail") {
_currentPrintable = code == Common::KEYCODE_SPACE;
}
#endif
}

//_currentKeyData = KeyData;
@@ -337,8 +348,141 @@ enum VKeyCodes {
//TODO: shift, ctrl, menu, etc...
};

#ifdef ENABLE_FOXTAIL
enum FoxtailVKeyCodes {
ftVkBack = 8,
ftVkTab = 9,
ftVkClear = 1073741980,
ftVkReturn = 13,
ftVkPause = 1073741896,
ftVkCapital = 1073741881,
ftVkEscape = 27,
ftVkSpace = 32, //printable

ftVkPrior = 1073741899,
ftVkNext = 1073741902,
ftVkEnd = 1073741901,
ftVkHome = 1073741898,
ftVkLeft = 1073741904,
ftVkUp = 1073741906,
ftVkRight = 1073741903,
ftVkDown = 1073741905,
ftVkPrint = 1073741894,
ftVkInsert = 1073741897,
ftVkDelete = 127,

ftVkF1 = 1073741882,
ftVkF2 = 1073741883,
ftVkF3 = 1073741884,
ftVkF4 = 1073741885,
ftVkF5 = 1073741886,
ftVkF6 = 1073741887,
ftVkF7 = 1073741888,
ftVkF8 = 1073741889,
ftVkF9 = 1073741890,
ftVkF10 = 1073741891,
ftVkF11 = 1073741892,
ftVkF12 = 1073741893,

ftVkNumLock = 1073741907,
ftVkScroll = 1073741895
};
#endif

//////////////////////////////////////////////////////////////////////////
uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {
#ifdef ENABLE_FOXTAIL
if (BaseEngine::instance().getGameId() == "foxtail") {
switch (event->kbd.keycode) {
case Common::KEYCODE_BACKSPACE:
return ftVkBack;
case Common::KEYCODE_TAB:
return ftVkTab;
case Common::KEYCODE_CLEAR:
case Common::KEYCODE_KP5:
return ftVkClear;
case Common::KEYCODE_RETURN:
case Common::KEYCODE_KP_ENTER:
return ftVkReturn;
case Common::KEYCODE_PAUSE:
return ftVkPause;
case Common::KEYCODE_CAPSLOCK:
return ftVkCapital;
case Common::KEYCODE_ESCAPE:
return ftVkEscape;
case Common::KEYCODE_SPACE:
return ftVkSpace;
case Common::KEYCODE_KP9:
case Common::KEYCODE_PAGEUP:
return ftVkPrior;
case Common::KEYCODE_KP3:
case Common::KEYCODE_PAGEDOWN:
return ftVkNext;
case Common::KEYCODE_END:
case Common::KEYCODE_KP1:
return ftVkEnd;
case Common::KEYCODE_HOME:
case Common::KEYCODE_KP7:
return ftVkHome;
case Common::KEYCODE_LEFT:
case Common::KEYCODE_KP4:
return ftVkLeft;
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_KP6:
return ftVkRight;
case Common::KEYCODE_UP:
case Common::KEYCODE_KP8:
return ftVkUp;
case Common::KEYCODE_DOWN:
case Common::KEYCODE_KP2:
return ftVkDown;
case Common::KEYCODE_PRINT:
return ftVkPrint;
case Common::KEYCODE_INSERT:
case Common::KEYCODE_KP0:
return ftVkInsert;
case Common::KEYCODE_DELETE:
case Common::KEYCODE_KP_PERIOD:
return ftVkDelete;
case Common::KEYCODE_F1:
return ftVkF1;
case Common::KEYCODE_F2:
return ftVkF2;
case Common::KEYCODE_F3:
return ftVkF3;
case Common::KEYCODE_F4:
return ftVkF4;
case Common::KEYCODE_F5:
return ftVkF5;
case Common::KEYCODE_F6:
return ftVkF6;
case Common::KEYCODE_F7:
return ftVkF7;
case Common::KEYCODE_F8:
return ftVkF8;
case Common::KEYCODE_F9:
return ftVkF9;
case Common::KEYCODE_F10:
return ftVkF10;
case Common::KEYCODE_F11:
return ftVkF11;
case Common::KEYCODE_F12:
return ftVkF12;
case Common::KEYCODE_NUMLOCK:
return ftVkNumLock;
case Common::KEYCODE_SCROLLOCK:
return ftVkScroll;
default:
// check if any non-sticky keys were used, otherwise key is unknown to us
if ((event->kbd.flags & Common::KBD_NON_STICKY) == 0) {
warning("Key pressed is not recognized, ASCII returned (%d '%c').", event->kbd.keycode, event->kbd.keycode);
}
// return ASCII if no match, since it could be used for typing
return event->kbd.ascii;
break;
}
}
#endif
switch (event->kbd.keycode) {
case Common::KEYCODE_BACKSPACE:
return kVkBack;
@@ -432,6 +576,82 @@ uint32 BaseKeyboardState::keyCodeToVKey(Common::Event *event) {

//////////////////////////////////////////////////////////////////////////
Common::KeyCode BaseKeyboardState::vKeyToKeyCode(uint32 vkey) {
#ifdef ENABLE_FOXTAIL
if (BaseEngine::instance().getGameId() == "foxtail") {
switch (vkey) {
case ftVkBack:
return Common::KEYCODE_BACKSPACE;
case ftVkTab:
return Common::KEYCODE_TAB;
case ftVkClear:
return Common::KEYCODE_CLEAR;
case ftVkReturn:
return Common::KEYCODE_RETURN;
case ftVkPause:
return Common::KEYCODE_PAUSE;
case ftVkCapital:
return Common::KEYCODE_CAPSLOCK;
case ftVkEscape:
return Common::KEYCODE_ESCAPE;
case ftVkSpace:
return Common::KEYCODE_SPACE;
case ftVkPrior:
return Common::KEYCODE_PAGEUP;
case ftVkNext:
return Common::KEYCODE_PAGEDOWN;
case ftVkHome:
return Common::KEYCODE_HOME;
case ftVkEnd:
return Common::KEYCODE_END;
case ftVkLeft:
return Common::KEYCODE_LEFT;
case ftVkRight:
return Common::KEYCODE_RIGHT;
case ftVkUp:
return Common::KEYCODE_UP;
case ftVkDown:
return Common::KEYCODE_DOWN;
case ftVkPrint:
return Common::KEYCODE_PRINT;
case ftVkInsert:
return Common::KEYCODE_INSERT;
case ftVkDelete:
return Common::KEYCODE_DELETE;
case ftVkF1:
return Common::KEYCODE_F1;
case ftVkF2:
return Common::KEYCODE_F2;
case ftVkF3:
return Common::KEYCODE_F3;
case ftVkF4:
return Common::KEYCODE_F4;
case ftVkF5:
return Common::KEYCODE_F5;
case ftVkF6:
return Common::KEYCODE_F6;
case ftVkF7:
return Common::KEYCODE_F7;
case ftVkF8:
return Common::KEYCODE_F8;
case ftVkF9:
return Common::KEYCODE_F9;
case ftVkF10:
return Common::KEYCODE_F10;
case ftVkF11:
return Common::KEYCODE_F11;
case ftVkF12:
return Common::KEYCODE_F12;
case ftVkNumLock:
return Common::KEYCODE_NUMLOCK;
case ftVkScroll:
return Common::KEYCODE_SCROLLOCK;
default:
warning("Unknown VKEY: %d", vkey);
return (Common::KeyCode)(vkey < KEYSTATES_ARRAY_SIZE ? vkey : 0);
break;
}
}
#endif
switch (vkey) {
case kVkBack:
return Common::KEYCODE_BACKSPACE;

0 comments on commit db07aad

Please sign in to comment.