This commit is contained in:
恍兮惚兮 2024-11-29 18:33:04 +08:00
parent 1056df85c6
commit 97c6999f9b
5 changed files with 88 additions and 58 deletions

View File

@ -4,6 +4,7 @@ namespace
auto isVirtual = true; auto isVirtual = true;
auto idxDescriptor = isVirtual == true ? 2 : 1; auto idxDescriptor = isVirtual == true ? 2 : 1;
auto idxEntrypoint = idxDescriptor + 1; auto idxEntrypoint = idxDescriptor + 1;
std::string Vita3KGameID;
uintptr_t getDoJitAddress() 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"; 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<uintptr_t, emfuncinfo> emfunctionhooks; std::unordered_map<uintptr_t, emfuncinfo> 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() bool vita3k::attach_function()
{ {
ConsoleOutput("[Compatibility] Vita3k 0.1.9 3339+"); ConsoleOutput("[Compatibility] Vita3k 0.1.9 3339+");
auto DoJitPtr = getDoJitAddress(); auto DoJitPtr = getDoJitAddress();
if (DoJitPtr == 0) if (DoJitPtr == 0)
return false; return false;
trygetgameinwindowtitle();
spDefault.isjithook = true; spDefault.isjithook = true;
spDefault.minAddress = 0; spDefault.minAddress = 0;
spDefault.maxAddress = -1; spDefault.maxAddress = -1;
@ -84,9 +121,8 @@ bool vita3k::attach_function()
if (emfunctionhooks.find(em_address) == emfunctionhooks.end()) if (emfunctionhooks.find(em_address) == emfunctionhooks.end())
return; return;
auto op = emfunctionhooks.at(em_address); auto op = emfunctionhooks.at(em_address);
if (!(checkiscurrentgame(op))) if (Vita3KGameID.size() && (op._id != Vita3KGameID))
return; return;
HookParam hpinternal; HookParam hpinternal;
hpinternal.address = entrypoint; hpinternal.address = entrypoint;
hpinternal.emu_addr = em_address; // 用于生成hcode hpinternal.emu_addr = em_address; // 用于生成hcode

View File

@ -63,21 +63,19 @@ namespace
} game_info; } game_info;
bool checkiscurrentgame(const emfuncinfo &em) bool checkiscurrentgame(const emfuncinfo &em)
{ {
auto wininfos = get_proc_windows(); if ((game_info.version.size()) && game_info.name.size() && (game_info.id != 0))
for (auto &&info : wininfos)
{ {
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));
// 判断是有效的info auto checkid = (std::stoll(em._id, 0, 16) == game_info.id);
auto checkversion = (em._version == 0) || (std::string(em._version) == (game_info.version)); return checkid && checkversion;
auto checkid = (std::stoll(em._id, 0, 16) == game_info.id); }
if (checkid && checkversion) else
return true; {
} // 加载游戏后在hook没有办法获取id。
else if ((em._version == 0) || (info.title.find(acastw(em._version)) != info.title.npos)) // 标题里没有id只有version没啥必要判断了直接true得了。
return true; return true;
} }
return false;
} }
} }
bool Hook_Network_RoomMember_SendGameInfo() bool Hook_Network_RoomMember_SendGameInfo()
@ -147,17 +145,11 @@ namespace
size_t firstPos = str.find(L'|'); size_t firstPos = str.find(L'|');
if (firstPos == std::wstring::npos) if (firstPos == std::wstring::npos)
return L""; return L"";
size_t lastPos = str.rfind(L'|'); size_t nextPos = str.find(L'|', firstPos + 1);
if (lastPos == std::wstring::npos) if (nextPos == 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)
return L""; return L"";
size_t start = firstPos + 1; size_t start = firstPos + 1;
size_t end = lastPos; size_t end = nextPos;
return str.substr(start, end - start); return str.substr(start, end - start);
}; };
auto wininfos = get_proc_windows(); auto wininfos = get_proc_windows();

View File

@ -275,19 +275,21 @@ namespace ppsspp
} game_info; } game_info;
bool checkiscurrentgame(const emfuncinfo &em) bool checkiscurrentgame(const emfuncinfo &em)
{ {
auto wininfos = get_proc_windows(); if (game_info.DISC_ID.size())
for (auto &&info : wininfos)
{ {
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_search(info.title, std::wregex(acastw(em._id))))
if (std::regex_match(game_info.DISC_ID, match, std::regex(em._id)))
return true; return true;
} }
else if (std::regex_search(info.title, std::wregex(acastw(em._id)))) return false;
return true;
} }
return false;
} }
std::unordered_set<uintptr_t> breakpoints; std::unordered_set<uintptr_t> breakpoints;

View File

@ -735,27 +735,27 @@ bool Engine::isAddressWritable(const wchar_t *p, size_t count)
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{ {
std::vector<WindowInfo> *windowList = reinterpret_cast<std::vector<WindowInfo> *>(lParam); auto *hwnds = reinterpret_cast<std::vector<HWND> *>(lParam);
DWORD processId; DWORD processId;
GetWindowThreadProcessId(hwnd, &processId); if (GetWindowThreadProcessId(hwnd, &processId) && (processId == GetCurrentProcessId()))
if (processId == GetCurrentProcessId()) hwnds->push_back(hwnd);
{
auto length = GetWindowTextLengthW(hwnd);
auto title = std::vector<WCHAR>(length + 1);
GetWindowTextW(hwnd, title.data(), title.size());
WindowInfo windowInfo;
windowInfo.handle = hwnd;
windowInfo.title = title.data();
windowList->push_back(windowInfo);
}
return TRUE; return TRUE;
} }
std::vector<WindowInfo> get_proc_windows() std::vector<WindowInfo> get_proc_windows()
{ {
std::vector<HWND> hwnds;
std::vector<WindowInfo> windows; std::vector<WindowInfo> windows;
EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&windows)); EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&hwnds));
for (auto hwnd : hwnds)
{
WindowInfo windowInfo;
windowInfo.handle = hwnd;
auto length = GetWindowTextLengthW(hwnd);
auto title = std::vector<WCHAR>(length + 1);
GetWindowTextW(hwnd, title.data(), title.size());
windowInfo.title = title.data();
windows.emplace_back(windowInfo);
}
return windows; return windows;
} }

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6) set(VERSION_MAJOR 6)
set(VERSION_MINOR 7) set(VERSION_MINOR 7)
set(VERSION_PATCH 1) set(VERSION_PATCH 2)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)