Compare commits
2 Commits
Canary-1.2
...
Canary-1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe43c32e60 | ||
|
|
8117e160c2 |
@@ -1,80 +0,0 @@
|
||||
using Gommon;
|
||||
using MsgPack;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.Common.Helper
|
||||
{
|
||||
public class PlayReportAnalyzer
|
||||
{
|
||||
private readonly List<PlayReportGameSpec> _specs = [];
|
||||
|
||||
public PlayReportAnalyzer AddSpec(string titleId, Func<PlayReportGameSpec, PlayReportGameSpec> transform)
|
||||
{
|
||||
_specs.Add(transform(new PlayReportGameSpec { TitleIdStr = titleId }));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayReportAnalyzer AddSpec(string titleId, Action<PlayReportGameSpec> transform)
|
||||
{
|
||||
_specs.Add(new PlayReportGameSpec { TitleIdStr = titleId }.Apply(transform));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<string> Run(string runningGameId, MessagePackObject playReport)
|
||||
{
|
||||
if (!playReport.IsDictionary)
|
||||
return Optional<string>.None;
|
||||
|
||||
if (!_specs.TryGetFirst(s => s.TitleIdStr.EqualsIgnoreCase(runningGameId), out PlayReportGameSpec spec))
|
||||
return Optional<string>.None;
|
||||
|
||||
foreach (PlayReportValueFormatterSpec formatSpec in spec.Analyses.OrderBy(x => x.Priority))
|
||||
{
|
||||
if (!playReport.AsDictionary().TryGetValue(formatSpec.ReportKey, out MessagePackObject valuePackObject))
|
||||
continue;
|
||||
|
||||
return formatSpec.ValueFormatter(valuePackObject.ToObject());
|
||||
}
|
||||
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PlayReportGameSpec
|
||||
{
|
||||
public required string TitleIdStr { get; init; }
|
||||
public List<PlayReportValueFormatterSpec> Analyses { get; } = [];
|
||||
|
||||
public PlayReportGameSpec AddValueFormatter(string reportKey, Func<object, string> valueFormatter)
|
||||
{
|
||||
Analyses.Add(new PlayReportValueFormatterSpec
|
||||
{
|
||||
Priority = Analyses.Count,
|
||||
ReportKey = reportKey,
|
||||
ValueFormatter = valueFormatter
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayReportGameSpec AddValueFormatter(int priority, string reportKey, Func<object, string> valueFormatter)
|
||||
{
|
||||
Analyses.Add(new PlayReportValueFormatterSpec
|
||||
{
|
||||
Priority = priority,
|
||||
ReportKey = reportKey,
|
||||
ValueFormatter = valueFormatter
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public struct PlayReportValueFormatterSpec
|
||||
{
|
||||
public required int Priority { get; init; }
|
||||
public required string ReportKey { get; init; }
|
||||
public required Func<object, string> ValueFormatter { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace Ryujinx.Ava
|
||||
private static DiscordRpcClient _discordClient;
|
||||
private static RichPresence _discordPresenceMain;
|
||||
private static RichPresence _discordPresencePlaying;
|
||||
private static ApplicationMetadata _currentApp;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
@@ -82,36 +83,6 @@ namespace Ryujinx.Ava
|
||||
}
|
||||
}
|
||||
|
||||
public static string MarioKart8(object obj)
|
||||
{
|
||||
return obj 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",
|
||||
_ => "Playing Mario Kart 8 Deluxe"
|
||||
};
|
||||
}
|
||||
|
||||
public static void Use(Optional<string> titleId)
|
||||
{
|
||||
if (titleId.TryGet(out string tid))
|
||||
@@ -143,6 +114,7 @@ namespace Ryujinx.Ava
|
||||
private static void SwitchToPlayingState(ApplicationMetadata appMeta, ProcessResult procRes)
|
||||
{
|
||||
_discordClient?.SetPresence(_discordPresencePlaying ??= CreatePlayingState(appMeta, procRes));
|
||||
_currentApp = appMeta;
|
||||
}
|
||||
|
||||
private static void UpdatePlayingState()
|
||||
@@ -154,46 +126,15 @@ namespace Ryujinx.Ava
|
||||
{
|
||||
_discordClient?.SetPresence(_discordPresenceMain);
|
||||
_discordPresencePlaying = null;
|
||||
_currentApp = null;
|
||||
}
|
||||
|
||||
private static readonly PlayReportAnalyzer _playReportAnalyzer = new PlayReportAnalyzer()
|
||||
.AddSpec( // Breath of the Wild
|
||||
"01007ef00011e000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("IsHardMode", val => val is 1 ? "Playing Master Mode" : "Playing Normal Mode")
|
||||
)
|
||||
.AddSpec( // Super Mario Odyssey
|
||||
"0100000000010000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("is_kids_mode", val => val is 1 ? "Playing in Assist Mode" : "Playing in Regular Mode")
|
||||
)
|
||||
.AddSpec( // Super Mario Odyssey (China)
|
||||
"010075000ECBE000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("is_kids_mode", val => val is 1 ? "Playing in 帮助模式" : "Playing in 普通模式")
|
||||
)
|
||||
.AddSpec( // Super Mario 3D World + Bowser's Fury
|
||||
"010028600EBDA000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("mode", val => val is 0 ? "Playing Super Mario 3D World" : "Playing Bowser's Fury")
|
||||
)
|
||||
.AddSpec( // Mario Kart 8 Deluxe
|
||||
"0100152000022000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("To", MarioKart8)
|
||||
)
|
||||
.AddSpec( // Mario Kart 8 Deluxe (China)
|
||||
"010075100E8EC000",
|
||||
gameSpec =>
|
||||
gameSpec.AddValueFormatter("To", MarioKart8)
|
||||
);
|
||||
|
||||
private static void HandlePlayReport(MessagePackObject playReport)
|
||||
{
|
||||
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
|
||||
if (_discordPresencePlaying is null) return;
|
||||
|
||||
Optional<string> details = _playReportAnalyzer.Run(TitleIDs.CurrentApplication.Value, playReport);
|
||||
Optional<string> details = PlayReport.Analyzer.Run(TitleIDs.CurrentApplication.Value, _currentApp, playReport);
|
||||
|
||||
if (!details.HasValue) return;
|
||||
|
||||
|
||||
171
src/Ryujinx/Utilities/PlayReport.cs
Normal file
171
src/Ryujinx/Utilities/PlayReport.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using Gommon;
|
||||
using MsgPack;
|
||||
using Ryujinx.Ava.Utilities.AppLibrary;
|
||||
using Ryujinx.Common.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.Ava.Utilities
|
||||
{
|
||||
public static class PlayReport
|
||||
{
|
||||
public static PlayReportAnalyzer Analyzer { get; } = new PlayReportAnalyzer()
|
||||
.AddSpec(
|
||||
"01007ef00011e000",
|
||||
spec => spec.AddValueFormatter("IsHardMode", BreathOfTheWild_MasterMode)
|
||||
)
|
||||
.AddSpec( // Super Mario Odyssey
|
||||
"0100000000010000",
|
||||
spec =>
|
||||
spec.AddValueFormatter("is_kids_mode", SuperMarioOdyssey_AssistMode)
|
||||
)
|
||||
.AddSpec( // Super Mario Odyssey (China)
|
||||
"010075000ECBE000",
|
||||
spec =>
|
||||
spec.AddValueFormatter("is_kids_mode", SuperMarioOdysseyChina_AssistMode)
|
||||
)
|
||||
.AddSpec( // Super Mario 3D World + Bowser's Fury
|
||||
"010028600EBDA000",
|
||||
spec => spec.AddValueFormatter("mode", SuperMario3DWorldOrBowsersFury)
|
||||
)
|
||||
.AddSpec( // Mario Kart 8 Deluxe
|
||||
"0100152000022000",
|
||||
spec => spec.AddValueFormatter("To", MarioKart8Deluxe_Mode)
|
||||
)
|
||||
.AddSpec( // Mario Kart 8 Deluxe (China)
|
||||
"010075100E8EC000",
|
||||
spec => spec.AddValueFormatter("To", MarioKart8Deluxe_Mode)
|
||||
);
|
||||
|
||||
private static string BreathOfTheWild_MasterMode(ref PlayReportValue value)
|
||||
=> value.BoxedValue is 1 ? "Playing Master Mode" : "Playing Normal Mode";
|
||||
|
||||
private static string SuperMarioOdyssey_AssistMode(ref PlayReportValue value)
|
||||
=> value.BoxedValue is 1 ? "Playing in Assist Mode" : "Playing in Regular Mode";
|
||||
|
||||
private static string SuperMarioOdysseyChina_AssistMode(ref PlayReportValue value)
|
||||
=> value.BoxedValue is 1 ? "Playing in 帮助模式" : "Playing in 普通模式";
|
||||
|
||||
private static string SuperMario3DWorldOrBowsersFury(ref PlayReportValue value)
|
||||
=> value.BoxedValue is 0 ? "Playing Super Mario 3D World" : "Playing Bowser's Fury";
|
||||
|
||||
private static string MarioKart8Deluxe_Mode(ref PlayReportValue value)
|
||||
=> value.BoxedValue 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",
|
||||
_ => $"Playing {value.Application.Title}"
|
||||
};
|
||||
}
|
||||
|
||||
#region Analyzer implementation
|
||||
|
||||
public class PlayReportAnalyzer
|
||||
{
|
||||
private readonly List<PlayReportGameSpec> _specs = [];
|
||||
|
||||
public PlayReportAnalyzer AddSpec(string titleId, Func<PlayReportGameSpec, PlayReportGameSpec> transform)
|
||||
{
|
||||
_specs.Add(transform(new PlayReportGameSpec { TitleIdStr = titleId }));
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayReportAnalyzer AddSpec(string titleId, Action<PlayReportGameSpec> transform)
|
||||
{
|
||||
_specs.Add(new PlayReportGameSpec { TitleIdStr = titleId }.Apply(transform));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Optional<string> Run(string runningGameId, ApplicationMetadata appMeta, MessagePackObject playReport)
|
||||
{
|
||||
if (!playReport.IsDictionary)
|
||||
return Optional<string>.None;
|
||||
|
||||
if (!_specs.TryGetFirst(s => s.TitleIdStr.EqualsIgnoreCase(runningGameId), out PlayReportGameSpec spec))
|
||||
return Optional<string>.None;
|
||||
|
||||
foreach (PlayReportValueFormatterSpec formatSpec in spec.Analyses.OrderBy(x => x.Priority))
|
||||
{
|
||||
if (!playReport.AsDictionary().TryGetValue(formatSpec.ReportKey, out MessagePackObject valuePackObject))
|
||||
continue;
|
||||
|
||||
PlayReportValue value = new()
|
||||
{
|
||||
Application = appMeta,
|
||||
BoxedValue = valuePackObject.ToObject()
|
||||
};
|
||||
|
||||
return formatSpec.ValueFormatter(ref value);
|
||||
}
|
||||
|
||||
return Optional<string>.None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PlayReportGameSpec
|
||||
{
|
||||
public required string TitleIdStr { get; init; }
|
||||
public List<PlayReportValueFormatterSpec> Analyses { get; } = [];
|
||||
|
||||
public PlayReportGameSpec AddValueFormatter(string reportKey, PlayReportValueFormatter valueFormatter)
|
||||
{
|
||||
Analyses.Add(new PlayReportValueFormatterSpec
|
||||
{
|
||||
Priority = Analyses.Count,
|
||||
ReportKey = reportKey,
|
||||
ValueFormatter = valueFormatter
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public PlayReportGameSpec AddValueFormatter(int priority, string reportKey, PlayReportValueFormatter valueFormatter)
|
||||
{
|
||||
Analyses.Add(new PlayReportValueFormatterSpec
|
||||
{
|
||||
Priority = priority,
|
||||
ReportKey = reportKey,
|
||||
ValueFormatter = valueFormatter
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public struct PlayReportValue
|
||||
{
|
||||
public ApplicationMetadata Application { get; init; }
|
||||
public object BoxedValue { get; init; }
|
||||
}
|
||||
|
||||
public struct PlayReportValueFormatterSpec
|
||||
{
|
||||
public required int Priority { get; init; }
|
||||
public required string ReportKey { get; init; }
|
||||
public required PlayReportValueFormatter ValueFormatter { get; init; }
|
||||
}
|
||||
|
||||
public delegate string PlayReportValueFormatter(ref PlayReportValue value);
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user