Skip to content

Commit

Permalink
Update SearchAndDestroy (#491)
Browse files Browse the repository at this point in the history
Update to make the patch work with the unofficial continuation of the mod since the original appears to be abandoned
  • Loading branch information
InfernalSkys authored Oct 26, 2024
1 parent c7a46f2 commit f831645
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions Source/Mods/SearchAndDestroy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,46 @@

namespace Multiplayer.Compat
{
/// <summary>Search and Destroy by Roolo</summary>
/// <see href="https://github.com/rheirman/SearchAndDestroy"/>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=1467764609"/>
[MpCompatFor("roolo.SearchAndDestroy")]
/// <summary>Search and Destroy updated mod by MemeGoddess</summary>
/// <see href="https://github.com/MemeGoddess/SearchAndDestroy"/>
/// <see href="https://steamcommunity.com/sharedfiles/filedetails/?id=3232242247"/>
[MpCompatFor("MemeGoddess.SearchAndDestroy")]
public class SearchAndDestroy
{
// Base class
// Fields for accessing private data structures
private static FastInvokeHandler searchAndDestroyInstance;
private static AccessTools.FieldRef<object, object> extendedDataStorageField;

// ExtendedDataStorage class
private static AccessTools.FieldRef<object, IDictionary> 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<object>(type, "_extendedDataStorage");
// Register a SyncWorker for ExtendedPawnData to synchronize custom data
var extendedPawnDataType = AccessTools.TypeByName("SearchAndDestroy.Storage.ExtendedPawnData");
MP.RegisterSyncWorker<object>(SyncExtendedPawnData, extendedPawnDataType);

type = AccessTools.TypeByName("SearchAndDestroy.Storage.ExtendedPawnData");
MP.RegisterSyncWorker<object>(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<object>(baseType, "_extendedDataStorage");

storeField = AccessTools.FieldRefAccess<IDictionary>("SearchAndDestroy.Storage.ExtendedDataStorage:_store");
storeField = AccessTools.FieldRefAccess<IDictionary>(
"SearchAndDestroy.Storage.ExtendedDataStorage:_store"
);
}

// SyncWorker method to synchronize ExtendedPawnData across clients
public static void SyncExtendedPawnData(SyncWorker sync, ref object pawnData)
{
var instance = searchAndDestroyInstance(null);
Expand Down Expand Up @@ -66,4 +76,4 @@ public static void SyncExtendedPawnData(SyncWorker sync, ref object pawnData)
}
}
}
}
}

0 comments on commit f831645

Please sign in to comment.