Skip to content

Commit

Permalink
Code now on GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
HW12Dev committed Sep 2, 2024
0 parents commit 5f34135
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vsxmake2022
build
.xmake
.vscode
10 changes: 10 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# dslConsole

Open source version of a development tool, called wxConsole, used with the Diesel game engine (PAYDAY: The Heist, PAYDAY 2, RAID: World War II)

Currently only works with [Lead and Gold - Gangs of the Wild West](https://store.steampowered.com/app/42120/Lead_and_Gold_Gangs_of_the_Wild_West/),
as that is the only Diesel engine game to be released with the ability to connect to wxConsole.

# Disclaimer

I am not affiliated with Grin, Fatshark, Starbreeze Studios or Lion game Lion.
1 change: 1 addition & 0 deletions project.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xmake project -k vsxmake2022 -y
154 changes: 154 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#define WIN32_LEAN_AND_MEAN
#define DIESEL_CONSOLE_PORT 20249

#include <QApplication>
#include <QThread>
#include <QTimer>
#include "main.hpp"

QString INF_COLOUR("#FFFFFF");
QString ECH_COLOUR("");
QString WRN_COLOUR("#FFFF00");
QString ERR_COLOUR("#FF0000");
QString NUL_COLOUR("");

void MainWindow::SockConnected() {
AddToCommandIn("Connected to game socket\n");
}

void MainWindow::SockDisconnected() {
AddToCommandIn("Game socket disconnected\n");
}

void MainWindow::ReadReady() {
QString raw_to_write = consoleSock->readAll();

AddToCommandIn(raw_to_write);
}

void MainWindow::SocketStateChanged(QTcpSocket::SocketState state) {
if (state == QTcpSocket::SocketState::UnconnectedState) {
this->SetupSocketConnection();
}
}

void MainWindow::BytesWritten(qint64 bytes) {

}

void MainWindow::AddToCommandIn(QString to_add) {
commandIn->moveCursor(QTextCursor::End);
commandIn->insertPlainText(to_add);
commandIn->moveCursor(QTextCursor::End);
}

void MainWindow::SetupSocketConnection() {
if (consoleSock == nullptr) {
consoleSock = new QTcpSocket();

connect(consoleSock, &QTcpSocket::connected, this, &MainWindow::SockConnected);
connect(consoleSock, &QTcpSocket::disconnected, this, &MainWindow::SockDisconnected);
connect(consoleSock, &QTcpSocket::bytesWritten, this, &MainWindow::BytesWritten);
connect(consoleSock, &QTcpSocket::readyRead, this, &MainWindow::ReadReady);
connect(consoleSock, &QTcpSocket::stateChanged, this, &MainWindow::SocketStateChanged);
}

consoleSock->connectToHost("127.0.0.1", DIESEL_CONSOLE_PORT);
/*if (!consoleSock->waitForConnected(5000)) {
qDebug() << "Error: " << consoleSock->errorString();
SetupSocketConnection();
}*/
}

void MainWindow::SubmitCommand() {
consoleSock->write(commandEntry->text().toLocal8Bit());
commandEntry->setText("");
}

void MainWindow::SaveLog() {
QFile out_file(save_file_dialog->selectedFiles().first());
out_file.open(QFile::OpenModeFlag::WriteOnly);
QTextStream out(&out_file);
out << this->commandIn->toPlainText();
out_file.close();
}

void MainWindow::SaveLogDialog() {
this->save_file_dialog->exec();
}

void MainWindow::Clear() {
this->commandIn->setText(QString(""));
}

MainWindow::MainWindow() {
this->resize(QSize(800, 600));

QWidget* central = new QWidget(this);
setCentralWidget(central);

menu_bar = new QMenuBar(this);
setMenuBar(menu_bar);

this->save_file_dialog = new QFileDialog(this);
this->save_file_dialog->setFileMode(QFileDialog::FileMode::AnyFile);
this->save_file_dialog->setAcceptMode(QFileDialog::AcceptSave);

connect(save_file_dialog, &QFileDialog::fileSelected, this, &MainWindow::SaveLog);

file_menu = new QMenu(QString("File"));
menu_bar->addMenu(file_menu);

save_menu = file_menu->addAction(QString("Save"));

clear_menu = file_menu->addAction(QString("Clear"));

connect(save_menu, &QAction::triggered, this, &MainWindow::SaveLogDialog);
connect(clear_menu, &QAction::triggered, this, &MainWindow::Clear);


QVBoxLayout* verticalLayout = new QVBoxLayout(central);
verticalLayout->setContentsMargins(0, 0, 0, 0);
verticalLayout->setSpacing(0);

commandIn = new QTextEdit();
commandIn->setReadOnly(true);

commandEntry = new QLineEdit();

connect(commandEntry, &QLineEdit::returnPressed, this, &MainWindow::SubmitCommand);

verticalLayout->addWidget(commandIn);
verticalLayout->addWidget(commandEntry);


this->setStyleSheet(QString(
"* {"
"color: #eef3ef"
"}"
"QMainWindow, QTextEdit, QMenuBar {"
"background-color: #1a1c19;"
"accent-color: #1a1c19;"
"outline: #1a1c19;"
"border: #5a5c59;"
"}"
"QTextEdit {"
"background-color: #4a4c49;"
"}"
"QLineEdit {"
"background-color: #2a2c29;"
"}"
));

this->SetupSocketConnection();
}

MainWindow::~MainWindow() {}

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

MainWindow mainWindow;
mainWindow.show();
return app.exec();
}
45 changes: 45 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <QMainWindow>

#include <QTcpSocket>
#include <QTextEdit>
#include <QMenuBar>
#include <QLineEdit>
#include <QFileDialog>
#include <QVBoxLayout>

class MainWindow : public QMainWindow {
public:
MainWindow();
~MainWindow();

void AddToCommandIn(QString to_add);

void SetupSocketConnection();

void SockConnected();
void SockDisconnected();
void BytesWritten(qint64 bytes);
void ReadReady();
void SocketStateChanged(QTcpSocket::SocketState state);

void SubmitCommand();

void SaveLog();
void SaveLogDialog();
void Clear();

QTextEdit *commandIn;
QLineEdit *commandEntry;

QTcpSocket* consoleSock = nullptr;
QThread* socket_connection_thread;

QFileDialog* save_file_dialog;

QMenuBar* menu_bar;
QMenu* file_menu;
QAction* save_menu;
QAction* clear_menu;
};
17 changes: 17 additions & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local projectName = "dslConsole"

add_rules("mode.release", "mode.debug")

add_requires("qt6widgets", "qt6network")

target(projectName)
set_languages("cxxlatest")
set_exceptions("cxx")

add_includedirs("./src")

add_files("./src/*.cpp")

add_packages("qt6widgets", "qt6network")

add_cxxflags("-Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -permissive- -Zc:__cplusplus -Zc:externConstexpr -utf-8 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458")

0 comments on commit 5f34135

Please sign in to comment.