From 97c6999f9b57848f7fa6264d7c5a808b9e72317f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Fri, 29 Nov 2024 18:33:04 +0800 Subject: [PATCH] . --- cpp/LunaHook/LunaHook/engine64/vita3k.cpp | 60 +++++++++++++++---- cpp/LunaHook/LunaHook/engine64/yuzu.cpp | 36 +++++------ .../LunaHook/engines/ppsspp/ppsspp.cpp | 18 +++--- cpp/LunaHook/LunaHook/util/util.cc | 30 +++++----- cpp/version.cmake | 2 +- 5 files changed, 88 insertions(+), 58 deletions(-) diff --git a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp index f683b877..7ff07999 100644 --- a/cpp/LunaHook/LunaHook/engine64/vita3k.cpp +++ b/cpp/LunaHook/LunaHook/engine64/vita3k.cpp @@ -4,6 +4,7 @@ namespace auto isVirtual = true; auto idxDescriptor = isVirtual == true ? 2 : 1; auto idxEntrypoint = idxDescriptor + 1; + std::string Vita3KGameID; uintptr_t getDoJitAddress() { auto RegisterBlockSig1 = "40 55 53 56 57 41 54 41 56 41 57 48 8D 6C 24 E9 48 81 EC 90 00 00 00 48 8B ?? ?? ?? ?? ?? 48 33 C4 48 89 45 07 4D 8B F1 49 8B F0 48 8B FA 48 8B D9 4C 8B 7D 77 48 8B 01 48 8D 55 C7 FF 50 10"; @@ -45,24 +46,60 @@ namespace }; std::unordered_map emfunctionhooks; - bool checkiscurrentgame(const emfuncinfo &em) - { - auto wininfos = get_proc_windows(); - for (auto &&info : wininfos) - { - if (info.title.find(acastw(em._id)) != info.title.npos) - return true; - } - return false; - } } +namespace +{ + void trygetgameinwindowtitle() + { + + HookParam hp; + hp.address = 0x3000; + hp.text_fun = [](hook_stack *stack, HookParam *hp, TextBuffer *buffer, uintptr_t *split) + { + static std::wstring last; + // vita3k Vulkan模式GetWindowText会卡住 + auto getSecondSubstring = [](const std::wstring &str) -> std::wstring + { + size_t firstPos = str.find(L'|'); + if (firstPos == std::wstring::npos) + return L""; + size_t nextPos = str.find(L'|', firstPos + 1); + if (nextPos == std::wstring::npos) + return L""; + size_t start = firstPos + 1; + size_t end = nextPos; + return str.substr(start, end - start); + }; + auto wininfos = get_proc_windows(); + for (auto &&info : wininfos) + { + auto game = getSecondSubstring(info.title); + if (!game.size()) + continue; + std::wregex reg1(L"\\((.*?)\\)"); + std::wsmatch match; + if (!std::regex_search(game, match, reg1)) + return; + auto curr = match[1].str(); + if (last == curr) + return; + Vita3KGameID = wcasta(curr); + last = curr; + return HostInfo(HOSTINFO::EmuGameName, WideStringToString(game).c_str()); + } + }; + hp.type = DIRECT_READ; + NewHook(hp, "Vita3KGameInfo"); + } +} bool vita3k::attach_function() { ConsoleOutput("[Compatibility] Vita3k 0.1.9 3339+"); auto DoJitPtr = getDoJitAddress(); if (DoJitPtr == 0) return false; + trygetgameinwindowtitle(); spDefault.isjithook = true; spDefault.minAddress = 0; spDefault.maxAddress = -1; @@ -84,9 +121,8 @@ bool vita3k::attach_function() if (emfunctionhooks.find(em_address) == emfunctionhooks.end()) return; auto op = emfunctionhooks.at(em_address); - if (!(checkiscurrentgame(op))) + if (Vita3KGameID.size() && (op._id != Vita3KGameID)) return; - HookParam hpinternal; hpinternal.address = entrypoint; hpinternal.emu_addr = em_address; // 用于生成hcode diff --git a/cpp/LunaHook/LunaHook/engine64/yuzu.cpp b/cpp/LunaHook/LunaHook/engine64/yuzu.cpp index edfde146..67b63c3e 100644 --- a/cpp/LunaHook/LunaHook/engine64/yuzu.cpp +++ b/cpp/LunaHook/LunaHook/engine64/yuzu.cpp @@ -63,21 +63,19 @@ namespace } game_info; bool checkiscurrentgame(const emfuncinfo &em) { - auto wininfos = get_proc_windows(); - for (auto &&info : wininfos) + if ((game_info.version.size()) && game_info.name.size() && (game_info.id != 0)) { - if ((game_info.version.size()) && game_info.name.size() && (game_info.id != 0)) - { - // 判断是有效的info - auto checkversion = (em._version == 0) || (std::string(em._version) == (game_info.version)); - auto checkid = (std::stoll(em._id, 0, 16) == game_info.id); - if (checkid && checkversion) - return true; - } - else if ((em._version == 0) || (info.title.find(acastw(em._version)) != info.title.npos)) - return true; + // 判断是有效的info + auto checkversion = (em._version == 0) || (std::string(em._version) == (game_info.version)); + auto checkid = (std::stoll(em._id, 0, 16) == game_info.id); + return checkid && checkversion; + } + else + { + // 加载游戏后在hook,没有办法获取id。 + // 标题里没有id,只有version,没啥必要判断了,直接true得了。 + return true; } - return false; } } bool Hook_Network_RoomMember_SendGameInfo() @@ -147,17 +145,11 @@ namespace size_t firstPos = str.find(L'|'); if (firstPos == std::wstring::npos) return L""; - size_t lastPos = str.rfind(L'|'); - if (lastPos == std::wstring::npos) - return L""; - lastPos = str.rfind(L'|', lastPos - 1); - if (lastPos == std::wstring::npos) - return L""; - lastPos = str.rfind(L'(', lastPos - 1); - if (lastPos == std::wstring::npos) + size_t nextPos = str.find(L'|', firstPos + 1); + if (nextPos == std::wstring::npos) return L""; size_t start = firstPos + 1; - size_t end = lastPos; + size_t end = nextPos; return str.substr(start, end - start); }; auto wininfos = get_proc_windows(); diff --git a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp index 56aecf2d..0cdfaa8b 100644 --- a/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp +++ b/cpp/LunaHook/LunaHook/engines/ppsspp/ppsspp.cpp @@ -275,19 +275,21 @@ namespace ppsspp } game_info; bool checkiscurrentgame(const emfuncinfo &em) { - auto wininfos = get_proc_windows(); - for (auto &&info : wininfos) + if (game_info.DISC_ID.size()) { - if (game_info.DISC_ID.size()) + std::smatch match; + return std::regex_match(game_info.DISC_ID, match, std::regex(em._id)); + } + else + { + auto wininfos = get_proc_windows(); + for (auto &&info : wininfos) { - std::smatch match; - if (std::regex_match(game_info.DISC_ID, match, std::regex(em._id))) + if (std::regex_search(info.title, std::wregex(acastw(em._id)))) return true; } - else if (std::regex_search(info.title, std::wregex(acastw(em._id)))) - return true; + return false; } - return false; } std::unordered_set breakpoints; diff --git a/cpp/LunaHook/LunaHook/util/util.cc b/cpp/LunaHook/LunaHook/util/util.cc index b7eed390..2dca52eb 100644 --- a/cpp/LunaHook/LunaHook/util/util.cc +++ b/cpp/LunaHook/LunaHook/util/util.cc @@ -735,27 +735,27 @@ bool Engine::isAddressWritable(const wchar_t *p, size_t count) BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { - std::vector *windowList = reinterpret_cast *>(lParam); + auto *hwnds = reinterpret_cast *>(lParam); DWORD processId; - GetWindowThreadProcessId(hwnd, &processId); - if (processId == GetCurrentProcessId()) - { - auto length = GetWindowTextLengthW(hwnd); - auto title = std::vector(length + 1); - GetWindowTextW(hwnd, title.data(), title.size()); - - WindowInfo windowInfo; - windowInfo.handle = hwnd; - windowInfo.title = title.data(); - - windowList->push_back(windowInfo); - } + if (GetWindowThreadProcessId(hwnd, &processId) && (processId == GetCurrentProcessId())) + hwnds->push_back(hwnd); return TRUE; } std::vector get_proc_windows() { + std::vector hwnds; std::vector windows; - EnumWindows(EnumWindowsProc, reinterpret_cast(&windows)); + EnumWindows(EnumWindowsProc, reinterpret_cast(&hwnds)); + for (auto hwnd : hwnds) + { + WindowInfo windowInfo; + windowInfo.handle = hwnd; + auto length = GetWindowTextLengthW(hwnd); + auto title = std::vector(length + 1); + GetWindowTextW(hwnd, title.data(), title.size()); + windowInfo.title = title.data(); + windows.emplace_back(windowInfo); + } return windows; } diff --git a/cpp/version.cmake b/cpp/version.cmake index 5aa7f9c8..58221ae5 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 6) set(VERSION_MINOR 7) -set(VERSION_PATCH 1) +set(VERSION_PATCH 2) set(VERSION_REVISION 0) set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)