C# Library to integrate a standalone client with RetroAchievements.
Target Frameworks: .NET 5.0, .NET 6.0, .NET 7.0, .NET 8.0, .NET 9.0
Unit tests are located at RASharpIntegration Tests.
-
Add this repository as a submodule to your C# project.
-
Add
using RASharpIntegration.Networkto a C# file. -
Create a
RequestHeaderand populate it with the required information (host,game,hardcore). -
Create an
HttpClientto make requests with. Set a User Agent that RA will accept. Example:
HttpClient _client;
_client.DefaultRequestHeaders.Add("User-Agent", $"{ClientName}/{Version}");- Call the static methods within
NetworkInterfaceto make requests to the RA host. Example:
private async Task Login(string user, string pass)
{
_header.user = user;
MessageUtil.Log($"Logging in {user} to {_header.host}...");
ApiResponse<LoginResponse> api = await NetworkInterface.TryLogin(_client, _header, pass);
if (!string.IsNullOrEmpty(api.Failure))
{
MessageUtil.Log($"Unable to login ({api.Failure})");
return;
}
if (!api.Response.Success)
{
MessageUtil.Log($"Unable to login ({api.Response.Error})");
return;
}
_header.token = api.Response.Token;
CacheCredentials();
MessageUtil.Log($"{user} has successfully logged in!");
StartSessionCommand.Invoke(this, null);
}