implemented crc.

open issues:
  - HTTPS is not working yet. probably caused by OpenSSL v1.0.2 not being linked?
  - GiantsMain.exe process is being blocked by something ("file is being used by another process")
master
Tibor 10 months ago
parent 3e95ac6265
commit b84004ef54
  1. 74
      giantswdefimporter.cpp
  2. 5
      giantswdefimporter.h
  3. BIN
      lib/zlibstat.lib
  4. 14
      mainwindow.cpp
  5. 8
      wdef-importer.pro

@ -11,6 +11,8 @@
#include <vector>
#include <string>
#include "zlib.h"
GiantsWdefImporter::GiantsWdefImporter()
{
@ -93,15 +95,33 @@ void GiantsWdefImporter::revertFile(const std::filesystem::path& path)
fs::copy(dest, path, fs::copy_options::overwrite_existing);
}
void GiantsWdefImporter::giantsFinished(const std::filesystem::path& giantsMainPath, const std::filesystem::path& wdefsPath, QPushButton* btn)
{
revertFile(giantsMainPath);
revertFile(wdefsPath);
QMessageBox::information(nullptr, "wdefs", "Giants has been reverted to original state.");
btn->setText("Play");
btn->setEnabled(true);
}
void GiantsWdefImporter::setParent(QObject* parent)
{
_parent = parent;
}
int GiantsWdefImporter::crc(const QByteArray &bytes)
{
uLong prev { crc32(0L, reinterpret_cast<const unsigned char*>(bytes.data()), bytes.length()) };
return static_cast<int>(prev);
}
QByteArray GiantsWdefImporter::newExeBytes(const QByteArray& wdefsBytes, const std::filesystem::path& giantsMainPath)
{
// Look for checksum in exe file
// subject to change
QByteArray checksum { "\x78\x05\x44\xb6" }; // should be at offset 0x152bff in giantsmain.exe
QFile exeFile { QString::fromStdString(giantsMainPath.string()) };
@ -123,10 +143,14 @@ QByteArray GiantsWdefImporter::newExeBytes(const QByteArray& wdefsBytes, const s
exit(-1);
}
// TODO go on here: https://git.hipstercat.fr/hipstercat/giants-wdefs-importer-gui/src/branch/master/main.py#L162
Q_UNUSED(wdefsBytes);
int wdefsCrc { crc(wdefsBytes) };
QByteArray wdefsCrcBytes;
wdefsCrcBytes.setNum(wdefsCrc);
return QByteArray();
content.replace(index, checksum.length(), wdefsCrcBytes);
return content;
}
GiantsWdefImporter::StartResult GiantsWdefImporter::startGiantsWithWdefsBytes(QByteArray const& wdefsBytes, fs::path const& wdefsPath, fs::path const& giantsMainPath, QPushButton* button)
@ -164,39 +188,37 @@ GiantsWdefImporter::StartResult GiantsWdefImporter::startGiantsWithWdefsBytes(QB
return StartResult::FAILURE;
}
auto giantsFinished = [&]() {
revertFile(giantsMainPath);
revertFile(wdefsPath);
QMessageBox::information(nullptr, "wdefs", "Giants has been reverted to original state.");
button->setText("Play");
button->setEnabled(true);
};
_giantsMainProcess = new QProcess(_parent);
QProcess process(_parent);
QObject::connect(&process, &QProcess::stateChanged, [&](QProcess::ProcessState state) {
QObject::connect(_giantsMainProcess, &QProcess::stateChanged, [&](QProcess::ProcessState state) {
qDebug() << "[STATE] " << state;
switch (state) {
case QProcess::ProcessState::Starting:
button->setText("Starting");
break;
case QProcess::ProcessState::Running:
qDebug() << "Running";
button->setText("Game started");
button->setText("Running.");
break;
default:
button->setText("Game not running");
button->setText("Not running.");
break;
}
});
QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[&]() { giantsFinished(); }
);
QObject::connect(&process, &QProcess::errorOccurred,
[&]() { giantsFinished(); }
);
QObject::connect(_giantsMainProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [&]() {
qDebug() << "[FINISHED]";
giantsFinished(giantsMainPath, wdefsPath, button);
});
QObject::connect(_giantsMainProcess, &QProcess::errorOccurred, [&]() {
qDebug() << "[ERROR] " << _giantsMainProcess->errorString();
giantsFinished(giantsMainPath, wdefsPath, button);
});
_giantsMainProcess->setWorkingDirectory(QString::fromStdString(giantsMainPath.parent_path().string()));
_giantsMainProcess->start(QString::fromStdString(giantsMainPath.string()), { "-launcher" });
process.setWorkingDirectory(QString::fromStdString(giantsMainPath.parent_path().string()));
process.start(QString::fromStdString(giantsMainPath.string()), { "-launcher" });
// temporary
_giantsMainProcess->waitForFinished();
return StartResult::SUCCESS;
}

@ -4,6 +4,7 @@
#include <filesystem>
#include <QByteArray>
#include <QPushButton>
#include <QProcess>
namespace fs = std::filesystem;
@ -24,7 +25,10 @@ public:
void backupFile(fs::path const& path);
void revertFile(fs::path const& path);
void giantsFinished(fs::path const& giantsMainPath, fs::path const& wdefsPath, QPushButton* btn);
void setParent(QObject* parent);
int crc(QByteArray const& bytes);
QByteArray newExeBytes(QByteArray const& wdefsBytes, fs::path const& giantsMainPath);
@ -32,6 +36,7 @@ public:
private:
QObject* _parent { nullptr };
QProcess* _giantsMainProcess { nullptr };
};
#endif // GIANTSWDEFIMPORTER_H

Binary file not shown.

@ -59,7 +59,19 @@ void MainWindow::on_pushButton_clicked()
return;
}
QNetworkRequest request;
QNetworkAccessManager manager(this);
// not completely working yet
if (text.contains("https://")) {
QSslConfiguration sslConfig;
sslConfig.setDefaultConfiguration(QSslConfiguration::defaultConfiguration());
sslConfig.setProtocol(QSsl::TlsV1_2OrLater);
request.setSslConfiguration(sslConfig);
}
request.setUrl(QUrl(text));
QByteArray requestReply {};
QObject::connect(&manager, &QNetworkAccessManager::finished, [&](QNetworkReply* reply) {
@ -73,7 +85,7 @@ void MainWindow::on_pushButton_clicked()
requestReply = reply->readAll();
});
manager.get(QNetworkRequest(QUrl(text)));
manager.get(request);
GiantsWdefImporter::StartResult giantsStartResult = _importer.startGiantsWithWdefsBytes(requestReply, _wdefsPath, _giantsMainPath, ui->pushButton);

@ -32,3 +32,11 @@ DISTFILES += \
icon.ico
RC_ICONS = icon.ico
win32: LIBS += -L$$PWD/lib/ -lzlibstat
INCLUDEPATH += C:/dev/zlib
DEPENDPATH += C:/dev/zlib
win32:!win32-g++: PRE_TARGETDEPS += $$PWD/lib/zlibstat.lib
else:win32-g++: PRE_TARGETDEPS += $$PWD/lib/libzlibstat.a

Loading…
Cancel
Save