Skip to content

Commit 53ca936

Browse files
committed
fix(patch):
fix a possible cause the make the patch not applied. when the dll createthread is slower than target, the patch may not be applied
1 parent f98e9ef commit 53ca936

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/dllmain.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ void Logging()
6767
DWORD __stdcall Main(void*) {
6868
Logging();
6969
std::filesystem::path startup_check = L"success.txt";
70+
// MessageBoxW(NULL, L"警告:这是测试版补丁,设定为必定会炸,用于检测补丁是否正确应用。", L"L4D2 Fix", MB_OK);
71+
7072
if (!std::filesystem::exists(startup_check)) {
7173
MessageBoxW(NULL, L"这是一个启动测试,用于检验补丁是否正常运行。\n请注意由于修改内存,请不要进 VAC 服,后果未知。\n本弹窗仅首次启动出现,后续运行情况参见 L4D2Fix.log 日志文件。\n\n关注B站 5050 直播间,谢谢喵 by KurikoMoe!", L"L4D2 Fix", MB_OK);
7274
}
@@ -80,8 +82,11 @@ DWORD __stdcall Main(void*) {
8082
auto f = [&](const char* tag, const char* pattern, size_t offset, size_t w_offset) {
8183
std::uint8_t* ptr = Memory::PatternScan(hDll, pattern);
8284

85+
constexpr uint32_t new_buffer_size = 0x020000;
86+
// constexpr uint32_t new_buffer_size = 32;
87+
8388
if (ptr != nullptr) {
84-
Memory::Write((uintptr_t)(ptr + w_offset), (uint32_t)0x020000);
89+
Memory::Write((uintptr_t)(ptr + w_offset), new_buffer_size);
8590
spdlog::info("Modified the vertex max buffer shaderapidx9.dll: {}", tag);
8691
return ptr;
8792
}
@@ -102,7 +107,12 @@ DWORD __stdcall Main(void*) {
102107
// Not known
103108
auto ptr3 = f("Unknown", "0F B6 C0 50 68 00 80 00 00 53 8B CF E8 ?? ?? ?? ??", (size_t)ptr1, 5);
104109

105-
if (ptr1 == nullptr || ptr2 == nullptr || ptr3 == nullptr) {
110+
if (ptr1 == nullptr
111+
|| ptr1_1 == nullptr
112+
|| ptr2 == nullptr
113+
|| ptr2_1 == nullptr
114+
|| ptr3 == nullptr
115+
) {
106116
MessageBoxW(NULL, L"未能正常应用补丁,patch 未生效,请联系开发者", L"L4D2 Fix", MB_OK);
107117
} else {
108118
std::fstream file(startup_check, std::ios::out);
@@ -117,12 +127,13 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv
117127

118128
switch (ul_reason_for_call) {
119129
case DLL_PROCESS_ATTACH:
120-
HANDLE mainHandle = CreateThread(NULL, 0, Main, 0, CREATE_SUSPENDED, 0);
121-
if (mainHandle) {
122-
SetThreadPriority(mainHandle, THREAD_PRIORITY_TIME_CRITICAL);
123-
ResumeThread(mainHandle);
124-
CloseHandle(mainHandle);
125-
}
130+
Main(nullptr);
131+
// HANDLE mainHandle = CreateThread(NULL, 0, Main, 0, CREATE_SUSPENDED, 0);
132+
// if (mainHandle) {
133+
// SetThreadPriority(mainHandle, THREAD_PRIORITY_TIME_CRITICAL);
134+
// ResumeThread(mainHandle);
135+
// CloseHandle(mainHandle);
136+
// }
126137
break;
127138
}
128139
return TRUE;

third/source-engine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 29985681a18508e78dc79ad863952f830be237b6

0 commit comments

Comments
 (0)