source: Daodan/src/Daodan_WindowHack.c@ 456

Last change on this file since 456 was 435, checked in by gumby, 15 years ago

Added ActiveCharacter struct and associated structs...

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 {
[430]18 case WM_KEYDOWN:
[435]19 if (wParam == VK_F5) {
20 MessageBox(0, "test", "", 0);
[430]21 CHARTest();
[435]22 }
[351]23 case WM_ACTIVATE:
24 case WM_CHAR:
25 case WM_KEYUP:
26 ONrPlatform_WindowProc(onihwnd, msg, wParam, lParam);
27 return DefWindowProc(hwnd, msg, wParam, lParam);
28 case WM_SETCURSOR:
29 if (LOWORD(lParam) == HTCLIENT)
30 {
31 if (!inclient)
32 {
33 inclient = 1;
34 ShowCursor(FALSE);
35 }
36 }
37 else if (inclient)
38 {
39 inclient = 0;
40 ShowCursor(TRUE);
41 }
42 break;
43 case WM_CLOSE:
[435]44 CHARTest();
[351]45 break;
46 case WM_DESTROY:
47 PostQuitMessage(0);
48 ExitProcess(0);
49 break;
[354]50 case WM_ENTERSIZEMOVE:
51 dragging = 1;
52 break;
53 case WM_EXITSIZEMOVE:
54 dragging = 0;
55 break;
[351]56 default:
57 return DefWindowProc(hwnd, msg, wParam, lParam);
58 }
59 return 0;
60}
61
62DWORD WINAPI DDrHack_WndMain(LPVOID param)
63{
64 MSG Msg;
65
66 WNDCLASSEX wc;
67
68 wc.cbSize = sizeof(WNDCLASSEX);
69 wc.style = 0;
70 wc.lpfnWndProc = DDrHack_WndProc;
71 wc.cbClsExtra = 0;
72 wc.cbWndExtra = 0;
73 wc.hInstance = DDrDLLModule;
74 wc.hIcon = LoadIcon(DDrONiModule, MAKEINTRESOURCE(103));
75 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
76 wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
77 wc.lpszMenuName = NULL;
78 wc.lpszClassName = "OniGanbatte";
79 wc.hIconSm = NULL;
80 RegisterClassEx(&wc);
81
82 RECT re;
83 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (640 / 2);
84 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (480 / 2);
85 re.right = re.left + 640;
86 re.bottom = re.top + 480;
87 AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
88
89 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);
90 ShowWindow(boxhwnd, SW_SHOW);
91 UpdateWindow(boxhwnd);
92
93 while (GetMessage(&Msg, NULL, 0, 0) > 0)
94 {
95 TranslateMessage(&Msg);
96 DispatchMessage(&Msg);
97 }
98 return 0;
99}
100
101HWND 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)
102{
103 CloseHandle(CreateThread(NULL, 0, DDrHack_WndMain, NULL, 0, NULL));
104
105 while (!boxhwnd)
106 Sleep(50);
107
108 onihwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, boxhwnd, hMenu, hInstance, lpParam);
109 SetParent(onihwnd, boxhwnd);
110 return onihwnd;
111}
112
113BOOL WINAPI glpi_SetWindowPosHook(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags)
114{
115 SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE);
116 SetCursor(LoadCursor(NULL, IDC_ARROW));
117
118 RECT re;
119 re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2);
120 re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2);
121 re.right = re.left + cx;
122 re.bottom = re.top + cy;
123 AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE);
124
125 SetWindowPos(boxhwnd, NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, uFlags | SWP_NOOWNERZORDER);
126 return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER);
127}
128
129BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint)
130{
[354]131 if (GetAsyncKeyState(VK_F4) || dragging)
[351]132 {
133 lpPoint->x = gl->DisplayMode.Width / 2;
134 lpPoint->y = gl->DisplayMode.Height / 2;
135 }
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.