Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Source/Mods/WhatTheHack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Multiplayer.Compat
[MpCompatFor("roolo.whatthehack")]
class WhatTheHack
{
private static Dictionary<int, Thing> thingsById;

private static object extendedDataStorageInstance; // WorldComponent
private static AccessTools.FieldRef<object, IDictionary> pawnStorageDictionary;
private static MethodInfo getExtendedDataForPawnMethod;
Expand All @@ -26,8 +24,6 @@ class WhatTheHack

public WhatTheHack(ModContentPack mod)
{
thingsById = (Dictionary<int, Thing>)AccessTools.Field(AccessTools.TypeByName("Multiplayer.Client.ThingsById"), "thingsById").GetValue(null);

// Setup
{
// Base mod class
Expand Down Expand Up @@ -147,7 +143,7 @@ private static void SyncExtendedPawnData(SyncWorker sync, ref object data)
{
var id = sync.Read<int>();

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 });
}
}
Expand Down
8 changes: 2 additions & 6 deletions Source_Referenced/SaveOurShip2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ internal class SaveOurShip2
private static AccessTools.FieldRef<object, Building_ShipBridge> toggleShieldParentClassField;
private static object bridgeInnerClassStaticField;

private static Dictionary<int, Thing> thingsById;

public SaveOurShip2(ModContentPack mod) => LongEventHandler.ExecuteWhenFinished(LatePatch);

private static void LatePatch()
{
thingsById = (Dictionary<int, Thing>)AccessTools.Field(AccessTools.TypeByName("Multiplayer.Client.ThingsById"), "thingsById").GetValue(null);

// Ship bridge
{
// Launching ship
Expand Down Expand Up @@ -322,8 +318,8 @@ private static void SyncedSelectTarget(List<Building_ShipTurret> 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);
Expand Down