Update to 3.5.6 and for components
This commit is contained in:
207
Plugin.cs
207
Plugin.cs
@@ -1,172 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Aki.Reflection.Patching;
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using Comfort.Common;
|
||||
using EFT;
|
||||
using EFT.InventoryLogic;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using VersionChecker;
|
||||
|
||||
namespace armorMod
|
||||
namespace ASS
|
||||
{
|
||||
[BepInPlugin("com.armorMod.ASS", "armorMod.ASS", "1.0.0")]
|
||||
|
||||
public class ASS : BaseUnityPlugin
|
||||
[BepInPlugin("com.dvize.ASS", "dvize.ASS", "1.1.0")]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
{
|
||||
private ConfigEntry<Boolean> ArmorServiceMode
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
private static ConfigEntry<float> TimeDelayRepairInSec
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
private static ConfigEntry<float> ArmorRepairRateOverTime
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
private AbstractGame game;
|
||||
private bool runOnceAlready = false;
|
||||
private bool newGame = true;
|
||||
private float newRepairRate;
|
||||
private ArmorComponent armor;
|
||||
private static float timeSinceLastHit = 0f;
|
||||
|
||||
private readonly Dictionary<EquipmentSlot, List<Item>> equipmentSlotDictionary = new Dictionary<EquipmentSlot, List<Item>>
|
||||
{
|
||||
{ EquipmentSlot.ArmorVest, new List<Item>() },
|
||||
{ EquipmentSlot.TacticalVest, new List<Item>() },
|
||||
{ EquipmentSlot.Eyewear, new List<Item>() },
|
||||
{ EquipmentSlot.FaceCover, new List<Item>() },
|
||||
{ EquipmentSlot.Headwear, new List<Item>() }
|
||||
};
|
||||
internal static ConfigEntry<Boolean> ArmorServiceMode { get; set; }
|
||||
internal static ConfigEntry<float> TimeDelayRepairInSec { get; set; }
|
||||
internal static ConfigEntry<float> ArmorRepairRateOverTime { get; set; }
|
||||
|
||||
internal void Awake()
|
||||
{
|
||||
ArmorServiceMode = Config.Bind("Armor Repair Settings", "Enable/Disable Mod", true, "Enables the Armor Repairing Options Below");
|
||||
TimeDelayRepairInSec = Config.Bind("Armor Repair Settings", "Time Delay Repair in Sec", 60f, "How Long Before you were last hit that it repairs armor");
|
||||
ArmorRepairRateOverTime = Config.Bind("Armor Repair Settings", "Armor Repair Rate", 0.5f, "How much durability per second is repaired");
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
game = Singleton<AbstractGame>.Instance;
|
||||
CheckEftVersion();
|
||||
|
||||
if (game.InRaid && Camera.main.transform.position != null && newGame && ArmorServiceMode.Value)
|
||||
{
|
||||
var player = Singleton<GameWorld>.Instance.MainPlayer;
|
||||
timeSinceLastHit += Time.deltaTime;
|
||||
|
||||
if (!runOnceAlready && game.Status == GameStatus.Started)
|
||||
{
|
||||
Logger.LogDebug("ASS: Attaching events");
|
||||
player.BeingHitAction += Player_BeingHitAction;
|
||||
player.OnPlayerDeadOrUnspawn += Player_OnPlayerDeadOrUnspawn;
|
||||
runOnceAlready = true;
|
||||
}
|
||||
|
||||
RepairArmor();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
ArmorServiceMode = Config.Bind(
|
||||
"Armor Repair Settings",
|
||||
"Enable/Disable Mod",
|
||||
true,
|
||||
"Enables the Armor Repairing Options Below"
|
||||
);
|
||||
TimeDelayRepairInSec = Config.Bind(
|
||||
"Armor Repair Settings",
|
||||
"Time Delay Repair in Sec",
|
||||
60f,
|
||||
"How Long Before you were last hit that it repairs armor"
|
||||
);
|
||||
ArmorRepairRateOverTime = Config.Bind(
|
||||
"Armor Repair Settings",
|
||||
"Armor Repair Rate",
|
||||
0.5f,
|
||||
"How much durability per second is repaired"
|
||||
);
|
||||
}
|
||||
|
||||
private void RepairArmor()
|
||||
private void CheckEftVersion()
|
||||
{
|
||||
//if the time since we were last hit exceeds TimeDelayRepairInSec.Value then repair all armor
|
||||
if (timeSinceLastHit >= TimeDelayRepairInSec.Value)
|
||||
// Make sure the version of EFT being run is the correct version
|
||||
int currentVersion = FileVersionInfo
|
||||
.GetVersionInfo(BepInEx.Paths.ExecutablePath)
|
||||
.FilePrivatePart;
|
||||
int buildVersion = TarkovVersion.BuildVersion;
|
||||
if (currentVersion != buildVersion)
|
||||
{
|
||||
//Logger.LogInfo($"Repairing Armor Block Reached Because TimeSinceLastHitReached: " + timeSinceLastHit);
|
||||
//repair the armor divided by the time.unfixed rate
|
||||
newRepairRate = ArmorRepairRateOverTime.Value * Time.deltaTime;
|
||||
|
||||
foreach (EquipmentSlot slot in equipmentSlotDictionary.Keys.ToArray())
|
||||
{
|
||||
Logger.LogInfo("ASS: Checking EquipmentSlot: " + slot);
|
||||
Slot tempSlot = getEquipSlot(slot);
|
||||
|
||||
if (tempSlot == null || tempSlot.ContainedItem == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var item in tempSlot.ContainedItem.GetAllItems())
|
||||
{
|
||||
//get the armorcomponent of each item in items and check to see if all item componenets (even helmet side ears) are max durability
|
||||
armor = item.GetItemComponent<ArmorComponent>();
|
||||
|
||||
//check if it needs repair for the current item in loop of all items for the slot
|
||||
if (armor != null && (armor.Repairable.Durability < armor.Repairable.MaxDurability))
|
||||
{
|
||||
//increase armor durability by newRepairRate until maximum then set as maximum durability
|
||||
if (armor.Repairable.Durability + newRepairRate >= armor.Repairable.MaxDurability)
|
||||
{
|
||||
armor.Repairable.Durability = armor.Repairable.MaxDurability;
|
||||
//Logger.LogInfo("ASS: Setting MaxDurability for " + item.LocalizedName());
|
||||
}
|
||||
else
|
||||
{
|
||||
armor.Repairable.Durability += newRepairRate;
|
||||
//Logger.LogInfo("ASS: Repairing " + item.LocalizedName() + " : " + armor.Repairable.Durability + "/" + armor.Repairable.MaxDurability);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Logger.LogError(
|
||||
$"ERROR: This version of {Info.Metadata.Name} v{Info.Metadata.Version} was built for Tarkov {buildVersion}, but you are running {currentVersion}. Please download the correct plugin version."
|
||||
);
|
||||
EFT.UI.ConsoleScreen.LogError(
|
||||
$"ERROR: This version of {Info.Metadata.Name} v{Info.Metadata.Version} was built for Tarkov {buildVersion}, but you are running {currentVersion}. Please download the correct plugin version."
|
||||
);
|
||||
throw new Exception($"Invalid EFT Version ({currentVersion} != {buildVersion})");
|
||||
}
|
||||
}
|
||||
|
||||
private void Player_BeingHitAction(DamageInfo dmgInfo, EBodyPart bodyPart, float hitEffectId) => timeSinceLastHit = 0f;
|
||||
|
||||
private void Player_OnPlayerDeadOrUnspawn(Player player)
|
||||
{
|
||||
Logger.LogDebug("ASS: Undo all events");
|
||||
player.BeingHitAction -= Player_BeingHitAction;
|
||||
player.OnPlayerDeadOrUnspawn -= Player_OnPlayerDeadOrUnspawn;
|
||||
runOnceAlready = false;
|
||||
newGame = false;
|
||||
|
||||
Task.Delay(TimeSpan.FromSeconds(15)).ContinueWith(_ =>
|
||||
{
|
||||
// Set newGame = true after the timer is finished so it doesn't execute the events right away
|
||||
newGame = true;
|
||||
});
|
||||
}
|
||||
|
||||
private Slot slotContents;
|
||||
private InventoryControllerClass inventoryController;
|
||||
private Slot getEquipSlot(EquipmentSlot slot)
|
||||
{
|
||||
var player = Singleton<GameWorld>.Instance.MainPlayer;
|
||||
|
||||
// Use AccessTools to get the protected field _inventoryController
|
||||
inventoryController = (InventoryControllerClass)AccessTools.Field(typeof(Player), "_inventoryController").GetValue(player);
|
||||
|
||||
|
||||
if (inventoryController != null)
|
||||
{
|
||||
slotContents = inventoryController.Inventory.Equipment.GetSlot(slot);
|
||||
|
||||
if (slotContents.ContainedItem == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return slotContents;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//re-initializes each new game
|
||||
internal class NewGamePatch : ModulePatch
|
||||
{
|
||||
protected override MethodBase GetTargetMethod() =>
|
||||
typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
|
||||
|
||||
[PatchPrefix]
|
||||
public static void PatchPrefix()
|
||||
{
|
||||
ASS.ArmorRegenComponent.Enable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user