From d417229e6bbaaf393d9172b3c46ee36d285f2196 Mon Sep 17 00:00:00 2001 From: TanninOne Date: Mon, 28 Dec 2015 13:54:16 +0100 Subject: [PATCH] executables installed as mods are now run through a proxy (not working yet) --- src/organizercore.cpp | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 6a8e148f..2caf0241 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -997,7 +997,31 @@ HANDLE OrganizerCore::spawnBinaryDirect(const QFileInfo &binary, const QString & // TODO: should also pass arguments if (m_AboutToRun(binary.absoluteFilePath())) { m_USVFS.updateMapping(fileMapping()); - return startBinary(binary, arguments, currentDirectory, true); + QString modsPath(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::modsPath())); + + QString binPath = binary.absoluteFilePath(); + + if (binPath.startsWith(modsPath, Qt::CaseInsensitive)) { + // binary was installed as a MO mod. Need to start it through a (hooked) + // proxy to ensure pathes are correct + + QString cwdPath = currentDirectory.absolutePath(); + + int binOffset = binPath.indexOf('/', modsPath.length() + 1); + int cwdOffset = cwdPath.indexOf('/', cwdPath.length() + 1); + QString binPath = m_GamePlugin->dataDirectory().absolutePath() + "/" + binPath.mid(binOffset); + QString cwd = m_GamePlugin->dataDirectory().absolutePath() + "/" + cwdPath.mid(cwdOffset); + QString cmdline = QString("launch \"%1\" \"%2\" %3") + .arg(QDir::toNativeSeparators(cwd), + QDir::toNativeSeparators(binPath), + arguments); + + return startBinary(QFileInfo(QCoreApplication::applicationDirPath() + "/helper.exe"), + cmdline, + QCoreApplication::applicationDirPath(), true); + } else { + return startBinary(binary, arguments, currentDirectory, true); + } } else { qDebug("start of \"%s\" canceled by plugin", qPrintable(binary.absoluteFilePath())); return INVALID_HANDLE_VALUE; @@ -1576,7 +1600,7 @@ std::vector OrganizerCore::fileMapping() int overwriteId = m_DirectoryStructure->getOriginByName(L"Overwrite").getID(); - IPluginGame *game = qApp->property("managed_game").value(); + const IPluginGame *game = qApp->property("managed_game").value(); MappingType result = fileMapping( QDir::toNativeSeparators(game->dataDirectory().absolutePath()), "\\", @@ -1585,11 +1609,12 @@ std::vector OrganizerCore::fileMapping() if (m_CurrentProfile->localSavesEnabled()) { LocalSavegames *localSaves = game->feature(); - if (localSaves != nullptr) { MappingType saveMap = localSaves->mappings(currentProfile()->absolutePath() + "/saves"); result.reserve(result.size() + saveMap.size()); result.insert(result.end(), saveMap.begin(), saveMap.end()); + } else { + qWarning("local save games not supported by this game plugin"); } }