Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/SimConnect.NET/Enums/SimConnectInputEventType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ namespace SimConnect.NET
/// </summary>
public enum SimConnectInputEventType
{
/// <summary>
/// No data type specification required (C++ only).
/// </summary>
None,

/// <summary>
/// Specifies a double value.
/// </summary>
Expand Down
29 changes: 21 additions & 8 deletions src/SimConnect.NET/InputEvents/InputEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using SimConnect.NET.Events;
Expand Down Expand Up @@ -179,7 +180,9 @@ await Task.Run(

using (cancellationToken.Register(() => tcs.TrySetCanceled()))
{
return await tcs.Task.ConfigureAwait(false);
var value = await tcs.Task.ConfigureAwait(false);
value.Hash = hash; // Set the hash for reference
return value;
}
}
finally
Expand Down Expand Up @@ -591,14 +594,13 @@ private void ProcessEnumerateInputEvents(IntPtr ppData)
var typeValue = Marshal.ReadInt32(currentPtr);
var inputEventType = Enum.IsDefined(typeof(SimConnectInputEventType), typeValue)
? (SimConnectInputEventType)typeValue
: SimConnectInputEventType.None; // Default to None if invalid
: SimConnectInputEventType.DoubleValue; // Default to None if invalid

// Convert to SimConnectDataType for the descriptor
var type = inputEventType switch
{
SimConnectInputEventType.DoubleValue => SimConnectDataType.FloatDouble,
SimConnectInputEventType.StringValue => SimConnectDataType.String128,
SimConnectInputEventType.None => SimConnectDataType.FloatDouble, // Default to double for unspecified type
_ => SimConnectDataType.FloatDouble, // Default fallback
};

Expand Down Expand Up @@ -671,26 +673,37 @@ private void ProcessGetInputEvent(IntPtr ppData)
{
try
{
var recvGet = Marshal.PtrToStructure<SimConnectRecvGetInputEvent>(ppData);
var recvGet = Marshal.PtrToStructure<SimConnectRecvGetInputEventHeader>(ppData);
int headerSize = Marshal.SizeOf<SimConnectRecvGetInputEventHeader>();
int totalSize = checked((int)recvGet.Size);
int payloadSize = totalSize - headerSize;
System.Diagnostics.Debug.WriteLine($"[InputEventManager] Payload size: {payloadSize}");
IntPtr pValue = IntPtr.Add(ppData, headerSize);

// Extract value based on the type
object value;
switch (recvGet.Type)
{
case SimConnectInputEventType.DoubleValue:
value = Marshal.PtrToStructure<double>(recvGet.Value);
value = Marshal.PtrToStructure<double>(pValue);
break;
case SimConnectInputEventType.StringValue:
value = Marshal.PtrToStringAnsi(recvGet.Value) ?? string.Empty;
byte[] buf = new byte[payloadSize];
Marshal.Copy(pValue, buf, 0, buf.Length);
int nul = Array.IndexOf(buf, (byte)0);
int len = nul >= 0 ? nul : buf.Length;
value = Encoding.ASCII.GetString(buf, 0, len);
break;
default:
value = recvGet.Value.ToInt64();
byte[] defBuf = new byte[payloadSize];
Marshal.Copy(pValue, defBuf, 0, defBuf.Length);
value = defBuf;
value = BitConverter.ToDouble(defBuf, 0);
break;
}

var inputEventValue = new InputEventValue
{
Hash = recvGet.RequestId,
Type = recvGet.Type,
Value = value,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// <copyright file="SimConnectRecvGetInputEvent.cs" company="BARS">
// <copyright file="SimConnectRecvGetInputEventHeader.cs" company="BARS">
// Copyright (c) BARS. All rights reserved.
// </copyright>

namespace SimConnect.NET
{
/// <summary>
/// The SimConnectRecvGetInputEvent structure is used to return the value of a specific input event.
/// The SimConnectRecvGetInputEventHeader structure is used to return the header of a specific input event including the type but without the value.
/// </summary>
public struct SimConnectRecvGetInputEvent
public struct SimConnectRecvGetInputEventHeader
{
/// <summary>
/// Gets or sets the total size of the returned structure in bytes.
Expand All @@ -33,10 +33,5 @@ public struct SimConnectRecvGetInputEvent
/// Gets or sets the type of the input event. This is used to cast the Value to the correct type.
/// </summary>
public SimConnectInputEventType Type { get; set; }

/// <summary>
/// Gets or sets the value of the requested input event, which should be cast to the correct format (float / string).
/// </summary>
public IntPtr Value { get; set; }
}
}