0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

Fix BTR patches to work with new publicized Assembly (!59)

Should make the BTR work again.

I've also switched named methods to use "nameof" where it made sense. And removed an unnecessary method call and fixed an incorrect async on one of my patches

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: SPT-AKI/Modules#59
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-01-14 09:05:13 +00:00 committed by chomp
parent 337a0733ae
commit 7f5b068bb8
9 changed files with 22 additions and 15 deletions

View File

@ -23,7 +23,7 @@ namespace Aki.Debugging.BTR.Patches
_playerInventoryControllerField = AccessTools.Field(typeof(Player), "_inventoryController"); _playerInventoryControllerField = AccessTools.Field(typeof(Player), "_inventoryController");
_playerQuestControllerField = AccessTools.Field(typeof(Player), "_questController"); _playerQuestControllerField = AccessTools.Field(typeof(Player), "_questController");
var targetType = typeof(GetActionsClass).GetNestedTypes(PatchConstants.PrivateFlags).Single(IsTargetType); var targetType = AccessTools.FirstInner(typeof(GetActionsClass), IsTargetType);
return AccessTools.Method(targetType, "method_2"); return AccessTools.Method(targetType, "method_2");
} }

View File

@ -7,6 +7,7 @@ using Comfort.Common;
using EFT; using EFT;
using HarmonyLib; using HarmonyLib;
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -22,8 +23,8 @@ namespace Aki.Debugging.BTR.Patches
.First(t => t.GetField("Converters", BindingFlags.Static | BindingFlags.Public) != null); .First(t => t.GetField("Converters", BindingFlags.Static | BindingFlags.Public) != null);
_defaultJsonConverters = Traverse.Create(converterClass).Field<JsonConverter[]>("Converters").Value; _defaultJsonConverters = Traverse.Create(converterClass).Field<JsonConverter[]>("Converters").Value;
return PatchConstants.EftTypes.Single(x => x.Name == "LocalGame").BaseType // BaseLocalGame Type baseLocalGameType = PatchConstants.LocalGameType.BaseType;
.GetMethod("Stop", BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance); return AccessTools.Method(baseLocalGameType, nameof(LocalGame.Stop));
} }
[PatchPrefix] [PatchPrefix]

View File

@ -12,7 +12,7 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(VehicleBase), "ExtractPassengers"); return AccessTools.Method(typeof(VehicleBase), nameof(VehicleBase.ExtractPassengers));
} }
[PatchPrefix] [PatchPrefix]

View File

@ -2,6 +2,7 @@
using Comfort.Common; using Comfort.Common;
using EFT; using EFT;
using EFT.Vehicle; using EFT.Vehicle;
using HarmonyLib;
using System; using System;
using System.Reflection; using System.Reflection;
@ -11,8 +12,15 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; return AccessTools.FirstMethod(typeof(Player), IsTargetMethod);
return typeof(Player).GetMethod("BtrInteraction", bindingFlags); }
/**
* Find the "BtrInteraction" method that takes parameters
*/
private bool IsTargetMethod(MethodBase method)
{
return method.Name == nameof(Player.BtrInteraction) && method.GetParameters().Length > 0;
} }
[PatchPostfix] [PatchPostfix]

View File

@ -10,7 +10,7 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(VehicleBase), "IsDoorsClosed"); return AccessTools.Method(typeof(VehicleBase), nameof(VehicleBase.IsDoorsClosed));
} }
[PatchPrefix] [PatchPrefix]

View File

@ -3,6 +3,7 @@ using Aki.Reflection.Patching;
using Comfort.Common; using Comfort.Common;
using EFT; using EFT;
using EFT.UI; using EFT.UI;
using HarmonyLib;
namespace Aki.Debugging.BTR.Patches namespace Aki.Debugging.BTR.Patches
{ {
@ -13,7 +14,7 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted)); return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted));
} }
[PatchPostfix] [PatchPostfix]

View File

@ -14,7 +14,7 @@ namespace Aki.Debugging.BTR.Patches
private static GameStatus originalStatus; private static GameStatus originalStatus;
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
_statusProperty = AccessTools.Property(typeof(AbstractGame), "Status"); _statusProperty = AccessTools.Property(typeof(AbstractGame), nameof(AbstractGame.Status));
return AccessTools.Method(typeof(BTRControllerClass), "method_1"); return AccessTools.Method(typeof(BTRControllerClass), "method_1");
} }

View File

@ -14,11 +14,11 @@ namespace Aki.Debugging.BTR.Patches
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(TransferItemsInRaidScreen), "Close"); return AccessTools.Method(typeof(TransferItemsInRaidScreen), nameof(TransferItemsInRaidScreen.Close));
} }
[PatchPostfix] [PatchPostfix]
public static async void PatchPostfix(bool ___bool_1) public static void PatchPostfix(bool ___bool_1)
{ {
// Didn't extract items // Didn't extract items
if (!___bool_1) if (!___bool_1)
@ -35,9 +35,6 @@ namespace Aki.Debugging.BTR.Patches
return; return;
} }
// NOTE: This is just here so I remember how to get the items the player transfered
gameWorld.BtrController.GetOrAddTransferContainer(player.Profile.Id);
// Update the trader services information now that we've used this service // Update the trader services information now that we've used this service
btrManager.SetServicePurchased(ETraderServiceType.BtrItemsDelivery, BTRUtil.BTRTraderId); btrManager.SetServicePurchased(ETraderServiceType.BtrItemsDelivery, BTRUtil.BTRTraderId);
BTRUtil.UpdateTraderServices(BTRUtil.BTRTraderId); BTRUtil.UpdateTraderServices(BTRUtil.BTRTraderId);

View File

@ -10,7 +10,7 @@ namespace Aki.Debugging.BTR.Patches
{ {
protected override MethodBase GetTargetMethod() protected override MethodBase GetTargetMethod()
{ {
return AccessTools.Method(typeof(BTRTurretServer), "Start"); return AccessTools.Method(typeof(BTRTurretServer), nameof(BTRTurretServer.Start));
} }
[PatchPrefix] [PatchPrefix]