1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-20 11:47:46 +00:00

Communicate to nativelauncher through IPC

This makes Dalamud launching under Wine scenarios (such as on Linux or
macOS) much more stable, as it's no longer sifting through stdout
output.

This requires nativelauncher >=v1.1.0, and the update functionality will
 come in a later commit.
This commit is contained in:
Joshua Goins 2022-04-06 13:18:40 -04:00
parent d39aa8d5aa
commit dbbcb67134

View file

@ -18,6 +18,7 @@
#include <QStandardPaths>
#include <QRegularExpressionMatch>
#include <algorithm>
#include <QTcpServer>
#include "launchercore.h"
#include "sapphirelauncher.h"
@ -63,6 +64,7 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
if(profile.dalamud.enabled) {
arguments.push_back(dataDir + "/NativeLauncher.exe");
arguments.push_back("5248"); // TODO: make port configurable/random
}
// now for the actual game...
@ -112,20 +114,33 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
gameProcess->setProcessEnvironment(env);
gameProcess->setProcessChannelMode(QProcess::MergedChannels);
gameProcess->setProcessChannelMode(QProcess::ForwardedChannels);
const QString argFormat = profile.encryptArguments ? " /%1 =%2" : " %1=%2";
QString argJoined;
for(const auto& arg : gameArgs) {
argJoined += argFormat.arg(arg.key, arg.value);
}
if(profile.encryptArguments) {
arguments.append(encryptGameArg(argJoined));
} else {
arguments.append(argJoined);
}
if(profile.dalamud.enabled) {
connect(gameProcess, &QProcess::readyReadStandardOutput, [this, gameProcess, profile] {
QString output = gameProcess->readAllStandardOutput();
auto socket = new QTcpServer();
connect(socket, &QTcpServer::newConnection, [this, profile, socket] {
auto connection = socket->nextPendingConnection();
connect(connection, &QTcpSocket::readyRead, [this, connection, profile, socket] {
QString output = connection->readAll();
bool success;
int dec = output.toInt(&success, 10);
if(!success)
return;
qDebug() << "got output: " << output;
qDebug() << "Now launching dalamud...";
int exitCode = output.toInt(&success, 10);
if(exitCode != -1 && success) {
QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
dataDir = "Z:" + dataDir.replace('/', '\\');
@ -155,28 +170,17 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
auto list = dalamudProcess->processEnvironment().toStringList();
launchExecutable(profile, dalamudProcess, {dataDir + "/Dalamud/" + "Dalamud.Injector.exe", output, argsEncoded});
launchExecutable(profile, dalamudProcess, {dataDir + "/Dalamud/" + "Dalamud.Injector.exe", QString::number(exitCode), argsEncoded});
connection->close();
socket->close();
}
});
}
const QString argFormat = profile.encryptArguments ? " /%1 =%2" : " %1=%2";
QString argJoined;
for(const auto& arg : gameArgs) {
argJoined += argFormat.arg(arg.key, arg.value);
}
if(profile.encryptArguments) {
arguments.append(encryptGameArg(argJoined));
} else {
arguments.append(argJoined);
}
connect(gameProcess, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[=](int exitCode, QProcess::ExitStatus exitStatus){
gameClosed();
});
socket->listen(QHostAddress::Any, 5248);
}
launchGameExecutable(profile, gameProcess, arguments);
successfulLaunch();