Decompiled source of HeavyArmorSkill v1.0.0

HeavyArmorSkill.dll

Decompiled 3 days ago
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HeavyArmorSkill")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HeavyArmorSkill")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0d34960b-f2f8-4deb-a280-2e7385fb0457")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HeavyArmorSkill;

[BepInPlugin("com.Perevoznikov.heavyarmorskill", "Heavy Armor Skill", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class HeavyArmorPlugin : BaseUnityPlugin
{
	public static SkillType HeavyArmorSkillType;

	private CustomLocalization Localization;

	public static ConfigEntry<float> MaxStaminaReduction;

	public static ConfigEntry<float> SkillGainPerTick;

	public static ConfigEntry<float> MinArmorThreshold;

	private void Awake()
	{
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Expected O, but got Unknown
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		MaxStaminaReduction = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxStaminaReduction", 0.4f, "Максимальное снижение затрат выносливости (0.4 = 40%) на 100 уровне навыка.");
		SkillGainPerTick = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SkillGainPerTick", 0.005f, "Сколько опыта навыка добавляется за каждый кадр бега в тяжелой броне.");
		MinArmorThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MinArmorThreshold", 30f, "Минимальное значение брони, чтобы навык начал качаться и работать.");
		Localization = LocalizationManager.Instance.GetLocalization();
		CustomLocalization localization = Localization;
		string text = "Russian";
		localization.AddTranslation(ref text, new Dictionary<string, string>
		{
			{ "skill_heavyarmor", "Тяжёлая броня" },
			{ "skill_heavyarmor_desc", "Снижает расход выносливости при ношении тяжёлой брони." }
		});
		CustomLocalization localization2 = Localization;
		text = "English";
		localization2.AddTranslation(ref text, new Dictionary<string, string>
		{
			{ "skill_heavyarmor", "Heavy Armor" },
			{ "skill_heavyarmor_desc", "Reduces stamina drain when wearing heavy armor." }
		});
		Sprite icon = LoadCustomIcon("heavy_armor_icon.png");
		SkillConfig val = new SkillConfig
		{
			Identifier = "com.yourname.heavyarmorskill.heavyarmor",
			Name = "$skill_heavyarmor",
			Description = "$skill_heavyarmor_desc",
			IncreaseStep = 1f,
			Icon = icon
		};
		HeavyArmorSkillType = SkillManager.Instance.AddSkill(val);
		CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new RaiseHeavyArmorCommand());
		Harmony val2 = new Harmony("com.yourname.heavyarmorskill");
		val2.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Heavy Armor Skill mod loaded!");
	}

	private Sprite LoadCustomIcon(string fileName)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), fileName);
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Файл иконки не найден: " + text));
			return null;
		}
		Texture2D val = AssetUtils.LoadTexture(text, true);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
	}

	private void Update()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null))
		{
			Vector3 velocity = ((Character)localPlayer).GetVelocity();
			Vector3 val = new Vector3(velocity.x, 0f, velocity.z);
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude > 6f && ((Character)localPlayer).GetBodyArmor() >= MinArmorThreshold.Value)
			{
				((Character)localPlayer).RaiseSkill(HeavyArmorSkillType, SkillGainPerTick.Value);
			}
		}
	}
}
[HarmonyPatch(typeof(Player), "UseStamina")]
public static class Patch_Player_UseStamina
{
	private static void Postfix(Player __instance, float v)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance == (Object)null) && ((Character)__instance).IsOwner() && (!((Object)(object)ZNet.instance != (Object)null) || ZNet.instance.IsServer()) && !(__instance.GetStamina() <= 0f))
		{
			float skillLevel = ((Character)__instance).GetSkillLevel(HeavyArmorPlugin.HeavyArmorSkillType);
			if (!(skillLevel <= 0f))
			{
				float num = skillLevel / 100f * HeavyArmorPlugin.MaxStaminaReduction.Value;
				float num2 = v * num;
				((Character)__instance).AddStamina(num2);
			}
		}
	}
}
public class RaiseHeavyArmorCommand : ConsoleCommand
{
	public override string Name => "raiseheavyarmor";

	public override string Help => "Устанавливает уровень навыка. Использование: raiseheavyarmor [уровень]";

	public override bool IsCheat => true;

	public override void Run(string[] args)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		int result;
		if ((Object)(object)Player.m_localPlayer == (Object)null)
		{
			Console.instance.Print("Игрок ещё не загружен.");
		}
		else if (args.Length == 0)
		{
			Console.instance.Print($"Текущий уровень: {((Character)Player.m_localPlayer).GetSkillLevel(HeavyArmorPlugin.HeavyArmorSkillType)}");
			Console.instance.Print("Использование: raiseheavyarmor [уровень]");
		}
		else if (int.TryParse(args[0], out result))
		{
			result = Mathf.Clamp(result, 0, 100);
			object? obj = typeof(Player).GetField("m_skills", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(Player.m_localPlayer);
			Skills val = (Skills)((obj is Skills) ? obj : null);
			Skill val2 = ((val != null) ? val.GetSkillList() : null)?.Find((Skill s) => s.m_info.m_skill == HeavyArmorPlugin.HeavyArmorSkillType);
			if (val2 != null)
			{
				val2.m_level = result;
				val2.m_accumulator = 0f;
				Console.instance.Print($"Навык 'Тяжёлая броня' установлен на уровень {result}.");
			}
			else
			{
				Console.instance.Print("Ошибка: навык не найден. Попробуйте сначала побегать.");
			}
		}
		else
		{
			Console.instance.Print("Ошибка: укажите число. Например: raiseheavyarmor 100");
		}
	}
}