Decompiled source of OilSlideUniversalManipula v0.0.1

plugins/OilSlideUniversalManipula/OilSlideUniversalManipula.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("OilSlideUniversalManipula")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("WYSI")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1+852a9a7925aa3f8d83d238328dde887deb73a6df")]
[assembly: AssemblyProduct("OilSlideUniversalManipula")]
[assembly: AssemblyTitle("OilSlideUniversalManipula")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 OilSlideUniversalManipula
{
	public static class AudioClipLoader
	{
		public static async Task<AudioClip> LoadAudioClipAsync(string path)
		{
			string extension = Path.GetExtension(path).ToLower();
			AudioType unityAudioType = GetUnityAudioType(extension);
			AudioClip clip = null;
			try
			{
				if ((int)unityAudioType > 0)
				{
					clip = await UnitySupport.LoadWithUnityAsync(path, unityAudioType);
				}
				else
				{
					LogHelper.LogError("Unsupported audio format: 「" + extension + "」 for " + path, "H:\\C#Project\\OilSlideUniversal\\src\\AudioClipLoader.cs");
				}
				if ((Object)(object)clip == (Object)null)
				{
					return null;
				}
				return clip;
			}
			catch (Exception ex2)
			{
				Exception ex = ex2;
				LogHelper.LogError("Error while loading " + path + ": " + ex.Message + "\n" + ex.StackTrace, "H:\\C#Project\\OilSlideUniversal\\src\\AudioClipLoader.cs");
				return null;
			}
		}

		[Description("https://docs.unity3d.com/2022.3/Documentation//ScriptReference/AudioType.html")]
		private static AudioType GetUnityAudioType(string extension)
		{
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			if (1 == 0)
			{
			}
			AudioType result = (AudioType)(extension switch
			{
				".aac" => 1, 
				".aiff" => 2, 
				".aif" => 2, 
				".aifc" => 2, 
				".it" => 10, 
				".mod" => 12, 
				".mp3" => 13, 
				".mpga" => 13, 
				".mpeg" => 13, 
				".ogg" => 14, 
				".s3m" => 17, 
				".wav" => 20, 
				".xm" => 21, 
				".xma" => 22, 
				".vag" => 23, 
				_ => 0, 
			});
			if (1 == 0)
			{
			}
			return result;
		}
	}
	[Description("Patch from plonk, thanks :>")]
	[HarmonyPatch]
	public static class NoLeaderboard
	{
		[HarmonyPatch(typeof(LeaderboardController), "SubmitCyberGrindScore")]
		[HarmonyPrefix]
		public static bool OnSubmitCyberGrindScore()
		{
			return false;
		}

		[HarmonyPatch(typeof(LeaderboardController), "SubmitLevelScore")]
		[HarmonyPrefix]
		public static bool OnSubmitLevelScore()
		{
			return false;
		}
	}
	internal static class LogHelper
	{
		internal static ManualLogSource log { get; set; }

		public static void LogInfo(object data, [CallerFilePath] string filePath = "")
		{
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogInfo((object)$"[{GetClassName(filePath)}] {data}");
			}
		}

		public static void LogWarning(object data, [CallerFilePath] string filePath = "")
		{
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogWarning((object)$"[{GetClassName(filePath)}] {data}");
			}
		}

		public static void LogError(object data, [CallerFilePath] string filePath = "")
		{
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogError((object)$"[{GetClassName(filePath)}] {data}");
			}
		}

		public static void LogDebug(object data, [CallerFilePath] string filePath = "")
		{
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogDebug((object)$"[{GetClassName(filePath)}] {data}");
			}
		}

		private static string GetClassName(string path)
		{
			return Path.GetFileNameWithoutExtension(path);
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	public static class NewMovementPatch
	{
		[CompilerGenerated]
		private sealed class <AllowOSUTimer>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <AllowOSUTimer>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					allowOSU = true;
					<>2__current = (object)new WaitForSeconds(0.3f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					allowOSU = false;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <DelayedTeleport>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public NewMovement instance;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <DelayedTeleport>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					allowOSU = false;
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					Transform transform = ((Component)instance).transform;
					transform.position += new Vector3(0f, -5f, 0f);
					instance.StopSlide();
					return false;
				}
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static bool allowOSU;

		[IteratorStateMachine(typeof(<DelayedTeleport>d__1))]
		private static IEnumerator DelayedTeleport(NewMovement instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DelayedTeleport>d__1(0)
			{
				instance = instance
			};
		}

		[HarmonyPrefix]
		[HarmonyPatch("StartSlide")]
		public static void StartSlidePrefix(NewMovement __instance)
		{
			if (__instance.onGasoline && allowOSU)
			{
				((MonoBehaviour)__instance).StartCoroutine(DelayedTeleport(__instance));
			}
		}

		[HarmonyTranspiler]
		[HarmonyPatch("Update")]
		public static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0044: 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_006d: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			FieldInfo fieldInfo = AccessTools.Field(typeof(NewMovement), "fallSpeed");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(NewMovement), "slamStorage");
			MethodInfo methodInfo = AccessTools.Method(typeof(NewMovementPatch), "OnGroundLand", (Type[])null, (Type[])null);
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[5]
			{
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)0f, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo2, (string)null)
			}).Insert((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)methodInfo)
			}).InstructionEnumeration();
		}

		public static void OnGroundLand(NewMovement instance)
		{
			if (instance.slamStorage && instance.onGasoline)
			{
				LogHelper.LogInfo("Successed land on oil when slam storage", "H:\\C#Project\\OilSlideUniversal\\src\\NewMovementPatch.cs");
				TryPlayHitsound();
				((MonoBehaviour)instance).StartCoroutine(AllowOSUTimer());
			}
		}

		[IteratorStateMachine(typeof(<AllowOSUTimer>d__5))]
		private static IEnumerator AllowOSUTimer()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <AllowOSUTimer>d__5(0);
		}

		private static void TryPlayHitsound()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)MonoSingleton<CameraController>.Instance).transform;
			if (transform.forward.y > 0.9f)
			{
				LogHelper.LogInfo("ITS LOOKING AT FGSKY", "H:\\C#Project\\OilSlideUniversal\\src\\NewMovementPatch.cs");
				SoloAudioSource.Instance.Play();
			}
		}
	}
	public static class PathHelper
	{
		public static string GetCurrentPluginPath(params string[] paths)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			return CleanPath((paths == null || paths.Length == 0) ? directoryName : Path.Combine(directoryName, Path.Combine(paths)));
		}

		public static string GetGamePath(string filePath)
		{
			return CleanPath(Path.Combine(Paths.GameRootPath, filePath));
		}

		[Description("Reference : (因win程序员想偷懒! 竟在剪切板插入隐藏字符) https://www.bilibili.com/video/BV1ebLczjEWZ (Accessed in 24/4/2025)")]
		public static string CleanPath(string path)
		{
			if (string.IsNullOrEmpty(path))
			{
				return path;
			}
			char[] trimChars = new char[5] { '\u202a', '\u202b', '\u202c', '\u202d', '\u202e' };
			string text = path.TrimStart(trimChars);
			if (!path.Equals(text))
			{
				LogHelper.LogInfo("[CleanPath] Path cleaned: Original='" + path + "', Cleaned='" + text + "'", "H:\\C#Project\\OilSlideUniversal\\src\\PathHelper.cs");
			}
			return text;
		}

		public static string GetFile(string filePath, string fileName)
		{
			string text = Path.Combine(filePath, fileName);
			if (File.Exists(text))
			{
				return text;
			}
			return null;
		}

		public static bool TryGetExtension(string filePath, out string foundExtension, params string[] extensions)
		{
			foundExtension = null;
			if (string.IsNullOrWhiteSpace(filePath))
			{
				return false;
			}
			string[] source = (from e in extensions.SelectMany((string e) => e.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries))
				select e.Trim()).ToArray();
			string text = filePath.Trim();
			while (!string.IsNullOrEmpty(text))
			{
				string ext = Path.GetExtension(text)?.Trim();
				if (string.IsNullOrEmpty(ext))
				{
					break;
				}
				if (source.Any((string e) => e.Equals(ext, StringComparison.OrdinalIgnoreCase)))
				{
					foundExtension = ext;
					return true;
				}
				text = Path.Combine(Path.GetDirectoryName(text) ?? "", Path.GetFileNameWithoutExtension(text));
			}
			return false;
		}
	}
	[BepInPlugin("greycsont.ultrakill.OilSlideUniversal", "OilSlideUniversal", "0.0.1")]
	[BepInProcess("ULTRAKILL.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static AudioClip clip;

		private Harmony harmony;

		private void Awake()
		{
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
			LogHelper.log = ((BaseUnityPlugin)this).Logger;
			LoadMainModule();
			LoadOptionalModule();
			PatchHarmony();
			LogHelper.LogInfo("Plugin greycsont.ultrakill.OilSlideUniversal is loaded!", "H:\\C#Project\\OilSlideUniversal\\src\\Plugin.cs");
		}

		private async Task LoadMainModule()
		{
			string[] files = Directory.GetFiles(PathHelper.GetCurrentPluginPath(), "soft-hitnormal.*");
			if (files.Length != 0)
			{
				clip = await AudioClipLoader.LoadAudioClipAsync(files[0]);
			}
		}

		private void LoadOptionalModule()
		{
		}

		private void PatchHarmony()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("greycsont.ultrakill.OilSlideUniversal.harmony");
			harmony.PatchAll();
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "greycsont.ultrakill.OilSlideUniversal";

		public const string PLUGIN_NAME = "OilSlideUniversal";

		public const string PLUGIN_VERSION = "0.0.1";
	}
	public sealed class SoloAudioSource : MonoBehaviour
	{
		private AudioSource _audioSource;

		private static SoloAudioSource _instance;

		public static SoloAudioSource Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					GameObject val = new GameObject("SoloAudioSource");
					Object.DontDestroyOnLoad((Object)(object)val);
					_instance = val.AddComponent<SoloAudioSource>();
				}
				return _instance;
			}
		}

		public void Play()
		{
			Play(Plugin.clip);
		}

		public void Play(AudioClip clip)
		{
			if ((Object)(object)_audioSource == (Object)null)
			{
				_audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_audioSource.Stop();
			AudioSourceExtensions.SetSpatialBlend(_audioSource, 0f);
			_audioSource.volume = 1f;
			AudioSourceExtensions.PlayOneShot(_audioSource, clip, true);
		}
	}
	public static class UnitySupport
	{
		public static async Task<AudioClip> LoadWithUnityAsync(string path, AudioType audioType)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			string url = new Uri(path).AbsoluteUri;
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, audioType);
			try
			{
				UnityWebRequestAsyncOperation operation = www.SendWebRequest();
				while (!((AsyncOperation)operation).isDone)
				{
					await Task.Delay(10);
				}
				if ((int)www.result != 1)
				{
					LogHelper.LogError("UnityRequest Failed to load audio: " + www.error, "H:\\C#Project\\OilSlideUniversal\\src\\UnitySupport.cs");
					return null;
				}
				return DownloadHandlerAudioClip.GetContent(www);
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}