From ac3c8159c30c5cc0c889ecc0503ef02767890d6f Mon Sep 17 00:00:00 2001 From: Earu <20880060+Earu@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:43:58 +0400 Subject: [PATCH 1/3] match gmod's hardcoded filsystem search path order --- Game.Assets/Assets.cs | 1 + Source.Engine/FileSystem.cs | 9 ++-- Source.Filesystem/BaseFileSystem.cs | 47 +++++++++++++++++-- .../GarrysMod/GameDepotSystem.cs | 4 ++ 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Game.Assets/Assets.cs b/Game.Assets/Assets.cs index 4db9a793f..b8607de57 100644 --- a/Game.Assets/Assets.cs +++ b/Game.Assets/Assets.cs @@ -33,6 +33,7 @@ public static List GetRequiredAssets() { new("platform", "platform", IsDirectory: true), new("sdn/maps", "garrysmod/maps", IsDirectory: true), new("sdn/materials", "garrysmod/materials", IsDirectory: true), + new("sdn/particles", "garrysmod/particles", IsDirectory: true), new("sdn/resource", "garrysmod/resource", IsDirectory: true), new("sdn/scenes", "garrysmod/scenes", IsDirectory: true), #if GMOD_DLL 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..a8cfe53a9 100644 --- a/Source.Filesystem/GarrysMod/GameDepotSystem.cs +++ b/Source.Filesystem/GarrysMod/GameDepotSystem.cs @@ -22,6 +22,10 @@ public class GameDepotSystem : GameDepot.System void MountGame(ref IGameDepotSystem.Information game) { if (game.Mounted || !game.Installed) return; Msg($"Mounting game '{game.Title}' ({game.Folder}, {(uint)game.AppID})\n"); + if (game.Folder.Equals("hl2", StringComparison.OrdinalIgnoreCase)) { + game.Mounted = true; + return; + } SteamApps.GetAppInstallDir(game.AppID, out string dir, MAX_PATH); foreach (string extra in game.ExtraFolders) MountContentDir(Path.Combine(dir, extra), game.Folder); From 3adb5d54aa6d1f8591c97359e22e27151c273eed Mon Sep 17 00:00:00 2001 From: Earu <20880060+Earu@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:45:30 +0400 Subject: [PATCH 2/3] this should be done in particle draft instead --- Game.Assets/Assets.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Game.Assets/Assets.cs b/Game.Assets/Assets.cs index b8607de57..4db9a793f 100644 --- a/Game.Assets/Assets.cs +++ b/Game.Assets/Assets.cs @@ -33,7 +33,6 @@ public static List GetRequiredAssets() { new("platform", "platform", IsDirectory: true), new("sdn/maps", "garrysmod/maps", IsDirectory: true), new("sdn/materials", "garrysmod/materials", IsDirectory: true), - new("sdn/particles", "garrysmod/particles", IsDirectory: true), new("sdn/resource", "garrysmod/resource", IsDirectory: true), new("sdn/scenes", "garrysmod/scenes", IsDirectory: true), #if GMOD_DLL From 49340d02bd9b4a135eeeaefe26eb008192686be0 Mon Sep 17 00:00:00 2001 From: Earu <20880060+Earu@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:01:36 +0400 Subject: [PATCH 3/3] mount extra game folders and bundled content fallback, remove hl2 skip --- .../GarrysMod/GameDepotSystem.cs | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/Source.Filesystem/GarrysMod/GameDepotSystem.cs b/Source.Filesystem/GarrysMod/GameDepotSystem.cs index a8cfe53a9..1877b5332 100644 --- a/Source.Filesystem/GarrysMod/GameDepotSystem.cs +++ b/Source.Filesystem/GarrysMod/GameDepotSystem.cs @@ -22,10 +22,6 @@ public class GameDepotSystem : GameDepot.System void MountGame(ref IGameDepotSystem.Information game) { if (game.Mounted || !game.Installed) return; Msg($"Mounting game '{game.Title}' ({game.Folder}, {(uint)game.AppID})\n"); - if (game.Folder.Equals("hl2", StringComparison.OrdinalIgnoreCase)) { - game.Mounted = true; - return; - } SteamApps.GetAppInstallDir(game.AppID, out string dir, MAX_PATH); foreach (string extra in game.ExtraFolders) MountContentDir(Path.Combine(dir, extra), game.Folder); @@ -42,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")) { @@ -101,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() { @@ -130,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, @@ -154,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); } }