From 1c181a351bf1a4dbd36c8c750efd746963aaeac2 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Mon, 27 Jun 2011 01:27:57 -0500 Subject: [PATCH] Allow downloading of encrypted content. --- DepotDownloader/CDRManager.cs | 52 +++++++++++++++++++++++++++- DepotDownloader/ContentDownloader.cs | 4 ++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index c97c73c9..5fdaa02c 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -25,8 +25,23 @@ namespace DepotDownloader [BlobField( FieldKey = CDRAppRecordFields.eFieldCurrentVersionId, Depth = 1 )] public int CurrentVersion { get; set; } + [BlobField( FieldKey = CDRAppRecordFields.eFieldVersionsRecord, Complex = true, Depth = 1 )] + public List Versions { get; private set; } + [BlobField( FieldKey = CDRAppRecordFields.eFieldFilesystemsRecord, Complex = true, Depth = 1 )] - public List FileSystems { get; set; } + public List FileSystems { get; private set; } + } + + class AppVersion + { + [BlobField( FieldKey = CDRAppVersionFields.eFieldVersionId )] + public uint VersionID { get; set; } + + [BlobField( FieldKey = CDRAppVersionFields.eFieldDepotEncryptionKey )] + public string DepotEncryptionKey { get; set; } + + [BlobField( FieldKey = CDRAppVersionFields.eFieldIsEncryptionKeyAvailable )] + public bool IsEncryptionKeyAvailable { get; set; } } class FileSystem @@ -124,6 +139,28 @@ namespace DepotDownloader return app.CurrentVersion; } + public static byte[] GetDepotEncryptionKey( int depotId, int version ) + { + App app = GetAppBlob( depotId ); + + if ( app == null ) + { + return null; + } + + foreach ( AppVersion ver in app.Versions ) + { + if ( ver.VersionID == version ) + { + if ( ver.IsEncryptionKeyAvailable ) + return DecodeHexString( ver.DepotEncryptionKey ); + break; + } + } + + return null; + } + public static List GetDepotIDsForGameserver( string gameName ) { List appIDs = new List(); @@ -171,5 +208,18 @@ namespace DepotDownloader return null; } } + static byte[] DecodeHexString( string hex ) + { + if ( hex == null ) + return null; + + int chars = hex.Length; + byte[] bytes = new byte [ chars / 2 ]; + + for ( int i = 0 ; i < chars ; i += 2 ) + bytes[ i / 2 ] = Convert.ToByte( hex.Substring( i, 2 ), 16 ); + + return bytes; + } } } diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index ae0df17f..bc36a625 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -122,6 +122,8 @@ namespace DepotDownloader } } + byte[] cryptKey = CDRManager.GetDepotEncryptionKey( depotId, depotVersion ); + for ( int x = 0 ; x < manifest.Nodes.Count ; ++x ) { var dirEntry = manifest.Nodes[ x ]; @@ -192,7 +194,7 @@ namespace DepotDownloader if ( fi.Exists && fi.Length == dirEntry.SizeOrCount ) continue; - var file = session.DownloadFile( dirEntry, ContentServerClient.StorageSession.DownloadPriority.High ); + var file = session.DownloadFile( dirEntry, ContentServerClient.StorageSession.DownloadPriority.High, cryptKey ); File.WriteAllBytes( downloadPath, file ); }