/******************************************************************************** Copyright (C) 2012 Hugh Bailey This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. ********************************************************************************/ #include "GraphicsCapture.h" extern "C" __declspec(dllexport) bool LoadPlugin(); extern "C" __declspec(dllexport) void UnloadPlugin(); extern "C" __declspec(dllexport) CTSTR GetPluginName(); extern "C" __declspec(dllexport) CTSTR GetPluginDescription(); HINSTANCE hinstMain = NULL; HANDLE textureMutexes[2] = {NULL, NULL}; #define GRAPHICSCAPTURE_CLASSNAME TEXT("GraphicsCapture") struct WindowInfo { String strClass; BOOL bRequiresAdmin; }; struct ConfigDialogData { XElement *data; List windowData; StringList adminWindows; UINT cx, cy; inline void ClearData() { for(UINT i=0; idata; SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); LocalizeWindow(hwnd); //-------------------------------------------- SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_REFRESH, BN_CLICKED), (LPARAM)GetDlgItem(hwnd, IDC_APPLIST)); //-------------------------------------------- BOOL bCaptureMouse = data->GetInt(TEXT("captureMouse"), 1); BOOL bStretchImage = data->GetInt(TEXT("stretchImage")); SendMessage(GetDlgItem(hwnd, IDC_STRETCHTOSCREEN), BM_SETCHECK, bStretchImage ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_IGNOREASPECT), BM_SETCHECK, data->GetInt(TEXT("ignoreAspect")) ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_CAPTUREMOUSE), BM_SETCHECK, bCaptureMouse ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_INVERTMOUSEONCLICK), BM_SETCHECK, data->GetInt(TEXT("invertMouse")) ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_INVERTMOUSEONCLICK), bCaptureMouse); EnableWindow(GetDlgItem(hwnd, IDC_IGNOREASPECT), bStretchImage); return TRUE; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_CAPTUREMOUSE: { BOOL bCaptureMouse = SendMessage(GetDlgItem(hwnd, IDC_CAPTUREMOUSE), BM_GETCHECK, 0, 0) == BST_CHECKED; EnableWindow(GetDlgItem(hwnd, IDC_INVERTMOUSEONCLICK), bCaptureMouse); } break; case IDC_STRETCHTOSCREEN: { BOOL bStretchToScreen = SendMessage(GetDlgItem(hwnd, IDC_STRETCHTOSCREEN), BM_GETCHECK, 0, 0) == BST_CHECKED; EnableWindow(GetDlgItem(hwnd, IDC_IGNOREASPECT), bStretchToScreen); } break; case IDC_REFRESH: { ConfigDialogData *info = (ConfigDialogData*)GetWindowLongPtr(hwnd, DWLP_USER); XElement *data = info->data; CTSTR lpWindowName = data->GetString(TEXT("window")); HWND hwndWindowList = GetDlgItem(hwnd, IDC_APPLIST); RefreshWindowList(hwndWindowList, *info); UINT windowID = 0; if(lpWindowName) windowID = (UINT)SendMessage(hwndWindowList, CB_FINDSTRINGEXACT, -1, (LPARAM)lpWindowName); if(windowID != CB_ERR) SendMessage(hwndWindowList, CB_SETCURSEL, windowID, 0); else SendMessage(hwndWindowList, CB_SETCURSEL, 0, 0); String strInfoText; if(info->adminWindows.Num()) { strInfoText << Str("Sources.GameCaptureSource.RequiresAdmin") << TEXT("\r\n"); for(UINT i=0; iadminWindows.Num(); i++) strInfoText << info->adminWindows[i] << TEXT("\r\n"); } SetWindowText(GetDlgItem(hwnd, IDC_INFO), strInfoText); } break; case IDOK: { UINT windowID = (UINT)SendMessage(GetDlgItem(hwnd, IDC_APPLIST), CB_GETCURSEL, 0, 0); if(windowID == CB_ERR) windowID = 0; ConfigDialogData *info = (ConfigDialogData*)GetWindowLongPtr(hwnd, DWLP_USER); XElement *data = info->data; if(!info->windowData.Num()) return 0; String strWindow = GetCBText(GetDlgItem(hwnd, IDC_APPLIST), windowID); data->SetString(TEXT("window"), strWindow); data->SetString(TEXT("windowClass"), info->windowData[windowID].strClass); data->SetInt(TEXT("stretchImage"), SendMessage(GetDlgItem(hwnd, IDC_STRETCHTOSCREEN), BM_GETCHECK, 0, 0) == BST_CHECKED); data->SetInt(TEXT("ignoreAspect"), SendMessage(GetDlgItem(hwnd, IDC_IGNOREASPECT), BM_GETCHECK, 0, 0) == BST_CHECKED); data->SetInt(TEXT("captureMouse"), SendMessage(GetDlgItem(hwnd, IDC_CAPTUREMOUSE), BM_GETCHECK, 0, 0) == BST_CHECKED); data->SetInt(TEXT("invertMouse"), SendMessage(GetDlgItem(hwnd, IDC_INVERTMOUSEONCLICK), BM_GETCHECK, 0, 0) == BST_CHECKED); } case IDCANCEL: EndDialog(hwnd, LOWORD(wParam)); } break; case WM_CLOSE: EndDialog(hwnd, IDCANCEL); } return 0; } bool STDCALL ConfigureGraphicsCaptureSource(XElement *element, bool bCreating) { if(!element) { AppWarning(TEXT("ConfigureGraphicsCaptureSource: NULL element")); return false; } XElement *data = element->GetElement(TEXT("data")); if(!data) data = element->CreateElement(TEXT("data")); ConfigDialogData *configData = new ConfigDialogData; configData->data = data; if(DialogBoxParam(hinstMain, MAKEINTRESOURCE(IDD_CONFIG), API->GetMainWindow(), ConfigureDialogProc, (LPARAM)configData) == IDOK) { UINT width, height; API->GetBaseSize(width, height); element->SetInt(TEXT("cx"), width); element->SetInt(TEXT("cy"), height); delete configData; return true; } delete configData; return false; } ImageSource* STDCALL CreateGraphicsCaptureSource(XElement *data) { GraphicsCaptureSource *source = new GraphicsCaptureSource; if(!source->Init(data)) { delete source; return NULL; } return source; } bool LoadPlugin() { textureMutexes[0] = CreateMutex(NULL, NULL, TEXTURE_MUTEX1); if(!textureMutexes[0]) { AppWarning(TEXT("Could not create texture mutex 1, GetLastError = %u"), GetLastError()); return false; } textureMutexes[1] = CreateMutex(NULL, NULL, TEXTURE_MUTEX2); if(!textureMutexes[1]) { AppWarning(TEXT("Could not create texture mutex 2, GetLastError = %u"), GetLastError()); return false; } API->RegisterImageSourceClass(GRAPHICSCAPTURE_CLASSNAME, Str("Sources.GameCaptureSource"), (OBSCREATEPROC)CreateGraphicsCaptureSource, (OBSCONFIGPROC)ConfigureGraphicsCaptureSource); return true; } void UnloadPlugin() { CloseHandle(textureMutexes[0]); CloseHandle(textureMutexes[1]); } CTSTR GetPluginName() { return Str("Sources.GameCaptureSource.PluginName"); } CTSTR GetPluginDescription() { return Str("Sources.GameCaptureSource.PluginDescription"); } BOOL CALLBACK DllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpBla) { if(dwReason == DLL_PROCESS_ATTACH) hinstMain = hInst; return TRUE; }