Decompiled source of SpeedMOB v0.1.1

SpeedMOB.dll

Decompiled 21 hours 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SpeedMOB")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Link MOB Room")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpeedMOB")]
[assembly: AssemblyTitle("SpeedMOB")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
	[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 SpeedMOB
{
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}
	}
	[HarmonyPatch]
	public class Patches
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerSitAtSavePointCondition), "get_isValid")]
		public static bool PatchIsSitAtSavePoint(ref PlayerSitAtSavePointCondition __instance, ref bool __result)
		{
			if (SpeedMOB.Instance.isSitAtSavePoint.Value && ((Object)__instance).name.Contains("[Condition]"))
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Player), "RestoreEverything")]
		public static bool PatchRestoreEverything(ref Player __instance)
		{
			if (SpeedMOB.Instance.isNoRecoveryHealth.Value && ((Health)__instance.health).currentValue > 0f)
			{
				return false;
			}
			return true;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("SpeedMOB", "SpeedMOB", "1.0.0")]
	public class SpeedMOB : BaseUnityPlugin
	{
		public ConfigEntry<bool> isSitAtSavePoint;

		public ConfigEntry<bool> isNoRecoveryHealth;

		public ConfigEntry<bool> gotoChallengeHub;

		private Harmony harmony;

		private static readonly Dictionary<string, (string sceneName, Vector3 position)> teleportPoints = new Dictionary<string, (string, Vector3)>
		{
			{
				"A2_S5_BossHorseman_Final",
				("A3_S5_BossGouMang_Final", new Vector3(-4430f, -2288f, 0f))
			},
			{
				"A3_S5_BossGouMang_Final",
				("A4_S5_DaoTrapHouse_Final", new Vector3(1833f, -3744f, 0f))
			},
			{
				"A4_S5_DaoTrapHouse_Final",
				("A5_S5_JieChuanHall", new Vector3(-4784f, -2288f, 0f))
			},
			{
				"A5_S5_JieChuanHall",
				("A7_S5_Boss_ButterFly", new Vector3(-2640f, -1104f, 0f))
			},
			{
				"A7_S5_Boss_ButterFly",
				("A9_S5_風氏", new Vector3(-2370f, -1264f, 0f))
			},
			{
				"A9_S5_風氏",
				("A10_S5_Boss_Jee", new Vector3(-48f, -64f, 0f))
			},
			{
				"A10_S5_Boss_Jee",
				("A11_S0_Boss_YiGung", new Vector3(-2686f, -1104f, 0f))
			},
			{
				"A11_S0_Boss_YiGung",
				("VR_Challenge_Hub", new Vector3(-4280f, -2192f, 0f))
			}
		};

		public static SpeedMOB Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			harmony = Harmony.CreateAndPatchAll(typeof(SpeedMOB).Assembly, (string)null);
			isSitAtSavePoint = ((BaseUnityPlugin)this).Config.Bind<bool>("", "NotAtSavePointUseJade", true, (ConfigDescription)null);
			isNoRecoveryHealth = ((BaseUnityPlugin)this).Config.Bind<bool>("", "NoRecoveryHealth", false, (ConfigDescription)null);
			gotoChallengeHub = ((BaseUnityPlugin)this).Config.Bind<bool>("", "gotoChallengeHub", false, (ConfigDescription)null);
			Log.Info("Plugin SpeedMOB is loaded!");
			gotoChallengeHub.SettingChanged += delegate
			{
				if (gotoChallengeHub.Value)
				{
					GotoChallengeHub();
					gotoChallengeHub.Value = false;
				}
			};
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			((MonoBehaviour)this).StartCoroutine(HandleSceneLoadedWithDelay());
		}

		private void GotoChallengeHub()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			TeleportPointData val = CreateTeleportPointData("VR_Challenge_Hub", new Vector3(-4280f, -2192f, 0f));
			GameCore instance = SingletonBehaviour<GameCore>.Instance;
			if (instance != null)
			{
				instance.TeleportToSavePoint(val, false, 0f);
			}
		}

		private IEnumerator HandleSceneLoadedWithDelay()
		{
			yield return (object)new WaitForSeconds(2f);
			TeleportToSavePointAction[] array = Object.FindObjectsOfType<TeleportToSavePointAction>();
			foreach (TeleportToSavePointAction val in array)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).transform == (Object)null || (Object)(object)((Component)val).transform.parent == (Object)null)
				{
					continue;
				}
				DelayActionModifier component = ((Component)((Component)val).transform.parent).GetComponent<DelayActionModifier>();
				if (!((Object)(object)component == (Object)null))
				{
					component.delayTime = 0f;
					Dictionary<string, (string sceneName, Vector3 position)> dictionary = teleportPoints;
					Scene activeScene = SceneManager.GetActiveScene();
					if (dictionary.TryGetValue(((Scene)(ref activeScene)).name, out (string, Vector3) value))
					{
						val.teleportPointData.sceneName = value.Item1;
						val.teleportPointData.TeleportPosition = value.Item2;
					}
				}
			}
		}

		private TeleportPointData CreateTeleportPointData(string sceneName, Vector3 position)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			TeleportPointData obj = ScriptableObject.CreateInstance<TeleportPointData>();
			obj.sceneName = sceneName;
			obj.TeleportPosition = position;
			return obj;
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			harmony.UnpatchSelf();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SpeedMOB";

		public const string PLUGIN_NAME = "SpeedMOB";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}