diff --git a/Plugin/MainTextLineBreak.cpp b/Plugin/MainTextLineBreak.cpp index 8e8737d..f2f95cd 100644 --- a/Plugin/MainTextLineBreak.cpp +++ b/Plugin/MainTextLineBreak.cpp @@ -553,7 +553,7 @@ namespace MainTextLineBreak { //左側のブロックの開始位置 // push offset asc_XXXXXX - byte_pattern::temp_instance().find_pattern("68 ? ? ? ? 8D 4D C0 E8 71 24 07 00"); + byte_pattern::temp_instance().find_pattern("68 ? ? ? ? 8D ? ? ? ? 24 07 00"); if (byte_pattern::temp_instance().has_size(1, desc)) { ee_2_v301 = byte_pattern::temp_instance().get_first().address(); } @@ -561,7 +561,7 @@ namespace MainTextLineBreak { //右側のブロックの開始位置 // push offset asc_XXXXXX - byte_pattern::temp_instance().find_pattern("68 ? ? ? ? 8D 4D C0 E8 DA 23 07 00"); + byte_pattern::temp_instance().find_pattern("68 ? ? ? ? 8D ? ? ? ? 23 07 00"); if (byte_pattern::temp_instance().has_size(1, desc)) { ee_3_v301 = byte_pattern::temp_instance().get_first().address(); } @@ -667,11 +667,12 @@ namespace MainTextLineBreak { return NOERROR; case v3_0_X: - // lea ecx,[ebp+var_88] - byte_pattern::temp_instance().find_pattern("8D 8D 78 FF FF FF E8 60 C5 62 FF"); + // mov eax, [ebp+arg_10] + byte_pattern::temp_instance().find_pattern("8B 45 18 8B CE 8A 55 20 89 4D E4"); if (byte_pattern::temp_instance().has_size(1, desc)) { - injector::MakeJMP(byte_pattern::temp_instance().get_first().address(), x_1_v301); - x_2_v301 = byte_pattern::temp_instance().get_first().address(0xB); + // lea ecx,[ebp+var_88] + injector::MakeJMP(byte_pattern::temp_instance().get_first().address(-0x22), x_1_v301); + x_2_v301 = byte_pattern::temp_instance().get_first().address(0xB - 0x22); } else return CK2ERROR1; return NOERROR; diff --git a/Plugin/NickNameFix.cpp b/Plugin/NickNameFix.cpp index ab6909a..dc1f711 100644 --- a/Plugin/NickNameFix.cpp +++ b/Plugin/NickNameFix.cpp @@ -338,13 +338,13 @@ namespace NickNameFix else return CK2ERROR1; return NOERROR; case v3_0_X: - // lea ecx,[ebp+var_DC] - byte_pattern::temp_instance().find_pattern("8D 8D 24 FF FF FF E8 F1 8A EF FF"); + // mov ecx, [edi+7Ch] + byte_pattern::temp_instance().find_pattern("8B 75 08 C6 45 FC 19 8B 4F 7C"); if (byte_pattern::temp_instance().has_size(1, desc)) { // lea eax,[ebp+var_C4] - injector::MakeJMP(byte_pattern::temp_instance().get_first().address(-0x59), start); - - issue_14_end_R_v30 = byte_pattern::temp_instance().get_first().address(); + injector::MakeJMP(byte_pattern::temp_instance().get_first().address(-0x4A), start); + // lea ecx,[ebp+var_DC] + issue_14_end_R_v30 = byte_pattern::temp_instance().get_first().address(0xF); } else return CK2ERROR1; return NOERROR; diff --git a/Plugin/dllmain.cpp b/Plugin/dllmain.cpp index d8791c3..b798934 100644 --- a/Plugin/dllmain.cpp +++ b/Plugin/dllmain.cpp @@ -91,7 +91,7 @@ BOOL WINAPI DllMain(HMODULE module, DWORD reason, void *reserved) byte_pattern::debug_output2("Multibyte DLL [OK]"); } else { - MessageBoxW(NULL, L"[Multibyte DLL ERROR]\n\nYour current version is 3.0.1.1 is not supported by now.\n\nThe latest supprot version is 3.0.1, please rollback your main exe.\n\Or play game in english after delete d3d9.dll...\n\n Thanks", L"Multibyte DLL", MB_OK); + MessageBoxW(NULL, L"[Multibyte DLL ERROR]\n\nThe latest supprot version is 3.0.1.1, please rollback your main exe.\n\Or play game in english after delete d3d9.dll...\n\n Thanks", L"Multibyte DLL", MB_OK); byte_pattern::debug_output2("Multibyte DLL [NG]"); exit(-1); } diff --git a/README.md b/README.md index 76f4f67..1ec5a4c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ This dll makes it possible to display double-byte characters on Crusader Kings I ## Find bugs If you find a bug, **create a issue** in this repository. If possible, please write the issue report in English. However you can also create it in your language (Japanese, Korean, Chinese, Russian etc). + +## Autoupdate +Plugin.dll will be updated automatically. It requires an Internet connection at game run. If you do not need or play offline game, please DELETE "plugins/autoupdate.bat" file. ## Licence MIT Licence @@ -23,5 +26,5 @@ This dll was forked by the following project. Thank you so much. [EU4CHS](https://bitbucket.org/kelashi/eu4chs/src/master/) -## ini - ini +## plugin.ini + TBD diff --git a/d3d9/d3d9.vcxproj b/d3d9/d3d9.vcxproj index c155774..802a8aa 100644 --- a/d3d9/d3d9.vcxproj +++ b/d3d9/d3d9.vcxproj @@ -87,6 +87,10 @@ + + + + diff --git a/d3d9/d3d9.vcxproj.filters b/d3d9/d3d9.vcxproj.filters index fe5e0c9..ee0dbc0 100644 --- a/d3d9/d3d9.vcxproj.filters +++ b/d3d9/d3d9.vcxproj.filters @@ -18,5 +18,13 @@ 貅先枚莉カ + + 貅先枚莉カ + + + + + 螟エ譁莉カ + \ No newline at end of file diff --git a/d3d9/dllmain.cpp b/d3d9/dllmain.cpp index e83fad1..0b5d73f 100644 --- a/d3d9/dllmain.cpp +++ b/d3d9/dllmain.cpp @@ -8,6 +8,8 @@ #include #pragma comment(lib, "Ole32.lib") +#include "filedl.h" + using namespace std; using namespace std::experimental::filesystem::v1; @@ -58,10 +60,15 @@ void Initialize(HMODULE hSelf) { wchar_t pluginpath[MAX_PATH]; - GetModuleFileNameW(hSelf, pluginpath, MAX_PATH); + GetModuleFileNameW(hSelf, pluginpath, MAX_PATH); + + const path pluginsPath = path{ pluginpath }.parent_path() / L"plugins"; + + if (!InitAutoUpdate(pluginsPath)) exit(-1); InitD3D9(); - LoadScripts(path{ pluginpath }.parent_path() / L"plugins"); + + LoadScripts(pluginsPath); } BOOL WINAPI DllMain(HMODULE module, DWORD reason, LPVOID reserved) diff --git a/d3d9/filedl.cpp b/d3d9/filedl.cpp new file mode 100644 index 0000000..bb17b06 --- /dev/null +++ b/d3d9/filedl.cpp @@ -0,0 +1,55 @@ +#include "filedl.h" + +bool createProcess(WCHAR* szCmd, DWORD flag) { + STARTUPINFO si; + PROCESS_INFORMATION pi; + WCHAR *message = L"Autoupdate error. Please DELETE 'plugins/autoupdate.bat'."; + WCHAR *title = NULL; + + memset(&si, 0, sizeof(STARTUPINFO)); + memset(&pi, 0, sizeof(PROCESS_INFORMATION)); + si.cb = sizeof(STARTUPINFO); + + BOOL createProcessSuccess = CreateProcess(NULL, szCmd, NULL, NULL, FALSE, flag, NULL, NULL, &si, &pi); + + if (!createProcessSuccess) { + title = L"Autoupdate createProcess failed."; + } + else { + DWORD result = WaitForSingleObject(pi.hProcess, 10 * 1000); // 10 sec + switch (result) + { + case WAIT_FAILED: + title = L"Autoupdate wait failed."; + break; + case WAIT_TIMEOUT: + title = L"Autoupdate wait timeout."; + break; + default: + break; + } + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + if (title != NULL) { + MessageBox(NULL, message, title, MB_OK); + return false; + } + } + + return true; +} + +bool InitAutoUpdate(const path &pluginsPath) +{ + path batFilePath = path{ pluginsPath } / L"autoupdate.bat"; + + if (std::experimental::filesystem::exists(batFilePath)) { + return createProcess( + wcsdup(batFilePath.c_str()), + CREATE_NO_WINDOW + ); + } + + return true; +} diff --git a/d3d9/filedl.h b/d3d9/filedl.h new file mode 100644 index 0000000..6b93537 --- /dev/null +++ b/d3d9/filedl.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include +#include +#include + +using namespace std; +using namespace std::experimental::filesystem::v1; + +bool InitAutoUpdate(const path &folder); \ No newline at end of file diff --git a/other/autoupdate.bat b/other/autoupdate.bat new file mode 100644 index 0000000..3a012b2 --- /dev/null +++ b/other/autoupdate.bat @@ -0,0 +1,25 @@ +cd /d %~dp0 + +SET pluginMD5= +SET exeMD5= + +rem https://stackoverflow.com/questions/38771114/saving-result-of-certutil-hashfile-to-a-variable-and-remove-spaces-of-the-hash + +setlocal enabledelayedexpansion +set /a count=1 +for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile ./plugin.dll MD5') do ( + if !count! equ 1 set "pluginMD5=%%a" + set/a count+=1 +) +set "pluginMD5=%pluginMD5: =% + +set /a count=1 +for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile ../ck2game.exe MD5') do ( + if !count! equ 1 set "exeMD5=%%a" + set/a count+=1 +) +set "exeMD5=%exeMD5: =% + +set url=https://d3mq2c18xv0s3o.cloudfront.net/api/v1/distribution/139275487/%exeMD5%?dll_md5=%pluginMD5% + +call "curl.exe" -k -f --connect-timeout 3 -m 6 -s -o "Plugin.dll" %url% diff --git a/other/autoupdate_test.bat b/other/autoupdate_test.bat new file mode 100644 index 0000000..a735ec6 --- /dev/null +++ b/other/autoupdate_test.bat @@ -0,0 +1,29 @@ +cd /d %~dp0 + +SET pluginMD5= +SET exeMD5= + +rem https://stackoverflow.com/questions/38771114/saving-result-of-certutil-hashfile-to-a-variable-and-remove-spaces-of-the-hash + +setlocal enabledelayedexpansion +set /a count=1 +for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile ./plugin.dll MD5') do ( + if !count! equ 1 set "pluginMD5=%%a" + set/a count+=1 +) +set "pluginMD5=%pluginMD5: =% + +set /a count=1 +for /f "skip=1 delims=:" %%a in ('CertUtil -hashfile ../ck2game.exe MD5') do ( + if !count! equ 1 set "exeMD5=%%a" + set/a count+=1 +) +set "exeMD5=%exeMD5: =% + +set url=https://d3mq2c18xv0s3o.cloudfront.net/api/v1/distribution/139275487/%exeMD5%?dll_md5=%pluginMD5% + +echo %url% + +call "curl.exe" -f -k -v --connect-timeout 3 -m 6 -o "Plugin.dll" %url% + +pause \ No newline at end of file diff --git a/other/curl.exe b/other/curl.exe new file mode 100644 index 0000000..bd47ad2 Binary files /dev/null and b/other/curl.exe differ diff --git a/plugin.ini b/other/plugin.ini similarity index 100% rename from plugin.ini rename to other/plugin.ini