Class InteropHelpers
Marshalling helpers for the generated wrappers: UTF-8 strings, fixed-size char buffers, SteamParamStringArray_t, and the API-initialization guards.
Inherited Members
Namespace: Unity.Steamworks.Interop
Assembly: Unity.Steamworks.Interop.dll
Syntax
public static class InteropHelpers
Methods
ByteArrayToStringUTF8(byte[])
Reads a null-terminated UTF-8 string from a fixed-size buffer (an inline char[] struct field).
Declaration
public static string ByteArrayToStringUTF8(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | A fixed-size buffer holding a null-terminated UTF-8 string. |
Returns
| Type | Description |
|---|---|
| string | The decoded string, stopping at the first null byte. |
PtrToStringUTF8(IntPtr)
Copies a native null-terminated UTF-8 string into a managed one.
Declaration
public static string PtrToStringUTF8(IntPtr nativeUtf8)
Parameters
| Type | Name | Description |
|---|---|---|
| IntPtr | nativeUtf8 | Pointer to a null-terminated UTF-8 string owned by Steam. |
Returns
| Type | Description |
|---|---|
| string | The decoded string, or null when the pointer is IntPtr.Zero. |
PtrToStructureOrNull<T>(IntPtr)
Copies a native struct, returning null for a null pointer where PtrToStructure<T>(IntPtr) would throw. Used for flat calls that return null to indicate no result, such as GetServerDetails(HServerListRequest, int).
Declaration
public static T PtrToStructureOrNull<T>(IntPtr native) where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| IntPtr | native | Pointer to the struct, or IntPtr.Zero. |
Returns
| Type | Description |
|---|---|
| T | The marshalled struct, or null when the pointer is IntPtr.Zero. |
Type Parameters
| Name | Description |
|---|---|
| T | The struct type to read out of unmanaged memory. |
RequiredClient(IntPtr)
Returns a generated wrapper's interface pointer, throwing when it is null.
Declaration
public static IntPtr RequiredClient(IntPtr self)
Parameters
| Type | Name | Description |
|---|---|---|
| IntPtr | self | The interface pointer resolved from SteamContext. |
Returns
| Type | Description |
|---|---|
| IntPtr | The same pointer, guaranteed non-null. |
RequiredGameServer(IntPtr)
Game-server counterpart of RequiredClient(IntPtr).
Declaration
public static IntPtr RequiredGameServer(IntPtr self)
Parameters
| Type | Name | Description |
|---|---|---|
| IntPtr | self | The interface pointer resolved from SteamGameServerContext. |
Returns
| Type | Description |
|---|---|
| IntPtr | The same pointer, guaranteed non-null. |
StringToByteArrayUTF8(string, byte[], int)
Writes a string as null-terminated UTF-8 into a fixed-size buffer (an inline char[] struct field). Writes nothing if it does not fit.
Declaration
public static bool StringToByteArrayUTF8(string str, byte[] dest, int size)
Parameters
| Type | Name | Description |
|---|---|---|
| string | str | The string to encode. |
| byte[] | dest | The buffer to write the encoded bytes into. |
| int | size | The number of bytes available in |
Returns
| Type | Description |
|---|---|
| bool | true when the encoded string and its terminator fit. |
TestIfAvailableClient()
Throws if the client-side Steamworks API has not been initialized.
Declaration
public static void TestIfAvailableClient()
TestIfAvailableGameServer()
Throws if the game-server Steamworks API has not been initialized.
Declaration
public static void TestIfAvailableGameServer()