0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-12 20:50:44 -05:00

Disabled various patches based on client analysis

This commit is contained in:
Dev 2024-08-29 10:15:58 +01:00
parent 6667e347f3
commit 32b2136630
8 changed files with 24 additions and 297 deletions

View File

@ -1,35 +0,0 @@
using SPT.Reflection.Patching;
using EFT;
using HarmonyLib;
using System.Reflection;
namespace SPT.SinglePlayer.Patches.Progression
{
/**
* There is no reason to update quest counters when exiting the hideout, so set the
* player's QuestController to null while calling HideoutPlayer.OnGameSessionEnd to
* avoid the quest controller counters from being triggered
*
* Note: Player.OnGameSessionEnd handles the player's quest controller not being set gracefully
*/
public class HideoutQuestIgnorePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(HideoutPlayer), nameof(HideoutPlayer.OnGameSessionEnd));
}
[PatchPrefix]
public static void PatchPrefix(ref AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController)
{
__state = ____questController;
____questController = null;
}
[PatchPostfix]
public static void PatchPostfix(AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController)
{
____questController = __state;
}
}
}

View File

@ -1,49 +0,0 @@
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using EFT;
using System;
using System.Linq;
using System.Reflection;
namespace SPT.SinglePlayer.Patches.Quests
{
public class SpawnPmcPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = PatchConstants.EftTypes.SingleCustom(IsTargetType);
var desiredMethod = desiredType.GetMethod("method_1", PatchConstants.PublicDeclaredFlags);
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
return desiredMethod;
}
private static bool IsTargetType(Type type)
{
if (!typeof(IGetProfileData).IsAssignableFrom(type) || type.GetMethod("method_1", PatchConstants.PublicDeclaredFlags) == null)
{
return false;
}
var fields = type.GetFields(PatchConstants.PrivateFlags);
return fields.Any(f => f.FieldType != typeof(WildSpawnType)) && fields.Any(f => f.FieldType == typeof(BotDifficulty));
}
[PatchPrefix]
public static bool PatchPrefix(ref bool __result, WildSpawnType ___wildSpawnType_0, BotDifficulty ___botDifficulty_0, Profile x)
{
if (x == null)
{
__result = false;
Logger.LogInfo($"profile x was null, ___wildSpawnType_0 = {___wildSpawnType_0}");
return false; // Skip original
}
__result = x.Info.Settings.Role == ___wildSpawnType_0 && x.Info.Settings.BotDifficulty == ___botDifficulty_0;
return false; // Skip original
}
}
}

View File

@ -1,73 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using Comfort.Common;
using EFT;
using EFT.Game.Spawning;
using UnityEngine;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// An empty EntryPoint string (string_0 in BaseLocalGame) causes exfil point initialization to be skipped.
/// This patch sets an EntryPoint string if it's missing.
/// </summary>
public class EmptyInfilFixPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = PatchConstants.LocalGameType.BaseType;
var desiredMethod = desiredType
.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.CreateInstance)
.SingleCustom(IsTargetMethod);
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
return desiredMethod;
}
private static bool IsTargetMethod(MethodInfo methodInfo)
{
return (methodInfo.IsVirtual
&& methodInfo.GetParameters().Length == 0
&& methodInfo.ReturnType == typeof(void)
&& methodInfo.GetMethodBody().LocalVariables.Count > 0);
}
[PatchPrefix]
public static void PatchPrefix(ref string ___string_0)
{
if (!string.IsNullOrWhiteSpace(___string_0)) return;
var spawnPoints = Resources.FindObjectsOfTypeAll<SpawnPointMarker>().ToList();
var filteredSpawns = new List<SpawnPointMarker>();
foreach (var spawn in spawnPoints)
{
if (!string.IsNullOrEmpty(spawn?.SpawnPoint?.Infiltration?.Trim()))
{
filteredSpawns.Add(spawn);
}
}
var playerPos = Singleton<GameWorld>.Instance.MainPlayer.Transform.position;
SpawnPointMarker closestSpawn = null;
var minDist = Mathf.Infinity;
foreach (var filter in filteredSpawns)
{
var dist = Vector3.Distance(filter.gameObject.transform.position, playerPos);
if (dist < minDist)
{
closestSpawn = filter;
minDist = dist;
}
}
___string_0 = closestSpawn.SpawnPoint.Infiltration;
}
}
}

View File

@ -1,36 +0,0 @@
using System.Reflection;
using EFT;
using EFT.InventoryLogic;
using HarmonyLib;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// this patch aims to allow achievements and quests to activate/change and finish whilst inraid
/// </summary>
public class FixQuestAchieveControllersPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(Player), nameof(Player.Init));
}
[PatchPostfix]
public static void PatchPostfix(Profile profile, InventoryController inventoryController, ref AbstractQuestControllerClass ____questController, ref AbstractAchievementControllerClass ____achievementsController)
{
var questController = new LocalQuestControllerClass(profile, inventoryController, PatchConstants.BackEndSession, true);
questController.Init();
questController.Run();
var achievementController =
new AchievementControllerClass(profile, inventoryController, PatchConstants.BackEndSession, true);
achievementController.Init();
achievementController.Run();
____questController = questController;
____achievementsController = achievementController;
}
}
}

View File

@ -1,37 +0,0 @@
using SPT.Reflection.Patching;
using HarmonyLib;
using System;
using System.Reflection;
using EFT;
namespace SPT.SinglePlayer.Patches.RaidFix
{
public class PostRaidHealingPricePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(Profile.TraderInfo), nameof(Profile.TraderInfo.UpdateLevel));
}
[PatchPrefix]
public static void PatchPrefix(Profile.TraderInfo __instance)
{
if (__instance.Settings == null)
{
return;
}
var loyaltyLevel = __instance.Settings.GetLoyaltyLevel(__instance);
var loyaltyLevelSettings = __instance.Settings.GetLoyaltyLevelSettings(loyaltyLevel);
if (loyaltyLevelSettings == null)
{
throw new IndexOutOfRangeException($"Loyalty level {loyaltyLevel} not found.");
}
// Backing field of the "CurrentLoyalty" property
// Traverse.Create(__instance).Field("<CurrentLoyalty>k__BackingField").SetValue(loyaltyLevelSettings.Value);
__instance.CurrentLoyalty = loyaltyLevelSettings.Value;
}
}
}

View File

@ -1,41 +0,0 @@
using SPT.Reflection.Patching;
using EFT;
using System;
using System.Reflection;
using HarmonyLib;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// Prevent BotSpawnerClass from adjusting the spawn process value to be below 0
/// This fixes aiamount = high spawning 80+ bots on maps like streets/customs
/// int_0 = all bots alive
/// int_1 = followers alive
/// int_2 = bosses currently alive
/// int_3 = spawn process? - current guess is open spawn positions - bsg doesn't seem to handle negative vaues well
/// int_4 = max bots
/// </summary>
public class SpawnProcessNegativeValuePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotSpawner), nameof(BotSpawner.CheckOnMax));
}
[PatchPrefix]
public static bool PatchPreFix(int wantSpawn, ref int toDelay, ref int toSpawn, ref int ____maxBots, int ____allBotsCount, int ____inSpawnProcess)
{
// Set bots to delay if alive bots + spawning bots count > maxbots
// ____inSpawnProcess can be negative, don't go below 0 when calculating
if ((____allBotsCount + Math.Max(____inSpawnProcess, 0)) > ____maxBots)
{
toDelay += wantSpawn;
toSpawn = 0;
return false; // Skip original
}
return true; // Do original
}
}
}

View File

@ -13,27 +13,31 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp" HintPath="..\Shared\Hollowed\hollowed.dll" Private="False"/>
<Reference Include="Comfort.Unity" HintPath="..\Shared\Managed\Comfort.Unity.dll" Private="False"/>
<Reference Include="DissonanceVoip" HintPath="..\Shared\Managed\DissonanceVoip.dll" Private="False"/>
<Reference Include="ItemComponent.Types" HintPath="..\Shared\Managed\ItemComponent.Types.dll" Private="False"/>
<Reference Include="Comfort" HintPath="..\Shared\Managed\Comfort.dll" Private="False"/>
<Reference Include="UnityEngine" HintPath="..\Shared\Managed\UnityEngine.dll" Private="False"/>
<Reference Include="UnityEngine.AudioModule" HintPath="..\Shared\Managed\UnityEngine.AudioModule.dll" Private="False"/>
<Reference Include="UnityEngine.CoreModule" HintPath="..\Shared\Managed\UnityEngine.CoreModule.dll" Private="False"/>
<Reference Include="Sirenix.Serialization" HintPath="..\Shared\Managed\Sirenix.Serialization.dll" Private="False"/>
<Reference Include="Assembly-CSharp" HintPath="..\Shared\Hollowed\hollowed.dll" Private="False" />
<Reference Include="Comfort.Unity" HintPath="..\Shared\Managed\Comfort.Unity.dll" Private="False" />
<Reference Include="DissonanceVoip" HintPath="..\Shared\Managed\DissonanceVoip.dll" Private="False" />
<Reference Include="ItemComponent.Types" HintPath="..\Shared\Managed\ItemComponent.Types.dll" Private="False" />
<Reference Include="Comfort" HintPath="..\Shared\Managed\Comfort.dll" Private="False" />
<Reference Include="UnityEngine" HintPath="..\Shared\Managed\UnityEngine.dll" Private="False" />
<Reference Include="UnityEngine.AudioModule" HintPath="..\Shared\Managed\UnityEngine.AudioModule.dll" Private="False" />
<Reference Include="UnityEngine.CoreModule" HintPath="..\Shared\Managed\UnityEngine.CoreModule.dll" Private="False" />
<Reference Include="Sirenix.Serialization" HintPath="..\Shared\Managed\Sirenix.Serialization.dll" Private="False" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" ExcludeAssets="runtime" PrivateAssets="all">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2"/>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SPT.Common\SPT.Common.csproj"/>
<ProjectReference Include="..\SPT.Reflection\SPT.Reflection.csproj"/>
<ProjectReference Include="..\SPT.Common\SPT.Common.csproj" />
<ProjectReference Include="..\SPT.Reflection\SPT.Reflection.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Patches\Quests\" />
</ItemGroup>
</Project>

View File

@ -2,7 +2,6 @@ using System;
using SPT.Common;
using SPT.SinglePlayer.Patches.MainMenu;
using SPT.SinglePlayer.Patches.Progression;
using SPT.SinglePlayer.Patches.Quests;
using SPT.SinglePlayer.Patches.RaidFix;
using SPT.SinglePlayer.Patches.ScavMode;
using BepInEx;
@ -19,18 +18,14 @@ namespace SPT.SinglePlayer
try
{
// TODO: check if these patches are needed
new TinnitusFixPatch().Enable();
new EmptyInfilFixPatch().Enable();
new MaxBotPatch().Enable();
new PostRaidHealingPricePatch().Enable();
new HideoutQuestIgnorePatch().Enable();
new SpawnProcessNegativeValuePatch().Enable();
new SpawnPmcPatch().Enable();
// new ScavRepAdjustmentPatch().Enable();
// new ArmorDamageCounterPatch().Enable();
// new AmmoUsedCounterPatch().Enable();
new TinnitusFixPatch().Enable(); // Probably needed
//new EmptyInfilFixPatch().Enable();
new MaxBotPatch().Enable(); // Custom code, needed
//new PostRaidHealingPricePatch().Enable(); // Client handles this now
//new HideoutQuestIgnorePatch().Enable(); // Was only needed because FixQuestAchieveControllersPatch was causing issues
//new SpawnProcessNegativeValuePatch().Enable(); // Client handles this edge case, revisit if bot count keeps going up
//new SpawnPmcPatch().Enable(); // 2.5+ years old, PMC spawn system very different, likely not needed
//new FixQuestAchieveControllersPatch().Enable(); // Likely not needed, if cheevos don't appear, revisit patch
// Still need
// new SmokeGrenadeFuseSoundFixPatch().Enable(); TODO: refactor as it causes exceptions to be thrown when grenade is tossed by player
@ -60,7 +55,6 @@ namespace SPT.SinglePlayer
new GetProfileAtEndOfRaidPatch().Enable();
new FixSavageInventoryScreenPatch().Enable();
new InsuranceScreenPatch().Enable();
new FixQuestAchieveControllersPatch().Enable();
new RemoveStashUpgradeLabelPatch().Enable();
new RemoveClothingItemExternalObtainLabelPatch().Enable();
}