diff --git a/Fika.Core/Bundles/Files/README.md b/Fika.Core/Bundles/Files/README.md index 1d1f88a3..f9b649df 100644 --- a/Fika.Core/Bundles/Files/README.md +++ b/Fika.Core/Bundles/Files/README.md @@ -1,3 +1 @@ -To build these assets, Please refer to the Fika-SDK for more information. -It will tell you how to install the SDK & build the assets. -https://github.com/project-fika/Fika-SDK \ No newline at end of file +These assets are managed and built by the Fika team \ No newline at end of file diff --git a/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs b/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs index 09f6335b..c3276968 100644 --- a/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs +++ b/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs @@ -122,7 +122,7 @@ private void Update() BTRPacket packet = btrPackets.Dequeue(); if (packet.HasBotProfileId) { - AttachBot(packet.BotProfileId); + AttachBot(packet.BotNetId); } if (packet.HasShot) { @@ -151,11 +151,11 @@ private void ObservedShot(Vector3 position, Vector3 direction) firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, position, direction, false); } - public void AttachBot(string profileId) + public void AttachBot(int netId) { if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) { - if (coopHandler.Players.TryGetValue(profileId, out CoopPlayer player)) + if (coopHandler.Players.TryGetValue(netId, out CoopPlayer player)) { BTRTurretView turretView = btrClientSide.turret; diff --git a/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs b/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs index 2486cc93..a96ac738 100644 --- a/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs +++ b/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs @@ -8,6 +8,7 @@ using EFT.InventoryLogic; using EFT.Vehicle; using Fika.Core.Coop.GameMode; +using Fika.Core.Coop.Players; using Fika.Core.Networking; using HarmonyLib; using LiteNetLib; @@ -138,7 +139,7 @@ private IEnumerator SendBotProfileId() { BTRDataPacket = btrDataPacket, HasBotProfileId = true, - BotProfileId = btrBotShooter.ProfileId + BotNetId = ((CoopPlayer)btrBotShooter.GetPlayer).NetId }; writer.Reset(); @@ -383,7 +384,7 @@ private void BtrTraderServicePurchased(ETraderServiceType serviceType, string su GenericPacket responsePacket = new(EPackageType.TraderServiceNotification) { - ProfileId = gameWorld.MainPlayer.ProfileId, + NetId = ((CoopPlayer)gameWorld.MainPlayer).NetId, TraderServiceType = serviceType }; @@ -417,7 +418,7 @@ public void NetworkBtrTraderServicePurchased(BTRServicePacket packet) GenericPacket responsePacket = new(EPackageType.TraderServiceNotification) { - ProfileId = gameWorld.MainPlayer.ProfileId, + NetId = ((CoopPlayer)gameWorld.MainPlayer).NetId, TraderServiceType = packet.TraderServiceType }; diff --git a/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs b/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs index ad5ca6e9..903d1afc 100644 --- a/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs +++ b/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs @@ -37,14 +37,14 @@ public override void SendNetworkSyncPacket(GStruct346 packet) if (!isBot) { - coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(new(coopPlayer.ProfileId) + coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(new(coopPlayer.NetId) { Packet = packet }); } else { - coopBot?.PacketSender?.HealthSyncPackets.Enqueue(new(coopBot.ProfileId) + coopBot?.PacketSender?.HealthSyncPackets.Enqueue(new(coopBot.NetId) { Packet = packet }); diff --git a/Fika.Core/Coop/Components/CoopExfilManager.cs b/Fika.Core/Coop/Components/CoopExfilManager.cs index 91d4a02c..6dacb84a 100644 --- a/Fika.Core/Coop/Components/CoopExfilManager.cs +++ b/Fika.Core/Coop/Components/CoopExfilManager.cs @@ -196,7 +196,7 @@ private void ExfiltrationPoint_OnStatusChanged(ExfiltrationPoint point, EExfiltr CoopPlayer mainPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; GenericPacket packet = new(EPackageType.ExfilCountdown) { - ProfileId = mainPlayer.ProfileId, + NetId = mainPlayer.NetId, ExfilName = point.Settings.Name, ExfilStartTime = point.ExfiltrationStartTime }; diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index b09018a2..cb8d9434 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -33,9 +33,9 @@ public class CoopHandler : MonoBehaviour /// /// ProfileId to Player instance /// - public Dictionary Players { get; } = new(); + public Dictionary Players { get; } = new(); public int HumanPlayers = 1; - public List ExtractedPlayers { get; set; } = []; + public List ExtractedPlayers { get; set; } = []; ManualLogSource Logger { get; set; } public CoopPlayer MyPlayer => (CoopPlayer)Singleton.Instance.MainPlayer; @@ -45,12 +45,13 @@ public class CoopHandler : MonoBehaviour //private Thread loopThread; //private CancellationTokenSource loopToken; - public class SpawnObject(Profile profile, Vector3 position, bool isAlive, bool isAI) + public class SpawnObject(Profile profile, Vector3 position, bool isAlive, bool isAI, int netId) { public Profile Profile { get; set; } = profile; public Vector3 Position { get; set; } = position; public bool IsAlive { get; set; } = isAlive; public bool IsAI { get; set; } = isAI; + public int NetId { get; set; } = netId; } public bool RunAsyncTasks { get; set; } = true; @@ -180,10 +181,13 @@ protected void OnDestroy() loopThread?.Join();*/ StopCoroutine(ProcessSpawnQueue()); - StopCoroutine(PingRoutine); + if (PingRoutine != null) + { + StopCoroutine(PingRoutine); + } } - public bool RequestQuitGame { get; set; } + private bool requestQuitGame = false; /// /// The state your character or game is in to Quit. @@ -232,7 +236,7 @@ public EQuitState GetQuitState() } // Extractions - if (coopGame.ExtractedPlayers.Contains(MyPlayer.ProfileId)) + if (coopGame.ExtractedPlayers.Contains(MyPlayer.NetId)) { quitState = EQuitState.YouHaveExtracted; } @@ -247,9 +251,9 @@ void ProcessQuitting() { EQuitState quitState = GetQuitState(); - if (Input.GetKeyDown(KeyCode.F8) && quitState != EQuitState.NONE && !RequestQuitGame) + if (FikaPlugin.ExtractKey.Value.IsDown() && quitState != EQuitState.NONE && !requestQuitGame) { - RequestQuitGame = true; + requestQuitGame = true; // If you are the server / host if (MatchmakerAcceptPatches.IsServer) @@ -258,13 +262,13 @@ void ProcessQuitting() if ((Singleton.Instance.NetServer.ConnectedPeersCount > 0) && quitState != EQuitState.NONE) { NotificationManagerClass.DisplayWarningNotification("HOSTING: You cannot exit the game until all clients have disconnected."); - RequestQuitGame = false; + requestQuitGame = false; return; } else if (Singleton.Instance.NetServer.ConnectedPeersCount == 0 && Singleton.Instance.timeSinceLastPeerDisconnected > DateTime.Now.AddSeconds(-5) && Singleton.Instance.hasHadPeer) { NotificationManagerClass.DisplayWarningNotification($"HOSTING: Please wait at least 5 seconds after the last peer disconnected before quitting."); - RequestQuitGame = false; + requestQuitGame = false; return; } else @@ -325,7 +329,7 @@ private void ReadFromServerCharacters() if (Players.Count > 0) { requestPacket.HasCharacters = true; - requestPacket.Characters = [.. Players.Keys, .. queuedProfileIds]; + requestPacket.Characters = [.. Players.Values.Select(p => p.ProfileId), .. queuedProfileIds]; } NetDataWriter writer = Singleton.Instance.DataWriter; @@ -382,7 +386,7 @@ await Singleton.Instance.LoadBundlesAndCreatePools(PoolManager.Pool } }); - LocalPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI); + LocalPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI, spawnObject.NetId); if (!spawnObject.IsAlive) { @@ -439,7 +443,7 @@ private IEnumerator ProcessSpawnQueue() } } - public void QueueProfile(Profile profile, Vector3 position, bool isAlive = true, bool isAI = false) + public void QueueProfile(Profile profile, Vector3 position, int netId, bool isAlive = true, bool isAI = false) { if (Singleton.Instance.RegisteredPlayers.Any(x => x.ProfileId == profile.ProfileId)) return; @@ -452,7 +456,7 @@ public void QueueProfile(Profile profile, Vector3 position, bool isAlive = true, queuedProfileIds.Add(profile.ProfileId); Logger.LogInfo($"Queueing profile: {profile.Nickname}, {profile.ProfileId}"); - spawnQueue.Enqueue(new SpawnObject(profile, position, isAlive, isAI)); + spawnQueue.Enqueue(new SpawnObject(profile, position, isAlive, isAI, netId)); } public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInteractiveObject worldInteractiveObject) @@ -464,7 +468,7 @@ public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInt return null; } - private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI) + private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId) { LocalPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer( playerId, @@ -488,12 +492,13 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p if (otherPlayer == null) return null; + ((CoopPlayer)otherPlayer).NetId = netId; if (!isAI) HumanPlayers++; - if (!Players.ContainsKey(profile.ProfileId)) + if (!Players.ContainsKey(netId)) { - Players.Add(profile.ProfileId, (CoopPlayer)otherPlayer); + Players.Add(netId, (CoopPlayer)otherPlayer); } if (!Singleton.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId)) diff --git a/Fika.Core/Coop/Factories/PingFactory.cs b/Fika.Core/Coop/Factories/PingFactory.cs index 445723b3..b5fb37b6 100644 --- a/Fika.Core/Coop/Factories/PingFactory.cs +++ b/Fika.Core/Coop/Factories/PingFactory.cs @@ -51,7 +51,7 @@ private void Awake() { image = GetComponentInChildren(); image.color = Color.clear; - Destroy(gameObject, 3f); + Destroy(gameObject, FikaPlugin.PingTime.Value); } private void Update() diff --git a/Fika.Core/Coop/FreeCamera/FreeCamera.cs b/Fika.Core/Coop/FreeCamera/FreeCamera.cs index b059ca8f..24cba179 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCamera.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCamera.cs @@ -258,7 +258,7 @@ protected void Update() Player player = Singleton.Instance.MainPlayer; - if (!coopHandler.ExtractedPlayers.Contains(player.ProfileId) && player.HealthController.IsAlive) + if (!coopHandler.ExtractedPlayers.Contains(((CoopPlayer)player).NetId) && player.HealthController.IsAlive) { player?.Teleport(transform.position); } diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index 7c38b97e..29750ec4 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -4,7 +4,12 @@ using EFT.UI; using Fika.Core.Coop.Components; using Fika.Core.Coop.GameMode; +using Fika.Core.Coop.Players; using Fika.Core.UI; +using Koenigz.PerfectCulling; +using Koenigz.PerfectCulling.EFT; +using System.Collections.Generic; +using System.Linq; using TMPro; using UnityEngine; @@ -38,11 +43,12 @@ public class FreeCameraController : MonoBehaviour private bool deathFadeEnabled; private float DeadTime = 0f; private DisablerCullingObjectBase[] allCullingObjects; + private List previouslyActiveBakeGroups; protected void Awake() { CameraParent = new GameObject("CameraParent"); - var FCamera = CameraParent.GetOrAddComponent(); + Camera FCamera = CameraParent.GetOrAddComponent(); FCamera.enabled = false; } @@ -73,6 +79,7 @@ protected void Start() deathFade.enabled = true; allCullingObjects = FindObjectsOfType(); + previouslyActiveBakeGroups = []; } protected void Update() @@ -127,7 +134,7 @@ protected void Update() if (quitState == CoopHandler.EQuitState.YouHaveExtracted && !extracted) { - if (coopGame.ExtractedPlayers.Contains(_player.ProfileId)) + if (coopGame.ExtractedPlayers.Contains(((CoopPlayer)_player).NetId)) { extracted = true; ShowExtractMessage(); @@ -225,7 +232,13 @@ private void ShowExtractMessage() { if (FikaPlugin.ShowExtractMessage.Value) { - extractText = FikaUIUtils.CreateOverlayText("Press 'F8' to extract"); + string text = FikaPlugin.ExtractKey.Value.MainKey.ToString(); + if (FikaPlugin.ExtractKey.Value.Modifiers.Count() > 0) + { + string modifiers = string.Join("+", FikaPlugin.ExtractKey.Value.Modifiers); + text = modifiers + "+" + text; + } + extractText = FikaUIUtils.CreateOverlayText($"Press '{text}' to extract"); } } @@ -318,6 +331,30 @@ private void SetPlayerToFreecamMode(Player localPlayer) cullingObject.SetComponentsEnabled(true); } FikaPlugin.Instance.FikaLogger.LogDebug($"Enabled {count} Culling Triggers."); + + PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType(); + if (perfectCullingAdaptiveGrid != null) + { + if (perfectCullingAdaptiveGrid.RuntimeGroupMapping.Count > 0) + { + foreach (PerfectCullingCrossSceneGroup sceneGroup in perfectCullingAdaptiveGrid.RuntimeGroupMapping) + { + foreach (PerfectCullingBakeGroup bakeGroup in sceneGroup.bakeGroups) + { + if (!bakeGroup.IsEnabled) + { + bakeGroup.IsEnabled = true; + } + else + { + previouslyActiveBakeGroups.Add(bakeGroup); + } + } + + sceneGroup.enabled = false; + } + } + } } /// @@ -326,7 +363,6 @@ private void SetPlayerToFreecamMode(Player localPlayer) /// private void SetPlayerToFirstPersonMode(Player localPlayer) { - // re-enable _gamePlayerOwner _gamePlayerOwner.enabled = true; _freeCamScript.SetActive(false); @@ -345,6 +381,32 @@ private void SetPlayerToFirstPersonMode(Player localPlayer) cullingObject.SetComponentsEnabled(false); } FikaPlugin.Instance.FikaLogger.LogDebug($"Disabled {count} Culling Triggers."); + + PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType(); + if (perfectCullingAdaptiveGrid != null) + { + if (perfectCullingAdaptiveGrid.RuntimeGroupMapping.Count > 0) + { + foreach (PerfectCullingCrossSceneGroup sceneGroup in perfectCullingAdaptiveGrid.RuntimeGroupMapping) + { + sceneGroup.enabled = true; + + foreach (PerfectCullingBakeGroup bakeGroup in sceneGroup.bakeGroups) + { + if (bakeGroup.IsEnabled && !previouslyActiveBakeGroups.Contains(bakeGroup)) + { + bakeGroup.IsEnabled = false; + } + else + { + previouslyActiveBakeGroups.Remove(bakeGroup); + } + } + + previouslyActiveBakeGroups.Clear(); + } + } + } } /// @@ -354,7 +416,7 @@ private void SetPlayerToFirstPersonMode(Player localPlayer) private Player GetLocalPlayerFromWorld() { // If the GameWorld instance is null or has no RegisteredPlayers, it most likely means we're not in a raid - var gameWorld = Singleton.Instance; + GameWorld gameWorld = Singleton.Instance; if (gameWorld == null || gameWorld.MainPlayer == null) { return null; diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 290b7da1..4dda819f 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -31,6 +31,7 @@ using HarmonyLib; using JsonType; using LiteNetLib.Utils; +using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; @@ -395,8 +396,6 @@ private async Task CreatePhysicalBot(Profile profile, Vector3 posit } } - coopHandler.Players.Add(profile.Id, (CoopPlayer)localPlayer); - if (Singleton.Instance != null) { if (!Singleton.Instance.RegisteredPlayers.Any(x => x.ProfileId == localPlayer.ProfileId)) @@ -408,8 +407,13 @@ private async Task CreatePhysicalBot(Profile profile, Vector3 posit } } - SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket() { Profile = localPlayer.Profile }, localPlayer.HealthController.IsAlive, true, localPlayer.Transform.position); + FikaServer server = Singleton.Instance; + int netId = server.PopNetId(); + CoopPlayer coopPlayer = (CoopPlayer)localPlayer; + coopPlayer.NetId = netId; + coopHandler.Players.Add(coopPlayer.NetId, coopPlayer); + SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket() { Profile = localPlayer.Profile }, localPlayer.HealthController.IsAlive, true, localPlayer.Transform.position, netId); Singleton.Instance?.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); return localPlayer; @@ -456,7 +460,8 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c botOwner?.Dispose(); Bots.Remove(botKey); - coopHandler.Players.Remove(bot.ProfileId); + CoopPlayer coopPlayer = (CoopPlayer)bot; + coopHandler.Players.Remove(coopPlayer.NetId); #if DEBUG Logger.LogWarning($"Bot {bot.Profile.Info.Settings.Role} despawned successfully."); #endif @@ -648,7 +653,7 @@ public override async Task vmethod_2(int playerId, Vector3 position LocalPlayer myPlayer = await CoopPlayer.Create(playerId, spawnPoint.Position, spawnPoint.Rotation, "Player", "Main_", EPointOfView.FirstPerson, profile, false, UpdateQueue, Player.EUpdateMode.Auto, Player.EUpdateMode.Auto, GClass549.Config.CharacterController.ClientPlayerMode, () => Singleton.Instance.Control.Settings.MouseSensitivity, - () => Singleton.Instance.Control.Settings.MouseAimingSensitivity, new GClass1445(), questController); + () => Singleton.Instance.Control.Settings.MouseAimingSensitivity, new GClass1445(), 0, questController); profile.SetSpawnedInSession(profile.Side == EPlayerSide.Savage); @@ -658,7 +663,8 @@ public override async Task vmethod_2(int playerId, Vector3 position await Task.Delay(5000); } - coopHandler.Players.Add(profile.Id, (CoopPlayer)myPlayer); + CoopPlayer coopPlayer = (CoopPlayer)myPlayer; + coopHandler.Players.Add(coopPlayer.NetId, coopPlayer); PlayerSpawnRequest body = new PlayerSpawnRequest(myPlayer.ProfileId, MatchmakerAcceptPatches.GetGroupId()); await FikaRequestHandler.UpdatePlayerSpawn(body); @@ -711,6 +717,8 @@ public override async Task vmethod_2(int playerId, Vector3 position ForceStart = true }; + FikaPlugin.Instance.FikaLogger.LogWarning("Force start was used!"); + NetDataWriter writer = new(); writer.Reset(); Singleton.Instance.SendDataToAll(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); @@ -723,7 +731,7 @@ public override async Task vmethod_2(int playerId, Vector3 position } } - SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket() { Profile = myPlayer.Profile }, myPlayer.HealthController.IsAlive, false, myPlayer.Transform.position); + SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket() { Profile = myPlayer.Profile }, myPlayer.HealthController.IsAlive, false, myPlayer.Transform.position, (myPlayer as CoopPlayer).NetId); if (MatchmakerAcceptPatches.IsServer) { @@ -1196,7 +1204,7 @@ public void ResetExfilPointsFromServer(ExfiltrationPoint[] points) GameUi.TimerPanel.SetTime(GClass1296.UtcNow, Profile_0.Info.Side, GameTimer.SessionSeconds(), points); } - public List ExtractedPlayers { get; } = []; + public List ExtractedPlayers { get; } = []; /// /// When the local player successfully extracts, enable freecam, notify other players about the extract @@ -1230,7 +1238,7 @@ public void Extract(Player player, ExfiltrationPoint point) GenericPacket genericPacket = new() { - ProfileId = player.ProfileId, + NetId = ((CoopPlayer)player).NetId, PacketType = EPackageType.ClientExtract }; @@ -1253,9 +1261,10 @@ public void Extract(Player player, ExfiltrationPoint point) CoopHandler coopHandler = CoopHandler.GetCoopHandler(); - ExtractedPlayers.Add(player.ProfileId); - coopHandler.ExtractedPlayers.Add(player.ProfileId); - coopHandler.Players.Remove(player.ProfileId); + CoopPlayer coopPlayer = (CoopPlayer)player; + ExtractedPlayers.Add(coopPlayer.NetId); + coopHandler.ExtractedPlayers.Add(coopPlayer.NetId); + coopHandler.Players.Remove(coopPlayer.NetId); preloaderUI.StartBlackScreenShow(2f, 2f, () => { preloaderUI.FadeBlackScreen(2f, -2f); }); @@ -1345,7 +1354,7 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa exitStatus = ExitStatus.Killed; } - if (!ExtractedPlayers.Contains(myPlayer.ProfileId)) + if (!ExtractedPlayers.Contains(myPlayer.NetId)) { if (GameTimer.SessionTime != null && GameTimer.PastTime >= GameTimer.SessionTime) { diff --git a/Fika.Core/Coop/GameMode/IMPTGame.cs b/Fika.Core/Coop/GameMode/IMPTGame.cs index 7a913f0a..2c8fdb80 100644 --- a/Fika.Core/Coop/GameMode/IMPTGame.cs +++ b/Fika.Core/Coop/GameMode/IMPTGame.cs @@ -5,7 +5,7 @@ namespace Fika.Core.Coop.GameMode { public interface IFikaGame { - public List ExtractedPlayers { get; } + public List ExtractedPlayers { get; } ExitStatus MyExitStatus { get; set; } diff --git a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs index c539947a..c2096d87 100644 --- a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs @@ -35,7 +35,7 @@ private void FixedUpdate() return; } - PlayerStatePacket playerStatePacket = new(player.ProfileId, player.Position, player.Rotation, player.HeadRotation, + PlayerStatePacket playerStatePacket = new(player.NetId, player.Position, player.Rotation, player.HeadRotation, player.LastDirection, player.CurrentManagedState.Name, player.MovementContext.SmoothedTilt, player.MovementContext.Step, player.CurrentAnimatorStateIndex, player.MovementContext.SmoothedCharacterMovementSpeed, player.IsInPronePose, player.PoseLevel, player.MovementContext.IsSprintEnabled, player.Physical.SerializationStruct, @@ -56,7 +56,7 @@ private void Update() for (int i = 0; i < firearmPackets; i++) { WeaponPacket firearmPacket = FirearmPackets.Dequeue(); - firearmPacket.ProfileId = player.ProfileId; + firearmPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); @@ -68,7 +68,7 @@ private void Update() for (int i = 0; i < healthPackets; i++) { DamagePacket healthPacket = HealthPackets.Dequeue(); - healthPacket.ProfileId = player.ProfileId; + healthPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); @@ -80,7 +80,7 @@ private void Update() for (int i = 0; i < inventoryPackets; i++) { InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); - inventoryPacket.ProfileId = player.ProfileId; + inventoryPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); @@ -92,7 +92,7 @@ private void Update() for (int i = 0; i < commonPlayerPackets; i++) { CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); - commonPlayerPacket.ProfileId = player.ProfileId; + commonPlayerPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); @@ -104,7 +104,7 @@ private void Update() for (int i = 0; i < healthSyncPackets; i++) { HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); - healthSyncPacket.ProfileId = player.ProfileId; + healthSyncPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); diff --git a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs index aedbca03..ded2b67c 100644 --- a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs @@ -43,7 +43,7 @@ private void FixedUpdate() return; } - PlayerStatePacket playerStatePacket = new(player.ProfileId, player.Position, player.Rotation, player.HeadRotation, + PlayerStatePacket playerStatePacket = new(player.NetId, player.Position, player.Rotation, player.HeadRotation, player.LastDirection, player.CurrentManagedState.Name, player.MovementContext.SmoothedTilt, player.MovementContext.Step, player.CurrentAnimatorStateIndex, player.MovementContext.SmoothedCharacterMovementSpeed, player.IsInPronePose, player.PoseLevel, player.MovementContext.IsSprintEnabled, player.Physical.SerializationStruct, @@ -67,7 +67,7 @@ private void Update() for (int i = 0; i < firearmPackets; i++) { WeaponPacket firearmPacket = FirearmPackets.Dequeue(); - firearmPacket.ProfileId = player.ProfileId; + firearmPacket.NetId = player.NetId; Writer?.Reset(); Client?.SendData(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); @@ -79,7 +79,7 @@ private void Update() for (int i = 0; i < healthPackets; i++) { DamagePacket healthPacket = HealthPackets.Dequeue(); - healthPacket.ProfileId = player.ProfileId; + healthPacket.NetId = player.NetId; Writer?.Reset(); Client?.SendData(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); @@ -91,7 +91,7 @@ private void Update() for (int i = 0; i < inventoryPackets; i++) { InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); - inventoryPacket.ProfileId = player.ProfileId; + inventoryPacket.NetId = player.NetId; Writer?.Reset(); Client?.SendData(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); @@ -103,7 +103,7 @@ private void Update() for (int i = 0; i < commonPlayerPackets; i++) { CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); - commonPlayerPacket.ProfileId = player.ProfileId; + commonPlayerPacket.NetId = player.NetId; Writer?.Reset(); Client?.SendData(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); @@ -115,13 +115,13 @@ private void Update() for (int i = 0; i < healthSyncPackets; i++) { HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); - healthSyncPacket.ProfileId = player.ProfileId; + healthSyncPacket.NetId = player.NetId; Writer?.Reset(); Client?.SendData(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); } } - if (Input.GetKey(FikaPlugin.PingButton.Value.MainKey) && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value) + if (FikaPlugin.PingButton.Value.IsPressed() && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value) { player?.Ping(); } diff --git a/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs index e7ed338e..6f4a7b2a 100644 --- a/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ObservedPacketSender.cs @@ -53,7 +53,7 @@ private void Update() for (int i = 0; i < healthPackets; i++) { DamagePacket healthPacket = HealthPackets.Dequeue(); - healthPacket.ProfileId = player.ProfileId; + healthPacket.NetId = player.NetId; Writer.Reset(); Server.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); @@ -65,7 +65,7 @@ private void Update() for (int i = 0; i < healthPackets; i++) { DamagePacket healthPacket = HealthPackets.Dequeue(); - healthPacket.ProfileId = player.ProfileId; + healthPacket.NetId = player.NetId; Writer.Reset(); Client.SendData(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); diff --git a/Fika.Core/Coop/PacketHandlers/PacketReceiver.cs b/Fika.Core/Coop/PacketHandlers/PacketReceiver.cs index 20ea1a3d..710bffff 100644 --- a/Fika.Core/Coop/PacketHandlers/PacketReceiver.cs +++ b/Fika.Core/Coop/PacketHandlers/PacketReceiver.cs @@ -43,14 +43,14 @@ private void Start() Client = Singleton.Instance; } - LastState = new(player.ProfileId, player.Position, player.Rotation, player.HeadRotation, + LastState = new(player.NetId, player.Position, player.Rotation, player.HeadRotation, player.LastDirection, player.CurrentManagedState.Name, player.MovementContext.Tilt, player.MovementContext.Step, player.CurrentAnimatorStateIndex, player.MovementContext.SmoothedCharacterMovementSpeed, player.IsInPronePose, player.PoseLevel, player.MovementContext.IsSprintEnabled, player.Physical.SerializationStruct, player.MovementContext.BlindFire, player.observedOverlap, player.leftStanceDisabled, player.MovementContext.IsGrounded, false, 0, Vector3.zero); - NewState = new(player.ProfileId, player.Position, player.Rotation, player.HeadRotation, + NewState = new(player.NetId, player.Position, player.Rotation, player.HeadRotation, player.LastDirection, player.CurrentManagedState.Name, player.MovementContext.Tilt, player.MovementContext.Step, player.CurrentAnimatorStateIndex, player.MovementContext.SmoothedCharacterMovementSpeed, player.IsInPronePose, player.PoseLevel, player.MovementContext.IsSprintEnabled, player.Physical.SerializationStruct, diff --git a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs index 296cc4ee..35230e19 100644 --- a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs @@ -50,7 +50,7 @@ private void FixedUpdate() return; } - PlayerStatePacket playerStatePacket = new(player.ProfileId, player.Position, player.Rotation, player.HeadRotation, + PlayerStatePacket playerStatePacket = new(player.NetId, player.Position, player.Rotation, player.HeadRotation, player.LastDirection, player.CurrentManagedState.Name, player.MovementContext.SmoothedTilt, player.MovementContext.Step, player.CurrentAnimatorStateIndex, player.MovementContext.SmoothedCharacterMovementSpeed, player.IsInPronePose, player.PoseLevel, player.MovementContext.IsSprintEnabled, player.Physical.SerializationStruct, @@ -74,7 +74,7 @@ private void Update() for (int i = 0; i < firearmPackets; i++) { WeaponPacket firearmPacket = FirearmPackets.Dequeue(); - firearmPacket.ProfileId = player.ProfileId; + firearmPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); @@ -86,7 +86,7 @@ private void Update() for (int i = 0; i < healthPackets; i++) { DamagePacket healthPacket = HealthPackets.Dequeue(); - healthPacket.ProfileId = player.ProfileId; + healthPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); @@ -98,7 +98,7 @@ private void Update() for (int i = 0; i < inventoryPackets; i++) { InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); - inventoryPacket.ProfileId = player.ProfileId; + inventoryPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); @@ -110,7 +110,7 @@ private void Update() for (int i = 0; i < commonPlayerPackets; i++) { CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); - commonPlayerPacket.ProfileId = player.ProfileId; + commonPlayerPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); @@ -122,13 +122,13 @@ private void Update() for (int i = 0; i < healthSyncPackets; i++) { HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); - healthSyncPacket.ProfileId = player.ProfileId; + healthSyncPacket.NetId = player.NetId; Writer?.Reset(); Server?.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); } } - if (Input.GetKey(FikaPlugin.PingButton.Value.MainKey) && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value) + if (FikaPlugin.PingButton.Value.IsPressed() && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value) { player?.Ping(); } @@ -167,7 +167,7 @@ private IEnumerator SendTrainTime() GenericPacket packet = new() { - ProfileId = player.ProfileId, + NetId = player.NetId, PacketType = EPackageType.TrainSync, DepartureTime = time }; diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index cfc59610..b737843a 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -25,7 +25,7 @@ namespace Fika.Core.Coop.Players { /// - /// Used to simulate bots for the host + /// Used to simulate bots for the host. /// public class CoopBot : CoopPlayer { @@ -346,17 +346,17 @@ public override void OnDestroy() FikaServer server = Singleton.Instance; GenericPacket packet = new(EPackageType.DisposeBot) { - ProfileId = MainPlayer.ProfileId, - BotProfileId = ProfileId + NetId = MainPlayer.NetId, + BotNetId = NetId }; server.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); } } if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) { - if (!coopHandler.Players.Remove(ProfileId)) + if (!coopHandler.Players.Remove(NetId)) { - FikaPlugin.Instance.FikaLogger.LogWarning("Unable to remove " + ProfileId + " from CoopHandler.Players when Destroying"); + FikaPlugin.Instance.FikaLogger.LogWarning("Unable to remove " + NetId + " from CoopHandler.Players when Destroying"); } } base.OnDestroy(); diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index 474e9fb6..be5e81c2 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -27,6 +27,9 @@ namespace Fika.Core.Coop.Players { + /// + /// CoopPlayer is the LocalPlayer there can only be one CoopPlayer in every game and that is yourself. + /// public class CoopPlayer : LocalPlayer { public PacketReceiver PacketReceiver; @@ -39,6 +42,8 @@ public class CoopPlayer : LocalPlayer public RagdollPacket RagdollPacket = default; public bool hasGround = false; public Transform RaycastCameraTransform; + public int NetId; + public bool IsObservedAI = false; public static async Task Create( int playerId, @@ -55,6 +60,7 @@ public static async Task Create( CharacterControllerSpawner.Mode characterControllerMode, Func getSensitivity, Func getAimingSensitivity, GInterface99 filter, + int netId, AbstractQuestControllerClass questController = null, AbstractAchievementControllerClass achievementsController = null) { @@ -74,7 +80,7 @@ public static async Task Create( isThirdPerson: false); player.IsYourPlayer = true; - + player.NetId = netId; CoopClientInventoryController inventoryController = new(player, profile, true); if (questController == null) @@ -140,7 +146,7 @@ public override void BtrInteraction(BTRSide btr, byte placeId, EInteractionType base.BtrInteraction(btr, placeId, interaction); if (MatchmakerAcceptPatches.IsClient) { - BTRInteractionPacket packet = new(ProfileId) + BTRInteractionPacket packet = new(NetId) { HasInteractPacket = true, InteractPacket = btr.GetInteractWithBtrPacket(placeId, interaction) @@ -158,7 +164,7 @@ public override void BtrInteraction(BTRSide btr, byte placeId, EInteractionType bool success = coopHandler.serverBTR.HostInteraction(this, interactPacket); if (success) { - BTRInteractionPacket packet = new(ProfileId) + BTRInteractionPacket packet = new(NetId) { HasInteractPacket = true, InteractPacket = interactPacket @@ -194,11 +200,6 @@ public override void ApplyDamageInfo(DamageInfo damageInfo, EBodyPart bodyPartTy { if (IsYourPlayer) { - if (!FikaPlugin.Instance.FriendlyFire && damageInfo.Player is not null && damageInfo.Player.iPlayer is ObservedCoopPlayer observedCoopPlayer && !observedCoopPlayer.IsObservedAI) - { - return; - } - if (colliderType == EBodyPartColliderType.HeadCommon) { damageInfo.Damage *= FikaPlugin.HeadDamageMultiplier.Value; @@ -215,15 +216,12 @@ public override void ApplyDamageInfo(DamageInfo damageInfo, EBodyPart bodyPartTy public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartType, EBodyPartColliderType colliderType, EArmorPlateCollider armorPlateCollider, GStruct390 shotId) { - if (IsYourPlayer) + if (damageInfo.Player != null & damageInfo.Player.iPlayer is CoopBot) { - if (!FikaPlugin.Instance.FriendlyFire && damageInfo.Player is not null && damageInfo.Player.iPlayer is ObservedCoopPlayer observedCoopPlayer && !observedCoopPlayer.IsObservedAI) - { - return null; - } + return base.ApplyShot(damageInfo, bodyPartType, colliderType, armorPlateCollider, shotId); } - return base.ApplyShot(damageInfo, bodyPartType, colliderType, armorPlateCollider, shotId); + return null; } public override void Proceed(bool withNetwork, Callback callback, bool scheduled = true) @@ -552,7 +550,7 @@ public HealthSyncPacket SetupDeathPacket(GStruct346 packet) SetupDogTag(); } - return new(ProfileId) + return new(NetId) { Packet = packet, KillerId = !string.IsNullOrEmpty(KillerId) ? KillerId : null, @@ -818,7 +816,7 @@ public void Ping() GenericPacket genericPacket = new() { - ProfileId = ProfileId, + NetId = NetId, PacketType = EPackageType.Ping, PingLocation = hitPoint, PingType = pingType, @@ -1262,6 +1260,7 @@ public virtual void HandleDamagePacket(DamagePacket packet) DamageType = packet.DamageInfo.DamageType, BodyPartColliderType = packet.DamageInfo.ColliderType, HitPoint = packet.DamageInfo.Point, + HitNormal = packet.DamageInfo.HitNormal, Direction = packet.DamageInfo.Direction, PenetrationPower = packet.DamageInfo.PenetrationPower, BlockedBy = packet.DamageInfo.BlockedBy, @@ -1276,6 +1275,13 @@ public virtual void HandleDamagePacket(DamagePacket packet) if (player != null) { damageInfo.Player = player; + if (IsYourPlayer) + { + if (!FikaPlugin.Instance.FriendlyFire && damageInfo.Player.iPlayer is ObservedCoopPlayer observedCoopPlayer && !observedCoopPlayer.IsObservedAI) + { + return; + } + } } if (Singleton.Instance.GetAlivePlayerByProfileID(packet.DamageInfo.ProfileId).HandsController.Item is Weapon weapon) diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index 509a5a5a..4307efc4 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -25,7 +25,9 @@ namespace Fika.Core.Coop.Players { /// - /// Observed players are any other players in the world for a client, including bots. They are all being handled by the server that moves them through packets. + /// Observed players are any other players in the world for a client, including bots. + /// They are all being handled by the server that moves them through packets. + /// As a host this is only other clients. /// public class ObservedCoopPlayer : CoopPlayer { @@ -38,7 +40,6 @@ public GClass2417 NetworkHealthController { get => HealthController as GClass2417; } - public bool IsObservedAI = false; private readonly GClass2156 ObservedVaultingParameters = new(); public override bool CanBeSnapped => false; public override EPointOfView PointOfView { get => EPointOfView.ThirdPerson; } @@ -322,12 +323,40 @@ public override void ApplyDamageInfo(DamageInfo damageInfo, EBodyPart bodyPartTy ManageAggressor(damageInfo, bodyPartType, colliderType);*/ } + /*public override void ShotReactions(DamageInfo shot, EBodyPart bodyPart) + { + Vector3 normalized = shot.Direction.normalized; + if (PointOfView == EPointOfView.ThirdPerson) + { + turnOffFbbikAt = Time.time + 0.6f; + _fbbik.solver.Quick = false; + BodyPartCollider bodyPartCollider; + if ((bodyPartCollider = shot.HittedBallisticCollider as BodyPartCollider) != null) + { + HitReaction.Hit(bodyPartCollider.BodyPartColliderType, bodyPartCollider.BodyPartType, normalized, shot.HitPoint, false); + } + } + if (shot.Weapon is KnifeClass knifeClass) + { + KnifeComponent itemComponent = knifeClass.GetItemComponent(); + Vector3 normalized2 = (shot.Player.iPlayer.Transform.position - Transform.position).normalized; + Vector3 vector = Vector3.Cross(normalized2, Vector3.up); + float y = normalized.y; + float num = Vector3.Dot(vector, normalized); + float num2 = 1f - Mathf.Abs(Vector3.Dot(normalized2, normalized)); + num2 = ((bodyPart == EBodyPart.Head) ? num2 : Mathf.Sqrt(num2)); + Rotation += new Vector2(-num, -y).normalized * itemComponent.Template.AppliedTrunkRotation.Random(false) * num2; + ProceduralWeaponAnimation.ForceReact.AddForce(new Vector3(-y, num, 0f).normalized, num2, 1f, itemComponent.Template.AppliedHeadRotation.Random(false)); + } + }*/ + public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartType, EBodyPartColliderType colliderType, EArmorPlateCollider armorPlateCollider, GStruct390 shotId) { - if (!IsObservedAI) + /*if (!IsObservedAI) { + ShotReactions(damageInfo, bodyPartType); return null; - } + }*/ if (damageInfo.Player != null) { @@ -337,7 +366,10 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy LastDamageInfo = damageInfo; LastDamageType = damageInfo.DamageType; - if (damageInfo.Player.iPlayer.IsYourPlayer) + // There should never be other instances than CoopPlayer or its derived types + CoopPlayer player = (CoopPlayer)damageInfo.Player.iPlayer; + + if (player.IsYourPlayer) { if (HealthController != null && !HealthController.IsAlive) { @@ -382,6 +414,66 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy Absorbed = 0f, Direction = damageInfo.Direction, Point = damageInfo.HitPoint, + HitNormal = damageInfo.HitNormal, + PenetrationPower = damageInfo.PenetrationPower, + BlockedBy = damageInfo.BlockedBy, + DeflectedBy = damageInfo.DeflectedBy, + SourceId = damageInfo.SourceId, + ProfileId = damageInfo.Player.iPlayer.ProfileId + } + }); + + // Run this to get weapon skill + ManageAggressor(damageInfo, bodyPartType, colliderType); + + return hitInfo; + } + else if (player.IsAI) + { + if (HealthController != null && !HealthController.IsAlive) + { + return null; + } + + bool flag = !string.IsNullOrEmpty(damageInfo.DeflectedBy); + float damage = damageInfo.Damage; + List list = ProceedDamageThroughArmor(ref damageInfo, colliderType, armorPlateCollider, true); + MaterialType materialType = (flag ? MaterialType.HelmetRicochet : ((list == null || list.Count < 1) ? MaterialType.Body : list[0].Material)); + GClass1676 hitInfo = new() + { + PoV = PointOfView, + Penetrated = (string.IsNullOrEmpty(damageInfo.BlockedBy) || string.IsNullOrEmpty(damageInfo.DeflectedBy)), + Material = materialType + }; + float num = damage - damageInfo.Damage; + if (num > 0) + { + damageInfo.DidArmorDamage = num; + } + damageInfo.DidBodyDamage = damageInfo.Damage; + //ApplyDamageInfo(damageInfo, bodyPartType, colliderType, 0f); + ShotReactions(damageInfo, bodyPartType); + ReceiveDamage(damageInfo.Damage, bodyPartType, damageInfo.DamageType, num, hitInfo.Material); + + if (damageInfo.HittedBallisticCollider != null) + { + BodyPartCollider bodyPartCollider = (BodyPartCollider)damageInfo.HittedBallisticCollider; + colliderType = bodyPartCollider.BodyPartColliderType; + } + + PacketSender?.HealthPackets?.Enqueue(new() + { + DamageInfo = new() + { + Damage = damage, + DamageType = damageInfo.DamageType, + BodyPartType = bodyPartType, + ColliderType = colliderType, + ArmorPlateCollider = armorPlateCollider, + Absorbed = 0f, + Direction = damageInfo.Direction, + Point = damageInfo.HitPoint, + HitNormal = damageInfo.HitNormal, PenetrationPower = damageInfo.PenetrationPower, BlockedBy = damageInfo.BlockedBy, DeflectedBy = damageInfo.DeflectedBy, @@ -399,6 +491,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy } else { + ShotReactions(damageInfo, bodyPartType); return null; } } @@ -716,17 +809,26 @@ public override void SetInventory(EquipmentClass equipmentClass) Inventory.Equipment = equipmentClass; BindableState itemInHands = (BindableState)Traverse.Create(this).Field("_itemInHands").GetValue(); - bool shouldSet = false; if (HandsController != null && HandsController.Item != null) { - shouldSet = true; Item item = FindItem(HandsController.Item.Id); if (item != null) { itemInHands.Value = item; } } - PlayerBody.Init(PlayerBody.BodyCustomization, Inventory.Equipment, shouldSet ? itemInHands : null, LayerMask.NameToLayer("Player"), Side); + + EquipmentSlot[] equipmentSlots = Traverse.Create().Field("SlotNames").Value; + foreach (EquipmentSlot equipmentSlot in equipmentSlots) + { + Transform slotBone = PlayerBody.GetSlotBone(equipmentSlot); + Transform alternativeHolsterBone = PlayerBody.GetAlternativeHolsterBone(equipmentSlot); + PlayerBody.GClass1860 gclass = new(PlayerBody, Inventory.Equipment.GetSlot(equipmentSlot), slotBone, equipmentSlot, Inventory.Equipment.GetSlot(EquipmentSlot.Backpack), alternativeHolsterBone); + PlayerBody.GClass1860 gclass2 = PlayerBody.SlotViews.AddOrReplace(equipmentSlot, gclass); + gclass2?.Dispose(); + } + + //PlayerBody.Init(PlayerBody.BodyCustomization, Inventory.Equipment, shouldSet ? itemInHands : null, LayerMask.NameToLayer("Player"), Side); } public override void DoObservedVault(VaultPacket packet) @@ -787,14 +889,15 @@ protected override async void Start() { IsObservedAI = true; } + + PacketSender = gameObject.AddComponent(); if (IsObservedAI) { - PacketSender = gameObject.AddComponent(); GenericPacket genericPacket = new(EPackageType.LoadBot) { - ProfileId = ProfileId, - BotProfileId = ProfileId + NetId = NetId, + BotNetId = NetId }; PacketSender.Writer.Reset(); PacketSender.Client.SendData(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); diff --git a/Fika.Core/Coop/Session/LoadLocationLoot_Patch.cs b/Fika.Core/Coop/Session/LoadLocationLoot_Patch.cs deleted file mode 100644 index 3a3c40d4..00000000 --- a/Fika.Core/Coop/Session/LoadLocationLoot_Patch.cs +++ /dev/null @@ -1,74 +0,0 @@ -using Aki.Common.Http; -using Aki.Reflection.Patching; -using EFT; -using Fika.Core.Coop.Matchmaker; -using Newtonsoft.Json; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; - -namespace Fika.Core.Coop.Session -{ - public class LocationDataRequest() - { - [JsonProperty("errmsg")] - public string Errmsg { get; set; } - [JsonProperty("err")] - public int Err { get; set; } - [JsonProperty("data")] - public LocationSettingsClass.Location Data { get; set; } - } - - public class LoadLocationLootPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() => typeof(Class263).GetMethod(nameof(Class263.LoadLocationLoot)); - - [PatchPrefix] - private static bool PatchPrefix(string locationId, int variantId, ref Task __result) - { - if (MatchmakerAcceptPatches.MatchingType == EMatchmakerType.Single) - { - return true; - } - - string serverId = MatchmakerAcceptPatches.GetGroupId(); - - var objectToSend = new Dictionary - { - { "locationId", locationId }, - { "variantId", variantId }, - { "serverId", serverId } - }; - - var converterType = typeof(AbstractGame).Assembly.GetTypes().First(t => t.GetField("Converters", BindingFlags.Static | BindingFlags.Public) != null). - GetField("Converters", BindingFlags.Static | BindingFlags.Public).GetValue(null) as JsonConverter[]; - - __result = Task.Run(() => - { - var result = RequestHandler.PostJson($"/coop/location/getLoot", JsonConvert.SerializeObject(objectToSend)); - var locationDataRequest = JsonConvert.DeserializeObject(result, new JsonSerializerSettings() - { - Converters = converterType, - NullValueHandling = NullValueHandling.Ignore, - MissingMemberHandling = MissingMemberHandling.Ignore, - ObjectCreationHandling = ObjectCreationHandling.Replace, - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - FloatFormatHandling = FloatFormatHandling.DefaultValue, - FloatParseHandling = FloatParseHandling.Double, - Error = (serializer, err) => - { - Logger.LogError("Serialization Error: " + err); - } - }); - - if (locationDataRequest != null) - return locationDataRequest.Data; - else - return null; - }); - - return __result == null; - } - } -} diff --git a/Fika.Core/EssentialPatches/FikaVersionLabelPatch.cs b/Fika.Core/EssentialPatches/FikaVersionLabelPatch.cs index b63acaa8..7ead2e64 100644 --- a/Fika.Core/EssentialPatches/FikaVersionLabelPatch.cs +++ b/Fika.Core/EssentialPatches/FikaVersionLabelPatch.cs @@ -35,7 +35,7 @@ internal static void PatchPostfix(string major, object __result) Traverse.Create(MonoBehaviourSingleton.Instance).Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}"); Traverse.Create(MonoBehaviourSingleton.Instance).Field("string_2").SetValue($"Fika {fikaVersion} |"); - Traverse.Create(__result).Field("Major").SetValue($"Fika BETA {fikaVersion} | {_versionLabel}"); + Traverse.Create(__result).Field("Major").SetValue($"FIKA BETA {fikaVersion} | {_versionLabel}"); } } } \ No newline at end of file diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index cbc720cb..e733f8b7 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -94,14 +94,18 @@ public class FikaPlugin : BaseUnityPlugin }; #region config values + // Hidden public static ConfigEntry AcceptedTOS { get; set; } + // Coop public static ConfigEntry ShowNotifications { get; set; } public static ConfigEntry AutoExtract { get; set; } public static ConfigEntry ShowExtractMessage { get; set; } public static ConfigEntry FasterInventoryScroll { get; set; } public static ConfigEntry FasterInventoryScrollSpeed { get; set; } + public static ConfigEntry ExtractKey { get; set; } + // Coop | Custom public static ConfigEntry UseNamePlates { get; set; } public static ConfigEntry UseHealthNumber { get; set; } @@ -111,9 +115,12 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry PingButton { get; set; } public static ConfigEntry PingColor { get; set; } public static ConfigEntry PingSize { get; set; } + public static ConfigEntry PingTime { get; set; } public static ConfigEntry PlayPingAnimation { get; set; } + // Coop | Debug public static ConfigEntry FreeCamButton { get; set; } + // Performance public static ConfigEntry DynamicAI { get; set; } public static ConfigEntry DynamicAIRange { get; set; } @@ -134,6 +141,7 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry MaxBotsShoreline { get; set; } public static ConfigEntry MaxBotsLabs { get; set; } public static ConfigEntry MaxBotsLighthouse { get; set; } + // Network public static ConfigEntry NativeSockets { get; set; } public static ConfigEntry ForceIP { get; set; } @@ -141,6 +149,8 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry AutoRefreshRate { get; set; } public static ConfigEntry UDPPort { get; set; } public static ConfigEntry UseUPnP { get; set; } + public static ConfigEntry ConnectionTimeout { get; set; } + // Gameplay public static ConfigEntry HeadDamageMultiplier { get; set; } public static ConfigEntry ArmpitDamageMultiplier { get; set; } @@ -233,33 +243,37 @@ private void SetupConfig() // Coop - ShowNotifications = Instance.Config.Bind("Coop", "Show Feed", true, new ConfigDescription("Enable custom notifications when a player dies, extracts, kills a boss, etc.", tags: new ConfigurationManagerAttributes() { Order = 5 })); + ShowNotifications = Instance.Config.Bind("Coop", "Show Feed", true, new ConfigDescription("Enable custom notifications when a player dies, extracts, kills a boss, etc.", tags: new ConfigurationManagerAttributes() { Order = 6 })); + + AutoExtract = Config.Bind("Coop", "Auto Extract", false, new ConfigDescription("Automatically extracts after the extraction countdown. As a host, this will only work if there are no clients connected.", tags: new ConfigurationManagerAttributes() { Order = 5 })); - AutoExtract = Config.Bind("Coop", "Auto Extract", false, new ConfigDescription("Automatically extracts after the extraction countdown. As a host, this will only work if there are no clients connected.", tags: new ConfigurationManagerAttributes() { Order = 4 })); + ShowExtractMessage = Config.Bind("Coop", "Show Extract Message", true, new ConfigDescription("Whether to show the extract message after dying/extracting.", tags: new ConfigurationManagerAttributes() { Order = 4 })); - ShowExtractMessage = Config.Bind("Coop", "Show Extract Message", true, new ConfigDescription("Whether to show the extract message after dying/extracting.", tags: new ConfigurationManagerAttributes() { Order = 3 })); + FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 3 })); - FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 2 })); + FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 2 })); - FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 1 })); + ExtractKey = Config.Bind("Coop", "Extract Key", new KeyboardShortcut(KeyCode.F8), new ConfigDescription("The key used to extract from the raid.", tags: new ConfigurationManagerAttributes() { Order = 1 })); // Coop | Custom - UseNamePlates = Config.Bind("Coop | Custom", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 9 })); + UseNamePlates = Config.Bind("Coop | Custom", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 10 })); - UseHealthNumber = Config.Bind("Coop | Custom", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 8 })); + UseHealthNumber = Config.Bind("Coop | Custom", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 9 })); - UsePlateFactionSide = Config.Bind("Coop | Custom", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 7 })); + UsePlateFactionSide = Config.Bind("Coop | Custom", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 8 })); - NamePlateScale = Config.Bind("Coop | Custom", "Name Plate Scale", 0.22f, new ConfigDescription("Size of the name plates", new AcceptableValueRange(0.05f, 1f), new ConfigurationManagerAttributes() { Order = 6 })); + NamePlateScale = Config.Bind("Coop | Custom", "Name Plate Scale", 0.22f, new ConfigDescription("Size of the name plates", new AcceptableValueRange(0.05f, 1f), new ConfigurationManagerAttributes() { Order = 7 })); - UsePingSystem = Config.Bind("Coop | Custom", "Ping System", false, new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 5 })); + UsePingSystem = Config.Bind("Coop | Custom", "Ping System", false, new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 6 })); - PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 4 })); + PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 5 })); - PingColor = Config.Bind("Coop | Custom", "Ping Color", Color.white, new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 3 })); + PingColor = Config.Bind("Coop | Custom", "Ping Color", Color.white, new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 4 })); - PingSize = Config.Bind("Coop | Custom", "Ping Size", 1f, new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 2 })); + PingSize = Config.Bind("Coop | Custom", "Ping Size", 1f, new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 3 })); + + PingTime = Config.Bind("Coop | Custom", "Ping Time", 3, new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange(2, 10), new ConfigurationManagerAttributes() { Order = 2 })); PlayPingAnimation = Config.Bind("Coop | Custom", "Play Ping Animation", false, new ConfigDescription("Plays the pointing animation automatically when pinging. Can interfere with gameplay.", tags: new ConfigurationManagerAttributes() { Order = 1 })); @@ -309,17 +323,19 @@ private void SetupConfig() // Network - NativeSockets = Config.Bind(section: "Network", "Native Sockets", false, new ConfigDescription("Use NativeSockets for gameplay traffic. This uses direct socket calls for send/receive to drastically increase speed and reduce GC pressure. Only for Windows/Linux and might not always work.", tags: new ConfigurationManagerAttributes() { Order = 6 })); + NativeSockets = Config.Bind(section: "Network", "Native Sockets", false, new ConfigDescription("Use NativeSockets for gameplay traffic. This uses direct socket calls for send/receive to drastically increase speed and reduce GC pressure. Only for Windows/Linux and might not always work.", tags: new ConfigurationManagerAttributes() { Order = 7 })); + + ForceIP = Config.Bind("Network", "Force IP", "", new ConfigDescription("Forces the server when hosting to use this IP when broadcasting to the backend instead of automatically trying to fetch it. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 6 })); - ForceIP = Config.Bind("Network", "Force IP", "", new ConfigDescription("Forces the server when hosting to use this IP when broadcasting to the backend instead of automatically trying to fetch it. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 5 })); + ForceBindIP = Config.Bind("Network", "Force Bind IP", "", new ConfigDescription("Forces the server when hosting to use this local IP when starting the server. Useful if you are hosting on a VPN. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 5 })); - ForceBindIP = Config.Bind("Network", "Force Bind IP", "", new ConfigDescription("Forces the server when hosting to use this local IP when starting the server. Useful if you are hosting on a VPN. Leave empty to disable.", tags: new ConfigurationManagerAttributes() { Order = 4 })); + AutoRefreshRate = Config.Bind("Network", "Auto Server Refresh Rate", 10f, new ConfigDescription("Every X seconds the client will ask the server for the list of matches while at the lobby screen.", new AcceptableValueRange(3f, 60f), new ConfigurationManagerAttributes() { Order = 4 })); - AutoRefreshRate = Config.Bind("Network", "Auto Server Refresh Rate", 10f, new ConfigDescription("Every X seconds the client will ask the server for the list of matches while at the lobby screen.", new AcceptableValueRange(3f, 60f), new ConfigurationManagerAttributes() { Order = 3 })); + UDPPort = Config.Bind("Network", "UDP Port", 25565, new ConfigDescription("Port to use for UDP gameplay packets.", tags: new ConfigurationManagerAttributes() { Order = 3 })); - UDPPort = Config.Bind("Network", "UDP Port", 25565, new ConfigDescription("Port to use for UDP gameplay packets.", tags: new ConfigurationManagerAttributes() { Order = 2 })); + UseUPnP = Config.Bind("Network", "Use UPnP", false, new ConfigDescription("Attempt to open ports using UPnP. Useful if you cannot open ports yourself but the router supports UPnP.", tags: new ConfigurationManagerAttributes() { Order = 2 })); - UseUPnP = Config.Bind("Network", "Use UPnP", false, new ConfigDescription("Attempt to open ports using UPnP. Useful if you cannot open ports yourself but the router supports UPnP.", tags: new ConfigurationManagerAttributes() { Order = 1 })); + ConnectionTimeout = Config.Bind("Network", "Connection Timeout", 15, new ConfigDescription("How long it takes for a connection to be considered dropped if no packets are received.", new AcceptableValueRange(5, 60), new ConfigurationManagerAttributes() { Order = 1 })); // Gameplay diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 55875cb5..4899f4f2 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -35,7 +35,7 @@ public class FikaClient : MonoBehaviour, INetEventListener private NetManager _netClient; public NetDataWriter DataWriter = new(); public CoopPlayer MyPlayer => (CoopPlayer)Singleton.Instance.MainPlayer; - public Dictionary Players => CoopHandler.Players; + public Dictionary Players => CoopHandler.Players; private CoopHandler CoopHandler { get; set; } public NetPacketProcessor packetProcessor = new(); public int Ping = 0; @@ -79,6 +79,7 @@ public void Start() packetProcessor.SubscribeNetSerializable(OnMinePacketReceived); packetProcessor.SubscribeNetSerializable(OnBorderZonePacketReceived); packetProcessor.SubscribeNetSerializable(OnSendCharacterPacketReceived); + packetProcessor.SubscribeNetSerializable(OnAssignNetIdPacketReceived); _netClient = new NetManager(this) { @@ -86,7 +87,7 @@ public void Start() UpdateTime = 15, NatPunchEnabled = false, IPv6Enabled = false, - DisconnectTimeout = 15000, + DisconnectTimeout = FikaPlugin.ConnectionTimeout.Value * 1000, UseNativeSockets = FikaPlugin.NativeSockets.Value, EnableStatistics = true }; @@ -113,11 +114,34 @@ public void Start() ClientReady = true; } + private void OnAssignNetIdPacketReceived(AssignNetIdPacket packet, NetPeer peer) + { + MyPlayer.NetId = packet.NetId; + int i = -1; + foreach (var player in Players) + { + if (player.Value == MyPlayer) + { + i = player.Key; + + break; + } + } + + if (i == -1) + { + return; + } + + Players.Remove(i); + Players[packet.NetId] = MyPlayer; + } + private void OnSendCharacterPacketReceived(SendCharacterPacket packet, NetPeer peer) { if (packet.PlayerInfo.Profile.ProfileId != MyPlayer.ProfileId) { - CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.IsAlive, packet.IsAI); + CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.netId, packet.IsAlive, packet.IsAI); } } @@ -166,7 +190,7 @@ private void OnMinePacketReceived(MinePacket packet, NetPeer peer) private void OnDeathPacketReceived(DeathPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.HandleDeathPatchet(packet); } @@ -174,7 +198,7 @@ private void OnDeathPacketReceived(DeathPacket packet, NetPeer peer) private void OnBTRInteractionPacketReceived(BTRInteractionPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer player)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer player)) { player.ProcessInteractWithBTR(packet); } @@ -289,21 +313,21 @@ private void OnExfiltrationPacketReceived(ExfiltrationPacket packet, NetPeer pee private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) { - if (!Players.ContainsKey(packet.ProfileId)) + if (!Players.ContainsKey(packet.NetId)) { return; } if (packet.PacketType == EPackageType.ClientExtract) { - if (CoopHandler.Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (CoopHandler.Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - CoopHandler.Players.Remove(packet.ProfileId); - if (!CoopHandler.ExtractedPlayers.Contains(packet.ProfileId)) + CoopHandler.Players.Remove(packet.NetId); + if (!CoopHandler.ExtractedPlayers.Contains(packet.NetId)) { - CoopHandler.ExtractedPlayers.Add(packet.ProfileId); + CoopHandler.ExtractedPlayers.Add(packet.NetId); CoopGame coopGame = (CoopGame)CoopHandler.LocalGameInstance; - coopGame.ExtractedPlayers.Add(packet.ProfileId); + coopGame.ExtractedPlayers.Add(packet.NetId); coopGame.ClearHostAI(playerToApply); if (FikaPlugin.ShowNotifications.Value) @@ -319,7 +343,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) } else if (packet.PacketType == EPackageType.Ping && FikaPlugin.UsePingSystem.Value) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.ReceivePing(packet.PingLocation, packet.PingType, packet.PingColor, packet.Nickname); } @@ -362,30 +386,30 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) } else if (packet.PacketType == EPackageType.DisposeBot) { - if (CoopHandler.Players.TryGetValue(packet.BotProfileId, out CoopPlayer playerToApply)) + if (CoopHandler.Players.TryGetValue(packet.BotNetId, out CoopPlayer playerToApply)) { - if (CoopHandler.Players.Remove(packet.BotProfileId)) + if (CoopHandler.Players.Remove(packet.BotNetId)) { playerToApply.Dispose(); AssetPoolObject.ReturnToPool(playerToApply.gameObject, true); - clientLogger.LogInfo("Disposing bot: " + packet.BotProfileId); + clientLogger.LogInfo("Disposing bot: " + packet.BotNetId); } else { - clientLogger.LogWarning("Unable to dispose of bot: " + packet.BotProfileId); + clientLogger.LogWarning("Unable to dispose of bot: " + packet.BotNetId); } } else { - clientLogger.LogWarning("Unable to dispose of bot: " + packet.BotProfileId + ", unable to find GameObject"); + clientLogger.LogWarning("Unable to dispose of bot: " + packet.BotNetId + ", unable to find GameObject"); } } } private void OnHealthSyncPacketReceived(HealthSyncPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); } @@ -452,7 +476,7 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe clientLogger.LogInfo($"Received CharacterRequest! ProfileID: {packet.PlayerInfo.Profile.ProfileId}, Nickname: {packet.PlayerInfo.Profile.Nickname}"); if (packet.ProfileId != MyPlayer.ProfileId) { - CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.IsAlive, packet.IsAI); + CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.NetId, packet.IsAlive, packet.IsAI); } } else if (packet.IsRequest) @@ -467,7 +491,8 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe }, IsAlive = MyPlayer.ActiveHealthController.IsAlive, IsAI = MyPlayer.IsAI, - Position = MyPlayer.Transform.position + Position = MyPlayer.Transform.position, + NetId = MyPlayer.NetId }; DataWriter.Reset(); SendData(DataWriter, ref requestPacket, DeliveryMethod.ReliableOrdered); @@ -476,7 +501,7 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); } @@ -484,7 +509,7 @@ private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet, NetPeer pee private void OnInventoryPacketReceived(InventoryPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.InventoryPackets?.Enqueue(packet); } @@ -492,7 +517,7 @@ private void OnInventoryPacketReceived(InventoryPacket packet, NetPeer peer) private void OnDamagePacketReceived(DamagePacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.DamagePackets?.Enqueue(packet); } @@ -500,7 +525,7 @@ private void OnDamagePacketReceived(DamagePacket packet, NetPeer peer) private void OnFirearmPacketReceived(WeaponPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.FirearmPackets?.Enqueue(packet); } @@ -540,7 +565,7 @@ private void OnGameTimerPacketReceived(GameTimerPacket packet, NetPeer peer) private void OnPlayerStatePacketReceived(PlayerStatePacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.PacketReceiver.NewState = packet; } diff --git a/Fika.Core/Networking/FikaSerialization.cs b/Fika.Core/Networking/FikaSerialization.cs index f7c4ee96..9b7a57e7 100644 --- a/Fika.Core/Networking/FikaSerialization.cs +++ b/Fika.Core/Networking/FikaSerialization.cs @@ -644,6 +644,7 @@ public struct ApplyShotPacket() public float Absorbed; public Vector3 Direction = Vector3.zero; public Vector3 Point = Vector3.zero; + public Vector3 HitNormal = Vector3.zero; public float PenetrationPower = 0f; public string BlockedBy; public string DeflectedBy; @@ -664,6 +665,7 @@ public static ApplyShotPacket Deserialize(NetDataReader reader) Absorbed = reader.GetFloat(), Direction = reader.GetVector3(), Point = reader.GetVector3(), + HitNormal = reader.GetVector3(), PenetrationPower = reader.GetFloat(), BlockedBy = reader.GetString(), DeflectedBy = reader.GetString(), @@ -684,6 +686,7 @@ public static void Serialize(NetDataWriter writer, ApplyShotPacket packet) writer.Put(packet.Absorbed); writer.Put(packet.Direction); writer.Put(packet.Point); + writer.Put(packet.HitNormal); writer.Put(packet.PenetrationPower); writer.Put(packet.BlockedBy); writer.Put(packet.DeflectedBy); diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 8cc5d839..db488ecd 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -36,7 +36,7 @@ public class FikaServer : MonoBehaviour, INetEventListener, INetLogger public NetPacketProcessor packetProcessor = new(); private NetDataWriter _dataWriter = new(); public CoopPlayer MyPlayer => (CoopPlayer)Singleton.Instance.MainPlayer; - public Dictionary Players => CoopHandler.Players; + public Dictionary Players => CoopHandler.Players; public List PlayersMissing = []; public string MyExternalIP { get; private set; } = NetUtils.GetLocalIp(LocalAddrType.IPv4); private int Port => FikaPlugin.UDPPort.Value; @@ -53,9 +53,13 @@ public NetManager NetServer public bool hasHadPeer = false; private ManualLogSource serverLogger; public bool ServerReady = false; + private int _currentNetId; public async void Start() { + // Start at 1 to avoid having 0 and making us think it's working when it's not + _currentNetId = 1; + NetDebug.Logger = this; serverLogger = new("Fika Server"); @@ -84,7 +88,7 @@ public async void Start() UpdateTime = 15, AutoRecycle = true, IPv6Enabled = false, - DisconnectTimeout = 15000, + DisconnectTimeout = FikaPlugin.ConnectionTimeout.Value * 1000, UseNativeSockets = FikaPlugin.NativeSockets.Value, EnableStatistics = true }; @@ -120,7 +124,6 @@ await Task.Run(async () => else if (FikaPlugin.ForceIP.Value != "") { MyExternalIP = FikaPlugin.ForceIP.Value; - NotificationManagerClass.DisplayMessageNotification($"Force IP enabled and set to: {MyExternalIP}", iconType: EFT.Communications.ENotificationIconType.Alert); } else { @@ -158,15 +161,34 @@ await Task.Run(async () => ServerReady = true; } + public int PopNetId() + { + int netId = _currentNetId; + _currentNetId++; + + return netId; + } + private void OnSendCharacterPacketReceived(SendCharacterPacket packet, NetPeer peer) { + int netId = PopNetId(); + packet.netId = netId; if (packet.PlayerInfo.Profile.ProfileId != MyPlayer.ProfileId) { - CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.IsAlive, packet.IsAI); + CoopHandler.QueueProfile(packet.PlayerInfo.Profile, packet.Position, packet.netId, packet.IsAlive, packet.IsAI); } _dataWriter.Reset(); SendDataToAll(_dataWriter, ref packet, DeliveryMethod.ReliableUnordered, peer); + + AssignNetIdPacket assignNetIdPacket = new() + { + NetId = netId + }; + + _dataWriter.Reset(); + packetProcessor.WriteNetSerializable(_dataWriter, ref assignNetIdPacket); + peer.Send(_dataWriter, DeliveryMethod.ReliableUnordered); } private void OnBorderZonePacketReceived(BorderZonePacket packet, NetPeer peer) @@ -193,7 +215,7 @@ private void OnMinePacketReceived(MinePacket packet, NetPeer peer) private void OnDeathPacketReceived(DeathPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.HandleDeathPatchet(packet); } @@ -211,7 +233,7 @@ private void OnBTRInteractionPacketReceived(BTRInteractionPacket packet, NetPeer { if (CoopHandler.serverBTR != null) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer player)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer player)) { if (CoopHandler.serverBTR.CanPlayerEnter(player)) { @@ -222,7 +244,7 @@ private void OnBTRInteractionPacketReceived(BTRInteractionPacket packet, NetPeer } else { - BTRInteractionPacket newPacket = new(packet.ProfileId) + BTRInteractionPacket newPacket = new(packet.NetId) { HasInteractPacket = false }; @@ -299,21 +321,21 @@ private void OnExfiltrationPacketReceived(ExfiltrationPacket packet, NetPeer pee private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) { - if (!Players.ContainsKey(packet.ProfileId)) + if (!Players.ContainsKey(packet.NetId)) { return; } if (packet.PacketType == EPackageType.ClientExtract) { - if (CoopHandler.Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (CoopHandler.Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - CoopHandler.Players.Remove(packet.ProfileId); - if (!CoopHandler.ExtractedPlayers.Contains(packet.ProfileId)) + CoopHandler.Players.Remove(packet.NetId); + if (!CoopHandler.ExtractedPlayers.Contains(packet.NetId)) { - CoopHandler.ExtractedPlayers.Add(packet.ProfileId); + CoopHandler.ExtractedPlayers.Add(packet.NetId); CoopGame coopGame = (CoopGame)CoopHandler.LocalGameInstance; - coopGame.ExtractedPlayers.Add(packet.ProfileId); + coopGame.ExtractedPlayers.Add(packet.NetId); coopGame.ClearHostAI(playerToApply); if (FikaPlugin.ShowNotifications.Value) @@ -329,14 +351,14 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) } else if (packet.PacketType == EPackageType.Ping && FikaPlugin.UsePingSystem.Value) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.ReceivePing(packet.PingLocation, packet.PingType, packet.PingColor, packet.Nickname); } } else if (packet.PacketType == EPackageType.LoadBot) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { if (playerToApply is CoopBot botToApply) { @@ -371,7 +393,7 @@ private void OnGenericPacketReceived(GenericPacket packet, NetPeer peer) private void OnHealthSyncPacketReceived(HealthSyncPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); } @@ -423,13 +445,14 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe }, IsAlive = player.HealthController.IsAlive, IsAI = player is CoopBot, - Position = player.Transform.position + Position = player.Transform.position, + NetId = player.NetId }; _dataWriter.Reset(); SendDataToPeer(peer, _dataWriter, ref requestPacket, DeliveryMethod.ReliableOrdered); } } - if (!Players.ContainsKey(packet.ProfileId) && !PlayersMissing.Contains(packet.ProfileId) && !CoopHandler.ExtractedPlayers.Contains(packet.ProfileId)) + if (!Players.ContainsKey(packet.NetId) && !PlayersMissing.Contains(packet.ProfileId) && !CoopHandler.ExtractedPlayers.Contains(packet.NetId)) { PlayersMissing.Add(packet.ProfileId); serverLogger.LogInfo($"Requesting missing player from server."); @@ -442,7 +465,7 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe serverLogger.LogInfo($"Received CharacterRequest from client: ProfileID: {packet.PlayerInfo.Profile.ProfileId}, Nickname: {packet.PlayerInfo.Profile.Nickname}"); if (packet.ProfileId != MyPlayer.ProfileId) { - CoopHandler.QueueProfile(packet.PlayerInfo.Profile, new Vector3(packet.Position.x, packet.Position.y + 0.5f, packet.Position.y), packet.IsAlive); + CoopHandler.QueueProfile(packet.PlayerInfo.Profile, new Vector3(packet.Position.x, packet.Position.y + 0.5f, packet.Position.y), packet.NetId, packet.IsAlive); PlayersMissing.Remove(packet.ProfileId); } } @@ -450,7 +473,7 @@ private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packe private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); } @@ -461,7 +484,7 @@ private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet, NetPeer pee private void OnInventoryPacketReceived(InventoryPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.InventoryPackets?.Enqueue(packet); } @@ -472,7 +495,7 @@ private void OnInventoryPacketReceived(InventoryPacket packet, NetPeer peer) private void OnDamagePacketReceived(DamagePacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.DamagePackets?.Enqueue(packet); } @@ -483,7 +506,7 @@ private void OnDamagePacketReceived(DamagePacket packet, NetPeer peer) private void OnFirearmPacketReceived(WeaponPacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply?.PacketReceiver?.FirearmPackets?.Enqueue(packet); } @@ -512,7 +535,7 @@ private void OnGameTimerPacketReceived(GameTimerPacket packet, NetPeer peer) private void OnPlayerStatePacketReceived(PlayerStatePacket packet, NetPeer peer) { - if (Players.TryGetValue(packet.ProfileId, out CoopPlayer playerToApply)) + if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { playerToApply.PacketReceiver.NewState = packet; } diff --git a/Fika.Core/Networking/Packets/Communication/AllCharacterRequestPacket.cs b/Fika.Core/Networking/Packets/Communication/AllCharacterRequestPacket.cs index 07b27cca..db431408 100644 --- a/Fika.Core/Networking/Packets/Communication/AllCharacterRequestPacket.cs +++ b/Fika.Core/Networking/Packets/Communication/AllCharacterRequestPacket.cs @@ -16,6 +16,7 @@ public struct AllCharacterRequestPacket(string profileId) : INetSerializable public bool IsAlive = true; public bool IsAI = false; public Vector3 Position; + public int NetId; public void Deserialize(NetDataReader reader) { @@ -33,6 +34,7 @@ public void Deserialize(NetDataReader reader) IsAlive = reader.GetBool(); IsAI = reader.GetBool(); Position = reader.GetVector3(); + NetId = reader.GetInt(); } public void Serialize(NetDataWriter writer) @@ -51,6 +53,7 @@ public void Serialize(NetDataWriter writer) writer.Put(IsAlive); writer.Put(IsAI); writer.Put(Position); + writer.Put(NetId); } } } diff --git a/Fika.Core/Networking/Packets/Communication/AssignNetIdPacket.cs b/Fika.Core/Networking/Packets/Communication/AssignNetIdPacket.cs new file mode 100644 index 00000000..e5483a3a --- /dev/null +++ b/Fika.Core/Networking/Packets/Communication/AssignNetIdPacket.cs @@ -0,0 +1,19 @@ +using LiteNetLib.Utils; + +namespace Fika.Core.Networking +{ + public struct AssignNetIdPacket : INetSerializable + { + public int NetId; + + public void Deserialize(NetDataReader reader) + { + NetId = reader.GetInt(); + } + + public void Serialize(NetDataWriter writer) + { + writer.Put(NetId); + } + } +} diff --git a/Fika.Core/Networking/Packets/Communication/SendCharacterPacket.cs b/Fika.Core/Networking/Packets/Communication/SendCharacterPacket.cs index 72a35f46..6c741bb7 100644 --- a/Fika.Core/Networking/Packets/Communication/SendCharacterPacket.cs +++ b/Fika.Core/Networking/Packets/Communication/SendCharacterPacket.cs @@ -4,12 +4,13 @@ namespace Fika.Core.Networking { - public struct SendCharacterPacket(PlayerInfoPacket playerInfoPacket, bool isAlive, bool isAi, Vector3 position) : INetSerializable + public struct SendCharacterPacket(PlayerInfoPacket playerInfoPacket, bool isAlive, bool isAi, Vector3 position, int netId) : INetSerializable { public PlayerInfoPacket PlayerInfo = playerInfoPacket; public bool IsAlive = isAlive; public bool IsAI = isAi; public Vector3 Position = position; + public int netId = netId; public void Deserialize(NetDataReader reader) { @@ -17,6 +18,7 @@ public void Deserialize(NetDataReader reader) IsAlive = reader.GetBool(); IsAI = reader.GetBool(); Position = reader.GetVector3(); + netId = reader.GetInt(); } public void Serialize(NetDataWriter writer) @@ -25,6 +27,7 @@ public void Serialize(NetDataWriter writer) writer.Put(IsAlive); writer.Put(IsAI); writer.Put(Position); + writer.Put(netId); } } } diff --git a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs index 26a0c179..ede93653 100644 --- a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs +++ b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs @@ -6,9 +6,9 @@ namespace Fika.Core.Networking { - public struct WeaponPacket(string profileId) : INetSerializable + public struct WeaponPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public bool HasShotInfo = false; public ShotInfoPacket ShotInfoPacket; public bool ChangeFireMode = false; @@ -57,7 +57,7 @@ public struct WeaponPacket(string profileId) : INetSerializable public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); HasShotInfo = reader.GetBool(); if (HasShotInfo) ShotInfoPacket = ShotInfoPacket.Deserialize(reader); @@ -127,7 +127,7 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put(HasShotInfo); if (HasShotInfo) ShotInfoPacket.Serialize(writer, ShotInfoPacket); diff --git a/Fika.Core/Networking/Packets/GameWorld/BTRInteractionPacket.cs b/Fika.Core/Networking/Packets/GameWorld/BTRInteractionPacket.cs index 5e2966a3..3fe06068 100644 --- a/Fika.Core/Networking/Packets/GameWorld/BTRInteractionPacket.cs +++ b/Fika.Core/Networking/Packets/GameWorld/BTRInteractionPacket.cs @@ -3,15 +3,15 @@ namespace Fika.Core.Networking { - public struct BTRInteractionPacket(string profileId) : INetSerializable + public struct BTRInteractionPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public bool HasInteractPacket = false; public PlayerInteractPacket InteractPacket; public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); HasInteractPacket = reader.GetBool(); if (HasInteractPacket) { @@ -28,7 +28,7 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put(HasInteractPacket); if (HasInteractPacket) { diff --git a/Fika.Core/Networking/Packets/GameWorld/BTRPacket.cs b/Fika.Core/Networking/Packets/GameWorld/BTRPacket.cs index fdff3c1c..525d913e 100644 --- a/Fika.Core/Networking/Packets/GameWorld/BTRPacket.cs +++ b/Fika.Core/Networking/Packets/GameWorld/BTRPacket.cs @@ -8,7 +8,7 @@ public struct BTRPacket() : INetSerializable { public BTRDataPacket BTRDataPacket; public bool HasBotProfileId = false; - public string BotProfileId; + public int BotNetId; public bool HasShot = false; public Vector3 ShotPosition; public Vector3 ShotDirection; @@ -18,7 +18,7 @@ public void Deserialize(NetDataReader reader) BTRDataPacket = BTRDataPacketUtils.Deserialize(reader); HasBotProfileId = reader.GetBool(); if (HasBotProfileId) - BotProfileId = reader.GetString(); + BotNetId = reader.GetInt(); HasShot = reader.GetBool(); if (HasShot) { @@ -32,7 +32,7 @@ public void Serialize(NetDataWriter writer) BTRDataPacketUtils.Serialize(writer, BTRDataPacket); writer.Put(HasBotProfileId); if (HasBotProfileId) - writer.Put(BotProfileId); + writer.Put(BotNetId); writer.Put(HasShot); if (HasShot) { diff --git a/Fika.Core/Networking/Packets/GameWorld/GenericPacket.cs b/Fika.Core/Networking/Packets/GameWorld/GenericPacket.cs index e5e02ad2..91969e17 100644 --- a/Fika.Core/Networking/Packets/GameWorld/GenericPacket.cs +++ b/Fika.Core/Networking/Packets/GameWorld/GenericPacket.cs @@ -13,13 +13,13 @@ namespace Fika.Core.Networking /// public struct GenericPacket(EPackageType packageType) : INetSerializable { - public string ProfileId; + public int NetId; public EPackageType PacketType = packageType; public Vector3 PingLocation; public PingFactory.EPingType PingType; public Color PingColor = Color.white; public string Nickname; - public string BotProfileId; + public int BotNetId; public long DepartureTime; public string ExfilName; public float ExfilStartTime; @@ -27,7 +27,7 @@ public struct GenericPacket(EPackageType packageType) : INetSerializable public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); PacketType = (EPackageType)reader.GetInt(); switch (PacketType) { @@ -38,7 +38,7 @@ public void Deserialize(NetDataReader reader) Nickname = reader.GetString(); break; case EPackageType.LoadBot: - BotProfileId = reader.GetString(); + BotNetId = reader.GetInt(); break; case EPackageType.TrainSync: DepartureTime = reader.GetLong(); @@ -51,14 +51,14 @@ public void Deserialize(NetDataReader reader) TraderServiceType = (ETraderServiceType)reader.GetInt(); break; case EPackageType.DisposeBot: - BotProfileId = reader.GetString(); + BotNetId = reader.GetInt(); break; } } public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put((int)PacketType); switch (PacketType) { @@ -69,7 +69,7 @@ public void Serialize(NetDataWriter writer) writer.Put(Nickname); break; case EPackageType.LoadBot: - writer.Put(BotProfileId); + writer.Put(BotNetId); break; case EPackageType.TrainSync: writer.Put(DepartureTime); @@ -82,7 +82,7 @@ public void Serialize(NetDataWriter writer) writer.Put((int)TraderServiceType); break; case EPackageType.DisposeBot: - writer.Put(BotProfileId); + writer.Put(BotNetId); break; } } diff --git a/Fika.Core/Networking/Packets/Player/CommonPlayerPacket.cs b/Fika.Core/Networking/Packets/Player/CommonPlayerPacket.cs index d81abb42..f6208c76 100644 --- a/Fika.Core/Networking/Packets/Player/CommonPlayerPacket.cs +++ b/Fika.Core/Networking/Packets/Player/CommonPlayerPacket.cs @@ -3,9 +3,9 @@ namespace Fika.Core.Networking { - public struct CommonPlayerPacket(string profileId) : INetSerializable + public struct CommonPlayerPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public EPhraseTrigger Phrase = EPhraseTrigger.PhraseNone; public int PhraseIndex; public bool HasWorldInteractionPacket = false; @@ -29,7 +29,7 @@ public struct CommonPlayerPacket(string profileId) : INetSerializable public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); Phrase = (EPhraseTrigger)reader.GetInt(); if (Phrase != EPhraseTrigger.PhraseNone) PhraseIndex = reader.GetInt(); @@ -64,7 +64,7 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put((int)Phrase); if (Phrase != EPhraseTrigger.PhraseNone) writer.Put(PhraseIndex); diff --git a/Fika.Core/Networking/Packets/Player/DamagePacket.cs b/Fika.Core/Networking/Packets/Player/DamagePacket.cs index 4cb4f230..f1dcc5f2 100644 --- a/Fika.Core/Networking/Packets/Player/DamagePacket.cs +++ b/Fika.Core/Networking/Packets/Player/DamagePacket.cs @@ -3,20 +3,20 @@ namespace Fika.Core.Networking { - public struct DamagePacket(string profileId) : INetSerializable + public struct DamagePacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public ApplyShotPacket DamageInfo; public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); DamageInfo = ApplyShotPacket.Deserialize(reader); } public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); ApplyShotPacket.Serialize(writer, DamageInfo); } } diff --git a/Fika.Core/Networking/Packets/Player/DeathPacket.cs b/Fika.Core/Networking/Packets/Player/DeathPacket.cs index 88849e57..d16f7536 100644 --- a/Fika.Core/Networking/Packets/Player/DeathPacket.cs +++ b/Fika.Core/Networking/Packets/Player/DeathPacket.cs @@ -3,16 +3,16 @@ namespace Fika.Core.Networking { - public struct DeathPacket(string profileId) : INetSerializable + public struct DeathPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public RagdollPacket RagdollPacket; public bool HasInventory = false; public EquipmentClass Equipment; public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); RagdollPacket = RagdollPacket.Deserialize(reader); HasInventory = reader.GetBool(); if (HasInventory) @@ -23,7 +23,7 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); RagdollPacket.Serialize(writer, RagdollPacket); writer.Put(HasInventory); if (HasInventory) diff --git a/Fika.Core/Networking/Packets/Player/HealthSyncPacket.cs b/Fika.Core/Networking/Packets/Player/HealthSyncPacket.cs index b533b9e2..c17ac483 100644 --- a/Fika.Core/Networking/Packets/Player/HealthSyncPacket.cs +++ b/Fika.Core/Networking/Packets/Player/HealthSyncPacket.cs @@ -4,9 +4,9 @@ namespace Fika.Core.Networking { - public struct HealthSyncPacket(string profileId) : INetSerializable + public struct HealthSyncPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public GStruct346 Packet; public string KillerId; public string KillerWeaponId; @@ -15,7 +15,7 @@ public struct HealthSyncPacket(string profileId) : INetSerializable public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); GStruct346 packet = new() { SyncType = (GStruct346.ESyncType)reader.GetInt() @@ -262,7 +262,7 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); GStruct346.GStruct365 packet = Packet.Data; writer.Put((int)Packet.SyncType); switch (Packet.SyncType) diff --git a/Fika.Core/Networking/Packets/Player/InventoryPacket.cs b/Fika.Core/Networking/Packets/Player/InventoryPacket.cs index 04f975f9..975248d1 100644 --- a/Fika.Core/Networking/Packets/Player/InventoryPacket.cs +++ b/Fika.Core/Networking/Packets/Player/InventoryPacket.cs @@ -3,9 +3,9 @@ namespace Fika.Core.Networking { - public struct InventoryPacket(string profileId) : INetSerializable + public struct InventoryPacket(int netId) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public bool HasItemControllerExecutePacket = false; public ItemControllerExecutePacket ItemControllerExecutePacket; public bool HasSearchPacket = false; @@ -13,7 +13,7 @@ public struct InventoryPacket(string profileId) : INetSerializable public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put(HasItemControllerExecutePacket); if (HasItemControllerExecutePacket) ItemControllerExecutePacket.Serialize(writer, ItemControllerExecutePacket); @@ -24,7 +24,7 @@ public void Serialize(NetDataWriter writer) public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); HasItemControllerExecutePacket = reader.GetBool(); if (HasItemControllerExecutePacket) ItemControllerExecutePacket = ItemControllerExecutePacket.Deserialize(reader); diff --git a/Fika.Core/Networking/Packets/Player/PlayerStatePacket.cs b/Fika.Core/Networking/Packets/Player/PlayerStatePacket.cs index 2387862c..cf9ff22b 100644 --- a/Fika.Core/Networking/Packets/Player/PlayerStatePacket.cs +++ b/Fika.Core/Networking/Packets/Player/PlayerStatePacket.cs @@ -4,12 +4,12 @@ namespace Fika.Core.Networking { - public struct PlayerStatePacket(string profileId, Vector3 position, Vector2 rotation, Vector2 headRotation, Vector2 movementDirection, + public struct PlayerStatePacket(int netId, Vector3 position, Vector2 rotation, Vector2 headRotation, Vector2 movementDirection, EPlayerState state, float tilt, int step, int animatorStateIndex, float characterMovementSpeed, bool isProne, float poseLevel, bool isSprinting, GClass681.GStruct35 stamina, int blindfire, float weaponOverlap, bool leftStanceDisabled, bool isGrounded, bool hasGround, ESurfaceSound surfaceSound, Vector3 surfaceNormal) : INetSerializable { - public string ProfileId = profileId; + public int NetId = netId; public Vector3 Position = position; public Vector2 Rotation = rotation; public Vector3 HeadRotation = headRotation; @@ -33,7 +33,7 @@ public struct PlayerStatePacket(string profileId, Vector3 position, Vector2 rota public void Serialize(NetDataWriter writer) { - writer.Put(ProfileId); + writer.Put(NetId); writer.Put(Position); writer.Put(Rotation); writer.Put(HeadRotation); @@ -62,7 +62,7 @@ public void Serialize(NetDataWriter writer) public void Deserialize(NetDataReader reader) { - ProfileId = reader.GetString(); + NetId = reader.GetInt(); Position = reader.GetVector3(); Rotation = reader.GetVector2(); HeadRotation = reader.GetVector3(); diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index 99e6a593..71d1adc5 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -7,6 +7,7 @@ using Fika.Core.Networking.Http.Models; using Fika.Core.UI.Models; using HarmonyLib; +using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; diff --git a/Fika.Core/UI/Patches/ItemContextPatch.cs b/Fika.Core/UI/Patches/ItemContextPatch.cs index cc877167..53de2019 100644 --- a/Fika.Core/UI/Patches/ItemContextPatch.cs +++ b/Fika.Core/UI/Patches/ItemContextPatch.cs @@ -7,6 +7,7 @@ using Fika.Core.Networking.Http; using Fika.Core.UI.Models; using HarmonyLib; +using Newtonsoft.Json; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/Fika.Core/UI/Patches/TOSPatch.cs b/Fika.Core/UI/Patches/TOSPatch.cs index 4f32e1db..0e9dbb2a 100644 --- a/Fika.Core/UI/Patches/TOSPatch.cs +++ b/Fika.Core/UI/Patches/TOSPatch.cs @@ -11,8 +11,8 @@ namespace Fika.Core.UI.Patches { public class TOSPatch : ModulePatch { - protected const string str_1 = "V2VsY29tZSB0byBNUFQhCgpNUFQgaXMgYSBjby1vcCBtb2QgZm9yIFNQVCwgYWxsb3dpbmcgeW91IHRvIHBsYXkgd2l0aCB5b3VyIGZyaWVuZHMuIE1QVCBpcyBhbmQgd2lsbCBhbHdheXMgYmUgZnJlZSwgaWYgeW91IHBhaWQgZm9yIGl0IHlvdSBnb3Qgc2NhbW1lZC4gWW91IGFyZSBhbHNvIG5vdCBhbGxvd2VkIHRvIGhvc3QgcHVibGljIHNlcnZlcnMgd2l0aCBtb25ldGl6YXRpb24gb3IgZG9uYXRpb25zLgoKV2FpdCBmb3IgdGhpcyBtZXNzYWdlIHRvIGZhZGUgdG8gYWNjZXB0IG91ciBUZXJtcyBvZiBTZXJ2aWNlLgoKWW91IGNhbiBqb2luIG91ciBEaXNjb3JkIGhlcmU6IGh0dHBzOi8vZGlzY29yZC5nZy9GOWpIajhKekF3"; - protected const string str_2 = "V2VsY29tZSB0byBNUFQhCgpNUFQgaXMgYSBjby1vcCBtb2QgZm9yIFNQVCwgYWxsb3dpbmcgeW91IHRvIHBsYXkgd2l0aCB5b3VyIGZyaWVuZHMuIE1QVCBpcyBhbmQgd2lsbCBhbHdheXMgYmUgZnJlZSwgaWYgeW91IHBhaWQgZm9yIGl0IHlvdSBnb3Qgc2NhbW1lZC4gWW91IGFyZSBhbHNvIG5vdCBhbGxvd2VkIHRvIGhvc3QgcHVibGljIHNlcnZlcnMgd2l0aCBtb25ldGl6YXRpb24gb3IgZG9uYXRpb25zLgoKWW91IGNhbiBqb2luIG91ciBEaXNjb3JkIGhlcmU6IGh0dHBzOi8vZGlzY29yZC5nZy9GOWpIajhKekF3"; + protected const string str_1 = "V2VsY29tZSB0byBGaWthIQoKRmlrYSBpcyBhIGNvLW9wIG1vZCBmb3IgU1BULCBhbGxvd2luZyB5b3UgdG8gcGxheSB3aXRoIHlvdXIgZnJpZW5kcy4gRmlrYSBpcyBhbmQgd2lsbCBhbHdheXMgYmUgZnJlZSwgaWYgeW91IHBhaWQgZm9yIGl0IHlvdSBnb3Qgc2NhbW1lZC4gWW91IGFyZSBhbHNvIG5vdCBhbGxvd2VkIHRvIGhvc3QgcHVibGljIHNlcnZlcnMgd2l0aCBtb25ldGl6YXRpb24gb3IgZG9uYXRpb25zLgoKV2FpdCBmb3IgdGhpcyBtZXNzYWdlIHRvIGZhZGUgdG8gYWNjZXB0IG91ciBUZXJtcyBvZiBTZXJ2aWNlLgoKWW91IGNhbiBqb2luIG91ciBEaXNjb3JkIGhlcmU6IGh0dHBzOi8vZGlzY29yZC5nZy9wcm9qZWN0LWZpa2E="; + protected const string str_2 = "V2VsY29tZSB0byBGaWthIQoKRmlrYSBpcyBhIGNvLW9wIG1vZCBmb3IgU1BULCBhbGxvd2luZyB5b3UgdG8gcGxheSB3aXRoIHlvdXIgZnJpZW5kcy4gRmlrYSBpcyBhbmQgd2lsbCBhbHdheXMgYmUgZnJlZSwgaWYgeW91IHBhaWQgZm9yIGl0IHlvdSBnb3Qgc2NhbW1lZC4gWW91IGFyZSBhbHNvIG5vdCBhbGxvd2VkIHRvIGhvc3QgcHVibGljIHNlcnZlcnMgd2l0aCBtb25ldGl6YXRpb24gb3IgZG9uYXRpb25zLgoKWW91IGNhbiBqb2luIG91ciBEaXNjb3JkIGhlcmU6IGh0dHBzOi8vZGlzY29yZC5nZy9wcm9qZWN0LWZpa2E="; private static bool HasShown = false;