2018-08-29 14:03:18 +02:00
|
|
|
#include <stdint.h>
|
2018-08-31 15:58:59 +02:00
|
|
|
#include <string.h>
|
2018-08-29 14:03:18 +02:00
|
|
|
#include "steamworks_api_wrapper.h"
|
|
|
|
#include "steamworks_c_wrapper.h"
|
|
|
|
#include "../util.h"
|
|
|
|
#include "../defines.h"
|
2018-08-29 14:11:36 +02:00
|
|
|
#include "../gui.h"
|
2018-08-31 15:58:59 +02:00
|
|
|
#include "../timer.h"
|
2019-02-20 19:45:55 +01:00
|
|
|
#include "../time.h"
|
2018-08-31 15:58:59 +02:00
|
|
|
|
2018-10-24 22:50:00 +02:00
|
|
|
static const char *LB_HIGHSCORE = "Highscore";
|
|
|
|
static const char *LB_QUICKPLAY_HIGHSCORE = "Quickplay Highscore";
|
2018-10-27 13:28:48 +02:00
|
|
|
static const char *LB_ARCADE_HIGHSCORE = "Arcade Highscore";
|
2018-10-24 22:50:00 +02:00
|
|
|
static const char *LB_ROGUE_HIGHSCORE = "Rogue Highscore";
|
|
|
|
static const char *LB_WARRIOR_HIGHSCORE = "Warrior Highscore";
|
|
|
|
static const char *LB_KILLS = "Most Kills";
|
2019-02-20 19:45:55 +01:00
|
|
|
static char *lb_weekly = NULL;
|
2018-08-29 14:03:18 +02:00
|
|
|
|
|
|
|
static Achievement g_Achievements[] = {
|
|
|
|
_ACH_ID(BAD_DOG, "Bad Dog"),
|
|
|
|
_ACH_ID(THE_DOCTOR_IS_OUT, "The Doctor is Out"),
|
|
|
|
_ACH_ID(LIGHTS_ON, "Omnidirectional light"),
|
|
|
|
_ACH_ID(BACK_TO_WORK, "Back to work"),
|
2018-10-18 23:19:33 +02:00
|
|
|
_ACH_ID(DRAGON_SLAYER, "Platinum dragon slayer"),
|
|
|
|
_ACH_ID(ROGUE_LIKE, "Rogue-like")
|
2018-08-29 14:03:18 +02:00
|
|
|
};
|
2018-10-18 23:19:33 +02:00
|
|
|
static Uint8 numAchievements = 6;
|
2018-08-29 14:03:18 +02:00
|
|
|
|
|
|
|
static bool m_Initiated = false;
|
2018-08-31 15:58:59 +02:00
|
|
|
static bool m_bStatsReceived = false;
|
2018-08-29 14:03:18 +02:00
|
|
|
static Sint64 m_AppID = 0;
|
2018-08-31 15:58:59 +02:00
|
|
|
static Sint64 m_hHighscoreLeaderboard = 0;
|
2018-10-24 22:50:00 +02:00
|
|
|
static Sint64 m_hQpHighscoreLeaderboard = 0;
|
2018-10-27 13:28:48 +02:00
|
|
|
static Sint64 m_hArcadeHighscoreLeaderboard = 0;
|
2018-08-31 15:58:59 +02:00
|
|
|
static Sint64 m_hKillsLeaderboard = 0;
|
2018-10-18 23:19:33 +02:00
|
|
|
static Sint64 m_hRogueHighscore = 0;
|
|
|
|
static Sint64 m_hWarriorHighscore = 0;
|
2019-02-20 19:45:55 +01:00
|
|
|
static Sint64 m_hWeeklyHighscore = 0;
|
2018-08-31 15:58:59 +02:00
|
|
|
|
|
|
|
static Timer *requestDataTimer = NULL;
|
2018-08-29 14:03:18 +02:00
|
|
|
|
|
|
|
static bool
|
2018-08-30 08:54:21 +02:00
|
|
|
steam_request_stats(void)
|
2018-08-29 14:03:18 +02:00
|
|
|
{
|
|
|
|
if (m_Initiated)
|
|
|
|
return c_SteamUserStats_RequestCurrentStats();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stats_received(void)
|
|
|
|
{
|
2018-08-29 14:26:07 +02:00
|
|
|
debug("Steam stats received");
|
2018-08-31 15:58:59 +02:00
|
|
|
m_bStatsReceived = true;
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
stats_stored(void)
|
|
|
|
{
|
2018-08-29 14:26:07 +02:00
|
|
|
debug("Steam stats stored");
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
2018-08-29 22:13:22 +02:00
|
|
|
static void
|
2018-08-31 15:58:59 +02:00
|
|
|
leaderboard_received(Sint64 hLeaderboard, const char *name)
|
2018-08-29 22:13:22 +02:00
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
debug("Leaderboard received: %s", name);
|
|
|
|
if (strcmp(LB_HIGHSCORE, name) == 0)
|
|
|
|
m_hHighscoreLeaderboard = hLeaderboard;
|
|
|
|
else if (strcmp(LB_KILLS, name) == 0)
|
|
|
|
m_hKillsLeaderboard = hLeaderboard;
|
2018-10-18 23:19:33 +02:00
|
|
|
else if (strcmp(LB_ROGUE_HIGHSCORE, name) == 0)
|
|
|
|
m_hRogueHighscore = hLeaderboard;
|
|
|
|
else if (strcmp(LB_WARRIOR_HIGHSCORE, name) == 0)
|
|
|
|
m_hWarriorHighscore = hLeaderboard;
|
2018-10-24 22:50:00 +02:00
|
|
|
else if (strcmp(LB_QUICKPLAY_HIGHSCORE, name) == 0)
|
|
|
|
m_hQpHighscoreLeaderboard = hLeaderboard;
|
2018-10-27 13:28:48 +02:00
|
|
|
else if (strcmp(LB_ARCADE_HIGHSCORE, name) == 0)
|
|
|
|
m_hArcadeHighscoreLeaderboard = hLeaderboard;
|
2019-02-20 19:45:55 +01:00
|
|
|
else if (strcmp(lb_weekly, name) == 0)
|
|
|
|
m_hWeeklyHighscore = hLeaderboard;
|
2018-08-29 22:13:22 +02:00
|
|
|
}
|
|
|
|
|
2018-09-17 14:23:35 +02:00
|
|
|
bool
|
|
|
|
steam_restart_needed()
|
|
|
|
{
|
|
|
|
return c_SteamAPI_RestartAppIfNecessary();
|
|
|
|
}
|
|
|
|
|
2018-08-29 14:03:18 +02:00
|
|
|
void
|
|
|
|
steam_init()
|
|
|
|
{
|
|
|
|
m_AppID = c_SteamAPI_Init();
|
|
|
|
m_Initiated = m_AppID != 0;
|
2019-02-20 19:45:55 +01:00
|
|
|
lb_weekly = time_get_weekly_lb_name();
|
2018-09-02 06:04:24 +02:00
|
|
|
if (m_Initiated)
|
|
|
|
c_SteamAPI_SetCallbacks(stats_received, stats_stored, leaderboard_received);
|
2019-02-20 18:08:13 +01:00
|
|
|
requestDataTimer = _timer_create();
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void steam_shutdown(void)
|
|
|
|
{
|
|
|
|
c_SteamAPI_Shutdown();
|
2018-08-31 15:58:59 +02:00
|
|
|
timer_destroy(requestDataTimer);
|
2019-02-20 19:45:55 +01:00
|
|
|
if (lb_weekly)
|
|
|
|
free(lb_weekly);
|
2018-08-31 15:58:59 +02:00
|
|
|
}
|
|
|
|
|
2018-09-02 06:04:24 +02:00
|
|
|
static void
|
2018-08-31 15:58:59 +02:00
|
|
|
request_data_queue_run(void)
|
|
|
|
{
|
|
|
|
if (!timer_started(requestDataTimer))
|
|
|
|
timer_start(requestDataTimer);
|
|
|
|
|
|
|
|
if (timer_get_ticks(requestDataTimer) > 1000) {
|
|
|
|
if (!m_bStatsReceived)
|
|
|
|
steam_request_stats();
|
|
|
|
else if (!m_hHighscoreLeaderboard)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_HIGHSCORE);
|
2018-10-24 22:50:00 +02:00
|
|
|
else if (!m_hQpHighscoreLeaderboard)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_QUICKPLAY_HIGHSCORE);
|
2018-10-27 13:28:48 +02:00
|
|
|
else if (!m_hArcadeHighscoreLeaderboard)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_ARCADE_HIGHSCORE);
|
2018-08-31 15:58:59 +02:00
|
|
|
else if (!m_hKillsLeaderboard)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_KILLS);
|
2018-10-18 23:19:33 +02:00
|
|
|
else if (!m_hRogueHighscore)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_ROGUE_HIGHSCORE);
|
|
|
|
else if (!m_hWarriorHighscore)
|
|
|
|
c_SteamUserStats_FindLeaderboard(LB_WARRIOR_HIGHSCORE);
|
2019-02-20 19:45:55 +01:00
|
|
|
else if (!m_hWeeklyHighscore)
|
|
|
|
c_SteamUserStats_FindLeaderboard(lb_weekly);
|
2018-08-31 15:58:59 +02:00
|
|
|
|
|
|
|
timer_start(requestDataTimer);
|
|
|
|
}
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void steam_run_callbacks(void)
|
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
if (m_Initiated) {
|
2018-08-29 14:03:18 +02:00
|
|
|
c_SteamAPI_RunCallbacks();
|
2018-08-31 15:58:59 +02:00
|
|
|
request_data_queue_run();
|
|
|
|
}
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void steam_set_achievement(EAchievement eAch)
|
|
|
|
{
|
2019-02-20 19:45:55 +01:00
|
|
|
if (!m_Initiated)
|
|
|
|
return;
|
|
|
|
|
2018-08-29 14:03:18 +02:00
|
|
|
for (Uint8 i = 0; i < numAchievements; ++i) {
|
2018-08-29 14:26:07 +02:00
|
|
|
Achievement *a = &g_Achievements[i];
|
|
|
|
if (a->m_eAchievementID == eAch && !a->m_bAchieved) {
|
2018-08-29 14:03:18 +02:00
|
|
|
c_SteamUserStats_SetAchievement(g_Achievements[i].m_pchAchievementID);
|
2018-08-29 14:26:07 +02:00
|
|
|
gui_log("You just earned the \"%s\" achievement", a->m_rgchName);
|
|
|
|
}
|
2018-08-29 14:03:18 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-29 22:13:22 +02:00
|
|
|
|
2018-09-02 23:44:48 +02:00
|
|
|
void steam_register_score(Sint32 nScore, const int32_t *details, int32_t nDetails)
|
2018-08-29 22:13:22 +02:00
|
|
|
{
|
2018-08-31 15:58:59 +02:00
|
|
|
if (!m_hHighscoreLeaderboard)
|
2018-08-29 22:13:22 +02:00
|
|
|
return;
|
2018-09-02 23:44:48 +02:00
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hHighscoreLeaderboard, nScore, details, nDetails);
|
2018-08-29 22:13:22 +02:00
|
|
|
}
|
2018-08-31 15:58:59 +02:00
|
|
|
|
2018-10-24 22:50:00 +02:00
|
|
|
void steam_register_qp_score(Sint32 nScore, const int32_t *details, int32_t nDetails)
|
|
|
|
{
|
|
|
|
if (!m_hQpHighscoreLeaderboard)
|
|
|
|
return;
|
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hQpHighscoreLeaderboard, nScore, details, nDetails);
|
|
|
|
}
|
|
|
|
|
2019-02-20 19:45:55 +01:00
|
|
|
void steam_register_weekly_score(Sint32 nScore, const int32_t *details, int32_t nDetails)
|
|
|
|
{
|
|
|
|
if (!m_hWeeklyHighscore)
|
|
|
|
return;
|
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hWeeklyHighscore, nScore, details, nDetails);
|
|
|
|
}
|
|
|
|
|
2018-10-27 13:28:48 +02:00
|
|
|
void steam_register_arcade_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
|
|
|
|
{
|
|
|
|
if (!m_hArcadeHighscoreLeaderboard)
|
|
|
|
return;
|
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hArcadeHighscoreLeaderboard, nScore, details, nDetails);
|
|
|
|
}
|
|
|
|
|
2018-10-18 23:19:33 +02:00
|
|
|
void steam_register_warrior_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
|
|
|
|
{
|
|
|
|
if (!m_hWarriorHighscore)
|
|
|
|
return;
|
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hWarriorHighscore, nScore, details, nDetails);
|
|
|
|
}
|
|
|
|
|
|
|
|
void steam_register_rogue_score(Sint32 nScore, const int32_t * details, int32_t nDetails)
|
|
|
|
{
|
|
|
|
if (!m_hRogueHighscore)
|
|
|
|
return;
|
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hRogueHighscore, nScore, details, nDetails);
|
|
|
|
}
|
|
|
|
|
2018-09-02 23:44:48 +02:00
|
|
|
void steam_register_kills(Sint32 nKills, const int32_t *details, int32_t nDetails)
|
2018-08-31 15:58:59 +02:00
|
|
|
{
|
|
|
|
if (!m_hKillsLeaderboard)
|
|
|
|
return;
|
2018-09-02 23:44:48 +02:00
|
|
|
c_SteamUserStats_UploadLeaderboardScore(m_hKillsLeaderboard, nKills, details, nDetails);
|
2018-09-02 06:04:24 +02:00
|
|
|
}
|