Skip to content

Commit

Permalink
Add more hooks to (somehow) improve compatibility (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
yezhiyi9670 authored Feb 11, 2025
1 parent 739d5e3 commit 99736f8
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions mods/per-app-language-preferences.wh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// @id per-app-language-preferences
// @name Per-app Language Preferences
// @description Override the preferred UI language for specific apps.
// @version 1.1
// @version 1.2
// @author yezhiyi9670
// @github https://github.com/yezhiyi9670
// @include *
Expand All @@ -17,9 +17,9 @@
/*
# Per-app Language Preferences
In Windows 11, it is no longer possible to set display languages for specific apps.
In Windows 11, it is no longer possible to set display languages for specific apps. This mod allow you to override the preferred language for specific apps using the mod's settings.
This mod allow you to override the preferred language for specific apps using the mod's settings.
**Currently, the approach only works for some apps, not all. Specifically, it does not seem to work for some UWP apps. See [#1510](https://github.com/ramensoftware/windhawk-mods/issues/1510).**
Instructions on the settings:
Expand Down Expand Up @@ -69,18 +69,35 @@ Note that it changes the language only and does not affect the encoding used in

int my_langid = -1;

using GetUserDefaultUILanguage_t = short(WINAPI*)();
GetUserDefaultUILanguage_t GetUserDefaultUILanguage_Original;
short WINAPI GetUserDefaultUILanguage_Hook() {
// Wh_Log(L">GetUserDefaultUILanguage");
using LangGetter_t = short(WINAPI*)();

LangGetter_t GetUserDefaultUILanguage_Original;
short WINAPI GetUserDefaultUILanguage_Hook() {
if(my_langid == -1) {
return GetUserDefaultUILanguage_Original();
} else {
return my_langid;
}
}

LangGetter_t GetUserDefaultLangID_Original;
short WINAPI GetUserDefaultLangID_Hook() {
if(my_langid == -1) {
return GetUserDefaultLangID_Original();
} else {
return my_langid;
}
}

LangGetter_t GetUserDefaultLCID_Original;
short WINAPI GetUserDefaultLCID_Hook() {
if(my_langid == -1) {
return GetUserDefaultLCID_Original();
} else {
return my_langid;
}
}

void determine_my_langid() {
wchar_t *filename_buf = new wchar_t[2048];
GetModuleFileNameW(NULL, filename_buf, 2048);
Expand Down Expand Up @@ -127,7 +144,11 @@ bool HookKernel32DllSymbols() {
};

// kernel32.dll
return setKernelFunctionHook("GetUserDefaultUILanguage", (void*)GetUserDefaultUILanguage_Hook, (void**)&GetUserDefaultUILanguage_Original);
return (
setKernelFunctionHook("GetUserDefaultUILanguage", (void*)GetUserDefaultUILanguage_Hook, (void**)&GetUserDefaultUILanguage_Original) &&
setKernelFunctionHook("GetUserDefaultLangID", (void*)GetUserDefaultLangID_Hook, (void**)&GetUserDefaultLangID_Original) &&
setKernelFunctionHook("GetUserDefaultLCID", (void*)GetUserDefaultLCID_Hook, (void**)&GetUserDefaultLCID_Original)
);
}

BOOL ModInit() {
Expand Down

0 comments on commit 99736f8

Please sign in to comment.