Decompiled source of PlayerSizePatch v1.1.0

plugins/PlayerSizePatch.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 Photon.Pun;
using TMPro;
using UnboundLib;
using UnboundLib.Networking;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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;
		}
	}
}
namespace PlayerSizePatch
{
	internal class ConfigMenu
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__2_0;

			public static UnityAction<float> <>9__3_0;

			public static UnityAction<float> <>9__3_1;

			internal void <RegisterMenu>b__2_0()
			{
			}

			internal void <CreateMenu>b__3_0(float value)
			{
				CapPlayerSize.Value = value;
			}

			internal void <CreateMenu>b__3_1(float value)
			{
				ScaleThreshold.Value = value;
			}
		}

		public static ConfigEntry<float> CapPlayerSize;

		public static ConfigEntry<float> ScaleThreshold;

		public static void RegisterMenu()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			CapPlayerSize = ((BaseUnityPlugin)PlayerSizePatch.instance).Config.Bind<float>("Player Size Patch", "CapPlayerSize", 10f, "Cap the player size to this value, 0 is no cap");
			ScaleThreshold = ((BaseUnityPlugin)PlayerSizePatch.instance).Config.Bind<float>("Player Size Patch", "ScaleThreshold", 0.3f, "Minimum scale threshold for player size");
			object obj = <>c.<>9__2_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
				};
				<>c.<>9__2_0 = val;
				obj = (object)val;
			}
			Unbound.RegisterMenu("Player Size Patch", (UnityAction)obj, (Action<GameObject>)CreateMenu, (GameObject)null, false);
		}

		private static void CreateMenu(GameObject menu)
		{
			TextMeshProUGUI val = default(TextMeshProUGUI);
			MenuHandler.CreateText("<b>Player Size Patch</b>", menu, ref val, 70, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			AddBlank(menu, 50);
			Slider val2 = default(Slider);
			MenuHandler.CreateSlider("Cap Player Size", menu, 30, 0f, 25f, CapPlayerSize.Value, (UnityAction<float>)delegate(float value)
			{
				CapPlayerSize.Value = value;
			}, ref val2, false, (Color?)null, (Direction)0, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText("Tip: Set the value to 0 to disable the cap", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			AddBlank(menu);
			MenuHandler.CreateSlider("Scale Threshold", menu, 30, 0.1f, 1f, ScaleThreshold.Value, (UnityAction<float>)delegate(float value)
			{
				ScaleThreshold.Value = value;
			}, ref val2, false, (Color?)null, (Direction)0, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText("Tip: Set the value to 0 to disable the threshold", menu, ref val, 20, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		}

		private static void AddBlank(GameObject menu, int size = 30)
		{
			TextMeshProUGUI val = default(TextMeshProUGUI);
			MenuHandler.CreateText(" ", menu, ref val, size, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.aalund13.rounds.playersizepatch", "Player Size Patch", "1.1.0")]
	[BepInProcess("Rounds.exe")]
	public class PlayerSizePatch : BaseUnityPlugin
	{
		private const string modId = "com.aalund13.rounds.playersizepatch";

		internal const string modName = "Player Size Patch";

		internal static PlayerSizePatch instance;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			instance = this;
			new Harmony("com.aalund13.rounds.playersizepatch").PatchAll();
			Unbound.RegisterHandshake("com.aalund13.rounds.playersizepatch", (Action)HandshakeCompleted);
		}

		private void Start()
		{
			ConfigMenu.RegisterMenu();
		}

		private static void HandshakeCompleted()
		{
			if (PhotonNetwork.IsMasterClient || PhotonNetwork.OfflineMode)
			{
				NetworkingManager.RPC(typeof(PlayerSizePatch), "SyncSettings", new object[2]
				{
					ConfigMenu.CapPlayerSize.Value,
					ConfigMenu.ScaleThreshold.Value
				});
			}
		}

		[UnboundRPC]
		private static void SyncSettings(float capPlayerSize, float scaleThreshold)
		{
			ConfigMenu.CapPlayerSize.Value = capPlayerSize;
			ConfigMenu.ScaleThreshold.Value = scaleThreshold;
		}
	}
}
namespace PlayerSizePatch.Patches
{
	[HarmonyPatch(typeof(CharacterStatModifiers), "ConfigureMassAndSize")]
	internal class ConfigureMassAndSizePatch
	{
		private static void Postfix(CharacterStatModifiers __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			CharacterData val = (CharacterData)Traverse.Create((object)__instance).Field("data").GetValue();
			float num = (float)Traverse.Create((object)__instance).Field("sizeMultiplier").GetValue();
			float num2 = 1.2f * Mathf.Pow(val.maxHealth / 100f * 1.2f, 0.2f) * num;
			num2 = Mathf.Clamp(num2, 0f - ConfigMenu.CapPlayerSize.Value, ConfigMenu.CapPlayerSize.Value);
			if (Mathf.Abs(num2) < ConfigMenu.ScaleThreshold.Value)
			{
				num2 = Mathf.Sign(num2) * ConfigMenu.ScaleThreshold.Value;
			}
			((Component)val).transform.localScale = new Vector3(num2, num2, num2);
			float num3 = (float)ExtensionMethods.GetFieldValue((object)val.playerVel, "mass");
			ExtensionMethods.SetFieldValue((object)val.playerVel, "mass", (object)Mathf.Clamp(num3, 0.3f, 1E+32f));
		}
	}
}