1
1
mirror of synced 2025-02-01 11:57:57 +01:00

Add support for UTF8 path

This commit is contained in:
esuo1198 2024-03-22 20:58:36 +09:00
parent 9e8375a21b
commit b452adeaed
5 changed files with 27 additions and 39 deletions

3
.gitignore vendored
View File

@ -12,4 +12,5 @@ subprojects/safetyhook
subprojects/zxing-cpp-2.2.1
subprojects/stb
dist.7z
.vscode
.vscode
out/

View File

@ -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',

View File

@ -8,6 +8,7 @@
#include <iostream>
#include <vector>
#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<stbi_uc, void (*) (void *)> buffer (stbi_load (imagePath, &width, &height, &channels, 3), stbi_image_free);
std::unique_ptr<stbi_uc, void (*) (void *)> 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: {

View File

@ -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,
+)

View File

@ -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