Compare commits

..

8 Commits

Author SHA1 Message Date
Evan Husted aa8ba8b503 Merge remote-tracking branch 'origin/master' 2025-02-06 22:56:33 -06:00
Evan Husted a4211fec33 UI: Properly space the play time & last play date in the game info popup 2025-02-06 22:56:25 -06:00
Daenorth 54b233dd78 Updated the compat list. (#618) 2025-02-06 04:46:23 -06:00
Evan Husted d1da937fce misc: chore: [ci skip] XMLdocs on new Play Report Analyzer members 2025-02-05 19:51:43 -06:00
Evan Husted 4a8f98126f [ci skip] remove test 2025-02-05 19:45:29 -06:00
Evan Husted e55629a908 misc: chore: [ci skip] Play Report Analyzer: Added Multi Value formatters 2025-02-05 19:42:36 -06:00
Evan Husted c638a7daf8 misc: chore: Move Play Report analyzer into a dedicated namespace and remove the PlayReport name prefix on types 2025-02-05 19:27:44 -06:00
Piplup 5e5e180fea PlayReportAnalyzer: Added Pokemon Scarlet and Violet (#630)
Every base game location excluding buildings are done, DLC locations
will be added at a later point
2025-02-05 18:32:27 -06:00
7 changed files with 321 additions and 195 deletions
+37 -37
View File
@@ -1576,50 +1576,50 @@
"ID": "GameListHeaderTimePlayed", "ID": "GameListHeaderTimePlayed",
"Translations": { "Translations": {
"ar_SA": "", "ar_SA": "",
"de_DE": "Spielzeit: {0}", "de_DE": "Spielzeit:",
"el_GR": "Χρόνος: {0}", "el_GR": "Χρόνος:",
"en_US": "Play Time: {0}", "en_US": "Play Time:",
"es_ES": "Tiempo jugado: {0}", "es_ES": "Tiempo jugado:",
"fr_FR": "Temps de jeu: {0}", "fr_FR": "Temps de jeu:",
"he_IL": "", "he_IL": "",
"it_IT": "Tempo di gioco: {0}", "it_IT": "Tempo di gioco:",
"ja_JP": "プレイ時間: {0}", "ja_JP": "プレイ時間:",
"ko_KR": "플레이 타임: {0}", "ko_KR": "플레이 타임:",
"no_NO": "Spilletid: {0}", "no_NO": "Spilletid:",
"pl_PL": "Czas w grze: {0}", "pl_PL": "Czas w grze:",
"pt_BR": "Tempo de jogo: {0}", "pt_BR": "Tempo de jogo:",
"ru_RU": "Время в игре: {0}", "ru_RU": "Время в игре:",
"sv_SE": "Speltid: {0}", "sv_SE": "Speltid:",
"th_TH": "เล่นไปแล้ว: {0}", "th_TH": "เล่นไปแล้ว:",
"tr_TR": "Oynama Süresi: {0}", "tr_TR": "Oynama Süresi:",
"uk_UA": "Зіграно часу: {0}", "uk_UA": "Зіграно часу:",
"zh_CN": "游玩时长: {0}", "zh_CN": "游玩时长:",
"zh_TW": "遊玩時數: {0}" "zh_TW": "遊玩時數:"
} }
}, },
{ {
"ID": "GameListHeaderLastPlayed", "ID": "GameListHeaderLastPlayed",
"Translations": { "Translations": {
"ar_SA": "", "ar_SA": "",
"de_DE": "Zuletzt gespielt: {0}", "de_DE": "Zuletzt gespielt: ",
"el_GR": "Παίχτηκε: {0}", "el_GR": "Παίχτηκε: ",
"en_US": "Last Played: {0}", "en_US": "Last Played:",
"es_ES": "Jugado por última vez: {0}", "es_ES": "Jugado por última vez:",
"fr_FR": "Dernière partie jouée: {0}", "fr_FR": "Dernière partie jouée:",
"he_IL": "", "he_IL": "",
"it_IT": "Ultima partita: {0}", "it_IT": "Ultima partita:",
"ja_JP": "最終プレイ日時: {0}", "ja_JP": "最終プレイ日時:",
"ko_KR": "마지막 플레이: {0}", "ko_KR": "마지막 플레이:",
"no_NO": "Sist Spilt: {0}", "no_NO": "Sist Spilt:",
"pl_PL": "Ostatnio grane: {0}", "pl_PL": "Ostatnio grane:",
"pt_BR": "Último jogo: {0}", "pt_BR": "Último jogo:",
"ru_RU": "Последний запуск: {0}", "ru_RU": "Последний запуск:",
"sv_SE": "Senast spelad: {0}", "sv_SE": "Senast spelad:",
"th_TH": "เล่นล่าสุด: {0}", "th_TH": "เล่นล่าสุด:",
"tr_TR": "Son Oynama Tarihi: {0}", "tr_TR": "Son Oynama Tarihi:",
"uk_UA": "Востаннє зіграно: {0}", "uk_UA": "Востаннє зіграно:",
"zh_CN": "最近游玩: {0}", "zh_CN": "最近游玩:",
"zh_TW": "最近遊玩: {0}" "zh_TW": "最近遊玩:"
} }
}, },
{ {
@@ -23698,4 +23698,4 @@
} }
} }
] ]
} }
+3 -7
View File
@@ -4,16 +4,12 @@ using MsgPack;
using Ryujinx.Ava.Utilities; using Ryujinx.Ava.Utilities;
using Ryujinx.Ava.Utilities.AppLibrary; using Ryujinx.Ava.Utilities.AppLibrary;
using Ryujinx.Ava.Utilities.Configuration; using Ryujinx.Ava.Utilities.Configuration;
using Ryujinx.Ava.Utilities.PlayReport;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Helper;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE; using Ryujinx.HLE;
using Ryujinx.HLE.Loaders.Processes; using Ryujinx.HLE.Loaders.Processes;
using Ryujinx.Horizon; using Ryujinx.Horizon;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text; using System.Text;
namespace Ryujinx.Ava namespace Ryujinx.Ava
@@ -130,8 +126,8 @@ namespace Ryujinx.Ava
if (!TitleIDs.CurrentApplication.Value.HasValue) return; if (!TitleIDs.CurrentApplication.Value.HasValue) return;
if (_discordPresencePlaying is null) return; if (_discordPresencePlaying is null) return;
PlayReportAnalyzer.FormattedValue formattedValue = Analyzer.FormattedValue formattedValue =
PlayReport.Analyzer.Format(TitleIDs.CurrentApplication.Value, _currentApp, playReport); PlayReports.Analyzer.Format(TitleIDs.CurrentApplication.Value, _currentApp, playReport);
if (!formattedValue.Handled) return; if (!formattedValue.Handled) return;
@@ -92,22 +92,35 @@
TextAlignment="Start" TextAlignment="Start"
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<Separator IsVisible="{Binding AppData.HasLdnGames}" Margin="0, 10, 0, 10" Height="1" BorderBrush="Gray" Background="Gray" /> <Separator IsVisible="{Binding AppData.HasLdnGames}" Margin="0, 10, 0, 10" Height="1" BorderBrush="Gray" Background="Gray" />
<StackPanel <StackPanel Orientation="Vertical" Spacing="5">
HorizontalAlignment="Left" <Grid
VerticalAlignment="Top" ColumnDefinitions="Auto,*,Auto">
Orientation="Vertical" <TextBlock
Spacing="5"> Grid.Column="0"
<TextBlock Text="{ext:Locale GameListHeaderLastPlayed}"
HorizontalAlignment="Stretch" VerticalAlignment="Top"
Text="{Binding FormattedLastPlayed}" TextAlignment="Start"
TextAlignment="Start" TextWrapping="NoWrap" />
TextWrapping="Wrap" /> <TextBlock
<TextBlock Grid.Column="2"
HorizontalAlignment="Stretch" Text="{Binding AppData.LastPlayedString}"
Text="{Binding FormattedPlayTime}" TextAlignment="End"
IsVisible="{Binding AppData.HasPlayedPreviously}" TextWrapping="Wrap" />
TextAlignment="Start" </Grid>
TextWrapping="Wrap" /> <Grid
ColumnDefinitions="Auto,*,Auto"
IsVisible="{Binding AppData.HasPlayedPreviously}">
<TextBlock
Grid.Column="0"
Text="{ext:Locale GameListHeaderTimePlayed}"
VerticalAlignment="Top"
TextAlignment="Start"
TextWrapping="NoWrap" />
<TextBlock Grid.Column="2"
Text="{Binding AppData.TimePlayedString}"
TextAlignment="End"
TextWrapping="Wrap" />
</Grid>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
@@ -12,10 +12,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public string FormattedVersion => LocaleManager.Instance[LocaleKeys.GameListHeaderVersion].Format(AppData.Version); public string FormattedVersion => LocaleManager.Instance[LocaleKeys.GameListHeaderVersion].Format(AppData.Version);
public string FormattedDeveloper => LocaleManager.Instance[LocaleKeys.GameListHeaderDeveloper].Format(AppData.Developer); public string FormattedDeveloper => LocaleManager.Instance[LocaleKeys.GameListHeaderDeveloper].Format(AppData.Developer);
public string FormattedFileExtension => LocaleManager.Instance[LocaleKeys.GameListHeaderFileExtension].Format(AppData.FileExtension); public string FormattedFileExtension => LocaleManager.Instance[LocaleKeys.GameListHeaderFileExtension].Format(AppData.FileExtension);
public string FormattedLastPlayed => LocaleManager.Instance[LocaleKeys.GameListHeaderLastPlayed].Format(AppData.LastPlayedString);
public string FormattedPlayTime => LocaleManager.Instance[LocaleKeys.GameListHeaderTimePlayed].Format(AppData.TimePlayedString);
public string FormattedFileSize => LocaleManager.Instance[LocaleKeys.GameListHeaderFileSize].Format(AppData.FileSizeString); public string FormattedFileSize => LocaleManager.Instance[LocaleKeys.GameListHeaderFileSize].Format(AppData.FileSizeString);
public string FormattedLdnInfo => public string FormattedLdnInfo =>
-85
View File
@@ -1,85 +0,0 @@
using PlayReportFormattedValue = Ryujinx.Ava.Utilities.PlayReportAnalyzer.FormattedValue;
namespace Ryujinx.Ava.Utilities
{
public static class PlayReport
{
public static PlayReportAnalyzer Analyzer { get; } = new PlayReportAnalyzer()
.AddSpec(
"01007ef00011e000",
spec => spec
.AddValueFormatter("IsHardMode", BreathOfTheWild_MasterMode)
// reset to normal status when switching between normal & master mode in title screen
.AddValueFormatter("AoCVer", PlayReportFormattedValue.AlwaysResets)
)
.AddSpec(
"0100f2c0115b6000",
spec => spec.AddValueFormatter("PlayerPosY", TearsOfTheKingdom_CurrentField))
.AddSpec(
"0100000000010000",
spec =>
spec.AddValueFormatter("is_kids_mode", SuperMarioOdyssey_AssistMode)
)
.AddSpec(
"010075000ecbe000",
spec =>
spec.AddValueFormatter("is_kids_mode", SuperMarioOdysseyChina_AssistMode)
)
.AddSpec(
"010028600ebda000",
spec => spec.AddValueFormatter("mode", SuperMario3DWorldOrBowsersFury)
)
.AddSpec( // Global & China IDs
["0100152000022000", "010075100e8ec000"],
spec => spec.AddValueFormatter("To", MarioKart8Deluxe_Mode)
);
private static PlayReportFormattedValue BreathOfTheWild_MasterMode(PlayReportValue value)
=> value.BoxedValue is 1 ? "Playing Master Mode" : PlayReportFormattedValue.ForceReset;
private static PlayReportFormattedValue TearsOfTheKingdom_CurrentField(PlayReportValue value) =>
value.DoubleValue switch
{
> 800d => "Exploring the Sky Islands",
< -201d => "Exploring the Depths",
_ => "Roaming Hyrule"
};
private static PlayReportFormattedValue SuperMarioOdyssey_AssistMode(PlayReportValue value)
=> value.BoxedValue is 1 ? "Playing in Assist Mode" : "Playing in Regular Mode";
private static PlayReportFormattedValue SuperMarioOdysseyChina_AssistMode(PlayReportValue value)
=> value.BoxedValue is 1 ? "Playing in 帮助模式" : "Playing in 普通模式";
private static PlayReportFormattedValue SuperMario3DWorldOrBowsersFury(PlayReportValue value)
=> value.BoxedValue is 0 ? "Playing Super Mario 3D World" : "Playing Bowser's Fury";
private static PlayReportFormattedValue MarioKart8Deluxe_Mode(PlayReportValue value)
=> value.StringValue switch
{
// Single Player
"Single" => "Single Player",
// Multiplayer
"Multi-2players" => "Multiplayer 2 Players",
"Multi-3players" => "Multiplayer 3 Players",
"Multi-4players" => "Multiplayer 4 Players",
// Wireless/LAN Play
"Local-Single" => "Wireless/LAN Play",
"Local-2players" => "Wireless/LAN Play 2 Players",
// CC Classes
"50cc" => "50cc",
"100cc" => "100cc",
"150cc" => "150cc",
"Mirror" => "Mirror (150cc)",
"200cc" => "200cc",
// Modes
"GrandPrix" => "Grand Prix",
"TimeAttack" => "Time Trials",
"VS" => "VS Races",
"Battle" => "Battle Mode",
"RaceStart" => "Selecting a Course",
"Race" => "Racing",
_ => PlayReportFormattedValue.ForceReset
};
}
}
@@ -6,27 +6,27 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
namespace Ryujinx.Ava.Utilities namespace Ryujinx.Ava.Utilities.PlayReport
{ {
/// <summary> /// <summary>
/// The entrypoint for the Play Report analysis system. /// The entrypoint for the Play Report analysis system.
/// </summary> /// </summary>
public class PlayReportAnalyzer public class Analyzer
{ {
private readonly List<PlayReportGameSpec> _specs = []; private readonly List<GameSpec> _specs = [];
/// <summary> /// <summary>
/// Add an analysis spec matching a specific game by title ID, with the provided spec configuration. /// Add an analysis spec matching a specific game by title ID, with the provided spec configuration.
/// </summary> /// </summary>
/// <param name="titleId">The ID of the game to listen to Play Reports in.</param> /// <param name="titleId">The ID of the game to listen to Play Reports in.</param>
/// <param name="transform">The configuration function for the analysis spec.</param> /// <param name="transform">The configuration function for the analysis spec.</param>
/// <returns>The current <see cref="PlayReportAnalyzer"/>, for chaining convenience.</returns> /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
public PlayReportAnalyzer AddSpec(string titleId, Func<PlayReportGameSpec, PlayReportGameSpec> transform) public Analyzer AddSpec(string titleId, Func<GameSpec, GameSpec> transform)
{ {
Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _), Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(PlayReportGameSpec)}."); $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(transform(new PlayReportGameSpec { TitleIds = [titleId] })); _specs.Add(transform(new GameSpec { TitleIds = [titleId] }));
return this; return this;
} }
@@ -35,13 +35,13 @@ namespace Ryujinx.Ava.Utilities
/// </summary> /// </summary>
/// <param name="titleId">The ID of the game to listen to Play Reports in.</param> /// <param name="titleId">The ID of the game to listen to Play Reports in.</param>
/// <param name="transform">The configuration function for the analysis spec.</param> /// <param name="transform">The configuration function for the analysis spec.</param>
/// <returns>The current <see cref="PlayReportAnalyzer"/>, for chaining convenience.</returns> /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
public PlayReportAnalyzer AddSpec(string titleId, Action<PlayReportGameSpec> transform) public Analyzer AddSpec(string titleId, Action<GameSpec> transform)
{ {
Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _), Guard.Ensure(ulong.TryParse(titleId, NumberStyles.HexNumber, null, out _),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(PlayReportGameSpec)}."); $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(new PlayReportGameSpec { TitleIds = [titleId] }.Apply(transform)); _specs.Add(new GameSpec { TitleIds = [titleId] }.Apply(transform));
return this; return this;
} }
@@ -50,15 +50,15 @@ namespace Ryujinx.Ava.Utilities
/// </summary> /// </summary>
/// <param name="titleIds">The IDs of the games to listen to Play Reports in.</param> /// <param name="titleIds">The IDs of the games to listen to Play Reports in.</param>
/// <param name="transform">The configuration function for the analysis spec.</param> /// <param name="transform">The configuration function for the analysis spec.</param>
/// <returns>The current <see cref="PlayReportAnalyzer"/>, for chaining convenience.</returns> /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
public PlayReportAnalyzer AddSpec(IEnumerable<string> titleIds, public Analyzer AddSpec(IEnumerable<string> titleIds,
Func<PlayReportGameSpec, PlayReportGameSpec> transform) Func<GameSpec, GameSpec> transform)
{ {
string[] tids = titleIds.ToArray(); string[] tids = titleIds.ToArray();
Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)), Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(PlayReportGameSpec)}."); $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(transform(new PlayReportGameSpec { TitleIds = [..tids] })); _specs.Add(transform(new GameSpec { TitleIds = [..tids] }));
return this; return this;
} }
@@ -67,20 +67,20 @@ namespace Ryujinx.Ava.Utilities
/// </summary> /// </summary>
/// <param name="titleIds">The IDs of the games to listen to Play Reports in.</param> /// <param name="titleIds">The IDs of the games to listen to Play Reports in.</param>
/// <param name="transform">The configuration function for the analysis spec.</param> /// <param name="transform">The configuration function for the analysis spec.</param>
/// <returns>The current <see cref="PlayReportAnalyzer"/>, for chaining convenience.</returns> /// <returns>The current <see cref="Analyzer"/>, for chaining convenience.</returns>
public PlayReportAnalyzer AddSpec(IEnumerable<string> titleIds, Action<PlayReportGameSpec> transform) public Analyzer AddSpec(IEnumerable<string> titleIds, Action<GameSpec> transform)
{ {
string[] tids = titleIds.ToArray(); string[] tids = titleIds.ToArray();
Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)), Guard.Ensure(tids.All(x => ulong.TryParse(x, NumberStyles.HexNumber, null, out _)),
$"Cannot use a non-hexadecimal string as the Title ID for a {nameof(PlayReportGameSpec)}."); $"Cannot use a non-hexadecimal string as the Title ID for a {nameof(GameSpec)}.");
_specs.Add(new PlayReportGameSpec { TitleIds = [..tids] }.Apply(transform)); _specs.Add(new GameSpec { TitleIds = [..tids] }.Apply(transform));
return this; return this;
} }
/// <summary> /// <summary>
/// Runs the configured <see cref="PlayReportGameSpec.FormatterSpec"/> for the specified game title ID. /// Runs the configured <see cref="GameSpec.FormatterSpec"/> for the specified game title ID.
/// </summary> /// </summary>
/// <param name="runningGameId">The game currently running.</param> /// <param name="runningGameId">The game currently running.</param>
/// <param name="appMeta">The Application metadata information, including localized game name and play time information.</param> /// <param name="appMeta">The Application metadata information, including localized game name and play time information.</param>
@@ -95,25 +95,44 @@ namespace Ryujinx.Ava.Utilities
if (!playReport.IsDictionary) if (!playReport.IsDictionary)
return FormattedValue.Unhandled; return FormattedValue.Unhandled;
if (!_specs.TryGetFirst(s => runningGameId.EqualsAnyIgnoreCase(s.TitleIds), out PlayReportGameSpec spec)) if (!_specs.TryGetFirst(s => runningGameId.EqualsAnyIgnoreCase(s.TitleIds), out GameSpec spec))
return FormattedValue.Unhandled; return FormattedValue.Unhandled;
foreach (PlayReportGameSpec.FormatterSpec formatSpec in spec.SimpleValueFormatters.OrderBy(x => x.Priority)) foreach (GameSpec.FormatterSpec formatSpec in spec.SimpleValueFormatters.OrderBy(x => x.Priority))
{ {
if (!playReport.AsDictionary().TryGetValue(formatSpec.ReportKey, out MessagePackObject valuePackObject)) if (!playReport.AsDictionary().TryGetValue(formatSpec.ReportKey, out MessagePackObject valuePackObject))
continue; continue;
return formatSpec.ValueFormatter(new PlayReportValue return formatSpec.ValueFormatter(new Value
{ {
Application = appMeta, PackedValue = valuePackObject Application = appMeta, PackedValue = valuePackObject
}); });
} }
foreach (GameSpec.MultiFormatterSpec formatSpec in spec.MultiValueFormatters.OrderBy(x => x.Priority))
{
List<MessagePackObject> packedObjects = [];
foreach (var reportKey in formatSpec.ReportKeys)
{
if (!playReport.AsDictionary().TryGetValue(reportKey, out MessagePackObject valuePackObject))
continue;
packedObjects.Add(valuePackObject);
}
if (packedObjects.Count != formatSpec.ReportKeys.Length)
return FormattedValue.Unhandled;
return formatSpec.ValueFormatter(packedObjects
.Select(packObject => new Value { Application = appMeta, PackedValue = packObject })
.ToArray());
}
return FormattedValue.Unhandled; return FormattedValue.Unhandled;
} }
/// <summary> /// <summary>
/// A potential formatted value returned by a <see cref="PlayReportValueFormatter"/>. /// A potential formatted value returned by a <see cref="ValueFormatter"/>.
/// </summary> /// </summary>
public readonly struct FormattedValue public readonly struct FormattedValue
{ {
@@ -123,7 +142,7 @@ namespace Ryujinx.Ava.Utilities
public bool Handled { get; private init; } public bool Handled { get; private init; }
/// <summary> /// <summary>
/// Did the handler request the caller of the <see cref="PlayReportAnalyzer"/> to reset the existing value? /// Did the handler request the caller of the <see cref="Analyzer"/> to reset the existing value?
/// </summary> /// </summary>
public bool Reset { get; private init; } public bool Reset { get; private init; }
@@ -151,42 +170,43 @@ namespace Ryujinx.Ava.Utilities
public static FormattedValue Unhandled => default; public static FormattedValue Unhandled => default;
/// <summary> /// <summary>
/// Return this to suggest the caller reset the value it's using the <see cref="PlayReportAnalyzer"/> for. /// Return this to suggest the caller reset the value it's using the <see cref="Analyzer"/> for.
/// </summary> /// </summary>
public static FormattedValue ForceReset => new() { Handled = true, Reset = true }; public static FormattedValue ForceReset => new() { Handled = true, Reset = true };
/// <summary> /// <summary>
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="PlayReportValueFormatter"/>. /// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="ValueFormatter"/>.
/// </summary> /// </summary>
public static readonly PlayReportValueFormatter AlwaysResets = _ => ForceReset; public static readonly ValueFormatter AlwaysResets = _ => ForceReset;
/// <summary> /// <summary>
/// A delegate factory you can use to always return the specified /// A delegate factory you can use to always return the specified
/// <paramref name="formattedValue"/> in a <see cref="PlayReportValueFormatter"/>. /// <paramref name="formattedValue"/> in a <see cref="ValueFormatter"/>.
/// </summary> /// </summary>
/// <param name="formattedValue">The string to always return for this delegate instance.</param> /// <param name="formattedValue">The string to always return for this delegate instance.</param>
public static PlayReportValueFormatter AlwaysReturns(string formattedValue) => _ => formattedValue; public static ValueFormatter AlwaysReturns(string formattedValue) => _ => formattedValue;
} }
} }
/// <summary> /// <summary>
/// A mapping of title IDs to value formatter specs. /// A mapping of title IDs to value formatter specs.
/// ///
/// <remarks>Generally speaking, use the <see cref="PlayReportAnalyzer"/>.AddSpec(...) methods instead of creating this class yourself.</remarks> /// <remarks>Generally speaking, use the <see cref="Analyzer"/>.AddSpec(...) methods instead of creating this class yourself.</remarks>
/// </summary> /// </summary>
public class PlayReportGameSpec public class GameSpec
{ {
public required string[] TitleIds { get; init; } public required string[] TitleIds { get; init; }
public List<FormatterSpec> SimpleValueFormatters { get; } = []; public List<FormatterSpec> SimpleValueFormatters { get; } = [];
public List<MultiFormatterSpec> MultiValueFormatters { get; } = [];
/// <summary> /// <summary>
/// Add a value formatter to the current <see cref="PlayReportGameSpec"/> /// Add a value formatter to the current <see cref="GameSpec"/>
/// matching a specific key that could exist in a Play Report for the previously specified title IDs. /// matching a specific key that could exist in a Play Report for the previously specified title IDs.
/// </summary> /// </summary>
/// <param name="reportKey">The key name to match.</param> /// <param name="reportKey">The key name to match.</param>
/// <param name="valueFormatter">The function which can return a potential formatted value.</param> /// <param name="valueFormatter">The function which can return a potential formatted value.</param>
/// <returns>The current <see cref="PlayReportGameSpec"/>, for chaining convenience.</returns> /// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public PlayReportGameSpec AddValueFormatter(string reportKey, PlayReportValueFormatter valueFormatter) public GameSpec AddValueFormatter(string reportKey, ValueFormatter valueFormatter)
{ {
SimpleValueFormatters.Add(new FormatterSpec SimpleValueFormatters.Add(new FormatterSpec
{ {
@@ -196,15 +216,15 @@ namespace Ryujinx.Ava.Utilities
} }
/// <summary> /// <summary>
/// Add a value formatter at a specific priority to the current <see cref="PlayReportGameSpec"/> /// Add a value formatter at a specific priority to the current <see cref="GameSpec"/>
/// matching a specific key that could exist in a Play Report for the previously specified title IDs. /// matching a specific key that could exist in a Play Report for the previously specified title IDs.
/// </summary> /// </summary>
/// <param name="priority">The resolution priority of this value formatter. Higher resolves sooner.</param> /// <param name="priority">The resolution priority of this value formatter. Higher resolves sooner.</param>
/// <param name="reportKey">The key name to match.</param> /// <param name="reportKey">The key name to match.</param>
/// <param name="valueFormatter">The function which can return a potential formatted value.</param> /// <param name="valueFormatter">The function which can return a potential formatted value.</param>
/// <returns>The current <see cref="PlayReportGameSpec"/>, for chaining convenience.</returns> /// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public PlayReportGameSpec AddValueFormatter(int priority, string reportKey, public GameSpec AddValueFormatter(int priority, string reportKey,
PlayReportValueFormatter valueFormatter) ValueFormatter valueFormatter)
{ {
SimpleValueFormatters.Add(new FormatterSpec SimpleValueFormatters.Add(new FormatterSpec
{ {
@@ -212,6 +232,40 @@ namespace Ryujinx.Ava.Utilities
}); });
return this; return this;
} }
/// <summary>
/// Add a multi-value formatter to the current <see cref="GameSpec"/>
/// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs.
/// </summary>
/// <param name="reportKeys">The key names to match.</param>
/// <param name="valueFormatter">The function which can format the values.</param>
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public GameSpec AddMultiValueFormatter(string[] reportKeys, MultiValueFormatter valueFormatter)
{
MultiValueFormatters.Add(new MultiFormatterSpec
{
Priority = SimpleValueFormatters.Count, ReportKeys = reportKeys, ValueFormatter = valueFormatter
});
return this;
}
/// <summary>
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
/// matching a specific set of keys that could exist in a Play Report for the previously specified title IDs.
/// </summary>
/// <param name="priority">The resolution priority of this value formatter. Higher resolves sooner.</param>
/// <param name="reportKeys">The key names to match.</param>
/// <param name="valueFormatter">The function which can format the values.</param>
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
public GameSpec AddMultiValueFormatter(int priority, string[] reportKeys,
MultiValueFormatter valueFormatter)
{
MultiValueFormatters.Add(new MultiFormatterSpec
{
Priority = priority, ReportKeys = reportKeys, ValueFormatter = valueFormatter
});
return this;
}
/// <summary> /// <summary>
/// A struct containing the data for a mapping of a key in a Play Report to a formatter for its potential value. /// A struct containing the data for a mapping of a key in a Play Report to a formatter for its potential value.
@@ -220,16 +274,26 @@ namespace Ryujinx.Ava.Utilities
{ {
public required int Priority { get; init; } public required int Priority { get; init; }
public required string ReportKey { get; init; } public required string ReportKey { get; init; }
public PlayReportValueFormatter ValueFormatter { get; init; } public ValueFormatter ValueFormatter { get; init; }
}
/// <summary>
/// A struct containing the data for a mapping of an arbitrary key set in a Play Report to a formatter for their potential values.
/// </summary>
public struct MultiFormatterSpec
{
public required int Priority { get; init; }
public required string[] ReportKeys { get; init; }
public MultiValueFormatter ValueFormatter { get; init; }
} }
} }
/// <summary> /// <summary>
/// The input data to a <see cref="PlayReportValueFormatter"/>, /// The input data to a <see cref="ValueFormatter"/>,
/// containing the currently running application's <see cref="ApplicationMetadata"/>, /// containing the currently running application's <see cref="ApplicationMetadata"/>,
/// and the matched <see cref="MessagePackObject"/> from the Play Report. /// and the matched <see cref="MessagePackObject"/> from the Play Report.
/// </summary> /// </summary>
public class PlayReportValue public class Value
{ {
/// <summary> /// <summary>
/// The currently running application's <see cref="ApplicationMetadata"/>. /// The currently running application's <see cref="ApplicationMetadata"/>.
@@ -245,7 +309,7 @@ namespace Ryujinx.Ava.Utilities
/// Access the <see cref="PackedValue"/> as its underlying .NET type.<br/> /// Access the <see cref="PackedValue"/> as its underlying .NET type.<br/>
/// ///
/// Does not seem to work well with comparing numeric types, /// Does not seem to work well with comparing numeric types,
/// so use <see cref="PackedValue"/> and the AsX (where X is a numerical type name i.e. Int32) methods for that. /// so use XValue properties for that.
/// </summary> /// </summary>
public object BoxedValue => PackedValue.ToObject(); public object BoxedValue => PackedValue.ToObject();
@@ -269,14 +333,26 @@ namespace Ryujinx.Ava.Utilities
} }
/// <summary> /// <summary>
/// The delegate type that powers the entire analysis system (as it currently is).<br/> /// The delegate type that powers single value formatters.<br/>
/// Takes in the result value from the Play Report, and outputs: /// Takes in the result value from the Play Report, and outputs:
/// <br/> /// <br/>
/// a formatted string, /// a formatted string,
/// <br/> /// <br/>
/// a signal that nothing was available to handle it, /// a signal that nothing was available to handle it,
/// <br/> /// <br/>
/// OR a signal to reset the value that the caller is using the <see cref="PlayReportAnalyzer"/> for. /// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
/// </summary> /// </summary>
public delegate PlayReportAnalyzer.FormattedValue PlayReportValueFormatter(PlayReportValue value); public delegate Analyzer.FormattedValue ValueFormatter(Value value);
/// <summary>
/// The delegate type that powers multiple value formatters.<br/>
/// Takes in the result value from the Play Report, and outputs:
/// <br/>
/// a formatted string,
/// <br/>
/// a signal that nothing was available to handle it,
/// <br/>
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
/// </summary>
public delegate Analyzer.FormattedValue MultiValueFormatter(Value[] value);
} }
@@ -0,0 +1,129 @@
using static Ryujinx.Ava.Utilities.PlayReport.Analyzer;
namespace Ryujinx.Ava.Utilities.PlayReport
{
public static class PlayReports
{
public static Analyzer Analyzer { get; } = new Analyzer()
.AddSpec(
"01007ef00011e000",
spec => spec
.AddValueFormatter("IsHardMode", BreathOfTheWild_MasterMode)
// reset to normal status when switching between normal & master mode in title screen
.AddValueFormatter("AoCVer", FormattedValue.AlwaysResets)
)
.AddSpec(
"0100f2c0115b6000",
spec => spec
.AddValueFormatter("PlayerPosY", TearsOfTheKingdom_CurrentField))
.AddSpec(
"0100000000010000",
spec =>
spec.AddValueFormatter("is_kids_mode", SuperMarioOdyssey_AssistMode)
)
.AddSpec(
"010075000ecbe000",
spec =>
spec.AddValueFormatter("is_kids_mode", SuperMarioOdysseyChina_AssistMode)
)
.AddSpec(
"010028600ebda000",
spec => spec.AddValueFormatter("mode", SuperMario3DWorldOrBowsersFury)
)
.AddSpec( // Global & China IDs
["0100152000022000", "010075100e8ec000"],
spec => spec.AddValueFormatter("To", MarioKart8Deluxe_Mode)
)
.AddSpec(
["0100a3d008c5c000", "01008f6008c5e000"],
spec => spec
.AddValueFormatter("area_no", PokemonSVArea)
.AddValueFormatter("team_circle", PokemonSVUnionCircle)
);
private static FormattedValue BreathOfTheWild_MasterMode(Value value)
=> value.BoxedValue is 1 ? "Playing Master Mode" : FormattedValue.ForceReset;
private static FormattedValue TearsOfTheKingdom_CurrentField(Value value) =>
value.DoubleValue switch
{
> 800d => "Exploring the Sky Islands",
< -201d => "Exploring the Depths",
_ => "Roaming Hyrule"
};
private static FormattedValue SuperMarioOdyssey_AssistMode(Value value)
=> value.BoxedValue is 1 ? "Playing in Assist Mode" : "Playing in Regular Mode";
private static FormattedValue SuperMarioOdysseyChina_AssistMode(Value value)
=> value.BoxedValue is 1 ? "Playing in 帮助模式" : "Playing in 普通模式";
private static FormattedValue SuperMario3DWorldOrBowsersFury(Value value)
=> value.BoxedValue is 0 ? "Playing Super Mario 3D World" : "Playing Bowser's Fury";
private static FormattedValue MarioKart8Deluxe_Mode(Value value)
=> value.StringValue switch
{
// Single Player
"Single" => "Single Player",
// Multiplayer
"Multi-2players" => "Multiplayer 2 Players",
"Multi-3players" => "Multiplayer 3 Players",
"Multi-4players" => "Multiplayer 4 Players",
// Wireless/LAN Play
"Local-Single" => "Wireless/LAN Play",
"Local-2players" => "Wireless/LAN Play 2 Players",
// CC Classes
"50cc" => "50cc",
"100cc" => "100cc",
"150cc" => "150cc",
"Mirror" => "Mirror (150cc)",
"200cc" => "200cc",
// Modes
"GrandPrix" => "Grand Prix",
"TimeAttack" => "Time Trials",
"VS" => "VS Races",
"Battle" => "Battle Mode",
"RaceStart" => "Selecting a Course",
"Race" => "Racing",
_ => FormattedValue.ForceReset
};
private static FormattedValue PokemonSVUnionCircle(Value value)
=> value.BoxedValue is 0 ? "Playing Alone" : "Playing in a group";
private static FormattedValue PokemonSVArea(Value value)
=> value.StringValue switch
{
// Base Game Locations
"a_w01" => "South Area One",
"a_w02" => "Mesagoza",
"a_w03" => "The Pokemon League",
"a_w04" => "South Area Two",
"a_w05" => "South Area Four",
"a_w06" => "South Area Six",
"a_w07" => "South Area Five",
"a_w08" => "South Area Three",
"a_w09" => "West Area One",
"a_w10" => "Asado Desert",
"a_w11" => "West Area Two",
"a_w12" => "Medali",
"a_w13" => "Tagtree Thicket",
"a_w14" => "East Area Three",
"a_w15" => "Artazon",
"a_w16" => "East Area Two",
"a_w18" => "Casseroya Lake",
"a_w19" => "Glaseado Mountain",
"a_w20" => "North Area Three",
"a_w21" => "North Area One",
"a_w22" => "North Area Two",
"a_w23" => "The Great Crater of Paldea",
"a_w24" => "South Paldean Sea",
"a_w25" => "West Paldean Sea",
"a_w26" => "East Paldean Sea",
"a_w27" => "Nouth Paldean Sea",
//TODO DLC Locations
_ => FormattedValue.ForceReset
};
}
}