Skip to content

Commit

Permalink
Changing parameter of callback with url
Browse files Browse the repository at this point in the history
  • Loading branch information
Shardul555 committed Jul 28, 2021
1 parent 1509ed5 commit cd28d68
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
39 changes: 27 additions & 12 deletions src/cheevos/Cheevos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "rcheevos/rconsoles.h"
#include "rcheevos/rhash.h"
#include "rcheevos/rurl.h"

#include <iostream>
constexpr int URL_SIZE = 512;
using namespace LIBRETRO;

CCheevos::CCheevos()
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions src/cheevos/Cheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit cd28d68

Please sign in to comment.