This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
forked from patmagauran/ForzaDualSense
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PacketParse.cs
66 lines (55 loc) · 1.77 KB
/
PacketParse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
namespace ForzaDSX
{
public static class PacketParse
{
private const int SLED_PACKET_LENGTH = 232; // FM7
private const int DASH_PACKET_LENGTH = 311; // FM7
private const int FH7_PACKET_LENGTH = 324; // FH4
public static bool IsSledFormat(byte[] packet)
{
return packet.Length == SLED_PACKET_LENGTH;
}
public static bool IsDashFormat(byte[] packet)
{
return packet.Length == DASH_PACKET_LENGTH;
}
public static bool IsFH7Format(byte[] packet)
{
return packet.Length == FH7_PACKET_LENGTH;
}
internal static float GetSingle(byte[] bytes, int index)
{
ByteCheck(bytes, index, 4);
return BitConverter.ToSingle(bytes, index);
}
internal static uint GetUInt16(byte[] bytes, int index)
{
ByteCheck(bytes, index, 2);
return BitConverter.ToUInt16(bytes, index);
}
internal static uint GetUInt32(byte[] bytes, int index)
{
ByteCheck(bytes, index, 4);
return BitConverter.ToUInt32(bytes, index);
}
internal static uint GetUInt8(byte[] bytes, int index)
{
ByteCheck(bytes, index, 1);
return bytes[index];
}
internal static int GetInt8(byte[] bytes, int index)
{
ByteCheck(bytes, index, 1);
return Convert.ToInt16((sbyte)bytes[index]);
}
private static void ByteCheck(byte[] bytes, int index, int byteCount)
{
if (index + byteCount <= bytes.Length)
{
return;
}
throw new ArgumentException("Not enough bytes in this array");
}
}
}