Skip to content

Commit

Permalink
Update and fix cache clearing, fixes #446 (#448)
Browse files Browse the repository at this point in the history
`Multiplayer.Client.ImplSerialization:Init` caches different (and more) stuff now. The data that we needed to re-cache (list of ISyncSimple implementations and since recently Session subclasses) is now handled in `Multiplayer.Client.ApiSerialization`.

On top of that, I've also added clearing of `subClassesOrdered` dictionary in `Multiplayer.Client.Util.TypeCache` to clear all the dictionaries before re-caching (as it was the only one that wasn't cleared, which I assume was due to it being added to MP after the cache clearing was made here).
  • Loading branch information
SokyranTheDragon authored Jun 9, 2024
1 parent becce73 commit a985d5c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Source/MpCompatLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ static void ClearCaches()
// GenTypes.ClearCache() on its own won't work, as MP isn't doing anything when it's called.
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, "subClassesOrdered").GetValue(null)).Clear();
((IDictionary)AccessTools.Field(mpType, "subClassesNonAbstract").GetValue(null)).Clear();
((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, []);
// Clear/re-init the list of ISyncSimple implementations and Session subclasses.
AccessTools.Method("Multiplayer.Client.ApiSerialization: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, []);
}
Expand Down

0 comments on commit a985d5c

Please sign in to comment.