From b452adeaed97015c639bec989b16a647410fa498 Mon Sep 17 00:00:00 2001 From: esuo1198 <54134.es@gmail.com> Date: Fri, 22 Mar 2024 20:58:36 +0900 Subject: [PATCH] Add support for UTF8 path --- .gitignore | 3 ++- meson.build | 16 ++++++++++------ src/patches/qr.cpp | 16 ++++++++++------ subprojects/packagefiles/safetyhook.patch | 18 ------------------ subprojects/safetyhook.wrap | 13 +++++-------- 5 files changed, 27 insertions(+), 39 deletions(-) delete mode 100644 subprojects/packagefiles/safetyhook.patch diff --git a/.gitignore b/.gitignore index dff58de..d8ed9b1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ subprojects/safetyhook subprojects/zxing-cpp-2.2.1 subprojects/stb dist.7z -.vscode \ No newline at end of file +.vscode +out/ \ No newline at end of file diff --git a/meson.build b/meson.build index 0c1f4a1..a5c6973 100644 --- a/meson.build +++ b/meson.build @@ -4,6 +4,9 @@ debug = true optimization = 3 b_lto = true b_pgo = 'use' +cmake = import('cmake') +opt_var = cmake.subproject_options() +opt_var.set_override_option('cpp_std', 'c++23') cpp = meson.get_compiler('cpp') @@ -20,8 +23,7 @@ add_project_link_arguments( #'-s', '-lws2_32', '-lssp', - '-lntdll', - '-Wl,--allow-multiple-definition' + '-lntdll' ), language: 'cpp', ) @@ -30,9 +32,12 @@ minhook = subproject('minhook') tomlc99 = subproject('tomlc99') sdl2 = subproject('sdl2', default_options: ['default_library=static', 'test=false', 'use_render=disabled']) xxhash = subproject('xxhash', default_options: ['default_library=static', 'cli=false']) -safetyhook = subproject('safetyhook') +opt_var.add_cmake_defines({'SAFETYHOOK_FETCH_ZYDIS': true}) +safetyhook_proj = cmake.subproject('safetyhook', options: opt_var) +safetyhook_dep = safetyhook_proj.dependency('safetyhook') stb = subproject('stb') -zxing_dep = dependency('ZXing') +zxing_proj = cmake.subproject('zxing', options: opt_var) +zxing_dep = zxing_proj.dependency('ZXing') library( 'bnusio', @@ -41,7 +46,6 @@ library( tomlc99.get_variable('tomlc99_lib'), sdl2.get_variable('sdl2'), xxhash.get_variable('xxhash'), - safetyhook.get_variable('safetyhook_lib'), ], include_directories: [ 'src', @@ -49,10 +53,10 @@ library( tomlc99.get_variable('tomlc99_inc'), sdl2.get_variable('core_inc'), xxhash.get_variable('inc'), - safetyhook.get_variable('safetyhook_inc'), ], dependencies: [stb.get_variable('stb_dep'), zxing_dep, + safetyhook_dep, ], sources : [ 'src/dllmain.cpp', diff --git a/src/patches/qr.cpp b/src/patches/qr.cpp index dc6c5f0..66cf0e3 100644 --- a/src/patches/qr.cpp +++ b/src/patches/qr.cpp @@ -8,6 +8,7 @@ #include #include #define STB_IMAGE_IMPLEMENTATION +#define STBI_WINDOWS_UTF8 #include "stb_image.h" extern GameVersion gameVersion; @@ -107,24 +108,26 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { gState = State::Ready; return byteBuffer.size (); } else { - const char *imagePath = ""; + std::string imagePath = ""; if (config) { auto qr = openConfigSection (config, "qr"); - if (qr) imagePath = readConfigString (qr, "image_path", imagePath); + if (qr) imagePath = readConfigString (qr, "image_path", ""); } - if (!std::filesystem::is_regular_file (imagePath)) { - std::cerr << "Failed to open image: " << imagePath << " (file not found)" + std::u8string u8PathStr (imagePath.begin (), imagePath.end ()); + std::filesystem::path u8Path (u8PathStr); + if (!std::filesystem::is_regular_file (u8Path)) { + std::cerr << "Failed to open image: " << u8Path.string () << " (file not found)" << "\n"; gState = State::Ready; return 0; } int width, height, channels; - std::unique_ptr buffer (stbi_load (imagePath, &width, &height, &channels, 3), stbi_image_free); + std::unique_ptr buffer (stbi_load (u8Path.string ().c_str (), &width, &height, &channels, 3), stbi_image_free); if (!buffer) { - std::cerr << "Failed to read image: " << imagePath << " (" << stbi_failure_reason () << ")" + std::cerr << "Failed to read image: " << u8Path << " (" << stbi_failure_reason () << ")" << "\n"; gState = State::Ready; return 0; @@ -185,6 +188,7 @@ Update () { void Init () { + SetConsoleOutputCP (CP_UTF8); auto amHandle = (u64)GetModuleHandle ("AMFrameWork.dll"); switch (gameVersion) { case GameVersion::JP_NOV_2020: { diff --git a/subprojects/packagefiles/safetyhook.patch b/subprojects/packagefiles/safetyhook.patch deleted file mode 100644 index 1286f17..0000000 --- a/subprojects/packagefiles/safetyhook.patch +++ /dev/null @@ -1,18 +0,0 @@ ---- safetyhook/meson.build -+++ safetyhook/meson.build -@@ -0,0 +1,15 @@ -+project('safetyhook', 'c', 'cpp', version: '0.1.3') -+ -+safetyhook_inc = include_directories('.') -+safetyhook_lib = static_library( -+ 'safetyhook', -+ include_directories: safetyhook_inc, -+ sources: [ -+ 'safetyhook.cpp', -+ 'Zydis.c' -+ ] -+) -+safetyhook_dep = declare_dependency( -+ link_with: safetyhook_lib, -+ include_directories: safetyhook_inc, -+) diff --git a/subprojects/safetyhook.wrap b/subprojects/safetyhook.wrap index bb5123c..0ec07f0 100644 --- a/subprojects/safetyhook.wrap +++ b/subprojects/safetyhook.wrap @@ -1,10 +1,7 @@ -[wrap-file] -directory = safetyhook -source_url = https://github.com/cursey/safetyhook/releases/download/v0.3.0/safetyhook-amalgamated-zydis.zip -source_filename = safetyhook-amalgamated-zydis.zip -source_hash = 274450d7baf6caee459752235d783ec24bd699b221b10c3df0fcce2a4e8e2ac8 -lead_directory_missing = yes -diff_files = safetyhook.patch +[wrap-git] +url = https://github.com/cursey/safetyhook.git +revision = v0.4.1 +method = cmake [provide] -libsafetyhook = safetyhook_dep +safetyhook = safetyhook_dep