From dd10fa64a8b09abfa1309c062a2d0a7cd2c9a74b Mon Sep 17 00:00:00 2001 From: Michael Carlson Date: Sat, 28 Oct 2023 11:33:42 -0700 Subject: [PATCH] Add SetRichPresence API on windows --- steamworks.go | 6 ++++-- steamworks_windows.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/steamworks.go b/steamworks.go index e1ff861..1730e16 100644 --- a/steamworks.go +++ b/steamworks.go @@ -82,6 +82,7 @@ type ISteamUtils interface { type ISteamFriends interface { GetPersonaName() string + SetRichPresence(string, string) } const ( @@ -94,8 +95,9 @@ const ( flatAPI_ISteamApps_GetAppInstallDir = "SteamAPI_ISteamApps_GetAppInstallDir" flatAPI_ISteamApps_GetCurrentGameLanguage = "SteamAPI_ISteamApps_GetCurrentGameLanguage" - flagAPI_SteamFriends = "SteamAPI_SteamFriends_v017" - flatAPI_ISteamFriends_GetPersonaName = "SteamAPI_ISteamFriends_GetPersonaName" + flagAPI_SteamFriends = "SteamAPI_SteamFriends_v017" + flatAPI_ISteamFriends_GetPersonaName = "SteamAPI_ISteamFriends_GetPersonaName" + flatAPI_ISteamFriends_SetRichPresence = "SteamAPI_ISteamFriends_SetRichPresence" flatAPI_SteamInput = "SteamAPI_SteamInput_v006" flatAPI_ISteamInput_GetConnectedControllers = "SteamAPI_ISteamInput_GetConnectedControllers" diff --git a/steamworks_windows.go b/steamworks_windows.go index cd6c522..836b0d4 100644 --- a/steamworks_windows.go +++ b/steamworks_windows.go @@ -3,6 +3,9 @@ package steamworks +// #include +import "C" + import ( "runtime" "unsafe" @@ -142,6 +145,20 @@ func (s steamFriends) GetPersonaName() string { return cStringToGoString(v, 64) } +func (s steamFriends) SetRichPresence(key, value string) { + keyString := C.CString(key) + valueString := C.CString(value) + defer func() { + C.free(unsafe.Pointer(keyString)) + C.free(unsafe.Pointer(valueString)) + }() + + _, err := theDLL.call(flatAPI_ISteamFriends_SetRichPresence, uintptr(s), uintptr(unsafe.Pointer(keyString)), uintptr(unsafe.Pointer(valueString))) + if err != nil { + panic(err) + } +} + func SteamInput() ISteamInput { v, err := theDLL.call(flatAPI_SteamInput) if err != nil {