Skip to content

Commit f8a3e62

Browse files
committed
Fix crashes on macOS and Linux
1 parent b615fca commit f8a3e62

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

LobbyHelper.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.CelesteNet.Client.Components;
2+
using Celeste.Mod.CelesteNet.DataTypes;
23
using Celeste.Mod.CollabUtils2.UI;
34
using Celeste.Mod.UI;
45
using Mono.Cecil;
@@ -38,7 +39,7 @@ internal static void OnInitialize() {
3839
}
3940

4041
if (Everest.Loader.DependencyLoaded(new EverestModuleMetadata() { Name = "CelesteNet.Client", Version = new Version(2, 0, 0) })) {
41-
adjustCollabIcon();
42+
setupAdjustCollabIcon();
4243
}
4344
}
4445

@@ -147,6 +148,8 @@ internal static void Load() {
147148
hookOnOuiJournalPoemLines = new ILHook(typeof(OuiJournalPoem).GetNestedType("PoemLine", BindingFlags.NonPublic).GetMethod("Render"), modJournalPoemHeartColors);
148149
hookOnOuiFileSelectSlotGolden = new ILHook(typeof(OuiFileSelectSlot).GetMethod("get_Golden", BindingFlags.NonPublic | BindingFlags.Instance), modSelectSlotCollectedStrawberries);
149150
hookOnOuiFileSelectSlotRender = new ILHook(typeof(OuiFileSelectSlot).GetMethod("orig_Render"), modOuiFileSelectSlotRender);
151+
152+
On.Monocle.Commands.ProcessMethod += onCommandLookupInMethod;
150153
}
151154

152155
internal static void Unload() {
@@ -172,10 +175,36 @@ internal static void Unload() {
172175
hookOnOuiJournalPoemLines?.Dispose();
173176
hookOnOuiFileSelectSlotGolden?.Dispose();
174177
hookOnOuiFileSelectSlotRender?.Dispose();
178+
179+
On.Monocle.Commands.ProcessMethod -= onCommandLookupInMethod;
180+
181+
if (Everest.Loader.DependencyLoaded(new EverestModuleMetadata() { Name = "CelesteNet.Client", Version = new Version(2, 0, 0) })) {
182+
teardownAdjustCollabIcon();
183+
}
184+
}
185+
186+
// TODO: this hook should be moved to Everest, I'm probably not the only one wanting to do optional dependencies like that
187+
188+
private static void onCommandLookupInMethod(On.Monocle.Commands.orig_ProcessMethod orig, Monocle.Commands self, MethodInfo method) {
189+
try {
190+
orig(self, method);
191+
} catch (Exception e) {
192+
// we probably met a method with some missing optional dependency, so just skip it.
193+
Logger.Log(LogLevel.Warn, "commands", "Could not look for custom commands in method " + method.Name);
194+
e.LogDetailed();
195+
}
196+
}
197+
198+
private static void setupAdjustCollabIcon() {
199+
CelesteNetPlayerListComponent.OnGetState += CelesteNet.adjustCollabIcon;
175200
}
176201

177-
private static void adjustCollabIcon() {
178-
CelesteNetPlayerListComponent.OnGetState += (blob, state) => {
202+
private static void teardownAdjustCollabIcon() {
203+
CelesteNetPlayerListComponent.OnGetState -= CelesteNet.adjustCollabIcon;
204+
}
205+
206+
private class CelesteNet {
207+
internal static void adjustCollabIcon(CelesteNetPlayerListComponent.BlobPlayer blob, DataPlayerState state) {
179208
// if we are in a collab map, change the icon displayed in the CelesteNet player list to the lobby icon.
180209
AreaData data = AreaData.Get(state.SID);
181210
if (data != null) {
@@ -184,7 +213,7 @@ private static void adjustCollabIcon() {
184213
blob.Location.Icon = AreaData.Get(lobbySID)?.Icon ?? blob.Location.Icon;
185214
}
186215
}
187-
};
216+
}
188217
}
189218

190219
public static void OnSessionCreated() {

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.6.2
2+
Version: 1.6.3
33
DLL: bin/Debug/net452/CollabUtils2.dll
44
Dependencies:
55
- Name: Everest

0 commit comments

Comments
 (0)