From cd28d682157c7f2b3bc17a99c7f2ea29d85c47c0 Mon Sep 17 00:00:00 2001 From: Shardul555 Date: Wed, 28 Jul 2021 20:29:43 +0530 Subject: [PATCH] Changing parameter of callback with url --- src/cheevos/Cheevos.cpp | 39 +++++++++++++++++++++++++++------------ src/cheevos/Cheevos.h | 6 ++++-- src/client.cpp | 8 ++++++-- src/client.h | 2 +- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/cheevos/Cheevos.cpp b/src/cheevos/Cheevos.cpp index 228a6542..69551610 100644 --- a/src/cheevos/Cheevos.cpp +++ b/src/cheevos/Cheevos.cpp @@ -14,7 +14,8 @@ #include "rcheevos/rconsoles.h" #include "rcheevos/rhash.h" #include "rcheevos/rurl.h" - +#include +constexpr int URL_SIZE = 512; using namespace LIBRETRO; CCheevos::CCheevos() @@ -98,8 +99,12 @@ void CCheevos::EvaluateRichPresence(char* evaluation, size_t size) void CCheevos::ActivateAchievement(unsigned cheevo_id, const char* memaddr) //1 { - rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0); - kodi::Log(ADDON_LOG_ERROR, "AAAbAAAAA"); + int res=rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0); + if (res == 0) + { + kodi::Log(ADDON_LOG_ERROR, "AAAbAAAAA"); + } + // it will return integer value 0 in case achivement is activated successfully. @@ -114,25 +119,35 @@ bool CCheevos::AwardAchievement(char* url, const char* game_hash) { - return rc_url_award_cheevo(url, size, m_username, m_token, m_cheevo_id, 0, game_hash) >= 0; + return rc_url_award_cheevo(url, size, username, token, cheevo_id, 0, game_hash) >= 0; } -void LIBRETRO::CCheevos::GetCheevo_ID(void (*Callback)(unsigned cheevo_id)) +bool LIBRETRO::CCheevos::GetCheevo_ID(void (*Callback)(char* achievement_url)) { - Callback(m_cheevo_id); + if (url != "") + { + Callback(url); + return true; + } + return false; + // m_cheevo_id = 0; - } void CCheevos::DeactivateTriggeredAchievement(unsigned cheevo_id) { - m_cheevo_id = cheevo_id; - rc_runtime_deactivate_achievement(&m_runtime, cheevo_id); - CCheevos::Get().GetCheevo_ID(this->Callback); - //this->Callback(m_cheevo_id); + if (CCheevos::Get().AwardAchievement(url, URL_SIZE, m_username, m_token, cheevo_id, 0, m_hash)) + { + // m_cheevo_id = cheevo_id; + rc_runtime_deactivate_achievement(&m_runtime, cheevo_id); + kodi::Log(ADDON_LOG_ERROR, "urls now"); + kodi::Log(ADDON_LOG_ERROR, url); + CCheevos::Get().GetCheevo_ID(this->Callback); + url = ""; + } + } - void CCheevos::TestAchievementPerFrame() { rc_runtime_do_frame(&m_runtime, RuntimeEventHandler, PeekInternal, this, NULL); diff --git a/src/cheevos/Cheevos.h b/src/cheevos/Cheevos.h index 806132cf..103a1967 100644 --- a/src/cheevos/Cheevos.h +++ b/src/cheevos/Cheevos.h @@ -54,8 +54,8 @@ class CCheevos void DeactivateTriggeredAchievement(unsigned cheevo_id); void TestAchievementPerFrame(); unsigned int Peek(unsigned int address, unsigned int numBytes); - void GetCheevo_ID(void (*Callback)(unsigned cheevo_id)); - void (*Callback)(unsigned cheevo_id); + bool GetCheevo_ID(void (*Callback)(char* achievement_url)); + void (*Callback)(char* achievement_url); private: const uint8_t* FixupFind(unsigned address, CMemoryMap& mmap, int consolecheevos); @@ -71,6 +71,8 @@ class CCheevos const char* m_hash; const char* m_username; const char* m_token; + char* url; + char postData[1024]; unsigned m_cheevo_id; // Rich Presence rc_richpresence_t* m_richPresence = nullptr; diff --git a/src/client.cpp b/src/client.cpp index 427d6d5a..034c356c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -530,9 +530,13 @@ GAME_ERROR CGameLibRetro::ActivateAchievement(unsigned cheevo_id, const char* me } -GAME_ERROR CGameLibRetro::GetCheevo_ID(void (*Callback)(unsigned cheevo_id)) +GAME_ERROR CGameLibRetro::GetCheevo_ID(void (*Callback)(char* achievement_url)) { - CCheevos::Get().GetCheevo_ID(Callback); + if (!CCheevos::Get().GetCheevo_ID(Callback)) + { + return GAME_ERROR_FAILED; + } + return GAME_ERROR_NO_ERROR(); } diff --git a/src/client.h b/src/client.h index b2fb843a..f8de294e 100644 --- a/src/client.h +++ b/src/client.h @@ -107,7 +107,7 @@ class ATTRIBUTE_HIDDEN CGameLibRetro GAME_ERROR DeactivateTriggeredAchievement(unsigned cheevo_id) override; GAME_ERROR TestAchievementPerFrame() override; GAME_ERROR RCResetRuntime() override; - GAME_ERROR GetCheevo_ID(void (*Callback)(unsigned cheevo_id)) override; + GAME_ERROR GetCheevo_ID(void (*Callback)(char* achievement_url))override; private: GAME_ERROR AudioAvailable();