mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-12 17:26:28 +02:00
misc: Overhaul DirtyHacks saving to support storing a value alongside an off/off flag.
This commit is contained in:
parent
f5ce539de9
commit
f362bef43d
13 changed files with 190 additions and 27 deletions
|
@ -1,11 +1,52 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.Common.Configuration
|
||||
{
|
||||
[Flags]
|
||||
public enum DirtyHacks
|
||||
public enum DirtyHacks : byte
|
||||
{
|
||||
None = 0,
|
||||
Xc2MenuSoftlockFix = 1 << 10
|
||||
Xc2MenuSoftlockFix = 1,
|
||||
ShaderCompilationThreadSleep = 2
|
||||
}
|
||||
|
||||
public record EnabledDirtyHack(DirtyHacks Hack, int Value)
|
||||
{
|
||||
private static readonly byte[] _packedFormat = [8, 32];
|
||||
|
||||
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], _packedFormat);
|
||||
|
||||
public static EnabledDirtyHack FromPacked(ulong packedHack)
|
||||
{
|
||||
var unpackedFields = BitTricks.UnpackBitFields(packedHack, _packedFormat);
|
||||
if (unpackedFields is not [var hack, var value])
|
||||
throw new ArgumentException(nameof(packedHack));
|
||||
|
||||
return new EnabledDirtyHack((DirtyHacks)hack, (int)value);
|
||||
}
|
||||
}
|
||||
|
||||
public class DirtyHackCollection : Dictionary<DirtyHacks, int>
|
||||
{
|
||||
public DirtyHackCollection(EnabledDirtyHack[] hacks)
|
||||
{
|
||||
foreach ((DirtyHacks dirtyHacks, int value) in hacks)
|
||||
{
|
||||
Add(dirtyHacks, value);
|
||||
}
|
||||
}
|
||||
|
||||
public DirtyHackCollection(ulong[] packedHacks)
|
||||
{
|
||||
foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.FromPacked))
|
||||
{
|
||||
Add(dirtyHacks, value);
|
||||
}
|
||||
}
|
||||
|
||||
public new int this[DirtyHacks hack] => TryGetValue(hack, out var value) ? value : -1;
|
||||
|
||||
public bool IsEnabled(DirtyHacks hack) => ContainsKey(hack);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue