Skip to content

Commit

Permalink
pure fiction of hoyolab toolbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Jan 13, 2024
1 parent 3a28ace commit da6bf0c
Show file tree
Hide file tree
Showing 30 changed files with 1,125 additions and 76 deletions.
11 changes: 11 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Starward.Core.GameRecord.Genshin.SpiralAbyss;
using Starward.Core.GameRecord.Genshin.TravelersDiary;
using Starward.Core.GameRecord.StarRail.ForgottenHall;
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using System.Net;
Expand Down Expand Up @@ -285,6 +286,16 @@ protected virtual async Task CommonSendAsync(HttpRequestMessage request, Cancell
public abstract Task<ForgottenHallInfo> GetForgottenHallInfoAsync(GameRecordRole role, int schedule, CancellationToken cancellationToken = default);


/// <summary>
/// 虚构叙事
/// </summary>
/// <param name="role"></param>
/// <param name="schedule">1当期,2上期</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public abstract Task<PureFictionInfo> GetPureFictionInfoAsync(GameRecordRole role, int schedule, CancellationToken cancellationToken = default);


/// <summary>
/// 模拟宇宙
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Starward.Core/GameRecord/GameRecordJsonContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Starward.Core.GameRecord.Genshin.SpiralAbyss;
using Starward.Core.GameRecord.Genshin.TravelersDiary;
using Starward.Core.GameRecord.StarRail.ForgottenHall;
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using System.Text.Json.Serialization;
Expand All @@ -17,6 +18,7 @@ namespace Starward.Core.GameRecord;
[JsonSerializable(typeof(miHoYoApiWrapper<TrailblazeCalendarDetail>))]
[JsonSerializable(typeof(miHoYoApiWrapper<ForgottenHallInfo>))]
[JsonSerializable(typeof(miHoYoApiWrapper<ForgottenHallTime>))]
[JsonSerializable(typeof(miHoYoApiWrapper<PureFictionInfo>))]
[JsonSerializable(typeof(miHoYoApiWrapper<SimulatedUniverseInfo>))]
[JsonSerializable(typeof(miHoYoApiWrapper<SimulatedUniverseTime>))]
internal partial class GameRecordJsonContext : JsonSerializerContext
Expand Down
24 changes: 24 additions & 0 deletions src/Starward.Core/GameRecord/HoyolabClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Starward.Core.GameRecord.Genshin.SpiralAbyss;
using Starward.Core.GameRecord.Genshin.TravelersDiary;
using Starward.Core.GameRecord.StarRail.ForgottenHall;
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;

Expand Down Expand Up @@ -265,6 +266,29 @@ public override async Task<ForgottenHallInfo> GetForgottenHallInfoAsync(GameReco
}


/// <summary>
/// 虚构叙事
/// </summary>
/// <param name="role"></param>
/// <param name="schedule">1当期,2上期</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<PureFictionInfo> GetPureFictionInfoAsync(GameRecordRole role, int schedule, CancellationToken cancellationToken = default)
{
var url = $"https://bbs-api-os.hoyolab.com/game_record/app/hkrpg/api/challenge_story?schedule_type={schedule}&server={role.Region}&role_id={role.Uid}&need_all=true";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(DS, CreateSecret2(url));
request.Headers.Add(Referer, "https://act.hoyolab.com");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_client_type, "5");
request.Headers.Add(X_Request_With, com_mihoyo_hoyolab);
var data = await CommonSendAsync<PureFictionInfo>(request, cancellationToken);
data.Uid = role.Uid;
return data;
}


/// <summary>
/// 模拟宇宙
/// </summary>
Expand Down
26 changes: 26 additions & 0 deletions src/Starward.Core/GameRecord/HyperionClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Starward.Core.GameRecord.Genshin.SpiralAbyss;
using Starward.Core.GameRecord.Genshin.TravelersDiary;
using Starward.Core.GameRecord.StarRail.ForgottenHall;
using Starward.Core.GameRecord.StarRail.PureFiction;
using Starward.Core.GameRecord.StarRail.SimulatedUniverse;
using Starward.Core.GameRecord.StarRail.TrailblazeCalendar;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -273,6 +274,31 @@ public override async Task<ForgottenHallInfo> GetForgottenHallInfoAsync(GameReco
}


/// <summary>
/// 虚构叙事
/// </summary>
/// <param name="role"></param>
/// <param name="schedule">1当期,2上期</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override async Task<PureFictionInfo> GetPureFictionInfoAsync(GameRecordRole role, int schedule, CancellationToken cancellationToken = default)
{
var url = $"https://api-takumi-record.mihoyo.com/game_record/app/hkrpg/api/challenge_story?schedule_type={schedule}&server={role.Region}&role_id={role.Uid}&need_all=true";
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(Cookie, role.Cookie);
request.Headers.Add(DS, CreateSecret2(url));
request.Headers.Add(Referer, "https://webstatic.mihoyo.com/");
request.Headers.Add(x_rpc_app_version, AppVersion);
request.Headers.Add(x_rpc_device_id, Regex.Match(role.Cookie ?? "", @"_MHYUUID=([^;]+)").Groups[1].Value);
request.Headers.Add(x_rpc_device_fp, Regex.Match(role.Cookie ?? "", @"DEVICEFP=([^;]+)").Groups[1].Value);
request.Headers.Add(x_rpc_client_type, "5");
request.Headers.Add(X_Request_With, com_mihoyo_hyperion);
var data = await CommonSendAsync<PureFictionInfo>(request, cancellationToken);
data.Uid = role.Uid;
return data;
}


/// <summary>
/// 模拟宇宙
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ public class ForgottenHallFloorDetail
/// <summary>
/// 快速通关
/// </summary>
[JsonInclude]
[JsonPropertyName("is_fast")]
private bool _isFast { get; set; }
internal bool _isFast { get; set; }

/// <summary>
/// 快速通关
Expand All @@ -43,11 +44,7 @@ public bool IsFast
{
return true;
}
else if (Node1?.ChallengeTime == Node2?.ChallengeTime)
{
return true;
}
else if (Node1?.Avatars?.Count == 0 || Node2?.Avatars?.Count == 0)
else if (Node1?.Avatars?.Count == 0 && Node2?.Avatars?.Count == 0)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,28 @@ public class ForgottenHallInfo
[JsonPropertyName("has_data")]
public bool HasData { get; set; }

[JsonPropertyName("max_floor_detail")]
public object MaxFloorDetail { get; set; }

[JsonPropertyName("all_floor_detail")]
public List<ForgottenHallFloorDetail> AllFloorDetail { get; set; }

[JsonPropertyName("groups")]
public List<ForgottenHallMeta>? Metas { get; set; }

[JsonIgnore]
public string? Name
{
get
{
if (Metas?.FirstOrDefault(x => x.ScheduleId == this.ScheduleId) is ForgottenHallMeta meta)
{
return meta.Name;
}
else
{
return null;
}
}
}


[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord.StarRail.ForgottenHall;


public class ForgottenHallMeta
{

[JsonPropertyName("schedule_id")]
public int ScheduleId { get; set; }

[JsonPropertyName("begin_time")]
[JsonConverter(typeof(ForgottenHallTimeJsonConverter))]
public DateTime BeginTime { get; set; }

[JsonPropertyName("end_time")]
[JsonConverter(typeof(ForgottenHallTimeJsonConverter))]
public DateTime EndTime { get; set; }

[JsonPropertyName("status")]
public string Status { get; set; }

[JsonPropertyName("name_mi18n")]
public string Name { get; set; }


[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }

}

Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
}
else
{
return new DateTime();
return DateTime.MinValue;
}
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
var time = new ForgottenHallTime
if (value != DateTime.MinValue)
{
Year = value.Year,
Month = value.Month,
Day = value.Day,
Hour = value.Hour,
Minute = value.Minute,
};
writer.WriteRawValue(JsonSerializer.Serialize(time, typeof(ForgottenHallTime), GameRecordJsonContext.Default));
var time = new ForgottenHallTime
{
Year = value.Year,
Month = value.Month,
Day = value.Day,
Hour = value.Hour,
Minute = value.Minute,
};
writer.WriteRawValue(JsonSerializer.Serialize(time, typeof(ForgottenHallTime), GameRecordJsonContext.Default));
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord.StarRail.PureFiction;

public class PureFictionAvatar
{

[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("level")]
public int Level { get; set; }

[JsonPropertyName("icon")]
public string Icon { get; set; }

[JsonPropertyName("rarity")]
public int Rarity { get; set; }

[JsonPropertyName("element")]
public string Element { get; set; }

[JsonPropertyName("rank")]
public int Rank { get; set; }


[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord.StarRail.PureFiction;

public class PureFictionBuff
{

[JsonPropertyName("id")]
public int Id { get; set; }

[JsonPropertyName("name_mi18n")]
public string Name { get; set; }

[JsonPropertyName("desc_mi18n")]
public string Desc { get; set; }

[JsonPropertyName("icon")]
public string Icon { get; set; }


[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }

}



Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Text.Json.Serialization;

namespace Starward.Core.GameRecord.StarRail.PureFiction;

public class PureFictionFloorDetail
{

[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("round_num")]
public int RoundNum { get; set; }

[JsonPropertyName("star_num")]
public int StarNum { get; set; }

[JsonPropertyName("node_1")]
public PureFictionNode Node1 { get; set; }

[JsonPropertyName("node_2")]
public PureFictionNode Node2 { get; set; }

[JsonPropertyName("maze_id")]
public int MazeId { get; set; }

[JsonPropertyName("is_fast")]
public bool IsFast { get; set; }

[JsonIgnore]
public int TotalScore => Node1.Score + Node2.Score;


[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }

}



Loading

0 comments on commit da6bf0c

Please sign in to comment.