├── .gitattributes ├── .gitignore ├── LICENSE ├── SteamDepotFileVerifier.sln └── SteamDepotFileVerifier ├── Program.cs ├── SteamClientUtils.cs └── SteamDepotFileVerifier.csproj /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.cs diff=csharp 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | 24 | # Visual Studio 2015 cache/options directory 25 | .vs/ 26 | # Uncomment if you have tasks that create the project's static files in wwwroot 27 | #wwwroot/ 28 | 29 | # MSTest test Results 30 | [Tt]est[Rr]esult*/ 31 | [Bb]uild[Ll]og.* 32 | 33 | # NUNIT 34 | *.VisualState.xml 35 | TestResult.xml 36 | 37 | # Build Results of an ATL Project 38 | [Dd]ebugPS/ 39 | [Rr]eleasePS/ 40 | dlldata.c 41 | 42 | # DNX 43 | project.lock.json 44 | artifacts/ 45 | 46 | *_i.c 47 | *_p.c 48 | *_i.h 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.tmp_proj 63 | *.log 64 | *.vspscc 65 | *.vssscc 66 | .builds 67 | *.pidb 68 | *.svclog 69 | *.scc 70 | 71 | # Chutzpah Test files 72 | _Chutzpah* 73 | 74 | # Visual C++ cache files 75 | ipch/ 76 | *.aps 77 | *.ncb 78 | *.opendb 79 | *.opensdf 80 | *.sdf 81 | *.cachefile 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | *.vspx 87 | *.sap 88 | 89 | # TFS 2012 Local Workspace 90 | $tf/ 91 | 92 | # Guidance Automation Toolkit 93 | *.gpState 94 | 95 | # ReSharper is a .NET coding add-in 96 | _ReSharper*/ 97 | *.[Rr]e[Ss]harper 98 | *.DotSettings.user 99 | 100 | # JustCode is a .NET coding add-in 101 | .JustCode 102 | 103 | # TeamCity is a build add-in 104 | _TeamCity* 105 | 106 | # DotCover is a Code Coverage Tool 107 | *.dotCover 108 | 109 | # NCrunch 110 | _NCrunch_* 111 | .*crunch*.local.xml 112 | nCrunchTemp_* 113 | 114 | # MightyMoose 115 | *.mm.* 116 | AutoTest.Net/ 117 | 118 | # Web workbench (sass) 119 | .sass-cache/ 120 | 121 | # Installshield output folder 122 | [Ee]xpress/ 123 | 124 | # DocProject is a documentation generator add-in 125 | DocProject/buildhelp/ 126 | DocProject/Help/*.HxT 127 | DocProject/Help/*.HxC 128 | DocProject/Help/*.hhc 129 | DocProject/Help/*.hhk 130 | DocProject/Help/*.hhp 131 | DocProject/Help/Html2 132 | DocProject/Help/html 133 | 134 | # Click-Once directory 135 | publish/ 136 | 137 | # Publish Web Output 138 | *.[Pp]ublish.xml 139 | *.azurePubxml 140 | # TODO: Comment the next line if you want to checkin your web deploy settings 141 | # but database connection strings (with potential passwords) will be unencrypted 142 | *.pubxml 143 | *.publishproj 144 | 145 | # NuGet Packages 146 | *.nupkg 147 | # The packages folder can be ignored because of Package Restore 148 | **/packages/* 149 | # except build/, which is used as an MSBuild target. 150 | !**/packages/build/ 151 | # Uncomment if necessary however generally it will be regenerated when needed 152 | #!**/packages/repositories.config 153 | # NuGet v3's project.json files produces more ignoreable files 154 | *.nuget.props 155 | *.nuget.targets 156 | 157 | # Microsoft Azure Build Output 158 | csx/ 159 | *.build.csdef 160 | 161 | # Microsoft Azure Emulator 162 | ecf/ 163 | rcf/ 164 | 165 | # Microsoft Azure ApplicationInsights config file 166 | ApplicationInsights.config 167 | 168 | # Windows Store app package directory 169 | AppPackages/ 170 | BundleArtifacts/ 171 | 172 | # Visual Studio cache files 173 | # files ending in .cache can be ignored 174 | *.[Cc]ache 175 | # but keep track of directories ending in .cache 176 | !*.[Cc]ache/ 177 | 178 | # Others 179 | ClientBin/ 180 | ~$* 181 | *~ 182 | *.dbmdl 183 | *.dbproj.schemaview 184 | *.pfx 185 | *.publishsettings 186 | node_modules/ 187 | orleans.codegen.cs 188 | 189 | # RIA/Silverlight projects 190 | Generated_Code/ 191 | 192 | # Backup & report files from converting an old project file 193 | # to a newer Visual Studio version. Backup files are not needed, 194 | # because we have git ;-) 195 | _UpgradeReport_Files/ 196 | Backup*/ 197 | UpgradeLog*.XML 198 | UpgradeLog*.htm 199 | 200 | # SQL Server files 201 | *.mdf 202 | *.ldf 203 | 204 | # Business Intelligence projects 205 | *.rdl.data 206 | *.bim.layout 207 | *.bim_*.settings 208 | 209 | # Microsoft Fakes 210 | FakesAssemblies/ 211 | 212 | # GhostDoc plugin setting file 213 | *.GhostDoc.xml 214 | 215 | # Node.js Tools for Visual Studio 216 | .ntvs_analysis.dat 217 | 218 | # Visual Studio 6 build log 219 | *.plg 220 | 221 | # Visual Studio 6 workspace options file 222 | *.opt 223 | 224 | # Visual Studio LightSwitch build output 225 | **/*.HTMLClient/GeneratedArtifacts 226 | **/*.DesktopClient/GeneratedArtifacts 227 | **/*.DesktopClient/ModelManifest.xml 228 | **/*.Server/GeneratedArtifacts 229 | **/*.Server/ModelManifest.xml 230 | _Pvt_Extensions 231 | 232 | # Paket dependency manager 233 | .paket/paket.exe 234 | 235 | # FAKE - F# Make 236 | .fake/ 237 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Pavel Djundik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SteamDepotFileVerifier.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30011.22 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamDepotFileVerifier", "SteamDepotFileVerifier\SteamDepotFileVerifier.csproj", "{6B285D2E-0613-434D-86B5-A51CEA7D4445}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {6B285D2E-0613-434D-86B5-A51CEA7D4445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {6B285D2E-0613-434D-86B5-A51CEA7D4445}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {6B285D2E-0613-434D-86B5-A51CEA7D4445}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {6B285D2E-0613-434D-86B5-A51CEA7D4445}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E22471A6-1221-414F-A190-24F1CCE1DDCB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /SteamDepotFileVerifier/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Security.Cryptography; 6 | using System.Threading.Tasks; 7 | using SteamKit2; 8 | 9 | namespace SteamDepotFileVerifier 10 | { 11 | public static class SteamDepotFileVerifierProgram 12 | { 13 | const bool VERIFY_HASHES = false; // Change to true to SHA1 hash every single file 14 | 15 | static async Task Main(string[] args) 16 | { 17 | var steamClient = new SteamClientUtils(); 18 | var steamLibraries = steamClient.GetLibraries(); 19 | 20 | Console.WriteLine($"Steam path: {steamClient.SteamPath}"); 21 | Console.WriteLine(); 22 | 23 | if (args.Length == 0 || !uint.TryParse(args[0], out var appid)) 24 | { 25 | foreach (var library in steamLibraries) 26 | { 27 | var manifests = Directory.GetFiles(library, "appmanifest_*.acf"); 28 | 29 | foreach (var appManifestPath in manifests) 30 | { 31 | await VerifyApp(steamClient, appManifestPath); 32 | 33 | Console.WriteLine(); 34 | Console.WriteLine("------------------------------"); 35 | Console.WriteLine(); 36 | } 37 | } 38 | } 39 | else 40 | { 41 | Console.WriteLine($"AppID: {appid}"); 42 | 43 | var appManifestPath = steamLibraries 44 | .Select(library => Path.Join(library, $"appmanifest_{appid}.acf")) 45 | .FirstOrDefault(File.Exists); 46 | 47 | if (appManifestPath == null) 48 | { 49 | throw new FileNotFoundException("Unable to find appmanifest anywhere."); 50 | } 51 | 52 | await VerifyApp(steamClient, appManifestPath); 53 | } 54 | 55 | Console.WriteLine(); 56 | Console.WriteLine("If some files are listed as unknown but shouldn't be, they are probably from the SDK."); 57 | Console.WriteLine("After deleting files, verify the game files in Steam."); 58 | 59 | return 0; 60 | } 61 | 62 | private static async Task VerifyApp(SteamClientUtils steamClient, string appManifestPath) 63 | { 64 | Console.WriteLine($"Parsing {appManifestPath}"); 65 | 66 | var kv = KeyValue.LoadAsText(appManifestPath); 67 | var depotManifests = new Dictionary(); 68 | var gamePath = Path.Join(Path.GetDirectoryName(appManifestPath), "common", kv["installdir"].Value) + Path.DirectorySeparatorChar; 69 | 70 | if (!Directory.Exists(gamePath)) 71 | { 72 | throw new DirectoryNotFoundException($"Game not found: {gamePath}"); 73 | } 74 | 75 | Console.WriteLine($"Scanning {gamePath}"); 76 | 77 | foreach (var mountedDepot in kv["MountedDepots"].Children) 78 | { 79 | depotManifests[mountedDepot.Name] = mountedDepot.Value; 80 | } 81 | 82 | foreach (var mountedDepot in kv["InstalledDepots"].Children) 83 | { 84 | depotManifests[mountedDepot.Name] = mountedDepot["manifest"].Value; 85 | } 86 | 87 | var allKnownDepotFiles = new Dictionary(StringComparer.OrdinalIgnoreCase); 88 | 89 | foreach (var (depotId, manifestId) in depotManifests) 90 | { 91 | var manifestPath = Path.Join(steamClient.SteamPath, "depotcache", $"{depotId}_{manifestId}.manifest"); 92 | 93 | if (!File.Exists(manifestPath)) 94 | { 95 | Console.ForegroundColor = ConsoleColor.Green; 96 | Console.Error.WriteLine($"Manifest does not exist: {manifestPath}"); 97 | Console.Error.WriteLine($"Try verifying \"{kv["name"].Value}\" in Steam and running this again."); 98 | Console.ResetColor(); 99 | return; 100 | } 101 | 102 | var manifest = DepotManifest.Deserialize(File.ReadAllBytes(manifestPath)); 103 | 104 | if (manifest.FilenamesEncrypted) 105 | { 106 | Console.ForegroundColor = ConsoleColor.Green; 107 | Console.Error.WriteLine($"Manifest {manifestPath} has encrypted filenames."); 108 | Console.ResetColor(); 109 | return; 110 | } 111 | 112 | foreach (var file in manifest.Files) 113 | { 114 | if (file.Flags.HasFlag(EDepotFileFlag.Directory)) 115 | { 116 | continue; 117 | } 118 | 119 | allKnownDepotFiles[file.FileName] = file; 120 | } 121 | 122 | Console.WriteLine($"{manifestPath} - {manifest.Files.Count} files"); 123 | } 124 | 125 | Console.WriteLine($"{allKnownDepotFiles.Count} files in depot manifests"); 126 | 127 | var filesOnDisk = Directory.GetFiles(gamePath, "*", SearchOption.AllDirectories).ToList(); 128 | filesOnDisk.Sort(); 129 | 130 | Console.WriteLine($"{filesOnDisk.Count} files on disk"); 131 | Console.WriteLine(); 132 | Console.ForegroundColor = ConsoleColor.Red; 133 | 134 | var filenamesOnDisk = new HashSet(StringComparer.OrdinalIgnoreCase); 135 | 136 | foreach (var file in filesOnDisk) 137 | { 138 | var unprefixedPath = file[gamePath.Length..]; 139 | 140 | filenamesOnDisk.Add(unprefixedPath); 141 | 142 | if (unprefixedPath == "installscript.vdf" || Path.GetFileName(unprefixedPath) == "steam_appid.txt") 143 | { 144 | continue; 145 | } 146 | 147 | if (!allKnownDepotFiles.TryGetValue(unprefixedPath, out var fileData)) 148 | { 149 | Console.WriteLine($"Unknown file: {unprefixedPath}"); 150 | continue; 151 | } 152 | 153 | if ((fileData.Flags & (EDepotFileFlag.UserConfig | EDepotFileFlag.VersionedUserConfig)) > 0) 154 | { 155 | Console.WriteLine($"Skipping user config: {unprefixedPath}"); 156 | continue; 157 | } 158 | 159 | var fileInfoOnDisk = new FileInfo(file); 160 | 161 | if (fileData.TotalSize != (ulong)fileInfoOnDisk.Length) 162 | { 163 | Console.WriteLine($"Mismatching file size: {unprefixedPath} (is {fileInfoOnDisk.Length} bytes, should be {fileData.TotalSize})"); 164 | continue; 165 | } 166 | 167 | // Verify hash of the file on disk 168 | if (VERIFY_HASHES) 169 | { 170 | await using var fs = fileInfoOnDisk.Open(FileMode.Open, FileAccess.Read, FileShare.Read); 171 | using var sha = SHA1.Create(); 172 | var fileOnDiskChecksum = await sha.ComputeHashAsync(fs); 173 | 174 | if (!fileData.FileHash.SequenceEqual(fileOnDiskChecksum)) 175 | { 176 | Console.WriteLine($"Mismatching file hash: {unprefixedPath}"); 177 | continue; 178 | } 179 | } 180 | } 181 | 182 | Console.ForegroundColor = ConsoleColor.Blue; 183 | 184 | foreach (var file in allKnownDepotFiles.Keys.Where(file => !filenamesOnDisk.Contains(file))) 185 | { 186 | Console.WriteLine($"Missing file: {file}"); 187 | } 188 | 189 | Console.ResetColor(); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /SteamDepotFileVerifier/SteamClientUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.InteropServices; 7 | using Microsoft.Win32; 8 | using SteamKit2; 9 | 10 | namespace SteamDepotFileVerifier 11 | { 12 | public class SteamClientUtils 13 | { 14 | public readonly string SteamPath; 15 | 16 | public SteamClientUtils() 17 | { 18 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 19 | { 20 | var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Valve\\Steam") ?? 21 | RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) 22 | .OpenSubKey("SOFTWARE\\Valve\\Steam"); 23 | 24 | if (key != null && key.GetValue("SteamPath") is string steamPath) 25 | { 26 | SteamPath = steamPath; 27 | } 28 | } 29 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) 30 | { 31 | var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); 32 | var paths = new [] {".steam", ".steam/steam", ".steam/root", ".local/share/Steam"}; 33 | 34 | SteamPath = paths 35 | .Select(path => Path.Join(home, path)) 36 | .FirstOrDefault(steamPath => Directory.Exists(Path.Join(steamPath, "appcache"))); 37 | } 38 | else 39 | { 40 | throw new PlatformNotSupportedException(); 41 | } 42 | 43 | if (SteamPath == default) 44 | { 45 | throw new DirectoryNotFoundException("Unable to find Steam on your computer."); 46 | } 47 | 48 | SteamPath = Path.GetFullPath(SteamPath); 49 | } 50 | 51 | public IEnumerable GetLibraries() 52 | { 53 | var libraryFoldersPath = Path.Join(SteamPath, "steamapps", "libraryfolders.vdf"); 54 | var libraryFoldersKv = KeyValue.LoadAsText(libraryFoldersPath); 55 | var libraryFolders = new List 56 | { 57 | Path.Join(SteamPath, "steamapps") 58 | }; 59 | 60 | if (libraryFoldersKv != null) 61 | { 62 | libraryFolders.AddRange(libraryFoldersKv.Children 63 | .Where(libraryFolder => int.TryParse(libraryFolder.Name, out _)) 64 | .Select(x => Path.Join(x.Value, "steamapps")) 65 | ); 66 | } 67 | 68 | return libraryFolders; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /SteamDepotFileVerifier/SteamDepotFileVerifier.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | --------------------------------------------------------------------------------