League-of-legends – How does League Replays work

league-of-legends

How does League Replays (unofficial) record full League games using such little CPU?

Please don't shy away from the technical details!

Best Answer

To the best of my knowledge, the League Replay software operates in the following manner.

During the game, LOLRecorder.exe uses the Riot API to find the game ID and other identifying information such as the region, and then starts a new connection with the riot servers in the background as a spectator of your current game. It then captures the network traffic from the server while observing your game and saves that traffic to a file along with metadata about the game (e.g. which champion the recording player was using, the game length, win/loss, etc). The format of this data is unknown to me, but it is stored in a way that LoLReplay can understand and later playback.

When you replay a recorded file, LoLReplay starts a server on your local machine which will playback the data in the recorded file and launches the standard LOL Client with instructions to spectate a game and to connect to that local server (rather than a Riot server). You can actually verify this by starting a replay and then checking the details of the 'Leageue Of Legends.exe' process. You'll see something like:

"League Of Legends.exe" "8391" "" "" "spectator localhost amplm2hJqLumnptJE6YNXDWlLZ1r2aIT 1054272266 NA"

You can see the parameter referring to "spectate localhost ...." which instructs the LOL client to make a loopback connection to the LoLReplay program itself.

To answer the secondary part of your question, "how does it use such little CPU", it's because it's simple streaming the information from the Riot Games Server about the spectated match directly to a file. The data itself is not very large (maybe 15MB for a 60 minute game, which averages out to 4 Kb/s) and LoLReplay doesn't need to process this data in any way whatsoever, it simply has to save the data. These two factors mean that LoLReplay can operate in the background quite easily without impacting your game!


This answer provides a technical overview of how the LoLReplay application works, but there are many more details and nuances that I haven't mentioned here or simply don't know. For instance, the application was much more complex before Riot introduced the ability to Spectate games (LoLRecorder had to capture the network traffic containing the outgoing commands of the player as well as the incoming traffic of the game state from the server, and then launch the local server and replay the players commands to itself while also running the normal Riot Games LOL Client against this local server. It was glitchy, to say the least, but it worked!).

If you want to explore more, you could grab a free demo of Red Gate's .NET Reflector and take a look at the source code of LoLRecorder.exe or LoLReplay.exe!