2018-08-27 17:16:01 +02:00
|
|
|
#include <steam_api.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "steamworks_c_wrapper.h"
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:03:18 +02:00
|
|
|
static bool m_Initiated = false;
|
|
|
|
static int64 m_AppId = 0;
|
|
|
|
static CallbackHandler *m_CallbackHandler = NULL;
|
|
|
|
static bool m_RecvCB = false;
|
|
|
|
|
|
|
|
static void(*statsReceivedCb)(void) = NULL;
|
|
|
|
static void(*statsStoredCb)(void) = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
extern "C" int64 c_SteamAPI_Init()
|
|
|
|
{
|
|
|
|
if (SteamAPI_Init()) {
|
|
|
|
m_AppId = SteamUtils()->GetAppID();
|
|
|
|
m_CallbackHandler = new CallbackHandler();
|
|
|
|
m_Initiated = true;
|
|
|
|
return m_AppId;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void))
|
2018-08-27 17:16:01 +02:00
|
|
|
{
|
2018-08-29 14:03:18 +02:00
|
|
|
statsReceivedCb = recvCB;
|
|
|
|
statsStoredCb = storCB;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int64 c_SteamAPI_GetAppID()
|
|
|
|
{
|
|
|
|
if (!m_Initiated)
|
|
|
|
return 0;
|
|
|
|
m_AppId = SteamUtils()->GetAppID();
|
|
|
|
return m_AppId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_SteamAPI_RunCallbacks(void)
|
|
|
|
{
|
|
|
|
if (m_Initiated)
|
|
|
|
SteamAPI_RunCallbacks();
|
2018-08-27 17:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void c_SteamAPI_Shutdown()
|
|
|
|
{
|
2018-08-29 14:03:18 +02:00
|
|
|
delete m_CallbackHandler;
|
2018-08-27 17:16:01 +02:00
|
|
|
SteamAPI_Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" bool c_SteamUserStats_RequestCurrentStats()
|
|
|
|
{
|
2018-08-29 14:03:18 +02:00
|
|
|
if (NULL == SteamUserStats() || NULL == SteamUser())
|
|
|
|
return false;
|
|
|
|
if (!SteamUser()->BLoggedOn())
|
|
|
|
return false;
|
|
|
|
|
2018-08-27 17:16:01 +02:00
|
|
|
return SteamUserStats()->RequestCurrentStats();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" bool c_SteamUserStats_SetAchievement(const char *pchName)
|
|
|
|
{
|
2018-08-29 14:03:18 +02:00
|
|
|
if (!m_RecvCB)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool result = SteamUserStats()->SetAchievement(pchName);
|
|
|
|
if (result)
|
|
|
|
SteamUserStats()->StoreStats();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void c_SteamUserStats_GetAchievement(const char *achId, bool *achieved)
|
|
|
|
{
|
|
|
|
SteamUserStats()->GetAchievement(achId, achieved);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" const char* c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName)
|
|
|
|
{
|
|
|
|
return SteamUserStats()->GetAchievementDisplayAttribute(achId, attrName);
|
|
|
|
}
|
|
|
|
|
|
|
|
CallbackHandler::CallbackHandler() :
|
|
|
|
m_CallbackUserStatsReceived(this, &CallbackHandler::OnUserStatsReceived),
|
|
|
|
m_CallbackUserStatsStored(this, &CallbackHandler::OnUserStatsStored)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CallbackHandler::OnUserStatsReceived(UserStatsReceived_t *pCallback)
|
|
|
|
{
|
|
|
|
if (m_AppId != pCallback->m_nGameID)
|
|
|
|
return;
|
|
|
|
m_RecvCB = true;
|
|
|
|
if (statsReceivedCb && k_EResultOK == pCallback->m_eResult)
|
|
|
|
statsReceivedCb();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CallbackHandler::OnUserStatsStored(UserStatsStored_t *pCallback)
|
|
|
|
{
|
|
|
|
if (m_AppId != pCallback->m_nGameID)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (statsStoredCb && k_EResultOK == pCallback->m_eResult)
|
|
|
|
statsStoredCb();
|
2018-08-27 17:16:01 +02:00
|
|
|
}
|