diff --git a/src/dbg/patches.cpp b/src/dbg/patches.cpp index ad1aa5a9..b4f99f1b 100644 --- a/src/dbg/patches.cpp +++ b/src/dbg/patches.cpp @@ -212,19 +212,18 @@ int PatchFile(const PATCHINFO* List, int Count, const char* FileName, char* Erro return -1; } - // Get the unicode version of the module's path - wchar_t originalName[MAX_PATH]; - - if(!GetModuleFileNameExW(fdProcessInfo->hProcess, (HMODULE)moduleBase, originalName, ARRAYSIZE(originalName))) + //get the origin module path + char modPath[MAX_PATH] = ""; + if(!ModPathFromAddr(moduleBase, modPath, MAX_PATH)) { - if(Error) + if (Error) sprintf_s(Error, MAX_ERROR_SIZE, "Failed to get module path of module %s", moduleName); return -1; } // Create a temporary backup file - if(!CopyFileW(originalName, StringUtils::Utf8ToUtf16(FileName).c_str(), false)) + if (!CopyFileW(StringUtils::Utf8ToUtf16(modPath).c_str(), StringUtils::Utf8ToUtf16(FileName).c_str(), false)) { if(Error) strcpy_s(Error, MAX_ERROR_SIZE, "Failed to make a copy of the original file (patch target is in use?)");