Decompiled source of MiniEepo v1.3.0

MiniEepo.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using ScalerCore;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MiniEepo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("MiniEepo")]
[assembly: AssemblyTitle("MiniEepo")]
[assembly: AssemblyVersion("1.3.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 MiniEepo
{
	[BepInPlugin("darkharasho.MiniEepo", "MiniEepo", "1.3.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log = null;

		internal static ConfigEntry<float> PlayerScale = null;

		internal static ConfigEntry<float> ItemScale = null;

		internal static ConfigEntry<float> ValuableScale = null;

		internal static ConfigEntry<float> CartScale = null;

		internal static ConfigEntry<bool> VoiceMod = null;

		internal static ConfigEntry<bool> ShrinkInShop = null;

		internal static float ActivePlayerScale;

		internal static float ActiveItemScale;

		internal static float ActiveValuableScale;

		internal static float ActiveCartScale;

		internal static bool ActiveVoiceMod;

		internal static bool ActiveShrinkInShop;

		internal static readonly HashSet<int> ManagedObjects = new HashSet<int>();

		internal static bool IsApplying;

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Expected O, but got Unknown
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Expected O, but got Unknown
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Expected O, but got Unknown
			//IL_0574: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Expected O, but got Unknown
			//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Expected O, but got Unknown
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0691: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0.1f, 1f);
			PlayerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "PlayerScale", 0.4f, new ConfigDescription("Scale multiplier for players (0.4 = 40%)", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ItemScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "ItemScale", 0.4f, new ConfigDescription("Scale multiplier for items (0.4 = 40%)", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ValuableScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "ValuableScale", 0.4f, new ConfigDescription("Scale multiplier for valuables (0.4 = 40%)", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			CartScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "CartScale", 1f, new ConfigDescription("Extra scale multiplier applied when a valuable is in the cart (1.0 = no change, 0.5 = half size)", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			VoiceMod = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "VoiceMod", true, new ConfigDescription("Enable voice pitch modulation when players are shrunk", (AcceptableValueBase)null, Array.Empty<object>()));
			ShrinkInShop = ((BaseUnityPlugin)this).Config.Bind<bool>("Scaling", "ShrinkInShop", false, new ConfigDescription("If true, shrinking applies in the shop level too. Default false — items stay normal size while shopping.", (AcceptableValueBase)null, Array.Empty<object>()));
			ResetToLocalConfig();
			VoiceMod.SettingChanged += delegate
			{
				ActiveVoiceMod = VoiceMod.Value;
			};
			PlayerScale.SettingChanged += delegate
			{
				OnHostScaleConfigChanged();
			};
			ItemScale.SettingChanged += delegate
			{
				OnHostScaleConfigChanged();
			};
			ValuableScale.SettingChanged += delegate
			{
				OnHostScaleConfigChanged();
			};
			CartScale.SettingChanged += delegate
			{
				OnHostScaleConfigChanged();
			};
			ShrinkInShop.SettingChanged += delegate
			{
				OnHostScaleConfigChanged();
			};
			((Component)this).gameObject.AddComponent<SettingsSyncer>();
			Harmony val2 = new Harmony("darkharasho.MiniEepo");
			val2.PatchAll();
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name != "ScalerCore")
				{
					continue;
				}
				Type[] types = assembly.GetTypes();
				foreach (Type type2 in types)
				{
					if (type2.Name == "AudioPitchHelper")
					{
						type = type2;
						break;
					}
				}
				if (type != null)
				{
					break;
				}
			}
			MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "ApplyPitch", (Type[])null, (Type[])null) : null);
			if (methodInfo != null)
			{
				val2.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(VoicePitchPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("[Voice] Patched " + type.FullName + ".ApplyPitch (Sound pitch)"));
			}
			else
			{
				Log.LogWarning((object)"[Voice] AudioPitchHelper.ApplyPitch not found");
			}
			Type type3 = AccessTools.TypeByName("PlayerVoiceChat");
			MethodInfo methodInfo2 = ((type3 != null) ? AccessTools.Method(type3, "OverridePitch", (Type[])null, (Type[])null) : null);
			if (methodInfo2 != null)
			{
				val2.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(VoicePitchPatch), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"[Voice] Patched PlayerVoiceChat.OverridePitch (Photon Voice pitch)");
			}
			else
			{
				Log.LogWarning((object)"[Voice] PlayerVoiceChat.OverridePitch not found");
			}
			Type type4 = null;
			assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly2 in assemblies)
			{
				if (assembly2.GetName().Name != "ScalerCore")
				{
					continue;
				}
				Type[] types = assembly2.GetTypes();
				foreach (Type type5 in types)
				{
					if (type5.Name == "PlayerHandler")
					{
						type4 = type5;
						break;
					}
				}
				if (type4 != null)
				{
					break;
				}
			}
			MethodInfo methodInfo3 = ((type4 != null) ? AccessTools.Method(type4, "OnUpdate", (Type[])null, (Type[])null) : null);
			if (methodInfo3 != null)
			{
				val2.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(VoicePitchPatch), "PlayerHandlerOnUpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("[Voice] Patched " + type4.FullName + ".OnUpdate (per-frame voice pitch fields)"));
			}
			else
			{
				Log.LogWarning((object)"[Voice] PlayerHandler.OnUpdate not found");
			}
			Type type6 = null;
			assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly3 in assemblies)
			{
				if (assembly3.GetName().Name != "ScalerCore")
				{
					continue;
				}
				Type[] types = assembly3.GetTypes();
				foreach (Type type7 in types)
				{
					if (type7.Name == "PlayerBonkPatch")
					{
						type6 = type7;
						break;
					}
				}
				if (type6 != null)
				{
					break;
				}
			}
			MethodInfo methodInfo4 = ((type6 != null) ? AccessTools.Method(type6, "Postfix", (Type[])null, (Type[])null) : null);
			if (methodInfo4 != null)
			{
				val2.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(BonkBlocker), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"[BonkImmune] Disabled ScalerCore's damage-bonk-expand (damage no longer un-shrinks)");
			}
			else
			{
				Log.LogWarning((object)"[BonkImmune] PlayerBonkPatch.Postfix not found — damage may un-shrink");
			}
			string[] array = new string[2] { "ReviveRPC", "Revive" };
			foreach (string text in array)
			{
				MethodInfo methodInfo5 = AccessTools.Method(typeof(PlayerAvatar), text, (Type[])null, (Type[])null);
				if (!(methodInfo5 == null))
				{
					val2.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, new HarmonyMethod(typeof(PlayerRevivePatch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					Log.LogInfo((object)("[Revive] Patched " + text));
				}
			}
			if (Chainloader.PluginInfos.ContainsKey("Jangnana.SolidAim"))
			{
				Log.LogInfo((object)"[Stabilize] SolidAim detected — skipping built-in held-gun stabilization");
			}
			else
			{
				MethodInfo methodInfo6 = AccessTools.Method(typeof(PhysGrabObject), "FixedUpdate", (Type[])null, (Type[])null);
				if (methodInfo6 != null)
				{
					val2.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, new HarmonyMethod(typeof(HeldGunStabilizationPatch), "Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			Log.LogInfo((object)"MiniEepo v1.3.0 loaded — everything is tiny now.");
		}

		internal static void ResetToLocalConfig()
		{
			ActivePlayerScale = PlayerScale.Value;
			ActiveItemScale = ItemScale.Value;
			ActiveValuableScale = ValuableScale.Value;
			ActiveCartScale = CartScale.Value;
			ActiveVoiceMod = VoiceMod.Value;
			ActiveShrinkInShop = ShrinkInShop.Value;
		}

		private static void OnHostScaleConfigChanged()
		{
			if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
			{
				ResetToLocalConfig();
				SettingsSyncer.Instance?.PushHostSettingsExternal();
			}
		}

		internal static bool IsInGameplay()
		{
			RunManager instance = RunManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			Level levelCurrent = instance.levelCurrent;
			if ((Object)(object)levelCurrent == (Object)null)
			{
				return false;
			}
			if ((Object)(object)levelCurrent == (Object)(object)instance.levelLobby || (Object)(object)levelCurrent == (Object)(object)instance.levelLobbyMenu)
			{
				return false;
			}
			if ((Object)(object)levelCurrent == (Object)(object)instance.levelMainMenu || (Object)(object)levelCurrent == (Object)(object)instance.levelSplashScreen)
			{
				return false;
			}
			if ((Object)(object)levelCurrent == (Object)(object)instance.levelTutorial || (Object)(object)levelCurrent == (Object)(object)instance.levelRecording)
			{
				return false;
			}
			if (SemiFunc.IsLevelShop(levelCurrent) && !ActiveShrinkInShop)
			{
				return false;
			}
			return true;
		}

		internal static void Shrink(GameObject go, float factor)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			ManagedObjects.Add(((Object)go).GetInstanceID());
			ScaleOptions @default = ScaleOptions.Default;
			@default.Factor = factor;
			IsApplying = true;
			try
			{
				ScaleManager.ApplyIfNotScaled(go, @default);
			}
			finally
			{
				IsApplying = false;
			}
		}
	}
	internal class SettingsSyncer : MonoBehaviour
	{
		private const string K_PLAYER = "ME_PS";

		private const string K_ITEM = "ME_IS";

		private const string K_VALUABLE = "ME_VS";

		private const string K_CART = "ME_CS";

		private const string K_SHOP = "ME_SS";

		internal static SettingsSyncer? Instance;

		private bool _wasInRoom;

		private bool _wasMaster;

		private float _pullPollDelay;

		private float _watcherTimer;

		private readonly Dictionary<int, Transform?> _visualsCache = new Dictionary<int, Transform>();

		private float _lastPushedPlayer = float.NaN;

		private float _lastPushedItem = float.NaN;

		private float _lastPushedValuable = float.NaN;

		private float _lastPushedCart = float.NaN;

		private bool? _lastPushedShop;

		private void Awake()
		{
			Instance = this;
		}

		private void Start()
		{
			Plugin.Log.LogInfo((object)"[Sync] SettingsSyncer ready (polling mode)");
		}

		internal void TriggerRescale()
		{
			((MonoBehaviour)this).StartCoroutine(RescaleAfterJoin());
		}

		private void Update()
		{
			bool inRoom = PhotonNetwork.InRoom;
			bool flag = inRoom && PhotonNetwork.IsMasterClient;
			if (inRoom && !_wasInRoom)
			{
				if (flag)
				{
					PushHostSettings();
				}
				else
				{
					PullHostSettings();
				}
			}
			else if (!inRoom && _wasInRoom)
			{
				Plugin.ResetToLocalConfig();
				Plugin.Log.LogInfo((object)"[Sync] Left room — reset to local config");
			}
			else if (inRoom && flag && !_wasMaster)
			{
				PushHostSettings();
			}
			else if (inRoom && !flag)
			{
				_pullPollDelay -= Time.unscaledDeltaTime;
				if (_pullPollDelay <= 0f)
				{
					_pullPollDelay = 1f;
					PullHostSettings();
				}
			}
			_wasInRoom = inRoom;
			_wasMaster = flag;
		}

		private void LateUpdate()
		{
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.IsInGameplay())
			{
				return;
			}
			_watcherTimer -= Time.deltaTime;
			if (_watcherTimer > 0f)
			{
				return;
			}
			_watcherTimer = 0.25f;
			float activePlayerScale = Plugin.ActivePlayerScale;
			if (activePlayerScale < 0.99f && GameDirector.instance?.PlayerList != null)
			{
				foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
				{
					if (!((Object)(object)player == (Object)null))
					{
						Transform transform = ((Component)player).transform;
						if (transform.localScale.x > 0.9f && transform.localScale.x > activePlayerScale + 0.4f)
						{
							transform.localScale = new Vector3(activePlayerScale, activePlayerScale, activePlayerScale);
						}
						int instanceID = ((Object)player).GetInstanceID();
						if (!_visualsCache.TryGetValue(instanceID, out Transform value) || (Object)(object)value == (Object)null)
						{
							value = (((Object)(object)transform.parent != (Object)null) ? transform.parent.Find("Player Visuals") : null);
							_visualsCache[instanceID] = value;
						}
						if ((Object)(object)value != (Object)null && value.localScale.x > 0.9f && value.localScale.x > activePlayerScale + 0.4f)
						{
							value.localScale = new Vector3(activePlayerScale, activePlayerScale, activePlayerScale);
						}
					}
				}
			}
			float activeItemScale = Plugin.ActiveItemScale;
			if (!(activeItemScale < 0.99f) || PhysGrabObjectPatch.DirectScaledItems.Count <= 0)
			{
				return;
			}
			List<int> list = null;
			foreach (KeyValuePair<int, Transform> directScaledItem in PhysGrabObjectPatch.DirectScaledItems)
			{
				Transform value2 = directScaledItem.Value;
				if ((Object)(object)value2 == (Object)null)
				{
					(list ?? (list = new List<int>())).Add(directScaledItem.Key);
				}
				else if (value2.localScale.x > 0.9f && value2.localScale.x > activeItemScale + 0.4f)
				{
					value2.localScale = new Vector3(activeItemScale, activeItemScale, activeItemScale);
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (int item in list)
			{
				PhysGrabObjectPatch.DirectScaledItems.Remove(item);
			}
		}

		private void PullHostSettings()
		{
			Room currentRoom = PhotonNetwork.CurrentRoom;
			Hashtable val = ((currentRoom != null) ? ((RoomInfo)currentRoom).CustomProperties : null);
			if (val == null)
			{
				return;
			}
			bool flag = false;
			if (((Dictionary<object, object>)(object)val).ContainsKey((object)"ME_PS"))
			{
				float num = (float)val[(object)"ME_PS"];
				if (Plugin.ActivePlayerScale != num)
				{
					Plugin.ActivePlayerScale = num;
					flag = true;
				}
			}
			if (((Dictionary<object, object>)(object)val).ContainsKey((object)"ME_IS"))
			{
				float num2 = (float)val[(object)"ME_IS"];
				if (Plugin.ActiveItemScale != num2)
				{
					Plugin.ActiveItemScale = num2;
					flag = true;
				}
			}
			if (((Dictionary<object, object>)(object)val).ContainsKey((object)"ME_VS"))
			{
				float num3 = (float)val[(object)"ME_VS"];
				if (Plugin.ActiveValuableScale != num3)
				{
					Plugin.ActiveValuableScale = num3;
					flag = true;
				}
			}
			if (((Dictionary<object, object>)(object)val).ContainsKey((object)"ME_CS"))
			{
				float num4 = (float)val[(object)"ME_CS"];
				if (Plugin.ActiveCartScale != num4)
				{
					Plugin.ActiveCartScale = num4;
					flag = true;
				}
			}
			if (((Dictionary<object, object>)(object)val).ContainsKey((object)"ME_SS"))
			{
				bool flag2 = (bool)val[(object)"ME_SS"];
				if (Plugin.ActiveShrinkInShop != flag2)
				{
					Plugin.ActiveShrinkInShop = flag2;
					flag = true;
				}
			}
			if (flag)
			{
				Plugin.Log.LogInfo((object)$"[Sync] Pulled host settings — player={Plugin.ActivePlayerScale} item={Plugin.ActiveItemScale} valuable={Plugin.ActiveValuableScale} cart={Plugin.ActiveCartScale} shrinkInShop={Plugin.ActiveShrinkInShop}");
			}
		}

		internal void PushHostSettingsExternal()
		{
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				PushHostSettings();
			}
		}

		private void PushHostSettings()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			if (PhotonNetwork.CurrentRoom != null)
			{
				float value = Plugin.PlayerScale.Value;
				float value2 = Plugin.ItemScale.Value;
				float value3 = Plugin.ValuableScale.Value;
				float value4 = Plugin.CartScale.Value;
				bool value5 = Plugin.ShrinkInShop.Value;
				if (value == _lastPushedPlayer && value2 == _lastPushedItem && value3 == _lastPushedValuable && value4 == _lastPushedCart && value5 == _lastPushedShop)
				{
					Plugin.ResetToLocalConfig();
					return;
				}
				_lastPushedPlayer = value;
				_lastPushedItem = value2;
				_lastPushedValuable = value3;
				_lastPushedCart = value4;
				_lastPushedShop = value5;
				Hashtable val = new Hashtable
				{
					[(object)"ME_PS"] = value,
					[(object)"ME_IS"] = value2,
					[(object)"ME_VS"] = value3,
					[(object)"ME_CS"] = value4,
					[(object)"ME_SS"] = value5
				};
				PhotonNetwork.CurrentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				Plugin.ResetToLocalConfig();
				Plugin.Log.LogInfo((object)$"[Sync] Host pushed settings — player={value} item={value2} valuable={value3} cart={value4} shrinkInShop={value5}");
			}
		}

		private IEnumerator RescaleAfterJoin()
		{
			yield return (object)new WaitForSeconds(3f);
			Plugin.Log.LogInfo((object)"[Sync] Running post-join rescale pass");
			PhysGrabObject[] array = Object.FindObjectsOfType<PhysGrabObject>();
			foreach (PhysGrabObject val in array)
			{
				ItemAttributes val2 = ((Component)val).GetComponentInParent<ItemAttributes>(true) ?? ((Component)val).GetComponentInChildren<ItemAttributes>(true);
				if ((Object)(object)val2 != (Object)null)
				{
					Plugin.Shrink(((Component)val2).gameObject, Plugin.ActiveItemScale);
				}
			}
			PlayerAvatar[] array2 = Object.FindObjectsOfType<PlayerAvatar>();
			for (int i = 0; i < array2.Length; i++)
			{
				Plugin.Shrink(((Component)array2[i]).gameObject, Plugin.ActivePlayerScale);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Start")]
	internal static class PlayerAvatarPatch
	{
		internal static readonly HashSet<int> DirectScaledPlayers = new HashSet<int>();

		private static IEnumerator ShrinkNextFrame(PlayerAvatar instance)
		{
			yield return null;
			if (!Plugin.IsInGameplay())
			{
				yield break;
			}
			if (PhotonNetwork.IsMasterClient || !PhotonNetwork.InRoom)
			{
				PhotonView component = ((Component)instance).GetComponent<PhotonView>();
				if ((Object)(object)component == (Object)null || component.IsMine)
				{
					float w = 0f;
					while (w < 5f && ((Object)(object)PhysGrabber.instance == (Object)null || (Object)(object)((Component)instance).GetComponent<PlayerVisionTarget>() == (Object)null || (Object)(object)CameraPosition.instance == (Object)null))
					{
						w += Time.deltaTime;
						yield return null;
					}
					if (!Plugin.IsInGameplay())
					{
						yield break;
					}
				}
				Plugin.Shrink(((Component)instance).gameObject, Plugin.ActivePlayerScale);
				yield break;
			}
			float waited = 0f;
			while (waited < 5f && ((Component)instance).transform.localScale.x > 0.99f)
			{
				waited += Time.deltaTime;
				yield return null;
			}
			if (!(((Component)instance).transform.localScale.x > 0.99f) || !DirectScaledPlayers.Add(((Object)((Component)instance).gameObject).GetInstanceID()))
			{
				yield break;
			}
			Transform transform = ((Component)instance).transform;
			transform.localScale *= Plugin.ActivePlayerScale;
			Transform parent = ((Component)instance).transform.parent;
			if ((Object)(object)parent != (Object)null)
			{
				Transform val = parent.Find("Player Visuals");
				if ((Object)(object)val != (Object)null && val.localScale.x > 0.99f)
				{
					val.localScale *= Plugin.ActivePlayerScale;
				}
			}
		}

		private static void Postfix(PlayerAvatar __instance)
		{
			((MonoBehaviour)__instance).StartCoroutine(ShrinkNextFrame(__instance));
		}
	}
	[HarmonyPatch(typeof(RunManager), "UpdateLevel")]
	internal static class RunManagerUpdateLevelPatch
	{
		private static void Postfix(RunManager __instance)
		{
			if (Plugin.IsInGameplay())
			{
				SettingsSyncer.Instance?.TriggerRescale();
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabObject), "Start")]
	internal static class PhysGrabObjectPatch
	{
		internal static readonly Dictionary<int, Transform> DirectScaledItems = new Dictionary<int, Transform>();

		private static void Postfix(PhysGrabObject __instance)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.IsInGameplay())
			{
				return;
			}
			GameObject val = null;
			ItemAttributes componentInParent = ((Component)__instance).GetComponentInParent<ItemAttributes>(true);
			if ((Object)(object)componentInParent != (Object)null)
			{
				val = ((Component)componentInParent).gameObject;
			}
			else if ((Object)(object)((Component)__instance).GetComponentInChildren<ItemAttributes>(true) != (Object)null)
			{
				val = ((Component)__instance).gameObject;
			}
			if ((Object)(object)val == (Object)null || (Object)(object)val.GetComponentInChildren<ItemVehicle>(true) != (Object)null)
			{
				return;
			}
			bool num = (Object)(object)val.GetComponentInChildren<ItemEquippable>(true) != (Object)null;
			bool flag = (Object)(object)val.GetComponentInChildren<ItemGun>(true) != (Object)null;
			if ((num && !flag) || (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient))
			{
				int instanceID = ((Object)val).GetInstanceID();
				if (!DirectScaledItems.ContainsKey(instanceID))
				{
					DirectScaledItems[instanceID] = val.transform;
					Transform transform = val.transform;
					transform.localScale *= Plugin.ActiveItemScale;
				}
			}
			else
			{
				Plugin.Shrink(val, Plugin.ActiveItemScale);
			}
		}
	}
	[HarmonyPatch(typeof(ValuableObject), "Start")]
	internal static class ValuableObjectPatch
	{
		private static readonly HashSet<int> _scaled = new HashSet<int>();

		private static void Postfix(ValuableObject __instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.IsInGameplay())
			{
				int instanceID = ((Object)((Component)__instance).gameObject).GetInstanceID();
				if (_scaled.Add(instanceID))
				{
					Transform transform = ((Component)__instance).transform;
					transform.localScale *= Plugin.ActiveValuableScale;
					PhysGrabObject val = ((Component)__instance).GetComponentInChildren<PhysGrabObject>(true) ?? ((Component)__instance).GetComponentInParent<PhysGrabObject>(true);
					(((Object)(object)val != (Object)null) ? ((Component)val).gameObject : ((Component)__instance).gameObject).AddComponent<ValuableCartTracker>().SetValuable(__instance);
				}
			}
		}
	}
	internal static class BonkBlocker
	{
		public static bool Prefix()
		{
			return false;
		}
	}
	internal static class VoicePitchPatch
	{
		private const BindingFlags BF = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static FieldInfo? _handlerStateField;

		private static FieldInfo? _avatarField;

		private static FieldInfo? _voiceChatField;

		private static FieldInfo? _activeField;

		private static FieldInfo? _multField;

		private static readonly object _boxedFalse = false;

		private static readonly object _boxedOne = 1f;

		public static bool Prefix()
		{
			return Plugin.ActiveVoiceMod;
		}

		public static void PlayerHandlerOnUpdatePostfix(object ctrl)
		{
			if (Plugin.ActiveVoiceMod || ctrl == null)
			{
				return;
			}
			try
			{
				if ((object)_handlerStateField == null)
				{
					_handlerStateField = ctrl.GetType().GetField("HandlerState", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				object obj = _handlerStateField?.GetValue(ctrl);
				if (obj == null)
				{
					return;
				}
				if ((object)_avatarField == null)
				{
					_avatarField = obj.GetType().GetField("PlayerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				object obj2 = _avatarField?.GetValue(obj);
				Object val = (Object)((obj2 is Object) ? obj2 : null);
				if ((val != null && val == (Object)null) || obj2 == null)
				{
					return;
				}
				if ((object)_voiceChatField == null)
				{
					_voiceChatField = obj2.GetType().GetField("voiceChat", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				object obj3 = _voiceChatField?.GetValue(obj2);
				Object val2 = (Object)((obj3 is Object) ? obj3 : null);
				if ((val2 == null || !(val2 == (Object)null)) && obj3 != null)
				{
					Type type = obj3.GetType();
					if ((object)_activeField == null)
					{
						_activeField = type.GetField("overridePitchIsActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					}
					if ((object)_multField == null)
					{
						_multField = type.GetField("overridePitchMultiplierTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					}
					_activeField?.SetValue(obj3, _boxedFalse);
					_multField?.SetValue(obj3, _boxedOne);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("[Voice] OnUpdate postfix swallowed: " + ex.GetType().Name));
			}
		}
	}
	internal static class PlayerRevivePatch
	{
		internal static void Postfix(PlayerAvatar __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			float activePlayerScale = Plugin.ActivePlayerScale;
			if (activePlayerScale < 0.99f)
			{
				((Component)__instance).transform.localScale = new Vector3(activePlayerScale, activePlayerScale, activePlayerScale);
			}
		}
	}
	[HarmonyPatch(typeof(ItemEquippable), "RPC_CompleteUnequip")]
	internal static class UnequipReshrinkPatch
	{
		private static void Postfix(ItemEquippable __instance)
		{
			if (!(Plugin.ActiveItemScale >= 0.99f))
			{
				((MonoBehaviour)__instance).StartCoroutine(Reshrink(__instance));
			}
		}

		private static IEnumerator Reshrink(ItemEquippable equip)
		{
			yield return null;
			if (!((Object)(object)equip == (Object)null))
			{
				ItemAttributes componentInParent = ((Component)equip).GetComponentInParent<ItemAttributes>(true);
				GameObject val = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).gameObject : ((Component)equip).gameObject);
				float activeItemScale = Plugin.ActiveItemScale;
				if (val.transform.localScale.x > 0.9f && val.transform.localScale.x > activeItemScale + 0.4f)
				{
					val.transform.localScale = new Vector3(activeItemScale, activeItemScale, activeItemScale);
				}
			}
		}
	}
	internal static class HeldGunStabilizationPatch
	{
		private static readonly Dictionary<int, bool> _isGun = new Dictionary<int, bool>();

		internal static void Postfix(PhysGrabObject __instance)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)__instance).GetInstanceID();
			if (!_isGun.TryGetValue(instanceID, out var value))
			{
				value = (Object)(object)((Component)__instance).GetComponent<ItemGun>() != (Object)null;
				_isGun[instanceID] = value;
			}
			if (!value)
			{
				return;
			}
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			if (!((Object)(object)val == (Object)null) && !(((Component)val).transform.localScale.x > 0.99f) && __instance.playerGrabbing.Contains(val.physGrabber))
			{
				__instance.OverrideMass(0.25f, 0.1f);
				__instance.OverrideGrabStrength(2f, 0.1f);
				__instance.OverrideTorqueStrength(5f, 0.1f);
				__instance.OverrideDrag(2f, 0.1f);
				if ((Object)(object)__instance.rb != (Object)null)
				{
					__instance.rb.angularDrag = 29f;
				}
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null && (Object)(object)__instance.rb != (Object)null)
				{
					__instance.rb.rotation = Quaternion.Slerp(__instance.rb.rotation, ((Component)main).transform.rotation, Time.fixedDeltaTime * 10f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ScaleManager), "Apply", new Type[]
	{
		typeof(GameObject),
		typeof(ScaleOptions)
	})]
	internal static class ScaleManagerApplyPatch
	{
		private static bool Prefix(GameObject target)
		{
			if (Plugin.IsApplying)
			{
				return true;
			}
			ScaleController controller = ScaleManager.GetController(target);
			int item = (((Object)(object)controller != (Object)null) ? ((Object)((Component)controller).gameObject).GetInstanceID() : ((Object)target).GetInstanceID());
			return !Plugin.ManagedObjects.Contains(item);
		}
	}
	internal class ValuableCartTracker : MonoBehaviour
	{
		private ValuableObject? _vo;

		private bool _inCart;

		private Vector3 _preCartScale;

		internal void SetValuable(ValuableObject vo)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_vo = vo;
			_preCartScale = ((Component)vo).transform.localScale;
		}

		private void OnTriggerEnter(Collider other)
		{
			//IL_004d: 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)
			if (!_inCart && !((Object)(object)_vo == (Object)null) && !((Object)(object)((Component)other).GetComponentInParent<PhysGrabInCart>() == (Object)null) && !(Plugin.ActiveCartScale >= 1f))
			{
				_inCart = true;
				((MonoBehaviour)this).StopAllCoroutines();
				((MonoBehaviour)this).StartCoroutine(ScaleTo(((Component)_vo).transform.localScale * Plugin.ActiveCartScale, 0.4f));
			}
		}

		private void OnTriggerExit(Collider other)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (_inCart && !((Object)(object)_vo == (Object)null) && !((Object)(object)((Component)other).GetComponentInParent<PhysGrabInCart>() == (Object)null))
			{
				_inCart = false;
				((MonoBehaviour)this).StopAllCoroutines();
				((MonoBehaviour)this).StartCoroutine(ScaleTo(_preCartScale, 0.3f));
			}
		}

		private IEnumerator ScaleTo(Vector3 target, float duration)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 start = ((Component)_vo).transform.localScale;
			for (float t = 0f; t < duration; t += Time.deltaTime)
			{
				((Component)_vo).transform.localScale = Vector3.Lerp(start, target, t / duration);
				yield return null;
			}
			((Component)_vo).transform.localScale = target;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "darkharasho.MiniEepo";

		public const string PLUGIN_NAME = "MiniEepo";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}