2018-09-14 08:47:41 +02:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-27 17:16:01 +02:00
|
|
|
#include <steam_api.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "steamworks_c_wrapper.h"
|
|
|
|
}
|
2018-08-31 15:58:59 +02:00
|
|
|
#include "CallbackHandler.h"
|
2018-08-27 17:16:01 +02:00
|
|
|
|
2018-08-29 14:03:18 +02:00
|
|
|
static bool m_Initiated = false;
|
|
|
|
static int64 m_AppId = 0;
|
|
|
|
static CallbackHandler *m_CallbackHandler = NULL;
|
|
|
|
|
2018-08-30 08:54:21 +02:00
|
|
|
extern "C" int64_t
|
2018-08-29 22:13:22 +02:00
|
|
|
c_SteamAPI_Init()
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
|
|
|
if (SteamAPI_Init()) {
|
|
|
|
m_AppId = SteamUtils()->GetAppID();
|
|
|
|
m_Initiated = true;
|
|
|
|
}
|
2018-09-02 17:39:43 +02:00
|
|
|
m_CallbackHandler = new CallbackHandler(m_AppId);
|
|
|
|
return m_AppId;
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-30 08:54:21 +02:00
|
|
|
extern "C" int64_t
|
2018-08-29 22:13:22 +02:00
|
|
|
c_SteamAPI_GetAppID()
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
|
|
|
if (!m_Initiated)
|
|
|
|
return 0;
|
|
|
|
m_AppId = SteamUtils()->GetAppID();
|
|
|
|
return m_AppId;
|
|
|
|
}
|
|
|
|
|
2018-09-17 14:23:35 +02:00
|
|
|
bool c_SteamAPI_RestartAppIfNecessary()
|
|
|
|
{
|
|
|
|
return SteamAPI_RestartAppIfNecessary(931040);
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
void
|
|
|
|
c_SteamAPI_RunCallbacks(void)
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
|
|
|
if (m_Initiated)
|
|
|
|
SteamAPI_RunCallbacks();
|
2018-08-27 17:16:01 +02:00
|
|
|
}
|
|
|
|
|
2018-08-31 15:58:59 +02:00
|
|
|
extern "C" void c_SteamAPI_SetCallbacks(void(*recvCB)(void), void(*storCB)(void), void(*recvLB)(int64_t, const char *))
|
2018-08-29 22:13:22 +02:00
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
m_CallbackHandler->statsReceivedCb = recvCB;
|
|
|
|
m_CallbackHandler->statsStoredCb = storCB;
|
|
|
|
m_CallbackHandler->leaderboardReceivedCb = recvLB;
|
2018-08-29 22:13:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void
|
|
|
|
c_SteamAPI_Shutdown()
|
2018-08-27 17:16:01 +02:00
|
|
|
{
|
2018-08-29 14:03:18 +02:00
|
|
|
delete m_CallbackHandler;
|
2018-08-27 17:16:01 +02:00
|
|
|
SteamAPI_Shutdown();
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
extern "C" bool
|
|
|
|
c_SteamUserStats_RequestCurrentStats()
|
2018-08-27 17:16:01 +02:00
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
extern "C" bool
|
|
|
|
c_SteamUserStats_SetAchievement(const char *pchName)
|
2018-08-27 17:16:01 +02:00
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
if (m_CallbackHandler && !m_CallbackHandler->CallbackReceived())
|
2018-08-29 14:03:18 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
bool result = SteamUserStats()->SetAchievement(pchName);
|
|
|
|
if (result)
|
|
|
|
SteamUserStats()->StoreStats();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
extern "C" void
|
|
|
|
c_SteamUserStats_GetAchievement(const char *achId, bool *achieved)
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
2018-08-29 22:13:22 +02:00
|
|
|
if (!m_Initiated)
|
|
|
|
return;
|
|
|
|
|
2018-08-29 14:03:18 +02:00
|
|
|
SteamUserStats()->GetAchievement(achId, achieved);
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
extern "C" const char*
|
|
|
|
c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName)
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
|
|
|
return SteamUserStats()->GetAchievementDisplayAttribute(achId, attrName);
|
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
extern "C" void
|
|
|
|
c_SteamUserStats_FindLeaderboard(const char * name)
|
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
if (!m_Initiated || !m_CallbackHandler)
|
2018-08-29 22:13:22 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(name);
|
|
|
|
m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard);
|
|
|
|
}
|
|
|
|
|
2019-02-20 20:03:06 +01:00
|
|
|
extern "C" void
|
|
|
|
c_SteamUserStats_FindOrCreateLeaderboard(const char *name)
|
|
|
|
{
|
|
|
|
if (!m_Initiated || !m_CallbackHandler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SteamAPICall_t hSteamAPICall = SteamUserStats()->FindOrCreateLeaderboard(name, k_ELeaderboardSortMethodAscending, k_ELeaderboardDisplayTypeNumeric);
|
|
|
|
m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard);
|
|
|
|
}
|
|
|
|
|
2018-09-03 17:21:33 +02:00
|
|
|
extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails)
|
2018-08-29 22:13:22 +02:00
|
|
|
{
|
|
|
|
if (!hLeaderboard || !m_Initiated)
|
|
|
|
return;
|
|
|
|
|
2018-09-02 23:44:48 +02:00
|
|
|
SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, details, nDetails);
|
2018-08-29 22:13:22 +02:00
|
|
|
}
|