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