#include #include "Daodan_WindowHack.h" #include "Daodan_Patch.h" #include "Oni.h" #include "BFW_Motoko_Draw.h" #include "oni_gl.h" volatile HWND onihwnd, boxhwnd = NULL; int inclient = 0; int dragging = 0; LRESULT CALLBACK DDrHack_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_ACTIVATE: case WM_CHAR: case WM_KEYUP: case WM_KEYDOWN: ONrPlatform_WindowProc(onihwnd, msg, wParam, lParam); return DefWindowProc(hwnd, msg, wParam, lParam); case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT) { if (!inclient) { inclient = 1; ShowCursor(FALSE); } } else if (inclient) { inclient = 0; ShowCursor(TRUE); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); ExitProcess(0); break; case WM_ENTERSIZEMOVE: dragging = 1; break; case WM_EXITSIZEMOVE: dragging = 0; break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } DWORD WINAPI DDrHack_WndMain(LPVOID param) { MSG Msg; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = DDrHack_WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = DDrDLLModule; wc.hIcon = LoadIcon(DDrONiModule, MAKEINTRESOURCE(103)); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); wc.lpszMenuName = NULL; wc.lpszClassName = "OniGanbatte"; wc.hIconSm = NULL; RegisterClassEx(&wc); RECT re; re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (640 / 2); re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (480 / 2); re.right = re.left + 640; re.bottom = re.top + 480; AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE); 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); ShowWindow(boxhwnd, SW_SHOW); UpdateWindow(boxhwnd); while (GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return 0; } 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) { CloseHandle(CreateThread(NULL, 0, DDrHack_WndMain, NULL, 0, NULL)); while (!boxhwnd) Sleep(50); onihwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, WS_POPUP | WS_VISIBLE, 0, 0, 640, 480, boxhwnd, hMenu, hInstance, lpParam); SetParent(onihwnd, boxhwnd); return onihwnd; } BOOL WINAPI glpi_SetWindowPosHook(HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags) { SetWindowLong(onihwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE); SetCursor(LoadCursor(NULL, IDC_ARROW)); RECT re; re.left = (GetSystemMetrics(SM_CXSCREEN) / 2) - (cx / 2); re.top = (GetSystemMetrics(SM_CYSCREEN) / 2) - (cy / 2); re.right = re.left + cx; re.bottom = re.top + cy; AdjustWindowRect(&re, WS_POPUP | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU, FALSE); SetWindowPos(boxhwnd, NULL, re.left, re.top, re.right - re.left, re.bottom - re.top, uFlags | SWP_NOOWNERZORDER); return SetWindowPos(hWnd, NULL, 0, 0, cx, cy, uFlags | SWP_NOOWNERZORDER); } BOOL WINAPI LIiP_GetCursorPosHook(LPPOINT lpPoint) { if (GetAsyncKeyState(VK_F4) || dragging) { lpPoint->x = gl->DisplayMode.Width / 2; lpPoint->y = gl->DisplayMode.Height / 2; } else { if (!GetCursorPos(lpPoint)) return 0; if (onihwnd != NULL) ScreenToClient(onihwnd, lpPoint); } return 1; } BOOL WINAPI LIiP_SetCursorPosHook(int X, int Y) { if (GetAsyncKeyState(VK_F4) || dragging) return TRUE; else { POINT pt; pt.x = X; pt.y = Y; if (onihwnd != NULL) ClientToScreen(onihwnd, &pt); return SetCursorPos(pt.x, pt.y); } } void DDrWindowHack_Install() { DDrPatch_NOOP((char*)0x0050F764, 6); DDrPatch_MakeCall((char*)0x0050F764, ONrPI_CreateWindowExHook); DDrPatch_NOOP((char*)0x00407E9F, 6); DDrPatch_MakeCall((char*)0x00407E9F, glpi_SetWindowPosHook); DDrPatch_NOOP((char*)0x004032CC, 6); DDrPatch_MakeCall((char*)0x004032CC, LIiP_GetCursorPosHook); DDrPatch_NOOP((char*)0x00402CC2, 6); DDrPatch_MakeCall((char*)0x00402CC2, LIiP_GetCursorPosHook); DDrPatch_NOOP((char*)0x004032B7, 6); DDrPatch_MakeCall((char*)0x004032B7, LIiP_SetCursorPosHook); DDrPatch_NOOP((char*)0x00403349, 6); DDrPatch_MakeCall((char*)0x00403349, LIiP_SetCursorPosHook); }