Skip to content

Commit

Permalink
Add SetRichPresence API on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
corfe83 committed Oct 28, 2023
1 parent 85388dd commit dd10fa6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions steamworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type ISteamUtils interface {

type ISteamFriends interface {
GetPersonaName() string
SetRichPresence(string, string)
}

const (
Expand All @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions steamworks_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

package steamworks

// #include <stdlib.h>
import "C"

import (
"runtime"
"unsafe"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dd10fa6

Please sign in to comment.