Skip to content

Commit

Permalink
Backport mAltAssetsEnabled functionality from 2.0. (Kenix3#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malkierian authored Jul 17, 2024
1 parent ce9dd90 commit 275c741
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ std::shared_ptr<IResource> ResourceManager::LoadResourceProcess(const std::strin

// Attempt to load the alternate version of the asset, if we fail then we continue trying to load the standard
// asset.
if (!loadExact && CVarGetInteger("gAltAssets", 0) && !filePath.starts_with(IResource::gAltAssetPrefix)) {
if (!loadExact && mAltAssetsEnabled && !filePath.starts_with(IResource::gAltAssetPrefix)) {
const auto altPath = IResource::gAltAssetPrefix + filePath;
auto altResource = LoadResourceProcess(altPath, loadExact);

Expand All @@ -96,7 +96,7 @@ std::shared_ptr<IResource> ResourceManager::LoadResourceProcess(const std::strin

// Check for resource load errors which can indicate an alternate asset.
// If we are attempting to load an alternate asset, we can return null
if (!loadExact && CVarGetInteger("gAltAssets", 0) && filePath.starts_with(IResource::gAltAssetPrefix)) {
if (!loadExact && mAltAssetsEnabled && filePath.starts_with(IResource::gAltAssetPrefix)) {
if (std::holds_alternative<ResourceLoadError>(cacheLine)) {
try {
// If we have attempted to cache an alternate asset, but failed, we return nullptr and rely on the
Expand Down Expand Up @@ -196,7 +196,7 @@ std::shared_ptr<IResource> ResourceManager::LoadResource(const std::string& file

std::variant<ResourceManager::ResourceLoadError, std::shared_ptr<IResource>>
ResourceManager::CheckCache(const std::string& filePath, bool loadExact) {
if (!loadExact && CVarGetInteger("gAltAssets", 0) && !filePath.starts_with(IResource::gAltAssetPrefix)) {
if (!loadExact && mAltAssetsEnabled && !filePath.starts_with(IResource::gAltAssetPrefix)) {
const auto altPath = IResource::gAltAssetPrefix + filePath;
auto altCacheResult = CheckCache(altPath, loadExact);

Expand Down Expand Up @@ -337,4 +337,12 @@ bool ResourceManager::OtrSignatureCheck(const char* fileName) {
return strncmp(fileName, sOtrSignature, strlen(sOtrSignature)) == 0;
}

bool ResourceManager::IsAltAssetsEnabled() {
return mAltAssetsEnabled;
}

void ResourceManager::SetAltAssetsEnabled(bool isEnabled) {
mAltAssetsEnabled = isEnabled;
}

} // namespace LUS
3 changes: 3 additions & 0 deletions src/resource/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ResourceManager {
void DirtyDirectory(const std::string& searchMask);
void UnloadDirectory(const std::string& searchMask);
bool OtrSignatureCheck(const char* fileName);
bool IsAltAssetsEnabled();
void SetAltAssetsEnabled(bool isEnabled);

protected:
std::shared_ptr<File> LoadFileProcess(const std::string& filePath);
Expand All @@ -57,5 +59,6 @@ class ResourceManager {
std::shared_ptr<Archive> mArchive;
std::shared_ptr<BS::thread_pool> mThreadPool;
std::mutex mMutex;
bool mAltAssetsEnabled = false;
};
} // namespace LUS

0 comments on commit 275c741

Please sign in to comment.