From 86403242b7ca0749aab0768862c5658eb17c8cd8 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:44:20 +0100 Subject: [PATCH] Fixes the range finder locally - Also bump version --- ...CoopClientPortableRangeFinderController.cs | 59 +++++++++++++++++++ Fika.Core/Coop/Players/CoopPlayer.cs | 45 ++++++++++++++ Fika.Core/FikaPlugin.cs | 2 +- 3 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientPortableRangeFinderController.cs diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientPortableRangeFinderController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientPortableRangeFinderController.cs new file mode 100644 index 00000000..4d18ac9f --- /dev/null +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientPortableRangeFinderController.cs @@ -0,0 +1,59 @@ +using EFT; +using EFT.InventoryLogic; +using Fika.Core.Coop.Players; +using Fika.Core.Networking; + +namespace Fika.Core.Coop.ClientClasses +{ + public class CoopClientPortableRangeFinderController : PortableRangeFinderController + { + protected CoopPlayer player; + + public static CoopClientPortableRangeFinderController Create(CoopPlayer player, Item item) + { + CoopClientPortableRangeFinderController controller = smethod_6(player, item); + controller.player = player; + return controller; + } + + public override void CompassStateHandler(bool isActive) + { + base.CompassStateHandler(isActive); + UsableItemPacket packet = new(player.NetId) + { + HasCompassState = true, + CompassState = isActive + }; + player.PacketSender.SendPacket(ref packet); + } + + public override bool ExamineWeapon() + { + bool flag = base.ExamineWeapon(); + if (flag) + { + UsableItemPacket packet = new(player.NetId) + { + ExamineWeapon = true + }; + player.PacketSender.SendPacket(ref packet); + } + return flag; + } + + public override void SetAim(bool value) + { + bool isAiming = IsAiming; + base.SetAim(value); + if (IsAiming != isAiming) + { + UsableItemPacket packet = new(player.NetId) + { + HasAim = value, + AimState = isAiming + }; + player.PacketSender.SendPacket(ref packet); + } + } + } +} diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index e810c228..b1064c1b 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -312,6 +312,17 @@ public override void Proceed(MedsItemClass meds, EBodyPart bodyPart, Callback(Item item, Callback callback, bool scheduled = true) { + if (item is PortableRangeFinderItemClass) + { + PortableRangeFinderControllerHandler rangeFinderHandler = new(this, item); + + Func rangeFinderFunc = new(rangeFinderHandler.ReturnController); + rangeFinderHandler.process = new(this, rangeFinderFunc, item, false); + rangeFinderHandler.confirmCallback = new(rangeFinderHandler.SendPacket); + rangeFinderHandler.process.method_0(new(rangeFinderHandler.HandleResult), callback, scheduled); + return; + } + UsableItemControllerHandler handler = new(this, item); Func func = new(handler.ReturnController); @@ -1469,6 +1480,40 @@ internal void HandleResult(IResult result) } } + private class PortableRangeFinderControllerHandler(CoopPlayer coopPlayer, Item item) + { + private readonly CoopPlayer coopPlayer = coopPlayer; + private readonly Item item = item; + public Process process; + public Action confirmCallback; + + internal CoopClientPortableRangeFinderController ReturnController() + { + return CoopClientPortableRangeFinderController.Create(coopPlayer, item); + } + + internal void SendPacket() + { + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() + { + Type = ECommonSubPacketType.Proceed, + SubPacket = new ProceedPacket() + { + ProceedType = EProceedType.UsableItem, + ItemId = item.Id + } + }); + } + + internal void HandleResult(IResult result) + { + if (result.Succeed) + { + confirmCallback(); + } + } + } + private class QuickUseItemControllerHandler(CoopPlayer coopPlayer, Item item) { private readonly CoopPlayer coopPlayer = coopPlayer; diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index 6b11cb06..63029ffa 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -50,7 +50,7 @@ namespace Fika.Core [BepInDependency("com.SPT.debugging", BepInDependency.DependencyFlags.HardDependency)] // This is used so that we guarantee to load after spt-debugging, that way we can disable its patches public class FikaPlugin : BaseUnityPlugin { - public const string FikaVersion = "1.0.4"; + public const string FikaVersion = "1.0.5"; public static FikaPlugin Instance; public static InternalBundleLoader BundleLoaderPlugin { get; private set; } public static string EFTVersionMajor { get; internal set; }