Decompiled source of BetterShockStick v1.1.0

BepInEx/plugins/BetterShockStick.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("BetterShockStick")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("BetterShockStick")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("BetterShockStick")]
[assembly: AssemblyTitle("BetterShockStick")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterShockStick
{
	[ContentWarningPlugin("viviko.BetterShockStick", "BetterShockStick", true)]
	[BepInPlugin("viviko.BetterShockStick", "BetterShockStick", "1.1.0")]
	public class BetterShockStick : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ShockStick))]
		internal class ShockStickPatch
		{
			[HarmonyPatch("ConfigItem")]
			[HarmonyPrefix]
			private static void ConfigItemPatch(ShockStick __instance)
			{
				__instance.shockBatteryCost = 0f;
			}

			[HarmonyPatch("RPC_Shock")]
			[HarmonyPostfix]
			private static void RPC_ShockPatch(ShockStick __instance)
			{
				if (!__instance.m_onOffEntry.on)
				{
					__instance.m_onOffEntry.on = true;
					((ItemDataEntry)__instance.m_onOffEntry).SetDirty();
				}
			}

			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			private static void UpdatePatch(ShockStick __instance)
			{
				if (Instance.infiniteCharge.Value)
				{
					__instance.m_batteryEntry.m_charge = __instance.m_batteryEntry.m_maxCharge;
				}
			}
		}

		[HarmonyPatch(typeof(ShockStickTrigger))]
		internal class ShockStickTriggerPatch
		{
			[HarmonyTranspiler]
			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			private static IEnumerable<CodeInstruction> TranspileMoveNext(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				for (int i = 0; i < list.Count; i++)
				{
					CodeInstruction val = list[i];
					if (!(val.opcode != OpCodes.Ldc_R4) && (float)val.operand == 1f)
					{
						val.operand = 0.2f;
					}
				}
				return list.AsEnumerable();
			}
		}

		[HarmonyPatch(typeof(GameHandler))]
		internal class GameHandlerPatch
		{
			[HarmonyPatch("Initialize")]
			[HarmonyPostfix]
			private static void InitializePatch(GameHandler __instance)
			{
				Setting val = (Setting)(object)new InfiniteChargeSetting();
				__instance.SettingsHandler.settings.Add(val);
				val.Load(__instance.SettingsHandler._settingsSaveLoad);
				val.ApplyValue();
			}
		}

		public class InfiniteChargeSetting : EnumSetting, IExposedSetting
		{
			public override void ApplyValue()
			{
				Instance.infiniteCharge.Value = ((IntSetting)this).Value != 0;
			}

			public override List<string> GetChoices()
			{
				return new List<string>(2) { "OFF", "ON" };
			}

			public string GetDisplayName()
			{
				return ((ConfigEntryBase)Instance.infiniteCharge).Definition.Key;
			}

			public SettingCategory GetSettingCategory()
			{
				return (SettingCategory)2;
			}

			protected override int GetDefaultValue()
			{
				return (int)((ConfigEntryBase)Instance.infiniteCharge).DefaultValue;
			}

			public override void Load(ISettingsSaveLoad loader)
			{
				((IntSetting)this).Value = (Instance.infiniteCharge.Value ? 1 : 0);
			}
		}

		private const string modGUID = "viviko.BetterShockStick";

		private const string modName = "BetterShockStick";

		private const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("viviko.BetterShockStick");

		public static BetterShockStick Instance;

		internal ManualLogSource mls;

		public ConfigEntry<bool> infiniteCharge;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("viviko.BetterShockStick");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			infiniteCharge = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Infinite ShockStick", false, "Infinite ShockStick battery");
			mls.LogInfo((object)"Plugin BetterShockStick is loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterShockStick";

		public const string PLUGIN_NAME = "BetterShockStick";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}