source: Daodan/MSVC/Daodan_WindowHack.c@ 986

Last change on this file since 986 was 567, checked in by gumby, 14 years ago

Daodan MSVC

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 RECT re;
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
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 RECT re;
112 SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE);
113 SetCursor(LoadCursor(NULL, IDC_ARROW));
114
115
116 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2);
117 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2);
118 re.right = re.left + cx;
119 re.bottom = re.top + cy;
120 AdjustWindowRect(&re, WS_POPUP | (opt_border ? WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU : 0), FALSE);
121
122 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));
123 ShowWindow(boxhwnd, SW_SHOW);
124 UpdateWindow(boxhwnd);
125 return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
126}
127
128BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
129{
130 if (GetAsyncKeyState(VK_F4) || dragging)
131 {
132 lpPoint->x = gl_eng->DisplayMode.Width / 2;
133 lpPoint->y = gl_eng->DisplayMode.Height / 2;
134 }
135 else
136 {
137 if (!GetCursorPos(lpPoint))
138 return 0;
139 if (onihwnd != NULL)
140 ScreenToClient(onihwnd, lpPoint);
141 }
142 return 1;
143}
144
145BOOL WINAPI LIiP_SetCursorPosHook(int X, int Y)
146{
147 if (GetAsyncKeyState(VK_F4) || dragging)
148 return TRUE;
149 else
150 {
151 POINT pt;
152 pt.x = X;
153 pt.y = Y;
154 if (onihwnd != NULL)
155 ClientToScreen(onihwnd, &pt);
156 return SetCursorPos(pt.x, pt.y);
157 }
158}
159
160void DDrWindowHack_Install()
161{
162 DDrPatch_NOOP((char*)0x0050F764, 6);
163 DDrPatch_MakeCall((char*)0x0050F764, ONrPI_CreateWindowExHook);
164
165 DDrPatch_NOOP((char*)0x00407E9F, 6);
166 DDrPatch_MakeCall((char*)0x00407E9F, glpi_SetWindowPosHook);
167
168 DDrPatch_NOOP((char*)0x004032CC, 6);
169 DDrPatch_MakeCall((char*)0x004032CC, LIiP_GetCursorPosHook);
170
171 DDrPatch_NOOP((char*)0x00402CC2, 6);
172 DDrPatch_MakeCall((char*)0x00402CC2, LIiP_GetCursorPosHook);
173
174 DDrPatch_NOOP((char*)0x004032B7, 6);
175 DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook);
176
177 DDrPatch_NOOP((char*)0x00403349, 6);
178 DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook);
179}
Note: See TracBrowser for help on using the repository browser.