@@ -658,7 +658,27 @@ static void Init(int argc, char** argv)
658658
659659 // Initialize the filesystem. For pakpaths, the libpath is added first and has the
660660 // lowest priority, while the homepath is added last and has the highest.
661- cmdlineArgs.pakPaths .insert (cmdlineArgs.pakPaths .begin (), FS::Path::Build (cmdlineArgs.libPath , " pkg" ));
661+
662+ /* The default pakpath is <libpath>/pkg, but we load <libpath>/../pkg instead
663+ if <libpath>/pkg doesn't exist but <libpath>/../pkg exists.
664+ This is to make sure extracting the engine archive in a subfolder works.
665+ Many file browsers create a parent directory when there is no directory in an archive. */
666+ std::string defaultPakPath = FS::Path::Build (cmdlineArgs.libPath , " pkg" );
667+
668+ std::error_code missing;
669+ FS::RawPath::ListFiles (defaultPakPath, missing);
670+ if (missing)
671+ {
672+ std::string parentPakPath = FS::Path::Build (cmdlineArgs.libPath , FS::Path::Build (" .." , " pkg" ));
673+ FS::RawPath::ListFiles (parentPakPath, missing);
674+ if (!missing)
675+ {
676+ defaultPakPath = parentPakPath;
677+ }
678+ }
679+
680+ cmdlineArgs.pakPaths .insert (cmdlineArgs.pakPaths .begin (), defaultPakPath);
681+
662682 cmdlineArgs.pakPaths .push_back (FS::Path::Build (cmdlineArgs.homePath , " pkg" ));
663683 EarlyCvar (" fs_legacypaks" , cmdlineArgs);
664684 FS::Initialize (cmdlineArgs.homePath , cmdlineArgs.libPath , cmdlineArgs.pakPaths );
0 commit comments