Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ZZZ] Add HoYoLab BattleChronicle page #1038

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 14 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ protected virtual async Task CommonSendAsync(HttpRequestMessage request, Cancell
#endregion


#region ZZZ

/// <summary>
/// Get ZZZ Role
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">杈撳叆鐨� <c>cookie</c> 涓虹┖</exception>
public abstract Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default);

#endregion


// 瀵板畤铦楃伨
// https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/api/rogue_locust?server=prod_gf_cn&role_id={uid}&need_detail=true

Expand Down
31 changes: 30 additions & 1 deletion src/Starward.Core/GameRecord/HoyolabClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class HoyolabClient : GameRecordClient

public override string UAContent => $"Mozilla/5.0 (Linux; Android 13; Pixel 5 Build/TQ3A.230901.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/118.0.0.0 Mobile Safari/537.36 miHoYoBBSOversea/{AppVersion}";

public override string AppVersion => "2.54.0";
public override string AppVersion => "2.59.0";

protected override string ApiSalt => "okr4obncj8bw5a65hbnn5oo6ixjc3l9w";

Expand Down Expand Up @@ -84,6 +84,7 @@ public override async Task<List<GameRecordRole>> GetAllGameRolesAsync(string coo
var list = new List<GameRecordRole>();
list.AddRange(await GetGenshinGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetStarRailGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetZZZGameRolesAsync(cookie, cancellationToken));
return list;
}

Expand Down Expand Up @@ -496,4 +497,32 @@ public override async Task<TrailblazeCalendarDetail> GetTrailblazeCalendarDetail
#endregion


#region ZZZ

/// <summary>
/// Get ZZZ Role
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">杈撳叆鐨� <c>cookie</c> 涓虹┖</exception>
public override async Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(cookie))
{
throw new ArgumentNullException(nameof(cookie));
}

const string url = "https://api-account-os.hoyolab.com/binding/api/getUserGameRolesByCookieToken?game_biz=nap_global";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, cookie);
request.Headers.Add(X_Request_With, com_mihoyo_hoyolab);
request.Headers.Add(Referer, "https://act.hoyolab.com");
var data = await CommonSendAsync<GameRecordRoleWrapper>(request, cancellationToken);
data.List?.ForEach(x => x.Cookie = cookie);
return data.List ?? new List<GameRecordRole>();
}

#endregion

}
32 changes: 31 additions & 1 deletion src/Starward.Core/GameRecord/HyperionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class HyperionClient : GameRecordClient

public override string UAContent => $"Mozilla/5.0 (Linux; Android 13; Pixel 5 Build/TQ3A.230901.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/118.0.0.0 Mobile Safari/537.36 miHoYoBBS/{AppVersion}";

public override string AppVersion => "2.71.1";
public override string AppVersion => "2.74.2";

protected override string ApiSalt => "t0qEgfub6cvueAPgR5m9aQWWVciEer7v";

Expand Down Expand Up @@ -81,6 +81,7 @@ public override async Task<List<GameRecordRole>> GetAllGameRolesAsync(string coo
var list = new List<GameRecordRole>();
list.AddRange(await GetGenshinGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetStarRailGameRolesAsync(cookie, cancellationToken));
list.AddRange(await GetZZZGameRolesAsync(cookie, cancellationToken));
return list;
}

Expand Down Expand Up @@ -554,6 +555,35 @@ public override async Task<TrailblazeCalendarDetail> GetTrailblazeCalendarDetail
#endregion


#region ZZZ

/// <summary>
/// Get ZZZ Role
/// </summary>
/// <param name="cookie"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException">杈撳叆鐨� <c>cookie</c> 涓虹┖</exception>
public override async Task<List<GameRecordRole>> GetZZZGameRolesAsync(string cookie, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(cookie))
{
throw new ArgumentNullException(nameof(cookie));
}
const string url = "https://api-takumi.mihoyo.com/binding/api/getUserGameRolesByCookie?game_biz=nap_cn";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, cookie);
request.Headers.Add(DS, CreateSecret2(url));
request.Headers.Add(X_Request_With, com_mihoyo_hyperion);
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_client_type, "5");
request.Headers.Add(Referer, "https://webstatic.mihoyo.com/");
var data = await CommonSendAsync<GameRecordRoleWrapper>(request, cancellationToken);
data.List?.ForEach(x => x.Cookie = cookie);
return data.List ?? new List<GameRecordRole>();
}

#endregion


}
16 changes: 8 additions & 8 deletions src/Starward/Controls/BBSWebBridge.xaml.cs
hinaloe marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Scighost 这个文件要是本地打开乱码要从GB 2312换成UTF-8。我这边看UTF-8打开是正常的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gongfuture Thanks for the follow up. You are correct, but I will put it back as it will be an unrelated change.

@Scighost Please re-check.

Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ public async Task LoadPageAsync(bool force = false)
{
(true, GameBiz.GenshinImpact) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=2",
(true, GameBiz.StarRail) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=6",
(true, GameBiz.ZZZ) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=8",
(true, GameBiz.ZZZ) => "https://act.hoyolab.com/app/mihoyo-zzz-game-record/m.html",
(false, GameBiz.GenshinImpact) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=2",
(false, GameBiz.StarRail) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=6",
(false, GameBiz.ZZZ) => "https://webstatic.mihoyo.com/app/community-game-records/?game_id=8",
(false, GameBiz.ZZZ) => "https://act.mihoyo.com/app/mihoyo-zzz-game-record/m.html",
_ => null,
};
if (url is not null)
Expand Down Expand Up @@ -645,19 +645,19 @@ private static string GetRandomString(int timestamp)
private class JsParam
{
/// <summary>
/// 方法名称
/// 鏂规硶鍚嶇О
/// </summary>
[JsonPropertyName("method")]
public string Method { get; set; }

/// <summary>
/// 数据 可以为空
/// 鏁版嵁 鍙互涓虹┖
/// </summary>
[JsonPropertyName("payload")]
public JsonNode? Payload { get; set; }

/// <summary>
/// 回调的名称,调用 JavaScript:mhyWebBridge 时作为首个参数传入
/// 鍥炶皟鐨勫悕绉帮紝璋冪敤 JavaScript:mhyWebBridge 鏃朵綔涓洪涓弬鏁颁紶鍏�
/// </summary>
[JsonPropertyName("callback")]
public string? Callback { get; set; }
Expand All @@ -668,19 +668,19 @@ private class JsParam
private class JsResult
{
/// <summary>
/// 代码
/// 浠g爜
/// </summary>
[JsonPropertyName("retcode")]
public int Code { get; set; }

/// <summary>
/// 消息
/// 娑堟伅
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;

/// <summary>
/// 数据
/// 鏁版嵁
/// </summary>
[JsonPropertyName("data")]
public Dictionary<string, object> Data { get; set; } = default!;
Expand Down
5 changes: 5 additions & 0 deletions src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image_BattleChronicle.Source
92b68a9465b5a8fc2ade9ef7a356c604_5553852234548352860

Copy link
Contributor Author

@hinaloe hinaloe Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that PR to other branches is required to add images... (And follow nuget package update)

Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ private void InitializeNavigationViewItemVisibility()
// 閾侀亾鎴樼哗鍥剧墖
Image_BattleChronicle.Source = new BitmapImage(new("ms-appx:///Assets/Image/ade9545750299456a3fcbc8c3b63521d_2941971308029698042.png"));
}

if (CurrentGameBiz.ToGame() is GameBiz.ZZZ)
{
NavigationViewItem_BattleChronicle.Visibility = Visibility.Visible;
}
}


Expand Down
5 changes: 2 additions & 3 deletions src/Starward/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@



private async Task ShowRecentUpdateContentAsync()

Check warning on line 157 in src/Starward/Pages/MainPage.xaml.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
#if !CI
try
Expand Down Expand Up @@ -534,7 +534,7 @@
NavigationViewItem_GameSetting.Visibility = Visibility.Visible;
NavigationViewItem_Screenshot.Visibility = Visibility.Visible;
NavigationViewItem_GachaLog.Visibility = Visibility.Visible;
NavigationViewItem_HoyolabToolbox.Visibility = Visibility.Collapsed;
NavigationViewItem_HoyolabToolbox.Visibility = Visibility.Visible;
NavigationViewItem_SelfQuery.Visibility = Visibility.Visible;
}
else
Expand Down Expand Up @@ -624,8 +624,7 @@
{
string? destPage = page?.Name;
if (destPage is null or nameof(BlankPage)
|| (CurrentGameBiz.ToGame() is GameBiz.Honkai3rd && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(ScreenshotPage))
|| CurrentGameBiz.ToGame() is GameBiz.ZZZ && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(GachaLogPage) and not nameof(ScreenshotPage) and not nameof(SelfQueryPage))
|| (CurrentGameBiz.ToGame() is GameBiz.Honkai3rd && destPage is not nameof(GameLauncherPage) and not nameof(GameSettingPage) and not nameof(ScreenshotPage)))
{
page = typeof(GameLauncherPage);
destPage = nameof(GameLauncherPage);
Expand Down
Loading