Skip to content

Commit 49340d0

Browse files
committed
mount extra game folders and bundled content fallback, remove hl2 skip
1 parent 3adb5d5 commit 49340d0

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

‎Source.Filesystem/GarrysMod/GameDepotSystem.cs‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ public class GameDepotSystem : GameDepot.System
2222
void MountGame(ref IGameDepotSystem.Information game) {
2323
if (game.Mounted || !game.Installed) return;
2424
Msg($"Mounting game '{game.Title}' ({game.Folder}, {(uint)game.AppID})\n");
25-
if (game.Folder.Equals("hl2", StringComparison.OrdinalIgnoreCase)) {
26-
game.Mounted = true;
27-
return;
28-
}
2925
SteamApps.GetAppInstallDir(game.AppID, out string dir, MAX_PATH);
3026
foreach (string extra in game.ExtraFolders)
3127
MountContentDir(Path.Combine(dir, extra), game.Folder);
@@ -42,6 +38,24 @@ void UnmountGame(ref IGameDepotSystem.Information game) {
4238
game.Mounted = false;
4339
}
4440

41+
static string FallbackVPK(string folder) => Path.Combine(AppContext.BaseDirectory, "sourceengine", $"content_{folder}_dir.vpk");
42+
43+
static void MountFallback(ref IGameDepotSystem.Information game) {
44+
string vpk = FallbackVPK(game.Folder);
45+
if (!File.Exists(vpk)) return;
46+
Msg($"Mounting game '{game.Title}' as fallback ({game.Folder}, {(uint)game.AppID})\n");
47+
g_FullFileSystem.AddSearchPath(vpk, "GAME", groupName: PathGroupName.GameContent);
48+
g_FullFileSystem.AddSearchPath(vpk, game.Folder, groupName: PathGroupName.GameContent);
49+
g_FullFileSystem.MarkPathIDByRequestOnly(game.Folder, true);
50+
}
51+
52+
static void UnmountFallback(ref IGameDepotSystem.Information game) {
53+
string vpk = FallbackVPK(game.Folder);
54+
if (!File.Exists(vpk)) return;
55+
g_FullFileSystem.RemoveSearchPath(vpk, "GAME");
56+
g_FullFileSystem.RemoveSearchPath(vpk, game.Folder);
57+
}
58+
4559
static void MountContentDir(string absDir, ReadOnlySpan<char> mountID) {
4660
if (!Directory.Exists(absDir)) return;
4761
foreach (string vpk in Directory.EnumerateFiles(absDir, "*_dir.vpk")) {
@@ -101,6 +115,12 @@ public void Refresh() {
101115
if (game.Enabled)
102116
MountGame(ref game);
103117
}
118+
119+
for (int i = 0; i < games.Length; i++) {
120+
ref IGameDepotSystem.Information game = ref games[i];
121+
if (!game.Mounted && game.Bundled)
122+
MountFallback(ref game);
123+
}
104124
}
105125

106126
private void LoadMountPrefs() {
@@ -130,7 +150,11 @@ private void LoadGameList() {
130150
return;
131151

132152
foreach (KeyValues game in manifest) {
133-
string[] extra = new string(game.GetString("extra")).Split(' ', StringSplitOptions.RemoveEmptyEntries);
153+
List<string> extra = [];
154+
KeyValues? extraKV = game.FindKey("extra");
155+
if (extraKV != null)
156+
foreach (KeyValues folder in extraKV)
157+
extra.Add(new(folder.GetString()));
134158
AppId_t appID = (AppId_t)uint.Parse(game.Name);
135159
Games.Add(new IGameDepotSystem.Information {
136160
AppID = appID,
@@ -154,6 +178,8 @@ private void UnmountAll() {
154178
ref IGameDepotSystem.Information game = ref games[i];
155179
if (game.Mounted)
156180
UnmountGame(ref game);
181+
else if (game.Bundled)
182+
UnmountFallback(ref game);
157183
}
158184
}
159185

0 commit comments

Comments
 (0)