Skip to content

Commit

Permalink
Added music, screenshots, and users functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Gramps committed Oct 21, 2019
1 parent 0ed7282 commit ab2bcde
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 1 deletion.
149 changes: 149 additions & 0 deletions SteamworksPy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,153 @@ SW_PY void GetFileDetails(const char* filename){
return;
}
SteamApps()->GetFileDetails(filename);
}

/////////////////////////////////////////////////
///// MUSIC /////////////////////////////////////
/////////////////////////////////////////////////
//
// Is Steam music enabled.
SW_PY bool MusicIsEnabled(){
if(SteamMusic() == NULL){
return false;
}
return SteamMusic()->BIsEnabled();
}
// Is Steam music playing something.
SW_PY bool MusicIsPlaying(){
if(SteamMusic() == NULL){
return false;
}
return SteamMusic()->BIsPlaying();
}
// Get the volume level of the music.
SW_PY float MusicGetVolume(){
if(SteamMusic() == NULL){
return 0;
}
return SteamMusic()->GetVolume();
}
// Pause whatever Steam music is playing.
SW_PY void MusicPause(){
if(SteamMusic() == NULL){
return;
}
return SteamMusic()->Pause();
}
// Play current track/album.
SW_PY void MusicPlay(){
if(SteamMusic() == NULL){
return;
}
return SteamMusic()->Play();
}
// Play next track/album.
SW_PY void MusicPlayNext(){
if(SteamMusic() == NULL){
return;
}
return SteamMusic()->PlayNext();
}
// Play previous track/album.
SW_PY void MusicPlayPrev(){
if(SteamMusic() == NULL){
return;
}
return SteamMusic()->PlayPrevious();
}
// Set the volume of Steam music.
SW_PY void MusicSetVolume(float value){
if(SteamMusic() == NULL){
return;
}
return SteamMusic()->SetVolume(value);
}

/////////////////////////////////////////////////
///// SCREENSHOTS ///////////////////////////////
/////////////////////////////////////////////////
//
// Adds a screenshot to the user's Steam screenshot library from disk.
SW_PY uint32_t AddScreenshotToLibrary(const char* filename, const char* thumbnailFilename, int width, int height){
if(SteamScreenshots() == NULL){
return 0;
}
return SteamScreenshots()->AddScreenshotToLibrary(filename, thumbnailFilename, width, height);
}
// Toggles whether the overlay handles screenshots.
SW_PY void HookScreenshots(bool hook){
if(SteamScreenshots() == NULL){
return;
}
SteamScreenshots()->HookScreenshots(hook);
}
// Checks if the app is hooking screenshots.
SW_PY bool IsScreenshotsHooked(){
if(SteamScreenshots() == NULL){
return false;
}
return SteamScreenshots()->IsScreenshotsHooked();
}
// Sets optional metadata about a screenshot's location.
SW_PY bool SetLocation(uint32_t screenshot, const char* location){
if(SteamScreenshots() == NULL){
return false;
}
ScreenshotHandle handle = (ScreenshotHandle)screenshot;
return SteamScreenshots()->SetLocation(handle, location);
}
// Causes Steam overlay to take a screenshot.
SW_PY void TriggerScreenshot(){
if(SteamScreenshots() == NULL){
return;
}
SteamScreenshots()->TriggerScreenshot();
}

/////////////////////////////////////////////////
///// USERS /////////////////////////////////////
/////////////////////////////////////////////////
//
// Get user's Steam ID.
SW_PY uint64_t GetSteamID(){
if(SteamUser() == NULL){
return 0;
}
CSteamID steamID = SteamUser()->GetSteamID();
return steamID.ConvertToUint64();
}
// Check, true/false, if user is logged into Steam currently.
SW_PY bool LoggedOn(){
if(SteamUser() == NULL){
return false;
}
return SteamUser()->BLoggedOn();
}
// Get the user's Steam level.
SW_PY int GetPlayerSteamLevel(){
if(SteamUser() == NULL){
return 0;
}
return SteamUser()->GetPlayerSteamLevel();
}
// Get the user's Steam installation path (this function is depreciated).
SW_PY const char* GetUserDataFolder(){
if(SteamUser() == NULL){
return "";
}
const int bufferSize = 256;
char *buffer = new char[bufferSize];
SteamUser()->GetUserDataFolder((char*)buffer, bufferSize);
char *data_path = buffer;
delete buffer;
return data_path;
}
// Trading Card badges data access, if you only have one set of cards, the series will be 1.
// The user has can have two different badges for a series; the regular (max level 5) and the foil (max level 1).
SW_PY int GetGameBadgeLevel(int series, bool foil){
if(SteamUser()== NULL){
return 0;
}
return SteamUser()->GetGameBadgeLevel(series, foil);
}
162 changes: 161 additions & 1 deletion steamworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def Init():
if OS_BIT == '32bits':
Steam.cdll = CDLL(os.path.join(os.getcwd(), "SteamworksPy.dll"))
else:
Steam.cdll = CDLL(os.path.join(os.getcwd(), "SteamworksPy.dll"))
Steam.cdll = CDLL(os.path.join(os.getcwd(), "SteamworksPy64.dll"))
print("INFO: SteamworksPy loaded for Windows")
Steam.loaded = True
# Unrecognized platform, warn user, do not load Steam API
Expand Down Expand Up @@ -100,6 +100,27 @@ def Init():
Steam.cdll.GetLaunchQueryParam.restype = c_char_p
Steam.cdll.GetAppBuildId.restype = int
Steam.cdll.GetFileDetails.restype = None
# Set restype for Music functions
Steam.cdll.MusicIsEnabled.restype = None
Steam.cdll.MusicIsPlaying.restype = None
Steam.cdll.MusicGetVolume.restype = c_float
Steam.cdll.MusicPause.restype = None
Steam.cdll.MusicPlay.restype = None
Steam.cdll.MusicPlayNext.restype = None
Steam.cdll.MusicPlayPrev.restype = None
Steam.cdll.MusicSetVolume.restype = None
# Set restype for Screenshot functions
Steam.cdll.AddScreenshotToLibrary.restype = c_uint32
Steam.cdll.HookScreenshots.restype = None
Steam.cdll.IsScreenshotsHooked.restype = bool
Steam.cdll.SetLocation.restype = bool
Steam.cdll.TriggerScreenshot.restype = None
# Set restype for User functions
Steam.cdll.GetSteamID.restype = c_uint64
Steam.cdll.LoggedOn.restype = bool
Steam.cdll.GetPlayerSteamLevel.restype = int
Steam.cdll.GetUserDataFolder.restype = c_char_p
Steam.cdll.GetGameBadgeLevel.restype = int

# Is Steam loaded
@staticmethod
Expand Down Expand Up @@ -271,3 +292,142 @@ def GetFileDetails(filename):
return Steam.cdll.GetFileDetails(filename)
else:
return
#------------------------------------------------
# Class for Steam Music
#------------------------------------------------
class SteamMusic:
# Is Steam music enabled.
@staticmethod
def MusicIsEnabled():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicIsEnabled()
else:
return False
# Is Steam music playing something.
@staticmethod
def MusicIsPlaying():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicIsPlaying()
else:
return False
# Get the volume level of the music.
@staticmethod
def MusicGetVolume():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicGetVolume()
else:
return 0
# Pause whatever Steam music is playing.
@staticmethod
def MusicPause():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicPause()
else:
return
# Play current track/album.
@staticmethod
def MusicPlay():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicPlay()
else:
return
# Play next track/album.
@staticmethod
def MusicPlayNext():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicPlayNext()
else:
return
# Play previous track/album.
@staticmethod
def MusicPlayPrev():
if Steam.IsSteamLoaded():
return Steam.cdll.MusicPlayPrev()
else:
return
# Set the volume of Steam music.
@staticmethod
def MusicSetVolume(volume):
if Steam.IsSteamLoaded():
return Steam.cdll.MusicSetVolume(volume)
else:
return
#------------------------------------------------
# Class for Steam Screenshots
#------------------------------------------------
class SteamScreenshots:
# Adds a screenshot to the user's Steam screenshot library from disk.
@staticmethod
def AddScreenshotToLibrary(filename, thumbnailFilename, width, height):
if Steam.IsSteamLoaded():
return Steam.cdll.AddScreenshotToLibrary(filename, thumbnailFilename, width, height)
else:
return 0
# Toggles whether the overlay handles screenshots.
@staticmethod
def HookScreenshots(hook):
if Steam.IsSteamLoaded():
return Steam.cdll.HookScreenshots(hook)
else:
return
# Checks if the app is hooking screenshots.
@staticmethod
def IsScreenshotsHooked():
if Steam.IsSteamLoaded():
return Steam.cdll.IsScreenshotsHooked()
else:
return False
# Sets optional metadata about a screenshot's location.
@staticmethod
def SetLocation(screenshot, location):
if Steam.IsSteamLoaded():
return Steam.cdll.SetLocation(screenshot, location)
else:
return False
# Causes Steam overlay to take a screenshot.
@staticmethod
def TriggerScreenshot():
if Steam.IsSteamLoaded():
return Steam.cdll.TriggerScreenshot()
else:
return
#------------------------------------------------
# Class for Steam Users
#------------------------------------------------
class SteamUsers:
# Get user's Steam ID.
@staticmethod
def GetSteamID():
if Steam.IsSteamLoaded():
return Steam.cdll.GetSteamID()
else:
return 0
# Check, true/false, if user is logged into Steam currently.
@staticmethod
def LoggedOn():
if Steam.IsSteamLoaded():
return Steam.cdll.LoggedOn()
else:
return False
# Get the user's Steam level.
@staticmethod
def GetPlayerSteamLevel():
if Steam.IsSteamLoaded():
return Steam.cdll.GetPlayerSteamLevel()
else:
return 0
# Get the user's Steam installation path (this function is depreciated).
@staticmethod
def GetUserDataFolder():
if Steam.IsSteamLoaded():
return Steam.cdll.GetUserDataFolder()
else:
return ""
# Trading Card badges data access, if you only have one set of cards, the series will be 1.
# The user has can have two different badges for a series; the regular (max level 5) and the foil (max level 1).
@staticmethod
def GetGameBadgeLevel(series, foil):
if Steam.IsSteamLoaded():
return Steam.cdll.GetGameBadgeLevel(series, foil)
else:
return 0

0 comments on commit ab2bcde

Please sign in to comment.