Skip to content

Commit

Permalink
fix: 某些场景下目录名仍然显示为...
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveBeforT committed Jul 23, 2022
1 parent a79e54f commit ae989b2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions WarcraftHelper/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ void DetachHook(void* pOldFuncAddr, void* pNewFuncAddr)

void PatchMemory(uintptr_t pAddress, unsigned char* bytes, uint32_t size)
{
if (!pAddress) {
return;
}

void* address = reinterpret_cast<void*>(pAddress);

unsigned long Protection;
Expand All @@ -45,6 +49,22 @@ void PatchMemory(uintptr_t pAddress, unsigned char* bytes, uint32_t size)
VirtualProtect(address, size, Protection, &Protection);
}

void WriteNOP(void* pAddress, DWORD dwCount)
{
if (!pAddress) {
return;
}
static DWORD dwProtect;

if (VirtualProtect(pAddress, dwCount, PAGE_EXECUTE_READWRITE, &dwProtect))
{
for (DWORD i = 0; i < dwCount; i++)
*(BYTE*)((DWORD)pAddress + i) = 0x90;

VirtualProtect(pAddress, dwCount, dwProtect, &dwProtect);
}
}

DWORD War3_Search(void* pPattern, DWORD dwPatternLen, DWORD dwSearchStart, DWORD dwSearchEnd)
{
DWORD dwStartAddr = dwSearchStart;
Expand Down
1 change: 1 addition & 0 deletions WarcraftHelper/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ DWORD War3_Search(void* pPattern, DWORD dwPatternLen, DWORD dwSearchStart, DWORD
DWORD ReadDwordFromReg(LPCTSTR regPath, LPCTSTR keyName);
BOOL WriteDwordToReg(LPCTSTR regPath, LPCTSTR keyName, DWORD value);
void DetachHook(void* pOldFuncAddr, void* pNewFuncAddr);
void WriteNOP(void* pAddress, DWORD dwCount);
10 changes: 10 additions & 0 deletions WarcraftHelper/pathfix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

bool PathFix_Hooked = false;
DWORD GetPathName_addr = 0;
DWORD PathCopy_addr = 0;
DWORD PathCopy_size = 0;

int(__fastcall* orgGetPathName)(char*, DWORD, DWORD, float, char*, int) = 0;
int __fastcall GetPathName(char* nameGB2312, DWORD edx, DWORD unk00, float unk01, char* dst, int unk02) {
dst[0] = 0;
DWORD rst = orgGetPathName(nameGB2312, edx, unk00, unk01, dst, unk02);
if (dst) {
if (!strncmp(dst, "...", 3) || dst[0] == 0) {
Expand Down Expand Up @@ -38,17 +41,24 @@ void PathFix::Start(DWORD m_GamedllBase, Version m_War3Version) {
switch (m_War3Version) {
case Version::v120e:
GetPathName_addr = m_GamedllBase + 0x2603E0;
PathCopy_addr = m_GamedllBase + 0x260489;
PathCopy_size = 0x31;
break;
case Version::v124e:
GetPathName_addr = m_GamedllBase + 0x5BD690;
PathCopy_addr = m_GamedllBase + 0x5BD754;
PathCopy_size = 0x3B;
break;
case Version::v127a:
GetPathName_addr = m_GamedllBase + 0x2A2540;
PathCopy_addr = m_GamedllBase + 0x2A2619;
PathCopy_size = 0x35;
break;
default:
return;
}
InlineHook((void*)GetPathName_addr, GetPathName, (void*&)orgGetPathName);
WriteNOP((void*)PathCopy_addr, PathCopy_size);
}

void PathFix::Stop() {
Expand Down

0 comments on commit ae989b2

Please sign in to comment.