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