diff --git a/SAM.API/Wrappers/SteamUserStats013.cs b/SAM.API/Wrappers/SteamUserStats013.cs index 23afe44f..a1637f0d 100644 --- a/SAM.API/Wrappers/SteamUserStats013.cs +++ b/SAM.API/Wrappers/SteamUserStats013.cs @@ -160,6 +160,32 @@ public bool GetAchievementAndUnlockTime(string name, out bool isAchieved, out ui } #endregion + #region GetGlobalAchievementPercantage + [UnmanagedFunctionPointer(CallingConvention.ThisCall)] + private delegate bool NativeRequestGlobalAchievementPercentages(IntPtr self); + + public bool RequestGlobalAchievementPercentages() + { + var call = this.GetFunction(this.Functions.RequestGlobalAchievementPercentages); + return call(this.ObjectAddress); + } + #endregion + + #region GetAchievementAchievedPercent + [UnmanagedFunctionPointer(CallingConvention.ThisCall)] + private delegate bool NativeGetAchievementAchievedPercent( + IntPtr self, + [MarshalAs(UnmanagedType.LPStr)] string achievementName, + out float percent + ); + + public bool GetAchievementAchievedPercent(string achievementName, out float percent) + { + var call = this.GetFunction(this.Functions.GetAchievementAchievedPercent); + return call(this.ObjectAddress, achievementName, out percent); + } + #endregion + #region StoreStats [UnmanagedFunctionPointer(CallingConvention.ThisCall)] [return: MarshalAs(UnmanagedType.I1)] diff --git a/SAM.Game/Manager.Designer.cs b/SAM.Game/Manager.Designer.cs index 5d783e02..36bca64a 100644 --- a/SAM.Game/Manager.Designer.cs +++ b/SAM.Game/Manager.Designer.cs @@ -48,6 +48,7 @@ private void InitializeComponent() this._AchievementNameColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this._AchievementDescriptionColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this._AchievementUnlockTimeColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this._AchievementGlobarProgressColumnHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this._AchievementsToolStrip = new System.Windows.Forms.ToolStrip(); this._LockAllButton = new System.Windows.Forms.ToolStripButton(); this._InvertAllButton = new System.Windows.Forms.ToolStripButton(); @@ -89,7 +90,7 @@ private void InitializeComponent() this._ResetButton}); this._MainToolStrip.Location = new System.Drawing.Point(0, 0); this._MainToolStrip.Name = "_MainToolStrip"; - this._MainToolStrip.Size = new System.Drawing.Size(712, 25); + this._MainToolStrip.Size = new System.Drawing.Size(1172, 25); this._MainToolStrip.TabIndex = 1; // // _StoreButton @@ -139,7 +140,7 @@ private void InitializeComponent() this._DownloadStatusLabel}); this._MainStatusStrip.Location = new System.Drawing.Point(0, 370); this._MainStatusStrip.Name = "_MainStatusStrip"; - this._MainStatusStrip.Size = new System.Drawing.Size(712, 22); + this._MainStatusStrip.Size = new System.Drawing.Size(1172, 22); this._MainStatusStrip.TabIndex = 4; // // _CountryStatusLabel @@ -150,7 +151,7 @@ private void InitializeComponent() // _GameStatusLabel // this._GameStatusLabel.Name = "_GameStatusLabel"; - this._GameStatusLabel.Size = new System.Drawing.Size(555, 17); + this._GameStatusLabel.Size = new System.Drawing.Size(1157, 17); this._GameStatusLabel.Spring = true; this._GameStatusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // @@ -177,7 +178,7 @@ private void InitializeComponent() this._MainTabControl.Location = new System.Drawing.Point(8, 33); this._MainTabControl.Name = "_MainTabControl"; this._MainTabControl.SelectedIndex = 0; - this._MainTabControl.Size = new System.Drawing.Size(696, 334); + this._MainTabControl.Size = new System.Drawing.Size(1156, 334); this._MainTabControl.TabIndex = 5; // // _AchievementsTabPage @@ -187,7 +188,7 @@ private void InitializeComponent() this._AchievementsTabPage.Location = new System.Drawing.Point(4, 22); this._AchievementsTabPage.Name = "_AchievementsTabPage"; this._AchievementsTabPage.Padding = new System.Windows.Forms.Padding(3); - this._AchievementsTabPage.Size = new System.Drawing.Size(688, 308); + this._AchievementsTabPage.Size = new System.Drawing.Size(1148, 308); this._AchievementsTabPage.TabIndex = 0; this._AchievementsTabPage.Text = "Achievements"; this._AchievementsTabPage.UseVisualStyleBackColor = true; @@ -201,7 +202,8 @@ private void InitializeComponent() this._AchievementListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this._AchievementNameColumnHeader, this._AchievementDescriptionColumnHeader, - this._AchievementUnlockTimeColumnHeader}); + this._AchievementUnlockTimeColumnHeader, + this._AchievementGlobarProgressColumnHeader}); this._AchievementListView.Dock = System.Windows.Forms.DockStyle.Fill; this._AchievementListView.ForeColor = System.Drawing.Color.White; this._AchievementListView.FullRowSelect = true; @@ -210,7 +212,7 @@ private void InitializeComponent() this._AchievementListView.LargeImageList = this._AchievementImageList; this._AchievementListView.Location = new System.Drawing.Point(3, 28); this._AchievementListView.Name = "_AchievementListView"; - this._AchievementListView.Size = new System.Drawing.Size(682, 277); + this._AchievementListView.Size = new System.Drawing.Size(1142, 277); this._AchievementListView.SmallImageList = this._AchievementImageList; this._AchievementListView.Sorting = System.Windows.Forms.SortOrder.Ascending; this._AchievementListView.TabIndex = 4; @@ -233,6 +235,11 @@ private void InitializeComponent() this._AchievementUnlockTimeColumnHeader.Text = "Unlock Time"; this._AchievementUnlockTimeColumnHeader.Width = 160; // + // _AchievementGlobarProgressColumnHeader + // + this._AchievementGlobarProgressColumnHeader.Text = "Global Progress"; + this._AchievementGlobarProgressColumnHeader.Width = 97; + // // _AchievementsToolStrip // this._AchievementsToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -248,7 +255,7 @@ private void InitializeComponent() this._MatchingStringTextBox}); this._AchievementsToolStrip.Location = new System.Drawing.Point(3, 3); this._AchievementsToolStrip.Name = "_AchievementsToolStrip"; - this._AchievementsToolStrip.Size = new System.Drawing.Size(682, 25); + this._AchievementsToolStrip.Size = new System.Drawing.Size(1142, 25); this._AchievementsToolStrip.TabIndex = 5; // // _LockAllButton @@ -333,7 +340,7 @@ private void InitializeComponent() this._StatisticsTabPage.Location = new System.Drawing.Point(4, 22); this._StatisticsTabPage.Name = "_StatisticsTabPage"; this._StatisticsTabPage.Padding = new System.Windows.Forms.Padding(3); - this._StatisticsTabPage.Size = new System.Drawing.Size(688, 308); + this._StatisticsTabPage.Size = new System.Drawing.Size(1148, 308); this._StatisticsTabPage.TabIndex = 1; this._StatisticsTabPage.Text = "Statistics"; this._StatisticsTabPage.UseVisualStyleBackColor = true; @@ -371,7 +378,7 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(712, 392); + this.ClientSize = new System.Drawing.Size(1172, 392); this.Controls.Add(this._MainToolStrip); this.Controls.Add(this._MainTabControl); this.Controls.Add(this._MainStatusStrip); @@ -426,5 +433,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripTextBox _MatchingStringTextBox; private System.Windows.Forms.ColumnHeader _AchievementUnlockTimeColumnHeader; private System.Windows.Forms.CheckBox _EnableStatsEditingCheckBox; + private System.Windows.Forms.ColumnHeader _AchievementGlobarProgressColumnHeader; } } diff --git a/SAM.Game/Manager.cs b/SAM.Game/Manager.cs index 319b6cec..e17f93ce 100644 --- a/SAM.Game/Manager.cs +++ b/SAM.Game/Manager.cs @@ -20,6 +20,7 @@ * distribution. */ +using SAM.API; using System; using System.Collections.Generic; using System.ComponentModel; @@ -98,6 +99,8 @@ public Manager(long gameId, API.Client client) base.Text += " | " + this._GameId.ToString(CultureInfo.InvariantCulture); } + this._SteamClient.SteamUserStats.RequestGlobalAchievementPercentages(); + this._UserStatsReceivedCallback = client.CreateAndRegisterCallback(); this._UserStatsReceivedCallback.OnRun += this.OnUserStatsReceived; @@ -431,7 +434,7 @@ private void GetAchievements() bool wantLocked = this._DisplayLockedOnlyButton.Checked == true; bool wantUnlocked = this._DisplayUnlockedOnlyButton.Checked == true; - + foreach (var def in this._AchievementDefinitions) { if (string.IsNullOrEmpty(def.Id) == true) @@ -459,12 +462,18 @@ private void GetAchievements() if (textSearch != null) { - if (def.Name.IndexOf(textSearch, StringComparison.OrdinalIgnoreCase) < 0 || - def.Description.IndexOf(textSearch, StringComparison.OrdinalIgnoreCase) < 0) + string[] searchTerms = textSearch.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + bool nameMatches = searchTerms.All(term => def.Name.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0); + bool descriptionMatches = searchTerms.All(term => def.Description.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0); + + if (!nameMatches && !descriptionMatches) { continue; } - } + } + + _SteamClient.SteamUserStats.GetAchievementAchievedPercent(def.Id, out float percentage); Stats.AchievementInfo info = new() { @@ -478,6 +487,7 @@ private void GetAchievements() Permission = def.Permission, Name = def.Name, Description = def.Description, + Progress = percentage, }; ListViewItem item = new() @@ -504,6 +514,8 @@ private void GetAchievements() ? info.UnlockTime.Value.ToString() : ""); + item.SubItems.Add((percentage > 0 ? $"{percentage}%" : "Error").ToString()); + info.ImageIndex = 0; this.AddAchievementToIconQueue(info, false); @@ -894,4 +906,4 @@ private void OnFilterUpdate(object sender, KeyEventArgs e) this.GetAchievements(); } } -} +} \ No newline at end of file diff --git a/SAM.Game/Stats/AchievementInfo.cs b/SAM.Game/Stats/AchievementInfo.cs index 90ea07b6..e1bd4610 100644 --- a/SAM.Game/Stats/AchievementInfo.cs +++ b/SAM.Game/Stats/AchievementInfo.cs @@ -35,6 +35,7 @@ internal class AchievementInfo public string IconLocked; public string Name; public string Description; + public float Progress; public ListViewItem Item; #region public int ImageIndex;