Skip to content

Commit

Permalink
AuthInvOp continued
Browse files Browse the repository at this point in the history
- Fixed nullref on SetupDogTag()
- Fixed boss items not being picked up for other clients
- Fixed adding attachments not playing animation
- Fixed fold not playing animation
  • Loading branch information
Lacyway committed May 12, 2024
1 parent 01634cf commit bcdcdcb
Show file tree
Hide file tree
Showing 13 changed files with 227 additions and 145 deletions.
3 changes: 1 addition & 2 deletions Fika.Core/Coop/BotClasses/CoopBotInventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
packet.ItemControllerExecutePacket = new()
{
CallbackId = operation.Id,
OperationBytes = opBytes,
InventoryId = ID
OperationBytes = opBytes
};

CoopBot.PacketSender?.InventoryPackets?.Enqueue(packet);
Expand Down
55 changes: 22 additions & 33 deletions Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
packet.ItemControllerExecutePacket = new()
{
CallbackId = operation.Id,
OperationBytes = opBytes,
InventoryId = ID
OperationBytes = opBytes
};

CoopPlayer.PacketSender?.InventoryPackets?.Enqueue(packet);
Expand All @@ -79,8 +78,6 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
}
else if (MatchmakerAcceptPatches.IsClient)
{
ConsoleScreen.Log(operation.GetType().ToString());

// Do not replicate picking up quest items, throws an error on the other clients
if (operation is GClass2839 pickupOperation)
{
Expand All @@ -91,12 +88,6 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
}
}

if (operation is GClass2870)
{
base.Execute(operation, callback);
return;
}

InventoryPacket packet = new()
{
HasItemControllerExecutePacket = true
Expand All @@ -119,8 +110,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback
packet.ItemControllerExecutePacket = new()
{
CallbackId = operationNum,
OperationBytes = opBytes,
InventoryId = ID
OperationBytes = opBytes
};

CoopPlayer.PacketSender?.InventoryPackets?.Enqueue(packet);
Expand Down Expand Up @@ -165,24 +155,27 @@ public void HandleResult(Result<EOperationStatus> result)
clientOperationManager = this,
result = result
};
if (callbackManager.result.Succeed && callbackManager.result.Value != EOperationStatus.Failed)

if (callbackManager.result.Succeed)
{
EOperationStatus value = callbackManager.result.Value;
if (value == EOperationStatus.Started)
{
localOperationStatus = EOperationStatus.Started;
serverOperationStatus = EOperationStatus.Started;
operation.vmethod_0(new Callback(callbackManager.HandleResult), false);
operation.vmethod_0(new Callback(callbackManager.HandleResult), true);
return;
}
/*if (value == EOperationStatus.Finished)
if (value == EOperationStatus.Finished)
{
serverOperationStatus = EOperationStatus.Finished;
localOperationStatus = EOperationStatus.Finished;
operation.Dispose();
callback.Succeed();
return;
}*/
if (localOperationStatus == serverOperationStatus)
{
operation.Dispose();
callback.Succeed();
return;
}
}
}
else
{
Expand All @@ -202,33 +195,29 @@ private class ClientInventoryCallbackManager

public void HandleResult(IResult executeResult)
{
if (!executeResult.Succeed)
if (!executeResult.Succeed && (executeResult.Error is not "skipped skippable" or "skipped _completed"))
{
FikaPlugin.Instance.FikaLogger.LogError($"{clientOperationManager.inventoryController.ID} - Client operation critical failure: {clientOperationManager.inventoryController.ID} - {clientOperationManager.operation}\r\nError: {executeResult.Error}");
}

clientOperationManager.operation.Dispose();
clientOperationManager.callback.Invoke(result);
clientOperationManager.localOperationStatus = EOperationStatus.Finished;

/*clientOperationManager.localOperationStatus = EOperationStatus.Finished;
EOperationStatus? serverOperationStatus = clientOperationManager.serverOperationStatus;
EOperationStatus? eoperationStatus = clientOperationManager.localOperationStatus;
if ((serverOperationStatus.GetValueOrDefault() == eoperationStatus.GetValueOrDefault()) & (serverOperationStatus != null == (eoperationStatus != null)))
if (clientOperationManager.localOperationStatus == clientOperationManager.serverOperationStatus)
{
clientOperationManager.operation.Dispose();
clientOperationManager.callback.Invoke(result);
return;
}*/
/*if (clientOperationManager.serverOperationStatus != null)
}

if (clientOperationManager.serverOperationStatus != null)
{
eoperationStatus = clientOperationManager.serverOperationStatus;
if ((eoperationStatus.GetValueOrDefault() == EOperationStatus.Failed) & (eoperationStatus != null))
if (clientOperationManager.serverOperationStatus == EOperationStatus.Failed)
{
clientOperationManager.operation.Dispose();
clientOperationManager.callback.Invoke(result);
}
}*/
}
}
}
}
}
}
2 changes: 1 addition & 1 deletion Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position
{
myPlayer.HealthController.DisableMetabolism();
NotificationManagerClass.DisplayMessageNotification("Metabolism disabled", iconType: EFT.Communications.ENotificationIconType.Alert);
}
}
}

CoopPlayer coopPlayer = (CoopPlayer)myPlayer;
Expand Down
7 changes: 2 additions & 5 deletions Fika.Core/Coop/ObservedClasses/ObservedInventoryController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// © 2024 Lacyway All Rights Reserved

using Comfort.Common;
using Diz.LanguageExtensions;
using EFT;
using EFT.InventoryLogic;

namespace Fika.Core.Coop.ObservedClasses
{
Expand Down Expand Up @@ -37,7 +34,7 @@ public override bool IsInventoryBlocked()
return false;
}

public override void InProcess(TraderControllerClass executor, Item item, ItemAddress to, bool succeed, GInterface338 operation, Callback callback)
/*public override void InProcess(TraderControllerClass executor, Item item, ItemAddress to, bool succeed, GInterface338 operation, Callback callback)
{
if (!succeed)
{
Expand All @@ -50,6 +47,6 @@ public override void InProcess(TraderControllerClass executor, Item item, ItemAd
return;
}
callback.Succeed();
}
}*/
}
}
89 changes: 32 additions & 57 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,32 @@ public virtual void DoObservedVault(VaultPacket vaultPacket)

}

public void HandleCallbackFromServer(in OperationCallbackPacket operationCallbackPacket)
{
if (OperationCallbacks.TryGetValue(operationCallbackPacket.CallbackId, out Callback<EOperationStatus> callback))
{
if (operationCallbackPacket.OperationStatus != EOperationStatus.Started)
{
OperationCallbacks.Remove(operationCallbackPacket.CallbackId);
}
if (operationCallbackPacket.OperationStatus != EOperationStatus.Failed)
{
callback(new Result<EOperationStatus>(operationCallbackPacket.OperationStatus));
}
else
{
callback(new Result<EOperationStatus>(EOperationStatus.Failed)
{
Error = operationCallbackPacket.Error
});
}
}
else
{
FikaPlugin.Instance.FikaLogger.LogError($"Could not find CallbackId {operationCallbackPacket.CallbackId}!");
}
}

public virtual void HandleInventoryPacket(in InventoryPacket packet)
{
if (packet.HasItemControllerExecutePacket)
Expand All @@ -1064,36 +1090,9 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
{
GStruct411 result = ToInventoryOperation(binaryReader.ReadPolymorph<GClass1532>());

if (IsYourPlayer)
{
if (OperationCallbacks.TryGetValue(packet.ItemControllerExecutePacket.CallbackId, out Callback<EOperationStatus> callback))
{
OperationCallbacks.Remove(packet.ItemControllerExecutePacket.CallbackId);
if (!result.Failed)
{
callback(new Result<EOperationStatus>(EOperationStatus.Started));
}
else
{
callback(new Result<EOperationStatus>(EOperationStatus.Failed)
{
Error = result.Error.ToString()
});
}
}
else
{
FikaPlugin.Instance.FikaLogger.LogError($"Could not find CallbackId {packet.ItemControllerExecutePacket.CallbackId}!");
}
return;
}

InventoryOperationHandler opHandler = new()
{
opResult = result,
inventoryId = _inventoryController.ID,
operationId = packet.ItemControllerExecutePacket.CallbackId,
netId = NetId
opResult = result
};

opHandler.opResult.Value.vmethod_0(new Callback(opHandler.HandleResult), false);
Expand Down Expand Up @@ -1144,7 +1143,7 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
}
}

// Fix for folding not replicating
/*// Fix for folding not replicating
if (result.Value is GClass2858 foldOperation)
{
if (HandsController is CoopObservedFirearmController observedFirearmController)
Expand All @@ -1154,14 +1153,14 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
observedFirearmController.InitiateOperation<FirearmController.Class1020>().Start(foldOperation, null);
}
}
}
}*/
}
catch (Exception exception)
{
FikaPlugin.Instance.FikaLogger.LogError($"ItemControllerExecutePacket::Exception thrown: {exception}");
if (MatchmakerAcceptPatches.IsServer)
{
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, false);
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, EOperationStatus.Failed);
Singleton<FikaServer>.Instance.SendDataToAll(new(), ref callbackPacket, LiteNetLib.DeliveryMethod.ReliableOrdered);
}
}
Expand All @@ -1171,7 +1170,7 @@ public virtual void HandleInventoryPacket(in InventoryPacket packet)
FikaPlugin.Instance.FikaLogger.LogError("ItemControllerExecutePacket: inventory was null!");
if (MatchmakerAcceptPatches.IsServer)
{
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, false);
OperationCallbackPacket callbackPacket = new(NetId, packet.ItemControllerExecutePacket.CallbackId, EOperationStatus.Failed);
Singleton<FikaServer>.Instance.SendDataToAll(new(), ref callbackPacket, LiteNetLib.DeliveryMethod.ReliableOrdered);
}
}
Expand Down Expand Up @@ -1351,7 +1350,6 @@ public virtual void HandleDamagePacket(DamagePacket packet)
}
}

//ClientApplyDamageInfo(damageInfo, packet.ApplyDamageInfo.BodyPartType, packet.ApplyDamageInfo.ColliderType, packet.ApplyDamageInfo.Absorbed);
ClientApplyShot(damageInfo, packet.DamageInfo.BodyPartType, packet.DamageInfo.ColliderType, packet.DamageInfo.ArmorPlateCollider);
}

Expand Down Expand Up @@ -1384,7 +1382,7 @@ public virtual void SetupDogTag()
dogtagComponent.Level = Profile.Info.Experience > 0 ? Profile.Info.Level : 1;
dogtagComponent.Time = DateTime.Now;
dogtagComponent.Status = "Killed by ";
dogtagComponent.WeaponName = LastDamageInfo.Weapon.Name;
dogtagComponent.WeaponName = LastDamageInfo.Weapon != null ? LastDamageInfo.Weapon.Name : "Unknown";
dogtagComponent.GroupId = GroupId;
}
}
Expand Down Expand Up @@ -1470,36 +1468,13 @@ internal void HandleKeyEvent()
private class InventoryOperationHandler()
{
public GStruct411 opResult;
public string inventoryId;
public uint operationId;
public int netId;

internal void HandleResult(IResult result)
{
if (!result.Succeed || !string.IsNullOrEmpty(result.Error))
{
FikaPlugin.Instance.FikaLogger.LogError($"Error in operation: {result.Error}");
}
if (MatchmakerAcceptPatches.IsServer)
{
InventoryPacket packet = new(netId)
{
HasItemControllerExecutePacket = true
};

using MemoryStream memoryStream = new();
using BinaryWriter binaryWriter = new(memoryStream);
binaryWriter.WritePolymorph(GClass1632.FromInventoryOperation(opResult.Value, false));
byte[] opBytes = memoryStream.ToArray();
packet.ItemControllerExecutePacket = new()
{
CallbackId = operationId,
OperationBytes = opBytes,
InventoryId = inventoryId
};

Singleton<FikaServer>.Instance.SendDataToAll(new(), ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);
}
}
}

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 @@ -150,7 +150,7 @@ public static async Task<LocalPlayer> CreateObservedPlayer(

player.IsYourPlayer = false;

InventoryControllerClass inventoryController = new ObservedInventoryController(player, profile, false);
InventoryControllerClass inventoryController = new ObservedInventoryController(player, profile, true);

PlayerHealthController tempController = new(profile.Health, player, inventoryController, profile.Skills, aiControl);
byte[] healthBytes = tempController.SerializeState();
Expand Down
15 changes: 6 additions & 9 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using Fika.Core.UI.Models;
using Fika.Core.UI.Patches;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
Expand All @@ -49,26 +50,20 @@ public class FikaPlugin : BaseUnityPlugin
/// Stores the Instance of this Plugin
/// </summary>
public static FikaPlugin Instance;

public static InternalBundleLoader BundleLoaderPlugin { get; private set; }

/// <summary>
/// If any mod dependencies fail, show an error. This is a flag to say it has occurred.
/// </summary>
private bool ShownDependencyError { get; set; }

/// <summary>
/// This is the Official EFT Version defined by BSG
/// </summary>
public static string EFTVersionMajor { get; internal set; }

public static string[] LoadedPlugins { get; private set; }

public ManualLogSource FikaLogger { get => Logger; }

public BotDifficulties BotDifficulties;

public string Locale { get; private set; } = "en";
public string[] LocalIPs;

public static Dictionary<string, string> RespectedPlayersList = new()
{
Expand Down Expand Up @@ -356,7 +351,7 @@ private void SetupConfig()

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 }));

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.", new AcceptableValueList<string>(GetLocalIPAddress()), 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.", new AcceptableValueList<string>(GetLocalAddresses()), new ConfigurationManagerAttributes() { Order = 5 }));

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<float>(3f, 60f), new ConfigurationManagerAttributes() { Order = 4 }));

Expand All @@ -373,7 +368,7 @@ private void SetupConfig()
ArmpitDamageMultiplier = Config.Bind("Gameplay", "Armpit Damage Multiplier", 1f, new ConfigDescription("X multiplier to damage taken on the armpits collider. 0.2 = 20%", new AcceptableValueRange<float>(0.2f, 1f), new ConfigurationManagerAttributes() { Order = 1 }));
}

private string[] GetLocalIPAddress()
private string[] GetLocalAddresses()
{
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
List<string> ips = [];
Expand All @@ -385,6 +380,8 @@ private string[] GetLocalIPAddress()
ips.Add(ip.ToString());
}
}

LocalIPs = ips.Skip(1).ToArray();
return [.. ips];
}

Expand Down
Loading

0 comments on commit bcdcdcb

Please sign in to comment.