2024-12-29 04:04:21 +00:00
|
|
|
|
using System;
|
2024-12-30 03:17:01 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-12-29 04:04:21 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Configuration
|
|
|
|
|
{
|
|
|
|
|
[Flags]
|
2024-12-30 03:17:01 +00:00
|
|
|
|
public enum DirtyHacks : byte
|
2024-12-29 04:04:21 +00:00
|
|
|
|
{
|
2024-12-30 03:17:01 +00:00
|
|
|
|
Xc2MenuSoftlockFix = 1,
|
|
|
|
|
ShaderCompilationThreadSleep = 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record EnabledDirtyHack(DirtyHacks Hack, int Value)
|
|
|
|
|
{
|
2024-12-30 05:39:40 +00:00
|
|
|
|
public static readonly byte[] PackedFormat = [8, 32];
|
2024-12-30 03:17:01 +00:00
|
|
|
|
|
2024-12-30 05:39:40 +00:00
|
|
|
|
public ulong Pack() => BitTricks.PackBitFields([(uint)Hack, (uint)Value], PackedFormat);
|
2024-12-30 03:17:01 +00:00
|
|
|
|
|
2024-12-30 06:14:55 +00:00
|
|
|
|
public static EnabledDirtyHack Unpack(ulong packedHack)
|
2024-12-30 03:17:01 +00:00
|
|
|
|
{
|
2024-12-30 05:39:40 +00:00
|
|
|
|
var unpackedFields = BitTricks.UnpackBitFields(packedHack, PackedFormat);
|
2024-12-30 03:17:01 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2024-12-30 06:14:55 +00:00
|
|
|
|
foreach ((DirtyHacks dirtyHacks, int value) in packedHacks.Select(EnabledDirtyHack.Unpack))
|
2024-12-30 03:17:01 +00:00
|
|
|
|
{
|
|
|
|
|
Add(dirtyHacks, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-30 05:39:40 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2024-12-30 03:17:01 +00:00
|
|
|
|
public new int this[DirtyHacks hack] => TryGetValue(hack, out var value) ? value : -1;
|
|
|
|
|
|
|
|
|
|
public bool IsEnabled(DirtyHacks hack) => ContainsKey(hack);
|
2024-12-29 04:04:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|