misc: chore: Merge into pattern

This commit is contained in:
KeatonTheBot
2025-09-24 13:51:15 -05:00
parent 503dea74c2
commit fa682d406e
157 changed files with 470 additions and 546 deletions
@@ -152,14 +152,12 @@ namespace Ryujinx.HLE.HOS.Applets
private bool InputModeControllerEnabled()
{
return _inputMode == KeyboardInputMode.ControllerAndKeyboard ||
_inputMode == KeyboardInputMode.ControllerOnly;
return _inputMode is KeyboardInputMode.ControllerAndKeyboard or KeyboardInputMode.ControllerOnly;
}
private bool InputModeTypingEnabled()
{
return _inputMode == KeyboardInputMode.ControllerAndKeyboard ||
_inputMode == KeyboardInputMode.KeyboardOnly;
return _inputMode is KeyboardInputMode.ControllerAndKeyboard or KeyboardInputMode.KeyboardOnly;
}
private void AdvanceInputMode()
@@ -69,14 +69,17 @@ namespace Ryujinx.HLE.HOS
mode = MemoryManagerMode.SoftwarePageTable;
}
ICpuEngine cpuEngine = isArm64Host && (mode == MemoryManagerMode.HostMapped || mode == MemoryManagerMode.HostMappedUnsafe) && !context.Device.Configuration.EnableGdbStub
ICpuEngine cpuEngine = isArm64Host &&
mode is MemoryManagerMode.HostMapped or MemoryManagerMode.HostMappedUnsafe &&
!context.Device.Configuration.EnableGdbStub
? new LightningJitEngine(_tickSource)
: new JitEngine(_tickSource);
AddressSpace addressSpace = null;
// We want to use host tracked mode if the host page size is > 4KB.
if ((mode == MemoryManagerMode.HostMapped || mode == MemoryManagerMode.HostMappedUnsafe) && MemoryBlock.GetPageSize() <= 0x1000)
if (mode is MemoryManagerMode.HostMapped or MemoryManagerMode.HostMappedUnsafe &&
MemoryBlock.GetPageSize() <= 0x1000)
{
if (!AddressSpace.TryCreate(context.Memory, addressSpaceSize, out addressSpace))
{
@@ -1430,10 +1430,10 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler
}
char foldKind = Peek();
bool hasInitializer = foldKind == 'L' || foldKind == 'R';
bool isLeftFold = foldKind == 'l' || foldKind == 'L';
bool hasInitializer = foldKind is 'L' or 'R';
bool isLeftFold = foldKind is 'l' or 'L';
if (!isLeftFold && !(foldKind == 'r' || foldKind == 'R'))
if (!isLeftFold && !(foldKind is 'r' or 'R'))
{
return null;
}
@@ -943,7 +943,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Ipc
{
return KernelResult.OutOfResource;
}
else if (recvListType == 1 || recvListType == 2)
else if (recvListType is 1 or 2)
{
ulong recvListBaseAddr;
ulong recvListEndAddr;
@@ -86,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
return KernelResult.InvalidState;
}
Debug.Assert(permission == KMemoryPermission.Read || permission == KMemoryPermission.ReadAndExecute);
Debug.Assert(permission is KMemoryPermission.Read or KMemoryPermission.ReadAndExecute);
Result result = Owner.MemoryManager.MapPages(address, _pageList, MemoryState.CodeReadOnly, permission);
+10 -14
View File
@@ -134,7 +134,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Pid = KernelContext.NewKipId();
if (Pid == 0 || Pid >= KernelConstants.InitialProcessId)
if (Pid is 0 or >= KernelConstants.InitialProcessId)
{
throw new InvalidOperationException($"Invalid KIP Id {Pid}.");
}
@@ -237,7 +237,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
Pid = KernelContext.NewProcessId();
if (Pid == ulong.MaxValue || Pid < KernelConstants.InitialProcessId)
if (Pid is ulong.MaxValue or < KernelConstants.InitialProcessId)
{
throw new InvalidOperationException($"Invalid Process Id {Pid}.");
}
@@ -897,10 +897,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
{
if (State >= ProcessState.Started)
{
if (State == ProcessState.Started ||
State == ProcessState.Crashed ||
State == ProcessState.Attached ||
State == ProcessState.DebugSuspended)
if (State is ProcessState.Started
or ProcessState.Crashed
or ProcessState.Attached
or ProcessState.DebugSuspended)
{
SetState(ProcessState.Exiting);
@@ -938,16 +938,12 @@ namespace Ryujinx.HLE.HOS.Kernel.Process
lock (_processLock)
{
if (State >= ProcessState.Started)
if (State is >= ProcessState.Started
and (ProcessState.Started or ProcessState.Attached or ProcessState.DebugSuspended))
{
if (State == ProcessState.Started ||
State == ProcessState.Attached ||
State == ProcessState.DebugSuspended)
{
SetState(ProcessState.Exiting);
SetState(ProcessState.Exiting);
shallTerminate = true;
}
shallTerminate = true;
}
}
@@ -1191,7 +1191,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidMemState;
}
if (permission > KMemoryPermission.ReadAndWrite || permission == KMemoryPermission.Write)
if (permission is > KMemoryPermission.ReadAndWrite or KMemoryPermission.Write)
{
return KernelResult.InvalidPermission;
}
@@ -1253,7 +1253,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
return KernelResult.InvalidMemState;
}
if (permission > KMemoryPermission.ReadAndWrite || permission == KMemoryPermission.Write)
if (permission is > KMemoryPermission.ReadAndWrite or KMemoryPermission.Write)
{
return KernelResult.InvalidPermission;
}
@@ -2126,7 +2126,7 @@ namespace Ryujinx.HLE.HOS.Kernel.SupervisorCall
case InfoType.ThreadTickCount:
{
if (subId < -1 || subId > 3)
if (subId is < -1 or > 3)
{
return KernelResult.InvalidCombination;
}
@@ -50,7 +50,7 @@ namespace Ryujinx.HLE.HOS.Services.Caps
MemoryHelper.FillWithZeros(context.Memory, applicationAlbumFileEntryPosition, (int)applicationAlbumFileEntrySize);
if (contentType > ContentType.Unknown || contentType == ContentType.ExtraMovie)
if (contentType is > ContentType.Unknown or ContentType.ExtraMovie)
{
resultCode = ResultCode.InvalidContentType;
}
@@ -1141,7 +1141,7 @@ namespace Ryujinx.HLE.HOS.Services.Hid
NpadStyleIndex deviceType = (NpadStyleIndex)deviceHandle.DeviceType;
NpadIdType npadIdType = (NpadIdType)deviceHandle.PlayerId;
if (deviceType < NpadStyleIndex.System || deviceType >= NpadStyleIndex.FullKey)
if (deviceType is < NpadStyleIndex.System or >= NpadStyleIndex.FullKey)
{
if (!HidUtils.IsValidNpadIdType(npadIdType))
{
@@ -178,7 +178,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
// NOTE: Return ResultCode.InvalidArgument if ip_address and subnet_mask are null, doesn't occur in our case.
if (_state == NetworkState.AccessPointCreated || _state == NetworkState.StationConnected)
if (_state is NetworkState.AccessPointCreated or NetworkState.StationConnected)
{
ProxyConfig config = _state switch
{
@@ -525,7 +525,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
return _nifmResultCode;
}
if (_state == NetworkState.AccessPoint || _state == NetworkState.AccessPointCreated)
if (_state is NetworkState.AccessPoint or NetworkState.AccessPointCreated)
{
DestroyNetworkImpl(DisconnectReason.DestroyedByUser);
}
@@ -701,12 +701,12 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
return _nifmResultCode;
}
if (bufferSize == 0 || bufferSize > LdnConst.AdvertiseDataSizeMax)
if (bufferSize is 0 or > LdnConst.AdvertiseDataSizeMax)
{
return ResultCode.InvalidArgument;
}
if (_state == NetworkState.AccessPoint || _state == NetworkState.AccessPointCreated)
if (_state is NetworkState.AccessPoint or NetworkState.AccessPointCreated)
{
byte[] advertiseData = new byte[bufferSize];
@@ -736,7 +736,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
return ResultCode.InvalidArgument;
}
if (_state == NetworkState.AccessPoint || _state == NetworkState.AccessPointCreated)
if (_state is NetworkState.AccessPoint or NetworkState.AccessPointCreated)
{
return _accessPoint.SetStationAcceptPolicy(acceptPolicy);
}
@@ -810,7 +810,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
return _nifmResultCode;
}
if (_state == NetworkState.Station || _state == NetworkState.StationConnected)
if (_state is NetworkState.Station or NetworkState.StationConnected)
{
DisconnectImpl(DisconnectReason.DisconnectedByUser);
}
@@ -47,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator.LdnRyu.Proxy
{
Logger.Error?.PrintMsg(LogClass.ServiceLdn, "Tcp proxy networking is untested. Please report this game so that it can be tested.");
}
return domain == AddressFamily.InterNetwork && (protocol == ProtocolType.Tcp || protocol == ProtocolType.Udp);
return domain == AddressFamily.InterNetwork && protocol is ProtocolType.Tcp or ProtocolType.Udp;
}
private void RegisterHandlers(RyuLdnProtocol protocol)
@@ -967,7 +967,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
// TODO: Find the differencies between IUser and ISystem/IDebug.
if (_permissionLevel == NfpPermissionLevel.Debug || _permissionLevel == NfpPermissionLevel.System)
if (_permissionLevel is NfpPermissionLevel.Debug or NfpPermissionLevel.System)
{
return GetRegisterInfo(context);
}
@@ -400,7 +400,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
private NvInternalResult SetTimeslice(ref uint timeslice)
{
if (timeslice < 1000 || timeslice > 50000)
if (timeslice is < 1000 or > 50000)
{
return NvInternalResult.InvalidInput;
}
@@ -243,9 +243,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
return NvInternalResult.Success;
}
if (hostEvent.State == NvHostEventState.Available ||
hostEvent.State == NvHostEventState.Cancelled ||
hostEvent.State == NvHostEventState.Signaled)
if (hostEvent.State is NvHostEventState.Available
or NvHostEventState.Cancelled
or NvHostEventState.Signaled)
{
_events[userEventId].CloseEvent(Context);
_events[userEventId] = null;
@@ -392,9 +392,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
{
lock (hostEvent.Lock)
{
if (hostEvent.State == NvHostEventState.Available ||
hostEvent.State == NvHostEventState.Signaled ||
hostEvent.State == NvHostEventState.Cancelled)
if (hostEvent.State is NvHostEventState.Available
or NvHostEventState.Signaled
or NvHostEventState.Cancelled)
{
bool timedOut = hostEvent.Wait(_device.Gpu, fence);
@@ -456,9 +456,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
if (Event != null)
{
if (Event.State == NvHostEventState.Available ||
Event.State == NvHostEventState.Signaled ||
Event.State == NvHostEventState.Cancelled)
if (Event.State is NvHostEventState.Available
or NvHostEventState.Signaled
or NvHostEventState.Cancelled)
{
eventIndex = index;
+3 -5
View File
@@ -352,8 +352,7 @@ namespace Ryujinx.HLE.HOS.Services
_requestDataStream.Write(request.RawData);
_requestDataStream.Position = 0;
if (request.Type == IpcMessageType.CmifRequest ||
request.Type == IpcMessageType.CmifRequestWithContext)
if (request.Type is IpcMessageType.CmifRequest or IpcMessageType.CmifRequestWithContext)
{
response.Type = IpcMessageType.CmifResponse;
@@ -373,8 +372,7 @@ namespace Ryujinx.HLE.HOS.Services
response.RawData = _responseDataStream.ToArray();
}
else if (request.Type == IpcMessageType.CmifControl ||
request.Type == IpcMessageType.CmifControlWithContext)
else if (request.Type is IpcMessageType.CmifControl or IpcMessageType.CmifControlWithContext)
{
#pragma warning disable IDE0059 // Remove unnecessary value assignment
uint magic = (uint)_requestDataReader.ReadUInt64();
@@ -424,7 +422,7 @@ namespace Ryujinx.HLE.HOS.Services
throw new NotImplementedException(cmdId.ToString());
}
}
else if (request.Type == IpcMessageType.CmifCloseSession || request.Type == IpcMessageType.TipcCloseSession)
else if (request.Type is IpcMessageType.CmifCloseSession or IpcMessageType.TipcCloseSession)
{
DestroySession(serverSessionHandle);
shouldReply = false;
@@ -63,7 +63,7 @@ namespace Ryujinx.HLE.HOS.Services.Settings
RegionCode regionCode = (RegionCode)context.Device.System.State.DesiredRegionCode;
if (regionCode < RegionCode.Min || regionCode > RegionCode.Max)
if (regionCode is < RegionCode.Min or > RegionCode.Max)
{
regionCode = RegionCode.USA;
}
@@ -79,7 +79,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
return WriteBsdResult(context, -1, LinuxError.EPROTONOSUPPORT);
}
else if ((type == BsdSocketType.Seqpacket || type == BsdSocketType.Raw) && !_isPrivileged)
else if (type is BsdSocketType.Seqpacket or BsdSocketType.Raw && !_isPrivileged)
{
if (domain != BsdAddressFamily.InterNetwork || type != BsdSocketType.Raw || protocol != ProtocolType.Icmp)
{
@@ -24,10 +24,10 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Nsd.Manager
public static ResultCode Resolve(string address, out string resolvedAddress)
{
if (address == "api.sect.srv.nintendo.net" ||
address == "ctest.cdn.nintendo.net" ||
address == "ctest.cdn.n.nintendoswitch.cn" ||
address == "unknown.dummy.nintendo.net")
if (address is "api.sect.srv.nintendo.net"
or "ctest.cdn.nintendo.net"
or "ctest.cdn.n.nintendoswitch.cn"
or "unknown.dummy.nintendo.net")
{
resolvedAddress = address;
}
@@ -336,7 +336,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
public Status SetMaxAcquiredBufferCount(int maxAcquiredBufferCount)
{
if (maxAcquiredBufferCount < 0 || maxAcquiredBufferCount > BufferSlotArray.MaxAcquiredBuffers)
if (maxAcquiredBufferCount is < 0 or > BufferSlotArray.MaxAcquiredBuffers)
{
return Status.BadValue;
}
@@ -126,7 +126,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
{
BufferState state = Slots[slot].BufferState;
if (state == BufferState.Queued || state == BufferState.Dequeued)
if (state is BufferState.Queued or BufferState.Dequeued)
{
maxBufferCount = slot + 1;
}
@@ -421,8 +421,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
Format format = ConvertColorFormat(item.GraphicBuffer.Object.Buffer.Surfaces[0].ColorFormat);
byte bytesPerPixel =
format == Format.B5G6R5Unorm ||
format == Format.R4G4B4A4Unorm ? (byte)2 : (byte)4;
format is Format.B5G6R5Unorm or Format.R4G4B4A4Unorm ? (byte)2 : (byte)4;
int gobBlocksInY = 1 << item.GraphicBuffer.Object.Buffer.Surfaces[0].BlockHeightLog2;
+1 -1
View File
@@ -173,7 +173,7 @@ namespace Ryujinx.HLE.HOS
// Look for the input of the player one or the handheld.
foreach (GamepadInput input in gamepadInputs)
{
if (input.PlayerId == PlayerIndex.Player1 || input.PlayerId == PlayerIndex.Handheld)
if (input.PlayerId is PlayerIndex.Player1 or PlayerIndex.Handheld)
{
Volatile.Write(ref _pressedKeys, (long)input.Buttons);