diff --git a/src/Starward.Core/GameRegistry.cs b/src/Starward.Core/GameRegistry.cs index 9227557a0..cbea99d34 100644 --- a/src/Starward.Core/GameRegistry.cs +++ b/src/Starward.Core/GameRegistry.cs @@ -60,6 +60,7 @@ public class GameRegistry public const string App_LastUserID_h2841727341 = "App_LastUserID_h2841727341"; public const string GENERAL_DATA_V2_LastLoginUserId_h47158221 = "GENERAL_DATA_V2_LastLoginUserId_h47158221"; public const string GraphicsSettings_Model_h2986158309 = "GraphicsSettings_Model_h2986158309"; + public const string __LastUid___h2153286551 = "__LastUid___h2153286551"; diff --git a/src/Starward/Converters/GameAccountUidStringConverter.cs b/src/Starward/Converters/GameAccountUidStringConverter.cs index ad0891c2c..9a356e06e 100644 --- a/src/Starward/Converters/GameAccountUidStringConverter.cs +++ b/src/Starward/Converters/GameAccountUidStringConverter.cs @@ -9,14 +9,14 @@ public object Convert(object value, Type targetType, object parameter, string la { return value switch { - int uid when uid > 0 => uid.ToString(), + long uid when uid > 0 => uid.ToString(), _ => string.Empty }; } public object ConvertBack(object value, Type targetType, object parameter, string language) { - if (int.TryParse(value as string, out int uid)) + if (long.TryParse(value as string, out long uid)) { return uid; } diff --git a/src/Starward/Models/GameAccount.cs b/src/Starward/Models/GameAccount.cs index a9086de22..806ba0851 100644 --- a/src/Starward/Models/GameAccount.cs +++ b/src/Starward/Models/GameAccount.cs @@ -11,8 +11,8 @@ public class GameAccount : ObservableObject public GameBiz GameBiz { get; set; } - private int _Uid; - public int Uid + private long _Uid; + public long Uid { get => _Uid; set => SetProperty(ref _Uid, value); diff --git a/src/Starward/Pages/GameLauncherPage.xaml.cs b/src/Starward/Pages/GameLauncherPage.xaml.cs index da5b2bb7c..74d09ec89 100644 --- a/src/Starward/Pages/GameLauncherPage.xaml.cs +++ b/src/Starward/Pages/GameLauncherPage.xaml.cs @@ -511,7 +511,7 @@ private void GetGameAccount() { try { - if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer() || CurrentGameBiz.ToGame() is GameBiz.ZZZ) + if (AppConfig.DisableGameAccountSwitcher || CurrentGameBiz.IsBilibiliServer()) { StackPanel_Account.Visibility = Visibility.Collapsed; return; diff --git a/src/Starward/Pages/SelfQueryPage.xaml.cs b/src/Starward/Pages/SelfQueryPage.xaml.cs index f091778d7..59218ebe7 100644 --- a/src/Starward/Pages/SelfQueryPage.xaml.cs +++ b/src/Starward/Pages/SelfQueryPage.xaml.cs @@ -563,9 +563,17 @@ private void LoadMonthQueryItems(int type, string month) } if (gameBiz.ToGame() is GameBiz.ZZZ) { - ZZZQueryItemList = dapper.Query(""" + var list = ZZZQueryItemList = dapper.Query(""" SELECT * FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND DateTime LIKE @month ORDER BY DateTime DESC; """, new { uid, type, month = month + "%" }).ToList(); + if (type is (int)ZZZQueryType.PurchaseGift) + { + foreach (var item in list) + { + item.Reason = item.ItemName; + } + } + ZZZQueryItemList = list; MonthAddNum = ZZZQueryItemList.Where(x => x.AddNum > 0).Sum(x => x.AddNum); MonthSubNum = ZZZQueryItemList.Where(x => x.AddNum < 0).Sum(x => x.AddNum); } diff --git a/src/Starward/Services/GameAccountService.cs b/src/Starward/Services/GameAccountService.cs index a3041f088..f05fcfb51 100644 --- a/src/Starward/Services/GameAccountService.cs +++ b/src/Starward/Services/GameAccountService.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; -using System.Text.RegularExpressions; +using System.Text; namespace Starward.Services; @@ -37,9 +37,9 @@ public GameAccountService(ILogger logger, DatabaseService da var key = biz.GetGameRegistryKey(); var keyName = (int)biz switch { - 11 or 21 or 31 or 14 or 24 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + 11 or 21 or 31 or 14 or 24 or 41 or 44 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, 13 => GameRegistry.MIHOYOSDK_ADL_0, - 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, + 12 or 22 or (>= 32 and <= 36) or 42 => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, _ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"), }; @@ -63,10 +63,14 @@ 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h115894 } else if (biz is GameBiz.hk4e_cn or GameBiz.hk4e_global) { - List uids = GetUidsFromRegistry(biz).ToList(); - if (uids.Count == 1) + byte[]? uidBytes = Registry.GetValue(key, GameRegistry.__LastUid___h2153286551, 0) as byte[]; + if (uidBytes is not null) { - account.Uid = uids[0]; + string uidStr = Encoding.UTF8.GetString(uidBytes).Trim(); + if (long.TryParse(uidStr, out long uid)) + { + account.Uid = uid; + } } } return account; @@ -76,26 +80,6 @@ 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h115894 - private IEnumerable GetUidsFromRegistry(GameBiz biz) - { - if (biz is GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_bilibili) - { - string key = biz.GetGameRegistryKey().Replace(@"HKEY_CURRENT_USER\", ""); - List usds = Registry.CurrentUser.OpenSubKey(key)?.GetValueNames()?.Where(x => x.StartsWith("USD_"))?.ToList() ?? []; - foreach (var usd in usds) - { - string uidstr = Regex.Match(usd, @"USD_(\d+)_h").Groups[1].Value; - if (int.TryParse(uidstr, out int uid)) - { - if (uid != 0) - { - yield return uid; - } - } - } - } - } - public IEnumerable GetGameAccountsFromDatabase(GameBiz biz) @@ -137,10 +121,6 @@ public IEnumerable GetSuggestionUids(GameBiz biz) { using var dapper = _database.CreateConnection(); List uids = dapper.Query("SELECT DISTINCT Uid FROM GameAccount WHERE GameBiz = @biz AND Uid > 0;", new { biz }).ToList(); - if (biz is GameBiz.hk4e_cn or GameBiz.hk4e_global) - { - uids.AddRange(GetUidsFromRegistry(biz)); - } return uids.Distinct().Order(); } @@ -172,19 +152,23 @@ public void ChangeGameAccount(GameAccount account) var key = account.GameBiz.GetGameRegistryKey(); var keyName = (int)account.GameBiz switch { - 11 or 21 or 31 or 14 or 24 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, + 11 or 21 or 31 or 14 or 24 or 41 or 44 => GameRegistry.MIHOYOSDK_ADL_PROD_CN_h3123967166, 13 => GameRegistry.MIHOYOSDK_ADL_0, - 12 or 22 or (>= 32 and <= 36) => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, + 12 or 22 or (>= 32 and <= 36) or 42 => GameRegistry.MIHOYOSDK_ADL_PROD_OVERSEA_h1158948810, _ => throw new ArgumentOutOfRangeException($"Unknown region {account.GameBiz}"), }; Registry.SetValue(key, keyName, account.Value); if (account.GameBiz.ToGame() is GameBiz.StarRail) { - Registry.SetValue(key, GameRegistry.App_LastUserID_h2841727341, account.Uid); + Registry.SetValue(key, GameRegistry.App_LastUserID_h2841727341, (int)account.Uid, RegistryValueKind.DWord); } if (account.GameBiz.ToGame() is GameBiz.Honkai3rd) { - Registry.SetValue(key, GameRegistry.GENERAL_DATA_V2_LastLoginUserId_h47158221, account.Uid); + Registry.SetValue(key, GameRegistry.GENERAL_DATA_V2_LastLoginUserId_h47158221, (int)account.Uid, RegistryValueKind.DWord); + } + if (account.GameBiz.ToGame() is GameBiz.GenshinImpact) + { + Registry.SetValue(key, GameRegistry.__LastUid___h2153286551, Encoding.UTF8.GetBytes($"{account.Uid}\0")); } _logger.LogInformation("Change account {name} ({biz}) successfully!", account.Name, account.GameBiz); } diff --git a/src/Starward/Services/SelfQueryService.cs b/src/Starward/Services/SelfQueryService.cs index 80b1460e5..a1971b9d5 100644 --- a/src/Starward/Services/SelfQueryService.cs +++ b/src/Starward/Services/SelfQueryService.cs @@ -280,12 +280,22 @@ public List GetZZZUids() public (long Add, long Sub) GetZZZQueryItemsNumSum(long uid, ZZZQueryType type) { using var dapper = _databaseService.CreateConnection(); - long add = dapper.QueryFirstOrDefault(""" - SELECT IFNULL(SUM(AddNum), 0) FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND AddNum>0; - """, new { uid, type }); - long sub = dapper.QueryFirstOrDefault(""" - SELECT IFNULL(SUM(AddNum), 0) FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND AddNum<0; - """, new { uid, type }); + long add = 0, sub = 0; + if (type is ZZZQueryType.PurchaseGift) + { + add = dapper.QueryFirstOrDefault(""" + SELECT COUNT(*) FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type; + """, new { uid, type }); + } + else + { + add = dapper.QueryFirstOrDefault(""" + SELECT IFNULL(SUM(AddNum), 0) FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND AddNum>0; + """, new { uid, type }); + sub = dapper.QueryFirstOrDefault(""" + SELECT IFNULL(SUM(AddNum), 0) FROM ZZZQueryItem WHERE Uid=@uid AND Type=@type AND AddNum<0; + """, new { uid, type }); + } return (add, sub); }