https://github.com/butr/bannerlord.discordrichpresence
Adds support for Discord Rich Presence.
https://github.com/butr/bannerlord.discordrichpresence
bannerlord bannerlord-mod library mod mount-and-blade-bannerlord
Last synced: 9 days ago
JSON representation
Adds support for Discord Rich Presence.
- Host: GitHub
- URL: https://github.com/butr/bannerlord.discordrichpresence
- Owner: BUTR
- Created: 2022-11-27T09:01:31.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2025-04-22T21:27:22.000Z (30 days ago)
- Last Synced: 2025-05-08T03:52:28.909Z (15 days ago)
- Topics: bannerlord, bannerlord-mod, library, mod, mount-and-blade-bannerlord
- Language: C#
- Homepage: https://www.nexusmods.com/mountandblade2bannerlord/mods/4836
- Size: 155 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- Support: supported-game-versions.txt
Awesome Lists containing this project
README
# Bannerlord.DiscordRichPresence
Adds Discord Rich Presence support for the game! Inspired by one of the first mods on NexusMods, [Discord RP for Bannerlord](https://github.com/TheDoctorOne/Discord-Rich-Presence-for-Bannerlord)!
Full translation support as expected from BUTR mods!
Settings are available via MCM!You can also enable mod sharing in Options that will add a fancy button on the bottom of your profile, opening it will give you an URL in format `https://modlist.butr.link/d29ee27c-5f08-4a53-b4ae-231a76d5e404` that will contain your game version and the list of enabled mods! The url will be available for 8 hour since the start of your game!
Some commentary about this feature. At the start of the game when the option is enabled or when saving with the enabled option, the module will send to `https://modlist.butr.link` the game version and the mod list and obtain a link that lives 8 hours that will show you the info. This is done this way because Discord has a limit on the URL length and we can't put the info inside the URL via the query params, so we have a quick lived backend server that stores this info.
Because the Module is open-sourced, even if our server dies after some years, we have the [backend available](https://github.com/BUTR/BUTR.ModListServer) for anyone to host and setup the module again with the feature!The game supports basic states:
* Main Menu
* Loading
* Custom Battles
* Campaign:
* Traveling near a settlement
* Conversation with someone
* At Settlement
* In Settlement (Mission)
* In Battle (simulation and not) with troop count. Attacking/Defending. Raid, Siege, Forcing* are all supported## For Modders
Other mods can use this module to set their own presence:
Note that you can use this code even if `Bannerlord.DiscordRichPresence` is not enabled by user, the actions will be skipped.
### ButterLib's DynamicAPI
```csharp
internal static class DiscordRichPresenceAPI
{
private static readonly Action? SetPresenceMethod =
DynamicAPIProvider.RequestAPIMethod>("Bannerlord.DiscordRichPresence", "SetPresence");
private static readonly Action? SetPreviousPresenceMethod =
DynamicAPIProvider.RequestAPIMethod>("Bannerlord.DiscordRichPresence", "SetPreviousPresence");public static void SetPresence(string details, DateTime? start, DateTime? end)
{
if (SetPresenceMethod != null)
{
SetPresenceMethod(details, start, end, true);
}
}
public static void SetPreviousPresence()
{
if (SetPreviousPresenceMethod != null)
{
SetPreviousPresence(true);
}
}
}
```
### Reflection and Harmony
```csharp
internal static class DiscordRichPresenceAPI
{
private static readonly Action? SetPresenceMethod =
AccessTools.Method("Bannerlord.DiscordRichPresence.DynamicAPI:SetPresence") is { } method
? AccessTools.MethodDelegate>(method)
: null;
private static readonly Action? SetPreviousPresenceMethod =
AccessTools.Method("Bannerlord.DiscordRichPresence.DynamicAPI:SetPreviousPresence") is { } method
? AccessTools.MethodDelegate>(method)
: null;public static void SetPresence(string details, DateTime? start, DateTime? end)
{
if (SetPresenceMethod != null)
{
SetPresenceMethod(details, start, end, true);
}
}
public static void SetPreviousPresence()
{
if (SetPreviousPresenceMethod != null)
{
SetPreviousPresence(true);
}
}
}
```