Decompiled source of WastedPercent v1.0.4

Wasted.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Wasted")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+7a6c17364966d044f39c603b4cea244a296dd92f")]
[assembly: AssemblyProduct("Wasted")]
[assembly: AssemblyTitle("Wasted")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Wasted
{
	[BepInPlugin("x.whiteknuckle.wastedpercent", "Wastedpercent", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private bool _wastedActive = false;

		private float _drunkLevel = 1f;

		private Harmony harmony;

		public static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			SceneManager.sceneLoaded += OnSceneLoaded;
			Logger.LogInfo((object)"[Wasted%] Loaded");
			harmony = new Harmony("x.whiteknuckle.wastedpercent");
			harmony.PatchAll();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (!((Object)(object)CommandConsole.instance == (Object)null))
			{
				CommandConsole.BuildCommand("wasted", (Action<string[]>)WastedCommand).Description("(true/false): Toggle the wasted effect").AutocompleteSingleBool()
					.NotCheat();
				CommandConsole.BuildCommand("wastedlevel", (Action<string[]>)WastedLevelCommand).Description("[value]: Set the drunk level, reapplies if wasted is active").NotCheat();
				Logger.LogInfo((object)"[Wasted%] Scene loaded");
				ENT_Player player = ENT_Player.GetPlayer();
				if ((Object)(object)player == (Object)null)
				{
					Logger.LogError((object)"[Wasted%] Player not found on scene load.");
				}
			}
		}

		private void WastedCommand(string[] args)
		{
			if (args.Length == 0)
			{
				_wastedActive = !_wastedActive;
			}
			else if (!bool.TryParse(args[0], out _wastedActive))
			{
				CommandConsole.Log("Unable to parse " + args[0] + " arg needs to be a boolean (true/false).");
				return;
			}
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player == (Object)null)
			{
				Logger.LogError((object)"[Wasted%] Player not found when executing WastedCommand.");
				CommandConsole.Log("Could not find the player.");
			}
			else if (_wastedActive)
			{
				ApplyWineBuff(player);
				CommandConsole.Log("Wasted% effect enabled at level " + _drunkLevel + "!");
			}
			else
			{
				RemoveWineBuff(player);
				CommandConsole.Log("Wasted% effect disabled!");
			}
		}

		private void WastedLevelCommand(string[] args)
		{
			if (args.Length == 0)
			{
				CommandConsole.Log("Incorrect Syntax: wastedlevel [value]");
				return;
			}
			if (!float.TryParse(args[0], out var result))
			{
				CommandConsole.Log("Unable to parse " + args[0] + " arg needs to be a number.");
				return;
			}
			_drunkLevel = result;
			CommandConsole.Log("Drunk level set to " + _drunkLevel);
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)(object)player == (Object)null)
			{
				Logger.LogError((object)"[Wasted%] Player not found when executing WastedLevelCommand.");
				CommandConsole.Log("Could not find the player.");
			}
			else if (_wastedActive)
			{
				RemoveWineBuff(player);
				ApplyWineBuff(player);
				CommandConsole.Log("Reapplying wasted effect at new level " + _drunkLevel + "!");
			}
		}

		private void ApplyWineBuff(ENT_Player player)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0068: Expected O, but got Unknown
			BuffContainer val = new BuffContainer
			{
				id = "intoxication",
				loseOverTime = false,
				loseRate = 0f,
				buffTime = 1f,
				multiplier = _drunkLevel,
				buffs = new List<Buff>
				{
					new Buff
					{
						id = "intoxication",
						maxAmount = 5f
					}
				}
			};
			((GameEntity)player).Buff(val);
			_wastedActive = true;
			Logger.LogInfo((object)("[Wasted%] Wine buff applied at level " + _drunkLevel));
		}

		private void RemoveWineBuff(ENT_Player player)
		{
			((GameEntity)player).RemoveBuff("intoxication");
			_wastedActive = false;
			Logger.LogInfo((object)"[Wasted%] Wine buff removed.");
		}
	}
}