From f8316451bf35da83a52860af65bc860fa6f5661e Mon Sep 17 00:00:00 2001 From: InfernalSkys <37850708+InfernalSkys@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:41:34 +0300 Subject: [PATCH] Update SearchAndDestroy (#491) Update to make the patch work with the unofficial continuation of the mod since the original appears to be abandoned --- Source/Mods/SearchAndDestroy.cs | 46 ++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/Source/Mods/SearchAndDestroy.cs b/Source/Mods/SearchAndDestroy.cs index b52f2e70..092fac9b 100644 --- a/Source/Mods/SearchAndDestroy.cs +++ b/Source/Mods/SearchAndDestroy.cs @@ -5,36 +5,46 @@ namespace Multiplayer.Compat { - /// Search and Destroy by Roolo - /// - /// - [MpCompatFor("roolo.SearchAndDestroy")] + /// Search and Destroy updated mod by MemeGoddess + /// + /// + [MpCompatFor("MemeGoddess.SearchAndDestroy")] public class SearchAndDestroy { - // Base class + // Fields for accessing private data structures private static FastInvokeHandler searchAndDestroyInstance; private static AccessTools.FieldRef extendedDataStorageField; - - // ExtendedDataStorage class private static AccessTools.FieldRef storeField; public SearchAndDestroy(ModContentPack mod) { - var type = AccessTools.TypeByName("SearchAndDestroy.Harmony.Pawn_DraftController_GetGizmos"); - - MpCompat.RegisterLambdaDelegate(type, "CreateGizmo_SearchAndDestroy_Melee", 1); - MpCompat.RegisterLambdaDelegate(type, "CreateGizmo_SearchAndDestroy_Ranged", 1); + // Register the gizmo creation methods to synchronize their actions across clients + MpCompat.RegisterLambdaDelegate( + "SearchAndDestroy.Harmony.Pawn_DraftController_GetGizmos", + "CreateGizmo_SearchAndDestroy_Melee", + 1 + ); + MpCompat.RegisterLambdaDelegate( + "SearchAndDestroy.Harmony.Pawn_DraftController_GetGizmos", + "CreateGizmo_SearchAndDestroy_Ranged", + 1 + ); - type = AccessTools.TypeByName("SearchAndDestroy.Base"); - searchAndDestroyInstance = MethodInvoker.GetHandler(AccessTools.PropertyGetter(type, "Instance")); - extendedDataStorageField = AccessTools.FieldRefAccess(type, "_extendedDataStorage"); + // Register a SyncWorker for ExtendedPawnData to synchronize custom data + var extendedPawnDataType = AccessTools.TypeByName("SearchAndDestroy.Storage.ExtendedPawnData"); + MP.RegisterSyncWorker(SyncExtendedPawnData, extendedPawnDataType); - type = AccessTools.TypeByName("SearchAndDestroy.Storage.ExtendedPawnData"); - MP.RegisterSyncWorker(SyncExtendedPawnData, type); + // Initialize reflection accessors for private fields and properties + var baseType = AccessTools.TypeByName("SearchAndDestroy.Base"); + searchAndDestroyInstance = MethodInvoker.GetHandler(AccessTools.PropertyGetter(baseType, "Instance")); + extendedDataStorageField = AccessTools.FieldRefAccess(baseType, "_extendedDataStorage"); - storeField = AccessTools.FieldRefAccess("SearchAndDestroy.Storage.ExtendedDataStorage:_store"); + storeField = AccessTools.FieldRefAccess( + "SearchAndDestroy.Storage.ExtendedDataStorage:_store" + ); } + // SyncWorker method to synchronize ExtendedPawnData across clients public static void SyncExtendedPawnData(SyncWorker sync, ref object pawnData) { var instance = searchAndDestroyInstance(null); @@ -66,4 +76,4 @@ public static void SyncExtendedPawnData(SyncWorker sync, ref object pawnData) } } } -} \ No newline at end of file +}