Decompiled source of ShowAmmo v1.0.0

ShowAmmo.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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using ShowAmmo.Generic;
using ShowAmmo.Patch.HUD;
using ShowAmmo.Patch.Key;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Build")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("5.0.1")]
[assembly: AssemblyInformationalVersion("3.0.0")]
[assembly: AssemblyProduct("ShowAmmo")]
[assembly: AssemblyTitle("ShowAmmo")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("5.0.1.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 ShowAmmo
{
	[BepInPlugin("Kaguya.ShowAmmo", "ShowAmmo", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public class InputKey : LcInputActions
		{
			[InputAction("<Keyboard>/v", Name = "Show ammo count")]
			public InputAction ToggleDeathBoxKey { get; set; }
		}

		private const string ModGuid = "Kaguya.ShowAmmo";

		private const string ModName = "ShowAmmo";

		private const string ModVersion = "1.0.0";

		private readonly Harmony _harmony = new Harmony("Kaguya.ShowAmmo");

		private static Plugin Instance;

		public static ManualLogSource mls;

		internal static InputKey InputActionInstance = new InputKey();

		public static ConfigEntry<int> Language { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Kaguya.ShowAmmo");
			mls.LogInfo((object)"ShowAmmo has loaded.");
			PatchAll();
			LoadConfig();
		}

		private void PatchAll()
		{
			_harmony.PatchAll(typeof(HUDManagerPostfixPatch));
			_harmony.PatchAll(typeof(KeyPatch));
		}

		private void LoadConfig()
		{
			Language = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "Language", 1, "Select the language for tips. Default is Chinese. Set to 0 for English.");
			GlobalVariables.Language = Language.Value;
		}
	}
}
namespace ShowAmmo.Patch.Key
{
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	internal static class KeyPatch
	{
		internal static void Postfix(PlayerControllerB __instance)
		{
			GlobalVariables.Player = __instance;
			if ((((NetworkBehaviour)__instance).IsOwner || __instance.isTestingPlayer) && !__instance.isPlayerDead && Plugin.InputActionInstance.ToggleDeathBoxKey.WasPressedThisFrame())
			{
				API.DisplayShellsLoaded();
			}
		}
	}
}
namespace ShowAmmo.Patch.HUD
{
	[HarmonyPatch(typeof(HUDManager), "Awake")]
	internal static class HUDManagerPostfixPatch
	{
		private static void Postfix(HUDManager __instance)
		{
			GlobalVariables.HUDManagerInstance = __instance;
		}
	}
}
namespace ShowAmmo.Generic
{
	public class API
	{
		private static int GetAmmoCount()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GlobalVariables.Player == (Object)null)
			{
				Plugin.mls.LogError((object)"Player is null.");
				return -1;
			}
			GrabbableObject val = GlobalVariables.Player.ItemSlots[GlobalVariables.Player.currentItemSlot];
			if (((Object)(object)val != (Object)null && val.itemProperties.itemName == "Shotgun") || ((Object)(object)val != (Object)null && val.itemProperties.itemName == "霰弹枪"))
			{
				return ((ShotgunItem)val).shellsLoaded;
			}
			return -1;
		}

		private static (bool, string, string) GetMessage(int num, int language)
		{
			bool item = false;
			string item2;
			string item3;
			if (language == 1)
			{
				item2 = "霰弹枪";
				if (num == 0)
				{
					item3 = "枪里没有子弹";
					item = true;
				}
				else
				{
					item3 = $"枪里有{num}发子弹";
				}
			}
			else
			{
				item2 = "Shotgun";
				if (num == 0)
				{
					item3 = "There is NO ammo remains in current shotgun.";
					item = true;
				}
				else
				{
					item3 = $"There are {num} ammos remains in current shotgun.";
				}
			}
			return (item, item2, item3);
		}

		public static bool DisplayShellsLoaded()
		{
			if ((Object)(object)GlobalVariables.Player != (Object)null && (Object)(object)GlobalVariables.HUDManagerInstance != (Object)null)
			{
				int ammoCount = GetAmmoCount();
				if (ammoCount == -1)
				{
					return false;
				}
				var (flag, text, text2) = GetMessage(ammoCount, GlobalVariables.Language);
				GlobalVariables.HUDManagerInstance.DisplayTip(text, text2, flag, false, "LC_Tip1");
				return true;
			}
			return false;
		}
	}
	public class GlobalVariables
	{
		public static HUDManager? HUDManagerInstance { get; set; }

		public static PlayerControllerB? Player { get; set; }

		public static int Language { get; set; }
	}
}