Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): label hotkeys match Turkish letters on any layout
Olcay Seygan556262786ad0
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.hindex 80bc2b7ea..bd73535ea 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h@@ -101,6 +101,7 @@ public:AsciiString searchHotKey( const AsciiString& label);AsciiString searchHotKey( const UnicodeString& uStr );+ static AsciiString nameOf( WideChar c ); ///< the map key for a letter: lower case, UTF-8/** The window this key is bound to at the moment, or NULL for a key nothing* claims. When there is one, pressable comes back with the answerdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex 40ec19382..214001bb0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -106,16 +106,22 @@ GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessage// Ctrl+F let go of Ctrl first ends on a bare F release; it is still Ctrl+Fif( keyState & KEY_STATE_PRESSED_WITH_CTRL_ALT )return disp;- // NUL-terminate it: UnicodeString::set() runs wcslen over what it is given, and this used- // to hand it a single un-terminated WideChar on the stack.- WideChar key[2];- key[0] = TheKeyboard->getPrintableKey(msg->getArgument(0)->integer, 0);- key[1] = 0;- UnicodeString uKey;- uKey.set(key);- AsciiString aKey;- aKey.translate(uKey);- if(TheHotKeyManager && TheHotKeyManager->executeHotKey(aKey))+ const UnsignedByte scanCode = (UnsignedByte)msg->getArgument(0)->integer;+ WideChar typed = TheKeyboard->getPrintableKey(scanCode, 0);+#if defined(_WIN32)+ // The game's own key tables know four layouts and name every key by its US position, so on a+ // Turkish keyboard the key marked i read as an apostrophe. The letter the player's layout+ // puts on that key is the one a label's '&' means.+ {+ HKL layout = GetKeyboardLayout(0);+ const UINT virtualKey = MapVirtualKeyExW(scanCode, MAPVK_VSC_TO_VK, layout);+ BYTE keys[256] = { 0 };+ WCHAR out[4] = { 0 };+ if( virtualKey != 0 && ToUnicodeEx(virtualKey, scanCode, keys, out, 4, 0x4, layout) == 1 )+ typed = (WideChar)out[0];+ }+#endif+ if(TheHotKeyManager && TheHotKeyManager->executeHotKey(HotKeyManager::nameOf(typed)))disp = DESTROY_MESSAGE;}return disp;@@ -223,6 +229,38 @@ Bool HotKeyManager::executeHotKey( const AsciiString& keyIn )return FALSE;}+//-----------------------------------------------------------------------------+/** The map key for a letter: lower case, as UTF-8, so a Turkish letter is itself rather than the+ * low byte of itself. I, dotted İ and dotless ı are all one key: a Turkish label's İptal and an+ * English player's I key have to meet, and so do the I key of a Turkish Q layout and a label's I. */+AsciiString HotKeyManager::nameOf( WideChar c )+{+ if( c == 0x0130 || c == 0x0131 || c == L'I' )+ c = L'i';+ else if( c >= L'A' && c <= L'Z' )+ c = c + ( L'a' - L'A' );+ else if( c >= 0x00C0 && c <= 0x00DE && c != 0x00D7 )+ c = c + 0x20;+ else if( c >= 0x0100 && c <= 0x017F && ( c & 1 ) == 0 )+ c = c + 1; // Latin Extended-A pairs: Ğ ğ, Ş ş++ char utf8[ 4 ] = { 0 };+ if( c < 0x80 )+ utf8[ 0 ] = (char)c;+ else if( c < 0x800 )+ {+ utf8[ 0 ] = (char)( 0xC0 | ( c >> 6 ) );+ utf8[ 1 ] = (char)( 0x80 | ( c & 0x3F ) );+ }+ else+ {+ utf8[ 0 ] = (char)( 0xE0 | ( c >> 12 ) );+ utf8[ 1 ] = (char)( 0x80 | ( ( c >> 6 ) & 0x3F ) );+ utf8[ 2 ] = (char)( 0x80 | ( c & 0x3F ) );+ }+ return AsciiString( utf8 );+}+//-----------------------------------------------------------------------------AsciiString HotKeyManager::searchHotKey( const AsciiString& label){@@ -241,11 +279,7 @@ AsciiString HotKeyManager::searchHotKey( const UnicodeString& uStr )if (*marker == u'&'){// found a '&' - now look for the next char- UnicodeString tmp = UnicodeString::TheEmptyString;- tmp.concat(*(marker+1));- AsciiString retStr;- retStr.translate(tmp);- return retStr;+ return nameOf( *(marker+1) );}marker++;}diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex ad70032d1..552129dc1 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -55,6 +55,7 @@#include "GameNetwork/RankPointValue.h"#include "GameClient/ChromaKeyboard.h"#include "GameClient/MetaEvent.h"+#include "GameClient/HotKey.h"#include "GameClient/ClickTolerance.h"#include "GameClient/HtmlTemplate.h"#include "GameClient/KeyDownInfo.h"@@ -1256,6 +1257,19 @@ TEST(force_fire_is_the_attack_key_and_nothing_else)CHECK( !CommandXlat_isForceAttackTargeting( false, true ) );}+/* HotKey.cpp: a label's '&' letter and the key a Turkish keyboard types meet on one map key. */+TEST(hotkey_names_fold_turkish_letters_and_case)+{+ CHECK_STR( HotKeyManager::nameOf( L'B' ).str(), "b" );+ CHECK_STR( HotKeyManager::nameOf( L'b' ).str(), "b" );+ CHECK( HotKeyManager::nameOf( 0x0130 ) == HotKeyManager::nameOf( L'i' ) ); // İptal against the i key+ CHECK( HotKeyManager::nameOf( 0x0131 ) == HotKeyManager::nameOf( L'I' ) );+ CHECK( HotKeyManager::nameOf( 0x015E ) == HotKeyManager::nameOf( 0x015F ) ); // Ş ş+ CHECK( HotKeyManager::nameOf( 0x00C7 ) == HotKeyManager::nameOf( 0x00E7 ) ); // Ç ç+ CHECK( HotKeyManager::nameOf( 0x011E ) == HotKeyManager::nameOf( 0x011F ) ); // Ğ ğ+ CHECK( HotKeyManager::nameOf( 0x015E ) != HotKeyManager::nameOf( L'^' ) ); // not its low byte+}+/* InGameUI.cpp: Classic is the game as shipped, where ctrl held was force fire. */extern Bool InGameUI_isForceFireOn( Bool forceAttackArmed, Bool ctrlHeld, Bool classicUI );