0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 06:10:45 -05:00

Added patch to remove the Labs Access Card from player inventory when entering Labs (!37)

Co-authored-by: Terkoiz <terkoiz@spt.dev>
Reviewed-on: SPT-AKI/Modules#37
Co-authored-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
Co-committed-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
This commit is contained in:
Terkoiz 2023-11-14 18:49:42 +00:00 committed by Dev
parent 1f6a8d0f2e
commit 8dcbd0f0b2
4 changed files with 53 additions and 3 deletions

View File

@ -8,7 +8,7 @@ namespace Aki.Core
[BepInPlugin("com.spt-aki.core", "AKI.Core", AkiPluginInfo.PLUGIN_VERSION)] [BepInPlugin("com.spt-aki.core", "AKI.Core", AkiPluginInfo.PLUGIN_VERSION)]
class AkiCorePlugin : BaseUnityPlugin class AkiCorePlugin : BaseUnityPlugin
{ {
public AkiCorePlugin() public void Awake()
{ {
Logger.LogInfo("Loading: Aki.Core"); Logger.LogInfo("Loading: Aki.Core");

View File

@ -8,7 +8,7 @@ namespace Aki.Debugging
[BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)] [BepInPlugin("com.spt-aki.debugging", "AKI.Debugging", AkiPluginInfo.PLUGIN_VERSION)]
public class AkiDebuggingPlugin : BaseUnityPlugin public class AkiDebuggingPlugin : BaseUnityPlugin
{ {
public AkiDebuggingPlugin() public void Awake()
{ {
Logger.LogInfo("Loading: Aki.Debugging"); Logger.LogInfo("Loading: Aki.Debugging");

View File

@ -13,7 +13,7 @@ namespace Aki.SinglePlayer
[BepInPlugin("com.spt-aki.singleplayer", "AKI.Singleplayer", AkiPluginInfo.PLUGIN_VERSION)] [BepInPlugin("com.spt-aki.singleplayer", "AKI.Singleplayer", AkiPluginInfo.PLUGIN_VERSION)]
class AkiSingleplayerPlugin : BaseUnityPlugin class AkiSingleplayerPlugin : BaseUnityPlugin
{ {
public AkiSingleplayerPlugin() public void Awake()
{ {
Logger.LogInfo("Loading: Aki.SinglePlayer"); Logger.LogInfo("Loading: Aki.SinglePlayer");
@ -54,6 +54,7 @@ namespace Aki.SinglePlayer
new SpawnProcessNegativeValuePatch().Enable(); new SpawnProcessNegativeValuePatch().Enable();
new InsuredItemManagerStartPatch().Enable(); new InsuredItemManagerStartPatch().Enable();
new MapReadyButtonPatch().Enable(); new MapReadyButtonPatch().Enable();
new LabsKeycardRemovalPatch().Enable();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -0,0 +1,49 @@
using System.Linq;
using System.Reflection;
using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using HarmonyLib;
namespace Aki.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// Patch to remove the Labs Access Card from player inventory upon entering Labs
/// </summary>
public class LabsKeycardRemovalPatch : ModulePatch
{
private const string LabsAccessCardTemplateId = "5c94bbff86f7747ee735c08f";
protected override MethodBase GetTargetMethod()
{
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
}
[PatchPostfix]
private static void PatchPostfix()
{
var gameWorld = Singleton<GameWorld>.Instance;
var player = gameWorld?.MainPlayer;
if (gameWorld == null || player == null)
{
return;
}
if (gameWorld.MainPlayer.Location.ToLower() != "laboratory")
{
return;
}
var accessCardItem = player.Profile.Inventory.AllRealPlayerItems.FirstOrDefault(x => x.TemplateId == LabsAccessCardTemplateId);
if (accessCardItem == null)
{
return;
}
var inventoryController = Traverse.Create(player).Field<InventoryControllerClass>("_inventoryController").Value;
GClass2585.Remove(accessCardItem, inventoryController, false, true);
}
}
}