Skip to content

Instantly share code, notes, and snippets.

@OndrejPetrzilka
Created July 9, 2019 15:58
Show Gist options
  • Save OndrejPetrzilka/eb83db3d466b0c5af2e9a6434dec51de to your computer and use it in GitHub Desktop.
Save OndrejPetrzilka/eb83db3d466b0c5af2e9a6434dec51de to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Steamworks
{
static class InterfaceHelper
{
[DllImport(NativeMethods.NativeLibraryName, EntryPoint = "SteamInternal_FindOrCreateUserInterface", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr SteamInternal_FindOrCreateUserInterface(HSteamUser hSteamUser, InteropHelp.UTF8StringHandle pszVersion);
[DllImport(NativeMethods.NativeLibraryName, EntryPoint = "SteamInternal_FindOrCreateGameServerInterface", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr SteamInternal_FindOrCreateGameServerInterface(HSteamUser hSteamUser, InteropHelp.UTF8StringHandle pszVersion);
public static IntPtr FindOrCreateUserInterface(HSteamUser hSteamUser, string interfaceVersion)
{
using (var pszVersion = new InteropHelp.UTF8StringHandle(interfaceVersion))
{
return SteamInternal_FindOrCreateUserInterface(hSteamUser, pszVersion);
}
}
public static IntPtr FindOrCreateGameServerInterface(HSteamUser hSteamUser, string interfaceVersion)
{
using (var pszVersion = new InteropHelp.UTF8StringHandle(interfaceVersion))
{
return SteamInternal_FindOrCreateGameServerInterface(hSteamUser, pszVersion);
}
}
public static IntPtr FindOrCreateUserInterface(ref IntPtr ptr, string interfaceVersion)
{
if (ptr == IntPtr.Zero)
{
ptr = FindOrCreateUserInterface((HSteamUser)NativeMethods.SteamAPI_GetHSteamUser(), interfaceVersion);
}
return ptr;
}
public static IntPtr FindOrCreateGameServerInterface(ref IntPtr ptr, string interfaceVersion)
{
if (ptr == IntPtr.Zero)
{
ptr = FindOrCreateGameServerInterface((HSteamUser)NativeMethods.SteamGameServer_GetHSteamUser(), interfaceVersion);
}
return ptr;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment