source: Daodan/src/Daodan_WindowHack.c@ 433

Last change on this file since 433 was 430, checked in by rossy, 15 years ago

it doesnt work :(

File size: 4.7 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
10volatile HWND onihwnd, boxhwnd = NULL;
11int inclient = 0;
12int dragging = 0;
13
14LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
15{
16 switch (msg)
17 {
18 case WM_KEYDOWN:
19 if (wParam == VK_F5)
20 CHARTest();
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 DestroyWindow(hwnd);
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 = 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 | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
86
87 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);
88 ShowWindow(boxhwnd, SW_SHOW);
89 UpdateWindow(boxhwnd);
90
91 while (GetMessage(&Msg, NULL, 0, 0) > 0)
92 {
93 TranslateMessage(&Msg);
94 DispatchMessage(&Msg);
95 }
96 return 0;
97}
98
99HWND 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)
100{
101 CloseHandle(CreateThread(NULL, 0, DDrHack_WndMain, NULL, 0, NULL));
102
103 while (!boxhwnd)
104 Sleep(50);
105
106 onihwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, boxhwnd, hMenu, hInstance, lpParam);
107 SetParent(onihwnd, boxhwnd);
108 return onihwnd;
109}
110
111BOOL WINAPI glpi_SetWindowPosHook(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
112{
113 SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE);
114 SetCursor(LoadCursor(NULL, IDC_ARROW));
115
116 RECT re;
117 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2);
118 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2);
119 re.right = re.left + cx;
120 re.bottom = re.top + cy;
121 AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
122
123 SetWindowPos(boxhwnd, NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, uFlags | SWP_NOOWNERZORDER);
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.