Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e9c4587e5 | |||
| f441d3e01d | |||
| cf1ad265f9 | |||
| 6773343d46 | |||
| 45af4d2517 | |||
| c279c7d5de | |||
| 753ca01c0d | |||
| 5aedeebfe9 | |||
| 5c67efd291 | |||
| b2354768c4 | |||
| 745bd91250 | |||
| 07ab817557 | |||
| 0e8a41b198 | |||
| 969e94f913 | |||
| 2e2d26d49d |
@@ -7,6 +7,7 @@ namespace ARMeilleure.Memory
|
|||||||
public const int DefaultGranularity = 65536; // Mapping granularity in Windows.
|
public const int DefaultGranularity = 65536; // Mapping granularity in Windows.
|
||||||
|
|
||||||
public IJitMemoryBlock Block { get; }
|
public IJitMemoryBlock Block { get; }
|
||||||
|
public IJitMemoryAllocator Allocator { get; }
|
||||||
|
|
||||||
public nint Pointer => Block.Pointer;
|
public nint Pointer => Block.Pointer;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ namespace ARMeilleure.Memory
|
|||||||
granularity = DefaultGranularity;
|
granularity = DefaultGranularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Allocator = allocator;
|
||||||
Block = allocator.Reserve(maxSize);
|
Block = allocator.Reserve(maxSize);
|
||||||
_maxSize = maxSize;
|
_maxSize = maxSize;
|
||||||
_sizeGranularity = granularity;
|
_sizeGranularity = granularity;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ using ARMeilleure.CodeGen;
|
|||||||
using ARMeilleure.CodeGen.Unwinding;
|
using ARMeilleure.CodeGen.Unwinding;
|
||||||
using ARMeilleure.Memory;
|
using ARMeilleure.Memory;
|
||||||
using ARMeilleure.Native;
|
using ARMeilleure.Native;
|
||||||
|
using Humanizer;
|
||||||
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -18,9 +20,8 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
private static readonly int _pageMask = _pageSize - 1;
|
private static readonly int _pageMask = _pageSize - 1;
|
||||||
|
|
||||||
private const int CodeAlignment = 4; // Bytes.
|
private const int CodeAlignment = 4; // Bytes.
|
||||||
private const int CacheSize = 2047 * 1024 * 1024;
|
private const int CacheSize = 128 * 1024 * 1024;
|
||||||
|
|
||||||
private static ReservedRegion _jitRegion;
|
|
||||||
private static JitCacheInvalidation _jitCacheInvalidator;
|
private static JitCacheInvalidation _jitCacheInvalidator;
|
||||||
|
|
||||||
private static CacheMemoryAllocator _cacheAllocator;
|
private static CacheMemoryAllocator _cacheAllocator;
|
||||||
@@ -30,6 +31,9 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
private static readonly Lock _lock = new();
|
private static readonly Lock _lock = new();
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
|
||||||
|
private static readonly List<ReservedRegion> _jitRegions = new();
|
||||||
|
private static int _activeRegionIndex = 0;
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||||
public static partial nint FlushInstructionCache(nint hProcess, nint lpAddress, nuint dwSize);
|
public static partial nint FlushInstructionCache(nint hProcess, nint lpAddress, nuint dwSize);
|
||||||
@@ -48,7 +52,9 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_jitRegion = new ReservedRegion(allocator, CacheSize);
|
var firstRegion = new ReservedRegion(allocator, CacheSize);
|
||||||
|
_jitRegions.Add(firstRegion);
|
||||||
|
_activeRegionIndex = 0;
|
||||||
|
|
||||||
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsMacOS())
|
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsMacOS())
|
||||||
{
|
{
|
||||||
@@ -59,7 +65,9 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
|
|
||||||
if (OperatingSystem.IsWindows())
|
if (OperatingSystem.IsWindows())
|
||||||
{
|
{
|
||||||
JitUnwindWindows.InstallFunctionTableHandler(_jitRegion.Pointer, CacheSize, _jitRegion.Pointer + Allocate(_pageSize));
|
JitUnwindWindows.InstallFunctionTableHandler(
|
||||||
|
firstRegion.Pointer, CacheSize, firstRegion.Pointer + Allocate(_pageSize)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
@@ -75,8 +83,8 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
Debug.Assert(_initialized);
|
Debug.Assert(_initialized);
|
||||||
|
|
||||||
int funcOffset = Allocate(code.Length);
|
int funcOffset = Allocate(code.Length);
|
||||||
|
ReservedRegion targetRegion = _jitRegions[_activeRegionIndex];
|
||||||
nint funcPtr = _jitRegion.Pointer + funcOffset;
|
nint funcPtr = targetRegion.Pointer + funcOffset;
|
||||||
|
|
||||||
if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||||
{
|
{
|
||||||
@@ -90,9 +98,9 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ReprotectAsWritable(funcOffset, code.Length);
|
ReprotectAsWritable(targetRegion, funcOffset, code.Length);
|
||||||
Marshal.Copy(code, 0, funcPtr, code.Length);
|
Marshal.Copy(code, 0, funcPtr, code.Length);
|
||||||
ReprotectAsExecutable(funcOffset, code.Length);
|
ReprotectAsExecutable(targetRegion, funcOffset, code.Length);
|
||||||
|
|
||||||
if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||||
{
|
{
|
||||||
@@ -116,52 +124,83 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
{
|
{
|
||||||
Debug.Assert(_initialized);
|
Debug.Assert(_initialized);
|
||||||
|
|
||||||
int funcOffset = (int)(pointer.ToInt64() - _jitRegion.Pointer.ToInt64());
|
foreach (var region in _jitRegions)
|
||||||
|
|
||||||
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
|
||||||
{
|
{
|
||||||
_cacheAllocator.Free(funcOffset, AlignCodeSize(entry.Size));
|
if (pointer.ToInt64() < region.Pointer.ToInt64() ||
|
||||||
_cacheEntries.RemoveAt(entryIndex);
|
pointer.ToInt64() >= (region.Pointer + CacheSize).ToInt64())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int funcOffset = (int)(pointer.ToInt64() - region.Pointer.ToInt64());
|
||||||
|
|
||||||
|
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
||||||
|
{
|
||||||
|
_cacheAllocator.Free(funcOffset, AlignCodeSize(entry.Size));
|
||||||
|
_cacheEntries.RemoveAt(entryIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReprotectAsWritable(int offset, int size)
|
private static void ReprotectAsWritable(ReservedRegion region, int offset, int size)
|
||||||
{
|
{
|
||||||
int endOffs = offset + size;
|
int endOffs = offset + size;
|
||||||
|
|
||||||
int regionStart = offset & ~_pageMask;
|
int regionStart = offset & ~_pageMask;
|
||||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||||
|
|
||||||
_jitRegion.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
region.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReprotectAsExecutable(int offset, int size)
|
private static void ReprotectAsExecutable(ReservedRegion region, int offset, int size)
|
||||||
{
|
{
|
||||||
int endOffs = offset + size;
|
int endOffs = offset + size;
|
||||||
|
|
||||||
int regionStart = offset & ~_pageMask;
|
int regionStart = offset & ~_pageMask;
|
||||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||||
|
|
||||||
_jitRegion.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
region.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int Allocate(int codeSize)
|
private static int Allocate(int codeSize)
|
||||||
{
|
{
|
||||||
codeSize = AlignCodeSize(codeSize);
|
codeSize = AlignCodeSize(codeSize);
|
||||||
|
|
||||||
int allocOffset = _cacheAllocator.Allocate(codeSize);
|
for (int i = _activeRegionIndex; i < _jitRegions.Count; i++)
|
||||||
|
|
||||||
if (allocOffset < 0)
|
|
||||||
{
|
{
|
||||||
throw new OutOfMemoryException("JIT Cache exhausted.");
|
int allocOffset = _cacheAllocator.Allocate(codeSize);
|
||||||
|
|
||||||
|
if (allocOffset >= 0)
|
||||||
|
{
|
||||||
|
_jitRegions[i].ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
||||||
|
_activeRegionIndex = i;
|
||||||
|
return allocOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_jitRegion.ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
int exhaustedRegion = _activeRegionIndex;
|
||||||
|
var newRegion = new ReservedRegion(_jitRegions[0].Allocator, CacheSize);
|
||||||
|
_jitRegions.Add(newRegion);
|
||||||
|
_activeRegionIndex = _jitRegions.Count - 1;
|
||||||
|
|
||||||
|
int newRegionNumber = _activeRegionIndex;
|
||||||
|
|
||||||
return allocOffset;
|
Logger.Warning?.Print(LogClass.Cpu, $"JIT Cache Region {exhaustedRegion} exhausted, creating new Cache Region {newRegionNumber} ({((newRegionNumber + 1) * CacheSize).Bytes()} Total Allocation).");
|
||||||
|
|
||||||
|
_cacheAllocator = new CacheMemoryAllocator(CacheSize);
|
||||||
|
|
||||||
|
int allocOffsetNew = _cacheAllocator.Allocate(codeSize);
|
||||||
|
if (allocOffsetNew < 0)
|
||||||
|
{
|
||||||
|
throw new OutOfMemoryException("Failed to allocate in new Cache Region!");
|
||||||
|
}
|
||||||
|
|
||||||
|
newRegion.ExpandIfNeeded((ulong)allocOffsetNew + (ulong)codeSize);
|
||||||
|
return allocOffsetNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int AlignCodeSize(int codeSize)
|
private static int AlignCodeSize(int codeSize)
|
||||||
{
|
{
|
||||||
return checked(codeSize + (CodeAlignment - 1)) & ~(CodeAlignment - 1);
|
return checked(codeSize + (CodeAlignment - 1)) & ~(CodeAlignment - 1);
|
||||||
@@ -185,18 +224,21 @@ namespace ARMeilleure.Translation.Cache
|
|||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
int index = _cacheEntries.BinarySearch(new CacheEntry(offset, 0, default));
|
foreach (var region in _jitRegions)
|
||||||
|
|
||||||
if (index < 0)
|
|
||||||
{
|
{
|
||||||
index = ~index - 1;
|
int index = _cacheEntries.BinarySearch(new CacheEntry(offset, 0, default));
|
||||||
}
|
|
||||||
|
|
||||||
if (index >= 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
entry = _cacheEntries[index];
|
index = ~index - 1;
|
||||||
entryIndex = index;
|
}
|
||||||
return true;
|
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
entry = _cacheEntries[index];
|
||||||
|
entryIndex = index;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using ARMeilleure.Memory;
|
using ARMeilleure.Memory;
|
||||||
|
using Humanizer;
|
||||||
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,9 +17,8 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
private static readonly int _pageMask = _pageSize - 1;
|
private static readonly int _pageMask = _pageSize - 1;
|
||||||
|
|
||||||
private const int CodeAlignment = 4; // Bytes.
|
private const int CodeAlignment = 4; // Bytes.
|
||||||
private const int CacheSize = 2047 * 1024 * 1024;
|
private const int CacheSize = 128 * 1024 * 1024;
|
||||||
|
|
||||||
private static ReservedRegion _jitRegion;
|
|
||||||
private static JitCacheInvalidation _jitCacheInvalidator;
|
private static JitCacheInvalidation _jitCacheInvalidator;
|
||||||
|
|
||||||
private static CacheMemoryAllocator _cacheAllocator;
|
private static CacheMemoryAllocator _cacheAllocator;
|
||||||
@@ -26,6 +27,8 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
|
|
||||||
private static readonly Lock _lock = new();
|
private static readonly Lock _lock = new();
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
|
private static readonly List<ReservedRegion> _jitRegions = new();
|
||||||
|
private static int _activeRegionIndex = 0;
|
||||||
|
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
[LibraryImport("kernel32.dll", SetLastError = true)]
|
[LibraryImport("kernel32.dll", SetLastError = true)]
|
||||||
@@ -45,7 +48,9 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_jitRegion = new ReservedRegion(allocator, CacheSize);
|
var firstRegion = new ReservedRegion(allocator, CacheSize);
|
||||||
|
_jitRegions.Add(firstRegion);
|
||||||
|
_activeRegionIndex = 0;
|
||||||
|
|
||||||
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsMacOS())
|
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsMacOS())
|
||||||
{
|
{
|
||||||
@@ -65,8 +70,8 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
Debug.Assert(_initialized);
|
Debug.Assert(_initialized);
|
||||||
|
|
||||||
int funcOffset = Allocate(code.Length);
|
int funcOffset = Allocate(code.Length);
|
||||||
|
ReservedRegion targetRegion = _jitRegions[_activeRegionIndex];
|
||||||
nint funcPtr = _jitRegion.Pointer + funcOffset;
|
nint funcPtr = targetRegion.Pointer + funcOffset;
|
||||||
|
|
||||||
if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||||
{
|
{
|
||||||
@@ -80,18 +85,11 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ReprotectAsWritable(funcOffset, code.Length);
|
ReprotectAsWritable(targetRegion, funcOffset, code.Length);
|
||||||
code.CopyTo(new Span<byte>((void*)funcPtr, code.Length));
|
Marshal.Copy(code.ToArray(), 0, funcPtr, code.Length);
|
||||||
ReprotectAsExecutable(funcOffset, code.Length);
|
ReprotectAsExecutable(targetRegion, funcOffset, code.Length);
|
||||||
|
|
||||||
if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
_jitCacheInvalidator?.Invalidate(funcPtr, (ulong)code.Length);
|
||||||
{
|
|
||||||
FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (nuint)code.Length);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_jitCacheInvalidator?.Invalidate(funcPtr, (ulong)code.Length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Add(funcOffset, code.Length);
|
Add(funcOffset, code.Length);
|
||||||
@@ -106,50 +104,80 @@ namespace Ryujinx.Cpu.LightningJit.Cache
|
|||||||
{
|
{
|
||||||
Debug.Assert(_initialized);
|
Debug.Assert(_initialized);
|
||||||
|
|
||||||
int funcOffset = (int)(pointer.ToInt64() - _jitRegion.Pointer.ToInt64());
|
foreach (var region in _jitRegions)
|
||||||
|
|
||||||
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
|
||||||
{
|
{
|
||||||
_cacheAllocator.Free(funcOffset, AlignCodeSize(entry.Size));
|
if (pointer.ToInt64() < region.Pointer.ToInt64() ||
|
||||||
_cacheEntries.RemoveAt(entryIndex);
|
pointer.ToInt64() >= (region.Pointer + CacheSize).ToInt64())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int funcOffset = (int)(pointer.ToInt64() - region.Pointer.ToInt64());
|
||||||
|
|
||||||
|
if (TryFind(funcOffset, out CacheEntry entry, out int entryIndex) && entry.Offset == funcOffset)
|
||||||
|
{
|
||||||
|
_cacheAllocator.Free(funcOffset, AlignCodeSize(entry.Size));
|
||||||
|
_cacheEntries.RemoveAt(entryIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReprotectAsWritable(int offset, int size)
|
private static void ReprotectAsWritable(ReservedRegion region, int offset, int size)
|
||||||
{
|
{
|
||||||
int endOffs = offset + size;
|
int endOffs = offset + size;
|
||||||
|
|
||||||
int regionStart = offset & ~_pageMask;
|
int regionStart = offset & ~_pageMask;
|
||||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||||
|
|
||||||
_jitRegion.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
region.Block.MapAsRwx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ReprotectAsExecutable(int offset, int size)
|
private static void ReprotectAsExecutable(ReservedRegion region, int offset, int size)
|
||||||
{
|
{
|
||||||
int endOffs = offset + size;
|
int endOffs = offset + size;
|
||||||
|
|
||||||
int regionStart = offset & ~_pageMask;
|
int regionStart = offset & ~_pageMask;
|
||||||
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
int regionEnd = (endOffs + _pageMask) & ~_pageMask;
|
||||||
|
|
||||||
_jitRegion.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
region.Block.MapAsRx((ulong)regionStart, (ulong)(regionEnd - regionStart));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int Allocate(int codeSize)
|
private static int Allocate(int codeSize)
|
||||||
{
|
{
|
||||||
codeSize = AlignCodeSize(codeSize);
|
codeSize = AlignCodeSize(codeSize);
|
||||||
|
|
||||||
int allocOffset = _cacheAllocator.Allocate(codeSize);
|
for (int i = _activeRegionIndex; i < _jitRegions.Count; i++)
|
||||||
|
|
||||||
if (allocOffset < 0)
|
|
||||||
{
|
{
|
||||||
throw new OutOfMemoryException("JIT Cache exhausted.");
|
int allocOffset = _cacheAllocator.Allocate(codeSize);
|
||||||
|
|
||||||
|
if (allocOffset >= 0)
|
||||||
|
{
|
||||||
|
_jitRegions[i].ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
||||||
|
_activeRegionIndex = i;
|
||||||
|
return allocOffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_jitRegion.ExpandIfNeeded((ulong)allocOffset + (ulong)codeSize);
|
int exhaustedRegion = _activeRegionIndex;
|
||||||
|
var newRegion = new ReservedRegion(_jitRegions[0].Allocator, CacheSize);
|
||||||
|
_jitRegions.Add(newRegion);
|
||||||
|
_activeRegionIndex = _jitRegions.Count - 1;
|
||||||
|
|
||||||
|
int newRegionNumber = _activeRegionIndex;
|
||||||
|
|
||||||
return allocOffset;
|
Logger.Warning?.Print(LogClass.Cpu, $"JIT Cache Region {exhaustedRegion} exhausted, creating new Cache Region {newRegionNumber} ({((newRegionNumber + 1) * CacheSize).Bytes()} Total Allocation).");
|
||||||
|
|
||||||
|
_cacheAllocator = new CacheMemoryAllocator(CacheSize);
|
||||||
|
|
||||||
|
int allocOffsetNew = _cacheAllocator.Allocate(codeSize);
|
||||||
|
if (allocOffsetNew < 0)
|
||||||
|
{
|
||||||
|
throw new OutOfMemoryException("Failed to allocate in new Cache Region!");
|
||||||
|
}
|
||||||
|
|
||||||
|
newRegion.ExpandIfNeeded((ulong)allocOffsetNew + (ulong)codeSize);
|
||||||
|
return allocOffsetNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int AlignCodeSize(int codeSize)
|
private static int AlignCodeSize(int codeSize)
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
|
|||||||
{ BsdSocketOption.SoLinger, SocketOptionName.Linger },
|
{ BsdSocketOption.SoLinger, SocketOptionName.Linger },
|
||||||
{ BsdSocketOption.SoOobInline, SocketOptionName.OutOfBandInline },
|
{ BsdSocketOption.SoOobInline, SocketOptionName.OutOfBandInline },
|
||||||
{ BsdSocketOption.SoReusePort, SocketOptionName.ReuseAddress },
|
{ BsdSocketOption.SoReusePort, SocketOptionName.ReuseAddress },
|
||||||
|
{ BsdSocketOption.SoNoSigpipe, SocketOptionName.DontLinger },
|
||||||
{ BsdSocketOption.SoSndBuf, SocketOptionName.SendBuffer },
|
{ BsdSocketOption.SoSndBuf, SocketOptionName.SendBuffer },
|
||||||
{ BsdSocketOption.SoRcvBuf, SocketOptionName.ReceiveBuffer },
|
{ BsdSocketOption.SoRcvBuf, SocketOptionName.ReceiveBuffer },
|
||||||
{ BsdSocketOption.SoSndLoWat, SocketOptionName.SendLowWater },
|
{ BsdSocketOption.SoSndLoWat, SocketOptionName.SendLowWater },
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using MsgPack;
|
using MsgPack;
|
||||||
using Ryujinx.Horizon.Common;
|
using Ryujinx.Horizon.Common;
|
||||||
using Ryujinx.Horizon.Prepo.Types;
|
|
||||||
using Ryujinx.Memory;
|
using Ryujinx.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@@ -9,7 +8,7 @@ namespace Ryujinx.Horizon
|
|||||||
{
|
{
|
||||||
public static class HorizonStatic
|
public static class HorizonStatic
|
||||||
{
|
{
|
||||||
internal static void HandlePlayReport(PlayReport report) =>
|
internal static void HandlePlayReport(MessagePackObject report) =>
|
||||||
new Thread(() => PlayReport?.Invoke(report))
|
new Thread(() => PlayReport?.Invoke(report))
|
||||||
{
|
{
|
||||||
Name = "HLE.PlayReportEvent",
|
Name = "HLE.PlayReportEvent",
|
||||||
@@ -17,7 +16,7 @@ namespace Ryujinx.Horizon
|
|||||||
Priority = ThreadPriority.AboveNormal
|
Priority = ThreadPriority.AboveNormal
|
||||||
}.Start();
|
}.Start();
|
||||||
|
|
||||||
public static event Action<PlayReport> PlayReport;
|
public static event Action<MessagePackObject> PlayReport;
|
||||||
|
|
||||||
[field: ThreadStatic]
|
[field: ThreadStatic]
|
||||||
public static HorizonOptions Options { get; private set; }
|
public static HorizonOptions Options { get; private set; }
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Gommon;
|
||||||
using MsgPack;
|
using MsgPack;
|
||||||
using MsgPack.Serialization;
|
using MsgPack.Serialization;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
@@ -11,12 +12,19 @@ using Ryujinx.Horizon.Sdk.Sf;
|
|||||||
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
using Ryujinx.Horizon.Sdk.Sf.Hipc;
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId;
|
using ApplicationId = Ryujinx.Horizon.Sdk.Ncm.ApplicationId;
|
||||||
|
|
||||||
namespace Ryujinx.Horizon.Prepo.Ipc
|
namespace Ryujinx.Horizon.Prepo.Ipc
|
||||||
{
|
{
|
||||||
partial class PrepoService : IPrepoService
|
partial class PrepoService : IPrepoService
|
||||||
{
|
{
|
||||||
|
enum PlayReportKind
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
System,
|
||||||
|
}
|
||||||
|
|
||||||
private readonly ArpApi _arp;
|
private readonly ArpApi _arp;
|
||||||
private readonly PrepoServicePermissionLevel _permissionLevel;
|
private readonly PrepoServicePermissionLevel _permissionLevel;
|
||||||
private ulong _systemSessionId;
|
private ulong _systemSessionId;
|
||||||
@@ -188,17 +196,10 @@ namespace Ryujinx.Horizon.Prepo.Ipc
|
|||||||
{
|
{
|
||||||
return PrepoResult.InvalidBufferSize;
|
return PrepoResult.InvalidBufferSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder builder = new();
|
StringBuilder builder = new();
|
||||||
MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(reportBuffer.ToArray());
|
MessagePackObject deserializedReport = MessagePackSerializer.UnpackMessagePackObject(reportBuffer.ToArray());
|
||||||
|
|
||||||
PlayReport playReport = new()
|
|
||||||
{
|
|
||||||
Kind = playReportKind,
|
|
||||||
Room = gameRoom,
|
|
||||||
ReportData = deserializedReport
|
|
||||||
};
|
|
||||||
|
|
||||||
builder.AppendLine();
|
builder.AppendLine();
|
||||||
builder.AppendLine("PlayReport log:");
|
builder.AppendLine("PlayReport log:");
|
||||||
builder.AppendLine($" Kind: {playReportKind}");
|
builder.AppendLine($" Kind: {playReportKind}");
|
||||||
@@ -208,12 +209,10 @@ namespace Ryujinx.Horizon.Prepo.Ipc
|
|||||||
if (pid != 0)
|
if (pid != 0)
|
||||||
{
|
{
|
||||||
builder.AppendLine($" Pid: {pid}");
|
builder.AppendLine($" Pid: {pid}");
|
||||||
playReport.Pid = pid;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
builder.AppendLine($" ApplicationId: {applicationId}");
|
builder.AppendLine($" ApplicationId: {applicationId}");
|
||||||
playReport.AppId = applicationId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result result = _arp.GetApplicationInstanceId(out ulong applicationInstanceId, pid);
|
Result result = _arp.GetApplicationInstanceId(out ulong applicationInstanceId, pid);
|
||||||
@@ -224,20 +223,17 @@ namespace Ryujinx.Horizon.Prepo.Ipc
|
|||||||
|
|
||||||
_arp.GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, applicationInstanceId).AbortOnFailure();
|
_arp.GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, applicationInstanceId).AbortOnFailure();
|
||||||
|
|
||||||
playReport.Version = applicationLaunchProperty.Version;
|
|
||||||
|
|
||||||
builder.AppendLine($" ApplicationVersion: {applicationLaunchProperty.Version}");
|
builder.AppendLine($" ApplicationVersion: {applicationLaunchProperty.Version}");
|
||||||
|
|
||||||
if (!userId.IsNull)
|
if (!userId.IsNull)
|
||||||
{
|
{
|
||||||
builder.AppendLine($" UserId: {userId}");
|
builder.AppendLine($" UserId: {userId}");
|
||||||
playReport.UserId = userId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.AppendLine($" Room: {gameRoom}");
|
builder.AppendLine($" Room: {gameRoom}");
|
||||||
builder.AppendLine($" Report: {MessagePackObjectFormatter.Format(deserializedReport)}");
|
builder.AppendLine($" Report: {MessagePackObjectFormatter.Format(deserializedReport)}");
|
||||||
|
|
||||||
HorizonStatic.HandlePlayReport(playReport);
|
HorizonStatic.HandlePlayReport(deserializedReport);
|
||||||
|
|
||||||
Logger.Info?.Print(LogClass.ServicePrepo, builder.ToString());
|
Logger.Info?.Print(LogClass.ServicePrepo, builder.ToString());
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
using MsgPack;
|
|
||||||
using Ryujinx.Horizon.Sdk.Account;
|
|
||||||
using Ryujinx.Horizon.Sdk.Ncm;
|
|
||||||
|
|
||||||
namespace Ryujinx.Horizon.Prepo.Types
|
|
||||||
{
|
|
||||||
public struct PlayReport
|
|
||||||
{
|
|
||||||
public PlayReportKind Kind { get; init; }
|
|
||||||
public string Room { get; init; }
|
|
||||||
public MessagePackObject ReportData { get; init; }
|
|
||||||
|
|
||||||
public ApplicationId? AppId;
|
|
||||||
public ulong? Pid;
|
|
||||||
public uint Version;
|
|
||||||
public Uid? UserId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum PlayReportKind
|
|
||||||
{
|
|
||||||
Normal,
|
|
||||||
System,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23696,56 +23696,6 @@
|
|||||||
"zh_CN": "选择一个要解压的 DLC",
|
"zh_CN": "选择一个要解压的 DLC",
|
||||||
"zh_TW": ""
|
"zh_TW": ""
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"ID": "GameInfoRpcImage",
|
|
||||||
"Translations": {
|
|
||||||
"ar_SA": "",
|
|
||||||
"de_DE": "",
|
|
||||||
"el_GR": "",
|
|
||||||
"en_US": "Rich Presence Image",
|
|
||||||
"es_ES": "",
|
|
||||||
"fr_FR": "",
|
|
||||||
"he_IL": "",
|
|
||||||
"it_IT": "",
|
|
||||||
"ja_JP": "",
|
|
||||||
"ko_KR": "",
|
|
||||||
"no_NO": "",
|
|
||||||
"pl_PL": "",
|
|
||||||
"pt_BR": "",
|
|
||||||
"ru_RU": "",
|
|
||||||
"sv_SE": "",
|
|
||||||
"th_TH": "",
|
|
||||||
"tr_TR": "",
|
|
||||||
"uk_UA": "",
|
|
||||||
"zh_CN": "",
|
|
||||||
"zh_TW": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ID": "GameInfoRpcDynamic",
|
|
||||||
"Translations": {
|
|
||||||
"ar_SA": "",
|
|
||||||
"de_DE": "",
|
|
||||||
"el_GR": "",
|
|
||||||
"en_US": "Dynamic Rich Presence",
|
|
||||||
"es_ES": "",
|
|
||||||
"fr_FR": "",
|
|
||||||
"he_IL": "",
|
|
||||||
"it_IT": "",
|
|
||||||
"ja_JP": "",
|
|
||||||
"ko_KR": "",
|
|
||||||
"no_NO": "",
|
|
||||||
"pl_PL": "",
|
|
||||||
"pt_BR": "",
|
|
||||||
"ru_RU": "",
|
|
||||||
"sv_SE": "",
|
|
||||||
"th_TH": "",
|
|
||||||
"tr_TR": "",
|
|
||||||
"uk_UA": "",
|
|
||||||
"zh_CN": "",
|
|
||||||
"zh_TW": ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,6 @@ 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 Ryujinx.Horizon.Prepo.Types;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Ryujinx.Ava
|
namespace Ryujinx.Ava
|
||||||
@@ -39,9 +37,6 @@ namespace Ryujinx.Ava
|
|||||||
private static RichPresence _discordPresencePlaying;
|
private static RichPresence _discordPresencePlaying;
|
||||||
private static ApplicationMetadata _currentApp;
|
private static ApplicationMetadata _currentApp;
|
||||||
|
|
||||||
public static bool HasAssetImage(string titleId) => TitleIDs.DiscordGameAssetKeys.ContainsIgnoreCase(titleId);
|
|
||||||
public static bool HasAnalyzer(string titleId) => PlayReports.Analyzer.TitleIds.ContainsIgnoreCase(titleId);
|
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize()
|
||||||
{
|
{
|
||||||
_discordPresenceMain = new RichPresence
|
_discordPresenceMain = new RichPresence
|
||||||
@@ -125,7 +120,7 @@ namespace Ryujinx.Ava
|
|||||||
_currentApp = null;
|
_currentApp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandlePlayReport(PlayReport playReport)
|
private static void HandlePlayReport(MessagePackObject playReport)
|
||||||
{
|
{
|
||||||
if (_discordClient is null) return;
|
if (_discordClient is null) return;
|
||||||
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
|
if (!TitleIDs.CurrentApplication.Value.HasValue) return;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
xmlns:helpers="clr-namespace:Ryujinx.Ava.UI.Helpers"
|
||||||
xmlns:ext="using:Ryujinx.Ava.Common.Markup"
|
xmlns:ext="using:Ryujinx.Ava.Common.Markup"
|
||||||
xmlns:viewModels="using:Ryujinx.Ava.UI.ViewModels"
|
xmlns:viewModels="using:Ryujinx.Ava.UI.ViewModels"
|
||||||
xmlns:ui="using:FluentAvalonia.UI.Controls"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Ryujinx.Ava.UI.Controls.ApplicationDataView"
|
x:Class="Ryujinx.Ava.UI.Controls.ApplicationDataView"
|
||||||
@@ -86,49 +85,6 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Separator Margin="0, 10, 0, 10" Height="1" BorderBrush="Gray" Background="Gray" />
|
<Separator Margin="0, 10, 0, 10" Height="1" BorderBrush="Gray" Background="Gray" />
|
||||||
<StackPanel Orientation="Vertical" Spacing="5">
|
|
||||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
|
||||||
<ui:SymbolIcon Foreground="ForestGreen" Symbol="Checkmark" IsVisible="{Binding AppData.HasRichPresenceAsset}"/>
|
|
||||||
<TextBlock
|
|
||||||
Foreground="ForestGreen"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
IsVisible="{Binding AppData.HasRichPresenceAsset}"
|
|
||||||
Text="{ext:Locale GameInfoRpcImage}"
|
|
||||||
TextAlignment="Start"
|
|
||||||
TextWrapping="Wrap" >
|
|
||||||
</TextBlock>
|
|
||||||
<ui:SymbolIcon Foreground="Red" Symbol="Cancel" IsVisible="{Binding !AppData.HasRichPresenceAsset}"/>
|
|
||||||
<TextBlock
|
|
||||||
Foreground="Red"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
IsVisible="{Binding !AppData.HasRichPresenceAsset}"
|
|
||||||
Text="{ext:Locale GameInfoRpcImage}"
|
|
||||||
TextAlignment="Start"
|
|
||||||
TextWrapping="Wrap" >
|
|
||||||
</TextBlock>
|
|
||||||
</StackPanel>
|
|
||||||
<StackPanel Orientation="Horizontal" Spacing="5">
|
|
||||||
<ui:SymbolIcon Foreground="ForestGreen" Symbol="Checkmark" IsVisible="{Binding AppData.HasDynamicRichPresenceSupport}"/>
|
|
||||||
<TextBlock
|
|
||||||
Foreground="ForestGreen"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
IsVisible="{Binding AppData.HasDynamicRichPresenceSupport}"
|
|
||||||
Text="{ext:Locale GameInfoRpcDynamic}"
|
|
||||||
TextAlignment="Start"
|
|
||||||
TextWrapping="Wrap" >
|
|
||||||
</TextBlock>
|
|
||||||
<ui:SymbolIcon Foreground="Red" Symbol="Cancel" IsVisible="{Binding !AppData.HasDynamicRichPresenceSupport}"/>
|
|
||||||
<TextBlock
|
|
||||||
Foreground="Red"
|
|
||||||
HorizontalAlignment="Stretch"
|
|
||||||
IsVisible="{Binding !AppData.HasDynamicRichPresenceSupport}"
|
|
||||||
Text="{ext:Locale GameInfoRpcDynamic}"
|
|
||||||
TextAlignment="Start"
|
|
||||||
TextWrapping="Wrap" >
|
|
||||||
</TextBlock>
|
|
||||||
</StackPanel>
|
|
||||||
</StackPanel>
|
|
||||||
<Separator Margin="0, 10, 0, 10" Height="1" BorderBrush="Gray" Background="Gray" />
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
IsVisible="{Binding AppData.HasLdnGames}"
|
IsVisible="{Binding AppData.HasLdnGames}"
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace Ryujinx.Ava.UI.Helpers
|
|||||||
LocaleKeys.CompatibilityListNothing or
|
LocaleKeys.CompatibilityListNothing or
|
||||||
LocaleKeys.CompatibilityListBoots or
|
LocaleKeys.CompatibilityListBoots or
|
||||||
LocaleKeys.CompatibilityListMenus => Brushes.Red,
|
LocaleKeys.CompatibilityListMenus => Brushes.Red,
|
||||||
LocaleKeys.CompatibilityListIngame => Brushes.DarkOrange,
|
LocaleKeys.CompatibilityListIngame => Brushes.Yellow,
|
||||||
_ => Brushes.ForestGreen
|
_ => Brushes.ForestGreen
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,6 @@ namespace Ryujinx.Ava.Utilities.AppLibrary
|
|||||||
public int GameCount { get; set; }
|
public int GameCount { get; set; }
|
||||||
|
|
||||||
public bool HasLdnGames => PlayerCount != 0 && GameCount != 0;
|
public bool HasLdnGames => PlayerCount != 0 && GameCount != 0;
|
||||||
|
|
||||||
public bool HasRichPresenceAsset => DiscordIntegrationModule.HasAssetImage(IdString);
|
|
||||||
public bool HasDynamicRichPresenceSupport => DiscordIntegrationModule.HasAnalyzer(IdString);
|
|
||||||
|
|
||||||
public TimeSpan TimePlayed { get; set; }
|
public TimeSpan TimePlayed { get; set; }
|
||||||
public DateTime? LastPlayed { get; set; }
|
public DateTime? LastPlayed { get; set; }
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using MsgPack;
|
|||||||
using Ryujinx.Ava.Utilities.AppLibrary;
|
using Ryujinx.Ava.Utilities.AppLibrary;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -16,10 +15,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
{
|
{
|
||||||
private readonly List<GameSpec> _specs = [];
|
private readonly List<GameSpec> _specs = [];
|
||||||
|
|
||||||
public string[] TitleIds => Specs.SelectMany(x => x.TitleIds).ToArray();
|
|
||||||
|
|
||||||
public IReadOnlyList<GameSpec> Specs => new ReadOnlyCollection<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>
|
||||||
@@ -85,7 +80,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs the configured <see cref="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>
|
||||||
@@ -94,21 +89,54 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
public FormattedValue Format(
|
public FormattedValue Format(
|
||||||
string runningGameId,
|
string runningGameId,
|
||||||
ApplicationMetadata appMeta,
|
ApplicationMetadata appMeta,
|
||||||
Horizon.Prepo.Types.PlayReport playReport
|
MessagePackObject playReport
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (!playReport.ReportData.IsDictionary)
|
if (!playReport.IsDictionary)
|
||||||
return FormattedValue.Unhandled;
|
return FormattedValue.Unhandled;
|
||||||
|
|
||||||
if (!_specs.TryGetFirst(s => runningGameId.EqualsAnyIgnoreCase(s.TitleIds), out GameSpec spec))
|
if (!_specs.TryGetFirst(s => runningGameId.EqualsAnyIgnoreCase(s.TitleIds), out GameSpec spec))
|
||||||
return FormattedValue.Unhandled;
|
return FormattedValue.Unhandled;
|
||||||
|
|
||||||
foreach (FormatterSpecBase formatSpec in spec.ValueFormatters.OrderBy(x => x.Priority))
|
foreach (FormatterSpec formatSpec in spec.SimpleValueFormatters.OrderBy(x => x.Priority))
|
||||||
{
|
{
|
||||||
if (!formatSpec.Format(appMeta, playReport, out FormattedValue value))
|
if (!playReport.AsDictionary().TryGetValue(formatSpec.ReportKey, out MessagePackObject valuePackObject))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return value;
|
return formatSpec.Formatter(new Value { Application = appMeta, PackedValue = valuePackObject });
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (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.Formatter(packedObjects
|
||||||
|
.Select(packObject => new Value { Application = appMeta, PackedValue = packObject })
|
||||||
|
.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (SparseMultiFormatterSpec formatSpec in spec.SparseMultiValueFormatters.OrderBy(x => x.Priority))
|
||||||
|
{
|
||||||
|
Dictionary<string, Value> packedObjects = [];
|
||||||
|
foreach (var reportKey in formatSpec.ReportKeys)
|
||||||
|
{
|
||||||
|
if (!playReport.AsDictionary().TryGetValue(reportKey, out MessagePackObject valuePackObject))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
packedObjects.Add(reportKey, new Value { Application = appMeta, PackedValue = valuePackObject });
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatSpec.Formatter(packedObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FormattedValue.Unhandled;
|
return FormattedValue.Unhandled;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Ryujinx.Ava.Utilities.PlayReport
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Ryujinx.Ava.Utilities.PlayReport
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The delegate type that powers single value formatters.<br/>
|
/// The delegate type that powers single value formatters.<br/>
|
||||||
@@ -10,7 +12,7 @@
|
|||||||
/// <br/>
|
/// <br/>
|
||||||
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate FormattedValue SingleValueFormatter(SingleValue value);
|
public delegate FormattedValue ValueFormatter(Value value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The delegate type that powers multiple value formatters.<br/>
|
/// The delegate type that powers multiple value formatters.<br/>
|
||||||
@@ -22,7 +24,7 @@
|
|||||||
/// <br/>
|
/// <br/>
|
||||||
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate FormattedValue MultiValueFormatter(MultiValue value);
|
public delegate FormattedValue MultiValueFormatter(Value[] value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The delegate type that powers multiple value formatters.
|
/// The delegate type that powers multiple value formatters.
|
||||||
@@ -36,5 +38,5 @@
|
|||||||
/// <br/>
|
/// <br/>
|
||||||
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
/// OR a signal to reset the value that the caller is using the <see cref="Analyzer"/> for.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate FormattedValue SparseMultiValueFormatter(SparseMultiValue value);
|
public delegate FormattedValue SparseMultiValueFormatter(Dictionary<string, Value> values);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
using MsgPack;
|
|
||||||
using Ryujinx.Ava.Utilities.AppLibrary;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ava.Utilities.PlayReport
|
|
||||||
{
|
|
||||||
public abstract class MatchedValue<T>
|
|
||||||
{
|
|
||||||
protected MatchedValue(T matched)
|
|
||||||
{
|
|
||||||
Matched = matched;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The currently running application's <see cref="ApplicationMetadata"/>.
|
|
||||||
/// </summary>
|
|
||||||
public ApplicationMetadata Application { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The entire play report.
|
|
||||||
/// </summary>
|
|
||||||
public Horizon.Prepo.Types.PlayReport PlayReport { get; init; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The matched value from the Play Report.
|
|
||||||
/// </summary>
|
|
||||||
public T Matched { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The input data to a <see cref="SingleValueFormatter"/>,
|
|
||||||
/// containing the currently running application's <see cref="ApplicationMetadata"/>,
|
|
||||||
/// and the matched <see cref="MessagePackObject"/> from the Play Report.
|
|
||||||
/// </summary>
|
|
||||||
public class SingleValue : MatchedValue<Value>
|
|
||||||
{
|
|
||||||
public SingleValue(Value matched) : base(matched)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The input data to a <see cref="MultiValueFormatter"/>,
|
|
||||||
/// containing the currently running application's <see cref="ApplicationMetadata"/>,
|
|
||||||
/// and the matched <see cref="MessagePackObject"/>s from the Play Report.
|
|
||||||
/// </summary>
|
|
||||||
public class MultiValue : MatchedValue<Value[]>
|
|
||||||
{
|
|
||||||
public MultiValue(Value[] matched) : base(matched)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public MultiValue(IEnumerable<MessagePackObject> matched) : base(Value.ConvertPackedObjects(matched))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The input data to a <see cref="SparseMultiValueFormatter"/>,
|
|
||||||
/// containing the currently running application's <see cref="ApplicationMetadata"/>,
|
|
||||||
/// and the matched <see cref="MessagePackObject"/>s from the Play Report.
|
|
||||||
/// </summary>
|
|
||||||
public class SparseMultiValue : MatchedValue<Dictionary<string, Value>>
|
|
||||||
{
|
|
||||||
public SparseMultiValue(Dictionary<string, Value> matched) : base(matched)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public SparseMultiValue(Dictionary<string, MessagePackObject> matched) : base(Value.ConvertPackedObjectMap(matched))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,296 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Buffers.Binary;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ava.Utilities.PlayReport
|
|
||||||
{
|
|
||||||
public partial class PlayReports
|
|
||||||
{
|
|
||||||
private static FormattedValue BreathOfTheWild_MasterMode(SingleValue value)
|
|
||||||
=> value.Matched.BoxedValue is 1 ? "Playing Master Mode" : FormattedValue.ForceReset;
|
|
||||||
|
|
||||||
private static FormattedValue TearsOfTheKingdom_CurrentField(SingleValue value) =>
|
|
||||||
value.Matched.DoubleValue switch
|
|
||||||
{
|
|
||||||
> 800d => "Exploring the Sky Islands",
|
|
||||||
< -201d => "Exploring the Depths",
|
|
||||||
_ => "Roaming Hyrule"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static FormattedValue SuperMarioOdyssey_AssistMode(SingleValue value)
|
|
||||||
=> value.Matched.BoxedValue is 1 ? "Playing in Assist Mode" : "Playing in Regular Mode";
|
|
||||||
|
|
||||||
private static FormattedValue SuperMarioOdysseyChina_AssistMode(SingleValue value)
|
|
||||||
=> value.Matched.BoxedValue is 1 ? "Playing in 帮助模式" : "Playing in 普通模式";
|
|
||||||
|
|
||||||
private static FormattedValue SuperMario3DWorldOrBowsersFury(SingleValue value)
|
|
||||||
=> value.Matched.BoxedValue is 0 ? "Playing Super Mario 3D World" : "Playing Bowser's Fury";
|
|
||||||
|
|
||||||
private static FormattedValue MarioKart8Deluxe_Mode(SingleValue value)
|
|
||||||
=> value.Matched.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(SingleValue value)
|
|
||||||
=> value.Matched.BoxedValue is 0 ? "Playing Alone" : "Playing in a group";
|
|
||||||
|
|
||||||
private static FormattedValue PokemonSVArea(SingleValue value)
|
|
||||||
=> value.Matched.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
|
|
||||||
};
|
|
||||||
|
|
||||||
private static FormattedValue SuperSmashBrosUltimate_Mode(SparseMultiValue values)
|
|
||||||
{
|
|
||||||
// Check if the PlayReport is for a challenger approach or an achievement.
|
|
||||||
if (values.Matched.TryGetValue("fighter", out Value fighter) && values.Matched.ContainsKey("reason"))
|
|
||||||
{
|
|
||||||
return $"Challenger Approaches - {SuperSmashBrosUltimate_Character(fighter)}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (values.Matched.TryGetValue("fighter", out fighter) && values.Matched.ContainsKey("challenge_count"))
|
|
||||||
{
|
|
||||||
return $"Fighter Unlocked - {SuperSmashBrosUltimate_Character(fighter)}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (values.Matched.TryGetValue("anniversary", out Value anniversary))
|
|
||||||
{
|
|
||||||
return $"Achievement Unlocked - ID: {anniversary}";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (values.Matched.ContainsKey("adv_slot"))
|
|
||||||
{
|
|
||||||
return "Playing Adventure Mode"; // Doing this as it can be a placeholder until we can grab the character.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if we have a match_mode at this point, if not, go to default.
|
|
||||||
if (!values.Matched.TryGetValue("match_mode", out Value matchMode))
|
|
||||||
{
|
|
||||||
return "Smashing";
|
|
||||||
}
|
|
||||||
|
|
||||||
return matchMode.BoxedValue switch
|
|
||||||
{
|
|
||||||
0 when values.Matched.TryGetValue("player_1_fighter", out Value player) &&
|
|
||||||
values.Matched.TryGetValue("player_2_fighter", out Value challenger)
|
|
||||||
=> $"Last Smashed: {SuperSmashBrosUltimate_Character(challenger)}'s Fighter Challenge - {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
1 => $"Last Smashed: Normal Battle - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
2 when values.Matched.TryGetValue("player_1_rank", out Value team)
|
|
||||||
=> team.BoxedValue is 0
|
|
||||||
? "Last Smashed: Squad Strike - Red Team Wins"
|
|
||||||
: "Last Smashed: Squad Strike - Blue Team Wins",
|
|
||||||
3 => $"Last Smashed: Custom Smash - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
4 => $"Last Smashed: Super Sudden Death - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
5 => $"Last Smashed: Smashdown - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
6 => $"Last Smashed: Tourney Battle - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
7 when values.Matched.TryGetValue("player_1_fighter", out Value player)
|
|
||||||
=> $"Last Smashed: Spirit Board Battle as {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
8 when values.Matched.TryGetValue("player_1_fighter", out Value player)
|
|
||||||
=> $"Playing Adventure Mode as {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
10 when values.Matched.TryGetValue("match_submode", out Value battle) &&
|
|
||||||
values.Matched.TryGetValue("player_1_fighter", out Value player)
|
|
||||||
=> $"Last Smashed: Classic Mode, Battle {(int)battle.BoxedValue + 1}/8 as {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
12 => $"Last Smashed: Century Smash - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
13 => $"Last Smashed: All-Star Smash - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
14 => $"Last Smashed: Cruel Smash - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
15 when values.Matched.TryGetValue("player_1_fighter", out Value player)
|
|
||||||
=> $"Last Smashed: Home-Run Contest - {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
16 when values.Matched.TryGetValue("player_1_fighter", out Value player1) &&
|
|
||||||
values.Matched.TryGetValue("player_2_fighter", out Value player2)
|
|
||||||
=> $"Last Smashed: Home-Run Content (Co-op) - {SuperSmashBrosUltimate_Character(player1)} and {SuperSmashBrosUltimate_Character(player2)}",
|
|
||||||
17 => $"Last Smashed: Home-Run Contest (Versus) - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
18 when values.Matched.TryGetValue("player_1_fighter", out Value player1) &&
|
|
||||||
values.Matched.TryGetValue("player_2_fighter", out Value player2)
|
|
||||||
=> $"Fresh out of Training mode - {SuperSmashBrosUltimate_Character(player1)} with {SuperSmashBrosUltimate_Character(player2)}",
|
|
||||||
58 => $"Last Smashed: LDN Battle - {SuperSmashBrosUltimate_PlayerListing(values)}",
|
|
||||||
63 when values.Matched.TryGetValue("player_1_fighter", out Value player)
|
|
||||||
=> $"Last Smashed: DLC Spirit Board Battle as {SuperSmashBrosUltimate_Character(player)}",
|
|
||||||
_ => "Smashing"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string SuperSmashBrosUltimate_Character(Value value) =>
|
|
||||||
BinaryPrimitives.ReverseEndianness(
|
|
||||||
BitConverter.ToInt64(((MsgPack.MessagePackExtendedTypeObject)value.BoxedValue).GetBody(), 0)) switch
|
|
||||||
{
|
|
||||||
0x0 => "Mario",
|
|
||||||
0x1 => "Donkey Kong",
|
|
||||||
0x2 => "Link",
|
|
||||||
0x3 => "Samus",
|
|
||||||
0x4 => "Dark Samus",
|
|
||||||
0x5 => "Yoshi",
|
|
||||||
0x6 => "Kirby",
|
|
||||||
0x7 => "Fox",
|
|
||||||
0x8 => "Pikachu",
|
|
||||||
0x9 => "Luigi",
|
|
||||||
0xA => "Ness",
|
|
||||||
0xB => "Captain Falcon",
|
|
||||||
0xC => "Jigglypuff",
|
|
||||||
0xD => "Peach",
|
|
||||||
0xE => "Daisy",
|
|
||||||
0xF => "Bowser",
|
|
||||||
0x10 => "Ice Climbers",
|
|
||||||
0x11 => "Sheik",
|
|
||||||
0x12 => "Zelda",
|
|
||||||
0x13 => "Dr. Mario",
|
|
||||||
0x14 => "Pichu",
|
|
||||||
0x15 => "Falco",
|
|
||||||
0x16 => "Marth",
|
|
||||||
0x17 => "Lucina",
|
|
||||||
0x18 => "Young Link",
|
|
||||||
0x19 => "Ganondorf",
|
|
||||||
0x1A => "Mewtwo",
|
|
||||||
0x1B => "Roy",
|
|
||||||
0x1C => "Chrom",
|
|
||||||
0x1D => "Mr Game & Watch",
|
|
||||||
0x1E => "Meta Knight",
|
|
||||||
0x1F => "Pit",
|
|
||||||
0x20 => "Dark Pit",
|
|
||||||
0x21 => "Zero Suit Samus",
|
|
||||||
0x22 => "Wario",
|
|
||||||
0x23 => "Snake",
|
|
||||||
0x24 => "Ike",
|
|
||||||
0x25 => "Pokémon Trainer",
|
|
||||||
0x26 => "Diddy Kong",
|
|
||||||
0x27 => "Lucas",
|
|
||||||
0x28 => "Sonic",
|
|
||||||
0x29 => "King Dedede",
|
|
||||||
0x2A => "Olimar",
|
|
||||||
0x2B => "Lucario",
|
|
||||||
0x2C => "R.O.B.",
|
|
||||||
0x2D => "Toon Link",
|
|
||||||
0x2E => "Wolf",
|
|
||||||
0x2F => "Villager",
|
|
||||||
0x30 => "Mega Man",
|
|
||||||
0x31 => "Wii Fit Trainer",
|
|
||||||
0x32 => "Rosalina & Luma",
|
|
||||||
0x33 => "Little Mac",
|
|
||||||
0x34 => "Greninja",
|
|
||||||
0x35 => "Palutena",
|
|
||||||
0x36 => "Pac-Man",
|
|
||||||
0x37 => "Robin",
|
|
||||||
0x38 => "Shulk",
|
|
||||||
0x39 => "Bowser Jr.",
|
|
||||||
0x3A => "Duck Hunt",
|
|
||||||
0x3B => "Ryu",
|
|
||||||
0x3C => "Ken",
|
|
||||||
0x3D => "Cloud",
|
|
||||||
0x3E => "Corrin",
|
|
||||||
0x3F => "Bayonetta",
|
|
||||||
0x40 => "Richter",
|
|
||||||
0x41 => "Inkling",
|
|
||||||
0x42 => "Ridley",
|
|
||||||
0x43 => "King K. Rool",
|
|
||||||
0x44 => "Simon",
|
|
||||||
0x45 => "Isabelle",
|
|
||||||
0x46 => "Incineroar",
|
|
||||||
0x47 => "Mii Brawler",
|
|
||||||
0x48 => "Mii Swordfighter",
|
|
||||||
0x49 => "Mii Gunner",
|
|
||||||
0x4A => "Piranha Plant",
|
|
||||||
0x4B => "Joker",
|
|
||||||
0x4C => "Hero",
|
|
||||||
0x4D => "Banjo",
|
|
||||||
0x4E => "Terry",
|
|
||||||
0x4F => "Byleth",
|
|
||||||
0x50 => "Min Min",
|
|
||||||
0x51 => "Steve",
|
|
||||||
0x52 => "Sephiroth",
|
|
||||||
0x53 => "Pyra/Mythra",
|
|
||||||
0x54 => "Kazuya",
|
|
||||||
0x55 => "Sora",
|
|
||||||
0xFE => "Random",
|
|
||||||
0xFF => "Scripted Entity",
|
|
||||||
_ => "Unknown"
|
|
||||||
};
|
|
||||||
|
|
||||||
private static string SuperSmashBrosUltimate_PlayerListing(SparseMultiValue values)
|
|
||||||
{
|
|
||||||
List<(string Character, int PlayerNumber, int? Rank)> players = [];
|
|
||||||
|
|
||||||
foreach (KeyValuePair<string, Value> player in values.Matched)
|
|
||||||
{
|
|
||||||
if (player.Key.StartsWith("player_") && player.Key.EndsWith("_fighter") &&
|
|
||||||
player.Value.BoxedValue is not null)
|
|
||||||
{
|
|
||||||
if (!int.TryParse(player.Key.Split('_')[1], out int playerNumber))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string character = SuperSmashBrosUltimate_Character(player.Value);
|
|
||||||
int? rank = values.Matched.TryGetValue($"player_{playerNumber}_rank", out Value rankValue)
|
|
||||||
? rankValue.IntValue
|
|
||||||
: null;
|
|
||||||
|
|
||||||
players.Add((character, playerNumber, rank));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
players = players.OrderBy(p => p.Rank ?? int.MaxValue).ToList();
|
|
||||||
|
|
||||||
return players.Count > 4
|
|
||||||
? $"{players.Count} Players - " + string.Join(", ",
|
|
||||||
players.Take(3).Select(p => $"{p.Character}({p.PlayerNumber}){RankMedal(p.Rank)}"))
|
|
||||||
: string.Join(", ", players.Select(p => $"{p.Character}({p.PlayerNumber}){RankMedal(p.Rank)}"));
|
|
||||||
|
|
||||||
string RankMedal(int? rank) => rank switch
|
|
||||||
{
|
|
||||||
0 => "🥇",
|
|
||||||
1 => "🥈",
|
|
||||||
2 => "🥉",
|
|
||||||
_ => ""
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,6 @@
|
|||||||
using System;
|
namespace Ryujinx.Ava.Utilities.PlayReport
|
||||||
using System.Buffers.Binary;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ava.Utilities.PlayReport
|
|
||||||
{
|
{
|
||||||
public static partial class PlayReports
|
public static class PlayReports
|
||||||
{
|
{
|
||||||
public static Analyzer Analyzer { get; } = new Analyzer()
|
public static Analyzer Analyzer { get; } = new Analyzer()
|
||||||
.AddSpec(
|
.AddSpec(
|
||||||
@@ -42,23 +37,91 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
spec => spec
|
spec => spec
|
||||||
.AddValueFormatter("area_no", PokemonSVArea)
|
.AddValueFormatter("area_no", PokemonSVArea)
|
||||||
.AddValueFormatter("team_circle", PokemonSVUnionCircle)
|
.AddValueFormatter("team_circle", PokemonSVUnionCircle)
|
||||||
).AddSpec(
|
|
||||||
"01006a800016e000",
|
|
||||||
spec => spec
|
|
||||||
.AddSparseMultiValueFormatter(
|
|
||||||
[
|
|
||||||
// Metadata to figure out what PlayReport we have.
|
|
||||||
"match_mode", "match_submode", "anniversary", "fighter", "reason", "challenge_count",
|
|
||||||
"adv_slot",
|
|
||||||
// List of Fighters
|
|
||||||
"player_1_fighter", "player_2_fighter", "player_3_fighter", "player_4_fighter",
|
|
||||||
"player_5_fighter", "player_6_fighter", "player_7_fighter", "player_8_fighter",
|
|
||||||
// List of rankings/placements
|
|
||||||
"player_1_rank", "player_2_rank", "player_3_rank", "player_4_rank", "player_5_rank",
|
|
||||||
"player_6_rank", "player_7_rank", "player_8_rank"
|
|
||||||
],
|
|
||||||
SuperSmashBrosUltimate_Mode
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
using FluentAvalonia.Core;
|
using FluentAvalonia.Core;
|
||||||
using MsgPack;
|
|
||||||
using Ryujinx.Ava.Utilities.AppLibrary;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@@ -14,11 +11,10 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class GameSpec
|
public class GameSpec
|
||||||
{
|
{
|
||||||
private int _lastPriority;
|
|
||||||
|
|
||||||
public required string[] TitleIds { get; init; }
|
public required string[] TitleIds { get; init; }
|
||||||
|
public List<FormatterSpec> SimpleValueFormatters { get; } = [];
|
||||||
public List<FormatterSpecBase> ValueFormatters { get; } = [];
|
public List<MultiFormatterSpec> MultiValueFormatters { get; } = [];
|
||||||
|
public List<SparseMultiFormatterSpec> SparseMultiValueFormatters { get; } = [];
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,8 +24,8 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <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="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddValueFormatter(string reportKey, SingleValueFormatter valueFormatter)
|
public GameSpec AddValueFormatter(string reportKey, ValueFormatter valueFormatter)
|
||||||
=> AddValueFormatter(_lastPriority++, reportKey, valueFormatter);
|
=> AddValueFormatter(SimpleValueFormatters.Count, reportKey, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@@ -40,11 +36,11 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <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="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddValueFormatter(int priority, string reportKey,
|
public GameSpec AddValueFormatter(int priority, string reportKey,
|
||||||
SingleValueFormatter valueFormatter)
|
ValueFormatter valueFormatter)
|
||||||
{
|
{
|
||||||
ValueFormatters.Add(new FormatterSpec
|
SimpleValueFormatters.Add(new FormatterSpec
|
||||||
{
|
{
|
||||||
Priority = priority, ReportKeys = [reportKey], Formatter = valueFormatter
|
Priority = priority, ReportKey = reportKey, Formatter = valueFormatter
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -57,7 +53,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddMultiValueFormatter(string[] reportKeys, MultiValueFormatter valueFormatter)
|
public GameSpec AddMultiValueFormatter(string[] reportKeys, MultiValueFormatter valueFormatter)
|
||||||
=> AddMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
=> AddMultiValueFormatter(MultiValueFormatters.Count, reportKeys, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@@ -70,7 +66,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
public GameSpec AddMultiValueFormatter(int priority, string[] reportKeys,
|
public GameSpec AddMultiValueFormatter(int priority, string[] reportKeys,
|
||||||
MultiValueFormatter valueFormatter)
|
MultiValueFormatter valueFormatter)
|
||||||
{
|
{
|
||||||
ValueFormatters.Add(new MultiFormatterSpec
|
MultiValueFormatters.Add(new MultiFormatterSpec
|
||||||
{
|
{
|
||||||
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
||||||
});
|
});
|
||||||
@@ -88,7 +84,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <param name="valueFormatter">The function which can format the values.</param>
|
/// <param name="valueFormatter">The function which can format the values.</param>
|
||||||
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
/// <returns>The current <see cref="GameSpec"/>, for chaining convenience.</returns>
|
||||||
public GameSpec AddSparseMultiValueFormatter(string[] reportKeys, SparseMultiValueFormatter valueFormatter)
|
public GameSpec AddSparseMultiValueFormatter(string[] reportKeys, SparseMultiValueFormatter valueFormatter)
|
||||||
=> AddSparseMultiValueFormatter(_lastPriority++, reportKeys, valueFormatter);
|
=> AddSparseMultiValueFormatter(SparseMultiValueFormatters.Count, reportKeys, valueFormatter);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
/// Add a multi-value formatter at a specific priority to the current <see cref="GameSpec"/>
|
||||||
@@ -104,7 +100,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
public GameSpec AddSparseMultiValueFormatter(int priority, string[] reportKeys,
|
public GameSpec AddSparseMultiValueFormatter(int priority, string[] reportKeys,
|
||||||
SparseMultiValueFormatter valueFormatter)
|
SparseMultiValueFormatter valueFormatter)
|
||||||
{
|
{
|
||||||
ValueFormatters.Add(new SparseMultiFormatterSpec
|
SparseMultiValueFormatters.Add(new SparseMultiFormatterSpec
|
||||||
{
|
{
|
||||||
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
Priority = priority, ReportKeys = reportKeys, Formatter = valueFormatter
|
||||||
});
|
});
|
||||||
@@ -115,101 +111,30 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class FormatterSpec : FormatterSpecBase
|
public struct FormatterSpec
|
||||||
{
|
{
|
||||||
public override bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object result)
|
public required int Priority { get; init; }
|
||||||
{
|
public required string ReportKey { get; init; }
|
||||||
if (!playReport.ReportData.AsDictionary().TryGetValue(ReportKeys[0], out MessagePackObject valuePackObject))
|
public ValueFormatter Formatter { get; init; }
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = valuePackObject;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
public class MultiFormatterSpec : FormatterSpecBase
|
public struct MultiFormatterSpec
|
||||||
{
|
{
|
||||||
public override bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object result)
|
public required int Priority { get; init; }
|
||||||
{
|
public required string[] ReportKeys { get; init; }
|
||||||
List<MessagePackObject> packedObjects = [];
|
public MultiValueFormatter Formatter { get; init; }
|
||||||
foreach (var reportKey in ReportKeys)
|
|
||||||
{
|
|
||||||
if (!playReport.ReportData.AsDictionary().TryGetValue(reportKey, out MessagePackObject valuePackObject))
|
|
||||||
{
|
|
||||||
result = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
packedObjects.Add(valuePackObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = packedObjects;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A struct containing the data for a mapping of an arbitrary key set in a Play Report to a formatter for their sparsely populated potential values.
|
/// A struct containing the data for a mapping of an arbitrary key set in a Play Report to a formatter for their sparsely populated potential values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SparseMultiFormatterSpec : FormatterSpecBase
|
public struct SparseMultiFormatterSpec
|
||||||
{
|
{
|
||||||
public override bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object result)
|
public required int Priority { get; init; }
|
||||||
{
|
public required string[] ReportKeys { get; init; }
|
||||||
Dictionary<string, MessagePackObject> packedObjects = [];
|
public SparseMultiValueFormatter Formatter { get; init; }
|
||||||
foreach (var reportKey in ReportKeys)
|
|
||||||
{
|
|
||||||
if (!playReport.ReportData.AsDictionary().TryGetValue(reportKey, out MessagePackObject valuePackObject))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
packedObjects.Add(reportKey, valuePackObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
result = packedObjects;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class FormatterSpecBase
|
|
||||||
{
|
|
||||||
public abstract bool GetData(Horizon.Prepo.Types.PlayReport playReport, out object data);
|
|
||||||
|
|
||||||
public int Priority { get; init; }
|
|
||||||
public string[] ReportKeys { get; init; }
|
|
||||||
public Delegate Formatter { get; init; }
|
|
||||||
|
|
||||||
public bool Format(ApplicationMetadata appMeta, Horizon.Prepo.Types.PlayReport playReport, out FormattedValue formattedValue)
|
|
||||||
{
|
|
||||||
formattedValue = default;
|
|
||||||
if (!GetData(playReport, out object data))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (data is FormattedValue fv)
|
|
||||||
{
|
|
||||||
formattedValue = fv;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (Formatter)
|
|
||||||
{
|
|
||||||
case SingleValueFormatter svf when data is MessagePackObject mpo:
|
|
||||||
formattedValue = svf(new SingleValue(mpo) { Application = appMeta, PlayReport = playReport });
|
|
||||||
return true;
|
|
||||||
case MultiValueFormatter mvf when data is List<MessagePackObject> messagePackObjects:
|
|
||||||
formattedValue = mvf(new MultiValue(messagePackObjects) { Application = appMeta, PlayReport = playReport });
|
|
||||||
return true;
|
|
||||||
case SparseMultiValueFormatter smvf when
|
|
||||||
data is Dictionary<string, MessagePackObject> sparseMessagePackObjects:
|
|
||||||
formattedValue = smvf(new SparseMultiValue(sparseMessagePackObjects) { Application = appMeta, PlayReport = playReport });
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
throw new InvalidOperationException("Formatter delegate is not of a known type!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
using MsgPack;
|
using MsgPack;
|
||||||
|
using Ryujinx.Ava.Utilities.AppLibrary;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Ryujinx.Ava.Utilities.PlayReport
|
namespace Ryujinx.Ava.Utilities.PlayReport
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The base input data to a ValueFormatter delegate,
|
/// The input data to a <see cref="ValueFormatter"/>,
|
||||||
|
/// 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 readonly struct Value
|
public class Value
|
||||||
{
|
{
|
||||||
public Value(MessagePackObject packedValue)
|
/// <summary>
|
||||||
{
|
/// The currently running application's <see cref="ApplicationMetadata"/>.
|
||||||
PackedValue = packedValue;
|
/// </summary>
|
||||||
}
|
public ApplicationMetadata Application { get; init; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The matched value from the Play Report.
|
/// The matched value from the Play Report.
|
||||||
@@ -37,17 +37,6 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
: boxed.ToString();
|
: boxed.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static implicit operator Value(MessagePackObject matched) => new(matched);
|
|
||||||
|
|
||||||
public static Value[] ConvertPackedObjects(IEnumerable<MessagePackObject> packObjects)
|
|
||||||
=> packObjects.Select(packObject => new Value(packObject)).ToArray();
|
|
||||||
|
|
||||||
public static Dictionary<string, Value> ConvertPackedObjectMap(Dictionary<string, MessagePackObject> packObjects)
|
|
||||||
=> packObjects.ToDictionary(
|
|
||||||
x => x.Key,
|
|
||||||
x => new Value(x.Value)
|
|
||||||
);
|
|
||||||
|
|
||||||
#region AsX accessors
|
#region AsX accessors
|
||||||
|
|
||||||
public bool BooleanValue => PackedValue.AsBoolean();
|
public bool BooleanValue => PackedValue.AsBoolean();
|
||||||
@@ -68,7 +57,7 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A potential formatted value returned by a ValueFormatter delegate.
|
/// A potential formatted value returned by a <see cref="ValueFormatter"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly struct FormattedValue
|
public readonly struct FormattedValue
|
||||||
{
|
{
|
||||||
@@ -114,47 +103,28 @@ namespace Ryujinx.Ava.Utilities.PlayReport
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return this to tell the caller there is no value to return.
|
/// Return this to tell the caller there is no value to return.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly 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="Analyzer"/> for.
|
/// Return this to suggest the caller reset the value it's using the <see cref="Analyzer"/> for.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly 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="SingleValueFormatter"/>.
|
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="ValueFormatter"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly SingleValueFormatter SingleAlwaysResets = _ => ForceReset;
|
public static readonly ValueFormatter SingleAlwaysResets = _ => ForceReset;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="MultiValueFormatter"/>.
|
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="MultiValueFormatter"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly MultiValueFormatter MultiAlwaysResets = _ => ForceReset;
|
public static readonly MultiValueFormatter MultiAlwaysResets = _ => ForceReset;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A delegate singleton you can use to always return <see cref="ForceReset"/> in a <see cref="SparseMultiValueFormatter"/>.
|
|
||||||
/// </summary>
|
|
||||||
public static readonly SparseMultiValueFormatter SparseMultiAlwaysResets = _ => 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="SingleValueFormatter"/>.
|
/// <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 SingleValueFormatter SingleAlwaysReturns(string formattedValue) => _ => formattedValue;
|
public static ValueFormatter AlwaysReturns(string formattedValue) => _ => formattedValue;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A delegate factory you can use to always return the specified
|
|
||||||
/// <paramref name="formattedValue"/> in a <see cref="MultiValueFormatter"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="formattedValue">The string to always return for this delegate instance.</param>
|
|
||||||
public static MultiValueFormatter MultiAlwaysReturns(string formattedValue) => _ => formattedValue;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A delegate factory you can use to always return the specified
|
|
||||||
/// <paramref name="formattedValue"/> in a <see cref="SparseMultiValueFormatter"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="formattedValue">The string to always return for this delegate instance.</param>
|
|
||||||
public static SparseMultiValueFormatter SparseMultiAlwaysReturns(string formattedValue) => _ => formattedValue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user