mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
Depends on SPT-AKI/SPT-AssemblyTool#3 * Refactored Modules for better consistency and general readability, along with preparing the code for a publicized assembly * Added `PublicDeclaredFlags` to `PatchConstants` to cover a set of commonly used flags to get methods post-publicizing * Added a replacement to LINQ's `.Single()` - `.SingleCustom()` which has improved logging to help with debugging Module code. Replaced all `.Single()` usages where applicable * Replaced most method info fetching with `AccessTools` for consistency and better readability, especially in places where methods were being retrieved by their name anyways **NOTE:** As a side effect of publicizing all properties, some property access code such as `Player.Position` will now show "ambiguous reference" errors during compile, due to there being multiple interfaces with the Property name being defined on the class. The way to get around this is to use a cast to an explicit interface Example: ```cs Singleton<GameWorld>.Instance.MainPlayer.Position ``` will now need to be ```cs ((IPlayer)Singleton<GameWorld>.Instance.MainPlayer).Position ``` Co-authored-by: Terkoiz <terkoiz@spt.dev> Reviewed-on: SPT-AKI/Modules#58 Co-authored-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com> Co-committed-by: Terkoiz <terkoiz@noreply.dev.sp-tarkov.com>
53 lines
2.1 KiB
C#
53 lines
2.1 KiB
C#
using System;
|
|
using Aki.Reflection.Patching;
|
|
using EFT;
|
|
using EFT.Counters;
|
|
using EFT.UI.SessionEnd;
|
|
using System.Reflection;
|
|
using HarmonyLib;
|
|
|
|
namespace Aki.SinglePlayer.Patches.Progression
|
|
{
|
|
/// <summary>
|
|
/// Fix xp gained value being 0 after a scav raid
|
|
/// </summary>
|
|
public class ScavExperienceGainPatch : ModulePatch
|
|
{
|
|
/// <summary>
|
|
/// Looking for SessionResultExitStatus Show() (private)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return AccessTools.Method(
|
|
typeof(SessionResultExitStatus),
|
|
nameof(SessionResultExitStatus.Show),
|
|
new []{ typeof(Profile), typeof(PlayerVisualRepresentation), typeof(ESideType), typeof(ExitStatus), typeof(TimeSpan), typeof(ISession), typeof(bool) });
|
|
}
|
|
|
|
// Unused, but left here in case patch breaks and finding the intended method is difficult
|
|
private static bool IsTargetMethod(MethodInfo mi)
|
|
{
|
|
var parameters = mi.GetParameters();
|
|
return (parameters.Length == 7
|
|
&& parameters[0].Name == "activeProfile"
|
|
&& parameters[1].Name == "lastPlayerState"
|
|
&& parameters[2].Name == "side"
|
|
&& parameters[3].Name == "exitStatus"
|
|
&& parameters[4].Name == "raidTime");
|
|
}
|
|
|
|
[PatchPrefix]
|
|
private static bool PatchPrefix(ref Profile activeProfile,ref EPlayerSide side)
|
|
{
|
|
if (activeProfile.Side == EPlayerSide.Savage)
|
|
{
|
|
side = EPlayerSide.Savage; // Also set side to correct value (defaults to usec/bear when playing as scav)
|
|
int xpGainedInSession = activeProfile.Stats.Eft.SessionCounters.GetAllInt(new object[] { CounterTag.Exp });
|
|
activeProfile.Stats.Eft.TotalSessionExperience = (int)(xpGainedInSession * activeProfile.Stats.Eft.SessionExperienceMult * activeProfile.Stats.Eft.ExperienceBonusMult);
|
|
}
|
|
|
|
return true; // Always do original method
|
|
}
|
|
}
|
|
} |