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

Backmerge hotfixes #292

Merged
merged 18 commits into from
Apr 30, 2024
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
1 change: 0 additions & 1 deletion .github/workflows/SIT-CI-Linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
- "master"
- "development"


workflow_dispatch:

jobs:
Expand Down
58 changes: 58 additions & 0 deletions Source/AkiSupport/Custom/BossSpawnChancePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using EFT;
using StayInTarkov;
using System.Linq;
using System.Reflection;

namespace Aki.Custom.Patches
{
/// <summary>
/// Created by: SPT-Aki
/// Link: https://dev.sp-tarkov.com/SPT-AKI/Modules/src/branch/master/project/Aki.Custom/Patches/BossSpawnChancePatch.cs
/// Boss spawn chance is 100%, all the time, this patch adjusts the chance to the maps boss wave value
/// </summary>
public class BossSpawnChancePatch : ModulePatch
{
private static float[] _bossSpawnPercent;

protected override MethodBase GetTargetMethod()
{
var desiredType = typeof(LocalGame);
var desiredMethod = desiredType
.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
.SingleOrDefault(IsTargetMethod);

Logger.LogDebug($"{this.GetType().Name} Type: {desiredType.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name ?? "NOT FOUND"}");

return desiredMethod;
}

private static bool IsTargetMethod(MethodInfo mi)
{
var parameters = mi.GetParameters();
return (parameters.Length == 2
&& parameters[0].Name == "wavesSettings"
&& parameters[1].Name == "bossLocationSpawn");
}

[PatchPrefix]
private static void PatchPrefix(BossLocationSpawn[] bossLocationSpawn)
{
_bossSpawnPercent = bossLocationSpawn.Select(s => s.BossChance).ToArray();
}

[PatchPostfix]
private static void PatchPostfix(ref BossLocationSpawn[] __result)
{
if (__result.Length != _bossSpawnPercent.Length)
{
return;
}

for (var i = 0; i < _bossSpawnPercent.Length; i++)
{
__result[i].BossChance = _bossSpawnPercent[i];
}
}
}
}
59 changes: 59 additions & 0 deletions Source/AkiSupport/Singleplayer/Patches/RaidFix/EndRaidDebug.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Reflection;
using BepInEx.Logging;
using EFT;
using EFT.UI;
using HarmonyLib;
using TMPro;
using StayInTarkov;

namespace StayInTarkov.AkiSupport.Singleplayer.Patches.RaidFix
{
/// <summary>
/// Created by: SPT-Aki team
/// Link: https://dev.sp-tarkov.com/SPT-AKI/Modules/src/branch/master/project/Aki.Debugging/AkiDebuggingPlugin.cs
/// </summary>
public class EndRaidDebug : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(TraderCard), nameof(TraderCard.method_0));
}

[PatchPrefix]
private static bool PatchPreFix(ref LocalizedText ____nickName, ref TMP_Text ____standing,
ref RankPanel ____rankPanel, ref Profile.TraderInfo ___traderInfo_0)
{
if (____nickName.LocalizationKey == null)
{
ConsoleScreen.LogError("This Shouldn't happen!! Please report this in discord");
Logger.Log(LogLevel.Error, "[AKI] _nickName.LocalizationKey was null");
}

if (____standing.text == null)
{
ConsoleScreen.LogError("This Shouldn't happen!! Please report this in discord");
Logger.Log(LogLevel.Error, "[AKI] _standing.text was null");
}

if (____rankPanel == null)
{
Logger.Log(LogLevel.Error, "[AKI] _rankPanel was null, skipping method_0");
return false; // skip original
}

if (___traderInfo_0?.LoyaltyLevel == null)
{
ConsoleScreen.LogError("This Shouldn't happen!! Please report this in discord");
Logger.Log(LogLevel.Error, "[AKI] ___traderInfo_0 or ___traderInfo_0.LoyaltyLevel was null");
}

if (___traderInfo_0?.MaxLoyaltyLevel == null)
{
ConsoleScreen.LogError("This Shouldn't happen!! Please report this in discord");
Logger.Log(LogLevel.Error, "[AKI] ___traderInfo_0 or ___traderInfo_0.MaxLoyaltyLevel was null");
}

return true;
}
}
}
111 changes: 6 additions & 105 deletions Source/Coop/SITGameModes/CoopSITGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

// ---------------------------------------------------------------------------------
// Non Waves Scenario setup
WildSpawnWave[] waves = FixScavWaveSettings(wavesSettings, location.waves);
WildSpawnWave[] waves = LocalGame.smethod_7(wavesSettings, location.waves);
coopGame.nonWavesSpawnScenario_0 = NonWavesSpawnScenario.smethod_0(coopGame, location, coopGame.PBotsController);
coopGame.nonWavesSpawnScenario_0.ImplementWaveSettings(wavesSettings);

Expand All @@ -174,14 +174,13 @@
coopGame.wavesSpawnScenario_0 = WavesSpawnScenario.smethod_0(
coopGame.gameObject
, waves
, new Action<BotWaveDataClass>((wave) => coopGame.PBotsController.ActivateBotsByWave(wave))
, new Action<BotWaveDataClass>(coopGame.PBotsController.ActivateBotsByWave)
, location);

// ---------------------------------------------------------------------------------
// Setup Boss Wave Manager
coopGame.BossWaves = coopGame.FixBossWaveSettings(wavesSettings, location);
var bosswavemanagerValue = BossWaveManager.smethod_0(coopGame.BossWaves, new Action<BossLocationSpawn>((bossWave) => { coopGame.PBotsController.ActivateBotsByWave(bossWave); }));
coopGame.BossWaveManager = bosswavemanagerValue;
coopGame.BossWaves = LocalGame.smethod_8(wavesSettings, location.BossLocationSpawn);
coopGame.BossWaveManager = BossWaveManager.smethod_0(coopGame.BossWaves, new Action<BossLocationSpawn>(coopGame.PBotsController.ActivateBotsByWave));

coopGame.func_1 = (player) => GamePlayerOwner.Create<GamePlayerOwner>(player, inputTree, insurance, backEndSession, commonUI, preloaderUI, gameUI, coopGame.GameDateTime, location);

Expand Down Expand Up @@ -392,29 +391,6 @@
}
}


public static WildSpawnWave[] FixScavWaveSettings(WavesSettings wavesSettings, WildSpawnWave[] waves)
{
Logger.LogDebug($"{nameof(CoopSITGame)}:{nameof(FixScavWaveSettings)}");

foreach (WildSpawnWave wildSpawnWave in waves)
{
wildSpawnWave.slots_min = wavesSettings.BotAmount == EBotAmount.NoBots ? 0 : 1;
wildSpawnWave.slots_max = wavesSettings.BotAmount == EBotAmount.NoBots ? 0 : Math.Max(1, wildSpawnWave.slots_max);
if (wavesSettings.IsTaggedAndCursed && wildSpawnWave.WildSpawnType == WildSpawnType.assault)
{
wildSpawnWave.WildSpawnType = WildSpawnType.cursedAssault;
}
if (wavesSettings.IsBosses)
{
wildSpawnWave.time_min += 5;
wildSpawnWave.time_max += 27;
}
wildSpawnWave.BotDifficulty = ToBotDifficulty(wavesSettings.BotDifficulty);
}
return waves;
}

public static BotDifficulty ToBotDifficulty(EBotDifficulty botDifficulty)
{
return botDifficulty switch
Expand All @@ -434,73 +410,6 @@
return (BotDifficulty)values.GetValue(UnityEngine.Random.Range(0, values.Length));
}

private static int[] CultistSpawnTime = new[] { 6, 22 };

private static bool CanSpawnCultist(int hour)
{
return hour <= CultistSpawnTime[0] || hour >= CultistSpawnTime[1];
}

public BossLocationSpawn[] FixBossWaveSettings(WavesSettings wavesSettings, LocationSettingsClass.Location location)
{
#if DEBUG
Logger.LogDebug($"{nameof(FixBossWaveSettings)}:{location.ToJson()}");
#endif

var bossLocationSpawns = location.BossLocationSpawn;
TimeSpan CurrentGameTime = GameDateTime.Calculate().TimeOfDay;
if (!wavesSettings.IsBosses)
{
Logger.LogDebug($"{nameof(CoopSITGame)}:{nameof(FixBossWaveSettings)}: Bosses are disabled");
return new BossLocationSpawn[0];
}
foreach (BossLocationSpawn bossLocationSpawn in bossLocationSpawns)
{
#if DEBUG
Logger.LogDebug($"{nameof(FixBossWaveSettings)}:===BEFORE===");
Logger.LogDebug($"{nameof(FixBossWaveSettings)}:{bossLocationSpawn.ToJson()}");
#endif

if (!CanSpawnCultist(CurrentGameTime.Hours) && bossLocationSpawn.BossName.Contains("sectant"))
{
Logger.LogDebug($"Block spawn of Sectant (Cultist) in day time in hour {CurrentGameTime.Hours}!");
bossLocationSpawn.BossChance = 0f;
}

//ArchangelWTF: boss types like 'arenaFighterEvent' can have multiple values, split these out and take the first value.
//We could maybe do some fancy randomization here at some point to get a number in between the two values, but for now this works.
if (bossLocationSpawn.BossEscortAmount.Contains(","))
bossLocationSpawn.BossEscortAmount = bossLocationSpawn.BossEscortAmount.Split(',')[0];

int EscortAmount = Convert.ToInt32(bossLocationSpawn.BossEscortAmount);

if (bossLocationSpawn.Supports == null && !string.IsNullOrEmpty(bossLocationSpawn.BossEscortType) && EscortAmount > 0)
{
Logger.LogDebug($"bossLocationSpawn.Supports is Null. Attempt to create them.");

Enum.TryParse<WildSpawnType>(bossLocationSpawn.BossEscortType, out var EscortType);

bossLocationSpawn.Supports = new WildSpawnSupports[EscortAmount];

for (int i = 0; i < EscortAmount; i++)
{
bossLocationSpawn.Supports[i] = new WildSpawnSupports
{
BossEscortDifficult = new[] { bossLocationSpawn.BossEscortDifficult },
BossEscortAmount = 1,
BossEscortType = EscortType
};
}
}

#if DEBUG
Logger.LogDebug($"{nameof(FixBossWaveSettings)}:===AFTER===");
Logger.LogDebug($"{nameof(FixBossWaveSettings)}:{bossLocationSpawn.ToJson()}");
#endif
}
return bossLocationSpawns;
}

public Dictionary<string, EFT.Player> Bots { get; } = new();

private async Task<LocalPlayer> CreatePhysicalBot(Profile profile, Vector3 position)
Expand All @@ -513,15 +422,7 @@
Logger.LogDebug("Block spawn of Bot. Max Bot Count has been reached!");
return null;
}

if (!CanSpawnCultist(GameDateTime.Calculate().TimeOfDay.Hours) && profile.Info != null && profile.Info.Settings != null
&& (profile.Info.Settings.Role == WildSpawnType.sectantPriest || profile.Info.Settings.Role == WildSpawnType.sectantWarrior)
)
{
Logger.LogDebug("Block spawn of Sectant (Cultist) in day time!");
return null;
}
Logger.LogDebug($"CreatePhysicalBot: {profile.ProfileId}");
Logger.LogDebug($"CreatePhysicalBot: {profile.ProfileId} role={profile.Info?.Settings?.Role}");

LocalPlayer botPlayer;
if (!Status.IsRunned())
Expand Down Expand Up @@ -631,7 +532,7 @@
base.vmethod_1(timeBeforeDeploy);
}

public static async Task<ISpawnPoint?> SendOrReceiveSpawnPoint(ISpawnPoint selectedSpawnPoint, SpawnPoints spawnPoints)

Check warning on line 535 in Source/Coop/SITGameModes/CoopSITGame.cs

View workflow job for this annotation

GitHub Actions / Build-SIT (Debug)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var position = selectedSpawnPoint.Position;
if (!SITMatchmaking.IsClient)
Expand Down Expand Up @@ -1058,7 +959,7 @@
, false // controllerSettings.IsScavWars
, true
, false // online
, GameDateTime.DateTime_0.Hour > 21 // have sectants
, this.BossWaveManager.HaveSectants
, Singleton<GameWorld>.Instance
, Location_0.OpenZones)
;
Expand Down
4 changes: 4 additions & 0 deletions Source/StayInTarkovPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using UnityEngine;
using StayInTarkov.Tools;
using System.Threading.Tasks;
using StayInTarkov.AkiSupport.Singleplayer.Patches.RaidFix;
using System.Reflection;
using HarmonyLib;

Expand Down Expand Up @@ -423,6 +424,8 @@ private void EnableCorePatches()
new SslCertificatePatch().Enable();
new Aki.Core.Patches.UnityWebRequestPatch().Enable();
new SendCommandsPatch().Enable();
// Fixes
new EndRaidDebug().Enable();

//https to http | wss to ws
var url = DetectBackendUrlAndToken.GetBackendConnection().BackendUrl;
Expand Down Expand Up @@ -514,6 +517,7 @@ private void EnableSPPatches_PlayerHealth(BepInEx.Configuration.ConfigFile confi
private static void EnableSPPatches_Bots(BepInEx.Configuration.ConfigFile config)
{
new CoreDifficultyPatch().Enable();
new BossSpawnChancePatch().Enable();
new BotDifficultyPatch().Enable();
new BotSettingsRepoClassIsFollowerFixPatch().Enable();
new BotSelfEnemyPatch().Enable();
Expand Down
Loading