Skip to content

Commit

Permalink
update: 修复1.27a下d3d模式fps解锁
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveBeforT committed Nov 15, 2022
1 parent ed479d9 commit 0d774a0
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
22 changes: 18 additions & 4 deletions WarcraftHelper/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Version GetWar3Version() {
}

Helper::Helper() {
this->m_IsWar3 = this->IsWar3();
this->m_IsWar3 = IsWar3();
if (!this->m_IsWar3) {
return;
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions WarcraftHelper/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Helper {
PathFix* m_PathFix;
ShowHPBar* m_ShowHPBar;

bool IsWar3();
};

bool InitConsole();
bool InitConsole();
bool IsWar3();
2 changes: 1 addition & 1 deletion WarcraftHelper/pathfix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion WarcraftHelper/showfps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 50 additions & 1 deletion WarcraftHelper/unlockfps.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "unlockfps.h"
#include <iostream>
#include <d3d9types.h>
#include <d3d9caps.h>
#include <d3d9.h>

bool UnlockFPS_Hooked = false;

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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);
}
19 changes: 13 additions & 6 deletions WarcraftHelper/windowfixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; // 目标窗口句柄
Expand All @@ -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);
Expand Down

0 comments on commit 0d774a0

Please sign in to comment.