summaryrefslogtreecommitdiffstats
path: root/xbmc/games/addons/cheevos
diff options
context:
space:
mode:
Diffstat (limited to 'xbmc/games/addons/cheevos')
-rw-r--r--xbmc/games/addons/cheevos/CMakeLists.txt5
-rw-r--r--xbmc/games/addons/cheevos/GameClientCheevos.cpp191
-rw-r--r--xbmc/games/addons/cheevos/GameClientCheevos.h57
3 files changed, 253 insertions, 0 deletions
diff --git a/xbmc/games/addons/cheevos/CMakeLists.txt b/xbmc/games/addons/cheevos/CMakeLists.txt
new file mode 100644
index 0000000..826fc04
--- /dev/null
+++ b/xbmc/games/addons/cheevos/CMakeLists.txt
@@ -0,0 +1,5 @@
+set(SOURCES GameClientCheevos.cpp)
+
+set(HEADERS GameClientCheevos.h)
+
+core_add_library(gamecheevos)
diff --git a/xbmc/games/addons/cheevos/GameClientCheevos.cpp b/xbmc/games/addons/cheevos/GameClientCheevos.cpp
new file mode 100644
index 0000000..e9d457b
--- /dev/null
+++ b/xbmc/games/addons/cheevos/GameClientCheevos.cpp
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2020-2021 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#include "GameClientCheevos.h"
+
+#include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/game.h"
+#include "cores/RetroPlayer/cheevos/RConsoleIDs.h"
+#include "games/addons/GameClient.h"
+
+using namespace KODI;
+using namespace GAME;
+
+CGameClientCheevos::CGameClientCheevos(CGameClient& gameClient, AddonInstance_Game& addonStruct)
+ : m_gameClient(gameClient), m_struct(addonStruct)
+{
+}
+
+bool CGameClientCheevos::RCGenerateHashFromFile(std::string& hash,
+ RETRO::RConsoleID consoleID,
+ const std::string& filePath)
+{
+ char* _hash = nullptr;
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(
+ error = m_struct.toAddon->RCGenerateHashFromFile(
+ &m_struct, &_hash, static_cast<unsigned int>(consoleID), filePath.c_str()),
+ "RCGenerateHashFromFile()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCGetGameIDUrl()");
+ }
+
+ if (_hash)
+ {
+ hash = _hash;
+ m_struct.toAddon->FreeString(&m_struct, _hash);
+ }
+
+ return error == GAME_ERROR_NO_ERROR;
+}
+
+bool CGameClientCheevos::RCGetGameIDUrl(std::string& url, const std::string& hash)
+{
+ char* _url = nullptr;
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCGetGameIDUrl(&m_struct, &_url, hash.c_str()),
+ "RCGetGameIDUrl()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCGetGameIDUrl()");
+ }
+
+ if (_url)
+ {
+ url = _url;
+ m_struct.toAddon->FreeString(&m_struct, _url);
+ }
+
+ return error == GAME_ERROR_NO_ERROR;
+}
+
+bool CGameClientCheevos::RCGetPatchFileUrl(std::string& url,
+ const std::string& username,
+ const std::string& token,
+ unsigned int gameID)
+{
+ char* _url = nullptr;
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCGetPatchFileUrl(
+ &m_struct, &_url, username.c_str(), token.c_str(), gameID),
+ "RCGetPatchFileUrl()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCGetPatchFileUrl()");
+ }
+
+ if (_url)
+ {
+ url = _url;
+ m_struct.toAddon->FreeString(&m_struct, _url);
+ }
+
+ return error == GAME_ERROR_NO_ERROR;
+}
+
+bool CGameClientCheevos::RCPostRichPresenceUrl(std::string& url,
+ std::string& postData,
+ const std::string& username,
+ const std::string& token,
+ unsigned gameID,
+ const std::string& richPresence)
+{
+ char* _url = nullptr;
+ char* _postData = nullptr;
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCPostRichPresenceUrl(
+ &m_struct, &_url, &_postData, username.c_str(), token.c_str(), gameID,
+ richPresence.c_str()),
+ "RCPostRichPresenceUrl()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCPostRichPresenceUrl()");
+ }
+
+ if (_url)
+ {
+ url = _url;
+ m_struct.toAddon->FreeString(&m_struct, _url);
+ }
+ if (_postData)
+ {
+ postData = _postData;
+ m_struct.toAddon->FreeString(&m_struct, _postData);
+ }
+
+ return error == GAME_ERROR_NO_ERROR;
+}
+
+void CGameClientCheevos::RCEnableRichPresence(const std::string& script)
+{
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCEnableRichPresence(&m_struct, script.c_str()),
+ "RCEnableRichPresence()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCEnableRichPresence()");
+ }
+}
+
+void CGameClientCheevos::RCGetRichPresenceEvaluation(std::string& evaluation,
+ RETRO::RConsoleID consoleID)
+{
+ char* _evaluation = nullptr;
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCGetRichPresenceEvaluation(
+ &m_struct, &_evaluation, static_cast<unsigned int>(consoleID)),
+ "RCGetRichPresenceEvaluation()");
+
+ if (_evaluation)
+ {
+ evaluation = _evaluation;
+ m_struct.toAddon->FreeString(&m_struct, _evaluation);
+ }
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCGetRichPresenceEvaluation()");
+ }
+}
+
+void CGameClientCheevos::RCResetRuntime()
+{
+ GAME_ERROR error = GAME_ERROR_NO_ERROR;
+
+ try
+ {
+ m_gameClient.LogError(error = m_struct.toAddon->RCResetRuntime(&m_struct), "RCResetRuntime()");
+ }
+ catch (...)
+ {
+ m_gameClient.LogException("RCResetRuntime()");
+ }
+}
diff --git a/xbmc/games/addons/cheevos/GameClientCheevos.h b/xbmc/games/addons/cheevos/GameClientCheevos.h
new file mode 100644
index 0000000..2be8c7a
--- /dev/null
+++ b/xbmc/games/addons/cheevos/GameClientCheevos.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020-2021 Team Kodi
+ * This file is part of Kodi - https://kodi.tv
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ * See LICENSES/README.md for more information.
+ */
+
+#pragma once
+
+#include <stddef.h> /* size_t */
+#include <string>
+
+struct AddonInstance_Game;
+
+namespace KODI
+{
+namespace RETRO
+{
+enum class RConsoleID;
+}
+
+namespace GAME
+{
+
+class CGameClient;
+
+class CGameClientCheevos
+{
+public:
+ CGameClientCheevos(CGameClient& gameClient, AddonInstance_Game& addonStruct);
+
+ bool RCGenerateHashFromFile(std::string& hash,
+ RETRO::RConsoleID consoleID,
+ const std::string& filePath);
+ bool RCGetGameIDUrl(std::string& url, const std::string& hash);
+ bool RCGetPatchFileUrl(std::string& url,
+ const std::string& username,
+ const std::string& token,
+ unsigned int gameID);
+ bool RCPostRichPresenceUrl(std::string& url,
+ std::string& postData,
+ const std::string& username,
+ const std::string& token,
+ unsigned gameID,
+ const std::string& richPresence);
+ void RCEnableRichPresence(const std::string& script);
+ void RCGetRichPresenceEvaluation(std::string& evaluation, RETRO::RConsoleID consoleID);
+ // When the game is reset, the runtime should also be reset
+ void RCResetRuntime();
+
+private:
+ CGameClient& m_gameClient;
+ AddonInstance_Game& m_struct;
+};
+} // namespace GAME
+} // namespace KODI