Decompiled source of ResizeGun 1911 v1.0.1

Mods/ResizeGunMod.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppSLZ.Marrow;
using MelonLoader;
using Microsoft.CodeAnalysis;
using ResizeGunMod;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ResizeGun), "Resize Gun", "1.0.0", "you", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ResizeGunMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ResizeGunMod")]
[assembly: AssemblyTitle("ResizeGunMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ResizeGunMod
{
	public class ResizeGun : MelonMod
	{
		private const float MaxRayDistance = 500f;

		private const float MinFactor = 0.05f;

		private const float MaxFactor = 10f;

		private const string TargetGunName = "1911";

		private float scaleFactor = 1.5f;

		private bool enabled = true;

		private bool menuCreated;

		private readonly Dictionary<Transform, Vector3> originalScales = new Dictionary<Transform, Vector3>();

		public override void OnInitializeMelon()
		{
			Hooking.OnPostFireGun += OnGunFired;
			MelonLogger.Msg("Resize Gun loaded. Fire the 1911 to scale what you aim at.");
		}

		public override void OnUpdate()
		{
			if (!menuCreated && Page.Root != null)
			{
				CreateMenu();
				menuCreated = true;
			}
		}

		private void CreateMenu()
		{
			//IL_000a: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			Page obj = Page.Root.CreatePage("Resize Gun", Color.cyan, 0, true);
			obj.CreateBool("Enabled", Color.white, true, (Action<bool>)delegate(bool value)
			{
				enabled = value;
			});
			obj.CreateFunction("Bigger (+0.5)", Color.green, (Action)delegate
			{
				scaleFactor = Mathf.Min(scaleFactor + 0.5f, 10f);
				MelonLogger.Msg($"Scale factor: {scaleFactor}");
			});
			obj.CreateFunction("Smaller (-0.5)", Color.yellow, (Action)delegate
			{
				scaleFactor = Mathf.Max(scaleFactor - 0.5f, 0.05f);
				MelonLogger.Msg($"Scale factor: {scaleFactor}");
			});
			obj.CreateFunction("Reset aimed object", Color.red, (Action)ResetAimedObject);
		}

		private void OnGunFired(Gun gun)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (enabled && !((Object)(object)gun == (Object)null))
			{
				string name = ((Object)gun).name;
				MelonLogger.Msg("Gun fired: " + name);
				RaycastHit val = default(RaycastHit);
				if (name.Contains("1911") && Physics.Raycast(((Component)gun).transform.position, ((Component)gun).transform.forward, ref val, 500f))
				{
					ScaleTarget(((RaycastHit)(ref val)).transform.root);
				}
			}
		}

		private void ScaleTarget(Transform target)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				if (!originalScales.ContainsKey(target))
				{
					originalScales[target] = target.localScale;
				}
				target.localScale *= scaleFactor;
			}
		}

		private bool TryGetAimedTarget(out Transform target)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			target = null;
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return false;
			}
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)main).transform.position, ((Component)main).transform.forward, ref val, 500f))
			{
				target = ((RaycastHit)(ref val)).transform.root;
				return true;
			}
			return false;
		}

		private void ResetAimedObject()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (TryGetAimedTarget(out var target) && originalScales.TryGetValue(target, out var value))
			{
				target.localScale = value;
				originalScales.Remove(target);
			}
		}
	}
}