From 0d774a02519ff8b32e6b684d0ebba3e6ce7d9710 Mon Sep 17 00:00:00 2001 From: KouKouChan <1010433454@qq.com> Date: Tue, 15 Nov 2022 19:49:29 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E4=BF=AE=E5=A4=8D1.27a=E4=B8=8Bd3d?= =?UTF-8?q?=E6=A8=A1=E5=BC=8Ffps=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarcraftHelper/helper.cpp | 22 ++++++++++++--- WarcraftHelper/helper.h | 4 +-- WarcraftHelper/pathfix.cpp | 2 +- WarcraftHelper/showfps.cpp | 2 +- WarcraftHelper/unlockfps.cpp | 51 +++++++++++++++++++++++++++++++++- WarcraftHelper/windowfixer.cpp | 19 +++++++++---- 6 files changed, 85 insertions(+), 15 deletions(-) diff --git a/WarcraftHelper/helper.cpp b/WarcraftHelper/helper.cpp index 284f758..951016f 100644 --- a/WarcraftHelper/helper.cpp +++ b/WarcraftHelper/helper.cpp @@ -18,7 +18,7 @@ Version GetWar3Version() { } Helper::Helper() { - this->m_IsWar3 = this->IsWar3(); + this->m_IsWar3 = IsWar3(); if (!this->m_IsWar3) { return; } @@ -47,15 +47,29 @@ void Helper::Start() { #ifdef DEBUG InitConsole(); #endif + /* + DWORD esiBak = 0; + DWORD ediBak = 0; + DWORD ebxBak = 0; + _asm { + mov esiBak, esi + mov ediBak, edi + mov ebxBak, ebx + }*/ + this->m_UnlockFPS->Start(this->m_GamedllBase, this->m_War3Version); + /*_asm { + mov esi, esiBak + mov edi, ediBak + mov ebx, ebxBak + }*/ this->m_SizeBypass->Start(this->m_GamedllBase, this->m_War3Version); this->m_WideScreen->Start(this->m_GamedllBase, this->m_War3Version); - this->m_UnlockFPS->Start(this->m_GamedllBase, this->m_War3Version); - this->m_WindowFixer->Start(); this->m_AutoRep->Start(this->m_GamedllBase, this->m_War3Version); this->m_ShowFPS->Start(this->m_GamedllBase, this->m_War3Version); this->m_PathFix->Start(this->m_GamedllBase, this->m_War3Version); this->m_ShowHPBar->Start(this->m_GamedllBase, this->m_War3Version); + this->m_WindowFixer->Start(); } void Helper::Stop() { @@ -74,7 +88,7 @@ void Helper::Stop() { Sleep(60); } -bool Helper::IsWar3() { +bool IsWar3() { TCHAR lpFilePATH[MAX_PATH]; memset(lpFilePATH, 0, MAX_PATH * sizeof(TCHAR)); ::GetModuleFileName(NULL, lpFilePATH, MAX_PATH); diff --git a/WarcraftHelper/helper.h b/WarcraftHelper/helper.h index aef349c..19236a6 100644 --- a/WarcraftHelper/helper.h +++ b/WarcraftHelper/helper.h @@ -31,7 +31,7 @@ class Helper { PathFix* m_PathFix; ShowHPBar* m_ShowHPBar; - bool IsWar3(); }; -bool InitConsole(); \ No newline at end of file +bool InitConsole(); +bool IsWar3(); \ No newline at end of file diff --git a/WarcraftHelper/pathfix.cpp b/WarcraftHelper/pathfix.cpp index 37cd5e1..9901a04 100644 --- a/WarcraftHelper/pathfix.cpp +++ b/WarcraftHelper/pathfix.cpp @@ -42,7 +42,7 @@ void PathFix::Start(DWORD m_GamedllBase, Version m_War3Version) { } PathFix_Hooked = true; if (!m_GamedllBase) { - MessageBoxA(0, "GameDll初始化失败", "AutoRep", 0); + MessageBoxA(0, "GameDll初始化失败", "PathFix", 0); return; } switch (m_War3Version) { diff --git a/WarcraftHelper/showfps.cpp b/WarcraftHelper/showfps.cpp index bfbc99c..a0df1be 100644 --- a/WarcraftHelper/showfps.cpp +++ b/WarcraftHelper/showfps.cpp @@ -11,7 +11,7 @@ void ShowFPS::Start(DWORD m_GamedllBase, Version m_War3Version) { } ShowFPS_Patched = true; if (!m_GamedllBase) { - MessageBoxA(0, "GameDll初始化失败", "CrashFixer", 0); + MessageBoxA(0, "GameDll初始化失败", "ShowFPS", 0); return; } DWORD offset = m_GamedllBase; diff --git a/WarcraftHelper/unlockfps.cpp b/WarcraftHelper/unlockfps.cpp index 20eb2a2..b58dfae 100644 --- a/WarcraftHelper/unlockfps.cpp +++ b/WarcraftHelper/unlockfps.cpp @@ -1,5 +1,8 @@ #include "unlockfps.h" #include +#include +#include +#include bool UnlockFPS_Hooked = false; @@ -9,12 +12,29 @@ DWORD(__fastcall* SetGameOptValue)(DWORD pthis, DWORD unused, DWORD idx, DWORD v UnlockFPS::UnlockFPS() {} UnlockFPS::~UnlockFPS() {} +DWORD(__fastcall* org_GetD3d9Parameters)(DWORD pthis, DWORD unused, D3DPRESENT_PARAMETERS* pPresentationParameters) = 0; +DWORD __fastcall GetD3d9Parameters(DWORD pthis, DWORD unused, D3DPRESENT_PARAMETERS* pPresentationParameters) { + DWORD result = org_GetD3d9Parameters(pthis, unused, pPresentationParameters); + if (pPresentationParameters) { + pPresentationParameters->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + } + + //IDirect3DDevice9* pReturnedDeviceInterface = *(IDirect3DDevice9**)(pthis + 1412); + //if (pReturnedDeviceInterface) { + // // reset d3d9 + // pReturnedDeviceInterface->Reset(pPresentationParameters); + //} + return result; +} + void UnlockFPS::Start(DWORD m_GamedllBase, Version m_War3Version) { if (UnlockFPS_Hooked) { return; } UnlockFPS_Hooked = true; DWORD addr = m_GamedllBase; + DWORD d3d9_addr = 0; + DWORD *is_enable_d3d_addr = 0; DWORD war3_addr = 0; byte SetFPS_pattern[] = { 0X83, 0XE0, 0XFB, 0X53, @@ -31,16 +51,20 @@ void UnlockFPS::Start(DWORD m_GamedllBase, Version m_War3Version) { addr += 2; GetGameOpt = (DWORD(*)())(m_GamedllBase + 0x2A50); SetGameOptValue = (DWORD(__fastcall*)(DWORD, DWORD, DWORD, DWORD))(m_GamedllBase + 0x2CC0); + is_enable_d3d_addr = (DWORD*)(m_GamedllBase + 0x7FA744); break; case Version::v124e: GetGameOpt = (DWORD(*)())(m_GamedllBase + 0x5720); SetGameOptValue = (DWORD(__fastcall*)(DWORD, DWORD, DWORD, DWORD))(m_GamedllBase + 0x57F0); addr += 0x62DF9B; + is_enable_d3d_addr = (DWORD*)(m_GamedllBase + 0xA9E764); break; case Version::v127a: GetGameOpt = (DWORD(*)())(m_GamedllBase + 0x23E00); SetGameOptValue = (DWORD(__fastcall*)(DWORD, DWORD, DWORD, DWORD))(m_GamedllBase + 0x25A70); addr += 0x5FCFB; + d3d9_addr = m_GamedllBase + 0xEC6B0; + is_enable_d3d_addr = (DWORD*)(m_GamedllBase + 0xB665C8); break; default: return; @@ -59,8 +83,33 @@ void UnlockFPS::Start(DWORD m_GamedllBase, Version m_War3Version) { unsigned char bytes[] = { 0xFF }; PatchMemory(addr, bytes, 1); + InlineHook((void*)d3d9_addr, GetD3d9Parameters, (void*&)org_GetD3d9Parameters); + + //// opengl 解锁垂直同步 + //if (is_enable_d3d_addr && !*is_enable_d3d_addr) { + // HMODULE hOpengl = GetModuleHandle("opengl32.dll"); + // if (!hOpengl) { + // return; + // } + // DWORD(*wglGetProcAddress)(const char*) = (DWORD(*)(const char*))GetProcAddress(hOpengl, "wglGetProcAddress"); + // if (!wglGetProcAddress) { + // return; + // } + // DWORD(*wglSwapIntervalEXT)(DWORD) = (DWORD(*)(DWORD))wglGetProcAddress("wglSwapIntervalEXT"); + // if (!wglSwapIntervalEXT) { + // return; + // } + // wglSwapIntervalEXT(1); + //} + + // d3d重设窗口 + if (d3d9_addr && is_enable_d3d_addr && *is_enable_d3d_addr) { + HWND target = GetActiveWindow(); + ShowWindow(target, SW_MINIMIZE); + ShowWindow(target, SW_SHOWNORMAL); + } } void UnlockFPS::Stop() { - + DetachHook((void*)org_GetD3d9Parameters, GetD3d9Parameters); } diff --git a/WarcraftHelper/windowfixer.cpp b/WarcraftHelper/windowfixer.cpp index 39c3ef2..2f16e50 100644 --- a/WarcraftHelper/windowfixer.cpp +++ b/WarcraftHelper/windowfixer.cpp @@ -5,6 +5,18 @@ extern HWND g_hWnd; #define IsKeyDown(VK_NAME) ((GetAsyncKeyState(VK_NAME) & 0x8000) ? true:false) +void ResetWindow(HWND target) { + if (!target) { + return; + } + RECT rect; + GetWindowRect(target, &rect); + // 閲嶆柊璁剧疆绐楀彛澶у皬 + MoveWindow(target, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top, false); + // 鎭㈠绐楀彛澶у皬 + MoveWindow(target, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, false); +} + DWORD __stdcall Listen(LPVOID lpThreadParameter) { POINT point; // 榧犳爣鎵鍦ㄤ綅缃 HWND target; // 鐩爣绐楀彛鍙ユ焺 @@ -18,12 +30,7 @@ DWORD __stdcall Listen(LPVOID lpThreadParameter) { GetCursorPos(&point); target = WindowFromPoint(point); if (target != NULL && target == g_hWnd) { - RECT rect; - GetWindowRect(target, &rect); - // 閲嶆柊璁剧疆绐楀彛澶у皬 - MoveWindow(target, rect.left, rect.top, rect.right - rect.left + 1, rect.bottom - rect.top, false); - // 鎭㈠绐楀彛澶у皬 - MoveWindow(target, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, false); + ResetWindow(target); } } Sleep(50);