aboutsummaryrefslogtreecommitdiff
path: root/libs/game_bethesda/src/games/ttw/gamefalloutttw.cpp
blob: 7ba105bed745579cfbc8c9e4604a9e6a8e1438ba (plain)
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
#include "gamefalloutttw.h"

#include "falloutttwbsainvalidation.h"
#include "falloutttwdataarchives.h"
#include "falloutttwmoddatachecker.h"
#include "falloutttwmoddatacontent.h"
#include "falloutttwsavegame.h"
#include "falloutttwscriptextender.h"

#include "executableinfo.h"
#include "pluginsetting.h"
#include "versioninfo.h"
#include <gamebryogameplugins.h>
#include <gamebryolocalsavegames.h>
#include <gamebryosavegameinfo.h>
#include <gamebryounmanagedmods.h>

#ifndef _WIN32
#include "gamedetection.h"
#endif

#include <QCoreApplication>
#include <QDir>
#include <QFileInfo>
#include <QList>
#include <QObject>
#include <QString>
#include <QStringList>

#include <memory>

using namespace MOBase;

GameFalloutTTW::GameFalloutTTW() {}

bool GameFalloutTTW::init(IOrganizer* moInfo)
{
  if (!GameGamebryo::init(moInfo)) {
    return false;
  }

  auto dataArchives = std::make_shared<FalloutTTWDataArchives>(this);
  registerFeature(std::make_shared<FalloutTTWScriptExtender>(this));
  registerFeature(dataArchives);
  registerFeature(
      std::make_shared<FalloutTTWBSAInvalidation>(dataArchives.get(), this));
  registerFeature(std::make_shared<GamebryoSaveGameInfo>(this));
  registerFeature(std::make_shared<GamebryoLocalSavegames>(this, "Fallout.ini"));
  registerFeature(std::make_shared<FalloutTTWModDataChecker>(this));
  registerFeature(
      std::make_shared<FalloutTTWModDataContent>(m_Organizer->gameFeatures()));
  registerFeature(std::make_shared<GamebryoGamePlugins>(moInfo));
  registerFeature(std::make_shared<GamebryoUnmangedMods>(this));

  return true;
}

void GameFalloutTTW::setVariant(QString variant)
{
  m_GameVariant = variant;
}

void GameFalloutTTW::checkVariants()
{
  QFileInfo gog_dll(m_GamePath + "\\Galaxy.dll");
  QFileInfo epic_dll(m_GamePath + "\\EOSSDK-Win32-Shipping.dll");
  if (gog_dll.exists())
    setVariant("GOG");
  else if (epic_dll.exists())
    setVariant("Epic Games");
  else
    setVariant("Steam");
}

QDir GameFalloutTTW::documentsDirectory() const
{
  return m_MyGamesPath;
}

QString GameFalloutTTW::identifyGamePath() const
{
  QString result;
#ifdef _WIN32
  QString path = "Software\\Bethesda Softworks\\FalloutNV";
  result       = findInRegistry(HKEY_LOCAL_MACHINE, path.toStdWString().c_str(),
                                L"Installed Path");
#else
  // TTW uses FalloutNV as its base game, so look for Fallout New Vegas
  {
    const GameScanResult scanResult = detectAllGames();
    for (const DetectedGame& game : scanResult.games) {
      if (game.name.contains("Fallout", Qt::CaseInsensitive) &&
          game.name.contains("Vegas", Qt::CaseInsensitive)) {
        if (looksValid(QDir(game.install_path))) {
          result = game.install_path;
          break;
        }
      }
    }
  }
#endif
  // EPIC Game Store
  if (result.isEmpty()) {
    /**
     * Basegame: 5daeb974a22a435988892319b3a4f476
     * Dead Money: b290229eb58045cbab9501640f3278f3
     * Honest Hearts: 562d4a2c1b3147b089a7c453e3ddbcbe
     * Old World Blues: c8dae1ab0570475a8b38a9041e614840
     * Lonesome Road: 4fa3d8d9b2cb4714a19a38d1a598be8f
     * Gun Runners' Arsenal: 7dcfb9cd9d134728b2646466c34c7b3b
     * Courier's Stash: ee9a44b4530942499ef1c8c390731fce
     */
    result = parseEpicGamesLocation({"5daeb974a22a435988892319b3a4f476"});
    if (QFileInfo(result).isDir()) {
      QDir startPath = QDir(result);
      auto subDirs   = startPath.entryList({"Fallout New Vegas*"},
                                           QDir::Dirs | QDir::NoDotAndDotDot);
      if (!subDirs.isEmpty())
        result += "/" + subDirs.first();
    }
  }
  return result;
}

void GameFalloutTTW::setGamePath(const QString& path)
{
  m_GamePath = path;
  checkVariants();
  m_MyGamesPath = determineMyGamesPath(gameDirectoryName(), !m_GamePath.isEmpty());
}

QDir GameFalloutTTW::savesDirectory() const
{
  return QDir(m_MyGamesPath + "/Saves");
}

QString GameFalloutTTW::myGamesPath() const
{
  return m_MyGamesPath;
}

bool GameFalloutTTW::isInstalled() const
{
  return !m_GamePath.isEmpty();
}

QString GameFalloutTTW::gameName() const
{
  return "TTW";
}

QString GameFalloutTTW::displayGameName() const
{
  return "Tale of Two Wastelands";
}

QString GameFalloutTTW::gameDirectoryName() const
{
  if (selectedVariant() == "Epic Games")
    return "FalloutNV_Epic";
  else
    return "FalloutNV";
}

void GameFalloutTTW::detectGame()
{
  m_GamePath = identifyGamePath();
  checkVariants();
  m_MyGamesPath = determineMyGamesPath(gameDirectoryName(), !m_GamePath.isEmpty());
}

QList<ExecutableInfo> GameFalloutTTW::executables() const
{
  ExecutableInfo game("Tale of Two Wastelands", findInGameFolder(binaryName()));
  ExecutableInfo launcher("Fallout Launcher", findInGameFolder(getLauncherName()));
  QList<ExecutableInfo> extraExecutables =
      QList<ExecutableInfo>() << ExecutableInfo("GECK", findInGameFolder("geck.exe"))
                              << ExecutableInfo("LOOT", QFileInfo(getLootPath()))
                                     .withArgument("--game=\"FalloutNV\"");
  if (selectedVariant() != "Epic Games") {
    extraExecutables.prepend(ExecutableInfo(
        "NVSE", findInGameFolder(m_Organizer->gameFeatures()
                                     ->gameFeature<MOBase::ScriptExtender>()
                                     ->loaderName())));
  } else {
    game.withArgument("-EpicPortal");
    launcher.withArgument("-EpicPortal");
  }
  QList<ExecutableInfo> executables = {game, launcher};
  executables += extraExecutables;
  return executables;
}

QList<ExecutableForcedLoadSetting> GameFalloutTTW::executableForcedLoads() const
{
  return QList<ExecutableForcedLoadSetting>();
}

QString GameFalloutTTW::name() const
{
  return "Fallout TTW Support Plugin";
}

QString GameFalloutTTW::localizedName() const
{
  return tr("Fallout TTW Support Plugin");
}

QString GameFalloutTTW::author() const
{
  return "SuperSandro2000 & MO2 Team";
}

QString GameFalloutTTW::description() const
{
  return tr("Adds support for the game Fallout TTW");
}

MOBase::VersionInfo GameFalloutTTW::version() const
{
  return VersionInfo(1, 6, 0, VersionInfo::RELEASE_FINAL);
}

QList<PluginSetting> GameFalloutTTW::settings() const
{
  return QList<PluginSetting>()
         << PluginSetting("enable_loot_sorting",
                          tr("Enables LOOT sorting for Tale of Two Wastelands"),
                          true);
}

void GameFalloutTTW::initializeProfile(const QDir& path, ProfileSettings settings) const
{
  if (settings.testFlag(IPluginGame::MODS)) {
    copyToProfile(localAppFolder() + "/" + gameDirectoryName(), path, "plugins.txt");
  }

  if (settings.testFlag(IPluginGame::CONFIGURATION)) {
    if (settings.testFlag(IPluginGame::PREFER_DEFAULTS) ||
        !QFileInfo(myGamesPath() + "/Fallout.ini").exists()) {
      copyToProfile(gameDirectory().absolutePath(), path, "Fallout_default.ini",
                    "Fallout.ini");
    } else {
      copyToProfile(myGamesPath(), path, "Fallout.ini");
    }

    copyToProfile(myGamesPath(), path, "FalloutPrefs.ini");
    copyToProfile(myGamesPath(), path, "FalloutCustom.ini");
    copyToProfile(myGamesPath(), path, "GECKCustom.ini");
    copyToProfile(myGamesPath(), path, "GECKPrefs.ini");
  }
}

QString GameFalloutTTW::savegameExtension() const
{
  return "fos";
}

QString GameFalloutTTW::savegameSEExtension() const
{
  return "nvse";
}

std::shared_ptr<const GamebryoSaveGame>
GameFalloutTTW::makeSaveGame(QString filePath) const
{
  return std::make_shared<const FalloutTTWSaveGame>(filePath, this);
}

QString GameFalloutTTW::steamAPPId() const
{
  if (selectedVariant() == "Steam") {
    if (m_GamePath.endsWith("enplczru")) {
      return "22490";
    } else {
      return "22380";
    }
  }
  return QString();
}

QStringList GameFalloutTTW::primaryPlugins() const
{
  return {"falloutnv.esm",     "deadmoney.esm",           "honesthearts.esm",
          "oldworldblues.esm", "lonesomeroad.esm",        "gunrunnersarsenal.esm",
          "fallout3.esm",      "anchorage.esm",           "thepitt.esm",
          "brokensteel.esm",   "pointlookout.esm",        "zeta.esm",
          "caravanpack.esm",   "classicpack.esm",         "mercenarypack.esm",
          "tribalpack.esm",    "taleoftwowastelands.esm", "YUPTTW.esm"};
}

QStringList GameFalloutTTW::gameVariants() const
{
  return {"Steam", "GOG", "Epic Games"};
}

QString GameFalloutTTW::binaryName() const
{
  return "FalloutNV.exe";
}

QString GameFalloutTTW::gameShortName() const
{
  return "TTW";
}

QStringList GameFalloutTTW::primarySources() const
{
  return {"FalloutNV"};
}

QStringList GameFalloutTTW::validShortNames() const
{
  return {"FalloutNV", "Fallout3"};
}

QString GameFalloutTTW::gameNexusName() const
{
  return "";
}

QStringList GameFalloutTTW::iniFiles() const
{
  return {"Fallout.ini", "FalloutPrefs.ini", "FalloutCustom.ini", "GECKCustom.ini",
          "GECKPrefs.ini"};
}

QStringList GameFalloutTTW::DLCPlugins() const
{
  return {};
}

MOBase::IPluginGame::SortMechanism GameFalloutTTW::sortMechanism() const
{
  if (m_Organizer->pluginSetting(name(), "enable_loot_sorting").toBool())
    return IPluginGame::SortMechanism::LOOT;
  return IPluginGame::SortMechanism::NONE;
}

QString GameFalloutTTW::lootGameName() const
{
  return "FalloutNV";
}

int GameFalloutTTW::nexusModOrganizerID() const
{
  return 0;
}

int GameFalloutTTW::nexusGameID() const
{
  return 0;
}

QDir GameFalloutTTW::gameDirectory() const
{
  return QDir(m_GamePath);
}

QString GameFalloutTTW::getLauncherName() const
{
  return "FalloutNVLauncher.exe";
}

MappingType GameFalloutTTW::mappings() const
{
  MappingType result;

  for (const QString& profileFile : {"plugins.txt", "loadorder.txt"}) {
    result.push_back({m_Organizer->profilePath() + "/" + profileFile,
                      localAppFolder() + "/FalloutNV/" + profileFile, false});
    if (selectedVariant() == "Epic Games") {
      result.push_back(
          {m_Organizer->profilePath() + "/" + profileFile,
           localAppFolder() + "/" + gameDirectoryName() + "/" + profileFile, false});
    }
  }
  return result;
}