当前位置:   article > 正文

96.网游逆向分析与插件开发-游戏窗口化助手-窗口化助手与游戏窗口同步移动

96.网游逆向分析与插件开发-游戏窗口化助手-窗口化助手与游戏窗口同步移动

内容参考于:易道云信息技术研究院VIP课

上一个内容:窗口化助手显示与大小调整

码云地址(游戏窗口化助手 分支):https://gitee.com/dye_your_fingers/sro_-ex.git

码云版本号:e85c0fc8b85895c8c2d3417ec3c75bcad8e7c41d

代码下载地址,在 SRO_EX 目录下,文件名为:SRO_Ex-窗口化助手与游戏窗口同步移动.zip

链接:https://pan.baidu.com/s/1W-JpUcGOWbSJmMdmtMzYZg

提取码:q9n5

--来自百度网盘超级会员V4的分享

HOOK引擎,文件名为:黑兔sdk.zip

链接:https://pan.baidu.com/s/1IB-Zs6hi3yU8LC2f-8hIEw

提取码:78h8

--来自百度网盘超级会员V4的分享

以 窗口化助手显示与大小调整 它的代码为基础进行修改

效果窗口化助手可以跟游戏窗口的移动而移动,实现这个东西在没有游戏源代码的情况下,实现起来比较好的方式是做个钩子,在钩子里面去做这个事情

CHelper.h文件的修改:新加 HideGame函数、hookGameWnd变量

  1. #pragma once
  2. #include "afxdialogex.h"
  3. #include "resource.h"
  4. // CHelperUI 对话框
  5. class CHelperUI : public CDialogEx
  6. {
  7. DECLARE_DYNAMIC(CHelperUI)
  8. public:
  9. CHelperUI(CWnd* pParent = nullptr); // 标准构造函数
  10. virtual ~CHelperUI();
  11. // 对话框数据
  12. #ifdef AFX_DESIGN_TIME
  13. enum { IDD = IDD_HELPER };
  14. #endif
  15. protected:
  16. virtual BOOL OnInitDialog();
  17. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  18. DECLARE_MESSAGE_MAP()
  19. public:
  20. afx_msg void OnBnClickedOk();
  21. // 血量条
  22. CProgressCtrl HPBar;
  23. // 魔法条
  24. CProgressCtrl MPBar;
  25. // 怒气条
  26. CProgressCtrl RageBar;
  27. // 升级经验值条
  28. CProgressCtrl ExBar;
  29. HHOOK hookGameWnd;
  30. bool GameShow = true;
  31. // 游戏句柄
  32. HWND hwndGame{};
  33. int helper_Width;
  34. void Init();
  35. void MoveHelper();
  36. void ShowData();
  37. void Show();
  38. afx_msg void OnBnClickedOk2();
  39. afx_msg void OnClose();
  40. void HideGame();
  41. };

CHelper.cpp文件的修改:新加 HideGame函数、CallWndProc函数,修改了 Init函数

  1. // CHelperUI.cpp: 实现文件
  2. //
  3. #include "pch.h"
  4. #include "CHelperUI.h"
  5. #include "afxdialogex.h"
  6. #include "extern_all.h"
  7. LRESULT _stdcall CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
  8. if (nCode == 0) {
  9. // 这里接收到的不只有游戏窗口的消息,还有我们的窗口消息
  10. // 所以要排除掉我们的窗口
  11. PCWPSTRUCT tmp = (PCWPSTRUCT)lParam;
  12. // 判断当前触发消息的窗口句柄是不是我们的游戏窗口句柄
  13. if (tmp->hwnd == _ui_helper->hwndGame) {
  14. // 拦截移动窗口消息
  15. if (tmp->message == WM_MOVE) {
  16. // 移动我们的窗口
  17. _ui_helper->MoveHelper();
  18. }
  19. if (tmp->message == WM_CLOSE) {
  20. // 游戏窗口右上角的X关闭按钮屏蔽掉了,这里我们给它处理一下
  21. // 让它点击之后可以隐藏游戏窗口并且显示我们的窗口
  22. /**
  23. _ui_helper->HideGame(); 里执行的代码如下面的两行
  24. this->ShowWindow(TRUE);
  25. ::ShowWindow(hwndGame, GameShow = false);
  26. */
  27. _ui_helper->HideGame();
  28. }
  29. }
  30. }
  31. return CallNextHookEx(_ui_helper->hookGameWnd, nCode, wParam, lParam);
  32. }
  33. void _stdcall TimeProcHelper(HWND, UINT, UINT_PTR, DWORD) {
  34. if (_ui_helper)_ui_helper->ShowData();
  35. }
  36. //获取程序当前所在显示器的分辨率大小,可以动态的获取程序所在显示器的分辨率
  37. SIZE GetScreenResolution(HWND hWnd) {
  38. SIZE size{};
  39. if (!hWnd)
  40. return size;
  41. //MONITOR_DEFAULTTONEAREST 返回值是最接近该点的屏幕句柄
  42. //MONITOR_DEFAULTTOPRIMARY 返回值是主屏幕的句柄
  43. //如果其中一个屏幕包含该点,则返回值是该屏幕的HMONITOR句柄。如果没有一个屏幕包含该点,则返回值取决于dwFlags的值
  44. HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
  45. MONITORINFOEX miex;
  46. miex.cbSize = sizeof(miex);
  47. if (!GetMonitorInfo(hMonitor, &miex))
  48. return size;
  49. DEVMODE dm;
  50. dm.dmSize = sizeof(dm);
  51. dm.dmDriverExtra = 0;
  52. //ENUM_CURRENT_SETTINGS 检索显示设备的当前设置
  53. //ENUM_REGISTRY_SETTINGS 检索当前存储在注册表中的显示设备的设置
  54. if (!EnumDisplaySettings(miex.szDevice, ENUM_CURRENT_SETTINGS, &dm))
  55. return size;
  56. size.cx = dm.dmPelsWidth;
  57. size.cy = dm.dmPelsHeight;
  58. return size;
  59. }
  60. IMPLEMENT_DYNAMIC(CHelperUI, CDialogEx)
  61. CHelperUI::CHelperUI(CWnd* pParent /*=nullptr*/)
  62. : CDialogEx(IDD_HELPER, pParent)
  63. {
  64. }
  65. CHelperUI::~CHelperUI()
  66. {
  67. }
  68. BOOL CHelperUI::OnInitDialog()
  69. {
  70. CDialogEx::OnInitDialog();
  71. this->SetBackgroundColor(RGB(255, 255, 255));
  72. HPBar.SetBkColor(RGB(0 ,0, 0));
  73. MPBar.SetBkColor(RGB(0 ,0, 0));
  74. RageBar.SetBkColor(RGB(0 ,0, 0));
  75. ExBar.SetBkColor(RGB(0 ,0, 0));
  76. HPBar.SetBarColor(RGB(255 ,0, 0));
  77. MPBar.SetBarColor(RGB(0x0, 0x0, 0x99));
  78. RageBar.SetBarColor(RGB(0x66, 0x0, 0x66));
  79. ExBar.SetBarColor(RGB(0x00, 0xFF, 0xCC));
  80. HPBar.SetRange(0, 999);
  81. MPBar.SetRange(0, 1000);
  82. RageBar.SetRange(0, 5);
  83. ExBar.SetRange(0, 1000);
  84. //HPBar.SetPos(50);
  85. //MPBar.SetPos(50);
  86. //RageBar.SetPos(50);
  87. //ExBar.SetPos(50);
  88. ::SetTimer(this->m_hWnd, 0x100002, 100, TimeProcHelper);
  89. return TRUE;
  90. }
  91. void CHelperUI::DoDataExchange(CDataExchange* pDX)
  92. {
  93. CDialogEx::DoDataExchange(pDX);
  94. DDX_Control(pDX, IDC_PRO_HP, HPBar);
  95. DDX_Control(pDX, IDC_PRO_MP, MPBar);
  96. DDX_Control(pDX, IDC_PRO_RAGE, RageBar);
  97. DDX_Control(pDX, IDC_PRO_RAGE2, ExBar);
  98. }
  99. BEGIN_MESSAGE_MAP(CHelperUI, CDialogEx)
  100. ON_BN_CLICKED(IDOK, &CHelperUI::OnBnClickedOk)
  101. ON_BN_CLICKED(IDOK2, &CHelperUI::OnBnClickedOk2)
  102. ON_WM_CLOSE()
  103. END_MESSAGE_MAP()
  104. // CHelperUI 消息处理程序
  105. void CHelperUI::OnBnClickedOk()
  106. {
  107. // TODO: 在此添加控件通知处理程序代码
  108. // CDialogEx::OnOK();
  109. //CString tmp;
  110. //tmp.Format(L"%d", _pgamebase->SRO_Player->MapId);
  111. //AfxMessageBox(tmp);
  112. //
  113. //CString city;
  114. //city.Format(L"%s", _pgamebase->SRO_Res->ReadTitle(tmp.GetBuffer())->wcstr());
  115. //AfxMessageBox(city);
  116. _ui->UIShow();
  117. }
  118. void CHelperUI::Init()
  119. {
  120. if (hwndGame) return;
  121. wchar_t buff[0xFF]{};
  122. // 获取主窗口句柄
  123. HWND _hwnd = ::GetActiveWindow();
  124. // 获取窗口标题
  125. ::GetWindowText(_hwnd, buff, 0xFF);
  126. CString _title = buff;
  127. if (_title == L"SRO_CLIENT") {
  128. hwndGame = _hwnd;
  129. CRect rect_me;
  130. // 获取当前窗口句柄
  131. GetWindowRect(&rect_me);
  132. helper_Width = rect_me.Width();
  133. SetWindowsHook(WH_CALLWNDPROC, CallWndProc);
  134. }
  135. }
  136. void CHelperUI::MoveHelper()
  137. {
  138. if (hwndGame) {
  139. CRect rect;
  140. // 获取游戏窗口(主窗口)样式
  141. ::GetWindowRect(hwndGame, &rect);
  142. int helper_left = rect.left + rect.Width();
  143. SIZE windowSize = GetScreenResolution(this->m_hWnd);
  144. if ((helper_left + helper_Width) > windowSize.cx) {
  145. helper_left -= helper_Width;
  146. }
  147. // 设置窗口大小
  148. ::MoveWindow(this->m_hWnd, helper_left, rect.top, helper_Width, rect.Height(), TRUE);
  149. }
  150. }
  151. void CHelperUI::ShowData()
  152. {
  153. CString tmp;
  154. CString city;
  155. auto _player = _pgamebase->SRO_Player;
  156. if (_player) {
  157. tmp.Format(L"%s Lv %d", _player->Name.wcstrByName(), _player->Lv);
  158. this->SetWindowText(tmp);
  159. float hpStep = _player->HP * 1000;
  160. hpStep = hpStep / _player->MaxHP;
  161. HPBar.SetPos(hpStep);
  162. float mpStep = _player->MP * 1000;
  163. mpStep = mpStep / _player->MaxMP;
  164. MPBar.SetPos(mpStep);
  165. RageBar.SetPos(_player->Rage);
  166. unsigned max_exp = _pgamebase->SRO_Core->GetLvMaxExp(_player->Lv)->Exp;
  167. float expSetp = _player->Exp * 1000;
  168. expSetp = expSetp / max_exp;
  169. ExBar.SetPos(expSetp);
  170. tmp.Format(L"%.1f %.1f %.1f", _player->x, _player->h, _player->y);
  171. GetDlgItem(IDC_STATIC_CORD)->SetWindowText(tmp);
  172. tmp.Format(L"%d", _pgamebase->SRO_Player->MapId);
  173. city.Format(L"%s", _pgamebase->SRO_Res->ReadTitle(tmp.GetBuffer())->wcstr());
  174. GetDlgItem(IDC_STATIC_MAP)->SetWindowText(city);
  175. }
  176. }
  177. void CHelperUI::Show()
  178. {
  179. MoveHelper();
  180. this->ShowWindow(TRUE);
  181. }
  182. void CHelperUI::OnBnClickedOk2()
  183. {
  184. if (hwndGame) {
  185. ::ShowWindow(hwndGame, GameShow = !GameShow);
  186. }
  187. }
  188. void CHelperUI::OnClose()
  189. {
  190. if (hwndGame) {
  191. ::ShowWindow(hwndGame, GameShow = true);
  192. this->ShowWindow(FALSE);
  193. }
  194. }
  195. void CHelperUI::HideGame()
  196. {
  197. this->ShowWindow(TRUE);
  198. ::ShowWindow(hwndGame, GameShow = false);
  199. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/107171
推荐阅读
相关标签
  

闽ICP备14008679号