1 | #include <windows.h>
|
---|
2 | #include "Daodan_WindowHack.h"
|
---|
3 | #include "Daodan_Patch.h"
|
---|
4 |
|
---|
5 | #include "Oni.h"
|
---|
6 | #include "Oni_GL.h"
|
---|
7 |
|
---|
8 | volatile HWND onihwnd, boxhwnd = NULL;
|
---|
9 | int inclient = 0;
|
---|
10 | int dragging = 0;
|
---|
11 |
|
---|
12 | LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
---|
13 | {
|
---|
14 | switch (msg)
|
---|
15 | {
|
---|
16 | case WM_KEYDOWN:
|
---|
17 | case WM_ACTIVATE:
|
---|
18 | case WM_CHAR:
|
---|
19 | case WM_KEYUP:
|
---|
20 | ONrPlatform_WindowProc(onihwnd, msg, wParam, lParam);
|
---|
21 | return DefWindowProc(hwnd, msg, wParam, lParam);
|
---|
22 | case WM_SETCURSOR:
|
---|
23 | if (LOWORD(lParam) == HTCLIENT)
|
---|
24 | {
|
---|
25 | if (!inclient)
|
---|
26 | {
|
---|
27 | inclient = 1;
|
---|
28 | ShowCursor(FALSE);
|
---|
29 | }
|
---|
30 | }
|
---|
31 | else if (inclient)
|
---|
32 | {
|
---|
33 | inclient = 0;
|
---|
34 | ShowCursor(TRUE);
|
---|
35 | }
|
---|
36 | break;
|
---|
37 | // case WM_CLOSE:
|
---|
38 | // CHARTest();
|
---|
39 | // break;
|
---|
40 | case WM_DESTROY:
|
---|
41 | PostQuitMessage(0);
|
---|
42 | ExitProcess(0);
|
---|
43 | break;
|
---|
44 | case WM_ENTERSIZEMOVE:
|
---|
45 | dragging = 1;
|
---|
46 | break;
|
---|
47 | case WM_EXITSIZEMOVE:
|
---|
48 | dragging = 0;
|
---|
49 | break;
|
---|
50 | default:
|
---|
51 | return DefWindowProc(hwnd, msg, wParam, lParam);
|
---|
52 | }
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 | DWORD WINAPI DDrHack_WndMain(LPVOID param)
|
---|
57 | {
|
---|
58 | MSG Msg;
|
---|
59 | RECT re;
|
---|
60 | WNDCLASSEX wc;
|
---|
61 |
|
---|
62 | wc.cbSize = sizeof(WNDCLASSEX);
|
---|
63 | wc.style = 0;
|
---|
64 | wc.lpfnWndProc = DDrHack_WndProc;
|
---|
65 | wc.cbClsExtra = 0;
|
---|
66 | wc.cbWndExtra = 0;
|
---|
67 | wc.hInstance = DDrDLLModule;
|
---|
68 | wc.hIcon = LoadIcon(DDrONiModule, MAKEINTRESOURCE(103));
|
---|
69 | wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
---|
70 | wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
|
---|
71 | wc.lpszMenuName = NULL;
|
---|
72 | wc.lpszClassName = "OniGanbatte";
|
---|
73 | wc.hIconSm = NULL;
|
---|
74 | RegisterClassEx(&wc);
|
---|
75 |
|
---|
76 |
|
---|
77 | re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (640 / 2);
|
---|
78 | re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (480 / 2);
|
---|
79 | re.right = re.left + 640;
|
---|
80 | re.bottom = re.top + 480;
|
---|
81 | AdjustWindowRect(&re, WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), FALSE);
|
---|
82 |
|
---|
83 | boxhwnd = CreateWindowEx(0, "OniGanbatte", "Oni", WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), re.left, re.top, re.right - re.left, re.bottom - re.top, NULL, NULL, DDrDLLModule, NULL);
|
---|
84 |
|
---|
85 | while (GetMessage(&Msg, NULL, 0, 0) > 0)
|
---|
86 | {
|
---|
87 | TranslateMessage(&Msg);
|
---|
88 | DispatchMessage(&Msg);
|
---|
89 | }
|
---|
90 | return 0;
|
---|
91 | }
|
---|
92 |
|
---|
93 | HWND 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)
|
---|
94 | {
|
---|
95 | CloseHandle(CreateThread(NULL, 0, DDrHack_WndMain, NULL, 0, NULL));
|
---|
96 |
|
---|
97 | while (!boxhwnd)
|
---|
98 | Sleep(50);
|
---|
99 |
|
---|
100 | onihwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, boxhwnd, hMenu, hInstance, lpParam);
|
---|
101 | SetParent(onihwnd, boxhwnd);
|
---|
102 | return onihwnd;
|
---|
103 | }
|
---|
104 |
|
---|
105 | BOOL WINAPI glpi_SetWindowPosHook(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
|
---|
106 | {
|
---|
107 | RECT re;
|
---|
108 | SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE);
|
---|
109 | SetCursor(LoadCursor(NULL, IDC_ARROW));
|
---|
110 |
|
---|
111 |
|
---|
112 | re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2);
|
---|
113 | re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2);
|
---|
114 | re.right = re.left + cx;
|
---|
115 | re.bottom = re.top + cy;
|
---|
116 | AdjustWindowRect(&re, WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), FALSE);
|
---|
117 |
|
---|
118 | SetWindowPos(boxhwnd, opt_topmost ? HWND_TOPMOST : NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, (opt_topmost ? uFlags & ~SWP_NOZORDER : uFlags | SWP_NOOWNERZORDER));
|
---|
119 | ShowWindow(boxhwnd, SW_SHOW);
|
---|
120 | UpdateWindow(boxhwnd);
|
---|
121 | return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
|
---|
122 | }
|
---|
123 |
|
---|
124 | BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
|
---|
125 | {
|
---|
126 | if (GetAsyncKeyState(VK_F4) || dragging)
|
---|
127 | {
|
---|
128 | lpPoint->x = gl_eng->DisplayMode.Width / 2;
|
---|
129 | lpPoint->y = gl_eng->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 |
|
---|
141 | BOOL 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 |
|
---|
156 | void DDrWindowHack_Install()
|
---|
157 | {
|
---|
158 | DDrPatch_NOOP((char*)0x0050F764, 6);
|
---|
159 | DDrPatch_MakeCall((char*)0x0050F764, (void*)ONrPI_CreateWindowExHook);
|
---|
160 |
|
---|
161 | DDrPatch_NOOP((char*)0x00407E9F, 6);
|
---|
162 | DDrPatch_MakeCall((char*)0x00407E9F, (void*)glpi_SetWindowPosHook);
|
---|
163 |
|
---|
164 | DDrPatch_NOOP((char*)0x004032CC, 6);
|
---|
165 | DDrPatch_MakeCall((char*)0x004032CC, (void*)LIiP_GetCursorPosHook);
|
---|
166 |
|
---|
167 | DDrPatch_NOOP((char*)0x00402CC2, 6);
|
---|
168 | DDrPatch_MakeCall((char*)0x00402CC2, (void*)LIiP_GetCursorPosHook);
|
---|
169 |
|
---|
170 | DDrPatch_NOOP((char*)0x004032B7, 6);
|
---|
171 | DDrPatch_MakeCall((char*)0x004032B7, (void*)LIiP_SetCursorPosHook);
|
---|
172 |
|
---|
173 | DDrPatch_NOOP((char*)0x00403349, 6);
|
---|
174 | DDrPatch_MakeCall((char*)0x00403349, (void*)LIiP_SetCursorPosHook);
|
---|
175 | }
|
---|