From a17713e1537c779b24164525d039c1eaf1fae647 Mon Sep 17 00:00:00 2001 From: Ryan Stecker Date: Fri, 27 Jan 2012 16:36:03 -0600 Subject: [PATCH] Fixed DepotDownloader for the latest SteamKit2 version. --- DepotDownloader/CDRManager.cs | 30 ++++++++++++++++++++++++++-- DepotDownloader/ContentDownloader.cs | 9 ++++++++- DepotDownloader/Program.cs | 1 + 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/DepotDownloader/CDRManager.cs b/DepotDownloader/CDRManager.cs index 1d3c663a..8630cf58 100644 --- a/DepotDownloader/CDRManager.cs +++ b/DepotDownloader/CDRManager.cs @@ -5,6 +5,8 @@ using System.Text; using System.IO; using SteamKit2; using System.Net; +using System.Security.Cryptography; +using SteamKit2.Blob; namespace DepotDownloader { @@ -190,7 +192,7 @@ namespace DepotDownloader if ( ver.VersionID == version ) { if ( ver.IsEncryptionKeyAvailable ) - return Utils.DecodeHexString( ver.DepotEncryptionKey ); + return DecodeHexString( ver.DepotEncryptionKey ); break; } } @@ -198,6 +200,20 @@ 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; + } + public static List GetDepotIDsForApp( int appId, bool allPlatforms ) { List depotIDs = new List(); @@ -403,12 +419,22 @@ namespace DepotDownloader if ( cdr == null ) return null; - return CryptoHelper.SHAHash( cdr ); + return SHAHash( cdr ); } catch { return null; } } + + static byte[] SHAHash( byte[] data ) + { + using ( SHA1Managed sha = new SHA1Managed() ) + { + byte[] output = sha.ComputeHash( data ); + + return output; + } + } } } diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 632bffca..9668faa1 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -561,7 +561,7 @@ namespace DepotDownloader foreach (var chunk in file.Chunks) { - string chunkID = Utils.EncodeHexString(chunk.ChunkID); + string chunkID = EncodeHexString(chunk.ChunkID); byte[] encrypted_chunk = cdnClient.DownloadDepotChunk(depotId, chunkID); byte[] chunk_data = cdnClient.ProcessChunk(encrypted_chunk, depotKey); @@ -749,5 +749,12 @@ namespace DepotDownloader return null; } + + static string EncodeHexString( byte[] input ) + { + return input.Aggregate( new StringBuilder(), + ( sb, v ) => sb.Append( v.ToString( "x2" ) ) + ).ToString(); + } } } diff --git a/DepotDownloader/Program.cs b/DepotDownloader/Program.cs index 3806426e..e9cd91b7 100644 --- a/DepotDownloader/Program.cs +++ b/DepotDownloader/Program.cs @@ -5,6 +5,7 @@ using System.Text; using SteamKit2; using System.IO; using System.Text.RegularExpressions; +using SteamKit2.Blob; namespace DepotDownloader {