Decompiled source of AssistModIThink v0.5.0

SlamStorageAssist.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SlamStorageAssist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SlamStorageAssist")]
[assembly: AssemblyTitle("SlamStorageAssist")]
[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 SlamStorageAssist
{
	[BepInPlugin("mastoor144.slamstorageassist", "Slam Storage Assist", "0.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private ConfigBuilder config;

		private Harmony harmony;

		[Configgable("General", "Enable Assist", 0, "Enables or disables SSA's assisted landing jump. The game's native movement mechanics remain available.")]
		private static ConfigToggle enableAssist = new ConfigToggle(true);

		[Configgable("Practice", "Show Feedback", 0, "Writes an informational message to the BepInEx log when SSA attempts an assisted landing jump. This does not display an on-screen message.")]
		private static ConfigToggle showFeedback = new ConfigToggle(true);

		[Configgable("Practice", "Landing Window", 1, "Time in seconds that a jump press remains valid after being captured during slam storage. Range: 0.00 to 0.25 seconds. Higher values are more forgiving; 0.00 effectively disables buffering.")]
		private static FloatSlider landingWindow = new FloatSlider(0.1f, 0f, 0.25f);

		private static ManualLogSource log;

		private static FieldInfo slamStorageField;

		private static MethodInfo jumpMethod;

		private static bool jumpQueued;

		private static float jumpExpiresAt;

		private const string DoorPath = "FirstRoom/Room/FinalDoor/DoorRight";

		private const string BoatPath = "Surface/Nonstuff/Boat/CrackCollider";

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			log = ((BaseUnityPlugin)this).Logger;
			config = new ConfigBuilder("mastoor144.slamstorageassist", "Slam Storage Assist");
			config.BuildAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
			Type type = AccessTools.TypeByName("NewMovement");
			if (type == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"SSA could not find NewMovement. Gameplay patches were not installed.");
				DiagnoseLoadedScenes();
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "JumpPerformed", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(type, "LandingImpact", (Type[])null, (Type[])null);
			slamStorageField = AccessTools.Field(type, "slamStorage");
			jumpMethod = AccessTools.Method(type, "Jump", Type.EmptyTypes, (Type[])null);
			if (methodInfo == null || methodInfo2 == null || slamStorageField == null || jumpMethod == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"SSA could not find all required movement members. Gameplay patches were not installed.");
				DiagnoseLoadedScenes();
				return;
			}
			harmony = new Harmony("mastoor144.slamstorageassist");
			harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Plugin).GetMethod("OnJumpPressed", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin).GetMethod("OnLanding", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SSA 0.5.0 loaded. Event-based movement patches installed; scene diagnostics enabled.");
			DiagnoseLoadedScenes();
		}

		private static void OnJumpPressed(object __instance)
		{
			if (!((ConfigValueElement<bool>)(object)enableAssist).Value)
			{
				return;
			}
			float value = ((ConfigValueElement<float>)(object)landingWindow).Value;
			if (value <= 0f)
			{
				return;
			}
			try
			{
				object value2 = slamStorageField.GetValue(__instance);
				if (value2 is bool && (bool)value2)
				{
					jumpQueued = true;
					jumpExpiresAt = Time.time + value;
				}
			}
			catch (Exception ex)
			{
				log.LogError((object)("SSA could not capture jump input: " + ex.Message));
				jumpQueued = false;
			}
		}

		private static void OnLanding(object __instance)
		{
			if (!jumpQueued)
			{
				return;
			}
			bool flag = Time.time <= jumpExpiresAt;
			jumpQueued = false;
			if (!((ConfigValueElement<bool>)(object)enableAssist).Value || !flag)
			{
				return;
			}
			try
			{
				jumpMethod.Invoke(__instance, null);
				if (((ConfigValueElement<bool>)(object)showFeedback).Value)
				{
					log.LogInfo((object)"SSA attempted an assisted landing jump.");
				}
			}
			catch (Exception ex)
			{
				log.LogError((object)("SSA landing attempt failed: " + ex.Message));
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			jumpQueued = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("SSA scene diagnostic: loaded scene '" + ((Scene)(ref scene)).name + "'."));
			DiagnoseScene(scene);
		}

		private void DiagnoseLoadedScenes()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < SceneManager.sceneCount; i++)
			{
				Scene sceneAt = SceneManager.GetSceneAt(i);
				if (((Scene)(ref sceneAt)).IsValid() && ((Scene)(ref sceneAt)).isLoaded)
				{
					DiagnoseScene(sceneAt);
				}
			}
		}

		private static void DiagnoseScene(Scene scene)
		{
			GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
			GameObject[] array = rootGameObjects;
			foreach (GameObject val in array)
			{
				InspectHierarchy(val.transform, ((Scene)(ref scene)).name);
			}
		}

		private static void InspectHierarchy(Transform current, string sceneName)
		{
			string hierarchyPath = GetHierarchyPath(current);
			bool flag = hierarchyPath.EndsWith("FirstRoom/Room/FinalDoor/DoorRight", StringComparison.Ordinal);
			bool flag2 = hierarchyPath.EndsWith("Surface/Nonstuff/Boat/CrackCollider", StringComparison.Ordinal);
			if (flag || flag2)
			{
				InspectCollider(current, sceneName, hierarchyPath);
			}
			for (int i = 0; i < current.childCount; i++)
			{
				InspectHierarchy(current.GetChild(i), sceneName);
			}
		}

		private static string GetHierarchyPath(Transform item)
		{
			string text = ((Object)item).name;
			Transform parent = item.parent;
			while ((Object)(object)parent != (Object)null)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private unsafe static void InspectCollider(Transform target, string sceneName, string path)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			BoxCollider component = ((Component)target).GetComponent<BoxCollider>();
			log.LogInfo((object)("SSA collider diagnostic: scene='" + sceneName + "', path='" + path + "'."));
			if ((Object)(object)component == (Object)null)
			{
				log.LogWarning((object)"SSA found the target object, but it has no BoxCollider on the same GameObject.");
				return;
			}
			Vector3 size = component.size;
			bool flag = size.x < 0f || size.y < 0f || size.z < 0f;
			if (flag)
			{
				component.size = new Vector3(Mathf.Abs(size.x), Mathf.Abs(size.y), Mathf.Abs(size.z));
				log.LogWarning((object)("SSA corrected negative BoxCollider.size on '" + path + "'. New size: " + ((object)component.size/*cast due to .constrained prefix*/).ToString() + "."));
			}
			bool flag2 = false;
			Transform val = target;
			while ((Object)(object)val != (Object)null)
			{
				Vector3 localScale = val.localScale;
				if (localScale.x < 0f || localScale.y < 0f || localScale.z < 0f)
				{
					flag2 = true;
					ManualLogSource obj = log;
					string[] obj2 = new string[5]
					{
						"SSA found negative transform scale on '",
						GetHierarchyPath(val),
						"': ",
						null,
						null
					};
					Vector3 val2 = localScale;
					obj2[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
					obj2[4] = ".";
					obj.LogWarning((object)string.Concat(obj2));
				}
				val = val.parent;
			}
			log.LogInfo((object)("SSA collider state: size=" + ((object)component.size/*cast due to .constrained prefix*/).ToString() + ", localScale=" + ((object)target.localScale/*cast due to .constrained prefix*/).ToString() + ", lossyScale=" + ((object)target.lossyScale/*cast due to .constrained prefix*/).ToString() + ", enabled=" + ((Collider)component).enabled + "."));
			if (flag2)
			{
				log.LogWarning((object)"SSA did not modify transform scales. Changing them automatically could alter the level's geometry.");
			}
			else if (!flag)
			{
				log.LogInfo((object)"SSA found no negative collider size or negative ancestor local scale on this object.");
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
				harmony = null;
			}
			jumpQueued = false;
		}
	}
}