Decompiled source of Hauling v0.2.0

NathansQol.Hauling.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("NathansQol.Hauling")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+3913b6848f8d56f5ee18d1fea8099922270f8d87")]
[assembly: AssemblyProduct("NathansQol.Hauling")]
[assembly: AssemblyTitle("NathansQol.Hauling")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NathansQol.Hauling
{
	[BepInPlugin("nathan.qol.hauling", "Nathans Hauling", "0.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class HaulingPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "nathan.qol.hauling";

		public const string PluginName = "Nathans Hauling";

		public const string PluginVersion = "0.2.0";

		private const string SkillId = "nathan.qol.hauling.skill";

		internal static ConfigEntry<float> WeightThreshold;

		internal static ConfigEntry<float> XpPerSecond;

		internal static ConfigEntry<float> XpPerJump;

		internal static ConfigEntry<float> CarryWeightPerLevel;

		internal static ConfigEntry<float> RunSneakJumpMultiplier;

		internal static ConfigEntry<float> FullLoadMultiplier;

		internal static ConfigEntry<float> FullLoadThreshold;

		internal static SkillType HaulingSkill;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			WeightThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "WeightThreshold", 0.85f, new ConfigDescription("Fraction of max carry weight needed to gain Hauling XP (0.85 = 255/300).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			XpPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "XpPerSecondMoving", 0.15f, "Skill XP per second of walking/running while above the weight threshold.");
			XpPerJump = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "XpPerJump", 0.2f, "Skill XP per jump while above the weight threshold.");
			CarryWeightPerLevel = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "CarryWeightPerLevel", 1f, "Extra max carry weight granted per whole Hauling level.");
			RunSneakJumpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "RunSneakJumpXpMultiplier", 2f, "XP multiplier while running, sneaking or jumping with a heavy load.");
			FullLoadMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "FullLoadXpMultiplier", 3f, "XP multiplier for all movement while carrying at least FullLoadThreshold of the max carry weight (also when encumbered). Replaces the run/sneak/jump multiplier, they do not stack.");
			FullLoadThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Hauling", "FullLoadThreshold", 0.99f, new ConfigDescription("Fraction of max carry weight that counts as a full load (0.99 = 99%).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			SkillConfig val = new SkillConfig
			{
				Identifier = "nathan.qol.hauling.skill",
				Name = "Hauling",
				Description = "Carrying heavy loads over long distances.",
				Icon = MakeIcon(),
				IncreaseStep = 1f
			};
			SkillManager.Instance.AddSkill(val);
			HaulingSkill = val.UID;
			new Harmony("nathan.qol.hauling").PatchAll();
		}

		private static Sprite MakeIcon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.55f, 0.36f, 0.18f, 1f);
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					val.SetPixel(j, i, val2);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}

		private static float LoadFraction(Player player)
		{
			Inventory inventory = ((Humanoid)player).GetInventory();
			float maxCarryWeight = player.GetMaxCarryWeight();
			if (inventory != null && !(maxCarryWeight <= 0f))
			{
				return inventory.GetTotalWeight() / maxCarryWeight;
			}
			return 0f;
		}

		internal static bool IsHeavilyLoaded(Player player)
		{
			return LoadFraction(player) >= WeightThreshold.Value;
		}

		internal static float XpMultiplier(Player player, bool jumping)
		{
			if (LoadFraction(player) >= FullLoadThreshold.Value)
			{
				return FullLoadMultiplier.Value;
			}
			if (jumping || ((Character)player).IsRunning() || ((Character)player).IsCrouching())
			{
				return RunSneakJumpMultiplier.Value;
			}
			return 1f;
		}
	}
	[HarmonyPatch(typeof(Player), "FixedUpdate")]
	internal static class MovementXpPatch
	{
		private static void Postfix(Player __instance)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Character)__instance).IsDead() && ((Character)__instance).IsOnGround() && !((Character)__instance).IsSwimming() && !((Character)__instance).InInterior())
			{
				Vector3 velocity = ((Character)__instance).GetVelocity();
				velocity.y = 0f;
				if (!(((Vector3)(ref velocity)).magnitude < 1f) && HaulingPlugin.IsHeavilyLoaded(__instance))
				{
					float num = HaulingPlugin.XpPerSecond.Value * HaulingPlugin.XpMultiplier(__instance, jumping: false) * Time.fixedDeltaTime;
					((Character)__instance).RaiseSkill(HaulingPlugin.HaulingSkill, num);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "OnJump")]
	internal static class JumpXpPatch
	{
		private static void Postfix(Player __instance)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && HaulingPlugin.IsHeavilyLoaded(__instance))
			{
				float num = HaulingPlugin.XpPerJump.Value * HaulingPlugin.XpMultiplier(__instance, jumping: true);
				((Character)__instance).RaiseSkill(HaulingPlugin.HaulingSkill, num);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "GetMaxCarryWeight")]
	internal static class CarryWeightPatch
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				float num = Mathf.Floor(((Character)__instance).GetSkillLevel(HaulingPlugin.HaulingSkill));
				__result += num * HaulingPlugin.CarryWeightPerLevel.Value;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}