1
Fork 0
mirror of https://github.com/redstrate/Astra.git synced 2025-04-21 20:27:45 +00:00

Don't hardcode FFXIV expansion names

Astra will now dynamically load them from the game itself, making it
much more future-proof for future expansion launches.
This commit is contained in:
Joshua Goins 2022-05-09 15:04:56 -04:00
parent e4a2d6f59d
commit 8c2a79b5cf
4 changed files with 61 additions and 45 deletions

View file

@ -41,13 +41,13 @@ struct ProfileSettings {
// game
int language = 1; // 1 is english, thats all i know
QString gamePath, winePath, winePrefixPath;
QString bootVersion, gameVersion, wineVersion;
QString bootVersion, wineVersion;
int installedMaxExpansion = -1;
QList<QString> expansionVersions;
QVector<QString> gameVersions;
bool enableWatchdog = false;
bool isGameInstalled() const {
return !gameVersion.isEmpty();
return !gameVersions.isEmpty();
}
bool isWineInstalled() const {
@ -175,14 +175,17 @@ public:
QString nativeLauncherVersion;
int defaultProfileIndex = 0;
QVector<QString> expansionNames;
signals:
void settingsChanged();
void successfulLaunch();
void gameClosed();
private:
void readExpansionVersions(ProfileSettings& info, int max);
bool checkIfInPath(QString program);
void readGameData(ProfileSettings& profile);
QString getDefaultGamePath();
QString getDefaultWinePrefixPath();

View file

@ -28,6 +28,8 @@
#include "blowfish.h"
#include "assetupdater.h"
#include "encryptedarg.h"
#include "gamedata.h"
#include "exdparser.h"
#ifdef ENABLE_WATCHDOG
#include "watchdog.h"
@ -86,7 +88,7 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
gameArgs.push_back({"DEV.TestSID", auth.SID});
gameArgs.push_back({"SYS.Region", QString::number(auth.region)});
gameArgs.push_back({"language", QString::number(profile.language)});
gameArgs.push_back({"ver", profile.gameVersion});
gameArgs.push_back({"ver", profile.gameVersions[0]});
if(!auth.lobbyhost.isEmpty()) {
gameArgs.push_back({"DEV.GMServerHost", auth.frontierHost});
@ -151,7 +153,7 @@ void LauncherCore::launchGame(const ProfileSettings& profile, const LoginAuth au
startInfo["AssetDirectory"] = dataDir + "\\DalamudAssets";
startInfo["DefaultPluginDirectory"] = dataDir + "\\devPlugins";
startInfo["DelayInitializeMs"] = 0;
startInfo["GameVersion"] = profile.gameVersion;
startInfo["GameVersion"] = profile.gameVersions[0];
startInfo["Language"] = profile.language;
startInfo["OptOutMbCollection"] = profile.dalamud.optOutOfMbCollection;
@ -496,18 +498,38 @@ void LauncherCore::readWineInfo(ProfileSettings& profile) {
void LauncherCore::readGameVersion() {
for(auto& profile : profileSettings) {
profile.bootVersion = readVersion(profile.gamePath + "/boot/ffxivboot.ver");
profile.gameVersion = readVersion(profile.gamePath + "/game/ffxivgame.ver");
profile.installedMaxExpansion = 0;
for(auto dir : QDir(profile.gamePath + "/game/sqpack/").entryList(QDir::Filter::Dirs)) {
if(dir.contains("ex") && dir.length() == 3 && dir[2].isDigit()) {
const int expacVersion = dir[2].digitValue();
auto sqpackDirectories = QDir(profile.gamePath + "/game/sqpack/").entryList(QDir::Filter::Dirs | QDir::Filter::NoDotAndDotDot);
profile.gameVersions.resize(sqpackDirectories.size());
profile.installedMaxExpansion = std::max(profile.installedMaxExpansion, expacVersion);
for(auto dir : sqpackDirectories) {
if(dir.contains("ex") || dir == "ffxiv") {
int expansion = -1;
// we're going to treat ffxiv as ex0
if(dir == "ffxiv") {
expansion = 0;
profile.gameVersions[0] = readVersion(profile.gamePath + QString("/game/ffxivgame.ver"));
} else {
QString originalName = dir.remove("ex");
bool ok = false;
int convertedInt = originalName.toInt(&ok);
if(ok)
expansion = convertedInt;
profile.gameVersions[convertedInt] = readVersion(QString("%1/game/sqpack/ex%2/ex%2.ver").arg(profile.gamePath, QString::number(expansion)));
}
if(expansion != -1) {
profile.installedMaxExpansion = std::max(profile.installedMaxExpansion, expansion);
}
}
}
readExpansionVersions(profile, profile.installedMaxExpansion);
if(profile.installedMaxExpansion >= 0)
readGameData(profile);
}
}
@ -658,13 +680,6 @@ void LauncherCore::addUpdateButtons(const ProfileSettings& settings, QMessageBox
messageBox.addButton(QMessageBox::StandardButton::Ok);
}
void LauncherCore::readExpansionVersions(ProfileSettings& info, int max) {
info.expansionVersions.clear();
for(int i = 0; i < max; i++)
info.expansionVersions.push_back(readVersion(QString("%1/game/sqpack/ex%2/ex%2.ver").arg(info.gamePath, QString::number(i + 1))));
}
bool LauncherCore::checkIfInPath(const QString program) {
// TODO: also check /usr/local/bin, /bin32 etc (basically read $PATH)
const QString directory = "/usr/bin";
@ -706,3 +721,16 @@ void LauncherCore::addRegistryKey(const ProfileSettings& settings,
process->setProcessEnvironment(QProcessEnvironment::systemEnvironment());
launchExecutable(settings, process, {"reg", "add", key, "/v", value, "/d", data, "/f" }, false, false);
}
void LauncherCore::readGameData(ProfileSettings& profile) {
GameData data(profile.gamePath.toStdString() + "/game/sqpack");
if(auto exh = data.readExcelSheet("ExVersion")) {
auto path = getEXDFilename(*exh, "exversion", "en", exh->pages[0]);
auto exd = readEXD(*exh, *data.extractFile("exd/" + path), exh->pages[0]);
for(auto row : exd.rows) {
expansionNames.push_back(row.data[0].data.c_str());
}
}
}

View file

@ -485,29 +485,14 @@ void SettingsWindow::reloadControls() {
expacString += "Boot";
expacString += QString(" (%1)\n").arg(profile.bootVersion);
if(profile.installedMaxExpansion >= 0) {
expacString += "A Realm Reborn";
expacString += QString(" (%1)\n").arg(profile.gameVersion);
}
for(int i = 0; i < profile.gameVersions.size(); i++) {
QString expansionName = "Unknown Expansion";
if(i < core.expansionNames.size()) {
expansionName = core.expansionNames[i];
}
if(profile.installedMaxExpansion >= 1) {
expacString += "Heavensward";
expacString += QString(" (%1)\n").arg(profile.expansionVersions[0]);
}
if(profile.installedMaxExpansion >= 2) {
expacString += "Stormblood";
expacString += QString(" (%1)\n").arg(profile.expansionVersions[1]);
}
if(profile.installedMaxExpansion >= 3) {
expacString += "Shadowbringers";
expacString += QString(" (%1)\n").arg(profile.expansionVersions[2]);
}
if(profile.installedMaxExpansion >= 4) {
expacString += "Endwalker";
expacString += QString(" (%1)\n").arg(profile.expansionVersions[3]);
expacString += expansionName;
expacString += QString(" (%1)\n").arg(profile.gameVersions[i]);
}
expansionVersionLabel->setText(expacString);

View file

@ -161,7 +161,7 @@ void SquareLauncher::registerSession(const LoginInformation& info) {
QUrl url;
url.setScheme("https");
url.setHost("patch-gamever.ffxiv.com");
url.setPath(QString("/http/win32/ffxivneo_release_game/%1/%2").arg(info.settings->gameVersion, SID));
url.setPath(QString("/http/win32/ffxivneo_release_game/%1/%2").arg(info.settings->gameVersions[0], SID));
auto request = QNetworkRequest(url);
window.setSSL(request);
@ -171,8 +171,8 @@ void SquareLauncher::registerSession(const LoginInformation& info) {
QString report = info.settings->bootVersion + "=" + getBootHash(info);
for(int i = 0; i < info.settings->installedMaxExpansion; i++)
report += QString("\nex%1\t%2").arg(QString::number(i + 1), info.settings->expansionVersions[i]);
for(int i = 1; i < info.settings->installedMaxExpansion; i++)
report += QString("\nex%1\t%2").arg(QString::number(i), info.settings->gameVersions[i]);
auto reply = window.mgr->post(request, report.toUtf8());
connect(reply, &QNetworkReply::finished, [=] {