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

Add patch to fix incorrect data being passed into SavageInventoryScreen.Remove old patch. Change Raidscreen patch to load the PVE version.

This commit is contained in:
Kaeno 2024-07-09 10:33:42 +01:00
parent cd76273abc
commit 0848617e29
5 changed files with 62 additions and 129 deletions

View File

@ -42,7 +42,7 @@ namespace SPT.Custom.Patches
[PatchPrefix]
private static bool PatchPrefix(BotOwner ___botOwner_0)
{
if (___botOwner_0.IsRole((WildSpawnType.pmcUSEC)) || ___botOwner_0.IsRole(WildSpawnType.pmcBEAR))
if (___botOwner_0.IsRole(WildSpawnType.pmcUSEC) || ___botOwner_0.IsRole(WildSpawnType.pmcBEAR))
{
var healthController = ___botOwner_0.GetPlayer.ActiveHealthController;

View File

@ -0,0 +1,55 @@
using EFT;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Reflection;
using System.Linq;
namespace SPT.SinglePlayer.Patches.ScavMode
{
/// <summary>
/// Get Profile at LocalGame End to use in FixSavageInventoryScreenPatch
/// </summary>
public class GetProfileAtEndOfRaidPatch : ModulePatch
{
public static string Profile { get; private set; }
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(LocalGame), nameof(LocalGame.Stop));
}
[PatchPrefix]
private static void PatchPrefix(LocalGame __instance)
{
GetProfileAtEndOfRaidPatch.Profile = __instance.Profile_0.ToJson();
}
}
/// <summary>
/// Get profile from other patch (GetProfileAtEndOfRaidPatch)
/// if our profile is savage Create new Session.AllProfiles and pass in our own profile to allow us to use the ScavengerInventoryScreen
/// </summary>
public class FixSavageInventoryScreenPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(PostRaidHealthScreenClass), nameof(PostRaidHealthScreenClass.method_2));
}
[PatchPrefix]
private static void PatchPrefix(ref ISession ___iSession)
{
var profile = GetProfileAtEndOfRaidPatch.Profile.ParseJsonTo<Profile>();
if (profile.Side != EPlayerSide.Savage)
{
return;
}
var session = (ProfileEndpointFactoryAbstractClass)___iSession;
session.AllProfiles = new Profile[]
{
session.AllProfiles.First(x => x.Side != EPlayerSide.Savage),
profile
};
session.ProfileOfPet.UncoverAll();
}
}
}

View File

@ -124,7 +124,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode
.Single(field => field.FieldType == typeof(MatchmakerPlayerControllerClass))
?.GetValue(menuController) as MatchmakerPlayerControllerClass;
var gclass = new MatchmakerOfflineRaidScreen.CreateRaidSettingsForProfileClass(profile?.Info, ref raidSettings, matchmakerPlayersController, ESessionMode.Regular);
var gclass = new MatchmakerOfflineRaidScreen.CreateRaidSettingsForProfileClass(profile?.Info, ref raidSettings, matchmakerPlayersController, ESessionMode.Pve);
gclass.OnShowNextScreen += LoadOfflineRaidNextScreen;

View File

@ -1,123 +0,0 @@
using SPT.Reflection.CodeWrapper;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using EFT;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
namespace SPT.SinglePlayer.Patches.ScavMode
{
public class ScavExfilPatchOld : ModulePatch
{
private static Type _profileType;
private static Type _profileInfoType;
private static Type _fenceTraderInfoType;
static ScavExfilPatchOld()
{
_profileType = PatchConstants.EftTypes.Single(x => x.GetMethod("AddToCarriedQuestItems") != null);
_profileInfoType = PatchConstants.EftTypes.Single(x => x.GetMethod("GetExperience") != null);
_fenceTraderInfoType = PatchConstants.EftTypes.Single(x => x.GetMethod("NewExfiltrationPrice") != null);
}
protected override MethodBase GetTargetMethod()
{
var desiredType = PatchConstants.LocalGameType.BaseType;
var desiredMethod = desiredType
.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.CreateInstance)
.Single(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);
}
[PatchTranspiler]
private static IEnumerable<CodeInstruction> PatchTranspile(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
var searchCode = new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(PatchConstants.ExfilPointManagerType, "EligiblePoints", new System.Type[] { typeof(Profile) }));
var searchIndex = -1;
for (var i = 0; i < codes.Count; i++)
{
if (codes[i].opcode == searchCode.opcode && codes[i].operand == searchCode.operand)
{
searchIndex = i;
break;
}
}
// Patch failed.
if (searchIndex == -1)
{
Logger.LogError(string.Format("Patch {0} failed: Could not find reference code.", MethodBase.GetCurrentMethod()));
return instructions;
}
searchIndex -= 3;
var brFalseLabel = generator.DefineLabel();
var brLabel = generator.DefineLabel();
var newCodes = CodeGenerator.GenerateInstructions(new List<Code>()
{
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Ldfld, typeof(Profile), "Info"),
new Code(OpCodes.Ldfld, _profileInfoType, "Side"),
new Code(OpCodes.Ldc_I4_4),
new Code(OpCodes.Ceq),
new Code(OpCodes.Brfalse, brFalseLabel),
new Code(OpCodes.Call, PatchConstants.ExfilPointManagerType, "get_Instance"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Ldfld, PatchConstants.LocalGameType.BaseType, "gparam_0"),
new Code(OpCodes.Box, typeof(PlayerOwner)),
new Code(OpCodes.Callvirt, typeof(PlayerOwner), "get_Player"),
new Code(OpCodes.Callvirt, typeof(Player), "get_Position"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Ldfld, typeof(Profile), "Id"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Call, _profileType, "get_FenceInfo"),
new Code(OpCodes.Call, _fenceTraderInfoType, "get_AvailableExitsCount"),
new Code(OpCodes.Callvirt, PatchConstants.ExfilPointManagerType, "ScavExfiltrationClaim", new System.Type[]{ typeof(Vector3), typeof(string), typeof(int) }),
new Code(OpCodes.Call, PatchConstants.ExfilPointManagerType, "get_Instance"),
new Code(OpCodes.Call, PatchConstants.ExfilPointManagerType, "get_Instance"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Ldfld, typeof(Profile), "Id"),
new Code(OpCodes.Callvirt, PatchConstants.ExfilPointManagerType, "GetScavExfiltrationMask"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Ldfld, typeof(Profile), "Id"),
new Code(OpCodes.Callvirt, PatchConstants.ExfilPointManagerType, "ScavExfiltrationClaim", new System.Type[]{ typeof(int), typeof(string) }),
new Code(OpCodes.Br, brLabel),
new CodeWithLabel(OpCodes.Call, brFalseLabel, PatchConstants.ExfilPointManagerType, "get_Instance"),
new Code(OpCodes.Ldarg_0),
new Code(OpCodes.Call, PatchConstants.LocalGameType.BaseType, "get_Profile_0"),
new Code(OpCodes.Callvirt, PatchConstants.ExfilPointManagerType, "EligiblePoints", new System.Type[]{ typeof(Profile) }),
new CodeWithLabel(OpCodes.Stloc_2, brLabel)
});
codes.RemoveRange(searchIndex, 5);
codes.InsertRange(searchIndex, newCodes);
return codes.AsEnumerable();
}
}
}

View File

@ -26,7 +26,6 @@ namespace SPT.SinglePlayer
new TinnitusFixPatch().Enable();
new SmokeGrenadeFuseSoundFixPatch().Enable();
new EmptyInfilFixPatch().Enable();
new ScavExperienceGainPatch().Enable();
new MainMenuControllerPatch().Enable();
new HealthControllerPatch().Enable();
new PlayerPatch().Enable();
@ -34,10 +33,11 @@ namespace SPT.SinglePlayer
new PostRaidHealingPricePatch().Enable();
new InRaidQuestAvailablePatch().Enable();
new ExfilPointManagerPatch().Enable();
new ScavEncyclopediaPatch().Enable();
new HideoutQuestIgnorePatch().Enable();
new SpawnProcessNegativeValuePatch().Enable();
new SpawnPmcPatch().Enable();
new ScavExperienceGainPatch().Enable();
new ScavEncyclopediaPatch().Enable();
new ScavProfileLoadPatch().Enable();
new ScavPrefabLoadPatch().Enable();
new ScavExfilPatch().Enable();
@ -46,7 +46,7 @@ namespace SPT.SinglePlayer
new GetTraderServicesPatch().Enable();
new PurchaseTraderServicePatch().Enable();
new LightKeeperServicesPatch().Enable();
// Still need
new DisableReadyLocationReadyPatch().Enable();
new BotTemplateLimitPatch().Enable();
@ -56,7 +56,6 @@ namespace SPT.SinglePlayer
new ScavRepAdjustmentPatch().Enable();
new PluginErrorNotifierPatch().Enable();
new GetNewBotTemplatesPatch().Enable();
new ScavLateStartPatch().Enable();
new LabsKeycardRemovalPatch().Enable();
new MapReadyButtonPatch().Enable();
new RemoveUsedBotProfilePatch().Enable();
@ -70,6 +69,8 @@ namespace SPT.SinglePlayer
new EnableRefIntermScreenPatch().Enable();
new EnablePlayerScavPatch().Enable();
new ScavFoundInRaidPatch().Enable();
new GetProfileAtEndOfRaidPatch().Enable();
new FixSavageInventoryScreenPatch().Enable();
}
catch (Exception ex)
{