Skip to content

Commit

Permalink
Merge pull request #602 from SteamRE/gameid-modshortcut
Browse files Browse the repository at this point in the history
Improve GameID support for mods and shortcuts
  • Loading branch information
yaakov-h authored Oct 25, 2018
2 parents 9a79a75 + 4c4a538 commit 8ea1d6a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
31 changes: 31 additions & 0 deletions SteamKit2/SteamKit2/Types/GameID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ public GameID( Int32 nAppID )
: this( ( UInt64 )nAppID )
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GameID"/> class.
/// </summary>
/// <param name="nAppID">The base app id of the mod.</param>
/// <param name="modPath">The game folder name of the mod.</param>
public GameID( UInt32 nAppID, string modPath )
: this(0)
{
AppID = nAppID;
AppType = GameType.GameMod;
ModID = Crc32.Compute(System.Text.Encoding.UTF8.GetBytes(modPath));
}
/// <summary>
/// Initializes a new instance of the <see cref="GameID"/> class.
/// </summary>
/// <param name="exePath">The path to the executable, usually quoted.</param>
/// <param name="appName">The name of the application shortcut.</param>
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 = Crc32.Compute(System.Text.Encoding.UTF8.GetBytes(combined));
}


/// <summary>
Expand Down Expand Up @@ -179,6 +209,7 @@ public UInt32 ModID
set
{
gameid[ 32, 0xFFFFFFFF ] = ( UInt64 )value;
gameid[ 63, 0xFF ] = 1;
}
}

Expand Down
34 changes: 34 additions & 0 deletions SteamKit2/Tests/GameIDFacts.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
}

0 comments on commit 8ea1d6a

Please sign in to comment.