Debian Codegraph @

xbmc/games/addons/cheevos/GameClientCheevos.cpp

raw
1 /*
2 * Copyright (C) 2020-2021 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "GameClientCheevos.h"
10
11 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/game.h"
12 #include "cores/RetroPlayer/cheevos/RConsoleIDs.h"
13 #include "games/addons/GameClient.h"
14
15 using namespace KODI;
16 using namespace GAME;
17
18 CGameClientCheevos::CGameClientCheevos(CGameClient& gameClient, AddonInstance_Game& addonStruct)
19 : m_gameClient(gameClient), m_struct(addonStruct)
20 {
21 }
22
23 bool CGameClientCheevos::RCGenerateHashFromFile(std::string& hash,
24 RETRO::RConsoleID consoleID,
25 const std::string& filePath)
26 {
27 char* _hash = nullptr;
28 GAME_ERROR error = GAME_ERROR_NO_ERROR;
29
30 try
31 {
32 m_gameClient.LogError(
33 error = m_struct.toAddon->RCGenerateHashFromFile(
34 &m_struct, &_hash, static_cast<unsigned int>(consoleID), filePath.c_str()),
35 "RCGenerateHashFromFile()");
36 }
37 catch (...)
38 {
39 m_gameClient.LogException("RCGetGameIDUrl()");
40 }
41
42 if (_hash)
43 {
44 hash = _hash;
45 m_struct.toAddon->FreeString(&m_struct, _hash);
46 }
47
48 return error == GAME_ERROR_NO_ERROR;
49 }
50
51 bool CGameClientCheevos::RCGetGameIDUrl(std::string& url, const std::string& hash)
52 {
53 char* _url = nullptr;
54 GAME_ERROR error = GAME_ERROR_NO_ERROR;
55
56 try
57 {
58 m_gameClient.LogError(error = m_struct.toAddon->RCGetGameIDUrl(&m_struct, &_url, hash.c_str()),
59 "RCGetGameIDUrl()");
60 }
61 catch (...)
62 {
63 m_gameClient.LogException("RCGetGameIDUrl()");
64 }
65
66 if (_url)
67 {
68 url = _url;
69 m_struct.toAddon->FreeString(&m_struct, _url);
70 }
71
72 return error == GAME_ERROR_NO_ERROR;
73 }
74
75 bool CGameClientCheevos::RCGetPatchFileUrl(std::string& url,
76 const std::string& username,
77 const std::string& token,
78 unsigned int gameID)
79 {
80 char* _url = nullptr;
81 GAME_ERROR error = GAME_ERROR_NO_ERROR;
82
83 try
84 {
85 m_gameClient.LogError(error = m_struct.toAddon->RCGetPatchFileUrl(
86 &m_struct, &_url, username.c_str(), token.c_str(), gameID),
87 "RCGetPatchFileUrl()");
88 }
89 catch (...)
90 {
91 m_gameClient.LogException("RCGetPatchFileUrl()");
92 }
93
94 if (_url)
95 {
96 url = _url;
97 m_struct.toAddon->FreeString(&m_struct, _url);
98 }
99
100 return error == GAME_ERROR_NO_ERROR;
101 }
102
103 bool CGameClientCheevos::RCPostRichPresenceUrl(std::string& url,
104 std::string& postData,
105 const std::string& username,
106 const std::string& token,
107 unsigned gameID,
108 const std::string& richPresence)
109 {
110 char* _url = nullptr;
111 char* _postData = nullptr;
112 GAME_ERROR error = GAME_ERROR_NO_ERROR;
113
114 try
115 {
116 m_gameClient.LogError(error = m_struct.toAddon->RCPostRichPresenceUrl(
117 &m_struct, &_url, &_postData, username.c_str(), token.c_str(), gameID,
118 richPresence.c_str()),
119 "RCPostRichPresenceUrl()");
120 }
121 catch (...)
122 {
123 m_gameClient.LogException("RCPostRichPresenceUrl()");
124 }
125
126 if (_url)
127 {
128 url = _url;
129 m_struct.toAddon->FreeString(&m_struct, _url);
130 }
131 if (_postData)
132 {
133 postData = _postData;
134 m_struct.toAddon->FreeString(&m_struct, _postData);
135 }
136
137 return error == GAME_ERROR_NO_ERROR;
138 }
139
140 void CGameClientCheevos::RCEnableRichPresence(const std::string& script)
141 {
142 GAME_ERROR error = GAME_ERROR_NO_ERROR;
143
144 try
145 {
146 m_gameClient.LogError(error = m_struct.toAddon->RCEnableRichPresence(&m_struct, script.c_str()),
147 "RCEnableRichPresence()");
148 }
149 catch (...)
150 {
151 m_gameClient.LogException("RCEnableRichPresence()");
152 }
153 }
154
155 void CGameClientCheevos::RCGetRichPresenceEvaluation(std::string& evaluation,
156 RETRO::RConsoleID consoleID)
157 {
158 char* _evaluation = nullptr;
159 GAME_ERROR error = GAME_ERROR_NO_ERROR;
160
161 try
162 {
163 m_gameClient.LogError(error = m_struct.toAddon->RCGetRichPresenceEvaluation(
164 &m_struct, &_evaluation, static_cast<unsigned int>(consoleID)),
165 "RCGetRichPresenceEvaluation()");
166
167 if (_evaluation)
168 {
169 evaluation = _evaluation;
170 m_struct.toAddon->FreeString(&m_struct, _evaluation);
171 }
172 }
173 catch (...)
174 {
175 m_gameClient.LogException("RCGetRichPresenceEvaluation()");
176 }
177 }
178
179 void CGameClientCheevos::RCResetRuntime()
180 {
181 GAME_ERROR error = GAME_ERROR_NO_ERROR;
182
183 try
184 {
185 m_gameClient.LogError(error = m_struct.toAddon->RCResetRuntime(&m_struct), "RCResetRuntime()");
186 }
187 catch (...)
188 {
189 m_gameClient.LogException("RCResetRuntime()");
190 }
191 }