Skip to content

Commit

Permalink
Merge pull request #50 from project-fika/dev
Browse files Browse the repository at this point in the history
dev > main
  • Loading branch information
Lacyway authored May 19, 2024
2 parents ce9f007 + 6fdc599 commit 7b37d84
Show file tree
Hide file tree
Showing 48 changed files with 1,000 additions and 805 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Aki.Custom.Airdrops.Patches
{
public class FikaAirdropFlarePatch : ModulePatch
public class FikaAirdropFlare_Patch : ModulePatch
{
private static readonly string[] _usableFlares = ["624c09cfbc2e27219346d955", "62389ba9a63f32501b1b4451"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Fika.Core.AkiSupport.Overrides
{
internal class AddEnemyToAllGroupsInBotZonePatchOverride : ModulePatch
internal class AddEnemyToAllGroupsInBotZonePatch_Override : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
Expand Down Expand Up @@ -37,7 +37,9 @@ private static bool PatchPrefix(BotsController __instance, IPlayer aggressor, IP
if (aggressor is ObservedCoopPlayer)
{
if (target.IsYourPlayer)
{
return false;
}
}

BotZone botZone = groupOwner.AIData.BotOwner.BotsGroup.BotZone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Fika.Core.AkiSupport.Overrides
{
public class BotDifficultyPatchOverride : ModulePatch
public class BotDifficultyPatch_Override : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace Fika.Core.AkiSupport.Overrides
{
internal class BotTemplateLimitPatchOverride : ModulePatch
internal class BotTemplateLimitPatch_Override : ModulePatch
{
static BotTemplateLimitPatchOverride()
static BotTemplateLimitPatch_Override()
{
_ = nameof(BotsPresets.CreateProfile);
_ = nameof(WaveInfo.Difficulty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Fika.Core.AkiSupport.Overrides
{
internal class MaxBotPatchOverride : ModulePatch
internal class MaxBotPatch_Override : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Fika.Core.AkiSupport.Overrides
{
public class OfflineRaidSettingsMenuPatchOverride : ModulePatch
public class OfflineRaidSettingsMenuPatch_Override : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Fika.Core.AkiSupport.Scav
{
internal class ScavProfileLoadOverride : ModulePatch
internal class ScavProfileLoad_Override : ModulePatch
{
protected override MethodBase GetTargetMethod() => typeof(TarkovApplication).GetMethod(nameof(TarkovApplication.method_46));

Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/BotClasses/BotMovementContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class BotMovementContext : MovementContext

public override void ApplyGravity(ref Vector3 motion, float deltaTime, bool stickToGround)
{
if (!Bot.isStarted || Bot.AIData.BotOwner.BotState == EBotState.NonActive)
if (Bot.AIData.BotOwner.BotState == EBotState.NonActive)
{
return;
}
Expand Down
6 changes: 0 additions & 6 deletions Fika.Core/Coop/ClientClasses/CoopClientStatisticsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ public sealed class CoopClientStatisticsManager(Profile profile) : GClass1790()
{
public Profile Profile = profile;

public override void BeginStatisticsSession()
{
//player_0.OnSpecialPlaceVisited += OnSpecialPlaceVisited;
base.BeginStatisticsSession();
}

public new void Init(Profile profile, IHealthController healthController)
{
Profile_0 = Profile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,7 @@ public override void ReloadBarrels(GClass2495 ammoPack, GClass2769 placeToPutCon
return;
}

ReloadBarrelsHandler handler = new()
{
coopPlayer = coopPlayer,
coopClientFirearmController = this,
placeToPutContainedAmmoMagazine = placeToPutContainedAmmoMagazine,
ammoPack = ammoPack
};

ReloadBarrelsHandler handler = new(coopPlayer, placeToPutContainedAmmoMagazine, ammoPack);
CurrentOperation.ReloadBarrels(ammoPack, placeToPutContainedAmmoMagazine, callback, new Callback(handler.Process));
}

Expand All @@ -303,18 +296,8 @@ public override void ReloadCylinderMagazine(GClass2495 ammoPack, Callback callba
return;
}

ReloadCylinderMagazineHandler handler = new()
{
coopPlayer = coopPlayer,
coopClientFirearmController = this,
quickReload = quickReload,
ammoIds = ammoPack.GetReloadingAmmoIds(),
cylinderMagazine = (CylinderMagazineClass)Item.GetCurrentMagazine(),
shellsIndexes = []
};

ReloadCylinderMagazineHandler handler = new(coopPlayer, this, quickReload, ammoPack.GetReloadingAmmoIds(), [], (CylinderMagazineClass)Item.GetCurrentMagazine());
Weapon.GetShellsIndexes(handler.shellsIndexes);

CurrentOperation.ReloadCylinderMagazine(ammoPack, callback, new Callback(handler.Process), handler.quickReload);
}

Expand Down Expand Up @@ -346,14 +329,7 @@ public override void ReloadMag(MagazineClass magazine, GClass2769 gridItemAddres
return;
}

ReloadMagHandler handler = new()
{
coopPlayer = coopPlayer,
coopClientFirearmController = this,
gridItemAddress = gridItemAddress,
magazine = magazine
};

ReloadMagHandler handler = new(coopPlayer, gridItemAddress, magazine);
CurrentOperation.ReloadMag(magazine, gridItemAddress, callback, new Callback(handler.Process));
}

Expand All @@ -368,13 +344,7 @@ public override void ReloadWithAmmo(GClass2495 ammoPack, Callback callback)
return;
}

ReloadWithAmmoHandler handler = new()
{
coopPlayer = coopPlayer,
coopClientFirearmController = this,
ammoIds = ammoPack.GetReloadingAmmoIds()
};

ReloadWithAmmoHandler handler = new(coopPlayer, ammoPack.GetReloadingAmmoIds());
CurrentOperation.ReloadWithAmmo(ammoPack, callback, new Callback(handler.Process));
}

Expand Down Expand Up @@ -608,7 +578,7 @@ public override void SwitchToIdle()
base.SwitchToIdle();
}

private CoopClientFirearmController coopClientFirearmController = (CoopClientFirearmController)controller;
private readonly CoopClientFirearmController coopClientFirearmController = (CoopClientFirearmController)controller;
}

private class FirearmClass3(Player.FirearmController controller) : GClass1591(controller)
Expand All @@ -629,7 +599,7 @@ public override void SwitchToIdle()
base.SwitchToIdle();
}

private CoopClientFirearmController coopClientFirearmController = (CoopClientFirearmController)controller;
private readonly CoopClientFirearmController coopClientFirearmController = (CoopClientFirearmController)controller;
}

private class FirearmClass4(Player.FirearmController controller) : GClass1602(controller)
Expand Down Expand Up @@ -689,8 +659,12 @@ public override void Reset()
private bool hasSent;
}

private class ReloadMagHandler
private class ReloadMagHandler(CoopPlayer coopPlayer, GClass2769 gridItemAddress, MagazineClass magazine)
{
private readonly CoopPlayer coopPlayer = coopPlayer;
private readonly GClass2769 gridItemAddress = gridItemAddress;
private readonly MagazineClass magazine = magazine;

public void Process(IResult error)
{
GClass1528 gridItemAddressDescriptor = (gridItemAddress == null) ? null : GClass1632.FromGridItemAddress(gridItemAddress);
Expand Down Expand Up @@ -722,15 +696,17 @@ public void Process(IResult error)
});
}
}

public CoopPlayer coopPlayer;
public GClass2769 gridItemAddress;
public CoopClientFirearmController coopClientFirearmController;
public MagazineClass magazine;
}

private class ReloadCylinderMagazineHandler
private class ReloadCylinderMagazineHandler(CoopPlayer coopPlayer, CoopClientFirearmController coopClientFirearmController, bool quickReload, string[] ammoIds, List<int> shellsIndexes, CylinderMagazineClass cylinderMagazine)
{
private readonly CoopPlayer coopPlayer = coopPlayer;
private readonly CoopClientFirearmController coopClientFirearmController = coopClientFirearmController;
public readonly bool quickReload = quickReload;
private readonly string[] ammoIds = ammoIds;
public readonly List<int> shellsIndexes = shellsIndexes;
private readonly CylinderMagazineClass cylinderMagazine = cylinderMagazine;

public void Process(IResult error)
{
coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new()
Expand All @@ -751,22 +727,19 @@ public void Process(IResult error)
}
});
}

public CoopPlayer coopPlayer;
public CoopClientFirearmController coopClientFirearmController;
public bool quickReload;
public string[] ammoIds;
public List<int> shellsIndexes;
public CylinderMagazineClass cylinderMagazine;
}

private class ReloadBarrelsHandler
private class ReloadBarrelsHandler(CoopPlayer coopPlayer, GClass2769 placeToPutContainedAmmoMagazine, GClass2495 ammoPack)
{
private readonly CoopPlayer coopPlayer = coopPlayer;
private readonly GClass2769 placeToPutContainedAmmoMagazine = placeToPutContainedAmmoMagazine;
private readonly GClass2495 ammoPack = ammoPack;

public void Process(IResult error)
{
GClass1528 gridItemAddressDescriptor = (placeToPutContainedAmmoMagazine == null) ? null : GClass1632.FromGridItemAddress(placeToPutContainedAmmoMagazine);

var ammoIds = ammoPack.GetReloadingAmmoIds();
string[] ammoIds = ammoPack.GetReloadingAmmoIds();

using MemoryStream memoryStream = new();
using BinaryWriter binaryWriter = new(memoryStream);
Expand Down Expand Up @@ -795,16 +768,13 @@ public void Process(IResult error)
});
}
}

public CoopPlayer coopPlayer;
public CoopClientFirearmController coopClientFirearmController;
public GClass2769 placeToPutContainedAmmoMagazine;
public GClass2495 ammoPack;

}

private class ReloadWithAmmoHandler()
private class ReloadWithAmmoHandler(CoopPlayer coopPlayer, string[] ammoIds)
{
private readonly CoopPlayer coopPlayer = coopPlayer;
private readonly string[] ammoIds = ammoIds;

public void Process(IResult error)
{
if (error.Succeed)
Expand All @@ -821,10 +791,6 @@ public void Process(IResult error)
});
}
}

public CoopPlayer coopPlayer;
public CoopClientFirearmController coopClientFirearmController;
public string[] ammoIds;
}
}
}
37 changes: 20 additions & 17 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,16 @@ public class SpawnObject(Profile profile, Vector3 position, bool isAlive, bool i

public static CoopHandler GetCoopHandler()
{
if (CoopHandler.CoopHandlerParent == null)
if (CoopHandlerParent == null)
{
return null;
}

CoopHandler coopHandler = CoopHandler.CoopHandlerParent.GetComponent<CoopHandler>();
if (coopHandler != null)
{
return coopHandler;
}

return null;
}
Expand Down Expand Up @@ -398,7 +402,7 @@ private IEnumerator ProcessSpawnQueue()
{
while (true)
{
yield return new WaitForSeconds(0.5f);
yield return new WaitForSeconds(1f);

if (Singleton<AbstractGame>.Instantiated)
{
Expand All @@ -421,13 +425,19 @@ private IEnumerator ProcessSpawnQueue()
public void QueueProfile(Profile profile, Vector3 position, int netId, bool isAlive = true, bool isAI = false)
{
if (Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.ProfileId == profile.ProfileId))
{
return;
}

if (Singleton<GameWorld>.Instance.AllAlivePlayersList.Any(x => x.ProfileId == profile.ProfileId))
{
return;
}

if (queuedProfileIds.Contains(profile.ProfileId))
{
return;
}

queuedProfileIds.Add(profile.ProfileId);
Logger.LogInfo($"Queueing profile: {profile.Nickname}, {profile.ProfileId}");
Expand All @@ -445,27 +455,18 @@ public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInt

private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId)
{
LocalPlayer 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,
LocalPlayer 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,
GClass549.Config.CharacterController.ObservedPlayerMode,
() => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseSensitivity,
() => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseAimingSensitivity,
GClass1446.Default,
null,
null).Result;
GClass1446.Default).Result;

if (otherPlayer == null)
{
return null;
}

((CoopPlayer)otherPlayer).NetId = netId;
Logger.LogInfo($"SpawnObservedPlayer: {profile.Nickname} spawning with NetId {netId}");
Expand All @@ -484,7 +485,9 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p
}

if (!Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId))
{
Singleton<GameWorld>.Instance.RegisteredPlayers.Add(otherPlayer);
}

foreach (CoopPlayer player in Players.Values)
{
Expand Down
Loading

0 comments on commit 7b37d84

Please sign in to comment.