Skip to content

Commit

Permalink
Merge pull request #162 from project-fika/dev
Browse files Browse the repository at this point in the history
Dev > Main
  • Loading branch information
Lacyway authored Sep 6, 2024
2 parents 9de9eca + 4a97495 commit 124733c
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 92 deletions.
1 change: 0 additions & 1 deletion Fika.Core/Coop/Airdrops/FikaAirdropsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Fika.Core.Coop.Utils;
using Fika.Core.Networking;
using LiteNetLib;
using LiteNetLib.Utils;
using SPT.Custom.Airdrops;
using System;
using System.Collections;
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/BTR/FikaBTRManager_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Fika.Core.Networking;
using GPUInstancer;
using HarmonyLib;
using LiteNetLib.Utils;
using SPT.Custom.BTR;
using SPT.Custom.BTR.Utils;
using SPT.SinglePlayer.Utils.TraderServices;
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/BTR/FikaBTRManager_Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using GPUInstancer;
using HarmonyLib;
using LiteNetLib;
using LiteNetLib.Utils;
using SPT.Custom.BTR;
using SPT.Custom.BTR.Utils;
using SPT.SinglePlayer.Utils.TraderServices;
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/Components/CoopExfilManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Fika.Core.Coop.Utils;
using Fika.Core.Networking;
using LiteNetLib;
using LiteNetLib.Utils;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/Components/CoopHalloweenEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Fika.Core.Coop.Utils;
using Fika.Core.Networking;
using LiteNetLib;
using LiteNetLib.Utils;
using System;
using UnityEngine;

Expand Down
53 changes: 7 additions & 46 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Fika.Core.Networking;
using Fika.Core.Utils;
using LiteNetLib;
using LiteNetLib.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -505,9 +504,13 @@ private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position
#if DEBUG
Logger.LogInfo($"CreateLocalPlayer::{profile.Info.Nickname}::Spawned.");
#endif

SetWeaponInHandsOfNewPlayer(otherPlayer);

otherPlayer.SetFirstAvailableItem((result) =>
{
if (result.Failed)
{
Logger.LogError($"SetFirstAvailableItem: Failed to set the first available item for {otherPlayer.Profile.Info.MainProfileNickname}");
}
});
return otherPlayer;
}

Expand Down Expand Up @@ -554,47 +557,5 @@ private IEnumerator AddClientToBotEnemies(BotsController botController, LocalPla
Logger.LogError($"Failed to add {playerToAdd.Profile.Nickname} to the enemy list.");
}
}

/// <summary>
/// Attempts to set up the New Player with the current weapon after spawning
/// </summary>
/// <param name="player">The player to set the item on</param>
public void SetWeaponInHandsOfNewPlayer(Player player)
{
EquipmentClass equipment = player.Profile.Inventory.Equipment;
if (equipment == null)
{
Logger.LogError($"SetWeaponInHandsOfNewPlayer: {player.Profile.Nickname}, {player.Profile.ProfileId} has no Equipment!");
}
Item item = null;

if (equipment.GetSlot(EquipmentSlot.FirstPrimaryWeapon).ContainedItem != null)
{
item = equipment.GetSlot(EquipmentSlot.FirstPrimaryWeapon).ContainedItem;
}

if (item == null && equipment.GetSlot(EquipmentSlot.SecondPrimaryWeapon).ContainedItem != null)
{
item = equipment.GetSlot(EquipmentSlot.SecondPrimaryWeapon).ContainedItem;
}

if (item == null && equipment.GetSlot(EquipmentSlot.Holster).ContainedItem != null)
{
item = equipment.GetSlot(EquipmentSlot.Holster).ContainedItem;
}

if (item == null && equipment.GetSlot(EquipmentSlot.Scabbard).ContainedItem != null)
{
item = equipment.GetSlot(EquipmentSlot.Scabbard).ContainedItem;
}

player.SetItemInHands(item, (IResult) =>
{
if (IResult.Failed == true)
{
Logger.LogError($"SetWeaponInHandsOfNewPlayer: Unable to set item {item} in hands for {player.Profile.Nickname}, {player.Profile.ProfileId}");
}
});
}
}
}
1 change: 0 additions & 1 deletion Fika.Core/Coop/FreeCamera/FreeCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Fika.Core.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using UnityEngine;

Expand Down
13 changes: 10 additions & 3 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
using HarmonyLib;
using JsonType;
using LiteNetLib;
using LiteNetLib.Utils;
using Newtonsoft.Json;
using SPT.Common.Http;
using SPT.SinglePlayer.Models.Progression;
Expand Down Expand Up @@ -738,6 +737,14 @@ private IEnumerator WaitForOtherPlayers()
{
DynamicAI.AddHumans();
}

InformationPacket finalPacket = new(false)
{
NumberOfPlayers = server.NetServer.ConnectedPeersCount,
ReadyPlayers = server.ReadyClients
};

server.SendDataToAll(ref finalPacket, DeliveryMethod.ReliableOrdered);
}
else
{
Expand Down Expand Up @@ -2304,7 +2311,7 @@ public void HandleExit()
if (screenManager.CheckCurrentScreen(EEftScreenType.Reconnect))
{
screenManager.CloseAllScreensForced();
}
}
localGame.gparam_0.Player.OnGameSessionEnd(exitStatus, localGame.PastTime, localGame.Location_0.Id, exitName);
localGame.CleanUp();
localGame.Status = GameStatus.Stopped;
Expand All @@ -2324,7 +2331,7 @@ public void HandleExit()
}
localGame.iSession.OfflineRaidEnded(exitStatus, exitName, timeSpan.TotalSeconds).HandleExceptions();
MonoBehaviourSingleton<BetterAudio>.Instance.FadeOutVolumeAfterRaid();
StaticManager staticManager = StaticManager.Instance;
StaticManager staticManager = StaticManager.Instance;
float num = delay;
EndAction = new Action(FireCallback);
staticManager.WaitSeconds(num, EndAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Fika.Core.Networking;
using Fika.Core.Networking.Packets.GameWorld;
using LiteNetLib;
using LiteNetLib.Utils;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public override void OnPlayerDead()
catch (Exception ex)
{
FikaPlugin.Instance.FikaLogger.LogError("CoopObservedFirearmController: Exception was caught: " + ex.Message);
}
}
}

private IEnumerator BreakFiringLoop()
Expand Down
18 changes: 4 additions & 14 deletions Fika.Core/Coop/ObservedClasses/ObservedInventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,9 @@ public override bool IsInventoryBlocked()
return false;
}

/*public override void InProcess(TraderControllerClass executor, Item item, ItemAddress to, bool succeed, GInterface338 operation, Callback callback)
{
if (!succeed)
{
callback.Succeed();
return;
}
if (!executor.CheckTransferOwners(item, to, out Error error))
{
callback.Fail(error.ToString());
return;
}
callback.Succeed();
}*/
public void SetNewID(MongoID newId)
{
mongoID_0 = newId;
}
}
}
2 changes: 1 addition & 1 deletion Fika.Core/Coop/PacketHandlers/BotPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void FixedUpdate()

Server.SendDataToAll(ref playerStatePacket, DeliveryMethod.Unreliable);

if (!mover.IsMoving || mover.Pause)
if (!mover.IsMoving || mover.Pause || player.MovementContext.CanWalk)
{
player.LastDirection = Vector2.zero;
}
Expand Down
1 change: 0 additions & 1 deletion Fika.Core/Coop/Patches/LocalGame/GameWorld_Create_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using EFT;
using Fika.Core.Coop.ClientClasses;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Utils;
using HarmonyLib;
using SPT.Reflection.Patching;
Expand Down
7 changes: 3 additions & 4 deletions Fika.Core/Coop/Players/CoopBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using Fika.Core.Coop.Utils;
using Fika.Core.Networking;
using Fika.Core.Utils;
using LiteNetLib.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -211,9 +210,9 @@ public override void OnDead(EDamageType damageType)
if (LastAggressor is CoopPlayer aggressor)
{
if (aggressor.gameObject.name.StartsWith("Player_") || aggressor.IsYourPlayer)
NotificationManagerClass.DisplayMessageNotification(string.Format(LocaleUtils.KILLED_BOSS.Localized(),
[ColorizeText(Colors.GREEN, LastAggressor.Profile.Info.MainProfileNickname), ColorizeText(Colors.BROWN, name)]),
iconType: EFT.Communications.ENotificationIconType.Friend);
NotificationManagerClass.DisplayMessageNotification(string.Format(LocaleUtils.KILLED_BOSS.Localized(),
[ColorizeText(Colors.GREEN, LastAggressor.Profile.Info.MainProfileNickname), ColorizeText(Colors.BROWN, name)]),
iconType: EFT.Communications.ENotificationIconType.Friend);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public override void Move(Vector2 direction)
base.Move(direction);
LastDirection = direction;
}
}
}

private void HandleInteractPacket(WorldInteractionPacket packet)
{
Expand Down Expand Up @@ -1098,14 +1098,19 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
try
{
GStruct411 result = ToInventoryOperation(binaryReader.ReadPolymorph<GClass1543>());
if (!result.Succeeded)
{
FikaPlugin.Instance.FikaLogger.LogError($"HandleInventoryPacket::Unable to process descriptor from netid {NetId}, error: {result.Error}");
return;
}

InventoryOperationHandler opHandler = new(result);

opHandler.opResult.Value.vmethod_0(new Callback(opHandler.HandleResult), false);
}
catch (Exception exception)
{
FikaPlugin.Instance.FikaLogger.LogError($"ItemControllerExecutePacket::Exception thrown: {exception}");
FikaPlugin.Instance.FikaLogger.LogError($"HandleInventoryPacket::Exception thrown on netId {NetId}, {Profile.Info.MainProfileNickname}: {exception}");
if (FikaBackendUtils.IsServer)
{
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, EOperationStatus.Failed);
Expand All @@ -1115,7 +1120,7 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
}
else
{
FikaPlugin.Instance.FikaLogger.LogError("ItemControllerExecutePacket: inventory was null!");
FikaPlugin.Instance.FikaLogger.LogError("HandleInventoryPacket: inventory was null!");
if (FikaBackendUtils.IsServer)
{
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, EOperationStatus.Failed);
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public void InitObservedPlayer(bool isDedicatedHost)

if (FikaPlugin.ShowNotifications.Value && !isDedicatedHost)
{
NotificationManagerClass.DisplayMessageNotification(string.Format(LocaleUtils.GROUP_MEMBER_SPAWNED.Localized(),
NotificationManagerClass.DisplayMessageNotification(string.Format(LocaleUtils.GROUP_MEMBER_SPAWNED.Localized(),
ColorizeText(Colors.GREEN, Profile.Info.MainProfileNickname)),
EFT.Communications.ENotificationDurationType.Default, EFT.Communications.ENotificationIconType.Friend);
}
Expand Down
6 changes: 3 additions & 3 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Fika.Core
/// Originally by: Paulov <br/>
/// Re-written by: Lacyway
/// </summary>
[BepInPlugin("com.fika.core", "Fika.Core", "0.9.9003")]
[BepInPlugin("com.fika.core", "Fika.Core", "0.9.9015")]
[BepInProcess("EscapeFromTarkov.exe")]
[BepInDependency("com.SPT.custom", BepInDependency.DependencyFlags.HardDependency)] // This is used so that we guarantee to load after spt-custom, that way we can disable its patches
[BepInDependency("com.SPT.singleplayer", BepInDependency.DependencyFlags.HardDependency)] // This is used so that we guarantee to load after spt-singleplayer, that way we can disable its patches
Expand Down Expand Up @@ -241,7 +241,7 @@ protected void Awake()
#if GOLDMASTER
new TOS_Patch().Enable();
#endif
OfficialVersion.SettingChanged += OfficialVersion_SettingChanged;
OfficialVersion.SettingChanged += OfficialVersion_SettingChanged;

DisableSPTPatches();
EnableOverridePatches();
Expand Down Expand Up @@ -291,7 +291,7 @@ private void VerifyServerVersion()
else
{
FikaLogger.LogInfo($"Server version check passed. Expected: >{RequiredServerVersion}, received: {serverVersion}");
}
}
}

/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Fika.Core.Coop.Factories;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Lighthouse;
using Fika.Core.Coop.ObservedClasses;
using Fika.Core.Coop.Players;
using Fika.Core.Coop.Utils;
using Fika.Core.Modding;
Expand Down Expand Up @@ -120,6 +121,7 @@ public async void Init()
packetProcessor.SubscribeNetSerializable<WorldLootPacket>(OnWorldLootPacketReceived);
packetProcessor.SubscribeNetSerializable<ReconnectPacket>(OnReconnectPacketReceived);
packetProcessor.SubscribeNetSerializable<LightkeeperGuardDeathPacket>(OnLightkeeperGuardDeathPacketReceived);
packetProcessor.SubscribeNetSerializable<ResyncInventoryPacket>(OnResyncInventoryPacketReceived);

netClient = new NetManager(this)
{
Expand Down Expand Up @@ -168,6 +170,29 @@ public async void Init()
FikaEventDispatcher.DispatchEvent(new FikaClientCreatedEvent(this));
}

private void OnResyncInventoryPacketReceived(ResyncInventoryPacket packet)
{
if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply))
{
if (playerToApply is ObservedCoopPlayer observedPlayer)
{
if (observedPlayer.InventoryControllerClass is ObservedInventoryController observedController)
{
observedController.SetNewID(new(packet.MongoId));
}
return;
}
if (playerToApply.IsYourPlayer)
{
ResyncInventoryPacket response = new(playerToApply.NetId)
{
MongoId = playerToApply.InventoryControllerClass.CurrentId.ToString()
};
SendData(ref response, DeliveryMethod.ReliableOrdered);
}
}
}

private void OnReconnectPacketReceived(ReconnectPacket packet)
{
if (!packet.IsRequest)
Expand Down
Loading

0 comments on commit 124733c

Please sign in to comment.