Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
oureveryday committed Jun 5, 2023
1 parent 3328e4a commit 973dbb8
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 111 deletions.
9 changes: 7 additions & 2 deletions DepotDownloaderMod/AccountSettingsStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
Expand All @@ -20,13 +20,18 @@ class AccountSettingsStore
[ProtoMember(3, IsRequired = false)]
public Dictionary<string, string> LoginKeys { get; private set; }

// Member 3 was a Dictionary<string, string> for LoginKeys.

[ProtoMember(4, IsRequired = false)]
public Dictionary<string, string> LoginTokens { get; private set; }

string FileName;

AccountSettingsStore()
{
SentryData = new Dictionary<string, byte[]>();
ContentServerPenalty = new ConcurrentDictionary<string, int>();
LoginKeys = new Dictionary<string, string>();
LoginTokens = new Dictionary<string, string>();
}

static bool Loaded
Expand Down
52 changes: 17 additions & 35 deletions DepotDownloaderMod/ContentDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static class ContentDownloader
public const uint INVALID_APP_ID = uint.MaxValue;
public const uint INVALID_DEPOT_ID = uint.MaxValue;
public const ulong INVALID_MANIFEST_ID = ulong.MaxValue;
public const string DEFAULT_BRANCH = "Public";
public const string DEFAULT_BRANCH = "public";

public static DownloadConfig Config = new DownloadConfig();

Expand Down Expand Up @@ -247,9 +247,9 @@ static ulong GetSteam3DepotManifest(uint depotId, uint appId, string branch)
if (manifests.Children.Count == 0 && manifests_encrypted.Children.Count == 0)
return INVALID_MANIFEST_ID;

var node = manifests[branch].Children.Count > 0 ? manifests[branch]["gid"] : manifests[branch];
var node = manifests[branch]["gid"];

if (branch != "Public" && node == KeyValue.Invalid)
if (node == KeyValue.Invalid && !string.Equals(branch, DEFAULT_BRANCH, StringComparison.OrdinalIgnoreCase))
{
var node_encrypted = manifests_encrypted[branch];
if (node_encrypted != KeyValue.Invalid)
Expand All @@ -261,35 +261,23 @@ static ulong GetSteam3DepotManifest(uint depotId, uint appId, string branch)
Config.BetaPassword = password = Console.ReadLine();
}

var encrypted_v1 = node_encrypted["encrypted_gid"];
var encrypted_v2 = node_encrypted["encrypted_gid_2"];
var encrypted_gid = node_encrypted["gid"];

if (encrypted_v1 != KeyValue.Invalid)
if (encrypted_gid == KeyValue.Invalid)
{
var input = Util.DecodeHexString(encrypted_v1.Value);
var manifest_bytes = CryptoHelper.VerifyAndDecryptPassword(input, password);

if (manifest_bytes == null)
{
Console.WriteLine("Password was invalid for branch {0}", branch);
return INVALID_MANIFEST_ID;
}

return BitConverter.ToUInt64(manifest_bytes, 0);
encrypted_gid = node_encrypted["encrypted_gid_2"];
}

if (encrypted_v2 != KeyValue.Invalid)
if (encrypted_gid != KeyValue.Invalid)
{
// Submit the password to Steam now to get encryption keys
steam3.CheckAppBetaPassword(appId, Config.BetaPassword);

if (!steam3.AppBetaPasswords.ContainsKey(branch))
{
Console.WriteLine("Password was invalid for branch {0}", branch);
return INVALID_MANIFEST_ID;
}

var input = Util.DecodeHexString(encrypted_v2.Value);
var input = Util.DecodeHexString(encrypted_gid.Value);
byte[] manifest_bytes;
try
{
Expand All @@ -300,20 +288,15 @@ static ulong GetSteam3DepotManifest(uint depotId, uint appId, string branch)
Console.WriteLine("Failed to decrypt branch {0}: {1}", branch, e.Message);
return INVALID_MANIFEST_ID;
}

return BitConverter.ToUInt64(manifest_bytes, 0);
}

Console.WriteLine("Unhandled depot encryption for depotId {0}", depotId);
return INVALID_MANIFEST_ID;
}

return INVALID_MANIFEST_ID;
}

if (node.Value == null)
return INVALID_MANIFEST_ID;

return UInt64.Parse(node.Value);
}

Expand All @@ -328,11 +311,11 @@ static string GetAppName(uint depotId, uint appId)

public static bool InitializeSteam3(string username, string password)
{
string loginKey = null;
string loginToken = null;

if (username != null && Config.RememberPassword)
{
_ = AccountSettingsStore.Instance.LoginKeys.TryGetValue(username, out loginKey);
_ = AccountSettingsStore.Instance.LoginTokens.TryGetValue(username, out loginToken);
}


Expand All @@ -346,9 +329,9 @@ public static bool InitializeSteam3(string username, string password)
{
SentryFileHash = sentryFileHash,
Username = username,
Password = loginKey == null ? password : null,
Password = loginToken == null ? password : null,
ShouldRememberPassword = Config.RememberPassword,
LoginKey = loginKey,
AccessToken = loginToken,
LoginID = Config.LoginID ?? 0x534B32, // "SK2"
}
);
Expand All @@ -359,9 +342,9 @@ public static bool InitializeSteam3(string username, string password)
new SteamUser.LogOnDetails
{
Username = username,
Password = loginKey == null ? password : null,
Password = loginToken == null ? password : null,
ShouldRememberPassword = Config.RememberPassword,
LoginKey = loginKey,
AccessToken = loginToken,
LoginID = Config.LoginID ?? 0x534B32, // "SK2"
}
);
Expand Down Expand Up @@ -392,7 +375,6 @@ public static void ShutdownSteam3()
if (steam3 == null)
return;

steam3.TryWaitForLoginKey();
steam3.Disconnect();
}

Expand Down Expand Up @@ -636,10 +618,10 @@ static DepotDownloadInfo GetDepotInfo(uint depotId, uint appId, ulong manifestId
if (manifestId == INVALID_MANIFEST_ID)
{
manifestId = GetSteam3DepotManifest(depotId, appId, branch);
if (manifestId == INVALID_MANIFEST_ID && branch != "public")
if (manifestId == INVALID_MANIFEST_ID && !string.Equals(branch, DEFAULT_BRANCH, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Warning: Depot {0} does not have branch named \"{1}\". Trying public branch.", depotId, branch);
branch = "public";
Console.WriteLine("Warning: Depot {0} does not have branch named \"{1}\". Trying {2} branch.", depotId, branch, DEFAULT_BRANCH);
branch = DEFAULT_BRANCH;
manifestId = GetSteam3DepotManifest(depotId, appId, branch);
}

Expand Down
1 change: 1 addition & 0 deletions DepotDownloaderMod/DepotDownloaderMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.2.26" />
<PackageReference Include="QRCoder" Version="1.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion DepotDownloaderMod/DownloadConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class DownloadConfig
public int MaxServers { get; set; }
public int MaxDownloads { get; set; }

public string SuppliedPassword { get; set; }
public bool RememberPassword { get; set; }

// A Steam LoginID to allow multiple concurrent connections
public uint? LoginID { get; set; }

public bool UseQrCode { get; set; }

public bool UseManifestFile { get; set; }
public string ManifestFile { get; set; }
}
Expand Down
44 changes: 22 additions & 22 deletions DepotDownloaderMod/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static async Task<int> MainAsync(string[] args)


ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");

ContentDownloader.Config.UseQrCode = HasParameter(args, "-qr");
ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

var cellId = GetParameter(args, "-cellid", -1);
Expand Down Expand Up @@ -312,32 +312,32 @@ ex is ContentDownloaderException

static bool InitializeSteam(string username, string password)
{
if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !AccountSettingsStore.Instance.LoginKeys.ContainsKey(username)))
if (!ContentDownloader.Config.UseQrCode)
{
do
if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !AccountSettingsStore.Instance.LoginTokens.ContainsKey(username)))
{
Console.Write("Enter account password for \"{0}\": ", username);
if (Console.IsInputRedirected)
{
password = Console.ReadLine();
}
else
do
{
// Avoid console echoing of password
password = Util.ReadPassword();
}
Console.Write("Enter account password for \"{0}\": ", username);
if (Console.IsInputRedirected)
{
password = Console.ReadLine();
}
else
{
// Avoid console echoing of password
password = Util.ReadPassword();
}

Console.WriteLine();
} while (string.Empty == password);
}
else if (username == null)
{
Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
Console.WriteLine();
} while (string.Empty == password);
}
else if (username == null)
{
Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
}
}

// capture the supplied password in case we need to re-use it after checking the login key
ContentDownloader.Config.SuppliedPassword = password;

return ContentDownloader.InitializeSteam3(username, password);
}

Expand Down Expand Up @@ -419,7 +419,7 @@ static void PrintUsage()
Console.WriteLine("\t-app <#>\t\t\t\t- the AppID to download.");
Console.WriteLine("\t-depot <#>\t\t\t\t- the DepotID to download.");
Console.WriteLine("\t-manifest <id>\t\t\t- manifest id of content to download (requires -depot, default: current for branch).");
Console.WriteLine("\t-beta <branchname>\t\t\t- download from specified branch if available (default: Public).");
Console.WriteLine($"\t-beta <branchname>\t\t\t- download from specified branch if available (default: {ContentDownloader.DEFAULT_BRANCH}).");
Console.WriteLine("\t-betapassword <pass>\t\t- branch password if applicable.");
Console.WriteLine("\t-all-platforms\t\t\t- downloads all platform-specific depots when -app is used.");
Console.WriteLine("\t-os <os>\t\t\t\t- the operating system for which to download the game (windows, macos or linux, default: OS the program is currently running on)");
Expand Down
Loading

0 comments on commit 973dbb8

Please sign in to comment.