steam: Remove the old _renpysteam.pyx module.

This commit is contained in:
Tom Rothamel
2022-02-24 00:00:55 -05:00
parent b94e23797a
commit 5782564a9c
2 changed files with 0 additions and 659 deletions
-650
View File
@@ -1,650 +0,0 @@
# Copyright 2004-2022 Tom Rothamel <pytom@bishoujo.us>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import print_function
version = 2
cdef extern from "steam/steam_api.h":
ctypedef bint bool
ctypedef int int32
ctypedef unsigned int uint32
ctypedef unsigned long long uint64
# Init.
bool SteamAPI_Init()
void SteamAPI_RunCallbacks()
bool SteamAPI_RestartAppIfNecessary(unsigned int)
# Stats & Achievements.
cdef cppclass ISteamUserStats:
bool RequestCurrentStats()
bool StoreStats()
bool GetAchievement(const char *pchName, bool *pbAchieved);
bool SetAchievement(const char *pchName);
bool ClearAchievement(const char *pchName);
bool IndicateAchievementProgress(const char *pchName, uint32 nCurProgress, uint32 nMaxProgress)
int GetNumAchievements()
char *GetAchievementName(int)
bool GetStat(const char *pchName, int32 *pData)
bool GetStat(const char *pchName, float *pData)
bool SetStat(const char *pchName, int32 iData)
bool SetStat(const char *pchName, float fData)
ctypedef struct UserStatsReceived_t
ISteamUserStats *SteamUserStats()
# Utils.
cdef enum ENotificationPosition:
k_EPositionTopLeft
k_EPositionTopRight
k_EPositionBottomLeft
k_EPositionBottomRight
cdef cppclass ISteamUtils:
bint IsOverlayEnabled()
void SetOverlayNotificationPosition(ENotificationPosition eNotificationPosition)
bool BOverlayNeedsPresent()
char *GetSteamUILanguage()
ISteamUtils *SteamUtils()
# Apps.
ctypedef int AppId_t
cdef cppclass ISteamApps:
bool BIsSubscribedApp(AppId_t appID)
const char *GetCurrentGameLanguage()
bool GetCurrentBetaName( char *pchName, int cchNameBufferSize );
bool BIsDlcInstalled(AppId_t nAppID)
void InstallDLC(AppId_t nAppID)
void UninstallDLC(AppId_t nAppID)
bool GetDlcDownloadProgress(AppId_t nAppID, uint64 *punBytesDownloaded, uint64 *punBytesTotal)
int GetAppBuildId();
ctypedef struct DlcInstalled_t:
AppId_t m_nAppID
ISteamApps *SteamApps()
# Friends.
cdef enum EOverlayToStoreFlag:
k_EOverlayToStoreFlag_None
k_EOverlayToStoreFlag_AddToCart
k_EOverlayToStoreFlag_AddToCartAndShow
cdef cppclass ISteamFriends:
const char *GetPersonaName()
void ActivateGameOverlay(const char *pchDialog)
void ActivateGameOverlayToWebPage(const char *pchURL)
void ActivateGameOverlayToStore(AppId_t nAppID, EOverlayToStoreFlag eFlag)
ISteamFriends *SteamFriends()
# User.
ctypedef uint32 AccountID_t
ctypedef uint32 HAuthTicket
cdef cppclass CSteamID:
AccountID_t GetAccountID()
uint64 ConvertToUint64()
cdef cppclass ISteamUser:
CSteamID GetSteamID()
HAuthTicket GetAuthSessionTicket(void *pTicket, int cbMaxTicket, uint32 *pcbTicket)
void CancelAuthTicket(HAuthTicket hAuthTicket)
int GetGameBadgeLevel( int nSeries, bool bFoil )
ISteamUser *SteamUser()
# UGC.
ctypedef uint64 PublishedFileId_t
cdef cppclass ISteamUGC:
bool GetItemInstallInfo(PublishedFileId_t nPublishedFileID, uint64 *punSizeOnDisk, char *pchFolder, uint32 cchFolderSize, uint32 *punTimeStamp )
uint32 GetSubscribedItems(PublishedFileId_t*pvecPublishedFileID, uint32 cMaxEntries)
uint32 GetNumSubscribedItems()
ISteamUGC *SteamUGC()
cdef extern from "steamcallbacks.h":
cdef cppclass SteamCallback[T]:
SteamCallback(void (*)(T *))
import renpy
######################################################### Stats and Achievements
# # A callable that is called when the stats are available.
# got_stats = None
#
# cdef void call_got_stats(UserStatsReceived_t *s):
# if got_stats is not None:
# got_stats()
#
# cdef SteamCallback[UserStatsReceived_t] *stats_received_callback = \
# new SteamCallback[UserStatsReceived_t](call_got_stats)
def retrieve_stats():
"""
:doc: steam_stats
Retrieves achievements and statistics from Steam.
"""
"""
`callback` will be
called with no parameters if and when the statistics become available.
"""
# global got_stats
# got_stats = callback
SteamUserStats().RequestCurrentStats()
def store_stats():
"""
:doc: steam_stats
Stores statistics and achievements on the Steam server.
"""
SteamUserStats().StoreStats()
def list_achievements():
"""
:doc: steam_stats
Returns a list of achievement names.
"""
rv = [ ]
cdef int na = SteamUserStats().GetNumAchievements()
cdef char *s
cdef int i
for 0 <= i < na:
s = <char *> SteamUserStats().GetAchievementName(i)
rv.append(s)
return rv
def get_achievement(name):
"""
:doc: steam_stats
Gets the state of the achievements with `name`. This returns True if the
achievement has been granted, False if it hasn't, and None if the achievement
is unknown or an error occurs.
"""
cdef bool rv
if not SteamUserStats().GetAchievement(name, &rv):
return None
return rv
def grant_achievement(name):
"""
:doc: steam_stats
Grants the achievement with `name`. Call :func:`_renpysteam.store_stats` to
push this change to the server.
"""
return SteamUserStats().SetAchievement(name)
def clear_achievement(name):
"""
:doc: steam_stats
Clears the achievement with `name`. Call :func:`_renpysteam.store_stats` to
push this change to the server.
"""
return SteamUserStats().ClearAchievement(name)
def indicate_achievement_progress(name, cur_progress, max_progress):
"""
:doc: steam_stats
Indicates achievement progress to the user. This does *not* unlock the
achievement.
"""
return SteamUserStats().IndicateAchievementProgress(name, cur_progress, max_progress)
def get_float_stat(name):
"""
:doc: steam_stats
Returns the value of the stat with `name`, or None if no such stat
exits.
"""
cdef float rv
if not SteamUserStats().GetStat(<char *> name, &rv):
return None
return rv
def set_float_stat(name, value):
"""
:doc: steam_stats
Sets the value of the stat with `name`, which must have the type of
FLOAT. Call :func:`_renpysteam.store_stats` to push this change to the
server.
"""
cdef float v = value
return SteamUserStats().SetStat(<char *> name, v)
def get_int_stat(name):
"""
:doc: steam_stats
Returns the value of the stat with `name`, or None if no such stat
exits.
"""
cdef int32 rv
if not SteamUserStats().GetStat(<char *> name, &rv):
return None
return rv
def set_int_stat(name, value):
"""
:doc: steam_stats
Sets the value of the stat with `name`, which must have the type of
INT. Call :func:`_renpysteam.store_stats` to push this change to the
server.
"""
cdef int32 v = value
return SteamUserStats().SetStat(<char *> name, v)
########################################################################### Apps
def is_subscribed_app(appid):
"""
:doc: steam_apps
Returns true if the user owns the app with `appid`, and false otherwise.
"""
return SteamApps().BIsSubscribedApp(appid)
def get_current_game_language():
"""
:doc: steam_apps
Return the name of the language the user has selected.
"""
cdef const char *s = SteamApps().GetCurrentGameLanguage()
return str(s)
def get_steam_ui_language():
"""
:doc: steam_apps
Return the name of the language the steam UI is using.
"""
cdef const char *s = SteamUtils().GetSteamUILanguage()
return str(s)
def get_current_beta_name():
"""
:doc: steam_apps
Returns the name of the current beta, or None if it can't.
"""
cdef char rv[256]
if not SteamApps().GetCurrentBetaName(rv, 256):
return None
return str(rv)
def dlc_installed(appid):
"""
:doc: steam_apps
Returns True if `dlc` is installed, or False otherwise.
"""
return SteamApps().BIsDlcInstalled(appid)
def install_dlc(appid):
"""
:doc: steam_apps
Requests the DLC with `appid` be installed.
"""
SteamApps().InstallDLC(appid)
def uninstall_dlc(appid):
"""
:doc: steam_apps
Requests that the DLC with `appid` be uninstalled.
"""
SteamApps().UninstallDLC(appid)
def dlc_progress(appid):
"""
:doc: steam_apps
Reports the progress towards DLC download completion.
"""
cdef uint64 done = 0
cdef uint64 total = 0
if SteamApps().GetDlcDownloadProgress(appid, &done, &total):
return done, total
else:
return None
def get_app_build_id():
"""
:doc: steam_apps
Returns the build ID of the installed game.
"""
return SteamApps().GetAppBuildId()
######################################################################## Overlay
def is_overlay_enabled():
"""
:doc: steam_overlay
Returns true if the steam overlay is enabled. (This might take a while to
return true once the game starts.)
"""
return SteamUtils().IsOverlayEnabled()
def overlay_needs_present():
"""
:doc: steam_overlay
Returns true if the steam overlay is enabled. (This might take a while to
return true once the game starts.)
"""
return SteamUtils().BOverlayNeedsPresent()
POSITION_TOP_LEFT = k_EPositionTopLeft
POSITION_TOP_RIGHT = k_EPositionTopRight
POSITION_BOTTOM_LEFT = k_EPositionBottomLeft
POSITION_BOTTOM_RIGHT = k_EPositionBottomRight
def set_overlay_notification_position(position):
"""
:doc: steam_overlay
Sets the position of the steam overlay. `Position` should be one of
_renpysteam.POSTION_TOP_LEFT, .POSITION_TOP_RIGHT, .POSITION_BOTTOM_LEFT,
or .POSITION_BOTTOM_RIGHT.
"""
SteamUtils().SetOverlayNotificationPosition(position)
def activate_overlay(dialog):
"""
:doc: steam_overlay
Activates the Steam overlay.
`dialog`
The dialog to open the overlay to. One of "Friends", "Community",
"Players", "Settings", "OfficialGameGroup", "Stats", "Achievements"
"""
SteamFriends().ActivateGameOverlay(dialog)
def activate_overlay_to_web_page(url):
"""
:doc: steam_overlay
Activates the Steam overlay, and opens the web page at `url`.
"""
SteamFriends().ActivateGameOverlayToWebPage(url)
STORE_NONE = k_EOverlayToStoreFlag_None
STORE_ADD_TO_CART = k_EOverlayToStoreFlag_AddToCart
STORE_ADD_TO_CART_AND_SHOW = k_EOverlayToStoreFlag_AddToCartAndShow
def activate_overlay_to_store(appid, flag=STORE_NONE):
"""
:doc: steam_overlay
Opens the steam overlay to the store.
`appid`
The appid to open.
`flag`
One of _renpysteam.STORE_NONE, .STORE_ADD_TO_CART, or .STORE_ADD_TO_CART_AND_SHOW.
"""
SteamFriends().ActivateGameOverlayToStore(appid, flag)
########################################################################### User
def get_persona_name():
"""
:doc: steam_user
Returns the user's publicly-visible name.
"""
return SteamFriends().GetPersonaName().decode("utf-8")
cdef extern from "steam/steam_api_flat.h":
ctypedef unsigned long long uint64_steamid
ISteamUser *SteamAPI_SteamUser_v021();
uint64_steamid SteamAPI_ISteamUser_GetSteamID( ISteamUser* self );
def get_csteam_id():
"""
:doc: steam_user
Returns the user's full CSteamID as a 64-bit number..
"""
# Accessing methods on CSteamID was crashing on Windows, so use
# the flat API instead.
return SteamAPI_ISteamUser_GetSteamID(SteamAPI_SteamUser_v021())
def get_account_id():
"""
:doc: steam_user
Returns the user's account ID.
"""
return get_csteam_id() & 0xffffffff
cdef HAuthTicket h_ticket = 0
ticket = None
def get_session_ticket():
"""
:doc: steam_user
Gets a ticket that can be sent to the server to authenticate this user.
"""
global ticket
global h_ticket
cdef char ticket_buf[2048]
cdef uint32 ticket_len
if ticket is not None:
return ticket
h_ticket = SteamUser().GetAuthSessionTicket(ticket_buf, 2048, &ticket_len)
if h_ticket:
ticket = ticket_buf[0:ticket_len]
return ticket
def cancel_ticket():
"""
:doc: steam_user
Cancels the ticket returned by :func:`_renpysteam.get_session_ticket`.
"""
global h_ticket
global tocket
SteamUser().CancelAuthTicket(h_ticket)
h_ticket = 0
ticket = None
def get_game_badge_level(series, foil):
"""
:doc: steam_user
Gets the level of the users Steam badge for your game.
"""
return SteamUser().GetGameBadgeLevel(series, foil)
########################################################################### UGC
def get_subscribed_items():
"""
:doc: steam_ugc
Returns a list of the item ids the user has subscribed to in the steam
workshop.
"""
cdef PublishedFileId_t subscribed[512]
cdef uint32 count
cdef uint32 i
count = SteamUGC().GetSubscribedItems(subscribed, 512)
rv = [ ]
for 0 <= i <= count:
rv.append(subscribed[i])
return rv
def get_subscribed_item_path(item_id):
"""
:doc: steam_ugc
Returns the path where an item of user-generated content was installed. Returns
None if the item was not installed.
`item_id`
The item id.
"""
cdef char path[4096]
cdef uint64 size
cdef uint32 timestamp
if not SteamUGC().GetItemInstallInfo(item_id, &size, path, 4096, &timestamp):
return None
return renpy.exports.fsdecode(path)
################################################################# Initialization
# Have we been initialized?
initialized = None
# Called periodically to run callbacks.
def periodic():
SteamAPI_RunCallbacks()
# Initialize the Steam API.
def init():
"""
:doc: steam
Initializes the Steam API. Returns true for success, false for failure.
If a failure has occurred, no other steam functions should be called.
This may be called multiple times, but only attempts initialization the
first time it's been called.
"""
global initialized
if initialized is None:
initialized = SteamAPI_Init()
if initialized:
renpy.config.periodic_callbacks.append(periodic)
renpy.config.needs_redraw_callbacks.append(overlay_needs_present)
set_overlay_notification_position(POSITION_TOP_RIGHT)
return initialized
-9
View File
@@ -104,13 +104,6 @@ else:
sdl = [ 'SDL2' ]
png = 'png'
steam_sdk = os.environ.get("RENPY_STEAM_SDK", None)
steam_platform = os.environ.get("RENPY_STEAM_PLATFORM", "")
if steam_sdk:
setuplib.library_dirs.append("{}/redistributable_bin/{}".format(steam_sdk, steam_platform))
setuplib.include_dirs.append("{}/public".format(steam_sdk))
cubism = os.environ.get("CUBISM", None)
if cubism:
setuplib.include_dirs.append("{}/Core/include".format(cubism))
@@ -147,8 +140,6 @@ cython(
("HAVE_CONFIG_H", "1"),
])
cython("_renpysteam", language="c++", compile_if=steam_sdk, libs=["steam_api"])
# Sound.
sound = [ "avformat", "avcodec", "avutil", "z" ]