Decompiled source of MakeMeRagdoll v1.1.2

Ramune.MakeMeRagdoll.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Ramune.MakeMeRagdoll.Monos;
using RamuneLib;
using RamuneLib.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Ramune.MakeMeRagdoll")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ramune.MakeMeRagdoll")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("643be75b-e2f3-4dcf-9272-2d5d7f27ef41")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Ramune.MakeMeRagdoll
{
	[ContentWarningPlugin("com.ramune.MakeMeRagdoll", "1.1.2", true)]
	[BepInPlugin("com.ramune.MakeMeRagdoll", "Make Me Ragdoll", "1.1.2")]
	[BepInProcess("Content Warning.exe")]
	public class MakeMeRagdoll : BaseUnityPlugin
	{
		public static MakeMeRagdoll Instance;

		public static readonly Harmony harmony = new Harmony("com.ramune.MakeMeRagdoll");

		public const string GUID = "com.ramune.MakeMeRagdoll";

		public const string Name = "Make Me Ragdoll";

		public const string Version = "1.1.2";

		public static ManualLogSource logger => ((BaseUnityPlugin)Instance).Logger;

		public static ConfigEntry<bool> UseToggleEntry { get; set; }

		public static ConfigEntry<KeyCode> TriggerKeybindEntry { get; set; }

		public static ConfigEntry<float> DurationEntry { get; set; }

		public void Awake()
		{
			UseToggleEntry = ((BaseUnityPlugin)this).Config.Bind<bool>("MakeMeRagdoll", "Hold-to-ragdoll mode", true, "Enabling this makes the ragdolling to stay active continously while you hold your keybind");
			TriggerKeybindEntry = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("MakeMeRagdoll", "Activate ragdoll keybind", (KeyCode)96, "Press this key to make yourself ragdoll");
			DurationEntry = ((BaseUnityPlugin)this).Config.Bind<float>("MakeMeRagdoll", "Duration of ragdoll", 2f, "The amount of time to ragdoll for");
			Initializer.Initialize(harmony, ((BaseUnityPlugin)this).Logger, "Make Me Ragdoll", "1.1.2");
		}
	}
}
namespace Ramune.MakeMeRagdoll.Patches
{
	[HarmonyPatch(typeof(Player))]
	public static class PlayerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start(Player __instance)
		{
			if (__instance.IsLocal && !((Object)(object)((Component)__instance).gameObject.GetComponent<Ragdoller>() != (Object)null))
			{
				Ragdoller ragdoller = ((Component)__instance).gameObject.AddComponent<Ragdoller>();
				ragdoller.player = __instance;
			}
		}
	}
}
namespace Ramune.MakeMeRagdoll.Monos
{
	public class Ragdoller : MonoBehaviour
	{
		public bool KeyHeld;

		public Player player { get; set; }

		public void Update()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (MakeMeRagdoll.UseToggleEntry.Value)
			{
				if (GlobalInputHandler.GetKeyDown(MakeMeRagdoll.TriggerKeybindEntry.Value))
				{
					KeyHeld = true;
				}
				if (GlobalInputHandler.GetKeyUp(MakeMeRagdoll.TriggerKeybindEntry.Value))
				{
					KeyHeld = false;
				}
				if (KeyHeld && player.data.fallTime < 0.25f)
				{
					player.refs.ragdoll.CallFall(1f);
				}
			}
			else if (GlobalInputHandler.GetKeyDown(MakeMeRagdoll.TriggerKeybindEntry.Value))
			{
				player.refs.ragdoll.CallFall(MakeMeRagdoll.DurationEntry.Value);
			}
		}
	}
}
namespace RamuneLib
{
	public static class Initializer
	{
		public static void Initialize(Harmony harmony, ManualLogSource logger, string name, string version, bool patchAll = true)
		{
			Variables.harmony = harmony;
			Variables.logger = logger;
			string text = "======================= " + name + " (" + version + ") =======================";
			string message = new string('=', text.Length);
			LoggerUtils.LogInfo(text);
			if (patchAll)
			{
				LoggerUtils.LogInfo(">> Loading harmony patches for '" + name + " " + version + "'");
				harmony.PatchAll();
				LoggerUtils.LogInfo(">> Finished loading harmony patches for '" + name + " " + version + "'..");
			}
			LoggerUtils.LogInfo(message);
		}
	}
	public static class Variables
	{
		public static class Paths
		{
			public static string PluginFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

			public static string AssetsFolder => Path.Combine(PluginFolder, "Assets");

			public static string ConfigFolder()
			{
				string text = Path.Combine(Paths.ConfigPath, Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location));
				if (!Directory.Exists(text))
				{
					LoggerUtils.LogWarning("Config folder not found at: '" + text + "'");
					Directory.CreateDirectory(text);
					LoggerUtils.LogInfo("Generated a config folder at: '" + text + "'");
				}
				return text;
			}
		}

		public static Harmony harmony { get; set; }

		public static ManualLogSource logger { get; set; }
	}
}
namespace RamuneLib.Utils
{
	public static class LoggerUtils
	{
		public static bool Debug;

		public static void LogInfo(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogInfo((object)message);
			}
		}

		public static void LogDebug(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogDebug((object)message);
			}
		}

		public static void LogWarning(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogWarning((object)message);
			}
		}

		public static void LogError(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogError((object)message);
			}
		}

		public static void LogFatal(string message)
		{
			ManualLogSource logger = Variables.logger;
			if (logger != null)
			{
				logger.LogFatal((object)message);
			}
		}
	}
}