Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Commit

Permalink
cyrillic input, convertion utf8 code to cp1251
Browse files Browse the repository at this point in the history
  • Loading branch information
shevernitskiy committed Jul 4, 2023
1 parent 3418fe6 commit 148220d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/hook/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,8 @@ namespace Hooks {
// main handler for input from keyboard
SETUP_ORIG_FUNC(standardstringentry);
int __fastcall HOOK(standardstringentry)(std::string& str, int maxlen, unsigned int flag,
std::set<InterfaceKey>& events, __int64 a5)
std::set<InterfaceKey>& events, uint16_t* utf)
{
return ORIGINAL(standardstringentry)(str, maxlen, flag, events, a5);

char entry = char(1);
const auto shift = Config::Keybinding::shift;

Expand Down Expand Up @@ -434,6 +432,14 @@ namespace Hooks {
}
}

// patch after 50.09 with sdl2
// change only if utf code is in cyrillic zone, latin have small codes
if (*utf > 127 && entry != 0) {
if (cyrillic_utf8_to_cp1251.find(*utf) != cyrillic_utf8_to_cp1251.end()) {
entry = char(cyrillic_utf8_to_cp1251.at(*utf));
}
}

if (entry != 1) {
if (entry == 0) {
if (str.size() > 0) {
Expand Down Expand Up @@ -461,12 +467,6 @@ namespace Hooks {
}

return 0;

logger::debug("entry str {} maxlen {} flag {} events size {} a5 {}", str, maxlen, flag, events.size(), a5);
logger::debug("entry {}", entry);
for (auto event : events) {
logger::debug("event {}", event);
}
}

SETUP_ORIG_FUNC(simplify_string);
Expand Down
2 changes: 1 addition & 1 deletion src/hook/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ namespace Hooks {

// search
typedef int(__fastcall* standardstringentry)(std::string& str, int maxlen, unsigned int flag,
std::set<InterfaceKey>& events, __int64 a5);
std::set<InterfaceKey>& events, uint16_t* utf);
typedef void(__fastcall* upper_case_string)(std::string& str);
typedef void(__fastcall* simplify_string)(std::string& str);
typedef void(__fastcall* lower_case_string)(std::string& str);
Expand Down
14 changes: 14 additions & 0 deletions src/hook/keybindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,17 @@ enum InterfaceKeyType
INTERFACEKEY_KEYBINDING_COMPLETE,
INTERFACEKEYNUM,
};

static std::map<int, int> cyrillic_utf8_to_cp1251{
{ 37072, 192 }, { 37328, 193 }, { 37584, 194 }, { 37840, 195 }, { 38096, 196 }, { 38352, 197 }, { 38608, 198 },
{ 38864, 199 }, { 39120, 200 }, { 39376, 201 }, { 39632, 202 }, { 39888, 203 }, { 40144, 204 }, { 40400, 205 },
{ 40656, 206 }, { 40912, 207 }, { 41168, 208 }, { 41424, 209 }, { 41680, 210 }, { 41936, 211 }, { 42192, 212 },
{ 42448, 213 }, { 42704, 214 }, { 42960, 215 }, { 43216, 216 }, { 43472, 217 }, { 43728, 218 }, { 43984, 219 },
{ 44240, 220 }, { 44496, 221 }, { 44752, 222 }, { 45008, 223 }, { 45264, 224 }, { 45520, 225 }, { 45776, 226 },
{ 46032, 227 }, { 46288, 228 }, { 46544, 229 }, { 46800, 230 }, { 47056, 231 }, { 47312, 232 }, { 47568, 233 },
{ 47824, 234 }, { 48080, 235 }, { 48336, 236 }, { 48592, 237 }, { 48848, 238 }, { 49104, 239 }, { 32977, 240 },
{ 33233, 241 }, { 33489, 242 }, { 33745, 243 }, { 34001, 244 }, { 34257, 245 }, { 34513, 246 }, { 34769, 247 },
{ 35025, 248 }, { 35281, 249 }, { 35537, 250 }, { 35793, 251 }, { 36049, 252 }, { 36305, 253 }, { 36561, 254 },
{ 36817, 255 }, { 33232, 168 }, { 37329, 184 }, { 34000, 170 }, { 38097, 186 }, { 34768, 175 }, { 38865, 191 },
{ 34512, 178 }, { 38609, 179 }, { 37074, 165 }, { 37330, 180 }, { 36560, 161 }, { 40657, 162 }
};

0 comments on commit 148220d

Please sign in to comment.