source: Daodan/src/Daodan_WindowHack.c@ 637

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