From 93cd8ccdd9a19fae5bae268740fd2cbc8825875c Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Wed, 24 Oct 2018 23:46:35 -0400 Subject: [PATCH 1/2] Improve GameID support for mods and shortcuts. --- SteamKit2/SteamKit2/Types/GameID.cs | 31 ++++++++++++++++++++++++++ SteamKit2/Tests/GameIDFacts.cs | 34 +++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 SteamKit2/Tests/GameIDFacts.cs diff --git a/SteamKit2/SteamKit2/Types/GameID.cs b/SteamKit2/SteamKit2/Types/GameID.cs index 1419c9559..1a26d94bb 100644 --- a/SteamKit2/SteamKit2/Types/GameID.cs +++ b/SteamKit2/SteamKit2/Types/GameID.cs @@ -64,6 +64,36 @@ public GameID( Int32 nAppID ) : this( ( UInt64 )nAppID ) { } + /// + /// Initializes a new instance of the class. + /// + /// The base app id of the mod. + /// The game folder name of the mod. + public GameID( UInt32 nAppID, string modPath ) + : this(0) + { + AppID = nAppID; + AppType = GameType.GameMod; + ModID = BitConverter.ToUInt32(CryptoHelper.CRCHash(System.Text.Encoding.ASCII.GetBytes(modPath)), 0); + } + /// + /// Initializes a new instance of the class. + /// + /// The path to the executable, usually quoted. + /// The name of the application shortcut. + public GameID( string exePath, string appName ) + : this(0) + { + string combined = string.Empty; + if (exePath != null) + combined += exePath; + if (appName != null) + combined += appName; + + AppID = 0; + AppType = GameType.Shortcut; + ModID = BitConverter.ToUInt32(CryptoHelper.CRCHash(System.Text.Encoding.ASCII.GetBytes(combined)), 0); + } /// @@ -179,6 +209,7 @@ public UInt32 ModID set { gameid[ 32, 0xFFFFFFFF ] = ( UInt64 )value; + gameid[ 63, 0xFF ] = 1; } } diff --git a/SteamKit2/Tests/GameIDFacts.cs b/SteamKit2/Tests/GameIDFacts.cs new file mode 100644 index 000000000..06816480e --- /dev/null +++ b/SteamKit2/Tests/GameIDFacts.cs @@ -0,0 +1,34 @@ +using System; +using SteamKit2; +using Xunit; + +namespace Tests +{ + public class GameIDFacts + { + [Fact] + public void ModCRCCorrect() + { + GameID gameId = new GameID(420, "Research and Development"); + + Assert.True(gameId.IsMod); + Assert.Equal(gameId.AppID, 420u); + Assert.Equal(gameId, new GameID(10210309621176861092)); + + GameID gameId2 = new GameID(215, "hidden"); + + Assert.True(gameId2.IsMod); + Assert.Equal(gameId2.AppID, 215u); + Assert.Equal(gameId2, new GameID(9826266959967158487)); + } + + [Fact] + public void ShortcutCRCCorrect() + { + GameID gameId = new GameID("\"C:\\Program Files (x86)\\Git\\mingw64\\bin\\wintoast.exe\"", "Git for Windows"); + + Assert.True(gameId.IsShortcut); + Assert.Equal(gameId, new GameID(12754778225939316736)); + } + } +} From 4c4a538d37773fdaaa4b02b2a4c67887790cb61d Mon Sep 17 00:00:00 2001 From: Nick Hastings Date: Thu, 25 Oct 2018 17:05:24 -0400 Subject: [PATCH 2/2] Switch to more direct CRC call and fix encoding. --- SteamKit2/SteamKit2/Types/GameID.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SteamKit2/SteamKit2/Types/GameID.cs b/SteamKit2/SteamKit2/Types/GameID.cs index 1a26d94bb..4ac122ede 100644 --- a/SteamKit2/SteamKit2/Types/GameID.cs +++ b/SteamKit2/SteamKit2/Types/GameID.cs @@ -74,7 +74,7 @@ public GameID( UInt32 nAppID, string modPath ) { AppID = nAppID; AppType = GameType.GameMod; - ModID = BitConverter.ToUInt32(CryptoHelper.CRCHash(System.Text.Encoding.ASCII.GetBytes(modPath)), 0); + ModID = Crc32.Compute(System.Text.Encoding.UTF8.GetBytes(modPath)); } /// /// Initializes a new instance of the class. @@ -92,7 +92,7 @@ public GameID( string exePath, string appName ) AppID = 0; AppType = GameType.Shortcut; - ModID = BitConverter.ToUInt32(CryptoHelper.CRCHash(System.Text.Encoding.ASCII.GetBytes(combined)), 0); + ModID = Crc32.Compute(System.Text.Encoding.UTF8.GetBytes(combined)); }