From a8920f14182342fad1d5971bc0de906452d786b8 Mon Sep 17 00:00:00 2001 From: GP Garcia Date: Sun, 27 Oct 2019 19:16:28 -0500 Subject: [PATCH] Added Utils functions --- SteamworksPy.cpp | 146 +++++++++++++++++++++++++++++++++++++++++++++++ steamworks.py | 144 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 289 insertions(+), 1 deletion(-) diff --git a/SteamworksPy.cpp b/SteamworksPy.cpp index 8156232..53d0b00 100644 --- a/SteamworksPy.cpp +++ b/SteamworksPy.cpp @@ -414,4 +414,150 @@ SW_PY int GetGameBadgeLevel(int series, bool foil){ return 0; } return SteamUser()->GetGameBadgeLevel(series, foil); +} + +///////////////////////////////////////////////// +///// UTILS ///////////////////////////////////// +///////////////////////////////////////////////// +// +// Checks if the Overlay needs a present. Only required if using event driven render updates. +SW_PY bool OverlayNeedsPresent(){ + if(SteamUtils() == NULL){ + return false; + } + return SteamUtils()->BOverlayNeedsPresent(); +} +// Get the Steam ID of the running application/game. +SW_PY int GetAppID(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetAppID(); +} +// Get the amount of battery power, clearly for laptops. +SW_PY int GetCurrentBatteryPower(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetCurrentBatteryPower(); +} +// Returns the number of IPC calls made since the last time this function was called. +SW_PY uint32 GetIPCCallCount(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetIPCCallCount(); +} +// Get the user's country by IP. +SW_PY const char* GetIPCountry(){ + if(SteamUtils() == NULL){ + return ""; + } + return SteamUtils()->GetIPCountry(); +} +// Return amount of time, in seconds, user has spent in this session. +SW_PY int GetSecondsSinceAppActive(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetSecondsSinceAppActive(); +} +// Returns the number of seconds since the user last moved the mouse. +SW_PY int GetSecondsSinceComputerActive(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetSecondsSinceComputerActive(); +} +// Get the actual time. +SW_PY int GetServerRealTime(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->GetServerRealTime(); +} +// Get the Steam user interface language. +SW_PY const char* GetSteamUILanguage(){ + if(SteamUtils() == NULL){ + return ""; + } + return SteamUtils()->GetSteamUILanguage(); +} +// Returns true/false if Steam overlay is enabled. +SW_PY bool IsOverlayEnabled(){ + if(SteamUtils() == NULL){ + return false; + } + return SteamUtils()->IsOverlayEnabled(); +} +// Returns true if Steam & the Steam Overlay are running in Big Picture mode. +SW_PY bool IsSteamInBigPictureMode(){ + if(SteamUtils() == NULL){ + return false; + } + return SteamUtils()->IsSteamInBigPictureMode(); +} +// Is Steam running in VR? +SW_PY bool IsSteamRunningInVR(){ + if(SteamUtils() == NULL){ + return 0; + } + return SteamUtils()->IsSteamRunningInVR(); +} +// Checks if the HMD view will be streamed via Steam In-Home Streaming. +SW_PY bool IsVRHeadsetStreamingEnabled(){ + if(SteamUtils() == NULL){ + return false; + } + return SteamUtils()->IsVRHeadsetStreamingEnabled(); +} +// Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition. +SW_PY void SetOverlayNotificationInset(int horizontal, int vertical){ + if(SteamUtils() == NULL){ + return; + } + SteamUtils()->SetOverlayNotificationInset(horizontal, vertical); +} +// Set the position where overlay shows notifications. +SW_PY void SetOverlayNotificationPosition(int pos){ + if((pos < 0) || (pos > 3) || (SteamUtils() == NULL)){ + return; + } + SteamUtils()->SetOverlayNotificationPosition(ENotificationPosition(pos)); +} +// Set whether the HMD content will be streamed via Steam In-Home Streaming. +SW_PY void SetVRHeadsetStreamingEnabled(bool enabled){ + if(SteamUtils() == NULL){ + return; + } + SteamUtils()->SetVRHeadsetStreamingEnabled(enabled); +} +// Activates the Big Picture text input dialog which only supports gamepad input. +SW_PY bool ShowGamepadTextInput(int inputMode, int lineInputMode, const char* description, uint32 maxText, const char* presetText){ + if(SteamUtils() == NULL){ + return false; + } + // Convert modes + EGamepadTextInputMode mode; + if(inputMode == 0){ + mode = k_EGamepadTextInputModeNormal; + } + else{ + mode = k_EGamepadTextInputModePassword; + } + EGamepadTextInputLineMode lineMode; + if(lineInputMode == 0){ + lineMode = k_EGamepadTextInputLineModeSingleLine; + } + else{ + lineMode = k_EGamepadTextInputLineModeMultipleLines; + } + return SteamUtils()->ShowGamepadTextInput(mode, lineMode, description, maxText, presetText); +} +// Ask SteamUI to create and render its OpenVR dashboard. +SW_PY void StartVRDashboard(){ + if(SteamUtils() == NULL){ + return; + } + SteamUtils()->StartVRDashboard(); } \ No newline at end of file diff --git a/steamworks.py b/steamworks.py index 1287073..ae36532 100644 --- a/steamworks.py +++ b/steamworks.py @@ -121,6 +121,25 @@ def Init(): Steam.cdll.GetPlayerSteamLevel.restype = int Steam.cdll.GetUserDataFolder.restype = c_char_p Steam.cdll.GetGameBadgeLevel.restype = int + # Set restype for Utils functions + Steam.cdll.OverlayNeedsPresent.restype = bool + Steam.cdll.GetAppID.restype = int + Steam.cdll.GetCurrentBatteryPower.restype = int + Steam.cdll.GetIPCCallCount.restype = c_uint32 + Steam.cdll.GetIPCountry.restype = c_char_p + Steam.cdll.GetSecondsSinceAppActive.restype = int + Steam.cdll.GetSecondsSinceComputerActive.restype = int + Steam.cdll.GetServerRealTime.restype = int + Steam.cdll.GetSteamUILanguage.restype = c_char_p + Steam.cdll.IsOverlayEnabled.restype = bool + Steam.cdll.IsSteamInBigPictureMode.restype = bool + Steam.cdll.IsSteamRunningInVR.restype = bool + Steam.cdll.IsVRHeadsetStreamingEnabled.restype = bool + Steam.cdll.SetOverlayNotificationInset.restype = None + Steam.cdll.SetOverlayNotificationPosition.restype = None + Steam.cdll.SetVRHeadsetStreamingEnabled.restype = None + Steam.cdll.ShowGamepadTextInput.restype = bool + Steam.cdll.StartVRDashboard.restype = None # Is Steam loaded @staticmethod @@ -430,4 +449,127 @@ def GetGameBadgeLevel(series, foil): if Steam.IsSteamLoaded(): return Steam.cdll.GetGameBadgeLevel(series, foil) else: - return 0 \ No newline at end of file + return 0 +#------------------------------------------------ +# Class for Steam Utils +#------------------------------------------------ +class SteamUtils: + # Checks if the Overlay needs a present. Only required if using event driven render updates. + @staticmethod + def OverlayNeedsPresent(): + if Steam.IsSteamLoaded(): + return Steam.cdll.OverlayNeedsPresent() + else: + return False + # Get the Steam ID of the running application/game. + @staticmethod + def GetAppID(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetAppID() + else: + return 0 + # Get the amount of battery power, clearly for laptops. + @staticmethod + def GetCurrentBatteryPower(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetCurrentBatteryPower() + else: + return 0 + # Returns the number of IPC calls made since the last time this function was called. + @staticmethod + def GetIPCCallCount(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetIPCCallCount() + else: + return 0 + # Get the user's country by IP. + @staticmethod + def GetIPCountry(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetIPCountry() + else: + return "" + # Return amount of time, in seconds, user has spent in this session. + @staticmethod + def GetSecondsSinceAppActive(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetSecondsSinceAppActive() + else: + return 0 + # Returns the number of seconds since the user last moved the mouse. + @staticmethod + def GetSecondsSinceComputerActive(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetSecondsSinceComputerActive() + else: + return 0 + # Get the actual time. + @staticmethod + def GetServerRealTime(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetServerRealTime() + else: + return 0 + # Get the Steam user interface language. + @staticmethod + def GetSteamUILanguage(): + if Steam.IsSteamLoaded(): + return Steam.cdll.GetSteamUILanguage() + else: + return "" + # Returns true/false if Steam overlay is enabled. + @staticmethod + def IsOverlayEnabled(): + if Steam.IsSteamLoaded(): + return Steam.cdll.IsOverlayEnabled() + else: + return False + # Returns true if Steam & the Steam Overlay are running in Big Picture mode. + @staticmethod + def IsSteamInBigPictureMode(): + if Steam.IsSteamLoaded(): + return Steam.cdll.IsSteamInBigPictureMode() + else: + return False + # Is Steam running in VR? + @staticmethod + def IsVRHeadsetStreamingEnabled(): + if Steam.IsSteamLoaded(): + return Steam.cdll.IsVRHeadsetStreamingEnabled() + else: + return False + # Sets the inset of the overlay notification from the corner specified by SetOverlayNotificationPosition. + @staticmethod + def SetOverlayNotificationInset(horizontal, vertical): + if Steam.IsSteamLoaded(): + return Steam.cdll.SetOverlayNotificationInset(horizontal, vertical) + else: + return + # Set the position where overlay shows notifications. + @staticmethod + def SetOverlayNotificationPosition(pos): + if Steam.IsSteamLoaded(): + return Steam.cdll.SetOverlayNotificationPosition(pos) + else: + return + # Set whether the HMD content will be streamed via Steam In-Home Streaming. + @staticmethod + def SetVRHeadsetStreamingEnabled(enabled): + if Steam.IsSteamLoaded(): + return Steam.cdll.SetVRHeadsetStreamingEnabled(enabled) + else: + return + # Activates the Big Picture text input dialog which only supports gamepad input. + @staticmethod + def ShowGamepadTextInput(inputMode, lineInputMode, description, maxText, presetText): + if Steam.IsSteamLoaded(): + return Steam.cdll.ShowGamepadTextInput() + else: + return False + # Ask SteamUI to create and render its OpenVR dashboard. + @staticmethod + def StartVRDashboard(): + if Steam.IsSteamLoaded(): + return Steam.cdll.StartVRDashboard() + else: + return \ No newline at end of file