From a13fd761ccb73213ac56acb18755c32de14dd64c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Mar 2014 06:19:56 -0300 Subject: [PATCH] Updated love.filesystem's C library loader for require to look in paths added via love.filesystem.mount, when in fused mode --- src/modules/filesystem/physfs/Filesystem.cpp | 10 +++++++ src/modules/filesystem/physfs/Filesystem.h | 5 ++++ .../filesystem/physfs/wrap_Filesystem.cpp | 28 +++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index 25e4efbc9..aa2f5e826 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -397,6 +397,16 @@ std::string Filesystem::getSourceBaseDirectory() const return game_source.substr(0, base_end_pos); } +std::string Filesystem::getRealDirectory(const char *filename) const +{ + const char *dir = PHYSFS_getRealDir(filename); + + if (dir == nullptr) + throw love::Exception("File does not exist."); + + return std::string(dir); +} + bool Filesystem::exists(const char *file) const { return PHYSFS_exists(file); diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index a6ef9af5a..f9ccfecb3 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -166,6 +166,11 @@ public: **/ std::string getSourceBaseDirectory() const; + /** + * Gets the real directory path containing the file. + **/ + std::string getRealDirectory(const char *filename) const; + /** * Checks whether a file exists in the current search path * or not. diff --git a/src/modules/filesystem/physfs/wrap_Filesystem.cpp b/src/modules/filesystem/physfs/wrap_Filesystem.cpp index 6e76cbb52..0a89387e6 100644 --- a/src/modules/filesystem/physfs/wrap_Filesystem.cpp +++ b/src/modules/filesystem/physfs/wrap_Filesystem.cpp @@ -526,9 +526,31 @@ int extloader(lua_State *L) tokenized_name += library_extension(); - void *handle = SDL_LoadObject((std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name).c_str()); - if (!handle && instance->isFused()) - handle = SDL_LoadObject((std::string(instance->getSaveDirectory()) + LOVE_PATH_SEPARATOR + tokenized_name).c_str()); + void *handle = nullptr; + + // If the game is fused, try looking for the DLL in the game's read paths. + if (instance->isFused()) + { + try + { + std::string dir = instance->getRealDirectory(tokenized_name.c_str()); + + // We don't want to look in the game's source, because it can be a + // zip sometimes and a folder other times. + if (dir.find(instance->getSource()) == std::string::npos) + handle = SDL_LoadObject((dir + LOVE_PATH_SEPARATOR + tokenized_name).c_str()); + } + catch (love::Exception &) + { + // Nothing... + } + } + + if (!handle) + { + std::string path = std::string(instance->getAppdataDirectory()) + LOVE_PATH_SEPARATOR LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR + tokenized_name; + handle = SDL_LoadObject(path.c_str()); + } if (!handle) {