set up GUI skeleton, and small bugfixes

This commit is contained in:
Akash Mozumdar 2018-07-24 19:00:10 -07:00
parent a85c398f47
commit 11d6a156dd
4 changed files with 210 additions and 48 deletions

View File

@ -1,8 +1,10 @@
#include "mainwindow.h"
#include "../texthook/host.h"
#include <QApplication>
int main(int argc, char *argv[])
{
if (!Host::Start()) return 1;
QApplication a(argc, argv);
MainWindow w;
w.show();

View File

@ -55,7 +55,6 @@ MainWindow::MainWindow(QWidget *parent) :
ttCombo = mainWindow->findChild<QComboBox*>("ttCombo");
textOutput = mainWindow->findChild<QTextBrowser*>("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())
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)

View File

@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>949</width>
<height>600</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
@ -20,8 +26,50 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="options">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QFrame" name="processManager">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>2</horstretch>
@ -35,9 +83,18 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="processCombo">
<property name="insertPolicy">
@ -59,6 +116,97 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="hookButton">
<property name="text">
<string>Add hook</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="unhookButton">
<property name="text">
<string>Remove hook</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save hook(s)</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QFrame" name="extenManager">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="extenCombo"/>
</item>
<item>
<widget class="QPushButton" name="addExtenButton">
<property name="text">
<string>Add extension</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enableExtenButton">
<property name="text">
<string>Enable extension</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="disableExtenButton">
<property name="text">
<string>Disable extension</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
@ -77,6 +225,18 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="QComboBox" name="ttCombo"/>
</item>
@ -105,10 +265,22 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>23</height>
<width>949</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuOptions">
<property name="title">
<string>Options</string>
</property>
</widget>
<widget class="QMenu" name="menuAbout">
<property name="title">
<string>About</string>
</property>
</widget>
<addaction name="menuOptions"/>
<addaction name="menuAbout"/>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>

View File

@ -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;
@ -82,11 +80,8 @@ 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
@ -94,7 +89,6 @@ namespace Host
DeleteCriticalSection(&hostCs);
CloseHandle(preventDuplicationMutex);
}
}
DLLEXPORT bool InjectProcess(DWORD processId, DWORD timeout)
{