diff --git a/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs b/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs index 27784a6b..6498bb9f 100644 --- a/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs +++ b/Fika.Core/Coop/BTR/FikaBTRManager_Client.cs @@ -176,7 +176,7 @@ public void AttachBot(int netId) weaponPrefab.transform.SetPositionAndRotation(turretView.GunRoot.position, turretView.GunRoot.rotation); weaponTransform.SetPositionAndRotation(turretView.GunRoot.position, turretView.GunRoot.rotation); - string[] gunModsToDisable = Traverse.Create(turretView).Field("_gunModsToDisable").GetValue(); + string[] gunModsToDisable = Traverse.Create(turretView).Field("_gunModsToDisable").Value; if (gunModsToDisable != null) { foreach (Transform child in weaponTransform) diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index 1aa4c614..728c6f29 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -247,7 +247,7 @@ private async Task ReadFromServerCharactersLoop() { while (RunAsyncTasks) { - CoopGame coopGame = (CoopGame)Singleton.Instance; + CoopGame coopGame = LocalGameInstance; int waitTime = 2500; if (coopGame.Status == GameStatus.Started) { @@ -285,24 +285,31 @@ private void ReadFromServerCharacters() private async void SpawnPlayer(SpawnObject spawnObject) { - if (Singleton.Instance.RegisteredPlayers.Any(x => x.ProfileId == spawnObject.Profile.ProfileId)) + if (spawnObject.Profile == null) { + Logger.LogError("SpawnPlayer Profile is NULL!"); + queuedProfileIds.Remove(spawnObject.Profile.ProfileId); return; } - if (Singleton.Instance.AllAlivePlayersList.Any(x => x.ProfileId == spawnObject.Profile.ProfileId)) + foreach (IPlayer player in Singleton.Instance.RegisteredPlayers) { - return; + if (player.ProfileId == spawnObject.Profile.ProfileId) + { + return; + } } - int playerId = Players.Count + Singleton.Instance.RegisteredPlayers.Count + 1; - if (spawnObject.Profile == null) + foreach (IPlayer player in Singleton.Instance.AllAlivePlayersList) { - Logger.LogError("SpawnPlayer Profile is NULL!"); - queuedProfileIds.Remove(spawnObject.Profile.ProfileId); - return; + if (player.ProfileId == spawnObject.Profile.ProfileId) + { + return; + } } + int playerId = Players.Count + Singleton.Instance.RegisteredPlayers.Count + 1; + IEnumerable allPrefabPaths = spawnObject.Profile.GetAllPrefabPaths(); if (allPrefabPaths.Count() == 0) { @@ -311,9 +318,7 @@ private async void SpawnPlayer(SpawnObject spawnObject) } await Singleton.Instance.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, - PoolManager.AssemblyType.Local, - allPrefabPaths.ToArray(), - JobPriority.General).ContinueWith(x => + PoolManager.AssemblyType.Local, allPrefabPaths.ToArray(), JobPriority.General).ContinueWith(x => { if (x.IsCompleted) { @@ -340,8 +345,7 @@ await Singleton.Instance.LoadBundlesAndCreatePools(PoolManager.Pool { if (LocalGameInstance != null) { - CoopGame coopGame = LocalGameInstance; - BotsController botController = coopGame.BotsController; + BotsController botController = LocalGameInstance.BotsController; if (botController != null) { // Start Coroutine as botController might need a while to start sometimes... @@ -388,14 +392,20 @@ private IEnumerator ProcessSpawnQueue() 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)) + foreach (IPlayer player in Singleton.Instance.RegisteredPlayers) { - return; + if (player.ProfileId == profile.ProfileId) + { + return; + } } - if (Singleton.Instance.AllAlivePlayersList.Any(x => x.ProfileId == profile.ProfileId)) + foreach (IPlayer player in Singleton.Instance.AllAlivePlayersList) { - return; + if (player.ProfileId == profile.ProfileId) + { + return; + } } if (queuedProfileIds.Contains(profile.ProfileId)) @@ -419,10 +429,10 @@ public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInt private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId) { - ObservedCoopPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(playerId, position, Quaternion.identity, - "Player", isAI == true ? "Bot_" : $"Player_{profile.Nickname}_", EPointOfView.ThirdPerson, profile, isAI, - EUpdateQueue.Update, Player.EUpdateMode.Manual, Player.EUpdateMode.Auto, - GClass548.Config.CharacterController.ObservedPlayerMode, + ObservedCoopPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(playerId, position, + Quaternion.identity, "Player", isAI == true ? "Bot_" : $"Player_{profile.Nickname}_", + EPointOfView.ThirdPerson, profile, isAI, EUpdateQueue.Update, Player.EUpdateMode.Manual, + Player.EUpdateMode.Auto, GClass548.Config.CharacterController.ObservedPlayerMode, () => Singleton.Instance.Control.Settings.MouseSensitivity, () => Singleton.Instance.Control.Settings.MouseAimingSensitivity, GClass1457.Default).Result; @@ -474,7 +484,9 @@ private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position if (profile.Info.Side is EPlayerSide.Bear or EPlayerSide.Usec) { Item backpack = profile.Inventory.Equipment.GetSlot(EquipmentSlot.Backpack).ContainedItem; - backpack?.GetAllItems().Where(i => i != backpack).ExecuteForEach(i => i.SpawnedInSession = true); + backpack?.GetAllItems() + .Where(i => i != backpack) + .ExecuteForEach(i => i.SpawnedInSession = true); // We still want DogTags to be 'FiR' Item item = otherPlayer.Inventory.Equipment.GetSlot(EquipmentSlot.Dogtag).ContainedItem; diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index ac45bc5f..18ce9a35 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -227,13 +227,13 @@ private void ClearEffects() Traverse effectsController = Traverse.Create(cameraClass.EffectsController); - BloodOnScreen bloodOnScreen = effectsController.Field("bloodOnScreen_0").GetValue(); + BloodOnScreen bloodOnScreen = effectsController.Field("bloodOnScreen_0").Value; if (bloodOnScreen != null) { Destroy(bloodOnScreen); } - List effectsManagerList = effectsController.Field("list_0").GetValue>(); + List effectsManagerList = effectsController.Field>("list_0").Value; if (effectsManagerList != null) { foreach (EffectsController.Class576 effectsManager in effectsManagerList) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 9ebd64d2..2b690dec 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -705,7 +705,7 @@ private async Task SendOrReceiveSpawnPoint() { Logger.LogInfo($"Retrieved Spawn Point '{name}' from server"); - Dictionary allSpawnPoints = Traverse.Create(spawnPoints).Field("dictionary_0").GetValue>(); + Dictionary allSpawnPoints = Traverse.Create(spawnPoints).Field>("dictionary_0").Value; foreach (ISpawnPoint spawnPointObject in allSpawnPoints.Keys) { if (spawnPointObject.Id == name) @@ -790,7 +790,7 @@ public override async Task vmethod_2(int playerId, Vector3 position if (MenuUI.Instantiated) { MenuUI menuUI = MenuUI.Instance; - DefaultUIButton backButton = Traverse.Create(menuUI.MatchmakerTimeHasCome).Field("_cancelButton").GetValue(); + DefaultUIButton backButton = Traverse.Create(menuUI.MatchmakerTimeHasCome).Field("_cancelButton").Value; customButton = Instantiate(backButton.gameObject, backButton.gameObject.transform.parent); customButton.gameObject.name = "FikaBackButton"; customButton.gameObject.transform.position = new(customButton.transform.position.x, customButton.transform.position.y - 20, customButton.transform.position.z); @@ -1445,7 +1445,7 @@ public void UpdateExfilPointFromServer(ExfiltrationPoint point, bool enable) public void ResetExfilPointsFromServer(ExfiltrationPoint[] points) { - Dictionary currentExfils = Traverse.Create(GameUi.TimerPanel).Field("dictionary_0").GetValue>(); + Dictionary currentExfils = Traverse.Create(GameUi.TimerPanel).Field>("dictionary_0").Value; foreach (ExitTimerPanel exitTimerPanel in currentExfils.Values) { exitTimerPanel.Close(); @@ -1598,8 +1598,8 @@ public void ClearHostAI(Player player) } } - BotsClass bots = Traverse.Create(botsController_0.BotSpawner).Field("_bots").GetValue(); - HashSet allBots = Traverse.Create(bots).Field("hashSet_0").GetValue>(); + BotsClass bots = Traverse.Create(botsController_0.BotSpawner).Field("_bots").Value; + HashSet allBots = Traverse.Create(bots).Field>("hashSet_0").Value; foreach (BotOwner bot in allBots) { @@ -1994,7 +1994,7 @@ public void HandleExit() private void FireCallback() { - Callback endCallback = Traverse.Create(localGame).Field("callback_0").GetValue>(); + Callback endCallback = Traverse.Create(localGame).Field>("callback_0").Value; localGame.SavePlayer(localPlayer, exitStatus, exitName, false); diff --git a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs index daae1b1e..bf58a3fd 100644 --- a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs +++ b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs @@ -63,7 +63,7 @@ protected void Start() weaponPrefab = ControllerGameObject.GetComponent(); if (UnderbarrelWeapon != null) { - underBarrelManager = Traverse.Create(this).Field("gclass1593_0").GetValue(); + underBarrelManager = Traverse.Create(this).Field("gclass1593_0").Value; } } diff --git a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs index 1e8d7bc0..65d9ac65 100644 --- a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs @@ -173,7 +173,7 @@ private IEnumerator SendTrainTime() Locomotive locomotive = FindObjectOfType(); if (locomotive != null) { - long time = Traverse.Create(locomotive).Field("_depart").GetValue().Ticks; + long time = Traverse.Create(locomotive).Field("_depart").Value.Ticks; GenericPacket packet = new() { diff --git a/Fika.Core/Coop/Patches/Overrides/OfflineRaidSettingsMenuPatch_Override.cs b/Fika.Core/Coop/Patches/Overrides/OfflineRaidSettingsMenuPatch_Override.cs index f2bba600..cc624031 100644 --- a/Fika.Core/Coop/Patches/Overrides/OfflineRaidSettingsMenuPatch_Override.cs +++ b/Fika.Core/Coop/Patches/Overrides/OfflineRaidSettingsMenuPatch_Override.cs @@ -42,7 +42,7 @@ private static void PatchPostfix(RaidSettingsWindow __instance, UiElementBlocker } // Remove redundant settings and add our own "Random" to make the setting clear, while also renaming index 0 to "Together" - List labelList = Traverse.Create(____playersSpawnPlaceDropdown).Field("list_0").GetValue>(); + List labelList = Traverse.Create(____playersSpawnPlaceDropdown).Field>("list_0").Value; labelList.Clear(); labelList.Add(new() { diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index 256a64cd..1083d929 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -34,6 +34,7 @@ namespace Fika.Core.Coop.Players /// public class CoopPlayer : LocalPlayer { + #region Fields and Properties public PacketReceiver PacketReceiver; public IPacketSender PacketSender; private DateTime lastPingTime; @@ -46,7 +47,8 @@ public class CoopPlayer : LocalPlayer public Transform RaycastCameraTransform; public int NetId; public bool IsObservedAI = false; - public Dictionary> OperationCallbacks = []; + public Dictionary> OperationCallbacks = []; + #endregion public static async Task Create(int playerId, Vector3 position, Quaternion rotation, string layerName, string prefix, EPointOfView pointOfView, Profile profile, bool aiControl, diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index 84d50e36..20628f78 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -711,8 +711,8 @@ public PlayerStatePacket Interpolate(in PlayerStatePacket newState, in PlayerSta Move(Vector2.Lerp(newState.MovementDirection, lastState.MovementDirection, interpolationRatio)); } - Vector3 a = Vector3.Lerp(MovementContext.TransformPosition, newState.Position, interpolationRatio); - CharacterController.Move(a - MovementContext.TransformPosition, interpolationRatio); + Vector3 newPosition = Vector3.Lerp(MovementContext.TransformPosition, newState.Position, interpolationRatio); + CharacterController.Move(newPosition - MovementContext.TransformPosition, interpolationRatio); if (!Mathf.Approximately(MovementContext.Tilt, newState.Tilt)) { @@ -822,7 +822,7 @@ public override void SetInventory(EquipmentClass equipmentClass) { Inventory.Equipment = equipmentClass; - BindableState itemInHands = (BindableState)Traverse.Create(this).Field("_itemInHands").GetValue(); + BindableState itemInHands = Traverse.Create(this).Field>("_itemInHands").Value; if (HandsController != null && HandsController.Item != null) { Item item = FindItem(HandsController.Item.Id); @@ -920,13 +920,12 @@ public void InitObservedPlayer() PacketSender.Writer.Reset(); PacketSender.Client.SendData(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); - IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").GetValue(); + IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").Value; if (vaultingComponent != null) { UpdateEvent -= vaultingComponent.DoVaultingTick; } - playerTraverse.Field("_vaultingComponent").SetValue(null); playerTraverse.Field("_vaultingComponentDebug").SetValue(null); playerTraverse.Field("_vaultingParameters").SetValue(null); @@ -951,7 +950,7 @@ public void InitObservedPlayer() CoopGame coopGame = (CoopGame)Singleton.Instance; - IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").GetValue(); + IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").Value; if (vaultingComponent != null) { UpdateEvent -= vaultingComponent.DoVaultingTick; @@ -971,7 +970,7 @@ public void InitObservedPlayer() waitForStartRoutine = StartCoroutine(CreateHealthBar()); - RaycastCameraTransform = playerTraverse.Field("_playerLookRaycastTransform").GetValue(); + RaycastCameraTransform = playerTraverse.Field("_playerLookRaycastTransform").Value; } } @@ -1038,7 +1037,7 @@ public override void LandingAdjustments(float d) public new void CreateCompass() { - bool compassInstantiated = Traverse.Create(this).Field("_compassInstantiated").GetValue(); + bool compassInstantiated = Traverse.Create(this).Field("_compassInstantiated").Value; if (!compassInstantiated) { Transform transform = Singleton.Instance.CreateFromPool(new ResourceKey diff --git a/Fika.Core/UI/FikaUIUtils.cs b/Fika.Core/UI/FikaUIUtils.cs index 24333391..d0ac52f7 100644 --- a/Fika.Core/UI/FikaUIUtils.cs +++ b/Fika.Core/UI/FikaUIUtils.cs @@ -94,7 +94,7 @@ public static GClass3108 ShowFikaMessage(this ErrorScreen errorScreen, string ti errorScreenHandler.context.OnDecline += errorScreen.method_4; errorScreenHandler.context.OnCloseSilent += errorScreen.method_4; - GClass767 ui = Traverse.Create(errorScreen).Field("UI").GetValue(); + GClass767 ui = Traverse.Create(errorScreen).Field("UI").Value; ui.AddDisposable(new Action(errorScreenHandler.method_0)); string text = buttonType switch @@ -115,7 +115,7 @@ public static GClass3108 ShowFikaMessage(this ErrorScreen errorScreen, string ti string string_1 = message.SubstringIfNecessary(500); errorScreenTraverse.Field("string_1").SetValue(string_1); - TextMeshProUGUI errorDescription = Traverse.Create(errorScreen).Field("_errorDescription").GetValue(); + TextMeshProUGUI errorDescription = Traverse.Create(errorScreen).Field("_errorDescription").Value; errorDescription.text = string_1; Coroutine coroutine_0 = errorScreenTraverse.Field("coroutine_0").GetValue();