Skip to content

Commit

Permalink
Implemented better way to load mod files
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed Aug 27, 2022
1 parent ab7bcaf commit a8db78d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/CModLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
#include "Log.h"
#include "Utils.h"
void* __cdecl CModLoader::resolveFile_hook(PCSTR lpFileName, SIZE_T *outBuf, char isCritical) {
const auto fullPath = std::filesystem::current_path() / lpFileName;
const auto relPath = relative(fullPath, CGameApis::GetDataPath());
const auto curPath = std::filesystem::current_path();
const auto relPath = relative(curPath, CGameApis::GetDataPath());
const auto relPathStr = relPath.generic_string();
auto modPathStr = std::string(lpFileName);
bool changed = false;

if (relPathStr.size() < 2 || relPathStr[0] != '.' && relPathStr[1] != '.') {
for (const auto& loadedMod : Instance()._loadedMods) {
const auto modPath = CGameApis::GetModsPath() / loadedMod / relPath;
if (exists(modPath)) {
modPathStr = relative(modPath, std::filesystem::current_path()).generic_string();
Log::Debug << "Loaded mod file " << relPathStr << Log::Endl;
if (exists(modPath / lpFileName)) {
Log::Debug << "Loaded mod file " << lpFileName << Log::Endl;
current_path(modPath);
changed = true;
break;
}
}
}

return resolveFile_orig(modPathStr.c_str(), outBuf, isCritical);
const auto ptr = resolveFile_orig(lpFileName, outBuf, isCritical);
if (changed) current_path(curPath);
return ptr;
}

void CModLoader::Initialize() {
Expand Down

0 comments on commit a8db78d

Please sign in to comment.