diff --git a/LunaHook/engine64/PPSSPP.cpp b/LunaHook/engine64/PPSSPP.cpp index 052c8a3..1c0c9ff 100644 --- a/LunaHook/engine64/PPSSPP.cpp +++ b/LunaHook/engine64/PPSSPP.cpp @@ -77,6 +77,14 @@ struct emfuncinfo{ }; std::unordered_mapemfunctionhooks; std::unordered_setbreakpoints; + +bool checkiscurrentgame(const emfuncinfo& em){ + auto wininfos=get_proc_windows(); + for(auto&& info:wininfos){ + if(info.title.find(em._id)!=info.title.npos)return true; + } + return false; +} } bool hookPPSSPPDoJit(){ ConsoleOutput("[Compatibility] PPSSPP 1.12.3-867 -> v1.16.1-35"); @@ -90,7 +98,9 @@ bool hookPPSSPPDoJit(){ auto em_address=stack->ARG2; if(emfunctionhooks.find(em_address)==emfunctionhooks.end())return; - + + if(!(checkiscurrentgame(emfunctionhooks.at(em_address))))return; + HookParam hpinternal; hpinternal.user_value=em_address; hpinternal.address=stack->retaddr; @@ -104,8 +114,6 @@ bool hookPPSSPPDoJit(){ auto em_address=hp->user_value; auto op=emfunctionhooks.at(em_address); - DWORD _; - VirtualProtect((LPVOID)ret,0x10,PAGE_EXECUTE_READWRITE,&_); HookParam hpinternal; hpinternal.address=ret; hpinternal.user_value=em_address; diff --git a/LunaHook/engine64/yuzusuyu.cpp b/LunaHook/engine64/yuzusuyu.cpp index 28e41ed..3a66656 100644 --- a/LunaHook/engine64/yuzusuyu.cpp +++ b/LunaHook/engine64/yuzusuyu.cpp @@ -81,11 +81,20 @@ public: struct emfuncinfo{ const char* hookname; void* hookfunc; + void* filterfun; const wchar_t* _id; const wchar_t* _version; }; std::unordered_mapemfunctionhooks; + +bool checkiscurrentgame(const emfuncinfo& em){ + auto wininfos=get_proc_windows(); + for(auto&& info:wininfos){ + if(info.title.find(em._version)!=info.title.npos)return true; + } + return false; +} } bool yuzusuyu::attach_function() { @@ -101,15 +110,14 @@ bool yuzusuyu::attach_function() auto em_address = *(uintptr_t*)descriptor; em_address-=0x80004000; if(emfunctionhooks.find(em_address)==emfunctionhooks.end() || !entrypoint)return; - auto op=emfunctionhooks.at(em_address); - - DWORD _; - VirtualProtect((LPVOID)entrypoint,0x10,PAGE_EXECUTE_READWRITE,&_); + if(!(checkiscurrentgame(op)))return; + HookParam hpinternal; hpinternal.address=entrypoint; hpinternal.type=CODEC_UTF16|USING_STRING|NO_CONTEXT; hpinternal.text_fun=(decltype(hpinternal.text_fun))op.hookfunc; + hpinternal.filter_fun=(decltype(hpinternal.filter_fun))op.filterfun; NewHook(hpinternal,op.hookname); }; @@ -125,11 +133,34 @@ void _0100978013276000(hook_stack* stack, HookParam* hp, uintptr_t* data, uintpt auto s=mages::readString(emu_arg(stack)[0],0); write_string_new(data,len,s); } + +// @name [0100A460141B8000] Shiro to Kuro no Alice +// @version 1.0.0 +// @author Koukdw +// @description +// * Kogado Girls Project +// * Idea Factory (アイディアファクトリー) & Otomate +// * AliceNX_MPA (string inside binary) +// * +void _0100A460141B8000(hook_stack* stack, HookParam* hp, uintptr_t* data, uintptr_t* split, size_t* len){ + auto address=emu_arg(stack)[0]; + hp->type=USING_STRING|CODEC_UTF8|NO_CONTEXT; + *data=address;*len=strlen((char*)address); +} namespace{ auto _=[](){ emfunctionhooks={ - {0x8003eeac - 0x80004000,{"Memories Off",_0100978013276000,L"0100978013276000",L"1.0.0"}}, - {0x8003eebc - 0x80004000,{"Memories Off",_0100978013276000,L"0100978013276000",L"1.0.1"}}, + {0x8003eeac - 0x80004000,{"Memories Off",_0100978013276000,0,L"0100978013276000",L"1.0.0"}}, + {0x8003eebc - 0x80004000,{"Memories Off",_0100978013276000,0,L"0100978013276000",L"1.0.1"}}, + + // Shiro to Kuro no Alice + {0x80013f20 - 0x80004000,{"Shiro to Kuro no Alice",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, + {0x80013f94 - 0x80004000,{"Shiro to Kuro no Alice",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, + {0x8001419c - 0x80004000,{"Shiro to Kuro no Alice",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, + // Shiro to Kuro no Alice -Twilight line- + {0x80014260 - 0x80004000,{"Shiro to Kuro no Alice -Twilight line-",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, + {0x800142d4 - 0x80004000,{"Shiro to Kuro no Alice -Twilight line-",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, + {0x800144dc - 0x80004000,{"Shiro to Kuro no Alice -Twilight line-",_0100A460141B8000,NewLineCharFilterW,L"0100A460141B8000",L"1.0.0"}}, }; return 1; }(); diff --git a/LunaHook/util/util.cc b/LunaHook/util/util.cc index a4c221c..54f77d8 100644 --- a/LunaHook/util/util.cc +++ b/LunaHook/util/util.cc @@ -604,4 +604,29 @@ void write_string_new(uintptr_t* data, size_t* len,const std::wstring& s){write_ void write_string_new(uintptr_t* data, size_t* len,const std::string& s){write_string_new_impl(data,len,s);} bool write_string_overwrite(void* data, size_t* len,const std::wstring& s){return write_string_overwrite_impl(data,len,s);} -bool write_string_overwrite(void* data, size_t* len,const std::string& s){return write_string_overwrite_impl(data,len,s);} \ No newline at end of file +bool write_string_overwrite(void* data, size_t* len,const std::string& s){return write_string_overwrite_impl(data,len,s);} + + + +BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) { + std::vector* windowList = 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); + } + return TRUE; +} +std::vectorget_proc_windows(){ + std::vector windows; + EnumWindows(EnumWindowsProc, reinterpret_cast(&windows)); + return windows; +} \ No newline at end of file diff --git a/LunaHook/util/util.h b/LunaHook/util/util.h index d84bd5a..d4ce98c 100644 --- a/LunaHook/util/util.h +++ b/LunaHook/util/util.h @@ -80,4 +80,11 @@ inline bool isAddressWritable(uintptr_t addr) { return isAddressWritable((const void write_string_new(uintptr_t* data, size_t* len,const std::wstring& s); void write_string_new(uintptr_t* data, size_t* len,const std::string& s); bool write_string_overwrite(void* data, size_t* len,const std::wstring& s); -bool write_string_overwrite(void* data, size_t* len,const std::string& s); \ No newline at end of file +bool write_string_overwrite(void* data, size_t* len,const std::string& s); + + +struct WindowInfo { + HWND handle; + std::wstring title; +}; +std::vectorget_proc_windows(); \ No newline at end of file