old steamuserstats

This commit is contained in:
a 2024-12-06 22:40:23 +02:00
parent 6f01f26b2f
commit 8422cc49b5
4 changed files with 316 additions and 2 deletions

View File

@ -58,6 +58,8 @@ struct achievement_trigger {
};
class Steam_User_Stats :
public ISteamUserStats001,
public ISteamUserStats002,
public ISteamUserStats003,
public ISteamUserStats004,
public ISteamUserStats005,
@ -404,6 +406,31 @@ public:
bool GetAchievementProgressLimits( const char *pchName, float *pfMinProgress, float *pfMaxProgress );
// old interface version
uint32 GetNumStats( CGameID nGameID );
const char *GetStatName( CGameID nGameID, uint32 iStat );
ESteamUserStatType GetStatType( CGameID nGameID, const char *pchName );
uint32 GetNumAchievements( CGameID nGameID );
const char *GetAchievementName( CGameID nGameID, uint32 iAchievement );
uint32 GetNumGroupAchievements( CGameID nGameID );
const char *GetGroupAchievementName( CGameID nGameID, uint32 iAchievement );
bool RequestCurrentStats( CGameID nGameID );
bool GetStat( CGameID nGameID, const char *pchName, int32 *pData );
bool GetStat( CGameID nGameID, const char *pchName, float *pData );
bool SetStat( CGameID nGameID, const char *pchName, int32 nData );
bool SetStat( CGameID nGameID, const char *pchName, float fData );
bool UpdateAvgRateStat( CGameID nGameID, const char *pchName, float flCountThisSession, double dSessionLength );
bool GetAchievement( CGameID nGameID, const char *pchName, bool *pbAchieved );
bool GetGroupAchievement( CGameID nGameID, const char *pchName, bool *pbAchieved );
bool SetAchievement( CGameID nGameID, const char *pchName );
bool SetGroupAchievement( CGameID nGameID, const char *pchName );
bool StoreStats( CGameID nGameID );
bool ClearAchievement( CGameID nGameID, const char *pchName );
bool ClearGroupAchievement( CGameID nGameID, const char *pchName );
int GetAchievementIcon( CGameID nGameID, const char *pchName );
const char *GetAchievementDisplayAttribute( CGameID nGameID, const char *pchName, const char *pchKey );
bool IndicateAchievementProgress( CGameID nGameID, const char *pchName, uint32 nCurProgress, uint32 nMaxProgress );
};
#endif//__INCLUDED_STEAM_USER_STATS_H__

View File

@ -478,8 +478,11 @@ ISteamUserStats *Steam_Client::GetISteamUserStats( HSteamUser hSteamUser, HSteam
PRINT_DEBUG("%s", pchVersion);
if (!steam_pipes.count(hSteamPipe) || !hSteamUser) return NULL;
// v001, v002 Not found in public Archive, must be before 1.00
if (strcmp(pchVersion, "STEAMUSERSTATS_INTERFACE_VERSION003") == 0) {
if (strcmp(pchVersion, "STEAMUSERSTATS_INTERFACE_VERSION001") == 0) {
return reinterpret_cast<ISteamUserStats *>(static_cast<ISteamUserStats001 *>(steam_user_stats));
} else if (strcmp(pchVersion, "STEAMUSERSTATS_INTERFACE_VERSION002") == 0) {
return reinterpret_cast<ISteamUserStats *>(static_cast<ISteamUserStats002 *>(steam_user_stats));
} else if (strcmp(pchVersion, "STEAMUSERSTATS_INTERFACE_VERSION003") == 0) {
return reinterpret_cast<ISteamUserStats *>(static_cast<ISteamUserStats003 *>(steam_user_stats));
} else if (strcmp(pchVersion, "STEAMUSERSTATS_INTERFACE_VERSION004") == 0) {
return reinterpret_cast<ISteamUserStats *>(static_cast<ISteamUserStats004 *>(steam_user_stats));

View File

@ -152,6 +152,288 @@ SteamAPICall_t Steam_User_Stats::GetNumberOfCurrentPlayers()
// --- old interface version
uint32 Steam_User_Stats::GetNumStats( CGameID nGameID )
{
PRINT_DEBUG("old %llu", nGameID.ToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return 0;
}
return (uint32)settings->getStats().size();
}
const char *Steam_User_Stats::GetStatName( CGameID nGameID, uint32 iStat )
{
PRINT_DEBUG("old %llu [%u]", nGameID.ToUint64(), iStat);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
auto &stats = settings->getStats();
if (settings->get_local_game_id() != nGameID || iStat >= stats.size()) {
return "";
}
return std::next(stats.begin(), iStat)->first.c_str();
}
ESteamUserStatType Steam_User_Stats::GetStatType( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s'", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID || !pchName) {
return ESteamUserStatType::k_ESteamUserStatTypeINVALID;
}
std::string stat_name(common_helpers::to_lower(pchName));
const auto &stats = settings->getStats();
auto stat_info = stats.find(stat_name);
if (stats.end() == stat_info) {
return ESteamUserStatType::k_ESteamUserStatTypeINVALID;
}
switch (stat_info->second.type)
{
case GameServerStats_Messages::StatInfo::STAT_TYPE_INT: return ESteamUserStatType::k_ESteamUserStatTypeINT;
case GameServerStats_Messages::StatInfo::STAT_TYPE_FLOAT: return ESteamUserStatType::k_ESteamUserStatTypeFLOAT;
case GameServerStats_Messages::StatInfo::STAT_TYPE_AVGRATE: return ESteamUserStatType::k_ESteamUserStatTypeAVGRATE;
default: PRINT_DEBUG("[X] unhandled type %i", (int)stat_info->second.type); break;
}
return ESteamUserStatType::k_ESteamUserStatTypeINVALID;
}
uint32 Steam_User_Stats::GetNumAchievements( CGameID nGameID )
{
PRINT_DEBUG("old %llu", nGameID.ToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return 0;
}
return GetNumAchievements();
}
const char *Steam_User_Stats::GetAchievementName( CGameID nGameID, uint32 iAchievement )
{
PRINT_DEBUG("old %llu [%u]", nGameID.ToUint64(), iAchievement);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return "";
}
return GetAchievementName(iAchievement);
}
uint32 Steam_User_Stats::GetNumGroupAchievements( CGameID nGameID )
{
PRINT_DEBUG("old %llu // TODO", nGameID.ToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return 0;
}
return 0;
}
const char *Steam_User_Stats::GetGroupAchievementName( CGameID nGameID, uint32 iAchievement )
{
PRINT_DEBUG("old %llu [%u] // TODO", nGameID.ToUint64(), iAchievement);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return "";
}
return "";
}
bool Steam_User_Stats::RequestCurrentStats( CGameID nGameID )
{
PRINT_DEBUG("old %llu", nGameID.ToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return RequestCurrentStats();
}
bool Steam_User_Stats::GetStat( CGameID nGameID, const char *pchName, int32 *pData )
{
PRINT_DEBUG("old %llu '%s' %p", nGameID.ToUint64(), pchName, pData);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (pData) *pData = 0;
if (settings->get_local_game_id() != nGameID) {
return false;
}
return GetStat(pchName, pData);
}
bool Steam_User_Stats::GetStat( CGameID nGameID, const char *pchName, float *pData )
{
PRINT_DEBUG("old %llu '%s' %p", nGameID.ToUint64(), pchName, pData);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (pData) *pData = 0;
if (settings->get_local_game_id() != nGameID) {
return false;
}
return GetStat(pchName, pData);
}
bool Steam_User_Stats::SetStat( CGameID nGameID, const char *pchName, int32 nData )
{
PRINT_DEBUG("old %llu '%s' %i", nGameID.ToUint64(), pchName, nData);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return SetStat(pchName, nData);
}
bool Steam_User_Stats::SetStat( CGameID nGameID, const char *pchName, float fData )
{
PRINT_DEBUG("old %llu '%s' %f", nGameID.ToUint64(), pchName, fData);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return SetStat(pchName, fData);
}
bool Steam_User_Stats::UpdateAvgRateStat( CGameID nGameID, const char *pchName, float flCountThisSession, double dSessionLength )
{
PRINT_DEBUG("old %llu '%s' %f %f", nGameID.ToUint64(), pchName, flCountThisSession, dSessionLength);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return UpdateAvgRateStat(pchName, flCountThisSession, dSessionLength);
}
bool Steam_User_Stats::GetAchievement( CGameID nGameID, const char *pchName, bool *pbAchieved )
{
PRINT_DEBUG("old %llu '%s' %p", nGameID.ToUint64(), pchName, pbAchieved);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (pbAchieved) *pbAchieved = false;
if (settings->get_local_game_id() != nGameID) {
return false;
}
return GetAchievement(pchName, pbAchieved);
}
bool Steam_User_Stats::GetGroupAchievement( CGameID nGameID, const char *pchName, bool *pbAchieved )
{
PRINT_DEBUG("old %llu '%s' %p // TODO", nGameID.ToUint64(), pchName, pbAchieved);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (pbAchieved) *pbAchieved = false;
if (settings->get_local_game_id() != nGameID) {
return false;
}
return false;
}
bool Steam_User_Stats::SetAchievement( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s'", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID && settings->achievement_bypass) {
return false;
}
return SetAchievement(pchName);
}
bool Steam_User_Stats::SetGroupAchievement( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s' // TODO", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return false;
}
bool Steam_User_Stats::StoreStats( CGameID nGameID )
{
PRINT_DEBUG("old %llu", nGameID.ToUint64());
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return StoreStats();
}
bool Steam_User_Stats::ClearAchievement( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s'", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return ClearAchievement(pchName);
}
bool Steam_User_Stats::ClearGroupAchievement( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s' // TODO", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return 0;
}
return false;
}
int Steam_User_Stats::GetAchievementIcon( CGameID nGameID, const char *pchName )
{
PRINT_DEBUG("old %llu '%s'", nGameID.ToUint64(), pchName);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return Settings::INVALID_IMAGE_HANDLE;
}
return GetAchievementIcon(pchName);
}
const char *Steam_User_Stats::GetAchievementDisplayAttribute( CGameID nGameID, const char *pchName, const char *pchKey )
{
PRINT_DEBUG("old %llu '%s' ['%s']", nGameID.ToUint64(), pchName, pchKey);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return "";
}
return GetAchievementDisplayAttribute(pchName, pchKey);
}
bool Steam_User_Stats::IndicateAchievementProgress( CGameID nGameID, const char *pchName, uint32 nCurProgress, uint32 nMaxProgress )
{
PRINT_DEBUG("old %llu '%s' %u %u", nGameID.ToUint64(), pchName, nCurProgress, nMaxProgress);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (settings->get_local_game_id() != nGameID) {
return false;
}
return IndicateAchievementProgress(pchName, nCurProgress, nMaxProgress);
}
// --- steam callbacks
void Steam_User_Stats::steam_run_callback()

View File

@ -104,6 +104,8 @@
#include "isteamuserstats005.h"
#include "isteamuserstats004.h"
#include "isteamuserstats003.h"
#include "isteamuserstats002.h"
#include "isteamuserstats001.h"
#include "isteamapps.h"
#include "isteamapps007.h"
#include "isteamapps006.h"