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