mirror of
https://github.com/ModOrganizer2/modorganizer-game_fallout76.git
synced 2026-07-27 14:08:28 -07:00
implemented new plugins.txt format and set correct load order mechanism
This commit is contained in:
+12
-2
@@ -47,8 +47,18 @@ TARGET_LINK_LIBRARIES(${PROJ_NAME}
|
||||
Version
|
||||
game_gamebryo)
|
||||
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES COMPILE_FLAGS /GL)
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/LARGEADDRESSAWARE ${OPTIMIZE_LINK_FLAGS}")
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES LINK_FLAGS "/LARGEADDRESSAWARE")
|
||||
ELSE(MSVC)
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES LINK_FLAGS "-std=c++11")
|
||||
ENDIF(MSVC)
|
||||
|
||||
IF (NOT "${OPTIMIZE_COMPILE_FLAGS}" STREQUAL "")
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES COMPILE_FLAGS_RELWITHDEBINFO ${OPTIMIZE_COMPILE_FLAGS})
|
||||
ENDIF()
|
||||
IF (NOT "${OPTIMIZE_LINK_FLAGS}" STREQUAL "")
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES LINK_FLAGS_RELWITHDEBINFO ${OPTIMIZE_LINK_FLAGS})
|
||||
ENDIF()
|
||||
|
||||
QT5_USE_MODULES(${PROJ_NAME} Widgets)
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
#include "fallout4gameplugins.h"
|
||||
#include <safewritefile.h>
|
||||
#include <report.h>
|
||||
#include <ipluginlist.h>
|
||||
#include <report.h>
|
||||
#include <scopeguard.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QTextCodec>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
using MOBase::IPluginGame;
|
||||
using MOBase::IPluginList;
|
||||
using MOBase::IOrganizer;
|
||||
using MOBase::SafeWriteFile;
|
||||
using MOBase::reportError;
|
||||
|
||||
static const std::set<QString> OFFICIAL_FILES{"fallout4.esm", "dlcrobot.esm",
|
||||
"dlcworkshop01.esm"};
|
||||
|
||||
Fallout4GamePlugins::Fallout4GamePlugins(IOrganizer *organizer)
|
||||
: GamebryoGamePlugins(organizer)
|
||||
{
|
||||
}
|
||||
|
||||
void Fallout4GamePlugins::writePluginList(const IPluginList *pluginList,
|
||||
const QString &filePath) {
|
||||
SafeWriteFile file(filePath);
|
||||
|
||||
QTextCodec *textCodec = localCodec();
|
||||
|
||||
file->resize(0);
|
||||
|
||||
file->write(textCodec->fromUnicode(
|
||||
"# This file was automatically generated by Mod Organizer.\r\n"));
|
||||
|
||||
bool invalidFileNames = false;
|
||||
int writtenCount = 0;
|
||||
|
||||
QStringList plugins = pluginList->pluginNames();
|
||||
std::sort(plugins.begin(), plugins.end(),
|
||||
[pluginList](const QString &lhs, const QString &rhs) {
|
||||
return pluginList->priority(lhs) < pluginList->priority(rhs);
|
||||
});
|
||||
|
||||
for (const QString &pluginName : plugins) {
|
||||
if (pluginList->state(pluginName) == IPluginList::STATE_ACTIVE) {
|
||||
if (!textCodec->canEncode(pluginName)) {
|
||||
invalidFileNames = true;
|
||||
qCritical("invalid plugin name %s", qPrintable(pluginName));
|
||||
} else {
|
||||
file->write("*");
|
||||
file->write(textCodec->fromUnicode(pluginName));
|
||||
}
|
||||
file->write("\r\n");
|
||||
++writtenCount;
|
||||
}
|
||||
}
|
||||
|
||||
if (invalidFileNames) {
|
||||
reportError(QObject::tr("Some of your plugins have invalid names! These "
|
||||
"plugins can not be loaded by the game. Please see "
|
||||
"mo_interface.log for a list of affected plugins "
|
||||
"and rename them."));
|
||||
}
|
||||
|
||||
if (file.commitIfDifferent(m_LastSaveHash[filePath])) {
|
||||
qDebug("%s saved", qPrintable(QDir::toNativeSeparators(filePath)));
|
||||
}
|
||||
}
|
||||
|
||||
bool Fallout4GamePlugins::readPluginList(MOBase::IPluginList *pluginList,
|
||||
const QString &filePath,
|
||||
bool useLoadOrder)
|
||||
{
|
||||
QStringList plugins;
|
||||
|
||||
for (const QString &pluginName : OFFICIAL_FILES) {
|
||||
pluginList->setState(pluginName, IPluginList::STATE_ACTIVE);
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly)) {
|
||||
return false;
|
||||
}
|
||||
ON_BLOCK_EXIT([&]() { file.close(); });
|
||||
|
||||
if (file.size() == 0) {
|
||||
// MO stores at least a header in the file. if it's completely empty the
|
||||
// file is broken
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList loadOrder = organizer()->managedGame()->primaryPlugins();
|
||||
while (!file.atEnd()) {
|
||||
QByteArray line = file.readLine();
|
||||
QString pluginName;
|
||||
if ((line.size() > 0) && (line.at(0) != '#')) {
|
||||
pluginName = localCodec()->toUnicode(line.trimmed().constData());
|
||||
}
|
||||
if (pluginName.startsWith('*')) {
|
||||
pluginName.remove(0, 1);
|
||||
}
|
||||
if (pluginName.size() > 0) {
|
||||
pluginList->setState(pluginName, IPluginList::STATE_ACTIVE);
|
||||
plugins.removeAll(pluginName);
|
||||
if (!loadOrder.contains(pluginName, Qt::CaseInsensitive)) {
|
||||
loadOrder.append(pluginName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
// we removed each plugin found in the file, so what's left are inactive mods
|
||||
for (const QString &pluginName : plugins) {
|
||||
pluginList->setState(pluginName, IPluginList::STATE_INACTIVE);
|
||||
}
|
||||
|
||||
if (useLoadOrder) {
|
||||
pluginList->setLoadOrder(loadOrder);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef FALLOUT4GAMEPLUGINS_H
|
||||
#define FALLOUT4GAMEPLUGINS_H
|
||||
|
||||
|
||||
#include <gamebryogameplugins.h>
|
||||
#include <iplugingame.h>
|
||||
#include <imoinfo.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
class Fallout4GamePlugins : public GamebryoGamePlugins
|
||||
{
|
||||
public:
|
||||
Fallout4GamePlugins(MOBase::IOrganizer *organizer);
|
||||
|
||||
protected:
|
||||
virtual void writePluginList(const MOBase::IPluginList *pluginList,
|
||||
const QString &filePath) override;
|
||||
virtual bool readPluginList(MOBase::IPluginList *pluginList,
|
||||
const QString &filePath,
|
||||
bool useLoadOrder) override;
|
||||
|
||||
private:
|
||||
std::map<QString, QByteArray> m_LastSaveHash;
|
||||
};
|
||||
|
||||
#endif // FALLOUT4GAMEPLUGINS_H
|
||||
+11
-4
@@ -3,11 +3,13 @@
|
||||
#include "fallout4dataarchives.h"
|
||||
#include "fallout4scriptextender.h"
|
||||
#include "fallout4savegameinfo.h"
|
||||
#include "fallout4gameplugins.h"
|
||||
|
||||
#include <pluginsetting.h>
|
||||
#include "iplugingame.h"
|
||||
#include <executableinfo.h>
|
||||
#include <gamebryolocalsavegames.h>
|
||||
#include <gamebryogameplugins.h>
|
||||
#include "versioninfo.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -31,10 +33,13 @@ bool GameFallout4::init(IOrganizer *moInfo)
|
||||
if (!GameGamebryo::init(moInfo)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_ScriptExtender = std::shared_ptr<ScriptExtender>(new Fallout4ScriptExtender(this));
|
||||
m_DataArchives = std::shared_ptr<DataArchives>(new Fallout4DataArchives());
|
||||
m_LocalSavegames.reset(new GamebryoLocalSavegames(myGamesPath(), "Fallout4.ini"));
|
||||
m_SaveGameInfo = std::shared_ptr<SaveGameInfo>(new Fallout4SaveGameInfo(this));
|
||||
m_GamePlugins = std::shared_ptr<GamePlugins>(new Fallout4GamePlugins(moInfo));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +76,7 @@ QString GameFallout4::description() const
|
||||
|
||||
MOBase::VersionInfo GameFallout4::version() const
|
||||
{
|
||||
return VersionInfo(0, 2, 0, VersionInfo::RELEASE_BETA);
|
||||
return VersionInfo(0, 3, 0, VersionInfo::RELEASE_BETA);
|
||||
}
|
||||
|
||||
bool GameFallout4::isActive() const
|
||||
@@ -115,7 +120,7 @@ QString GameFallout4::steamAPPId() const
|
||||
|
||||
QStringList GameFallout4::primaryPlugins() const
|
||||
{
|
||||
return { "fallout4.esm" };
|
||||
return { "fallout4.esm", "dlcrobot.esm", "dlcworkshop01.esm" };
|
||||
}
|
||||
|
||||
QStringList GameFallout4::gameVariants() const
|
||||
@@ -138,8 +143,10 @@ QStringList GameFallout4::DLCPlugins() const
|
||||
return {};
|
||||
}
|
||||
|
||||
//what load order mechanism?
|
||||
// virtual LoadOrderMechanism getLoadOrderMechanism() const = 0;
|
||||
IPluginGame::LoadOrderMechanism GameFallout4::loadOrderMechanism() const
|
||||
{
|
||||
return IPluginGame::LoadOrderMechanism::PluginsTxt;
|
||||
}
|
||||
|
||||
int GameFallout4::nexusModOrganizerID() const
|
||||
{
|
||||
|
||||
+1
-2
@@ -31,8 +31,7 @@ public: // IPluginGame interface
|
||||
virtual QString gameShortName() const override;
|
||||
virtual QStringList iniFiles() const override;
|
||||
virtual QStringList DLCPlugins() const override;
|
||||
//what load order mechanism?
|
||||
// virtual LoadOrderMechanism getLoadOrderMechanism() const = 0;
|
||||
virtual LoadOrderMechanism loadOrderMechanism() const override;
|
||||
virtual int nexusModOrganizerID() const override;
|
||||
virtual int nexusGameID() const override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user