Skip to content

Commit e47549d

Browse files
committed
Update Discord Game SDK code to target the new stable Everest only
1 parent a351dc9 commit e47549d

File tree

6 files changed

+7
-36
lines changed

6 files changed

+7
-36
lines changed

LobbyHelper.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public static class LobbyHelper {
2929
private static ILHook hookOnLevelSetSwitch;
3030
private static ILHook hookOnOuiFileSelectSlotRender;
3131

32-
// TODO: replace this with On.Celeste once Discord Game SDK reached stable
33-
private static Hook hookDiscordGameSDKIcon;
34-
3532
private static HashSet<string> collabNames = new HashSet<string>();
3633

3734
internal static void OnInitialize() {
@@ -196,11 +193,7 @@ internal static void Load() {
196193
hookOnOuiFileSelectSlotGolden = new ILHook(typeof(OuiFileSelectSlot).GetMethod("get_Golden", BindingFlags.NonPublic | BindingFlags.Instance), modSelectSlotCollectedStrawberries);
197194
hookOnOuiFileSelectSlotRender = new ILHook(typeof(OuiFileSelectSlot).GetMethod("orig_Render"), modOuiFileSelectSlotRender);
198195

199-
MethodInfo discordRichPresence = typeof(EverestModule).Assembly.GetType("Celeste.Mod.Everest+DiscordSDK")?.GetMethod("GetMapIconURLCached", BindingFlags.NonPublic | BindingFlags.Instance);
200-
if (discordRichPresence != null) {
201-
hookDiscordGameSDKIcon = new Hook(discordRichPresence, typeof(LobbyHelper)
202-
.GetMethod("onDiscordGetPresenceIcon", BindingFlags.NonPublic | BindingFlags.Static));
203-
}
196+
On.Celeste.Mod.Everest.DiscordSDK.GetMapIconURLCached += onDiscordGetPresenceIcon;
204197

205198
typeof(ModExports).ModInterop();
206199
}
@@ -231,7 +224,7 @@ internal static void Unload() {
231224
hookOnOuiFileSelectSlotGolden?.Dispose();
232225
hookOnOuiFileSelectSlotRender?.Dispose();
233226

234-
hookDiscordGameSDKIcon?.Dispose();
227+
On.Celeste.Mod.Everest.DiscordSDK.GetMapIconURLCached -= onDiscordGetPresenceIcon;
235228

236229
if (Everest.Loader.DependencyLoaded(new EverestModuleMetadata() { Name = "CelesteNet.Client", Version = new Version(2, 0, 0) })) {
237230
teardownAdjustCollabIcon();
@@ -256,7 +249,7 @@ internal static void adjustCollabIcon(CelesteNetPlayerListComponent.BlobPlayer b
256249
}
257250
}
258251

259-
private static string onDiscordGetPresenceIcon(Func<object, AreaData, string> orig, object self, AreaData areaData) {
252+
private static string onDiscordGetPresenceIcon(On.Celeste.Mod.Everest.DiscordSDK.orig_GetMapIconURLCached orig, Everest.DiscordSDK self, AreaData areaData) {
260253
// if we are in a collab map, change the icon displayed in Discord Rich Presence to the lobby icon.
261254
string lobbySID = GetLobbyForMap(areaData.SID);
262255
if (lobbySID != null) {

UI/InGameOverworldHelper.cs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public static class InGameOverworldHelper {
4141
{ "grandmaster", Calc.HexToColor("DD87FF") }
4242
};
4343

44-
private static Hook hookOnDiscordRichPresenceChange;
45-
4644
private static bool presenceLock = false;
4745

4846
internal static void Load() {
@@ -65,20 +63,7 @@ internal static void Load() {
6563
IL.Celeste.OuiChapterPanel._FixTitleLength += ModFixTitleLength;
6664
On.Celeste.OuiMainMenu.CreateButtons += OnOuiMainMenuCreateButtons;
6765

68-
// hooks the Discord rich presence update method of stable version 3650
69-
// TODO: this should be replace with On.Celeste when this will have reached stable
70-
MethodInfo discordRichPresence = typeof(EverestModule).Assembly.GetType("Celeste.Mod.Everest+Discord")?.GetMethod("UpdateText");
71-
if (discordRichPresence != null) {
72-
hookOnDiscordRichPresenceChange = new Hook(discordRichPresence, typeof(InGameOverworldHelper)
73-
.GetMethod("OnDiscordChangePresenceOld", BindingFlags.NonPublic | BindingFlags.Static));
74-
}
75-
76-
// hooks the Discord rich presence update method of pull request https://github.com/EverestAPI/Everest/pull/543
77-
discordRichPresence = typeof(EverestModule).Assembly.GetType("Celeste.Mod.Everest+DiscordSDK")?.GetMethod("UpdatePresence", BindingFlags.NonPublic | BindingFlags.Instance);
78-
if (discordRichPresence != null) {
79-
hookOnDiscordRichPresenceChange = new Hook(discordRichPresence, typeof(InGameOverworldHelper)
80-
.GetMethod("OnDiscordChangePresenceNew", BindingFlags.NonPublic | BindingFlags.Static));
81-
}
66+
On.Celeste.Mod.Everest.DiscordSDK.UpdatePresence += OnDiscordChangePresence;
8267

8368
hookOnMapDataOrigLoad = new Hook(
8469
typeof(MapData).GetMethod("orig_Load", BindingFlags.NonPublic | BindingFlags.Instance),
@@ -129,8 +114,7 @@ internal static void Unload() {
129114
hookOnMapDataOrigLoad?.Dispose();
130115
hookOnMapDataOrigLoad = null;
131116

132-
hookOnDiscordRichPresenceChange?.Dispose();
133-
hookOnDiscordRichPresenceChange = null;
117+
On.Celeste.Mod.Everest.DiscordSDK.UpdatePresence -= OnDiscordChangePresence;
134118
}
135119

136120
private static void OnOuiChapterPanelStart(On.Celeste.OuiChapterPanel.orig_Start orig, OuiChapterPanel self, string checkpoint) {
@@ -217,14 +201,8 @@ private static void OnReloadLevel(On.Celeste.Mod.AssetReloadHelper.orig_ReloadLe
217201
orig();
218202
}
219203

220-
private static void OnDiscordChangePresenceOld(Action<string, string, Session> orig, string details, string state, Session session) {
221-
if (!presenceLock) {
222-
orig(details, state, session);
223-
}
224-
}
225-
226204

227-
private static void OnDiscordChangePresenceNew(Action<object, Session> orig, object self, Session session) {
205+
private static void OnDiscordChangePresence(On.Celeste.Mod.Everest.DiscordSDK.orig_UpdatePresence orig, Everest.DiscordSDK self, Session session) {
228206
if (!presenceLock) {
229207
orig(self, session);
230208
}

everest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
DLL: bin/Release/net452/CollabUtils2.dll
44
Dependencies:
55
- Name: Everest
6-
Version: 1.3471.0
6+
Version: 1.3847.0

lib-stripped/Celeste.exe

100644100755
78.5 KB
Binary file not shown.

lib-stripped/FNA.dll

100644100755
-83.5 KB
Binary file not shown.

lib-stripped/MMHOOK_Celeste.dll

100644100755
44 KB
Binary file not shown.

0 commit comments

Comments
 (0)