source: Daodan/src/Daodan_WindowHack.c@ 429

Last change on this file since 429 was 428, checked in by rossy, 15 years ago

getting closer...

File size: 4.7 KB
RevLine 
[351]1#include <windows.h>
[349]2#include "Daodan_WindowHack.h"
[351]3#include "Daodan_Patch.h"
[428]4#include "Daodan_Character.h"
[349]5
[351]6#include "Oni.h"
7#include "BFW_Motoko_Draw.h"
8#include "oni_gl.h"
9
10volatile HWND onihwnd, boxhwnd = NULL;
11int inclient = 0;
[354]12int dragging = 0;
[351]13
14LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
15{
16 switch (msg)
17 {
18 case WM_ACTIVATE:
19 case WM_CHAR:
20 case WM_KEYUP:
21 case WM_KEYDOWN:
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 DestroyWindow(hwnd);
41 break;
42 case WM_DESTROY:
43 PostQuitMessage(0);
44 ExitProcess(0);
45 break;
[354]46 case WM_ENTERSIZEMOVE:
47 dragging = 1;
48 break;
49 case WM_EXITSIZEMOVE:
50 dragging = 0;
51 break;
[351]52 default:
53 return DefWindowProc(hwnd, msg, wParam, lParam);
54 }
55 return 0;
56}
57
58DWORD WINAPI DDrHack_WndMain(LPVOID param)
59{
60 MSG Msg;
61
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 RECT re;
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 | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
84
85 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);
86 ShowWindow(boxhwnd, SW_SHOW);
87 UpdateWindow(boxhwnd);
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 | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
120
121 SetWindowPos(boxhwnd, NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, uFlags | SWP_NOOWNERZORDER);
122 return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
123}
124
125BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
126{
[354]127 if (GetAsyncKeyState(VK_F4) || dragging)
[351]128 {
129 lpPoint->x = gl->DisplayMode.Width / 2;
130 lpPoint->y = gl->DisplayMode.Height / 2;
131 }
[427]132 if (GetAsyncKeyState(VK_F12))
133 {
134 CHARTest();
135 }
[351]136 else
137 {
138 if (!GetCursorPos(lpPoint))
139 return 0;
140 if (onihwnd != NULL)
141 ScreenToClient(onihwnd, lpPoint);
142 }
143 return 1;
144}
145
146BOOL WINAPI LIiP_SetCursorPosHook(int X, int Y)
147{
[354]148 if (GetAsyncKeyState(VK_F4) || dragging)
[351]149 return TRUE;
150 else
151 {
152 POINT pt;
153 pt.x = X;
154 pt.y = Y;
155 if (onihwnd != NULL)
156 ClientToScreen(onihwnd, &pt);
157 return SetCursorPos(pt.x, pt.y);
158 }
159}
160
[349]161void DDrWindowHack_Install()
162{
[351]163 DDrPatch_NOOP((char*)0x0050F764, 6);
164 DDrPatch_MakeCall((char*)0x0050F764, ONrPI_CreateWindowExHook);
[349]165
[351]166 DDrPatch_NOOP((char*)0x00407E9F, 6);
167 DDrPatch_MakeCall((char*)0x00407E9F, glpi_SetWindowPosHook);
168
169 DDrPatch_NOOP((char*)0x004032CC, 6);
170 DDrPatch_MakeCall((char*)0x004032CC, LIiP_GetCursorPosHook);
171
172 DDrPatch_NOOP((char*)0x00402CC2, 6);
173 DDrPatch_MakeCall((char*)0x00402CC2, LIiP_GetCursorPosHook);
174
175 DDrPatch_NOOP((char*)0x004032B7, 6);
176 DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook);
177
178 DDrPatch_NOOP((char*)0x00403349, 6);
179 DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook);
[349]180}
Note: See TracBrowser for help on using the repository browser.