From 3006bab9cd86bb56f8b7a7a76e9648c84387e52b Mon Sep 17 00:00:00 2001 From: Terkoiz Date: Tue, 9 Jul 2024 00:08:59 +0300 Subject: [PATCH] Updated for SPT 3.9.0 + fix for multiple squad members triggering multiple notifications --- .gitignore | 1 + project/References/SPT/.keep | 0 .../FlareEventHookPatch.cs | 34 ++++++++++++++++--- .../FlareEventNotifierPlugin.cs | 2 +- .../Terkoiz.FlareEventNotifier.csproj | 4 +-- 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 project/References/SPT/.keep diff --git a/.gitignore b/.gitignore index c6a0c3b..8a854e4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ project/References/EFT_Managed/* # Allow these files, despite the rules above !project/References/EFT_Managed/.keep +!project/References/SPT/.keep # ---> VisualStudio ## Ignore Visual Studio temporary files, build results, and diff --git a/project/References/SPT/.keep b/project/References/SPT/.keep new file mode 100644 index 0000000..e69de29 diff --git a/project/Terkoiz.FlareEventNotifier/FlareEventHookPatch.cs b/project/Terkoiz.FlareEventNotifier/FlareEventHookPatch.cs index cdacee4..0060eb2 100644 --- a/project/Terkoiz.FlareEventNotifier/FlareEventHookPatch.cs +++ b/project/Terkoiz.FlareEventNotifier/FlareEventHookPatch.cs @@ -1,7 +1,8 @@ using System; using System.Linq; using System.Reflection; -using Aki.Reflection.Patching; +using Comfort.Common; +using SPT.Reflection.Patching; using EFT; using EFT.Communications; using EFT.PrefabSettings; @@ -23,17 +24,25 @@ namespace Terkoiz.FlareEventNotifier } [PatchPrefix] - public static void PatchPrefix(FlareEventType flareType, EZoneEventTypeEnumClone eventType) + public static void PatchPrefix(FlareEventType flareType, EZoneEventTypeEnumClone eventType, string playerProfileID) { if (flareType != FlareEventType.ExitActivate) { return; } - if (eventType == EZoneEventTypeEnumClone.FiredPlayerAddedInShotList || eventType == EZoneEventTypeEnumClone.PlayerByPartyAddedInShotList) + if (eventType != EZoneEventTypeEnumClone.FiredPlayerAddedInShotList && eventType != EZoneEventTypeEnumClone.PlayerByPartyAddedInShotList) { - NotificationManagerClass.DisplayNotification(new ExfilFlareSuccessNotification()); + return; } + + var localPlayer = GetLocalPlayerFromWorld(); + if (localPlayer != null && localPlayer.ProfileId != playerProfileID) + { + return; + } + + NotificationManagerClass.DisplayNotification(new ExfilFlareSuccessNotification()); } /// @@ -47,9 +56,24 @@ namespace Terkoiz.FlareEventNotifier FiredPlayerAddedInShotList, PlayerByPartyAddedInShotList } + + /// + /// Gets the current instance if it's available + /// + /// Local instance; returns null if the game is not in raid + private static Player GetLocalPlayerFromWorld() + { + var gameWorld = Singleton.Instance; + if (gameWorld == null || gameWorld.MainPlayer == null) + { + return null; + } + + return gameWorld.MainPlayer; + } } - public class ExfilFlareSuccessNotification : NotificationClass + public class ExfilFlareSuccessNotification : NotificationAbstractClass { public ExfilFlareSuccessNotification() { diff --git a/project/Terkoiz.FlareEventNotifier/FlareEventNotifierPlugin.cs b/project/Terkoiz.FlareEventNotifier/FlareEventNotifierPlugin.cs index ddde4d8..23e0c18 100644 --- a/project/Terkoiz.FlareEventNotifier/FlareEventNotifierPlugin.cs +++ b/project/Terkoiz.FlareEventNotifier/FlareEventNotifierPlugin.cs @@ -3,7 +3,7 @@ using JetBrains.Annotations; namespace Terkoiz.FlareEventNotifier { - [BepInPlugin("com.terkoiz.flareeventnotifier", "Terkoiz.FlareEventNotifier", "1.0.1")] + [BepInPlugin("com.terkoiz.flareeventnotifier", "Terkoiz.FlareEventNotifier", "1.0.2")] public class FlareEventNotifierPlugin : BaseUnityPlugin { [UsedImplicitly] diff --git a/project/Terkoiz.FlareEventNotifier/Terkoiz.FlareEventNotifier.csproj b/project/Terkoiz.FlareEventNotifier/Terkoiz.FlareEventNotifier.csproj index 804997d..20a9de9 100644 --- a/project/Terkoiz.FlareEventNotifier/Terkoiz.FlareEventNotifier.csproj +++ b/project/Terkoiz.FlareEventNotifier/Terkoiz.FlareEventNotifier.csproj @@ -2,7 +2,7 @@ net472 - 1.0.1 + 1.0.2 Terkoiz https://dev.sp-tarkov.com/Terkoiz/FlareEventNotifier NCSA @@ -16,7 +16,7 @@ - ..\References\EFT_Managed\Aki.Reflection.dll + ..\References\SPT\spt-reflection.dll False