Decompiled source of GunRangeNoLimit v1.0.0

GunRangeNoLimit.dll

Decompiled a day ago
using System;
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 HarmonyLib;
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: AssemblyCompany("zabu")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("zabumod")]
[assembly: AssemblyTitle("zabumod")]
[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 GunRangeNoLimit
{
	[BepInPlugin("jp.repo.gunrangenolimit", "GunRangeNoLimit", "1.0.0")]
	public sealed class GunRangeNoLimitPlugin : BaseUnityPlugin
	{
		private static class Patches
		{
			[HarmonyPatch(typeof(ItemGun), "Start")]
			[HarmonyPostfix]
			private static void ItemGun_Start_Postfix(ItemGun __instance)
			{
				ApplyRange(__instance);
			}

			[HarmonyPatch(typeof(ItemGun), "OnDestroy")]
			[HarmonyPrefix]
			private static void ItemGun_OnDestroy_Prefix(ItemGun __instance)
			{
				if (!((Object)(object)__instance == (Object)null))
				{
					int instanceID = ((Object)__instance).GetInstanceID();
					if (OriginalGunRanges.ContainsKey(instanceID))
					{
						OriginalGunRanges.Remove(instanceID);
					}
				}
			}
		}

		private Harmony _harmony;

		private static ConfigEntry<bool> CfgEnableMod;

		private static ConfigEntry<float> CfgRangeMultiplier;

		private static ConfigEntry<bool> CfgApplyVisualForClients;

		private static readonly Dictionary<int, float> OriginalGunRanges = new Dictionary<int, float>();

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			CfgEnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, new ConfigDescription("Enable or disable this mod.このMODを有効化または無効化します", (AcceptableValueBase)null, Array.Empty<object>()));
			CfgRangeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RangeMultiplier", 300f, new ConfigDescription("Multiplier applied to gun Raycast range.銃のRaycast射程へ適用する倍率", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 10000f), Array.Empty<object>()));
			CfgApplyVisualForClients = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ApplyVisualForClients", true, new ConfigDescription("Apply extended laser visuals on non-host clients.参加者側にもレーザー表示延長を適用します", (AcceptableValueBase)null, Array.Empty<object>()));
			CfgEnableMod.SettingChanged += delegate
			{
				ApplyAllExistingGuns();
			};
			CfgRangeMultiplier.SettingChanged += delegate
			{
				ApplyAllExistingGuns();
			};
			CfgApplyVisualForClients.SettingChanged += delegate
			{
				ApplyAllExistingGuns();
			};
			_harmony = new Harmony("jp.repo.gunrangenolimit.harmony");
			_harmony.PatchAll(typeof(Patches));
		}

		private static void ApplyAllExistingGuns()
		{
			try
			{
				ItemGun[] array = Object.FindObjectsOfType<ItemGun>(true);
				ItemGun[] array2 = array;
				foreach (ItemGun gun in array2)
				{
					ApplyRange(gun);
				}
			}
			catch
			{
			}
		}

		private static void ApplyRange(ItemGun gun)
		{
			if ((Object)(object)gun == (Object)null)
			{
				return;
			}
			if (!CfgEnableMod.Value)
			{
				RestoreRange(gun);
				return;
			}
			if (!CfgApplyVisualForClients.Value && !SemiFunc.IsMasterClientOrSingleplayer())
			{
				RestoreRange(gun);
				return;
			}
			int instanceID = ((Object)gun).GetInstanceID();
			if (!OriginalGunRanges.ContainsKey(instanceID))
			{
				OriginalGunRanges[instanceID] = gun.gunRange;
			}
			float num = OriginalGunRanges[instanceID];
			gun.gunRange = num * CfgRangeMultiplier.Value;
		}

		private static void RestoreRange(ItemGun gun)
		{
			if (!((Object)(object)gun == (Object)null))
			{
				int instanceID = ((Object)gun).GetInstanceID();
				if (OriginalGunRanges.TryGetValue(instanceID, out var value))
				{
					gun.gunRange = value;
				}
			}
		}
	}
}