Decompiled source of GunModifier v1.0.1

Mods/GunModifier.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using GunModifier;
using GunModifier.Core;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(GunModifierMod), "Gun Modifier", "1.0.0", "habibis_v on discord on discord", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GunModifier")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GunModifier")]
[assembly: AssemblyTitle("GunModifier")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace GunModifier
{
	public class GunModifierMod : MelonMod
	{
		public static GunModifierMod Instance { get; private set; }

		public override void OnInitializeMelon()
		{
			Instance = this;
			Hooking.OnUIRigCreated += MenuSetup.Build;
			((MelonBase)this).LoggerInstance.Msg("Gun Modifier loaded.");
		}
	}
}
namespace GunModifier.Core
{
	public static class MenuSetup
	{
		private record GunSnapshot(float Rpm, float MuzzleVelocity, bool Silenced, FireMode FireMode)
		{
			[CompilerGenerated]
			protected virtual bool PrintMembers(StringBuilder builder)
			{
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				RuntimeHelpers.EnsureSufficientExecutionStack();
				builder.Append("Rpm = ");
				builder.Append(Rpm.ToString());
				builder.Append(", MuzzleVelocity = ");
				builder.Append(MuzzleVelocity.ToString());
				builder.Append(", Silenced = ");
				builder.Append(Silenced.ToString());
				builder.Append(", FireMode = ");
				FireMode fireMode = FireMode;
				builder.Append(((object)(FireMode)(ref fireMode)).ToString());
				return true;
			}

			[CompilerGenerated]
			public void Deconstruct(out float Rpm, out float MuzzleVelocity, out bool Silenced, out FireMode FireMode)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected I4, but got Unknown
				Rpm = this.Rpm;
				MuzzleVelocity = this.MuzzleVelocity;
				Silenced = this.Silenced;
				FireMode = (FireMode)(int)this.FireMode;
			}
		}

		private static float _rpm = 600f;

		private static float _muzzleVelocity = 400f;

		private static bool _silenced = false;

		private static FireMode _fireMode = (FireMode)1;

		private static FloatElement? _rpmEl;

		private static FloatElement? _muzzleEl;

		private static BoolElement? _silencedEl;

		private static EnumElement? _modeEl;

		private static bool _built;

		private static readonly Dictionary<int, GunSnapshot> _snapshots = new Dictionary<int, GunSnapshot>();

		public static void Build()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			if (_built)
			{
				return;
			}
			_built = true;
			Page val = Page.Root.CreatePage("Gun Modifier", Color.yellow, 0, true);
			_rpmEl = val.CreateFloat("RPM", Color.cyan, _rpm, 100f, 100f, 99999f, (Action<float>)delegate(float v)
			{
				_rpm = v;
			});
			_muzzleEl = val.CreateFloat("Muzzle Velocity (m/s)", Color.cyan, _muzzleVelocity, 50f, 0f, 5000f, (Action<float>)delegate(float v)
			{
				_muzzleVelocity = v;
			});
			_silencedEl = val.CreateBool("Silenced", Color.white, _silenced, (Action<bool>)delegate(bool v)
			{
				_silenced = v;
			});
			_modeEl = val.CreateEnum("Fire Mode", Color.white, (Enum)(object)_fireMode, (Action<Enum>)delegate(Enum v)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				_fireMode = (FireMode)(object)v;
			});
			val.CreateFunction("────────────────", Color.grey, (Action)delegate
			{
			});
			val.CreateFunction("Apply to All Guns", Color.green, (Action)delegate
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				ApplyToAll(_rpm, _muzzleVelocity, _silenced, _fireMode);
			});
			val.CreateFunction("Reset All Guns", new Color(1f, 0.5f, 0f), (Action)delegate
			{
				ResetAll();
			});
			val.CreateFunction("omgomg", Color.red, (Action)delegate
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				_rpm = 99999f;
				_muzzleVelocity = 5000f;
				_silenced = true;
				_fireMode = (FireMode)2;
				if (_rpmEl != null)
				{
					_rpmEl.Value = _rpm;
				}
				if (_muzzleEl != null)
				{
					_muzzleEl.Value = _muzzleVelocity;
				}
				if (_silencedEl != null)
				{
					_silencedEl.Value = _silenced;
				}
				if (_modeEl != null)
				{
					_modeEl.Value = (Enum)(object)_fireMode;
				}
				ApplyToAll(_rpm, _muzzleVelocity, _silenced, _fireMode);
			});
			val.CreateFunction("────────────────", Color.blue, (Action)delegate
			{
			});
			val.CreateFunction("Add me on discord", Color.blue, (Action)delegate
			{
			});
			val.CreateFunction("if you need help!", Color.blue, (Action)delegate
			{
			});
			val.CreateFunction("Discord: habibis_v", Color.blue, (Action)delegate
			{
			});
		}

		private static void ApplyToAll(float rpm, float muzzleVelocity, bool silenced, FireMode mode)
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Il2CppArrayBase<Gun> val = Object.FindObjectsOfType<Gun>();
			if (val == null || val.Count == 0)
			{
				Notify((NotificationType)1, "You have not spawned anything.");
				return;
			}
			int num = 0;
			foreach (Gun item in val)
			{
				if (!((Object)(object)item == (Object)null))
				{
					int instanceID = ((Object)item).GetInstanceID();
					if (!_snapshots.ContainsKey(instanceID))
					{
						_snapshots[instanceID] = new GunSnapshot(item.roundsPerMinute, item.muzzleVelocity, item.isSilenced, item.fireMode);
					}
					Extensions.SetRpm(item, rpm);
					item.muzzleVelocity = muzzleVelocity;
					item.isSilenced = silenced;
					item.fireMode = mode;
					num++;
				}
			}
			MelonLogger.Msg($"[GunModifier] Applied to {num} guns — RPM:{rpm}  MV:{muzzleVelocity}  Silenced:{silenced}  Mode:{mode}");
			Notify((NotificationType)3, $"Modified {num} gun{((num == 1) ? "" : "s")}!");
		}

		private static void ResetAll()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (_snapshots.Count == 0)
			{
				Notify((NotificationType)1, "Nothing to reset — apply first.");
				return;
			}
			Il2CppArrayBase<Gun> val = Object.FindObjectsOfType<Gun>();
			int num = 0;
			foreach (Gun item in val)
			{
				if (!((Object)(object)item == (Object)null))
				{
					int instanceID = ((Object)item).GetInstanceID();
					if (_snapshots.TryGetValue(instanceID, out GunSnapshot value))
					{
						Extensions.SetRpm(item, value.Rpm);
						item.muzzleVelocity = value.MuzzleVelocity;
						item.isSilenced = value.Silenced;
						item.fireMode = value.FireMode;
						num++;
					}
				}
			}
			_snapshots.Clear();
			MelonLogger.Msg($"[GunModifier] Reset {num} guns to original values.");
			Notify((NotificationType)3, $"Reset {num} gun{((num == 1) ? "" : "s")} to original!");
		}

		private static void Notify(NotificationType type, string message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Notifier.Send(new Notification
			{
				Title = NotificationText.op_Implicit("Gun Modifier"),
				Message = NotificationText.op_Implicit(message),
				Type = type,
				ShowTitleOnPopup = true,
				PopupLength = 2f
			});
		}
	}
}