Skip to content

Commit

Permalink
Forced push changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shardul555 committed Aug 4, 2021
1 parent 940016b commit 693d4aa
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/cheevos/Cheevos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

using namespace LIBRETRO;

constexpr int URL_SIZE = 512;

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

void CCheevos::Initialize()
Expand Down Expand Up @@ -51,6 +55,7 @@ bool CCheevos::GenerateHashFromFile(char* hash, int consoleID, const char* fileP

bool CCheevos::GetGameIDUrl(char* url, size_t size, const char* hash)
{
m_hash = hash;
return rc_url_get_gameid(url, size, hash) == 0;
}

Expand All @@ -72,6 +77,8 @@ bool CCheevos::PostRichPresenceUrl(char* url,
unsigned gameID,
const char* richPresence)
{
m_username = username;
m_token = token;
return rc_url_ping(url, urlSize, postData, postSize, username, token, gameID, richPresence) >= 0;
}

Expand All @@ -91,6 +98,79 @@ void CCheevos::EvaluateRichPresence(char* evaluation, size_t size)
rc_evaluate_richpresence(m_richPresence, evaluation, size, PeekInternal, this, NULL);
}

void CCheevos::ActivateAchievement(unsigned cheevo_id, const char* memaddr) //1
{
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.
}

bool CCheevos::AwardAchievement(char* url,
size_t size,
const char* username,
const char* token,
unsigned cheevo_id,
int hardcore,
const char* game_hash)
{

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, unsigned cheevo_id))
{
kodi::Log(ADDON_LOG_ERROR, "Fine till nowwwww in Callback");
Callback(url, m_cheevo_id);
return true;
}

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;
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 = 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);
}
else
{
kodi::Log(ADDON_LOG_ERROR,
"Means function is running fine though achievement is not triggered");
printf("%u", runtime_event->id);
printf("%u", 1);
const char* b = &runtime_event->type;
kodi::Log(ADDON_LOG_ERROR, b);

}
kodi::Log(ADDON_LOG_ERROR, "Runtime Event Handler function is called");
}

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

unsigned int CCheevos::PeekInternal(unsigned address, unsigned num_bytes, void* ud)
{
CCheevos* cheevos = static_cast<CCheevos*>(ud);
Expand Down
22 changes: 22 additions & 0 deletions src/cheevos/Cheevos.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,22 @@ class CCheevos
const char* richPresence);
void EnableRichPresence(const char* script);
void EvaluateRichPresence(char* evaluation, size_t size);
void ActivateAchievement(unsigned cheevo_id, const char* memaddr);
bool AwardAchievement(char* url,
size_t size,
const char* username,
const char* token,
unsigned cheevo_id,
int hardcore,
const char* game_hash);
void DeactivateTriggeredAchievement(unsigned cheevo_id);
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, 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 @@ -59,5 +74,12 @@ class CCheevos
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;
};
}
58 changes: 58 additions & 0 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ GAME_ERROR CGameLibRetro::RunFrame()
m_clientBridge.FrameTime(delta);

m_client.retro_run();
TestAchievementPerFrame();

CLibretroEnvironment::Get().OnFrameEnd();

Expand Down Expand Up @@ -523,6 +524,63 @@ GAME_ERROR CGameLibRetro::GetRichPresenceEvaluation(char* evaluation, size_t siz
return GAME_ERROR_NO_ERROR;
}

GAME_ERROR CGameLibRetro::ActivateAchievement(unsigned cheevo_id, const char* memaddr)
{
CCheevos::Get().ActivateAchievement(cheevo_id, memaddr);
return GAME_ERROR_NO_ERROR;
}


GAME_ERROR CGameLibRetro::GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id))
{
if (!CCheevos::Get().GetCheevo_ID(Callback))
{
return GAME_ERROR_FAILED;
}

return GAME_ERROR_NO_ERROR();
}

GAME_ERROR CGameLibRetro::AwardAchievement(char* url,
size_t size,
const char* username,
const char* token,
unsigned cheevo_id,
int hardcore,
const char* game_hash)
{
if (!CCheevos::Get().AwardAchievement(url, size, username, token, cheevo_id, hardcore, game_hash))
{
return GAME_ERROR_FAILED;
}
return GAME_ERROR_NO_ERROR;
}

/* GAME_ERROR CGameLibRetro::RuntimeEventHandler(char* url,
size_t size,
const char* username,
const char* token,
unsigned id,
unsigned cheevo_id,
int hardcore,
const char* game_hash)
{
return GAME_ERROR_NO_ERROR;
}
*/
GAME_ERROR CGameLibRetro::DeactivateTriggeredAchievement(unsigned cheevo_id)
{
CCheevos::Get().DeactivateTriggeredAchievement(cheevo_id);
return GAME_ERROR_NO_ERROR;
}


GAME_ERROR CGameLibRetro::TestAchievementPerFrame()
{
CCheevos::Get().TestAchievementPerFrame();
return GAME_ERROR_NO_ERROR;
}

GAME_ERROR CGameLibRetro::RCResetRuntime()
{
CCheevos::Get().ResetRuntime();
Expand Down
12 changes: 12 additions & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,19 @@ class ATTRIBUTE_HIDDEN CGameLibRetro
const char* richPresence) override;
GAME_ERROR EnableRichPresence(const char* script) override;
GAME_ERROR GetRichPresenceEvaluation(char* evaluation, size_t size) override;
GAME_ERROR ActivateAchievement(unsigned cheevo_id, const char* memaddr) override;
GAME_ERROR AwardAchievement(char* url,
size_t size,
const char* username,
const char* token,
unsigned cheevo_id,
int hardcore,
const char* game_hash) override;
GAME_ERROR DeactivateTriggeredAchievement(unsigned cheevo_id) override;
GAME_ERROR TestAchievementPerFrame() override;
GAME_ERROR RCResetRuntime() override;
GAME_ERROR GetCheevo_ID(void (*Callback)(char* achievement_url, unsigned cheevo_id)) override;
//GAME_ERROR RCResetRuntime() override;

private:
GAME_ERROR AudioAvailable();
Expand Down

0 comments on commit 693d4aa

Please sign in to comment.