@@ -30,6 +30,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
3131#if defined(BUILD_ENGINE)
3232#include " minizip/unzip.h"
33+ #include " DaemonEmbedded/EngineMedia.h"
3334#endif
3435
3536#ifdef BUILD_VM
@@ -129,6 +130,15 @@ static Cvar::Cvar<bool> fs_legacypaks("fs_legacypaks", "also load pk3s, ignoring
129130static Cvar::Cvar<int > fs_maxSymlinkDepth (" fs_maxSymlinkDepth" , " max depth of symlinks in zip paks (0 means disabled)" , Cvar::NONE, 1 );
130131static Cvar::Cvar<std::string> fs_pakprefixes (" fs_pakprefixes" , " prefixes to look for paks to load" , 0 , " " );
131132
133+ const PakInfo builtinPak =
134+ {
135+ " *builtin" ,
136+ ENGINE_VERSION,
137+ 0 ,
138+ pakType_t::PAK_BUILTIN,
139+ " *builtin" ,
140+ };
141+
132142bool UseLegacyPaks ()
133143{
134144 return fs_legacypaks.Get ();
@@ -1258,6 +1268,7 @@ static void InternalLoadPak(
12581268 offset_t depsOffset = 0 ;
12591269 ZipArchive zipFile;
12601270 bool isLegacy = pak.version .empty ();
1271+ bool isBuiltin = pak.type == pakType_t::PAK_BUILTIN;
12611272
12621273 // Check if this pak has already been loaded to avoid recursive dependencies
12631274 for (auto & x: loadedPaks) {
@@ -1279,6 +1290,8 @@ static void InternalLoadPak(
12791290 } else {
12801291 fsLogs.WithoutSuppression ().Notice (" Loading legacy pakdir '%s'..." , pak.path .c_str ());
12811292 }
1293+ } else if (pak.type == pakType_t::PAK_BUILTIN ) {
1294+ fsLogs.WithoutSuppression ().Notice (" Loading builtin pak '%s'..." , pak.path .c_str ());
12821295 } else {
12831296 ASSERT_UNREACHABLE ();
12841297 }
@@ -1369,6 +1382,11 @@ static void InternalLoadPak(
13691382 }, err);
13701383 if (err)
13711384 return ;
1385+ } else if (pak.type == pakType_t::PAK_BUILTIN) {
1386+ for ( auto it : EngineMedia::FileMap )
1387+ {
1388+ fileMap.emplace (it.first , std::pair<uint32_t , offset_t >(it.second .size (), 0 ));
1389+ }
13721390 } else {
13731391 ASSERT_UNREACHABLE ();
13741392 }
@@ -1388,8 +1406,8 @@ static void InternalLoadPak(
13881406
13891407 loadedPak.pathPrefix = pathPrefix;
13901408
1391- // Legacy paks don't have version neither checksum
1392- if (!isLegacy) {
1409+ // Legacy and builtin paks don't have version neither checksum
1410+ if (!isLegacy && !isBuiltin ) {
13931411 // If an explicit checksum was requested, verify that the pak we loaded is the one we are expecting
13941412 if (expectedChecksum && realChecksum != *expectedChecksum) {
13951413 SetErrorCodeFilesystem (err, filesystem_error::wrong_pak_checksum, pak.path );
@@ -1542,6 +1560,12 @@ std::string ReadFile(Str::StringRef path, std::error_code& err) {
15421560#ifdef BUILD_ENGINE
15431561std::string ReadFile (Str::StringRef path, std::error_code& err)
15441562{
1563+ if (EngineMedia::HasFile (path))
1564+ {
1565+ Log::Debug (" Loading internal file: %s" , path);
1566+ return EngineMedia::ReadFile (path);
1567+ }
1568+
15451569 auto it = fileMap.find (path);
15461570 if (it == fileMap.end ()) {
15471571 SetErrorCodeFilesystem (err, filesystem_error::no_such_file, path);
@@ -2660,6 +2684,13 @@ static const PakInfo* FindPakNoPrefix(Str::StringRef name)
26602684
26612685const PakInfo* FindPak (Str::StringRef name)
26622686{
2687+ #if defined(BUILD_ENGINE)
2688+ if (name == builtinPak.name )
2689+ {
2690+ return &builtinPak;
2691+ }
2692+ #endif
2693+
26632694 Cmd::Args pakprefixes (Cvar::GetValue (" fs_pakprefixes" ));
26642695 for (const std::string &pakprefix: pakprefixes)
26652696 {
0 commit comments