Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions SAM.Game/Manager.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 77 additions & 1 deletion SAM.Game/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal partial class Manager : Form
{
private readonly long _GameId;
private readonly API.Client _SteamClient;
private readonly DateTime _SAMStartDate;

private readonly WebClient _IconDownloader = new();

Expand All @@ -52,7 +53,7 @@ internal partial class Manager : Form

//private API.Callback<APITypes.UserStatsStored> UserStatsStoredCallback;

public Manager(long gameId, API.Client client)
public Manager(long gameId, API.Client client, DateTime samStartDate)
{
this.InitializeComponent();

Expand Down Expand Up @@ -85,6 +86,7 @@ public Manager(long gameId, API.Client client)

this._GameId = gameId;
this._SteamClient = client;
this._SAMStartDate = samStartDate;

this._IconDownloader.DownloadDataCompleted += this.OnIconDownload;

Expand Down Expand Up @@ -840,6 +842,80 @@ private void OnResetAllStats(object sender, EventArgs e)
this.RefreshStats();
}

private void OnRevertAchievements(object sender, EventArgs e)
{
int unlockedAchievementCount = 0;
int totalAchievementCount = this._AchievementListView.Items.Count;

if (MessageBox.Show(
$"Do you want to reset your achievements after {_SAMStartDate}?",
"Warning",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) == DialogResult.No)
{
return;
}

if (this._AchievementListView.Items.Count == 0 && this._AchievementListView.Items.Count < 5)
{
return;
}

List<Stats.AchievementInfo> achievements = new();
foreach (ListViewItem item in this._AchievementListView.Items)
{
if (item.Tag is not Stats.AchievementInfo achievementInfo ||
achievementInfo.IsAchieved == false)
{
continue;
}

unlockedAchievementCount++;

// UnlockTime can not be null, because we've already checked if it's achieved.
DateTime achievementDate = (DateTime)achievementInfo.UnlockTime;

if (achievementDate > _SAMStartDate)
{
achievementInfo.IsAchieved = false;
achievements.Add(achievementInfo);
}
}

if (achievements.Count == 0)
{
return;
}

if (MessageBox.Show(
$"{unlockedAchievementCount} out of {totalAchievementCount} achievements unlocked. There are {achievements.Count} achievements unlocked after {_SAMStartDate}\n" +
$"Current Completion Rate: {((unlockedAchievementCount / (float)totalAchievementCount) * 100).ToString("N2", CultureInfo.InvariantCulture)}%\n" +
$"Completion Rate After Reset: {(((unlockedAchievementCount - achievements.Count) / (float)totalAchievementCount) * 100).ToString("N2", CultureInfo.InvariantCulture)}%\n" +
$"Are you sure?",
"Warning",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) == DialogResult.No)
{
return;
}

foreach (var info in achievements)
{
if (this._SteamClient.SteamUserStats.SetAchievement(info.Id, info.IsAchieved) == false)
{
MessageBox.Show(
this,
$"An error occurred while setting the state for {info.Id}, aborting store.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
}

Application.Exit();
}

private void OnCheckAchievement(object sender, ItemCheckEventArgs e)
{
if (sender != this._AchievementListView)
Expand Down
15 changes: 13 additions & 2 deletions SAM.Game/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal static class Program
public static void Main(string[] args)
{
long appId;
DateTime samStartDate;

if (args.Length == 0)
{
Expand All @@ -49,6 +50,16 @@ public static void Main(string[] args)
return;
}

if (DateTime.TryParse(args[1], out samStartDate) == false)
{
MessageBox.Show(
"Could not parse SAM Start Date from command line argument.",
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}

if (API.Steam.GetInstallPath() == Application.StartupPath)
{
MessageBox.Show(
Expand All @@ -71,7 +82,7 @@ public static void Main(string[] args)
{
MessageBox.Show(
"Steam is not running. Please start Steam then run this tool again.\n\n" +
"If you have the game through Family Share, the game may be locked due to\n" +
"If you have the game through Family Share, the game may be locked due to\n\n" +
"the Family Share account actively playing a game.\n\n" +
"(" + e.Message + ")",
"Error",
Expand Down Expand Up @@ -109,7 +120,7 @@ public static void Main(string[] args)

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Manager(appId, client));
Application.Run(new Manager(appId, client, samStartDate));
}
}
}
Expand Down
Loading