Decompiled source of BetterWeaponDurability v1.0.2

BetterWeaponDurability.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Autodesk.Fbx")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("FbxBuildTestAssets")]
[assembly: IgnoresAccessChecksTo("Klattersynth")]
[assembly: IgnoresAccessChecksTo("Photon3Unity3D")]
[assembly: IgnoresAccessChecksTo("PhotonChat")]
[assembly: IgnoresAccessChecksTo("PhotonRealtime")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking.Utilities")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.API")]
[assembly: IgnoresAccessChecksTo("PhotonVoice")]
[assembly: IgnoresAccessChecksTo("PhotonVoice.PUN")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime")]
[assembly: IgnoresAccessChecksTo("SingularityGroup.HotReload.Runtime.Public")]
[assembly: IgnoresAccessChecksTo("Sirenix.OdinInspector.Attributes")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization.Config")]
[assembly: IgnoresAccessChecksTo("Sirenix.Serialization")]
[assembly: IgnoresAccessChecksTo("Sirenix.Utilities")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Formats.Fbx.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Postprocessing.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Antlr3.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Core")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.Flow")]
[assembly: IgnoresAccessChecksTo("Unity.VisualScripting.State")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: IgnoresAccessChecksTo("websocket-sharp")]
[assembly: AssemblyCompany("FancyDucc")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BetterWeaponDurability")]
[assembly: AssemblyTitle("BetterWeaponDurability")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BetterWeaponDurability
{
	[BepInPlugin("FancyDucc.BetterWeaponDurability", "BetterWeaponDurability", "1.0")]
	public class BetterWeaponDurability : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <AdjustItemProperties>d__20 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public BetterWeaponDurability <>4__this;

			private ItemMelee[] <melees>5__1;

			private ItemGun[] <guns>5__2;

			private ItemMelee[] <>s__3;

			private int <>s__4;

			private ItemMelee <m>5__5;

			private (float baseDrain, float baseDrainEnemies) <baseVals>5__6;

			private ItemGun[] <>s__7;

			private int <>s__8;

			private ItemGun <g>5__9;

			private float <baseVal>5__10;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AdjustItemProperties>d__20(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<melees>5__1 = null;
				<guns>5__2 = null;
				<>s__3 = null;
				<m>5__5 = null;
				<>s__7 = null;
				<g>5__9 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<melees>5__1 = Resources.FindObjectsOfTypeAll<ItemMelee>();
					<>s__3 = <melees>5__1;
					for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++)
					{
						<m>5__5 = <>s__3[<>s__4];
						if (!meleeBaseValues.ContainsKey(<m>5__5))
						{
							meleeBaseValues[<m>5__5] = (<m>5__5.durabilityDrain, <m>5__5.durabilityDrainOnEnemiesAndPVP);
						}
						<baseVals>5__6 = meleeBaseValues[<m>5__5];
						<m>5__5.durabilityDrain = <baseVals>5__6.baseDrain + MeleeDrainOffset.Value;
						<m>5__5.durabilityDrainOnEnemiesAndPVP = <baseVals>5__6.baseDrainEnemies + MeleeDrainOffset.Value;
						Logger.LogInfo((object)$"Modified ItemMelee {((Object)<m>5__5).name} | new durabilityDrain: {<m>5__5.durabilityDrain}, new durabilityDrainOnEnemiesAndPVP: {<m>5__5.durabilityDrainOnEnemiesAndPVP}");
						<m>5__5 = null;
					}
					<>s__3 = null;
					<guns>5__2 = Resources.FindObjectsOfTypeAll<ItemGun>();
					<>s__7 = <guns>5__2;
					for (<>s__8 = 0; <>s__8 < <>s__7.Length; <>s__8++)
					{
						<g>5__9 = <>s__7[<>s__8];
						if (!gunBaseValues.ContainsKey(<g>5__9))
						{
							gunBaseValues[<g>5__9] = <g>5__9.batteryDrain;
						}
						<baseVal>5__10 = gunBaseValues[<g>5__9];
						if (<g>5__9.batteryDrainFullBar)
						{
							<g>5__9.batteryDrainFullBar = false;
						}
						<g>5__9.batteryDrain = <baseVal>5__10 + GunBatteryDrainOffset.Value;
						Logger.LogInfo((object)$"Modified ItemGun {((Object)<g>5__9).name} | new batteryDrain: {<g>5__9.batteryDrain}");
						<g>5__9 = null;
					}
					<>s__7 = null;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly Dictionary<ItemMelee, (float baseDrain, float baseDrainEnemies)> meleeBaseValues = new Dictionary<ItemMelee, (float, float)>();

		private static readonly Dictionary<ItemGun, float> gunBaseValues = new Dictionary<ItemGun, float>();

		internal static BetterWeaponDurability Instance { get; private set; } = null;


		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal static ConfigEntry<float> MeleeDrainOffset { get; private set; } = null;


		internal static ConfigEntry<float> GunBatteryDrainOffset { get; private set; } = null;


		private void Awake()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			MeleeDrainOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Melee", "DrainOffset", 0f, new ConfigDescription("Offset for durabilityDrain on melee weapons. (Higher = Less Durability)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-500f, 100f), Array.Empty<object>()));
			GunBatteryDrainOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Guns", "BatteryDrainOffset", 0f, new ConfigDescription("Offset for batteryDrain on guns. (Higher = Less Durability)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 500f), Array.Empty<object>()));
			MeleeDrainOffset.SettingChanged += OnConfigChanged;
			GunBatteryDrainOffset.SettingChanged += OnConfigChanged;
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded! WHATS GOING ON GAMERRRSSSS, WE HAVING BETTER DURABILITY WITH THIS ONE \ud83d\ude4f\ud83d\ude4f\ud83c\udf39");
			((MonoBehaviour)this).StartCoroutine(AdjustItemProperties());
		}

		private void OnConfigChanged(object sender, EventArgs e)
		{
			Logger.LogInfo((object)"Only one config changed? Nah we reloading all of them.");
			((MonoBehaviour)this).StartCoroutine(AdjustItemProperties());
		}

		[IteratorStateMachine(typeof(<AdjustItemProperties>d__20))]
		private IEnumerator AdjustItemProperties()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AdjustItemProperties>d__20(0)
			{
				<>4__this = this
			};
		}
	}
}