Decompiled source of Better Shotgun Tooltip v1.5.2

BepInEx/Plugins/ShotgunSafety.dll

Decompiled 2 weeks 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 Microsoft.CodeAnalysis;
using Unity.Netcode;

[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("ShotgunSafety")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Config to the shotgun")]
[assembly: AssemblyTitle("ShotgunSafety")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("com.atomic.shotgunsafety", "Shotgun Safety", "1.4.0")]
public class ShotgunPatch : BaseUnityPlugin
{
	internal ConfigEntry<bool> colorizeTextConfig;

	internal ConfigEntry<bool> colorizeFullTextConfig;

	internal ConfigEntry<bool> ammoIndicator;

	internal ConfigEntry<bool> numberRepresentsAmmo;

	internal ConfigEntry<string> colorOnConfig;

	internal ConfigEntry<string> colorOffConfig;

	internal ConfigEntry<string> textOffConfig;

	internal ConfigEntry<string> textOnConfig;

	public static ShotgunPatch Instance { get; private set; }

	private void Awake()
	{
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		colorizeTextConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Text Color", "Colorize Text", false, "Enable or disable colorized text for shotgun safety.");
		colorizeFullTextConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Text Color", "Colorize Full-Text", false, "Enable or disable coloring the entire text instead of just the 'on' or 'off' word.");
		colorOnConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Text Color", "On-Text Color", "green", "The color for the 'on' text.");
		colorOffConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Text Color", "Off-Text Color", "red", "The color for the 'off' text.");
		textOffConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Text Settings", "Safety Text Off", "", "Custom text for safety off. Must contain the keyword 'off'.");
		textOnConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Text Settings", "Safety Text On", "", "Custom text for safety on. Must contain the keyword 'on'.");
		ammoIndicator = ((BaseUnityPlugin)this).Config.Bind<bool>("Miscellaneous", "Ammo Indicator", false, "Shows how much ammo you have in the shotgun.");
		numberRepresentsAmmo = ((BaseUnityPlugin)this).Config.Bind<bool>("Miscellaneous", "Number Represents Ammo", false, "False is more compact, True is more wordy. You can always change this mid game using LethalConfig without a restart");
		new Harmony("com.atomic.shotgunsafety").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Shotgun Safety Plugin loaded successfully.");
	}

	public static string FormatSafetyText(string text, string keyword, string color, bool fullColor, bool shouldColor)
	{
		if (string.IsNullOrWhiteSpace(text) || !text.ToLower().Contains(keyword.ToLower()))
		{
			return "Incorrect setup! Missing keyword: " + keyword;
		}
		string text2 = (fullColor ? ("<color=" + color + ">") : ("<color=white></color><color=" + color + ">"));
		if (!shouldColor)
		{
			return text;
		}
		if (fullColor)
		{
			return text.Replace(text, text2 + text + "</color>");
		}
		if (!fullColor)
		{
			return text.Replace(keyword, text2 + keyword + "</color>");
		}
		return null;
	}
}
[HarmonyPatch(typeof(ShotgunItem))]
public class ShotgunItemPatches
{
	[HarmonyPostfix]
	[HarmonyPatch("SetControlTipsForItem")]
	[HarmonyPatch("SetSafetyControlTip")]
	[HarmonyPatch("ItemActivate")]
	[HarmonyPatch("ReloadGunEffectsServerRpc")]
	private static void UpdateTooltips(ShotgunItem __instance, int ___shellsLoaded)
	{
		string text = (__instance.safetyOn ? ShotgunPatch.FormatSafetyText(string.IsNullOrWhiteSpace(ShotgunPatch.Instance.textOnConfig.Value) ? "The safety is on: [Q]" : (ShotgunPatch.Instance.textOnConfig.Value + ": [Q]"), "on", ShotgunPatch.Instance.colorOnConfig.Value, ShotgunPatch.Instance.colorizeFullTextConfig.Value, ShotgunPatch.Instance.colorizeTextConfig.Value ? true : false) : ShotgunPatch.FormatSafetyText(string.IsNullOrWhiteSpace(ShotgunPatch.Instance.textOffConfig.Value) ? "The safety is off: [Q]" : (ShotgunPatch.Instance.textOffConfig.Value + ": [Q]"), "off", ShotgunPatch.Instance.colorOffConfig.Value, ShotgunPatch.Instance.colorizeFullTextConfig.Value, ShotgunPatch.Instance.colorizeTextConfig.Value ? true : false));
		if (((NetworkBehaviour)__instance).IsOwner)
		{
			string[] toolTips = ((GrabbableObject)__instance).itemProperties.toolTips;
			toolTips[2] = (ShotgunPatch.Instance.colorizeTextConfig.Value ? text : (ShotgunPatch.Instance.textOnConfig.Value ?? "The safety is on: [Q]"));
			HUDManager.Instance.ChangeControlTip(3, text, false);
			HUDManager.Instance.ChangeControlTipMultiple(toolTips, true, ((GrabbableObject)__instance).itemProperties);
		}
		if (ShotgunPatch.Instance.ammoIndicator.Value)
		{
			if (ShotgunPatch.Instance.numberRepresentsAmmo.Value)
			{
				string[] toolTips2 = ((GrabbableObject)__instance).itemProperties.toolTips;
				toolTips2[0] = $"Fire ({___shellsLoaded} Loaded): [RMB]";
				if (((NetworkBehaviour)__instance).IsOwner)
				{
					HUDManager.Instance.ChangeControlTipMultiple(toolTips2, true, ((GrabbableObject)__instance).itemProperties);
				}
				return;
			}
			char c = ((___shellsLoaded >= 1) ? 'O' : ' ');
			char c2 = ((___shellsLoaded >= 2) ? 'O' : ' ');
			string[] toolTips3 = ((GrabbableObject)__instance).itemProperties.toolTips;
			toolTips3[0] = $"Fire ({c})({c2}): [RMB]";
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				HUDManager.Instance.ChangeControlTipMultiple(toolTips3, true, ((GrabbableObject)__instance).itemProperties);
			}
		}
		else
		{
			string[] toolTips4 = ((GrabbableObject)__instance).itemProperties.toolTips;
			toolTips4[0] = "Fire: [RMB]";
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				HUDManager.Instance.ChangeControlTipMultiple(toolTips4, true, ((GrabbableObject)__instance).itemProperties);
			}
		}
	}
}
namespace ShotgunSafety
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ShotgunSafety";

		public const string PLUGIN_NAME = "Config to the shotgun";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}