Skip to content

Commit 6506d33

Browse files
committed
Merge pull request #19 from psieg/fix/dxscan_thread
Move D3D10Grabber to dedicated thread
2 parents 985ede1 + 148dbbc commit 6506d33

File tree

7 files changed

+55
-21
lines changed

7 files changed

+55
-21
lines changed

Software/grab/D3D10Grabber.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ class D3D10GrabberImpl: public QObject
262262

263263
#endif
264264

265+
m_thread.reset(new QThread());
266+
m_thread->start();
267+
this->moveToThread(m_thread.data());
268+
265269
m_processesScanAndInfectTimer.reset(new QTimer(this));
266270
m_processesScanAndInfectTimer->setInterval(5000);
267271
m_processesScanAndInfectTimer->setSingleShot(false);
@@ -593,6 +597,11 @@ private slots:
593597
disconnect(m_worker.data());
594598
m_worker->stop = true;
595599

600+
m_thread->quit();
601+
m_workerThread->quit();
602+
m_thread->wait();
603+
m_workerThread->wait();
604+
596605
sanitizeProcesses();
597606

598607
disconnect(this, SLOT(handleIfFrameGrabbed()));
@@ -623,6 +632,7 @@ private slots:
623632
QScopedPointer<QTimer> m_checkIfFrameGrabbedTimer;
624633
QScopedPointer<D3D10GrabberWorker> m_worker;
625634
QScopedPointer<QThread> m_workerThread;
635+
QScopedPointer<QThread> m_thread;
626636
HOOKSGRABBER_SHARED_MEM_DESC m_memDesc;
627637
D3D10Grabber &m_owner;
628638
bool m_injectD3D9;

Software/grab/WinUtils.cpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ const WCHAR lightpackUnhookDllName[] = L"prismatik-unhook.dll";
4242
const WCHAR lightpackHooksDllName32[] = L"prismatik-hooks32.dll";
4343
const WCHAR lightpackOffsetFinderName[] = L"offsetfinder.exe";
4444
#endif
45-
static LPCWSTR pwstrExcludeProcesses[] = { L"skype.exe", L"chrome.exe", L"firefox.exe", L"iexplore.exe", L"qtcreator.exe", L"devenv.exe", L"thunderbird.exe" };
45+
static LPCWSTR pwstrExcludeProcesses[] = {
46+
// Windows
47+
L"dwm.exe", L"ShellExperienceHost.exe", L"ApplicationFrameHost.exe", L"LockAppHost.exe", L"explorer.exe", L"SearchUI.exe"
48+
// Graphics Drivers
49+
L"igfxEM.exe", L"igfxTray.exe", L"nvxdsync.exe", L"nvvsvc.exe",
50+
// Browsers
51+
L"chrome.exe", L"firefox.exe", L"iexplore.exe",
52+
// Apps
53+
L"skype.exe", L"SkypeHost.exe", L"qtcreator.exe", L"devenv.exe", L"thunderbird.exe", L"Steam.exe"
54+
};
4655
static LPCWSTR pwstrDxModules[] = { L"d3d9.dll", L"dxgi.dll" };
4756
static LPCWSTR pwstrDxgiModules[] = { L"dxgi.dll" };
4857
static LPCWSTR pwstrHookModules[] = { L"prismatik-hooks.dll", L"prismatik-hooks32.dll" };
@@ -133,10 +142,13 @@ QList<DWORD> * getProcessesIDs(QList<DWORD> * processes, LPCWSTR withModule[], U
133142
HMODULE hMods[1024];
134143
DWORD cbNeeded;
135144
DWORD cProcesses;
136-
char debug_buf[255];
145+
char debug_buf_process[255];
146+
char debug_buf_module[255];
137147
WCHAR executableName[MAX_PATH];
138148
unsigned int i;
139149

150+
DEBUG_MID_LEVEL << Q_FUNC_INFO << "scanning";
151+
140152
// Get the list of process identifiers.
141153
processes->clear();
142154

@@ -167,12 +179,12 @@ QList<DWORD> * getProcessesIDs(QList<DWORD> * processes, LPCWSTR withModule[], U
167179

168180
PathStripPathW(executableName);
169181

170-
::WideCharToMultiByte(CP_ACP, 0, executableName, -1, debug_buf, 255, NULL, NULL);
171-
DEBUG_MID_LEVEL << Q_FUNC_INFO << debug_buf;
182+
::WideCharToMultiByte(CP_ACP, 0, executableName, -1, debug_buf_process, 255, NULL, NULL);
183+
DEBUG_HIGH_LEVEL << Q_FUNC_INFO << "evaluating process" << debug_buf_process;
172184

173185
for (unsigned k = 0; k < SIZEOF_ARRAY(pwstrExcludeProcesses); k++) {
174186
if (wcsicmp(executableName, pwstrExcludeProcesses[k]) == 0) {
175-
DEBUG_MID_LEVEL << Q_FUNC_INFO << "skipping " << pwstrExcludeProcesses[k];
187+
DEBUG_HIGH_LEVEL << Q_FUNC_INFO << "skipping" << debug_buf_process;
176188
goto nextProcess;
177189
}
178190
}
@@ -194,8 +206,8 @@ QList<DWORD> * getProcessesIDs(QList<DWORD> * processes, LPCWSTR withModule[], U
194206
{
195207

196208
PathStripPathW(szModName);
197-
::WideCharToMultiByte(CP_ACP, 0, szModName, -1, debug_buf, 255, NULL, NULL);
198-
DEBUG_HIGH_LEVEL << Q_FUNC_INFO << debug_buf;
209+
::WideCharToMultiByte(CP_ACP, 0, szModName, -1, debug_buf_module, 255, NULL, NULL);
210+
//DEBUG_HIGH_LEVEL << Q_FUNC_INFO << debug_buf_process << "has module" << debug_buf_module;
199211

200212
for (unsigned k = 0; k < withoutModuleCount; k++) {
201213
if (wcsicmp(szModName, withoutModule[k]) == 0) {
@@ -220,11 +232,19 @@ QList<DWORD> * getProcessesIDs(QList<DWORD> * processes, LPCWSTR withModule[], U
220232
RECT rcWindow;
221233
GetWindowRect(wnd, &rcWindow);
222234
if ((w == (rcWindow.right - rcWindow.left)) &&
223-
(h == (rcWindow.bottom - rcWindow.top)))
224-
processes->append(aProcesses[i]);
235+
(h == (rcWindow.bottom - rcWindow.top))) {
225236

237+
DEBUG_MID_LEVEL << Q_FUNC_INFO << debug_buf_process << "has required module and fullscreen window";
238+
processes->append(aProcesses[i]);
239+
} else {
240+
DEBUG_MID_LEVEL << Q_FUNC_INFO << debug_buf_process << "has required module and non-fullscreen window";
241+
}
242+
} else {
243+
DEBUG_MID_LEVEL << Q_FUNC_INFO << debug_buf_process << "has required module and no window";
226244
}
227-
} else {
245+
}
246+
else {
247+
DEBUG_MID_LEVEL << Q_FUNC_INFO << debug_buf_process << "has required module";
228248
processes->append(aProcesses[i]);
229249
}
230250

@@ -241,11 +261,11 @@ QList<DWORD> * getProcessesIDs(QList<DWORD> * processes, LPCWSTR withModule[], U
241261
}
242262

243263
QList<DWORD> * getDxProcessesIDs(QList<DWORD> * processes, LPCWSTR wstrSystemRootPath) {
244-
return getProcessesIDs(processes, pwstrDxModules, SIZEOF_ARRAY(pwstrDxModules), pwstrHookModules, SIZEOF_ARRAY(pwstrHookModules), wstrSystemRootPath, true);
264+
return getProcessesIDs(processes, pwstrDxModules, SIZEOF_ARRAY(pwstrDxModules), pwstrHookModules, SIZEOF_ARRAY(pwstrHookModules), wstrSystemRootPath, true);
245265
}
246266

247267
QList<DWORD> * getDxgiProcessesIDs(QList<DWORD> * processes, LPCWSTR wstrSystemRootPath) {
248-
return getProcessesIDs(processes, pwstrDxgiModules, SIZEOF_ARRAY(pwstrDxgiModules), pwstrHookModules, SIZEOF_ARRAY(pwstrHookModules), wstrSystemRootPath, true);
268+
return getProcessesIDs(processes, pwstrDxgiModules, SIZEOF_ARRAY(pwstrDxgiModules), pwstrHookModules, SIZEOF_ARRAY(pwstrHookModules), wstrSystemRootPath, true);
249269
}
250270

251271
QList<DWORD> * getHookedProcessesIDs(QList<DWORD> * processes, LPCWSTR wstrSystemRootPath) {

Software/src/ApiServer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ ApiServer::ApiServer(quint16 port, QObject *parent)
182182
}
183183
}
184184

185+
ApiServer::~ApiServer() {
186+
m_apiSetColorTaskThread->quit();
187+
m_apiSetColorTaskThread->wait();
188+
}
189+
185190
void ApiServer::setInterface(LightpackPluginInterface *lightpackInterface)
186191
{
187192
QString test = lightpack->Version();

Software/src/ApiServer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ApiServer : public QTcpServer
5656
public:
5757
ApiServer(QObject *parent = 0);
5858
ApiServer(quint16 port, QObject *parent = 0);
59+
~ApiServer();
5960

6061
void setInterface(LightpackPluginInterface *lightpackInterface);
6162
void firstStart();

Software/src/LedDeviceManager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ LedDeviceManager::LedDeviceManager(QObject *parent)
5959

6060
LedDeviceManager::~LedDeviceManager()
6161
{
62-
m_ledDeviceThread->deleteLater();
62+
m_ledDeviceThread->quit();
63+
m_ledDeviceThread->wait();
64+
6365
for (int i = 0; i < m_ledDevices.size(); i++) {
6466
if(m_ledDevices[i])
6567
m_ledDevices[i]->close();

Software/src/LightpackApplication.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ LightpackApplication::~LightpackApplication()
6565

6666
m_EventFilters.clear();
6767

68-
m_ledDeviceManagerThread->exit(0);
69-
m_apiServerThread->exit(0);
70-
68+
m_ledDeviceManagerThread->quit();
69+
m_apiServerThread->quit();
70+
m_ledDeviceManagerThread->wait();
71+
m_apiServerThread->wait();
7172

7273
delete m_settingsWindow;
7374
m_settingsWindow = NULL;
@@ -632,10 +633,6 @@ void LightpackApplication::startPluginManager()
632633
m_pluginManager->LoadPlugins(QString(Settings::getApplicationDirPath() + "Plugins"));
633634
m_pluginManager->StartPlugins();
634635

635-
//m_PluginThread = new QThread();
636-
//m_pluginManager->moveToThread(m_PluginThread);
637-
//m_PluginThread->start();
638-
639636
}
640637

641638

Software/src/LightpackApplication.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ private slots:
113113

114114
PluginsManager *m_pluginManager;
115115
LightpackPluginInterface *m_pluginInterface;
116-
QThread* m_PluginThread;
117116
QWidget *consolePlugin;
118117

119118
QString m_applicationDirPath;

0 commit comments

Comments
 (0)