Decompiled source of React v0.1.0

plugins/com.github.Skubaniec_DEV.React.dll

Decompiled a week 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using React.Utils;
using TMPro;
using UnityEngine;

[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("com.github.Skubaniec_DEV.React")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.Skubaniec_DEV.React")]
[assembly: AssemblyTitle("React")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace React
{
	[BepInPlugin("com.github.Skubaniec_DEV.React", "React", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("com.github.Skubaniec_DEV.React");

		public const string Id = "com.github.Skubaniec_DEV.React";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "React";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			ZConfig.AllConfigs(((BaseUnityPlugin)this).Config);
		}
	}
}
namespace React.Utils
{
	public class ZConfig
	{
		public static ConfigEntry<int> ReactChance;

		public static ConfigEntry<float> ReactTimeBase;

		public static ConfigEntry<float> MaxExtraReactTime;

		public static ConfigEntry<float> HealthPunishment;

		public static ConfigEntry<float> SleepPunishment;

		public static ConfigEntry<float> HungerPunishment;

		public static ConfigEntry<float> PoisonPunishment;

		public static ConfigEntry<bool> SniperMode;

		public static ConfigEntry<float> ExtraStaminaReward;

		public static ConfigEntry<float> HealReward;

		public static void AllConfigs(ConfigFile cfg)
		{
			ReactChance = cfg.Bind<int>("General", "React Chance", 250, "A 1 in X chance EVERY SECOND of getting the REACT event to happen.");
			ReactTimeBase = cfg.Bind<float>("Reaction Time", "Reaction Time Base", 1f, "The minimum time there is to click the displayed button.");
			MaxExtraReactTime = cfg.Bind<float>("Reaction Time", "Extra Maximum Reaction Time", 0.5f, "A random number between 0 and X that will be added to the base reaction time. (0.01 is the least you can put.)");
			HealthPunishment = cfg.Bind<float>("Punishments", "Health damage punishment", 15f, "The amount of health u lose as a possible punishment for not pressing the required key in time.");
			SleepPunishment = cfg.Bind<float>("Punishments", "Sleep damage punishment", 110f, "The amount of sleep/drowsy effect u gain as a possible punishment for not pressing the required key in time.");
			HungerPunishment = cfg.Bind<float>("Punishments", "Hunger damage punishment", 20f, "The amount of hunger effect u gain as a possible punishment for not pressing the required key in time.");
			PoisonPunishment = cfg.Bind<float>("Punishments", "Poison damage punishment", 70f, "The amount of poison effect u gain as a possible punishment for not pressing the required key in time.");
			ExtraStaminaReward = cfg.Bind<float>("Rewards", "Extra Stamina Reward", 25f, "The amount of extra stamina u gain for pressing the required key in time.");
			HealReward = cfg.Bind<float>("Rewards", "Heal Injury Reward", 10f, "The amount of Injury effect that will be healed for pressing the required key in time.");
			SniperMode = cfg.Bind<bool>("Extra", "Sniper Mode", false, "Pressing any key other than the one you're required to press results in a punishment.");
		}
	}
}
namespace React.Patches
{
	[HarmonyPatch]
	internal class PlayerPatch
	{
		public static readonly KeyCode[] LetterKeys;

		private static GameObject reactText;

		private static KeyCode requestedKey;

		private static bool HasStarted;

		private static bool MidReact;

		private static float timer;

		private static float interval;

		private static float ReactInterval;

		public static void ClearText()
		{
			if ((Object)(object)reactText != (Object)null)
			{
				Object.Destroy((Object)(object)reactText);
				reactText = null;
			}
		}

		[HarmonyPatch(typeof(GUIManager), "SetHeroTitle")]
		[HarmonyPostfix]
		private static void Shore_Start()
		{
			Plugin.Log.LogInfo((object)"Start the REACT protocol.");
			HasStarted = true;
		}

		[HarmonyPatch(typeof(RunManager), "EndGame")]
		[HarmonyPostfix]
		private static void Game_Stop()
		{
			Plugin.Log.LogInfo((object)"Terminate the REACT protocol.");
			HasStarted = false;
		}

		[HarmonyPatch(typeof(Character), "Update")]
		[HarmonyPostfix]
		private static void React_Protocol(ref Character __instance)
		{
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)(object)Character.localCharacter)
			{
				return;
			}
			timer += Time.deltaTime;
			if (!MidReact)
			{
				if (!(timer >= interval) || !HasStarted || Character.localCharacter.IsGhost)
				{
					return;
				}
				timer = 0f;
				int num = Random.Range(1, ZConfig.ReactChance.Value + 1);
				Plugin.Log.LogInfo((object)("Rolled: " + num));
				if (num == 1)
				{
					if ((Object)(object)reactText != (Object)null)
					{
						ClearText();
						return;
					}
					int num2 = Random.Range(0, LetterKeys.Length);
					requestedKey = LetterKeys[num2];
					GameObject val = GameObject.Find("GAME/GUIManager/Canvas_HUD");
					reactText = new GameObject("React Text Object");
					reactText.transform.SetParent(val.transform, false);
					reactText.AddComponent<TextMeshProUGUI>();
					TextMeshProUGUI component = reactText.GetComponent<TextMeshProUGUI>();
					((TMP_Text)component).text = "<b>PRESS <color=red>\"" + ((object)(KeyCode)(ref requestedKey)).ToString() + "\"</color> QUICK</b>";
					((TMP_Text)component).textWrappingMode = (TextWrappingModes)0;
					((TMP_Text)component).overflowMode = (TextOverflowModes)0;
					((TMP_Text)component).richText = true;
					((TMP_Text)component).fontMaterial.EnableKeyword("OUTLINE_ON");
					((TMP_Text)component).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
					((TMP_Text)component).outlineWidth = 0.37f;
					((TMP_Text)component).alignment = (TextAlignmentOptions)514;
					Plugin.Log.LogInfo((object)"Pre Rect");
					((TMP_Text)component).UpdateMeshPadding();
					Plugin.Log.LogInfo((object)"Added The Text");
					MidReact = true;
					ReactInterval = ZConfig.ReactTimeBase.Value + Random.Range(0f, ZConfig.MaxExtraReactTime.Value * 100f + 1f) / 100f;
					Plugin.Log.LogInfo((object)("ReactInterval is " + ReactInterval));
				}
				return;
			}
			if (timer >= ReactInterval)
			{
				MidReact = false;
				ReactInterval = 0f;
				ClearText();
				int num3 = Random.Range(1, 5);
				if (num3 == 1)
				{
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)0, ZConfig.HealthPunishment.Value / 100f, false, true);
				}
				if (num3 == 2)
				{
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)6, ZConfig.SleepPunishment.Value / 100f, false, true);
				}
				if (num3 == 3)
				{
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)1, ZConfig.HungerPunishment.Value / 100f, false, true);
				}
				if (num3 == 4)
				{
					Character.localCharacter.refs.afflictions.AddStatus((STATUSTYPE)3, ZConfig.PoisonPunishment.Value / 100f, false, true);
				}
				return;
			}
			_ = requestedKey;
			if (ZConfig.SniperMode.Value)
			{
				bool flag = false;
				KeyCode[] letterKeys = LetterKeys;
				foreach (KeyCode val2 in letterKeys)
				{
					if (Input.GetKeyDown(val2) && val2 != requestedKey)
					{
						flag = true;
					}
				}
				if (flag)
				{
					timer = ReactInterval;
				}
				else if (Input.GetKeyDown(requestedKey))
				{
					MidReact = false;
					ReactInterval = 0f;
					ClearText();
					Character.localCharacter.refs.afflictions.SubtractStatus((STATUSTYPE)0, ZConfig.HealReward.Value / 100f, false, false);
					Character.localCharacter.AddExtraStamina(ZConfig.ExtraStaminaReward.Value / 100f);
				}
			}
			else if (Input.GetKeyDown(requestedKey))
			{
				MidReact = false;
				ReactInterval = 0f;
				ClearText();
				Character.localCharacter.refs.afflictions.SubtractStatus((STATUSTYPE)0, ZConfig.HealReward.Value / 100f, false, false);
				Character.localCharacter.AddExtraStamina(ZConfig.ExtraStaminaReward.Value / 100f);
			}
		}

		static PlayerPatch()
		{
			KeyCode[] array = new KeyCode[18];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			LetterKeys = (KeyCode[])(object)array;
			HasStarted = false;
			MidReact = false;
			timer = 0f;
			interval = 1f;
			ReactInterval = 1f;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}