diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index 9a9e1163..75170b89 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -12,6 +12,9 @@ namespace DepotDownloader { [BlobField( FieldKey = CDRFields.eFieldApplicationsRecord, Depth = 1, Complex = true )] public List Apps { get; set; } + + [BlobField( FieldKey = CDRFields.eFieldSubscriptionsRecord, Depth = 1, Complex = true )] + public List Subs { get; set; } } class App @@ -35,6 +38,15 @@ namespace DepotDownloader public Dictionary UserDefined { get; private set; } } + class Sub + { + [BlobField( FieldKey = CDRSubRecordFields.eFieldSubId, Depth = 1 )] + public int SubID { get; set; } + + [BlobField( FieldKey = CDRSubRecordFields.eFieldAppIdsRecord, Depth = 1 )] + public List AppIDs { get; private set; } + } + class AppVersion { [BlobField( FieldKey = CDRAppVersionFields.eFieldVersionId )] @@ -121,6 +133,11 @@ namespace DepotDownloader return cdrObj.Apps.Find( ( app ) => app.AppID == appID ); } + static Sub GetSubBlob( int subID ) + { + return cdrObj.Subs.Find( ( sub ) => sub.SubID == subID ); + } + public static string GetDepotName( int depotId ) { // Match hardcoded names from hldsupdatetool for certain HL1 depots @@ -352,6 +369,16 @@ namespace DepotDownloader Console.WriteLine( "\t\"{0}\"", game ); } + public static bool SubHasDepot( int subId, int depotId ) + { + Sub sub = GetSubBlob( subId ); + + if ( sub == null ) + return false; + + return sub.AppIDs.Contains( depotId ); + } + static byte[] GetCdr() { try diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index ffb408e8..0ffeec26 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -108,6 +108,20 @@ namespace DepotDownloader return false; } + static bool AccountHasAccess( int depotId ) + { + if ( steam3 == null || steam3.Licenses == null ) + return CDRManager.SubHasDepot( 0, depotId ); + + foreach ( var license in steam3.Licenses ) + { + if ( CDRManager.SubHasDepot( ( int )license.PackageID, depotId ) ) + return true; + } + + return false; + } + public static void Download( int depotId, int depotVersion, int cellId, string username, string password, bool onlyManifest, bool gameServer, bool exclude, string installDir, string[] fileList ) { if ( !CreateDirectories( depotId, depotVersion, ref installDir ) ) @@ -135,6 +149,17 @@ namespace DepotDownloader credentials = GetCredentials( ( uint )depotId, username, password ); } + if ( !AccountHasAccess( depotId ) ) + { + string contentName = CDRManager.GetDepotName( depotId ); + Console.WriteLine( "Depot {0} ({1}) is not available from this account.", depotId, contentName ); + + if ( steam3 != null ) + steam3.Disconnect(); + + return; + } + string manifestFile = Path.Combine( installDir, "manifest.bin" ); string txtManifest = Path.Combine( installDir, "manifest.txt" ); diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index c3dd5a96..c94ca21c 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using SteamKit2; using System.Threading; +using System.Collections.ObjectModel; namespace DepotDownloader { @@ -18,6 +19,12 @@ namespace DepotDownloader public byte[] AppTicket { get; set; } } + public ReadOnlyCollection Licenses + { + get; + private set; + } + SteamClient steamClient; SteamUser steamUser; @@ -90,7 +97,7 @@ namespace DepotDownloader if ( diff > STEAM3_TIMEOUT && !bConnected ) break; - if ( credentials.HasSessionToken && credentials.AppTicket != null ) + if ( credentials.HasSessionToken && credentials.AppTicket != null && Licenses != null ) break; if ( callback == null ) @@ -162,6 +169,21 @@ namespace DepotDownloader credentials.SessionToken = msg.SessionToken; credentials.HasSessionToken = true; } + + if ( callback.IsType() ) + { + var msg = callback as SteamApps.LicenseListCallback; + + if ( msg.Result != EResult.OK ) + { + Console.WriteLine( "Unable to get license list: {0} ", msg.Result ); + steamUser.LogOff(); + break; + } + + Console.WriteLine( "Got {0} licenses for account!", msg.LicenseList.Count ); + Licenses = msg.LicenseList; + } } credentialHandle.Set();