Skip to content

Commit

Permalink
Merge pull request #891 from rfuzzo/feat/uvfs_support
Browse files Browse the repository at this point in the history
fix: no explicit mo2 folder name checking
  • Loading branch information
maximegmd authored Oct 21, 2023
2 parents 7682be8 + 548aeea commit fbfe95b
Showing 1 changed file with 2 additions and 41 deletions.
43 changes: 2 additions & 41 deletions src/scripting/LuaSandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,50 +693,11 @@ std::filesystem::path LuaSandbox::GetLuaPath(std::filesystem::path aFilePath, co
const auto relativeFilePathToRoot = relative(aFilePath, acRootPath);
if (relativeFilePathToRoot.native().starts_with(L"..\\") || relativeFilePathToRoot.native().find(L"\\..\\") != std::wstring::npos)
{
auto _Weakly_canonical_path = weakly_canonical(aFilePath);
auto _Weakly_canonical_base = weakly_canonical(acRootPath);

#ifdef CET_DEBUG
if (auto existingLogger = spdlog::get("scripting"))
{
existingLogger->warn("lua sandbox path missmatch for: ");
existingLogger->info("\t{}", acRootPath.string());
existingLogger->info("\tresolved to: {}", _Weakly_canonical_base.string());
existingLogger->info("\t{}", aFilePath.string());
existingLogger->info("\tresolved to: {}", _Weakly_canonical_path.string());
}
#endif // CET_DEBUG

// path outside of sandbox
// make an exception if path outside of sandbox originates from MO2's overwrite directory
// make an exception if path outside of sandbox originates from MO2
if (m_isLaunchedThroughMO2)
{
auto relativeFilePathToGame = aFilePath.lexically_relative(m_pScripting->GameRoot());
auto overwritePath = "overwrite\\bin\\x64\\" + relativeFilePathToGame.string();

const auto relativeBasePathToGame = acRootPath.lexically_relative(m_pScripting->GameRoot());
const auto overwriteBase = "overwrite\\bin\\x64\\" + relativeBasePathToGame.string();

if (_Weakly_canonical_path.string().ends_with(overwritePath) || _Weakly_canonical_base.string().ends_with(overwriteBase))
{
auto resolved = aFilePath.lexically_relative(std::filesystem::current_path());
#ifdef CET_DEBUG
if (auto existingLogger = spdlog::get("scripting"))
{
existingLogger->warn("\tFix filepath for MO2 to: {}", resolved.string());
}
#endif // CET_DEBUG
return resolved;
}
}

#ifdef CET_DEBUG
if (auto existingLogger = spdlog::get("scripting"))
{
existingLogger->error("\tCould not resolve path: {}", aFilePath.string());
return aFilePath.lexically_relative(std::filesystem::current_path());
}
#endif // CET_DEBUG
return {};
}

return relative(aFilePath, std::filesystem::current_path());
Expand Down

0 comments on commit fbfe95b

Please sign in to comment.