diff --git a/GUI/main.cpp b/GUI/main.cpp index b48f94e..0058c1d 100644 --- a/GUI/main.cpp +++ b/GUI/main.cpp @@ -1,8 +1,10 @@ #include "mainwindow.h" +#include "../texthook/host.h" #include int main(int argc, char *argv[]) { + if (!Host::Start()) return 1; QApplication a(argc, argv); MainWindow w; w.show(); diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 306e6f7..6e1da8d 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -55,7 +55,6 @@ MainWindow::MainWindow(QWidget *parent) : ttCombo = mainWindow->findChild("ttCombo"); textOutput = mainWindow->findChild("textOutput"); - Host::Start(); hostSignaller->Initialize(); connect(hostSignaller, &HostSignaller::AddProcess, this, &MainWindow::AddProcess); connect(hostSignaller, &HostSignaller::RemoveProcess, this, &MainWindow::RemoveProcess); @@ -74,14 +73,12 @@ MainWindow::~MainWindow() void MainWindow::AddProcess(unsigned int processId) { - processCombo->addItem(ProcessString(processId), Qt::AlignHCenter); + processCombo->addItem(ProcessString(processId)); } void MainWindow::RemoveProcess(unsigned int processId) { - for (int i = 0; i < processCombo->count(); ++i) - if (processCombo->itemText(i).split(":")[0] == QString::number(processId)) - processCombo->removeItem(i); + processCombo->removeItem(processCombo->findText(QString::number(processId), Qt::MatchStartsWith)); } void MainWindow::AddThread(TextThread* thread) @@ -91,16 +88,13 @@ void MainWindow::AddThread(TextThread* thread) void MainWindow::RemoveThread(TextThread* thread) { - for (int i = 0; i < ttCombo->count(); ++i) - if (ttCombo->itemText(i).split(":")[0] == QString::number(thread->Number())) - { - ttCombo->removeItem(i); - if (i == ttCombo->currentIndex()) - { - ttCombo->setCurrentIndex(0); - on_ttCombo_activated(0); - } - } + int threadIndex = ttCombo->findText(QString::number(thread->Number()), Qt::MatchStartsWith); + ttCombo->removeItem(threadIndex); + if (threadIndex == ttCombo->currentIndex()) + { + ttCombo->setCurrentIndex(0); + on_ttCombo_activated(0); + } } void MainWindow::ThreadOutput(TextThread* thread, QString output) diff --git a/GUI/mainwindow.ui b/GUI/mainwindow.ui index d9b5878..53df71d 100644 --- a/GUI/mainwindow.ui +++ b/GUI/mainwindow.ui @@ -6,10 +6,16 @@ 0 0 - 800 + 949 600 + + + 2 + 0 + + 10 @@ -20,10 +26,22 @@ + + 0 + + + 0 + + + 0 + + + 0 + - + - + 2 0 @@ -34,29 +52,159 @@ QFrame::Raised - + + + 4 + + + 4 + + + 4 + + + 4 + - - - - - - QComboBox::InsertAtBottom + + + true + + + 2 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QComboBox::InsertAtBottom + + + + + + + Attach to game + + + + + + + Detach from game + + + + + + + Add hook + + + + + + + Remove hook + + + + + + + Save hook(s) + + + + - - - Attach to game + + + Qt::Vertical - + + + 20 + 40 + + + - - - Detach from game + + + + 0 + 0 + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + Add extension + + + + + + + Enable extension + + + + + + + Disable extension + + + + @@ -77,6 +225,18 @@ QFrame::Raised + + 4 + + + 4 + + + 4 + + + 4 + @@ -105,10 +265,22 @@ 0 0 - 800 - 23 + 949 + 21 + + + Options + + + + + About + + + + diff --git a/texthook/host.cc b/texthook/host.cc index 668aee8..ead94a6 100644 --- a/texthook/host.cc +++ b/texthook/host.cc @@ -23,7 +23,6 @@ ProcessEventCallback onAttach, onDetach; WORD nextThreadNumber; HWND dummyWindow; -bool running; #define HOST_LOCK CriticalSectionLocker hostLocker(hostCs) // Synchronized scope for accessing private data @@ -56,14 +55,13 @@ namespace Host DLLEXPORT bool Start() { preventDuplicationMutex = CreateMutexW(nullptr, TRUE, ITH_SERVER_MUTEX); - if (GetLastError() == ERROR_ALREADY_EXISTS || running) + if (GetLastError() == ERROR_ALREADY_EXISTS) { MessageBoxW(nullptr, L"I am sorry that this game is attached by some other VNR ><\nPlease restart the game and try again!", L"Error", MB_ICONERROR); return false; } else { - running = true; GetDebugPrivileges(); InitializeCriticalSection(&hostCs); onAttach = onDetach = nullptr; @@ -83,17 +81,13 @@ namespace Host DLLEXPORT void Close() { - if (running) - { - EnterCriticalSection(&hostCs); - running = false; - DestroyWindow(dummyWindow); - RemoveThreads([](auto one, auto two) { return true; }, {}); - //for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator - LeaveCriticalSection(&hostCs); - DeleteCriticalSection(&hostCs); - CloseHandle(preventDuplicationMutex); - } + EnterCriticalSection(&hostCs); + DestroyWindow(dummyWindow); + RemoveThreads([](auto one, auto two) { return true; }, {}); + //for (auto i : processRecordsByIds) UnregisterProcess(i.first); // Artikash 7/24/2018 FIXME: This segfaults since UnregisterProcess invalidates the iterator + LeaveCriticalSection(&hostCs); + DeleteCriticalSection(&hostCs); + CloseHandle(preventDuplicationMutex); } DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout)