source: Daodan/src/Daodan_WindowHack.c@ 352

Last change on this file since 352 was 351, checked in by rossy, 15 years ago

almost windowed mode

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