Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport mAltAssetsEnabled functionality from 2.0. #644

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading