Fix default font
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "utils"]
|
||||||
|
path = utils
|
||||||
|
url = https://github.com/lifegpc/c-utils
|
||||||
@@ -10,7 +10,12 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
|
|||||||
|
|
||||||
set(DETOURS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/lib/detours.lib")
|
set(DETOURS_LIB "${CMAKE_CURRENT_SOURCE_DIR}/lib/detours.lib")
|
||||||
|
|
||||||
|
set(ENABLE_ICONV OFF CACHE BOOL "Libiconv is not needed.")
|
||||||
|
add_subdirectory(utils)
|
||||||
|
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/utils")
|
||||||
|
|
||||||
add_library(jewena_patch SHARED dllmain.cpp)
|
add_library(jewena_patch SHARED dllmain.cpp)
|
||||||
target_link_libraries(jewena_patch "${DETOURS_LIB}")
|
target_link_libraries(jewena_patch "${DETOURS_LIB}")
|
||||||
|
target_link_libraries(jewena_patch utils)
|
||||||
|
|
||||||
add_executable(jewena-chs WIN32 main.cpp winres.rc jewena-chs.exe.manifest)
|
add_executable(jewena-chs WIN32 main.cpp winres.rc jewena-chs.exe.manifest)
|
||||||
|
|||||||
39
dllmain.cpp
39
dllmain.cpp
@@ -1,6 +1,10 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include "detours.h"
|
#include "detours.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "wchar_util.h"
|
||||||
|
|
||||||
|
static HFONT(WINAPI *TrueCreateFontW)(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCWSTR lpFaceName) = CreateFontW;
|
||||||
|
static HFONT(WINAPI *TrueCreateFontA)(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCSTR lpFaceName) = CreateFontA;
|
||||||
|
|
||||||
char* to_utf8(char* target, const char* source, UINT cp) {
|
char* to_utf8(char* target, const char* source, UINT cp) {
|
||||||
int count = MultiByteToWideChar(cp, MB_ERR_INVALID_CHARS, source, -1, NULL, 0);
|
int count = MultiByteToWideChar(cp, MB_ERR_INVALID_CHARS, source, -1, NULL, 0);
|
||||||
@@ -33,19 +37,50 @@ PVOID GetHandle() {
|
|||||||
return (char*)hModule + 0xf3c20;
|
return (char*)hModule + 0xf3c20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PVOID h = nullptr;
|
||||||
|
|
||||||
|
HFONT WINAPI HookedCreateFontW(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCWSTR lpFaceName) {
|
||||||
|
std::wstring name(lpFaceName);
|
||||||
|
if (name == L"Meiryo") {
|
||||||
|
lpFaceName = L"微软雅黑";
|
||||||
|
}
|
||||||
|
return TrueCreateFontW(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, lpFaceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
HFONT WINAPI HookedCreateFontA(int nHeight, int nWidth, int nEscapement, int nOrientation, int fnWeight, DWORD dwItalic, DWORD dwUnderline, DWORD dwStrikeOut, DWORD dwCharSet, DWORD dwOutPrecision, DWORD dwClipPrecision, DWORD dwQuality, DWORD dwPitchAndFamily, LPCSTR lpFaceName) {
|
||||||
|
UINT cp[] = { CP_UTF8, CP_OEMCP, CP_ACP, 932 };
|
||||||
|
std::wstring font;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
if (wchar_util::str_to_wstr(font, lpFaceName, cp[i])) {
|
||||||
|
if (font == L"Meiryo") {
|
||||||
|
font = L"微软雅黑";
|
||||||
|
}
|
||||||
|
return TrueCreateFontW(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, font.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!strcmp(lpFaceName, "Meiryo")) {
|
||||||
|
lpFaceName = "Microsoft YaHei";
|
||||||
|
}
|
||||||
|
return TrueCreateFontA(nHeight, nWidth, nEscapement, nOrientation, fnWeight, dwItalic, dwUnderline, dwStrikeOut, dwCharSet, dwOutPrecision, dwClipPrecision, dwQuality, dwPitchAndFamily, lpFaceName);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void Attach() {
|
extern "C" __declspec(dllexport) void Attach() {
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
DetourUpdateThread(GetCurrentThread());
|
DetourUpdateThread(GetCurrentThread());
|
||||||
PVOID h = GetHandle();
|
h = GetHandle();
|
||||||
DetourAttach(&h, (PVOID)jis_to_utf8);
|
DetourAttach(&h, (PVOID)jis_to_utf8);
|
||||||
|
DetourAttach(&TrueCreateFontW, HookedCreateFontW);
|
||||||
|
DetourAttach(&TrueCreateFontA, HookedCreateFontA);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __declspec(dllexport) void Detach() {
|
extern "C" __declspec(dllexport) void Detach() {
|
||||||
|
if (!h) return;
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
DetourUpdateThread(GetCurrentThread());
|
DetourUpdateThread(GetCurrentThread());
|
||||||
PVOID h = GetHandle();
|
|
||||||
DetourDetach(&h, (PVOID)jis_to_utf8);
|
DetourDetach(&h, (PVOID)jis_to_utf8);
|
||||||
|
DetourDetach(&TrueCreateFontW, HookedCreateFontW);
|
||||||
|
DetourDetach(&TrueCreateFontA, HookedCreateFontA);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
utils
Submodule
1
utils
Submodule
Submodule utils added at d4d0be7e7a
Reference in New Issue
Block a user