1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
#include "gamestarfield.h"
#include "ipluginlist.h"
#include "starfieldbsainvalidation.h"
#include "starfielddataarchives.h"
#include "starfieldgameplugins.h"
#include "starfieldmoddatachecker.h"
#include "starfieldmoddatacontent.h"
#include "starfieldsavegame.h"
#include "starfieldscriptextender.h"
#include "starfieldunmanagedmods.h"
#include "versioninfo.h"
#include <executableinfo.h>
#include <gamebryolocalsavegames.h>
#include <gamebryosavegameinfo.h>
#include <pluginsetting.h>
#include <QCoreApplication>
#include <QDesktopServices>
#include <QDir>
#include <QFileInfo>
#include <QList>
#include <QRegularExpression>
#include <QObject>
#include <QString>
#include <QStringList>
#include <memory>
#include "utility.h"
using namespace MOBase;
const unsigned int GameStarfield::PROBLEM_ESP;
const unsigned int GameStarfield::PROBLEM_TEST_FILE;
GameStarfield::GameStarfield() {}
bool GameStarfield::init(IOrganizer* moInfo)
{
if (!GameGamebryo::init(moInfo)) {
return false;
}
auto dataArchives = std::make_shared<StarfieldDataArchives>(this);
registerFeature(std::make_shared<StarfieldScriptExtender>(this));
registerFeature(dataArchives);
registerFeature(
std::make_shared<GamebryoLocalSavegames>(this, "StarfieldCustom.ini"));
registerFeature(std::make_shared<StarfieldModDataChecker>(this));
registerFeature(
std::make_shared<StarfieldModDataContent>(m_Organizer->gameFeatures()));
registerFeature(std::make_shared<GamebryoSaveGameInfo>(this));
registerFeature(std::make_shared<StarfieldGamePlugins>(moInfo));
registerFeature(std::make_shared<StarfieldUnmanagedMods>(this, localAppFolder()));
registerFeature(std::make_shared<StarfieldBSAInvalidation>(dataArchives.get(), this));
return true;
}
QString GameStarfield::gameName() const
{
return "Starfield";
}
void GameStarfield::detectGame()
{
m_GamePath = identifyGamePath();
m_MyGamesPath = determineMyGamesPath("Starfield", !m_GamePath.isEmpty());
}
QString GameStarfield::identifyGamePath() const
{
return parseSteamLocation(steamAPPId(), gameName());
}
QDir GameStarfield::dataDirectory() const
{
#ifdef _WIN32
// On Windows, USVFS hooks both the game-side Data folder (where SFSE
// loads plugins from) and My Games\Starfield\Data (where loose content
// lives) transparently, so MO2 can report the My Games path as primary.
QDir dataDir = documentsDirectory().absoluteFilePath("Data");
if (!dataDir.exists())
dataDir.mkdir(dataDir.path());
return documentsDirectory().absoluteFilePath("Data");
#else
// On Linux we have a single FUSE mount, so the primary dataDirectory
// MUST be the game-install Data folder — that's where SFSE looks for
// plugins. If the mount lived under My Games/Starfield/Data, the
// base game Data folder would only see dangling symlinks and SFSE
// plugins would silently fail to load. See issue #56.
return gameDirectory().absoluteFilePath("Data");
#endif
}
QMap<QString, QDir> GameStarfield::secondaryDataDirectories() const
{
QMap<QString, QDir> directories;
#ifdef _WIN32
directories.insert("game_data", gameDirectory().absoluteFilePath("Data"));
#else
// Primary is now gameDirectory/Data; My Games/Starfield/Data still
// needs to exist so the launcher and loose-file content work. Get it
// populated via the secondary-mapping symlink path.
directories.insert("documents_data",
documentsDirectory().absoluteFilePath("Data"));
#endif
return directories;
}
QList<ExecutableInfo> GameStarfield::executables() const
{
return QList<ExecutableInfo>()
<< ExecutableInfo("SFSE",
findInGameFolder(m_Organizer->gameFeatures()
->gameFeature<MOBase::ScriptExtender>()
->loaderName()))
<< ExecutableInfo("Starfield", findInGameFolder(binaryName()))
<< ExecutableInfo("Creation Kit", findInGameFolder("CreationKit.exe"))
.withSteamAppId("2722710")
<< ExecutableInfo("LOOT", QFileInfo(getLootPath()))
.withArgument("--game=\"Starfield\"");
}
QList<ExecutableForcedLoadSetting> GameStarfield::executableForcedLoads() const
{
return QList<ExecutableForcedLoadSetting>();
}
QString GameStarfield::name() const
{
return "Starfield Support Plugin";
}
QString GameStarfield::localizedName() const
{
return tr("Starfield Support Plugin");
}
QString GameStarfield::author() const
{
return "Silarn";
}
QString GameStarfield::description() const
{
return tr("Adds support for the game Starfield.");
}
MOBase::VersionInfo GameStarfield::version() const
{
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
}
QList<PluginSetting> GameStarfield::settings() const
{
return QList<PluginSetting>()
<< PluginSetting(
"enable_esp_warning",
tr("Show a warning when ESP plugins are enabled in the load order."),
true)
<< PluginSetting("enable_management_warnings",
tr("Show a warning when plugins.txt management is invalid."),
true);
}
MappingType GameStarfield::mappings() const
{
MappingType result;
if (testFilePlugins().isEmpty()) {
for (const QString& profileFile : {"plugins.txt", "loadorder.txt"}) {
result.push_back({m_Organizer->profilePath() + "/" + profileFile,
localAppFolder() + "/" + gameShortName() + "/" + profileFile,
false});
}
}
return result;
}
void GameStarfield::initializeProfile(const QDir& path, ProfileSettings settings) const
{
if (settings.testFlag(IPluginGame::MODS)) {
copyToProfile(localAppFolder() + "/Starfield", path, "plugins.txt");
}
if (settings.testFlag(IPluginGame::CONFIGURATION)) {
copyToProfile(myGamesPath(), path, "StarfieldPrefs.ini");
copyToProfile(myGamesPath(), path, "StarfieldCustom.ini");
}
}
QString GameStarfield::savegameExtension() const
{
return "sfs";
}
QString GameStarfield::savegameSEExtension() const
{
return "sfse";
}
std::shared_ptr<const GamebryoSaveGame>
GameStarfield::makeSaveGame(QString filePath) const
{
return std::make_shared<const StarfieldSaveGame>(filePath, this);
}
QString GameStarfield::steamAPPId() const
{
return "1716740";
}
QStringList GameStarfield::testFilePlugins() const
{
QStringList plugins;
if (m_Organizer != nullptr && m_Organizer->profile() != nullptr) {
QString customIni(
m_Organizer->profile()->absoluteIniFilePath("StarfieldCustom.ini"));
if (QFile(customIni).exists()) {
for (int i = 1; i <= 10; ++i) {
QString setting("sTestFile");
setting += std::to_string(i);
QString plugin = GameGamebryo::readIniValue(customIni, "General", setting, "");
if (!plugin.isEmpty() && !plugins.contains(plugin, Qt::CaseInsensitive)) {
plugins.append(plugin);
}
}
}
}
return plugins;
}
QStringList GameStarfield::primaryPlugins() const
{
QStringList plugins = {"Starfield.esm", "Constellation.esm", "OldMars.esm",
"ShatteredSpace.esm", "SFBGS00D.esm", "SFBGS050.esm",
"SFBGS003.esm", "SFBGS004.esm", "SFBGS006.esm",
"SFBGS007.esm", "SFBGS008.esm", "SFBGS047.esm"};
for (auto plugin : CCCPlugins()) {
if (!plugins.contains(plugin, Qt::CaseInsensitive)) {
plugins.append(plugin);
}
}
auto testPlugins = testFilePlugins();
if (loadOrderMechanism() == LoadOrderMechanism::None) {
plugins << enabledPlugins();
plugins << testPlugins;
}
plugins.removeDuplicates();
return plugins;
}
QStringList GameStarfield::enabledPlugins() const
{
return {};
}
QStringList GameStarfield::gameVariants() const
{
return {"Regular"};
}
QString GameStarfield::gameShortName() const
{
return "Starfield";
}
QString GameStarfield::gameNexusName() const
{
return "starfield";
}
QStringList GameStarfield::iniFiles() const
{
return {"StarfieldPrefs.ini", "StarfieldCustom.ini"};
}
bool GameStarfield::prepareIni(const QString& exec)
{
return true; // no need to write to Starfield.ini
}
QStringList GameStarfield::DLCPlugins() const
{
return {"Constellation.esm", "ShatteredSpace.esm", "SFBGS050.esm"};
}
QStringList GameStarfield::CCCPlugins() const
{
// While the CCC file appears to be mostly legacy, we need to parse it since the game
// will still read it and there are some compatibility reason to use it for
// force-loading the core game plugins.
QStringList plugins = {};
if (!testFilePresent()) {
QFile myDocsCCCFile(myGamesPath() + "/Starfield.ccc");
QFile gameCCCFile(gameDirectory().absoluteFilePath("Starfield.ccc"));
QFile* file;
if (myDocsCCCFile.exists()) {
file = &myDocsCCCFile;
} else {
file = &gameCCCFile;
}
if (file->open(QIODevice::ReadOnly)) {
if (file->size() > 0) {
while (!file->atEnd()) {
QByteArray line = file->readLine().trimmed();
QString modName;
if ((line.size() > 0) && (line.at(0) != '#')) {
modName = QString::fromUtf8(line.constData());
}
if (modName.size() > 0) {
plugins.append(modName);
}
}
}
}
}
return plugins;
}
QStringList GameStarfield::CCPlugins() const
{
QStringList plugins = {};
std::shared_ptr<StarfieldUnmanagedMods> unmanagedMods =
std::static_pointer_cast<StarfieldUnmanagedMods>(
m_Organizer->gameFeatures()->gameFeature<MOBase::UnmanagedMods>());
// The ContentCatalog.txt appears to be the main repository where Starfiled stores
// info about the installed Creations. We parse this to correctly mark unmanaged mods
// as Creations. The StarfieldUnmanagedMods class handles parsing mod names and files.
if (unmanagedMods.get()) {
auto contentCatalog = unmanagedMods->parseContentCatalog();
for (auto& mod : contentCatalog) {
QStringList pluginFiles = mod.second.files.filter(QRegularExpression(
"\\.es(m|p|l)$", QRegularExpression::CaseInsensitiveOption));
if (!pluginFiles.isEmpty()) {
plugins += pluginFiles;
}
}
}
plugins.removeDuplicates();
return plugins;
}
QString GameStarfield::blueprintPrefix() const
{
return "blueprintships-";
}
IPluginGame::SortMechanism GameStarfield::sortMechanism() const
{
return IPluginGame::SortMechanism::LOOT;
}
IPluginGame::LoadOrderMechanism GameStarfield::loadOrderMechanism() const
{
if (!testFilePresent())
return IPluginGame::LoadOrderMechanism::PluginsTxt;
return IPluginGame::LoadOrderMechanism::None;
}
int GameStarfield::nexusModOrganizerID() const
{
return 0;
}
int GameStarfield::nexusGameID() const
{
return 4187;
}
// Start Diagnose
std::vector<unsigned int> GameStarfield::activeProblems() const
{
std::vector<unsigned int> result;
if (m_Organizer->managedGame() == this) {
if (m_Organizer->pluginSetting(name(), "enable_esp_warning").toBool() &&
activeESP())
result.push_back(PROBLEM_ESP);
if (m_Organizer->pluginSetting(name(), "enable_management_warnings").toBool()) {
if (testFilePresent())
result.push_back(PROBLEM_TEST_FILE);
}
if (hasInvalidBlueprint())
result.push_back(PROBLEM_INVALID_BLUEPRINT);
if (hasUnpairedBlueprint())
result.push_back(PROBLEM_UNPAIRED_BLUEPRINT);
}
return result;
}
bool GameStarfield::activeESP() const
{
m_Active_ESPs.clear();
std::set<QString> enabledPlugins;
QStringList esps = m_Organizer->findFiles("", [](const QString& fileName) -> bool {
return fileName.endsWith(".esp", FileNameComparator::CaseSensitivity);
});
for (const QString& esp : esps) {
QString baseName = QFileInfo(esp).fileName();
if (m_Organizer->pluginList()->state(baseName) == IPluginList::STATE_ACTIVE) {
m_Active_ESPs.insert(baseName);
}
}
if (!m_Active_ESPs.empty())
return true;
return false;
}
bool GameStarfield::testFilePresent() const
{
if (!testFilePlugins().isEmpty())
return true;
return false;
}
bool GameStarfield::hasInvalidBlueprint() const
{
auto plugins = m_Organizer->pluginList()->pluginNames();
for (auto plugin : plugins) {
if (m_Organizer->pluginList()->isBlueprintFlagged(plugin)) {
if (!plugin.startsWith(blueprintPrefix(), Qt::CaseInsensitive) ||
!m_Organizer->pluginList()->hasMasterExtension(plugin))
return true;
} else if (plugin.startsWith(blueprintPrefix(), Qt::CaseInsensitive)) {
return true;
}
}
return false;
}
bool GameStarfield::hasUnpairedBlueprint() const
{
auto plugins = m_Organizer->pluginList()->pluginNames();
for (auto plugin : plugins) {
if (plugin.startsWith(blueprintPrefix(), Qt::CaseInsensitive) &&
m_Organizer->pluginList()->hasMasterExtension(plugin)) {
QString parent = plugin.mid(blueprintPrefix().size(),
plugin.size() - blueprintPrefix().size() - 4);
auto mainPlugin = plugins.filter(QRegularExpression(
"^" + parent + "\\.es(m|p|l)$", QRegularExpression::CaseInsensitiveOption));
if (mainPlugin.isEmpty())
return true;
}
}
return false;
}
QString GameStarfield::shortDescription(unsigned int key) const
{
switch (key) {
case PROBLEM_ESP:
return tr("You have active ESP plugins in Starfield");
case PROBLEM_TEST_FILE:
return tr("sTestFile entries are present");
case PROBLEM_INVALID_BLUEPRINT:
return tr("Invalid blueprint plugins found");
case PROBLEM_UNPAIRED_BLUEPRINT:
return tr("Unpaired blueprint plugins found");
}
return "";
}
QString GameStarfield::fullDescription(unsigned int key) const
{
switch (key) {
case PROBLEM_ESP: {
QString espInfo = SetJoin(m_Active_ESPs, ", ");
return tr("<p>ESP plugins are not ideal for Starfield. In addition to being unable "
"to sort them alongside ESM or master-flagged plugins, certain record "
"references are always kept loaded by the game. This consumes "
"unnecessary resources and limits the game's ability to load what it "
"needs.</p>"
"<p>Ideally, plugins should be saved as ESM files upon release. It can "
"also be released as an ESL plugin, however there are additional "
"concerns with the way light plugins are currently handled and should "
"only be used when absolutely certain about what you're doing.</p>"
"<p>Notably, xEdit does not currently support saving ESP files.</p>"
"<h4>Current ESPs:</h4><p>%1</p>")
.arg(espInfo);
}
case PROBLEM_TEST_FILE: {
return tr("<p>You have plugin managment enabled but you still have sTestFile "
"settings in your StarfieldCustom.ini. These must be removed or the game "
"will not read the plugins.txt file. Management is still disabled.</p>");
}
case PROBLEM_INVALID_BLUEPRINT:
return tr(
"<p>You have a blueprint file that is invalid. Blueprints require the "
"blueprint flag and prefix and must have the ESM extension to be valid.</p>");
case PROBLEM_UNPAIRED_BLUEPRINT:
return tr(
"<p>You have a valid blueprint file that has no paired main plugin. The only "
"way to load blueprint files is by enabling a main plugin with the same base "
"name. This is the part after the prefix and before the extension.</p><p>eg. "
"<strong>BlueprintShips-example.esm</strong> should have a paired main plugin "
"<strong>example.esm</strong></p>");
}
return "";
}
bool GameStarfield::hasGuidedFix(unsigned int key) const
{
return false;
}
void GameStarfield::startGuidedFix(unsigned int key) const {}
|