Skip to content

Commit 3d15b13

Browse files
Update version to 0.1.8-beta; add RawMessageReceived event and RawSimConnectMessageEventArgs for low-level message handling
1 parent 19dc836 commit 3d15b13

4 files changed

Lines changed: 76 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.1.8-beta] - 2025-08-10
11+
12+
### Added
13+
14+
- Public `SimConnectClient.Handle` property (was internal) to allow advanced consumers to perform custom native interop scenarios not yet wrapped by the library.
15+
- `SimConnectClient.RawMessageReceived` event exposing a low-level hook with raw pointer, size, and message id for diagnostics, custom decoding, or experimentation with unwrapped message types.
16+
17+
### Notes
18+
19+
- Raw message memory is only valid for the duration of the event callback; copy data immediately if you need to retain it.
20+
- This is an additive, non-breaking update.
21+
1022
## [0.1.7-beta] - 2025-08-10
1123

1224
### Added

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>0.1.7-beta</Version>
3+
<Version>0.1.8-beta</Version>
44
<Authors>BARS</Authors>
55
<Company>BARS</Company>
66
<Product>SimConnect.NET</Product>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// <copyright file="RawSimConnectMessageEventArgs.cs" company="BARS">
2+
// Copyright (c) BARS. All rights reserved.
3+
// </copyright>
4+
5+
using System;
6+
7+
namespace SimConnect.NET.Events
8+
{
9+
/// <summary>
10+
/// Provides data for the <see cref="SimConnectClient.RawMessageReceived"/> event, exposing the raw
11+
/// SimConnect dispatch pointer and size for advanced consumers that need low-level access.
12+
/// The data memory referenced by <see cref="DataPointer"/> is only valid for the duration of the event callback.
13+
/// </summary>
14+
public sealed class RawSimConnectMessageEventArgs : EventArgs
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="RawSimConnectMessageEventArgs"/> class.
18+
/// </summary>
19+
/// <param name="dataPointer">Pointer to the raw SimConnect message memory.</param>
20+
/// <param name="dataSize">Size (in bytes) of the message pointed to by <paramref name="dataPointer"/>.</param>
21+
/// <param name="messageId">The SimConnect receive message identifier.</param>
22+
public RawSimConnectMessageEventArgs(IntPtr dataPointer, uint dataSize, SimConnectRecvId messageId)
23+
{
24+
this.DataPointer = dataPointer;
25+
this.DataSize = dataSize;
26+
this.MessageId = messageId;
27+
}
28+
29+
/// <summary>
30+
/// Gets the pointer to the raw SimConnect message memory. Valid only within the event scope.
31+
/// </summary>
32+
public IntPtr DataPointer { get; }
33+
34+
/// <summary>
35+
/// Gets the size (in bytes) of the raw message.
36+
/// </summary>
37+
public uint DataSize { get; }
38+
39+
/// <summary>
40+
/// Gets the SimConnect receive message identifier for this message.
41+
/// </summary>
42+
public SimConnectRecvId MessageId { get; }
43+
}
44+
}

src/SimConnect.NET/SimConnectClient.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public SimConnectClient(string applicationName = "SimConnect.NET Client")
6161
/// </summary>
6262
public event EventHandler<SimConnectErrorEventArgs>? ErrorOccurred;
6363

64+
/// <summary>
65+
/// Occurs when any raw SimConnect message is received before it is dispatched to managers.
66+
/// Allows advanced consumers to inspect or override low-level processing.
67+
/// The underlying memory pointed to by <see cref="RawSimConnectMessageEventArgs.DataPointer"/> is only valid for the duration of the event callback.
68+
/// </summary>
69+
public event EventHandler<RawSimConnectMessageEventArgs>? RawMessageReceived;
70+
6471
/// <summary>
6572
/// Gets a value indicating whether the client is connected to SimConnect.
6673
/// </summary>
@@ -170,7 +177,7 @@ public InputGroupManager InputGroups
170177
/// Gets the SimConnect handle for advanced operations.
171178
/// </summary>
172179
/// <exception cref="InvalidOperationException">Thrown when not connected to SimConnect.</exception>
173-
internal IntPtr Handle
180+
public IntPtr Handle
174181
{
175182
get
176183
{
@@ -344,10 +351,20 @@ public async Task<bool> ProcessNextMessageAsync(CancellationToken cancellationTo
344351
if (ppData != IntPtr.Zero && pcbData > 0)
345352
{
346353
var recv = Marshal.PtrToStructure<SimConnectRecv>(ppData);
354+
var recvId = (SimConnectRecvId)recv.Id;
347355

348356
SimConnectLogger.Debug($"Received SimConnect message: Id={recv.Id}, Size={recv.Size}");
349357

350-
switch ((SimConnectRecvId)recv.Id)
358+
try
359+
{
360+
this.RawMessageReceived?.Invoke(this, new RawSimConnectMessageEventArgs(ppData, pcbData, recvId));
361+
}
362+
catch (Exception hookEx)
363+
{
364+
SimConnectLogger.Warning($"RawMessageReceived hook threw: {hookEx.Message}");
365+
}
366+
367+
switch (recvId)
351368
{
352369
case SimConnectRecvId.AssignedObjectId:
353370
this.ProcessAssignedObjectId(ppData);

0 commit comments

Comments
 (0)