Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RetroAchievements Memory, Events, and Awarding #11763

Conversation

LillyJadeKatrin
Copy link
Contributor

This is a portion of an integration with the RetroAchievements tools and libraries for connecting to the website, downloading data, unlocking achievements and submitting to leaderboards for games running in Dolphin. In this PR, the AchievementsManager created in a previous PR is further implemented to peek into game memory, process that within the rcheevos library, and handle achievement events that occur, resulting in the API calls to award achievements, submit scores/times to leaderboards, and generate and post Rich Presence for the currently played game.

Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.h Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.h Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.h Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Show resolved Hide resolved
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 5 times, most recently from 26da2e8 to b5ec51e Compare April 19, 2023 23:17
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/Core.cpp Outdated Show resolved Hide resolved
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 4 times, most recently from 0b3dd96 to 63c6361 Compare April 20, 2023 03:54
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 3 times, most recently from 4dbb66e to a7fbcaf Compare April 23, 2023 22:42
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
Source/Core/Core/AchievementManager.cpp Outdated Show resolved Hide resolved
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 2 times, most recently from 49d9b11 to 5135d60 Compare April 29, 2023 05:04
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 2 times, most recently from 0a3926c to a7092c6 Compare May 5, 2023 02:07
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch 3 times, most recently from 736f9bb to 42e1485 Compare May 11, 2023 00:38
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch from 42e1485 to 0d18fa0 Compare May 11, 2023 00:55
AwardAchievement performs the API call to notify the site that an achievement has been unlocked. As one of the parameters is the game hash (something I overlooked previously; I thought it was the game ID) this change also moves the game hash into a member field.
SubmitLeaderboard submits the player's score/time to a leaderboard on the website via an API call.
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch from 0d18fa0 to 264e09b Compare May 11, 2023 01:16
PingRichPresence makes a "ping" API request to the RetroAchievements website with the provided RichPresence string parameter. While there has been talk about tying ping in with session, in its current state the primary purpose of ping is to send the player's Rich Presence to the website.
HandleAchievementTriggeredEvent is an asynchronous method that processes an event and places a synchronous AwardAchievement call on the work queue. In the process, it also updates the unlock map and makes the ActivateDeactivateAchievement call to determine and adjust the achievement's current active state.
HandleLeaderboardTriggeredEvent processes a leaderboard event and asynchronizes via the work queue a synchronous call to SubmitLeaderboard.
AchievementEventHandler simply checks which kind of event is triggered and calls the appropriate function. Its primary purpose is as a function to be pointed to.
MemoryPeeker is a function passed by pointer into rcheevos DoFrame functionality that forms the lynchpin of the rcheevos runtime - it provides the interface by which rcheevos accesses memory and determines if the fields provided by achievement, leaderboard, and rich presence definitions are meeting the criteria needed.
GenerateRichPresence calls rc_runtime_get_richpresence in rhceevos on the achievement runtime to get the current Rich Presence string, a description of the player's current in-game state based on its memory as fed into a custom-developed script downloaded via FetchGameData. This gets passed into PingRichPresence, but is separated into its own method so it can be used elsewhere locally.
DoFrame is a function called every frame by the emulator so that rcheevos can be properly updated and processed. It requires a memory peeker and an event handler to be passed in; the memory peeker is called repeatedly each frame to measure what's in memory and compare to achievement definitions, and any events thrown by that comparison are sent to the event handler.

Also, DoFrame checks for the current system time to determine when to ping rich presence. Rich Presence on the RetroAchievements website updates every two minutes, so if two minutes have elapsed since the previous ping, another ping is sent.
@LillyJadeKatrin LillyJadeKatrin force-pushed the retroachievements-memory-events branch from 264e09b to c9c2e17 Compare May 11, 2023 11:56
@AdmiralCurtiss AdmiralCurtiss merged commit ef95d94 into dolphin-emu:master May 21, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants