GameNetworkingSocketsDotNet.LowLevel 1.0.0

dotnet add package GameNetworkingSocketsDotNet.LowLevel --version 1.0.0
                    
NuGet\Install-Package GameNetworkingSocketsDotNet.LowLevel -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GameNetworkingSocketsDotNet.LowLevel" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GameNetworkingSocketsDotNet.LowLevel" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GameNetworkingSocketsDotNet.LowLevel" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GameNetworkingSocketsDotNet.LowLevel --version 1.0.0
                    
#r "nuget: GameNetworkingSocketsDotNet.LowLevel, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package GameNetworkingSocketsDotNet.LowLevel@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GameNetworkingSocketsDotNet.LowLevel&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GameNetworkingSocketsDotNet.LowLevel&version=1.0.0
                    
Install as a Cake Tool

GameNetworkingSocketsDotNet.LowLevel

Low level .NET 7 bindings for Valve networking library found at: https://github.com/ValveSoftware/GameNetworkingSockets.

Available as a Nuget package at: https://www.nuget.org/packages/GameNetworkingSocketsDotNet.LowLevel/

The only class in this library: ValveNativeLibrary contains bindings to Constants, Enums, Functions but also to Structs mapped 1-to-1 to the native ones. So they can be passed along and accessed via pointers without any marshalling. (for simple value types at least)

This wrapper only dependencies are the .NET framework and the valve C++ library. It provides a very raw access to the native library.

For a higher-level solution, you can use my other project found at: https://github.com/Azengar/GameNetworkingSocketsDotNet/tree/main/GameNetworkingSocketsDotNet/GameNetworkingSocketsDotNet.HighLevel.

Building the native library

The native library binaries can be obtained either through an official release find on the official GitHub repo or by building it yourself. I recommend building it yourself in case you need one of the improvements listed just below.

Improvements to the native library

On top of these bindings, I also offer some small and targeted changes to the native library, for performances and/or special uses cases. Read more about this in the main README of the project, found at: https://github.com/Azengar/GameNetworkingSocketsDotNet.

All these improvements were made as separate commits in the dotnet-improvement branch of my own fork of the native library, I try to keep it up-to-date with master: https://github.com/Azengar/GameNetworkingSockets/tree/dotnet-extension.

I list these improvements right below.

Using different interfaces

When using the valve library it might be desirable to use different interfaces.

This might happen if you have separate clients or servers running in a single application that have nothing in common and you want to process them separately.

Doing so is possible from native code but no C binding-friendly function has been made to fit that use-case.

In the .NET ValveNativeLibrary class you might notice the function:


public static partial ISteamNetworkingSockets* GameNetworkingSockets_Create(SteamNetworkingIdentity* pIdentity, sbyte* errMesg);

This function allows you to do what is mentioned above but in order for it to work, the counterpart should be added to the native C++ library.

This requires a small addition to Valve's sources.

In steamnetworkingsockets.h:


STEAMNETWORKINGSOCKETS_INTERFACE ISteamNetworkingSockets *GameNetworkingSockets_Create( const SteamNetworkingIdentity *pIdentity, SteamNetworkingErrMsg &errMsg);

In steamnetworkingsockets.cpp:


STEAMNETWORKINGSOCKETS_INTERFACE ISteamNetworkingSockets *GameNetworkingSockets_Create( const SteamNetworkingIdentity *pIdentity, SteamNetworkingErrMsg &errMsg)
{
	CSteamNetworkingSockets *pSteamNetworkingSockets = new CSteamNetworkingSockets( ( CSteamNetworkingUtils *)SteamNetworkingUtils() );
	if ( !pSteamNetworkingSockets->BInitGameNetworkingSockets( pIdentity, errMsg ) )
	{
		pSteamNetworkingSockets->Destroy();
		return nullptr;
	}

	return pSteamNetworkingSockets;
}

Custom memory management

If you need fine-grained control over how the message buffers are allocated / de-allocated in the native library (for example in order to recycle buffers with pools) then you can do so with:


public static partial void SteamAPI_ISteamNetworkingUtils_SetCustomMessageDataMemoryManagement(ISteamNetworkingUtils* self, void* fnAllocator, void* fnDeallocator);

The native library gives you the option to do that with ougoing messages but not for incoming messages, so this change bridges this gap.

All messages created with the cbAllocateBuffer parameter will then be allocated with the functions passed in the above call:


public static partial SteamNetworkingMessage_t* SteamAPI_ISteamNetworkingUtils_AllocateMessage(ISteamNetworkingUtils* self, int cbAllocateBuffer);

For this function to work, you will need to implement the changes in the commit Allows custom memory allocation functions for message data.

However, from what I noticed with benchmarks, it is actually faster let the system allocate and deallocate memory rather than using pools, unless you work in a single-threaded environment.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 339 10/20/2023

Version 1.0.0

* Initial release.