diff --git a/Source.Engine/FileSystem.cs b/Source.Engine/FileSystem.cs index fd7c9ee8f..03f379d19 100644 --- a/Source.Engine/FileSystem.cs +++ b/Source.Engine/FileSystem.cs @@ -49,6 +49,7 @@ public FSReturnCode LoadSearchPaths(ref CFSSearchPathsInit initInfo) { initInfo.ModPath = initInfo.DirectoryName; +#if !GMOD_DLL const string GAMEINFOPATH_TOKEN = "|gameinfo_path|"; const string BASESOURCEPATHS_TOKEN = "|all_source_engine_paths|"; @@ -76,13 +77,12 @@ public FSReturnCode LoadSearchPaths(ref CFSSearchPathsInit initInfo) { string[] pathIDs = cur.Name.Split('+'); for (int i = 0; i < pathIDs.Length; i++) { pathIDs[i] = pathIDs[i].Trim(); -#if GMOD_DLL - initInfo.FileSystem.AddSearchPath(absSearchPath, pathIDs[i], SearchPathAdd.ToTail, PathGroupName.GModCore); -#else initInfo.FileSystem.AddSearchPath(absSearchPath, pathIDs[i]); -#endif } } +#else + initInfo.FileSystem.GMOD_SetupDefaultPaths(baseDir, initInfo.DirectoryName); +#endif initInfo.FileSystem.MarkPathIDByRequestOnly("executable_path", true); initInfo.FileSystem.MarkPathIDByRequestOnly("gamebin", true); @@ -92,7 +92,6 @@ public FSReturnCode LoadSearchPaths(ref CFSSearchPathsInit initInfo) { initInfo.FileSystem.MarkPathIDByRequestOnly("mod_write", true); #if GMOD_DLL - initInfo.FileSystem.GMOD_SetupDefaultPaths(baseDir, initInfo.DirectoryName); initInfo.FileSystem.DoFilesystemRefresh(); #endif diff --git a/Source.Filesystem/BaseFileSystem.cs b/Source.Filesystem/BaseFileSystem.cs index 4aab845f5..91901b551 100644 --- a/Source.Filesystem/BaseFileSystem.cs +++ b/Source.Filesystem/BaseFileSystem.cs @@ -1062,13 +1062,52 @@ public void AddVPKFileFromPath(ReadOnlySpan vpk, ReadOnlySpan path, AddVPKFile(vpk, path, (SearchPathAdd)id, PathGroupName.Default); } + private void GMOD_AddPath(string path, PathGroupName group, params ReadOnlySpan pathIDs) { + foreach (string pathID in pathIDs) + AddSearchPath(path, pathID, SearchPathAdd.ToTail, group); + } + + private void GMOD_AddVPK(string vpk, PathGroupName group, params ReadOnlySpan pathIDs) { + if (!File.Exists($"{vpk}_dir.vpk")) + return; + GMOD_AddPath($"{vpk}.vpk", group, pathIDs); + } + public void GMOD_SetupDefaultPaths(ReadOnlySpan path, ReadOnlySpan game) { - string workshop = Path.Combine(new string(game), "workshop"); - AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "GAME", SearchPathAdd.ToHead, PathGroupName.GModCore); - AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "workshop", SearchPathAdd.ToHead, PathGroupName.GModCore); - AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "thirdparty", SearchPathAdd.ToHead, PathGroupName.GModCore); + string baseDir = new(path); + string gameDir = new(game); + bool vpkBuild = FileExists("vpk_build", "BASE_PATH"); + + GMOD_AddPath(Path.Combine(gameDir, "bin"), PathGroupName.EngineCore, "GAMEBIN"); + + string workshop = Path.Combine(gameDir, "workshop"); + AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "GAME", SearchPathAdd.ToTail, PathGroupName.GModCore); + AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "workshop", SearchPathAdd.ToTail, PathGroupName.GModCore); + AddSearchPath(new AddonSearchPath(g_AddonFileSystem, workshop), "thirdparty", SearchPathAdd.ToTail, PathGroupName.GModCore); + + GMOD_AddVPK(Path.Combine(gameDir, "garrysmod"), PathGroupName.GModCore, "MOD", "GAME", "garrysmod"); + if (vpkBuild) + GMOD_AddPath(Path.Combine(gameDir, "overrides"), PathGroupName.GModCore, "GAME", "garrysmod"); + GMOD_AddPath(gameDir, PathGroupName.GModCore, "MOD", "MOD_WRITE", "DEFAULT_WRITE_PATH", "GAME", "GAME_WRITE", "garrysmod"); + MarkPathIDByRequestOnly("workshop", true); MarkPathIDByRequestOnly("thirdparty", true); + MarkPathIDByRequestOnly("garrysmod", true); + + string sourceEngine = Path.Combine(baseDir, "sourceengine"); + foreach (string vpk in (ReadOnlySpan)["hl2_misc", "hl2_sound_misc", "hl2_sound_vo_english", "hl2_textures"]) + GMOD_AddVPK(Path.Combine(sourceEngine, vpk), PathGroupName.SourceSDK, "GAME"); + GMOD_AddPath(sourceEngine, PathGroupName.SourceSDK, "GAME"); + + string platform = Path.Combine(baseDir, "platform"); + GMOD_AddVPK(Path.Combine(platform, "platform_misc"), PathGroupName.SourceSDK, "GAME", "PLATFORM"); + GMOD_AddPath(platform, PathGroupName.SourceSDK, "GAME", "PLATFORM"); + + GMOD_AddPath(Path.Combine(gameDir, "download"), PathGroupName.Downloads, "GAME", "DOWNLOAD"); + + GMOD_AddVPK(Path.Combine(gameDir, "fallbacks"), PathGroupName.Fallbacks, "GAME", "MOD"); + if (vpkBuild) + GMOD_AddPath(Path.Combine(gameDir, "fallbacks"), PathGroupName.Fallbacks, "GAME", "MOD"); } public void GMOD_FixPathCase(Span a) { diff --git a/Source.Filesystem/GarrysMod/GameDepotSystem.cs b/Source.Filesystem/GarrysMod/GameDepotSystem.cs index 37d7f37e3..1877b5332 100644 --- a/Source.Filesystem/GarrysMod/GameDepotSystem.cs +++ b/Source.Filesystem/GarrysMod/GameDepotSystem.cs @@ -38,6 +38,24 @@ void UnmountGame(ref IGameDepotSystem.Information game) { game.Mounted = false; } + static string FallbackVPK(string folder) => Path.Combine(AppContext.BaseDirectory, "sourceengine", $"content_{folder}_dir.vpk"); + + static void MountFallback(ref IGameDepotSystem.Information game) { + string vpk = FallbackVPK(game.Folder); + if (!File.Exists(vpk)) return; + Msg($"Mounting game '{game.Title}' as fallback ({game.Folder}, {(uint)game.AppID})\n"); + g_FullFileSystem.AddSearchPath(vpk, "GAME", groupName: PathGroupName.GameContent); + g_FullFileSystem.AddSearchPath(vpk, game.Folder, groupName: PathGroupName.GameContent); + g_FullFileSystem.MarkPathIDByRequestOnly(game.Folder, true); + } + + static void UnmountFallback(ref IGameDepotSystem.Information game) { + string vpk = FallbackVPK(game.Folder); + if (!File.Exists(vpk)) return; + g_FullFileSystem.RemoveSearchPath(vpk, "GAME"); + g_FullFileSystem.RemoveSearchPath(vpk, game.Folder); + } + static void MountContentDir(string absDir, ReadOnlySpan mountID) { if (!Directory.Exists(absDir)) return; foreach (string vpk in Directory.EnumerateFiles(absDir, "*_dir.vpk")) { @@ -97,6 +115,12 @@ public void Refresh() { if (game.Enabled) MountGame(ref game); } + + for (int i = 0; i < games.Length; i++) { + ref IGameDepotSystem.Information game = ref games[i]; + if (!game.Mounted && game.Bundled) + MountFallback(ref game); + } } private void LoadMountPrefs() { @@ -126,7 +150,11 @@ private void LoadGameList() { return; foreach (KeyValues game in manifest) { - string[] extra = new string(game.GetString("extra")).Split(' ', StringSplitOptions.RemoveEmptyEntries); + List extra = []; + KeyValues? extraKV = game.FindKey("extra"); + if (extraKV != null) + foreach (KeyValues folder in extraKV) + extra.Add(new(folder.GetString())); AppId_t appID = (AppId_t)uint.Parse(game.Name); Games.Add(new IGameDepotSystem.Information { AppID = appID, @@ -150,6 +178,8 @@ private void UnmountAll() { ref IGameDepotSystem.Information game = ref games[i]; if (game.Mounted) UnmountGame(ref game); + else if (game.Bundled) + UnmountFallback(ref game); } }