diff --git a/Source/Mods/WhatTheHack.cs b/Source/Mods/WhatTheHack.cs index f8950899..b226e98e 100644 --- a/Source/Mods/WhatTheHack.cs +++ b/Source/Mods/WhatTheHack.cs @@ -15,8 +15,6 @@ namespace Multiplayer.Compat [MpCompatFor("roolo.whatthehack")] class WhatTheHack { - private static Dictionary thingsById; - private static object extendedDataStorageInstance; // WorldComponent private static AccessTools.FieldRef pawnStorageDictionary; private static MethodInfo getExtendedDataForPawnMethod; @@ -26,8 +24,6 @@ class WhatTheHack public WhatTheHack(ModContentPack mod) { - thingsById = (Dictionary)AccessTools.Field(AccessTools.TypeByName("Multiplayer.Client.ThingsById"), "thingsById").GetValue(null); - // Setup { // Base mod class @@ -147,7 +143,7 @@ private static void SyncExtendedPawnData(SyncWorker sync, ref object data) { var id = sync.Read(); - if (id != int.MaxValue && thingsById.TryGetValue(id, out var thing) && thing is Pawn) + if (id != int.MaxValue && MP.TryGetThingById(id, out var thing) && thing is Pawn) data = getExtendedDataForPawnMethod.Invoke(extendedDataStorageInstance, new object[] { thing }); } } diff --git a/Source_Referenced/SaveOurShip2.cs b/Source_Referenced/SaveOurShip2.cs index 7cca7806..18fb2842 100644 --- a/Source_Referenced/SaveOurShip2.cs +++ b/Source_Referenced/SaveOurShip2.cs @@ -14,14 +14,10 @@ internal class SaveOurShip2 private static AccessTools.FieldRef toggleShieldParentClassField; private static object bridgeInnerClassStaticField; - private static Dictionary thingsById; - public SaveOurShip2(ModContentPack mod) => LongEventHandler.ExecuteWhenFinished(LatePatch); private static void LatePatch() { - thingsById = (Dictionary)AccessTools.Field(AccessTools.TypeByName("Multiplayer.Client.ThingsById"), "thingsById").GetValue(null); - // Ship bridge { // Launching ship @@ -322,8 +318,8 @@ private static void SyncedSelectTarget(List turrets, int id { LocalTargetInfo target; - if (id >= 0) - target = new LocalTargetInfo(thingsById.GetValueSafe(id)); + if (id >= 0 && MP.TryGetThingById(id, out var thing)) + target = new LocalTargetInfo(thing); else target = new LocalTargetInfo(cell); foreach (var turret in turrets) turret.SetTarget(target);