misc: prevent crashes
This commit is contained in:
@@ -13,13 +13,13 @@ namespace Ryujinx.Common.Configuration
|
||||
|
||||
public record EnabledDirtyHack(DirtyHacks Hack, int Value)
|
||||
{
|
||||
private static readonly byte[] _packedFormat = [8, 32];
|
||||
public static readonly byte[] PackedFormat = [8, 32];
|
||||
|
||||
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], _packedFormat);
|
||||
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], PackedFormat);
|
||||
|
||||
public static EnabledDirtyHack FromPacked(ulong packedHack)
|
||||
{
|
||||
var unpackedFields = BitTricks.UnpackBitFields(packedHack, _packedFormat);
|
||||
var unpackedFields = BitTricks.UnpackBitFields(packedHack, PackedFormat);
|
||||
if (unpackedFields is not [var hack, var value])
|
||||
throw new ArgumentException(nameof(packedHack));
|
||||
|
||||
@@ -45,6 +45,15 @@ namespace Ryujinx.Common.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
public ulong[] PackEntries() =>
|
||||
this
|
||||
.Select(it =>
|
||||
BitTricks.PackBitFields([(uint)it.Key, (uint)it.Value], EnabledDirtyHack.PackedFormat))
|
||||
.ToArray();
|
||||
|
||||
public static implicit operator DirtyHackCollection(EnabledDirtyHack[] hacks) => new(hacks);
|
||||
public static implicit operator DirtyHackCollection(ulong[] packedHacks) => new(packedHacks);
|
||||
|
||||
public new int this[DirtyHacks hack] => TryGetValue(hack, out var value) ? value : -1;
|
||||
|
||||
public bool IsEnabled(DirtyHacks hack) => ContainsKey(hack);
|
||||
|
||||
Reference in New Issue
Block a user