aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2019-11-23 03:15:15 +0100
committerjduncanator <1518948+jduncanator@users.noreply.github.com>2019-11-23 13:15:15 +1100
commitbb74aeae54e4579008ac23216b8b175d64c9f10f (patch)
tree0f773f5f84c05c663f4a81eb7fd26a2f54384845
parentcfcc360d0610c66e9b9986f7aab96f79df0da79e (diff)
Use BinaryPrimitives.ReverseEndianness instead EndianSwap class (#832)
This PR remove the `EndianSwap` class who isn't needed anymore since .NET Core 3.0 got a buildin method `BinaryPrimitives.ReverseEndianness` who did the same thing.
-rw-r--r--Ryujinx.Common/Utilities/EndianSwap.cs31
-rw-r--r--Ryujinx.HLE/HOS/Font/SharedFontManager.cs3
-rw-r--r--Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs5
-rw-r--r--Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs5
4 files changed, 8 insertions, 36 deletions
diff --git a/Ryujinx.Common/Utilities/EndianSwap.cs b/Ryujinx.Common/Utilities/EndianSwap.cs
deleted file mode 100644
index 049570e3..00000000
--- a/Ryujinx.Common/Utilities/EndianSwap.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System;
-
-namespace Ryujinx.Common
-{
- public static class EndianSwap
- {
- public static ushort Swap16(ushort value) => (ushort)(((value >> 8) & 0xff) | (value << 8));
-
- public static int Swap32(int value)
- {
- uint uintVal = (uint)value;
-
- return (int)(((uintVal >> 24) & 0x000000ff) |
- ((uintVal >> 8) & 0x0000ff00) |
- ((uintVal << 8) & 0x00ff0000) |
- ((uintVal << 24) & 0xff000000));
- }
-
- public static uint FromBigEndianToPlatformEndian(uint value)
- {
- uint result = value;
-
- if (BitConverter.IsLittleEndian)
- {
- result = (uint)EndianSwap.Swap32((int)result);
- }
-
- return result;
- }
- }
-}
diff --git a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs
index 40a81b86..99b662c0 100644
--- a/Ryujinx.HLE/HOS/Font/SharedFontManager.cs
+++ b/Ryujinx.HLE/HOS/Font/SharedFontManager.cs
@@ -5,6 +5,7 @@ using Ryujinx.Common;
using Ryujinx.HLE.Exceptions;
using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.FileSystem.Content;
+using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
@@ -142,7 +143,7 @@ namespace Ryujinx.HLE.HOS.Font
const int decMagic = 0x18029a7f;
const int key = 0x49621806;
- int encryptedSize = EndianSwap.Swap32(size ^ key);
+ int encryptedSize = BinaryPrimitives.ReverseEndianness(size ^ key);
_device.Memory.WriteInt32(position + 0, decMagic);
_device.Memory.WriteInt32(position + 4, encryptedSize);
diff --git a/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs b/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs
index bb4b6d16..0a50a5c8 100644
--- a/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs
+++ b/Ryujinx.HLE/HOS/Services/Audio/Types/OpusPacketHeader.cs
@@ -1,5 +1,6 @@
using Ryujinx.Common;
using System;
+using System.Buffers.Binary;
using System.IO;
using System.Runtime.InteropServices;
@@ -15,8 +16,8 @@ namespace Ryujinx.HLE.HOS.Services.Audio.Types
{
OpusPacketHeader header = reader.ReadStruct<OpusPacketHeader>();
- header.length = EndianSwap.FromBigEndianToPlatformEndian(header.length);
- header.finalRange = EndianSwap.FromBigEndianToPlatformEndian(header.finalRange);
+ header.length = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.length) : header.length;
+ header.finalRange = BitConverter.IsLittleEndian ? BinaryPrimitives.ReverseEndianness(header.finalRange) : header.finalRange;
return header;
}
diff --git a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs
index 7db8066a..af9b3881 100644
--- a/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs
+++ b/Ryujinx.HLE/HOS/Services/Sockets/Bsd/IClient.cs
@@ -1,6 +1,7 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.Utilities;
+using System.Buffers.Binary;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
@@ -199,7 +200,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
int size = context.Memory.ReadByte(bufferPosition);
int family = context.Memory.ReadByte(bufferPosition + 1);
- int port = EndianSwap.Swap16(context.Memory.ReadUInt16(bufferPosition + 2));
+ int port = BinaryPrimitives.ReverseEndianness(context.Memory.ReadUInt16(bufferPosition + 2));
byte[] rawIp = context.Memory.ReadBytes(bufferPosition + 4, 4);
@@ -210,7 +211,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd
{
context.Memory.WriteByte(bufferPosition, 0);
context.Memory.WriteByte(bufferPosition + 1, (byte)endPoint.AddressFamily);
- context.Memory.WriteUInt16(bufferPosition + 2, EndianSwap.Swap16((ushort)endPoint.Port));
+ context.Memory.WriteUInt16(bufferPosition + 2, BinaryPrimitives.ReverseEndianness((ushort)endPoint.Port));
context.Memory.WriteBytes(bufferPosition + 4, endPoint.Address.GetAddressBytes());
}