From 82946887a8684144216fd3c1383807777c984c8b Mon Sep 17 00:00:00 2001 From: Michael Nguyen Date: Sat, 3 Feb 2024 14:02:50 -0600 Subject: [PATCH] Added Left Stance sync and added patch for Sandbox map to allow more bots to spawn instead of being blocked after the first wave --- .../Custom/FixBrokenSpawnOnSandboxPatch.cs | 39 +++++++++++++++++++ .../CoopGameComponents/CoopGameComponent.cs | 1 + .../Coop/NetworkPacket/PlayerStatePacket.cs | 6 ++- Source/Coop/Players/CoopPlayerClient.cs | 2 +- Source/StayInTarkovPlugin.cs | 1 + 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 Source/AkiSupport/Custom/FixBrokenSpawnOnSandboxPatch.cs diff --git a/Source/AkiSupport/Custom/FixBrokenSpawnOnSandboxPatch.cs b/Source/AkiSupport/Custom/FixBrokenSpawnOnSandboxPatch.cs new file mode 100644 index 00000000..1b00a36a --- /dev/null +++ b/Source/AkiSupport/Custom/FixBrokenSpawnOnSandboxPatch.cs @@ -0,0 +1,39 @@ +using Comfort.Common; +using EFT; +using HarmonyLib; +using StayInTarkov; +using System.Linq; +using System.Reflection; +using UnityEngine; + +namespace Aki.Custom.Patches +{ + /// + /// Fixes the map sandbox from only spawning 1 bot at start of game as well as fixing no spawns till all bots are dead. + /// Remove once BSG decides to fix their map + /// + public class FixBrokenSpawnOnSandboxPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted)); + } + + [PatchPrefix] + private static void PatchPrefix() + { + var gameWorld = Singleton.Instance; + if (gameWorld == null) + { + return; + } + + var playerLocation = gameWorld.MainPlayer.Location; + + if (playerLocation == "Sandbox") + { + Object.FindObjectsOfType().ToList().First(x => x.name == "ZoneSandbox").MaxPersonsOnPatrol = 10; + } + } + } +} \ No newline at end of file diff --git a/Source/Coop/Components/CoopGameComponents/CoopGameComponent.cs b/Source/Coop/Components/CoopGameComponents/CoopGameComponent.cs index 6e680a65..70c64ac6 100644 --- a/Source/Coop/Components/CoopGameComponents/CoopGameComponent.cs +++ b/Source/Coop/Components/CoopGameComponents/CoopGameComponent.cs @@ -1306,6 +1306,7 @@ private void CreatePlayerStatePacketFromPRC(ref List playerSt , player.MovementContext.PoseLevel , player.MovementContext.IsSprintEnabled , player.InputDirection + , player.MovementContext.LeftStanceController.LastAnimValue , playerHealth , player.Physical.SerializationStruct , player.MovementContext.BlindFire diff --git a/Source/Coop/NetworkPacket/PlayerStatePacket.cs b/Source/Coop/NetworkPacket/PlayerStatePacket.cs index 69cc8793..b94efb36 100644 --- a/Source/Coop/NetworkPacket/PlayerStatePacket.cs +++ b/Source/Coop/NetworkPacket/PlayerStatePacket.cs @@ -35,6 +35,7 @@ public sealed class PlayerStatePacket : BasePlayerPacket, INetSerializable public Vector2 InputDirection { get; set; } public int Blindfire { get; set; } public float LinearSpeed { get; set; } + public bool LeftStance { get; set; } public PlayerHealthPacket PlayerHealth { get; set; } @@ -42,7 +43,7 @@ public PlayerStatePacket() { } public PlayerStatePacket(string profileId, Vector3 position, Vector2 rotation, Vector3 headRotation, Vector2 movementDirection, EPlayerState state, float tilt, int step, int animatorStateIndex, float characterMovementSpeed, - bool isProne, float poseLevel, bool isSprinting, Vector2 inputDirection + bool isProne, float poseLevel, bool isSprinting, Vector2 inputDirection, bool leftStance , PlayerHealthPacket playerHealth, Physical.PhysicalStamina stamina, int blindFire, float linearSpeed) : base(new string(profileId.ToCharArray()), "PlayerState") { @@ -72,6 +73,7 @@ public PlayerStatePacket(string profileId, Vector3 position, Vector2 rotation, V Stamina = stamina; Blindfire = blindFire; LinearSpeed = linearSpeed; + LeftStance = leftStance; } public override byte[] Serialize() @@ -94,6 +96,7 @@ public override byte[] Serialize() writer.Write(IsSprinting); PhysicalUtils.Serialize(writer, Stamina); Vector2Utils.Serialize(writer, InputDirection); + writer.Write(LeftStance); writer.Write(Blindfire); writer.Write(LinearSpeed); writer.Write(TimeSerializedBetter); @@ -145,6 +148,7 @@ public override ISITPacket Deserialize(byte[] bytes) IsSprinting = reader.ReadBoolean(); Stamina = PhysicalUtils.Deserialize(reader); InputDirection = Vector2Utils.Deserialize(reader); + LeftStance = reader.ReadBoolean(); Blindfire = reader.ReadInt32(); LinearSpeed = reader.ReadSingle(); TimeSerializedBetter = reader.ReadString(); diff --git a/Source/Coop/Players/CoopPlayerClient.cs b/Source/Coop/Players/CoopPlayerClient.cs index f903dc0a..10e02191 100644 --- a/Source/Coop/Players/CoopPlayerClient.cs +++ b/Source/Coop/Players/CoopPlayerClient.cs @@ -154,7 +154,7 @@ protected override void Interpolate() CurrentManagedState.SetStep(NewState.Step); MovementContext.PlayerAnimatorEnableSprint(NewState.IsSprinting); MovementContext.EnableSprint(NewState.IsSprinting); - + MovementContext.LeftStanceController.SetLeftStanceForce(NewState.LeftStance); MovementContext.IsInPronePose = NewState.IsProne; MovementContext.SetPoseLevel(Mathf.Lerp(LastState.PoseLevel, NewState.PoseLevel, InterpolationRatio)); diff --git a/Source/StayInTarkovPlugin.cs b/Source/StayInTarkovPlugin.cs index 374deb5e..c7f38872 100644 --- a/Source/StayInTarkovPlugin.cs +++ b/Source/StayInTarkovPlugin.cs @@ -443,6 +443,7 @@ private static void EnableSPPatches_Bots(BepInEx.Configuration.ConfigFile config new PmcFirstAidPatch().Enable(); new SpawnProcessNegativeValuePatch().Enable(); new LocationLootCacheBustingPatch().Enable(); + new FixBrokenSpawnOnSandboxPatch().Enable(); } private void EnableCoopPatches()