diff --git a/steamworks.go b/steamworks.go index 1730e16..117c5ef 100644 --- a/steamworks.go +++ b/steamworks.go @@ -82,7 +82,7 @@ type ISteamUtils interface { type ISteamFriends interface { GetPersonaName() string - SetRichPresence(string, string) + SetRichPresence(string, string) bool } const ( diff --git a/steamworks_unix.go b/steamworks_unix.go index 8e37c77..1e6b44c 100644 --- a/steamworks_unix.go +++ b/steamworks_unix.go @@ -303,6 +303,20 @@ func (s steamFriends) GetPersonaName() string { return C.GoString(C.uintptrToChar(C.uintptr_t(v))) } +func (s steamFriends) SetRichPresence(key, value string) bool { + ckey := append([]byte(key), 0) + defer runtime.KeepAlive(ckey) + cvalue := append([]byte(value), 0) + defer runtime.KeepAlive(cvalue) + + v, err := theLib.call(funcType_Bool_Ptr_Ptr_Ptr, flatAPI_ISteamFriends_SetRichPresence, uintptr(s), uintptr(unsafe.Pointer(ckey), uintptr(unsafe.Pointer(cvalue))) + if err != nil { + panic(err) + } + + return byte(v) != 0 +} + func SteamInput() ISteamInput { v, err := theLib.call(funcType_Ptr, flatAPI_SteamInput) if err != nil { diff --git a/steamworks_windows.go b/steamworks_windows.go index 836b0d4..2d9994e 100644 --- a/steamworks_windows.go +++ b/steamworks_windows.go @@ -3,9 +3,6 @@ package steamworks -// #include -import "C" - import ( "runtime" "unsafe" @@ -145,18 +142,17 @@ 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)) - }() +func (s steamFriends) SetRichPresence(key, value string) bool { + ckey := append([]byte(key), 0) + defer runtime.KeepAlive(ckey) + cvalue := append([]byte(value), 0) + defer runtime.KeepAlive(cvalue) - _, err := theDLL.call(flatAPI_ISteamFriends_SetRichPresence, uintptr(s), uintptr(unsafe.Pointer(keyString)), uintptr(unsafe.Pointer(valueString))) + v, err := theDLL.call(flatAPI_ISteamFriends_SetRichPresence, uintptr(s), uintptr(unsafe.Pointer(&ckey[0])), uintptr(unsafe.Pointer(&cvalue[0]))) if err != nil { panic(err) } + return byte(v) != 0 } func SteamInput() ISteamInput {