source: Daodan/src/Daodan_WindowHack.c@ 573

Last change on this file since 573 was 468, checked in by rossy, 15 years ago
File size: 4.9 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
[468]10#define CS_DROPSHADOW 0x20000
11
[351]12volatile HWND onihwnd, boxhwnd = NULL;
13int inclient = 0;
[354]14int dragging = 0;
[351]15
16LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
17{
18 switch (msg)
19 {
[430]20 case WM_KEYDOWN:
[351]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;
[468]41// case WM_CLOSE:
42// CHARTest();
43// break;
[351]44 case WM_DESTROY:
45 PostQuitMessage(0);
46 ExitProcess(0);
47 break;
[354]48 case WM_ENTERSIZEMOVE:
49 dragging = 1;
50 break;
51 case WM_EXITSIZEMOVE:
52 dragging = 0;
53 break;
[351]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);
[468]67 wc.style = (opt_border ? 0 : (opt_shadow ? CS_DROPSHADOW : 0));
[351]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;
[468]85 AdjustWindowRect(&re, WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), FALSE);
[351]86
[468]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);
[351]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;
[468]119 AdjustWindowRect(&re, WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), FALSE);
[351]120
[468]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);
[351]124 return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
125}
126
127BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
128{
[354]129 if (GetAsyncKeyState(VK_F4) || dragging)
[351]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{
[354]146 if (GetAsyncKeyState(VK_F4) || dragging)
[351]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
[349]159void DDrWindowHack_Install()
160{
[351]161 DDrPatch_NOOP((char*)0x0050F764, 6);
162 DDrPatch_MakeCall((char*)0x0050F764, ONrPI_CreateWindowExHook);
[349]163
[351]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);
[349]178}
Note: See TracBrowser for help on using the repository browser.