From 20e81f46ff3c14520488a6ee0c4865cfa61a7218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szil=C3=A1rd=20Bir=C3=B3?= Date: Tue, 3 Dec 2024 19:27:34 +0100 Subject: [PATCH] Polish localization support (#414) --- src/DETHRACE/common/utility.c | 3 ++- src/harness/harness.c | 20 ++++++++++++++++++++ src/harness/include/harness/config.h | 1 + src/harness/include/harness/hooks.h | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/DETHRACE/common/utility.c b/src/DETHRACE/common/utility.c index 4970b22c..f4c31aa5 100644 --- a/src/DETHRACE/common/utility.c +++ b/src/DETHRACE/common/utility.c @@ -8,6 +8,7 @@ #include "globvrpb.h" #include "graphics.h" #include "harness/config.h" +#include "harness/hooks.h" #include "harness/trace.h" #include "input.h" #include "loading.h" @@ -292,7 +293,7 @@ char* GetALineWithNoPossibleService(FILE* pF, unsigned char* pS) { if (ch != -1) { ungetc(ch, pF); } - } while (!isalnum(s[0]) + } while (!Harness_Hook_isalnum(s[0]) && s[0] != '-' && s[0] != '.' && s[0] != '!' diff --git a/src/harness/harness.c b/src/harness/harness.c index a9fbed67..0923cd11 100644 --- a/src/harness/harness.c +++ b/src/harness/harness.c @@ -6,6 +6,7 @@ #include "platforms/null.h" #include "version.h" +#include #include #include #include @@ -95,6 +96,9 @@ static void Harness_DetectGameMode(void) { if (strstr(buffer, "NEUES SPIEL") != NULL) { harness_game_info.localization = eGameLocalization_german; LOG_INFO("Language: \"%s\"", "German"); + } else if (strstr(buffer, "NOWA GRA") != NULL) { + harness_game_info.localization = eGameLocalization_polish; + LOG_INFO("Language: \"%s\"", "Polish"); } else { LOG_INFO("Language: unrecognized"); } @@ -285,3 +289,19 @@ int Harness_ProcessCommandLine(int* argc, char* argv[]) { FILE* Harness_Hook_fopen(const char* pathname, const char* mode) { return OS_fopen(pathname, mode); } + +// Localization +int Harness_Hook_isalnum(int c) +{ + if (harness_game_info.localization == eGameLocalization_polish) { + // Polish diacritic letters in Windows-1250 + unsigned char letters[] = { 140, 143, 156, 159, 163, 165, 175, 179, 185, 191, 198, 202, 209, 211, 230, 234, 241, 243 }; + for (int i = 0; i < (int)sizeof(letters); i++) { + if ((unsigned char)c == letters[i]) { + return 1; + } + } + } + + return isalnum(c); +} diff --git a/src/harness/include/harness/config.h b/src/harness/include/harness/config.h index 3ba68574..07de9b51 100644 --- a/src/harness/include/harness/config.h +++ b/src/harness/include/harness/config.h @@ -13,6 +13,7 @@ typedef enum tHarness_game_type { typedef enum { eGameLocalization_none, eGameLocalization_german, + eGameLocalization_polish, } tHarness_game_localization; typedef struct tHarness_game_info { diff --git a/src/harness/include/harness/hooks.h b/src/harness/include/harness/hooks.h index 5ac5a703..63ae1a9d 100644 --- a/src/harness/include/harness/hooks.h +++ b/src/harness/include/harness/hooks.h @@ -45,4 +45,7 @@ void Harness_Init(int* argc, char* argv[]); // Filesystem hooks FILE* Harness_Hook_fopen(const char* pathname, const char* mode); +// Localization +int Harness_Hook_isalnum(int c); + #endif