diff --git a/src/api/bsa.cpp b/src/api/bsa.cpp index 7fd34939..7aea15fd 100644 --- a/src/api/bsa.cpp +++ b/src/api/bsa.cpp @@ -115,9 +115,9 @@ std::map> GetAssetsInBSA( namespace ba2 { struct Header { - std::array typeId; + std::array typeId{}; uint32_t version{0}; - std::array archiveType; + std::array archiveType{}; uint32_t fileCount{0}; uint64_t filePathsOffset{0}; }; @@ -176,7 +176,7 @@ std::map> GetAssetsInBA2FromFilePaths( // The file paths are prefixed by a two-byte length, and not null-terminated. for (size_t i = 0; i < header.fileCount; ++i) { - uint16_t pathLength; + uint16_t pathLength = 0; in.read(reinterpret_cast(&pathLength), sizeof(pathLength)); std::string filePath(pathLength, '\0'); @@ -282,7 +282,7 @@ std::map> GetAssetsInBethesdaArchive( std::ios::eofbit); // Causes ifstream::failure to be thrown if // a problem is encountered. - std::array typeId; + std::array typeId{}; in.read(typeId.data(), typeId.size()); if (typeId == BSA_TYPE_ID) { diff --git a/src/api/bsa_detail.h b/src/api/bsa_detail.h index 271f7d06..56231cb8 100644 --- a/src/api/bsa_detail.h +++ b/src/api/bsa_detail.h @@ -34,7 +34,7 @@ namespace loot::bsa { struct Header { - std::array typeId; // Should always be "BSA\0" + std::array typeId{}; // Should always be "BSA\0" uint32_t version{0}; // 103 (0x67) for TES4, 104 (0x68) for FO3, FONV, TES5, // 105 // (0x69) for TES5SE. diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 812fa6b8..1e8e9550 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -50,73 +50,8 @@ using std::filesystem::u8path; namespace { -using std::string_view_literals::operator""sv; using loot::GameType; -// The Microsoft Store installs Fallout 4 DLCs to directories outside of the -// game's install path. These directories have fixed paths relative to the -// game install path (renaming them causes the game launch to fail, or not -// find the DLC files). -constexpr std::string_view MS_FO4_AUTOMATRON_DATA_PATH = - "../../Fallout 4- Automatron (PC)/Content/Data"sv; -constexpr std::string_view MS_FO4_CONTRAPTIONS_DATA_PATH = - "../../Fallout 4- Contraptions Workshop (PC)/Content/Data"sv; -constexpr std::string_view MS_FO4_FAR_HARBOR_DATA_PATH = - "../../Fallout 4- Far Harbor (PC)/Content/Data"sv; -constexpr std::string_view MS_FO4_TEXTURE_PACK_DATA_PATH = - "../../Fallout 4- High Resolution Texture Pack/Content/Data"sv; -constexpr std::string_view MS_FO4_NUKA_WORLD_DATA_PATH = - "../../Fallout 4- Nuka-World (PC)/Content/Data"sv; -constexpr std::string_view MS_FO4_VAULT_TEC_DATA_PATH = - "../../Fallout 4- Vault-Tec Workshop (PC)/Content/Data"sv; -constexpr std::string_view MS_FO4_WASTELAND_DATA_PATH = - "../../Fallout 4- Wasteland Workshop (PC)/Content/Data"sv; - -bool IsMicrosoftStoreInstall(const GameType gameType, - const std::filesystem::path& gamePath) { - switch (gameType) { - case GameType::tes3: - case GameType::tes4: - case GameType::fo3: - case GameType::fonv: - // tes3, tes4, fo3 and fonv install paths are localised, with the - // appxmanifest.xml file sitting in the parent directory. - return std::filesystem::exists(gamePath.parent_path() / - "appxmanifest.xml"); - case GameType::tes5se: - case GameType::fo4: - case GameType::starfield: - return std::filesystem::exists(gamePath / "appxmanifest.xml"); - case GameType::tes5: - case GameType::tes5vr: - case GameType::fo4vr: - case GameType::openmw: - return false; - default: - throw std::logic_error("Unrecognised game type"); - } -} - -std::filesystem::path GetUserDocumentsPath( - const std::filesystem::path& gameLocalPath) { -#ifdef _WIN32 - PWSTR path; - - if (SHGetKnownFolderPath(FOLDERID_Documents, 0, NULL, &path) != S_OK) - throw std::system_error(GetLastError(), - std::system_category(), - "Failed to get user Documents path."); - - std::filesystem::path documentsPath(path); - CoTaskMemFree(path); - - return documentsPath; -#else - // Get the documents path relative to the game's local path. - return gameLocalPath.parent_path().parent_path().parent_path() / "Documents"; -#endif -} - std::filesystem::path ResolvePluginPath( GameType gameType, const std::filesystem::path& dataPath, @@ -319,7 +254,7 @@ std::shared_ptr Game::GetPlugin( std::vector> Game::GetLoadedPlugins() const { std::vector> interfacePointers; - for (const auto plugin : cache_.GetPlugins()) { + for (const auto& plugin : cache_.GetPlugins()) { interfacePointers.push_back(plugin); } diff --git a/src/api/game/game.h b/src/api/game/game.h index 7733faba..1cd666f6 100644 --- a/src/api/game/game.h +++ b/src/api/game/game.h @@ -57,7 +57,7 @@ public: GameType GetType() const override; - std::vector GetAdditionalDataPaths() const; + std::vector GetAdditionalDataPaths() const override; void SetAdditionalDataPaths( const std::vector& additionalDataPaths) override; diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 8f9df4f2..51b7fe29 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -207,14 +207,15 @@ void HandleEspluginError(unsigned int returnCode, std::string_view operation) { throw std::system_error(returnCode, esplugin_category(), err); } +template void HandleEspluginError(unsigned int returnCode, std::string_view message, - std::string_view args...) { + Args... args) { if (returnCode == ESP_OK) { return; } - auto operation = fmt::format(message, args); + auto operation = fmt::format(message, args...); return HandleEspluginError(returnCode, operation); } diff --git a/src/api/plugin.h b/src/api/plugin.h index b8059cbd..522e2269 100644 --- a/src/api/plugin.h +++ b/src/api/plugin.h @@ -83,8 +83,8 @@ public: // Load ordering functions. size_t GetOverrideRecordCount() const override; - size_t GetAssetCount() const; - bool DoAssetsOverlap(const PluginSortingInterface& plugin) const; + size_t GetAssetCount() const override; + bool DoAssetsOverlap(const PluginSortingInterface& plugin) const override; // Validity checks. static bool IsValid(const GameType gameType, diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 6a5f07fe..97934436 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -461,8 +461,14 @@ std::string PathToString(const RawPluginGraph& graph, class BidirVisitor { public: + BidirVisitor() = default; + BidirVisitor(const BidirVisitor&) = delete; + BidirVisitor(BidirVisitor&&) = delete; virtual ~BidirVisitor() = default; + BidirVisitor& operator=(const BidirVisitor&) = delete; + BidirVisitor& operator=(BidirVisitor&&) = delete; + virtual void VisitForwardVertex(const vertex_t& sourceVertex, const vertex_t& targetVertex) = 0; @@ -479,15 +485,17 @@ public: const vertex_t& toVertex) : pathsCache_(&pathsCache), fromVertex_(fromVertex), toVertex_(toVertex) {} - void VisitForwardVertex(const vertex_t&, const vertex_t& targetVertex) { + void VisitForwardVertex(const vertex_t&, + const vertex_t& targetVertex) override { pathsCache_->CachePath(fromVertex_, targetVertex); } - void VisitReverseVertex(const vertex_t& sourceVertex, const vertex_t&) { + void VisitReverseVertex(const vertex_t& sourceVertex, + const vertex_t&) override { pathsCache_->CachePath(sourceVertex, toVertex_); } - void VisitIntersectionVertex(const vertex_t&) {} + void VisitIntersectionVertex(const vertex_t&) override {} protected: vertex_t GetFromVertex() const { return fromVertex_; } @@ -509,20 +517,20 @@ public: PathCacher(pathsCache, fromVertex, toVertex), graph_(&graph) {} void VisitForwardVertex(const vertex_t& sourceVertex, - const vertex_t& targetVertex) { + const vertex_t& targetVertex) override { PathCacher::VisitForwardVertex(sourceVertex, targetVertex); forwardParents.insert_or_assign(targetVertex, sourceVertex); } void VisitReverseVertex(const vertex_t& sourceVertex, - const vertex_t& targetVertex) { + const vertex_t& targetVertex) override { PathCacher::VisitReverseVertex(sourceVertex, targetVertex); reverseChildren.insert_or_assign(sourceVertex, targetVertex); } - void VisitIntersectionVertex(const vertex_t& intersectionVertex) { + void VisitIntersectionVertex(const vertex_t& intersectionVertex) override { intersectionVertex_ = intersectionVertex; }