mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 01:10:45 -05:00
scavprofileloadpatch reworked tobe prefix instead of IL
This commit is contained in:
parent
f90ca3f780
commit
cef94b5c40
@ -14,6 +14,7 @@ namespace SPT.SinglePlayer.Patches.ScavMode
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
// Struct324 - 3.10.0
|
||||
var desiredType = typeof(TarkovApplication)
|
||||
.GetNestedTypes(PatchConstants.PublicDeclaredFlags)
|
||||
.SingleCustom(x => x.GetField("timeAndWeather") != null
|
||||
|
@ -13,78 +13,30 @@ namespace SPT.SinglePlayer.Patches.ScavMode
|
||||
{
|
||||
public class ScavProfileLoadPatch : ModulePatch
|
||||
{
|
||||
/// <summary>
|
||||
/// This was changed from an IL Patch,
|
||||
/// aim is just to replace loaded profile with the Scav profile when creating a game
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
// Struct225 - 20575
|
||||
var desiredType = typeof(TarkovApplication)
|
||||
.GetNestedTypes(PatchConstants.PublicDeclaredFlags)
|
||||
.SingleCustom(x => x.GetField("timeAndWeather") != null
|
||||
&& x.GetField("timeHasComeScreenController") != null
|
||||
&& x.Name.Contains("Struct"));
|
||||
|
||||
var desiredMethod = desiredType.GetMethods(PatchConstants.PublicDeclaredFlags)
|
||||
.FirstOrDefault(x => x.Name == "MoveNext");
|
||||
|
||||
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
|
||||
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
|
||||
|
||||
return desiredMethod;
|
||||
return AccessTools.Method(typeof(LocalGame), nameof(LocalGame.smethod_6));
|
||||
}
|
||||
|
||||
[PatchTranspiler]
|
||||
private static IEnumerable<CodeInstruction> PatchTranspile(ILGenerator generator, IEnumerable<CodeInstruction> instructions)
|
||||
[PatchPrefix]
|
||||
public static void PatchPrefix(ref Profile profile, LocalRaidSettings raidSettings)
|
||||
{
|
||||
var codes = new List<CodeInstruction>(instructions);
|
||||
|
||||
// Search for code where backend.Session.getProfile() is called.
|
||||
var searchCode = new CodeInstruction(OpCodes.Callvirt, AccessTools.Method(PatchConstants.BackendProfileInterfaceType, "get_Profile"));
|
||||
var searchIndex = -1;
|
||||
|
||||
for (var i = 0; i < codes.Count; i++)
|
||||
// check raidsettings to see if its a pmc raid
|
||||
if (raidSettings.playerSide == ESideType.Pmc)
|
||||
{
|
||||
if (codes[i].opcode == searchCode.opcode && codes[i].operand == searchCode.operand)
|
||||
{
|
||||
searchIndex = i;
|
||||
break;
|
||||
}
|
||||
Logger.LogInfo("Side was PMC, returning");
|
||||
return;
|
||||
}
|
||||
|
||||
// Patch failed.
|
||||
if (searchIndex == -1)
|
||||
{
|
||||
Logger.LogError($"Patch {MethodBase.GetCurrentMethod()} failed: Could not find reference code.");
|
||||
return instructions;
|
||||
}
|
||||
|
||||
// Move back by 2. This is the start of this method call.
|
||||
searchIndex -= 2;
|
||||
|
||||
var brFalseLabel = generator.DefineLabel();
|
||||
var brLabel = generator.DefineLabel();
|
||||
var newCodes = CodeGenerator.GenerateInstructions(new List<Code>()
|
||||
{
|
||||
new Code(OpCodes.Ldloc_1),
|
||||
new Code(OpCodes.Call, typeof(ClientApplication<ISession>), "get_Session"),
|
||||
new Code(OpCodes.Ldloc_1),
|
||||
new Code(OpCodes.Ldfld, typeof(TarkovApplication), "_raidSettings"),
|
||||
new Code(OpCodes.Callvirt, typeof(RaidSettings), "get_IsPmc"),
|
||||
new Code(OpCodes.Brfalse, brFalseLabel),
|
||||
new Code(OpCodes.Callvirt, PatchConstants.BackendProfileInterfaceType, "get_Profile"),
|
||||
new Code(OpCodes.Br, brLabel),
|
||||
new CodeWithLabel(OpCodes.Callvirt, brFalseLabel, PatchConstants.BackendProfileInterfaceType, "get_ProfileOfPet"),
|
||||
new CodeWithLabel(OpCodes.Stfld, brLabel, typeof(TarkovApplication).GetNestedTypes(BindingFlags.Public).SingleCustom(IsTargetNestedType), "profile")
|
||||
});
|
||||
|
||||
codes.RemoveRange(searchIndex, 4);
|
||||
codes.InsertRange(searchIndex, newCodes);
|
||||
|
||||
return codes.AsEnumerable();
|
||||
}
|
||||
|
||||
private static bool IsTargetNestedType(System.Type nestedType)
|
||||
{
|
||||
return nestedType.GetMethods(PatchConstants.PublicDeclaredFlags)
|
||||
.Count(x => x.GetParameters().Length == 1 && x.GetParameters()[0].ParameterType == typeof(IResult)) > 0 && nestedType.GetField("savageProfile") != null;
|
||||
// if not get scav profile
|
||||
// load that into the profile param
|
||||
Logger.LogInfo("Side was Scav, setting profile");
|
||||
profile = PatchConstants.BackEndSession.ProfileOfPet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user