source: Daodan/src/Daodan_WindowHack.c@ 381

Last change on this file since 381 was 354, checked in by rossy, 15 years ago
File size: 4.6 KB
Line 
1#include <windows.h>
2#include "Daodan_WindowHack.h"
3#include "Daodan_Patch.h"
4
5#include "Oni.h"
6#include "BFW_Motoko_Draw.h"
7#include "oni_gl.h"
8
9volatile HWND onihwnd, boxhwnd = NULL;
10int inclient = 0;
11int dragging = 0;
12
13LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
14{
15 switch (msg)
16 {
17 case WM_ACTIVATE:
18 case WM_CHAR:
19 case WM_KEYUP:
20 case WM_KEYDOWN:
21 ONrPlatform_WindowProc(onihwnd, msg, wParam, lParam);
22 return DefWindowProc(hwnd, msg, wParam, lParam);
23 case WM_SETCURSOR:
24 if (LOWORD(lParam) == HTCLIENT)
25 {
26 if (!inclient)
27 {
28 inclient = 1;
29 ShowCursor(FALSE);
30 }
31 }
32 else if (inclient)
33 {
34 inclient = 0;
35 ShowCursor(TRUE);
36 }
37 break;
38 case WM_CLOSE:
39 DestroyWindow(hwnd);
40 break;
41 case WM_DESTROY:
42 PostQuitMessage(0);
43 ExitProcess(0);
44 break;
45 case WM_ENTERSIZEMOVE:
46 dragging = 1;
47 break;
48 case WM_EXITSIZEMOVE:
49 dragging = 0;
50 break;
51 default:
52 return DefWindowProc(hwnd, msg, wParam, lParam);
53 }
54 return 0;
55}
56
57DWORD WINAPI DDrHack_WndMain(LPVOID param)
58{
59 MSG Msg;
60
61 WNDCLASSEX wc;
62
63 wc.cbSize = sizeof(WNDCLASSEX);
64 wc.style = 0;
65 wc.lpfnWndProc = DDrHack_WndProc;
66 wc.cbClsExtra = 0;
67 wc.cbWndExtra = 0;
68 wc.hInstance = DDrDLLModule;
69 wc.hIcon = LoadIcon(DDrONiModule, MAKEINTRESOURCE(103));
70 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
71 wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
72 wc.lpszMenuName = NULL;
73 wc.lpszClassName = "OniGanbatte";
74 wc.hIconSm = NULL;
75 RegisterClassEx(&wc);
76
77 RECT re;
78 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (640 / 2);
79 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (480 / 2);
80 re.right = re.left + 640;
81 re.bottom = re.top + 480;
82 AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
83
84 boxhwnd = CreateWindowEx(0, "OniGanbatte", "Oni", WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, re.left, re.top, re.right - re.left, re.bottom - re.top, NULL, NULL, DDrDLLModule, NULL);
85 ShowWindow(boxhwnd, SW_SHOW);
86 UpdateWindow(boxhwnd);
87
88 while (GetMessage(&Msg, NULL, 0, 0) > 0)
89 {
90 TranslateMessage(&Msg);
91 DispatchMessage(&Msg);
92 }
93 return 0;
94}
95
96HWND WINAPI ONrPI_CreateWindowExHook(DWORD dwExStyle, const char* lpClassName, const char* lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
97{
98 CloseHandle(CreateThread(NULL, 0, DDrHack_WndMain, NULL, 0, NULL));
99
100 while (!boxhwnd)
101 Sleep(50);
102
103 onihwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, boxhwnd, hMenu, hInstance, lpParam);
104 SetParent(onihwnd, boxhwnd);
105 return onihwnd;
106}
107
108BOOL WINAPI glpi_SetWindowPosHook(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
109{
110 SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE);
111 SetCursor(LoadCursor(NULL, IDC_ARROW));
112
113 RECT re;
114 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2);
115 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2);
116 re.right = re.left + cx;
117 re.bottom = re.top + cy;
118 AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
119
120 SetWindowPos(boxhwnd, NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, uFlags | SWP_NOOWNERZORDER);
121 return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
122}
123
124BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
125{
126 if (GetAsyncKeyState(VK_F4) || dragging)
127 {
128 lpPoint->x = gl->DisplayMode.Width / 2;
129 lpPoint->y = gl->DisplayMode.Height / 2;
130 }
131 else
132 {
133 if (!GetCursorPos(lpPoint))
134 return 0;
135 if (onihwnd != NULL)
136 ScreenToClient(onihwnd, lpPoint);
137 }
138 return 1;
139}
140
141BOOL WINAPI LIiP_SetCursorPosHook(int X, int Y)
142{
143 if (GetAsyncKeyState(VK_F4) || dragging)
144 return TRUE;
145 else
146 {
147 POINT pt;
148 pt.x = X;
149 pt.y = Y;
150 if (onihwnd != NULL)
151 ClientToScreen(onihwnd, &pt);
152 return SetCursorPos(pt.x, pt.y);
153 }
154}
155
156void DDrWindowHack_Install()
157{
158 DDrPatch_NOOP((char*)0x0050F764, 6);
159 DDrPatch_MakeCall((char*)0x0050F764, ONrPI_CreateWindowExHook);
160
161 DDrPatch_NOOP((char*)0x00407E9F, 6);
162 DDrPatch_MakeCall((char*)0x00407E9F, glpi_SetWindowPosHook);
163
164 DDrPatch_NOOP((char*)0x004032CC, 6);
165 DDrPatch_MakeCall((char*)0x004032CC, LIiP_GetCursorPosHook);
166
167 DDrPatch_NOOP((char*)0x00402CC2, 6);
168 DDrPatch_MakeCall((char*)0x00402CC2, LIiP_GetCursorPosHook);
169
170 DDrPatch_NOOP((char*)0x004032B7, 6);
171 DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook);
172
173 DDrPatch_NOOP((char*)0x00403349, 6);
174 DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook);
175}
Note: See TracBrowser for help on using the repository browser.