-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsteamworks_c_wrapper.cpp
More file actions
128 lines (108 loc) · 3.34 KB
/
steamworks_c_wrapper.cpp
File metadata and controls
128 lines (108 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* 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/>.
*/
#include <steam_api.h>
extern "C" {
#include "steamworks_c_wrapper.h"
}
#include "CallbackHandler.h"
static bool m_Initiated = false;
static int64 m_AppId = 0;
static CallbackHandler *m_CallbackHandler = NULL;
extern "C" int64_t
c_SteamAPI_Init()
{
if (SteamAPI_Init()) {
m_AppId = SteamUtils()->GetAppID();
m_Initiated = true;
}
m_CallbackHandler = new CallbackHandler(m_AppId);
return m_AppId;
}
extern "C" int64_t
c_SteamAPI_GetAppID()
{
if (!m_Initiated)
return 0;
m_AppId = SteamUtils()->GetAppID();
return m_AppId;
}
bool c_SteamAPI_RestartAppIfNecessary()
{
return SteamAPI_RestartAppIfNecessary(931040);
}
void
c_SteamAPI_RunCallbacks(void)
{
if (m_Initiated)
SteamAPI_RunCallbacks();
}
extern "C" void c_SteamAPI_SetCallbacks(void(*storCB)(void), void(*recvLB)(int64_t, const char *))
{
m_CallbackHandler->statsStoredCb = storCB;
m_CallbackHandler->leaderboardReceivedCb = recvLB;
}
extern "C" void
c_SteamAPI_Shutdown()
{
delete m_CallbackHandler;
SteamAPI_Shutdown();
}
extern "C" bool
c_SteamUserStats_SetAchievement(const char *pchName)
{
if (m_CallbackHandler == nullptr)
return false;
bool result = SteamUserStats()->SetAchievement(pchName);
if (result)
SteamUserStats()->StoreStats();
return result;
}
extern "C" void
c_SteamUserStats_GetAchievement(const char *achId, bool *achieved)
{
if (!m_Initiated)
return;
SteamUserStats()->GetAchievement(achId, achieved);
}
extern "C" const char*
c_SteamUserStats_GetAchievementDisplayAttribute(const char *achId, const char *attrName)
{
return SteamUserStats()->GetAchievementDisplayAttribute(achId, attrName);
}
extern "C" void
c_SteamUserStats_FindLeaderboard(const char * name)
{
if (!m_Initiated || !m_CallbackHandler)
return;
SteamAPICall_t hSteamAPICall = SteamUserStats()->FindLeaderboard(name);
m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard);
}
extern "C" void
c_SteamUserStats_FindOrCreateLeaderboard(const char *name)
{
if (!m_Initiated || !m_CallbackHandler)
return;
SteamAPICall_t hSteamAPICall = SteamUserStats()->FindOrCreateLeaderboard(name, k_ELeaderboardSortMethodDescending, k_ELeaderboardDisplayTypeNumeric);
m_CallbackHandler->m_FindLeaderboardCallResult.Set(hSteamAPICall, m_CallbackHandler, &CallbackHandler::OnFindLeaderboard);
}
extern "C" void c_SteamUserStats_UploadLeaderboardScore(int64_t hLeaderboard, int32_t nScore, const int32_t *details, int32_t nDetails)
{
if (!hLeaderboard || !m_Initiated)
return;
SteamUserStats()->UploadLeaderboardScore(hLeaderboard, k_ELeaderboardUploadScoreMethodKeepBest, nScore, details, nDetails);
}