Skip to content

Commit

Permalink
Debug for awarding achievement feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Shardul555 committed Aug 2, 2021
1 parent cd28d68 commit 9a4a4a8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
49 changes: 27 additions & 22 deletions src/cheevos/Cheevos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
#include "rcheevos/rconsoles.h"
#include "rcheevos/rhash.h"
#include "rcheevos/rurl.h"
#include <iostream>

constexpr int URL_SIZE = 512;

using namespace LIBRETRO;

CCheevos::CCheevos()
{
rc_runtime_init(&m_runtime);
m_cheevo_id = 0;
url = NULL;
}

void CCheevos::Initialize()
Expand Down Expand Up @@ -82,7 +84,6 @@ bool CCheevos::PostRichPresenceUrl(char* url,

void CCheevos::EnableRichPresence(const char* script)
{

rc_runtime_activate_richpresence(&m_runtime, script, NULL, 0);

m_richPresenceBuffer.resize(rc_richpresence_size(script));
Expand All @@ -99,13 +100,12 @@ void CCheevos::EvaluateRichPresence(char* evaluation, size_t size)

void CCheevos::ActivateAchievement(unsigned cheevo_id, const char* memaddr) //1
{
int res=rc_runtime_activate_achievement(&m_runtime, cheevo_id, memaddr, NULL, 0);
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 @@ -122,44 +122,49 @@ bool CCheevos::AwardAchievement(char* url,
return rc_url_award_cheevo(url, size, username, token, cheevo_id, 0, game_hash) >= 0;
}

bool LIBRETRO::CCheevos::GetCheevo_ID(void (*Callback)(char* achievement_url))
bool LIBRETRO::CCheevos::GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id))
{
if (url != "")
{
Callback(url);
kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww in Callback");
Callback(url, m_cheevo_id);
return true;
}
return false;

// m_cheevo_id = 0;
}

void CCheevos::DeactivateTriggeredAchievement(unsigned cheevo_id)
{
kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww");
kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww");
kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww");
if (CCheevos::Get().AwardAchievement(url, URL_SIZE, m_username, m_token, cheevo_id, 0, m_hash))
{
// m_cheevo_id = cheevo_id;
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, "urls now");
kodi::Log(ADDON_LOG_ERROR, "urls now");
kodi::Log(ADDON_LOG_ERROR, url);
CCheevos::Get().GetCheevo_ID(this->Callback);
url = "";
url = NULL;
}

}

void CCheevos::TestAchievementPerFrame()
{
rc_runtime_do_frame(&m_runtime, RuntimeEventHandler, PeekInternal, this, NULL);
}


void CCheevos::RuntimeEventHandler(const rc_runtime_event_t* runtime_event)
{
if (runtime_event->type == RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED)
{
CCheevos::Get().DeactivateTriggeredAchievement(runtime_event->id);
CCheevos::Get().DeactivateTriggeredAchievement(runtime_event->id);
}
else
{
kodi::Log(ADDON_LOG_ERROR,
"Means function is running fine though achievement is not triggered");
}
kodi::Log(ADDON_LOG_ERROR, "Runtime Event Handler function is called");
}

void CCheevos::TestAchievementPerFrame()
{
rc_runtime_do_frame(&m_runtime, &RuntimeEventHandler, PeekInternal, NULL, 0);
}

unsigned int CCheevos::PeekInternal(unsigned address, unsigned num_bytes, void* ud)
Expand Down
20 changes: 11 additions & 9 deletions src/cheevos/Cheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class CCheevos
public:
CCheevos();
static CCheevos& Get();

void Initialize();
void Deinitialize();
// When the game is reset, the runtime should also be reset
Expand Down Expand Up @@ -52,10 +51,12 @@ class CCheevos
int hardcore,
const char* game_hash);
void DeactivateTriggeredAchievement(unsigned cheevo_id);
void TestAchievementPerFrame();
static void RuntimeEventHandler(const rc_runtime_event_t* runtime_event);
void TestAchievementPerFrame();
unsigned int Peek(unsigned int address, unsigned int numBytes);
bool GetCheevo_ID(void (*Callback)(char* achievement_url));
void (*Callback)(char* achievement_url);
bool GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id));
//static rc_runtime_event_handler_t RuntimeEventHandler;
void (*Callback)(char* achievement_url, unsigned cheevo_id);

private:
const uint8_t* FixupFind(unsigned address, CMemoryMap& mmap, int consolecheevos);
Expand All @@ -64,19 +65,20 @@ class CCheevos
size_t Reduse(size_t addr, size_t mask);

static unsigned int PeekInternal(unsigned address, unsigned num_bytes, void* ud);
static void RuntimeEventHandler(const rc_runtime_event_t* runtime_event);

rc_runtime_t m_runtime;
std::unordered_map<unsigned, const uint8_t*> m_addressFixups;

// Rich Presence
rc_richpresence_t* m_richPresence = nullptr;
std::string m_richPresenceScript;
std::vector<char> m_richPresenceBuffer;

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;
std::string m_richPresenceScript;
std::vector<char> m_richPresenceBuffer;
};
}
6 changes: 4 additions & 2 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ GAME_ERROR CGameLibRetro::RunFrame()
m_clientBridge.FrameTime(delta);

m_client.retro_run();

TestAchievementPerFrame();

CLibretroEnvironment::Get().OnFrameEnd();

return GAME_ERROR_NO_ERROR;
Expand Down Expand Up @@ -529,8 +531,8 @@ GAME_ERROR CGameLibRetro::ActivateAchievement(unsigned cheevo_id, const char* me
return GAME_ERROR_NO_ERROR;
}

GAME_ERROR CGameLibRetro::GetCheevo_ID(void (*Callback)(char* achievement_url))

GAME_ERROR CGameLibRetro::GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id))
{
if (!CCheevos::Get().GetCheevo_ID(Callback))
{
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)(char* achievement_url))override;
GAME_ERROR GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id)) override;

private:
GAME_ERROR AudioAvailable();
Expand Down

0 comments on commit 9a4a4a8

Please sign in to comment.