-
Notifications
You must be signed in to change notification settings - Fork 0
/
Global10.cpp
126 lines (98 loc) · 3.05 KB
/
Global10.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "edao.h"
#define ENABLE_LOG 0
#if !D3D9_VER
#undef ENABLE_LOG
#define ENABLE_LOG 0
#endif
void WriteLog(PCWSTR Format, ...)
{
#if ENABLE_LOG
NtFileDisk log;
WCHAR Buffer[0xFF0];
log.CreateIfNotExist(L"log.txt");
if (log.GetSize32() == 0)
{
ULONG BOM = BOM_UTF16_LE;
log.Write(&BOM, 2);
}
log.Seek(0, FILE_END);
log.Write(Buffer, vswprintf(Buffer, Format, (va_list)(&Format + 1)) * 2);
log.Write(L"\r\n", 4);
#endif
}
#if !ENABLE_LOG
#define WriteLog(...)
#endif
PWSTR
GetFileName(
PWSTR HookedPath,
ULONG HookedPathCount,
PWSTR OriginalPath,
ULONG OriginalCount,
LPCSTR InputFileName,
BOOL IsInputUnicode = FALSE
)
{
ULONG_PTR Length, AppPathLength;
PWSTR FileName;
static WCHAR szDataPath[] = L"data\\";
static WCHAR szPatch[] = L"patch\\\\";
static WCHAR szPatch2[] = L"patch2\\";
if (IsInputUnicode)
{
StrCopyW(OriginalPath, (PWSTR)InputFileName);
}
else
{
AnsiToUnicode(OriginalPath, OriginalCount, (PSTR)InputFileName, -1);
}
PLDR_MODULE Module;
Module = FindLdrModuleByHandle(NULL);
AppPathLength = (Module->FullDllName.Length - Module->BaseDllName.Length) / sizeof(WCHAR);
Length = RtlGetFullPathName_U(OriginalPath, HookedPathCount * sizeof(WCHAR), HookedPath, NULL);
Length = Length / sizeof(WCHAR) + 1;
FileName = HookedPath + AppPathLength;
LOOP_ONCE
{
if (StrNICompareW(FileName, szDataPath, countof(szDataPath) - 1) ||
StrNICompareW(Module->FullDllName.Buffer, HookedPath, AppPathLength))
{
FileName = OriginalPath;
break;
}
FileName += countof(szDataPath) - 2;
RtlMoveMemory(
FileName + countof(szPatch) - countof(szDataPath),
FileName,
(Length - (FileName - HookedPath)) * sizeof(*FileName)
);
FileName -= countof(szDataPath) - 2;
CopyStruct(FileName, szPatch, sizeof(szPatch) - sizeof(*szPatch));
WriteLog(L"pass1: %s", HookedPath);
if (IsPathExists(HookedPath))
{
FileName = HookedPath;
break;
}
CopyStruct(FileName, szPatch2, sizeof(szPatch2) - sizeof(*szPatch2));
FileName = IsPathExists(HookedPath) ? HookedPath : OriginalPath;
WriteLog(L"pass2: %s", HookedPath);
}
WriteLog(L"%d, %s -> %s", FileName == HookedPath, OriginalPath, HookedPath);
return FileName;
}
BOOL AoIsFileExist(PCSTR FileName)
{
WCHAR OriginalPath[MAX_NTPATH], HookedPath[MAX_NTPATH];
if (GetFileName(HookedPath, countof(HookedPath), OriginalPath, countof(OriginalPath), FileName) == HookedPath)
return TRUE;
return IsPathExists(OriginalPath);
}
EDAO* GlobalGetEDAO()
{
#if CHT_VER
return *(EDAO **)0xC27988;
#else
return *(EDAO **)0xC29988;
#endif
}