From 9b70f18c8c5ec7f5305fd1522638d598a3a9c31f Mon Sep 17 00:00:00 2001 From: Inori Date: Sat, 31 Aug 2019 14:41:21 -0400 Subject: [PATCH] Implement MKXP.user_language, return more LANGIDs --- binding/binding-mri.cpp | 10 ++++++++++ src/fake-api.cpp | 34 +++++++++++++++++++++++++++++++--- src/meson.build | 7 +++++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index cbffdf9b..692aa6f0 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -29,6 +29,7 @@ #include "debugwriter.h" #include "graphics.h" #include "audio.h" +#include "lang-fun.h" #include "boost-hash.h" #include @@ -95,6 +96,7 @@ RB_METHOD(mkxpPuts); RB_METHOD(mkxpRawKeyStates); RB_METHOD(mkxpMouseInWindow); RB_METHOD(mkxpPlatform); +RB_METHOD(mkxpUserLanguage); RB_METHOD(mriRgssMain); RB_METHOD(mriRgssStop); @@ -165,6 +167,7 @@ static void mriBindingInit() _rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates); _rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow); _rb_define_module_function(mod, "platform", mkxpPlatform); + _rb_define_module_function(mod, "user_language", mkxpUserLanguage); /* Load global constants */ rb_gv_set("MKXP", Qtrue); @@ -270,6 +273,13 @@ RB_METHOD(mkxpPlatform) return rb_str_new_cstr(SDL_GetPlatform()); } +RB_METHOD(mkxpUserLanguage) +{ + RB_UNUSED_PARAM; + + return rb_str_new_cstr(getUserLanguage()); +} + static VALUE rgssMainCb(VALUE block) { rb_funcall2(block, rb_intern("call"), 0, 0); diff --git a/src/fake-api.cpp b/src/fake-api.cpp index e33b8149..571744c7 100644 --- a/src/fake-api.cpp +++ b/src/fake-api.cpp @@ -13,6 +13,7 @@ #include "eventthread.h" #include "filesystem.h" #include "input.h" +#include "lang-fun.h" #include "fake-api.h" @@ -594,11 +595,38 @@ MKXP_GetPrivateProfileString(LPCTSTR lpAppName, } -// Only supports English, other languages are too -// much work to keep in hacky code like this +// Does not handle sublanguages, only returns a few +// common languages + +// Use MKXP.user_language instead PREFABI short // I know it's a LANGID but I don't care MKXP_GetUserDefaultLangID(void) -NOP_VAL(0xC09); +{ + char buf[50]; + strncpy(buf, getUserLanguage(), sizeof(buf)); + + for (int i = 0; i < strlen(buf); i++) + { + if (buf[i] == '_') + { + buf[i] = 0; + break; + } + } + +#define MATCH(l, c) if (!strcmp(l, buf)) return (c & 0x3ff); + MATCH("ja", 0x11); + MATCH("en", 0x09); + MATCH("fr", 0x0c); + MATCH("it", 0x10); + MATCH("de", 0x07); + MATCH("es", 0x0a); + MATCH("ko", 0x12); + MATCH("pt", 0x16); + MATCH("zh", 0x04); +#undef MATCH + return 0x09; +} #endif diff --git a/src/meson.build b/src/meson.build index dca8cda0..a9c6e2cf 100644 --- a/src/meson.build +++ b/src/meson.build @@ -15,6 +15,7 @@ zlib = dependency('zlib') main_dependencies = [sigcxx, openal, opengl, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] if host_system == 'darwin' main_dependencies += compiler.find_library('iconv') + main_dependencies += dependency('CoreFoundation') if openal.type_name() != 'pkgconfig' add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') @@ -96,7 +97,8 @@ main_headers = files( 'tileatlasvx.h', 'sharedmidistate.h', 'fluid-fun.h', - 'sdl-util.h' + 'sdl-util.h', + 'lang-fun.h' ) main_source = files( @@ -142,7 +144,8 @@ main_source = files( 'tileatlasvx.cpp', 'autotilesvx.cpp', 'midisource.cpp', - 'fluid-fun.cpp' + 'fluid-fun.cpp', + 'lang-fun.cpp' ) main = [main_source, main_headers]