Skip to content

Commit 3c52f19

Browse files
committed
Hide chapter number from Discord Rich Presence if in a collab map
1 parent e47549d commit 3c52f19

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

LobbyHelper.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ internal static void Load() {
194194
hookOnOuiFileSelectSlotRender = new ILHook(typeof(OuiFileSelectSlot).GetMethod("orig_Render"), modOuiFileSelectSlotRender);
195195

196196
On.Celeste.Mod.Everest.DiscordSDK.GetMapIconURLCached += onDiscordGetPresenceIcon;
197+
IL.Celeste.Mod.Everest.DiscordSDK.UpdatePresence += modDiscordChangePresence;
197198

198199
typeof(ModExports).ModInterop();
199200
}
@@ -225,6 +226,7 @@ internal static void Unload() {
225226
hookOnOuiFileSelectSlotRender?.Dispose();
226227

227228
On.Celeste.Mod.Everest.DiscordSDK.GetMapIconURLCached -= onDiscordGetPresenceIcon;
229+
IL.Celeste.Mod.Everest.DiscordSDK.UpdatePresence -= modDiscordChangePresence;
228230

229231
if (Everest.Loader.DependencyLoaded(new EverestModuleMetadata() { Name = "CelesteNet.Client", Version = new Version(2, 0, 0) })) {
230232
teardownAdjustCollabIcon();
@@ -259,6 +261,24 @@ private static string onDiscordGetPresenceIcon(On.Celeste.Mod.Everest.DiscordSDK
259261
return orig(self, areaData);
260262
}
261263

264+
265+
private static void modDiscordChangePresence(ILContext il) {
266+
ILCursor cursor = new ILCursor(il);
267+
268+
if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdflda<Session>("Area"), instr => instr.MatchCall<AreaKey>("get_ChapterIndex"))) {
269+
Logger.Log("CollabUtils2/InGameOverworldHelper", $"Hiding chapter number from collab maps at {cursor.Index} in IL for DiscordSDK.UpdatePresence");
270+
271+
cursor.Emit(OpCodes.Ldarg_1);
272+
cursor.EmitDelegate<Func<int, Session, int>>((orig, session) => {
273+
if (IsCollabMap(session.Area.GetSID())) {
274+
// prevent Everest from displaying the chapter number
275+
return -1;
276+
}
277+
return orig;
278+
});
279+
}
280+
}
281+
262282
public static void OnSessionCreated() {
263283
Session session = SaveData.Instance.CurrentSession_Safe;
264284
string levelSet = GetLobbyLevelSet(session.Area.GetSID());

everest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- Name: CollabUtils2
2-
Version: 1.8.10
2+
Version: 1.8.11
33
DLL: bin/Release/net452/CollabUtils2.dll
44
Dependencies:
55
- Name: Everest

0 commit comments

Comments
 (0)