Decompiled source of Personal Space v1.0.2

Mods/WoodStudios.PersonalSpace.dll

Decompiled 23 minutes 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 Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using PersonalSpace;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Personal Space", "1.0.2", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WoodStudios.PersonalSpace")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WoodStudios.PersonalSpace")]
[assembly: AssemblyTitle("WoodStudios.PersonalSpace")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 PersonalSpace
{
	public sealed class Core : MelonMod
	{
		internal static Instance Log;

		private static MelonPreferences_Entry<float> _range;

		private static MelonPreferences_Entry<float> _room;

		private static MelonPreferences_Entry<bool> _on;

		private static float _setRange = -1f;

		private static float _nextCheck;

		private static int _tuned;

		private static float _playingSince = -1f;

		public override void OnInitializeMelon()
		{
			Log = ((MelonBase)this).LoggerInstance;
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("PersonalSpace", "Personal Space");
			_on = obj.CreateEntry<bool>("Enabled", true, "Enabled", "People step around each other.", false, false, (ValueValidator)null, (string)null);
			_range = obj.CreateEntry<float>("Range", 40f, "Range (m)", "How far from a player people avoid each other (the game's own is shorter).", false, false, (ValueValidator)null, (string)null);
			_room = obj.CreateEntry<float>("Room", 0.32f, "Room (m)", "How much room each person keeps around them when passing someone.", false, false, (ValueValidator)null, (string)null);
			Log.Msg("Personal Space loaded: people step around each other instead of through each other.");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			_playingSince = -1f;
		}

		public override void OnUpdate()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Invalid comparison between Unknown and I4
			if (!_on.Value || Time.unscaledTime < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.unscaledTime + 0.5f;
			Vector3 position;
			try
			{
				Player local = Player.Local;
				if ((Object)(object)local == (Object)null)
				{
					_playingSince = -1f;
					return;
				}
				position = ((Component)local).transform.position;
			}
			catch
			{
				return;
			}
			if (_playingSince < 0f)
			{
				_playingSince = Time.unscaledTime;
			}
			else
			{
				if (Time.unscaledTime - _playingSince < 15f)
				{
					return;
				}
				float num = Mathf.Clamp(_range.Value, 5f, 150f);
				List<NPC> val = null;
				try
				{
					val = NPCManager.NPCRegistry;
				}
				catch
				{
				}
				if (val == null)
				{
					return;
				}
				float num2 = Mathf.Clamp(_room.Value, 0.15f, 0.6f);
				for (int i = 0; i < val.Count; i++)
				{
					try
					{
						NPC val2 = val[i];
						if ((Object)(object)val2 == (Object)null || !((Component)val2).gameObject.activeInHierarchy)
						{
							continue;
						}
						Vector3 val3 = ((Component)val2).transform.position - position;
						if (((Vector3)(ref val3)).sqrMagnitude > num * num)
						{
							continue;
						}
						NPCMovement movement = val2.Movement;
						NavMeshAgent val4 = (((Object)(object)movement != (Object)null) ? movement._agent : null);
						if ((Object)(object)val4 == (Object)null || !((Behaviour)val4).isActiveAndEnabled)
						{
							continue;
						}
						ObstacleAvoidanceType obstacleAvoidanceType = val4.obstacleAvoidanceType;
						if ((int)obstacleAvoidanceType != 0)
						{
							if ((int)obstacleAvoidanceType != 3)
							{
								val4.obstacleAvoidanceType = (ObstacleAvoidanceType)3;
							}
							if (val4.radius < num2)
							{
								val4.radius = num2;
							}
							if (++_tuned == 1)
							{
								Log.Msg("People near you now step around each other.");
							}
						}
					}
					catch
					{
					}
				}
			}
		}
	}
}