Skip to content

Commit

Permalink
Fix ClearCaches NPE
Browse files Browse the repository at this point in the history
Multiplayer updated and it broke cache clearing here
  • Loading branch information
notfood committed Apr 14, 2024
1 parent 776c89d commit 065f6da
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Source/MpCompatLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ static void ClearCaches()
var mpType = AccessTools.TypeByName("Multiplayer.Client.Util.TypeCache") ?? AccessTools.TypeByName("Multiplayer.Client.Multiplayer");
((IDictionary)AccessTools.Field(mpType, "subClasses").GetValue(null)).Clear();
((IDictionary)AccessTools.Field(mpType, "subClassesNonAbstract").GetValue(null)).Clear();
((IDictionary)AccessTools.Field(mpType, "implementations").GetValue(null)).Clear();
AccessTools.Method(mpType, "CacheTypeHierarchy").Invoke(null, Array.Empty<object>());
((IDictionary)AccessTools.Field(mpType, "interfaceImplementations").GetValue(null)).Clear();
((IDictionary)AccessTools.Field(mpType, "interfaceImplementationsOrdered").GetValue(null)).Clear();
AccessTools.Method(mpType, "CacheTypeHierarchy").Invoke(null, []);

// Clear/re-init the list of ISyncSimple implementations.
AccessTools.Method("Multiplayer.Client.ImplSerialization:Init").Invoke(null, Array.Empty<object>());
AccessTools.Method("Multiplayer.Client.ImplSerialization:Init").Invoke(null, []);
// Clear/re-init the localDefInfos dictionary so it contains the classes added from referenced assembly.
AccessTools.Method("Multiplayer.Client.MultiplayerData:CollectDefInfos").Invoke(null, Array.Empty<object>());
AccessTools.Method("Multiplayer.Client.MultiplayerData:CollectDefInfos").Invoke(null, []);
}
}
}

0 comments on commit 065f6da

Please sign in to comment.