Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remap, Prepare for new features & Fix F8 Extraction #78

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified References/Assembly-CSharp.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ public class PostRaidHealScreenPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = typeof(ProfileChangeHandler);
return ReflectionHelpers.GetMethodForType(desiredType, "smethod_0");
return ReflectionHelpers.GetMethodForType(typeof(Operation42), "smethod_0");
}

[PatchPrefix]
Expand Down
6 changes: 3 additions & 3 deletions Source/Coop/ASITGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class ASITGame : BaseLocalGame<GamePlayerOwner>, IBotGame
{
public new bool InRaid { get { return true; } }

public IBackEndSession BackEndSession { get { return StayInTarkovHelperConstants.BackEndSession; } }
public ISession BackEndSession { get { return StayInTarkovHelperConstants.BackEndSession; } }

BotsController IBotGame.BotsController
{
Expand Down Expand Up @@ -72,7 +72,7 @@ InputTree inputTree
, Callback<ExitStatus, TimeSpan, ClientMetrics> callback
, float fixedDeltaTime
, EUpdateQueue updateQueue
, IBackEndSession backEndSession
, ISession backEndSession
, TimeSpan sessionTime) where T : ASITGame
{

Expand All @@ -93,7 +93,7 @@ InputTree inputTree
(null, new object[] {
r.gameObject
, location.waves
, new Action<Wave>((wave) => r.PBotsController.ActivateBotsByWave(wave))
, new Action<BotSpawnWave>((wave) => r.PBotsController.ActivateBotsByWave(wave))
, location });

var bosswavemanagerValue = ReflectionHelpers.GetMethodForType(typeof(BossWaveManager), "smethod_0").Invoke
Expand Down
59 changes: 8 additions & 51 deletions Source/Coop/Components/ActionPacketHandlerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,62 +250,19 @@ bool ProcessPlayerPacket(Dictionary<string, object> packet)
return false;
}

//var profilePlayers = Players.Where(x => x.Key == profileId && x.Value != null).ToArray();

// ---------------------------------------------------
// Causes instance reference errors?
//var plyr = Singleton<GameWorld>.Instance.GetAlivePlayerByProfileID(profileId);// Players[profileId];

// ---------------------------------------------------
//
if (!Players.ContainsKey(profileId))
return false;

var plyr = Players[profileId];
bool processed = false;

//foreach (var plyr in profilePlayers)
{
//if (plyr.Value.TryGetComponent<PlayerReplicatedComponent>(out var prc))
var prc = plyr.GetComponent<PlayerReplicatedComponent>();
{
prc.ProcessPacket(packet);
processed = true;
}
//else
//{
// Logger.LogError($"Player {profileId} doesn't have a PlayerReplicatedComponent!");
//}

if (packet.ContainsKey("Extracted"))
{
if (CoopGame != null)
{
//Logger.LogInfo($"Received Extracted ProfileId {packet["profileId"]}");
if (!CoopGame.ExtractedPlayers.Contains(packet["profileId"].ToString()))
CoopGame.ExtractedPlayers.Add(packet["profileId"].ToString());

if (!MatchmakerAcceptPatches.IsClient)
{
var botController = (BotsController)ReflectionHelpers.GetFieldFromTypeByFieldType(typeof(BaseLocalGame<GamePlayerOwner>), typeof(BotsController)).GetValue(Singleton<AbstractGame>.Instance);
if (botController != null)
{
if (!RemovedFromAIPlayers.Contains(profileId))
{
RemovedFromAIPlayers.Add(profileId);
Logger.LogDebug("Removing Client Player to Enemy list");
var botSpawner = (BotSpawner)ReflectionHelpers.GetFieldFromTypeByFieldType(typeof(BotsController), typeof(BotSpawner)).GetValue(botController);
botSpawner.DeletePlayer(plyr);
}
}
}
}

processed = true;
}
}
if(plyr == null)
return false;

return processed;
var prc = plyr.GetComponent<PlayerReplicatedComponent>();
if (prc == null)
return false;

prc.ProcessPacket(packet);
return true;
}

async Task WaitForPlayerAndProcessPacket(string profileId, Dictionary<string, object> packet)
Expand Down
66 changes: 37 additions & 29 deletions Source/Coop/Components/CoopGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace StayInTarkov.Coop
/// <summary>
/// Coop Game Component is the User 1-2-1 communication to the Server. This can be seen as an extension component to CoopGame.
/// </summary>
public class CoopGameComponent : MonoBehaviour, IFrameIndexer
public class CoopGameComponent : MonoBehaviour
{
#region Fields/Properties
public WorldInteractiveObject[] ListOfInteractiveObjects { get; set; }
Expand Down Expand Up @@ -300,7 +300,6 @@ private IEnumerator EverySecondCoroutine()
yield return waitSeconds;

var playersToExtract = new List<string>();
// TODO: Store the exfil point in the ExtractingPlayers dict, need it for timer
foreach (var exfilPlayer in coopGame.ExtractingPlayers)
{
var exfilTime = new TimeSpan(0, 0, (int)exfilPlayer.Value.Item1);
Expand Down Expand Up @@ -329,15 +328,19 @@ private IEnumerator EverySecondCoroutine()
var world = Singleton<GameWorld>.Instance;

// Hide extracted Players
foreach (var playerId in coopGame.ExtractedPlayers)
foreach (var profileId in coopGame.ExtractedPlayers)
{
var player = world.RegisteredPlayers.Find(x => x.ProfileId == playerId) as EFT.Player;
var player = world.RegisteredPlayers.Find(x => x.ProfileId == profileId) as EFT.Player;
if (player == null)
continue;

AkiBackendCommunicationCoop.PostLocalPlayerData(player
, new Dictionary<string, object>() { { "Extracted", true } }
, true);
if (!ExtractedProfilesSent.Contains(profileId))
{
ExtractedProfilesSent.Add(profileId);
AkiBackendCommunicationCoop.PostLocalPlayerData(player
, new Dictionary<string, object>() { { "m", "Extraction" }, { "Extracted", true } }
);
}

if (player.ActiveHealthController != null)
{
Expand All @@ -349,12 +352,18 @@ private IEnumerator EverySecondCoroutine()
player.ActiveHealthController.PauseAllEffects();

player.SwitchRenderer(false);

// TODO: Currently. Destroying your own Player just breaks the game and it appears to be "frozen". Need to learn a new way to do a FreeCam!
if(Singleton<GameWorld>.Instance.MainPlayer.ProfileId != profileId)
GameObject.Destroy(player);
}
}
}
}
}

private HashSet<string> ExtractedProfilesSent = new();

void OnDestroy()
{
StayInTarkovHelperConstants.Logger.LogDebug($"CoopGameComponent:OnDestroy");
Expand Down Expand Up @@ -425,37 +434,36 @@ public EQuitState GetQuitState()
var numberOfPlayersAlive = PlayerUsers.Count(x => x.HealthController.IsAlive);
var numberOfPlayersExtracted = coopGame.ExtractedPlayers.Count;

// Simple check to see if you are dead
if (!Singleton<GameWorld>.Instance.MainPlayer.PlayerHealthController.IsAlive)
{
quitState = EQuitState.YouAreDead;
}

// You are playing with a team
if (PlayerUsers.Count() > 1)
{
// All Player's in the Raid are dead
if (PlayerUsers.Count() == numberOfPlayersDead)
{
quitState = EQuitState.YourTeamIsDead;
}
else if (!Singleton<GameWorld>.Instance.MainPlayer.PlayerHealthController.IsAlive)
{
quitState = EQuitState.YouAreDead;
}
}
else if (PlayerUsers.Any(x => !x.HealthController.IsAlive))
{
quitState = EQuitState.YouAreDead;
}

if (
numberOfPlayersAlive > 0
&&
(numberOfPlayersAlive == numberOfPlayersExtracted || PlayerUsers.Count() == numberOfPlayersExtracted)
)
{
quitState = EQuitState.YourTeamHasExtracted;
}
else if (coopGame.ExtractedPlayers.Contains(Singleton<GameWorld>.Instance.MainPlayer.ProfileId))
// -------------------------
// Extractions
if (coopGame.ExtractedPlayers.Contains(Singleton<GameWorld>.Instance.MainPlayer.ProfileId))
{
if (MatchmakerAcceptPatches.IsClient)
quitState = EQuitState.YouHaveExtractedOnlyAsClient;
else if (MatchmakerAcceptPatches.IsServer)
quitState = EQuitState.YouHaveExtractedOnlyAsHost;
}

if (numberOfPlayersAlive == numberOfPlayersExtracted || PlayerUsers.Count() == numberOfPlayersExtracted)
{
quitState = EQuitState.YourTeamHasExtracted;
}
return quitState;
}

Expand All @@ -479,18 +487,18 @@ void ProcessQuitting()
if (MatchmakerAcceptPatches.IsServer)
{
// A host needs to wait for the team to extract or die!
if ((quitState == EQuitState.YourTeamHasExtracted || quitState == EQuitState.YourTeamIsDead))
if((PlayerUsers.Count() > 1) && (quitState == EQuitState.YouAreDead || quitState == EQuitState.YouHaveExtractedOnlyAsHost))
{
NotificationManagerClass.DisplayWarningNotification("HOSTING: You cannot exit the game until all clients have escaped or dead");
}
else
{
Singleton<ISITGame>.Instance.Stop(
Singleton<GameWorld>.Instance.MainPlayer.ProfileId
, Singleton<ISITGame>.Instance.MyExitStatus
, Singleton<ISITGame>.Instance.MyExitLocation
, 0);
}
else
{
NotificationManagerClass.DisplayWarningNotification("HOSTING: You cannot exit the game until all clients have escaped or dead");
}
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Coop/Components/PlayerReplicatedComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
using static AHealthController<EFT.HealthSystem.ActiveHealthController.AbstractHealthEffect>;
using static AHealthController<EFT.HealthSystem.ActiveHealthController.AbstractEffect>;

namespace StayInTarkov.Core.Player
{
Expand Down Expand Up @@ -321,7 +321,7 @@ void Update()
var packet = new Dictionary<string, object>();
packet.Add("dmt", EDamageType.Undefined.ToString());
packet.Add("m", "Kill");
AkiBackendCommunicationCoop.PostLocalPlayerData(player, packet, true);
AkiBackendCommunicationCoop.PostLocalPlayerData(player, packet);
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions Source/Coop/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public sealed class CoopGame : BaseLocalGame<GamePlayerOwner>, IBotGame, ISITGam

public FriendlyAIPMCSystem FriendlyAIPMCSystem { get; set; } = new FriendlyAIPMCSystem();

public IBackEndSession BackEndSession { get { return StayInTarkovHelperConstants.BackEndSession; } }
public ISession BackEndSession { get { return StayInTarkovHelperConstants.BackEndSession; } }

BotsController IBotGame.BotsController
{
Expand Down Expand Up @@ -107,7 +107,7 @@ InputTree inputTree
, Callback<ExitStatus, TimeSpan, ClientMetrics> callback
, float fixedDeltaTime
, EUpdateQueue updateQueue
, IBackEndSession backEndSession
, ISession backEndSession
, TimeSpan sessionTime)
{
BotsController = null;
Expand All @@ -134,7 +134,7 @@ InputTree inputTree
(null, new object[] {
coopGame.gameObject
, location.waves
, new Action<Wave>((wave) => coopGame.PBotsController.ActivateBotsByWave(wave))
, new Action<BotSpawnWave>((wave) => coopGame.PBotsController.ActivateBotsByWave(wave))
, location });

var bosswavemanagerValue = ReflectionHelpers.GetMethodForType(typeof(BossWaveManager), "smethod_0").Invoke
Expand Down Expand Up @@ -839,7 +839,7 @@ public void CreateExfiltrationPointAndInitDeathHandler()
SpawnPoints spawnPoints = SpawnPoints.CreateFromScene(DateTime.Now, base.Location_0.SpawnPointParams);
int spawnSafeDistance = ((Location_0.SpawnSafeDistanceMeters > 0) ? Location_0.SpawnSafeDistanceMeters : 100);
SpawnSystemSettings settings = new(Location_0.MinDistToFreePoint, Location_0.MaxDistToFreePoint, Location_0.MaxBotPerZone, spawnSafeDistance);
SpawnSystem = SpawnSystemFactory.CreateSpawnSystem(settings, () => Time.time, Singleton<GameWorld>.Instance, PBotsController, spawnPoints);
SpawnSystem = SpawnSystemFactory.CreateSpawnSystem(settings, () => UnityEngine.Time.time, Singleton<GameWorld>.Instance, PBotsController, spawnPoints);

base.GameTimer.Start();
//base.vmethod_5();
Expand Down Expand Up @@ -872,6 +872,9 @@ public void CreateExfiltrationPointAndInitDeathHandler()

private void ExfiltrationPoint_OnCancelExtraction(ExfiltrationPoint point, EFT.Player player)
{
if (player.IsAI)
return;

Logger.LogDebug("ExfiltrationPoint_OnCancelExtraction");
Logger.LogDebug(point.Status);

Expand All @@ -883,6 +886,9 @@ private void ExfiltrationPoint_OnCancelExtraction(ExfiltrationPoint point, EFT.P

private void ExfiltrationPoint_OnStartExtraction(ExfiltrationPoint point, EFT.Player player)
{
if (player.IsAI)
return;

Logger.LogDebug("ExfiltrationPoint_OnStartExtraction");
Logger.LogDebug(point.Settings.Name);
Logger.LogDebug(point.Status);
Expand Down
4 changes: 2 additions & 2 deletions Source/Coop/CoopHealthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace StayInTarkov.Coop
{
internal class CoopHealthController : PlayerHealthController
{
public CoopHealthController(Profile.Health0 healthInfo, EFT.Player player, InventoryController inventoryController, SkillManager skillManager, bool aiHealth)
public CoopHealthController(Profile.ProfileHealth healthInfo, EFT.Player player, InventoryController inventoryController, SkillManager skillManager, bool aiHealth)
: base(healthInfo, player, inventoryController, skillManager, aiHealth)
{
}
Expand All @@ -16,7 +16,7 @@ public override bool ApplyItem(Item item, EBodyPart bodyPart, float? amount = nu
return base.ApplyItem(item, bodyPart, amount);
}

protected override void AddEffectToList(AbstractHealthEffect effect)
protected override void AddEffectToList(AbstractEffect effect)
{
base.AddEffectToList(effect);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Coop/CoopHealthControllerForClientDrone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace StayInTarkov.Coop
{
internal class CoopHealthControllerForClientDrone : PlayerHealthController
{
public CoopHealthControllerForClientDrone(Profile.Health0 healthInfo, EFT.Player player, InventoryController inventoryController, SkillManager skillManager, bool aiHealth)
public CoopHealthControllerForClientDrone(Profile.ProfileHealth healthInfo, EFT.Player player, InventoryController inventoryController, SkillManager skillManager, bool aiHealth)
: base(healthInfo, player, inventoryController, skillManager, aiHealth)
{
}
Expand All @@ -26,7 +26,7 @@ public override bool ApplyItem(Item item, EBodyPart bodyPart, float? amount = nu
return base.ApplyItem(item, bodyPart, amount);
}

protected override void AddEffectToList(AbstractHealthEffect effect)
protected override void AddEffectToList(AbstractEffect effect)
{
base.AddEffectToList(effect);
}
Expand Down
6 changes: 0 additions & 6 deletions Source/Coop/CoopInventoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ public CoopInventoryController(EFT.Player player, Profile profile, bool examined
base.ResetDiscardLimits();
}

public override void Execute(SearchContentOperation operation, Callback callback)
{
//BepInLogger.LogInfo($"CoopInventoryController: {operation}");
base.Execute(operation, callback);
}

public override Task<IResult> LoadMagazine(BulletClass sourceAmmo, MagazineClass magazine, int loadCount, bool ignoreRestrictions)
{
//BepInLogger.LogInfo("LoadMagazine");
Expand Down
Loading