Decompiled source of FairyMode v1.3.0

plugins/yazirushi-FairyMode/FairyMode.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
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("FairyMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FairyMode")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a59b435c-4381-43ed-b572-6d201d67ef2d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FairyMode;

[BepInPlugin("yazirushi.FairyMode", "FairyMode", "1.3.0")]
public class FairyMode : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("yazirushi.FairyMode");

	internal static ManualLogSource mls;

	public static ConfigEntry<bool> EnableMod;

	public static ConfigEntry<float> StrengthBalance;

	public static ConfigEntry<float> FlashlightIntensity;

	public static ConfigEntry<bool> EnableLogging;

	private void Awake()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Mod Enable", true, "");
		StrengthBalance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Strength Balance", 0.65f, new ConfigDescription("0 == Vanilla, 1 == Square Root.  The higher the value, the more easily the upgrade power decays.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		FlashlightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Flashlight Intensity", 0.5f, new ConfigDescription("0 == Invalid, 1 == Same as usual.  The higher the value, the brighter it is.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		EnableLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("DebugLog", "Enable Logging", false, "Display debug logs");
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"Starting FairyMode...");
		harmony.PatchAll();
	}
}
[HarmonyPatch(typeof(PlayerAvatar), "Awake")]
public class Permission_Patch
{
	private static void Postfix(PlayerAvatar __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			if ((Object)(object)((Component)__instance).GetComponent<Main_Patch>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<Main_Patch>();
			}
			if ((Object)(object)((Component)__instance).GetComponent<Sync_Patch>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<Sync_Patch>();
			}
			Sync_Patch component = ((Component)__instance).GetComponent<Sync_Patch>();
			component.EnableMod = false;
		}
	}
}
public class Main_Patch : MonoBehaviour
{
	private static readonly FieldInfo fieldDeadSet = AccessTools.Field(typeof(PlayerAvatar), "deadSet");

	private static readonly FieldInfo fieldTumble = AccessTools.Field(typeof(PlayerAvatar), "tumble");

	private static readonly FieldInfo fieldPhysGrabObject = AccessTools.Field(typeof(PlayerTumble), "physGrabObject");

	private static readonly FieldInfo fieldSemiAffect = AccessTools.Field(typeof(SemiAffectZeroGravity), "semiAffect");

	private static readonly FieldInfo fieldTimer = AccessTools.Field(typeof(SemiAffect), "timer");

	private static readonly FieldInfo fieldGrabbedPhysGrabObject = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject");

	private static readonly FieldInfo fieldBaseIntensity = AccessTools.Field(typeof(FlashlightController), "baseIntensity");

	private static readonly FieldInfo fieldLevelAnimationCompleted = AccessTools.Field(typeof(LoadingUI), "levelAnimationCompleted");

	internal float updateTimer = 0.5f;

	private static GameObject zeroGravityAffectPrefab;

	public void Update()
	{
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Expected O, but got Unknown
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Expected O, but got Unknown
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Expected O, but got Unknown
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Expected O, but got Unknown
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: 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_039c: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.RunIsLevel())
		{
			updateTimer = 999f;
			return;
		}
		if (SemiFunc.RunIsLevel() && !CompleteLoading())
		{
			updateTimer = 0.5f;
			return;
		}
		if ((Object)(object)PlayerAvatar.instance == (Object)null)
		{
			updateTimer = 0.5f;
			return;
		}
		Sync_Patch component = ((Component)PlayerAvatar.instance).GetComponent<Sync_Patch>();
		if ((Object)(object)component == (Object)null)
		{
			updateTimer = 0.5f;
			return;
		}
		if (SemiFunc.IsMasterClientOrSingleplayer() && (component.EnableMod != FairyMode.EnableMod.Value || component.FlashlightIntensity != FairyMode.FlashlightIntensity.Value) && updateTimer < 1f)
		{
			component.Permission();
		}
		if (!component.EnableMod)
		{
			return;
		}
		updateTimer -= Time.deltaTime;
		if (!(updateTimer <= 0f))
		{
			return;
		}
		updateTimer = 0.5f;
		if (SemiFunc.IsMasterClientOrSingleplayer())
		{
			if (!TryGetPrefab())
			{
				return;
			}
			{
				foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
				{
					if ((Object)(object)item == (Object)null || PlayerIsDead(item))
					{
						continue;
					}
					if ((Object)(object)item.activeZeroGravityAffect == (Object)null)
					{
						Vector3 position = ((Component)item).transform.position;
						PlayerTumble val = (PlayerTumble)fieldTumble.GetValue(item);
						if ((Object)(object)val == (Object)null)
						{
							continue;
						}
						PhysGrabObject val2 = (PhysGrabObject)fieldPhysGrabObject.GetValue(val);
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						SemiAffect component2 = Object.Instantiate<GameObject>(zeroGravityAffectPrefab, position, Quaternion.identity).GetComponent<SemiAffect>();
						component2.direction = Vector3.up;
						component2.positionOfOriginalAreaOfEffect = position;
						component2.SetupSingleplayer(((Component)item).transform, val2, 1f, item);
						item.activeZeroGravityAffect = ((Component)component2).GetComponentInChildren<SemiAffectZeroGravity>();
						if (FairyMode.EnableLogging.Value)
						{
							FairyMode.mls.LogInfo((object)("add affect for " + SemiFunc.PlayerGetName(item)));
						}
					}
					else
					{
						SemiAffect obj = (SemiAffect)fieldSemiAffect.GetValue(item.activeZeroGravityAffect);
						fieldTimer.SetValue(obj, 1f);
					}
					PhysGrabObject val3 = (PhysGrabObject)fieldGrabbedPhysGrabObject.GetValue(item.physGrabber);
					if ((Object)(object)val3 != (Object)null)
					{
						if ((Object)(object)((Component)val3).GetComponent<EnemyRigidbody>() == (Object)null)
						{
							val3.OverrideGrabStrength(Mathf.Lerp(item.physGrabber.grabStrength, Mathf.Sqrt(item.physGrabber.grabStrength), FairyMode.StrengthBalance.Value), 1f);
						}
						else
						{
							val3.OverrideGrabStrength(0.1f, 1f);
						}
					}
					if ((Object)(object)item.flashlightController != (Object)null)
					{
						((Behaviour)item.flashlightController.spotlight).enabled = true;
						item.flashlightController.halo.enabled = true;
						item.flashlightController.LightActive = true;
						item.flashlightController.hideTransform.localRotation = Quaternion.Euler(0f, 0f, 0f);
						fieldBaseIntensity.SetValue(item.flashlightController, component.FlashlightIntensity);
					}
				}
				return;
			}
		}
		foreach (PlayerAvatar item2 in SemiFunc.PlayerGetAll())
		{
			if (!((Object)(object)item2 == (Object)null) && !PlayerIsDead(item2) && (Object)(object)item2.flashlightController != (Object)null)
			{
				((Behaviour)item2.flashlightController.spotlight).enabled = true;
				item2.flashlightController.halo.enabled = true;
				item2.flashlightController.LightActive = true;
				item2.flashlightController.hideTransform.localRotation = Quaternion.Euler(0f, 0f, 0f);
				fieldBaseIntensity.SetValue(item2.flashlightController, component.FlashlightIntensity);
			}
		}
	}

	private static bool TryGetPrefab()
	{
		if ((Object)(object)zeroGravityAffectPrefab != (Object)null)
		{
			return true;
		}
		StatsManager.instance.itemDictionary.TryGetValue("Item Staff Zero Gravity", out var value);
		if ((Object)(object)value == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() item == null");
			}
			return false;
		}
		GameObject prefab = ((PrefabRef<GameObject>)(object)value.prefab).Prefab;
		if ((Object)(object)prefab == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() gameObject == null");
			}
			return false;
		}
		ItemStaffZeroGravity componentInChildren = prefab.GetComponentInChildren<ItemStaffZeroGravity>();
		if ((Object)(object)componentInChildren == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() staffZeroGravity == null");
			}
			return false;
		}
		PrefabRef projectilePrefab = componentInChildren.projectilePrefab;
		if (projectilePrefab == null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() zeroGravityProjectile == null");
			}
			return false;
		}
		SemiAreaOfEffect componentInChildren2 = ((PrefabRef<GameObject>)(object)projectilePrefab).Prefab.GetComponentInChildren<SemiAreaOfEffect>();
		if ((Object)(object)componentInChildren2 == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() projectileSemiAreaOfEffect == null");
			}
			return false;
		}
		SemiAffectZeroGravity componentInChildren3 = ((PrefabRef<GameObject>)(object)componentInChildren2.semiAffectPrefab).Prefab.GetComponentInChildren<SemiAffectZeroGravity>();
		if ((Object)(object)componentInChildren3 == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"Failed TryGetPrefab() affectZeroGravity == null");
			}
			return false;
		}
		zeroGravityAffectPrefab = ((PrefabRef<GameObject>)(object)componentInChildren2.semiAffectPrefab).Prefab;
		return true;
	}

	private static bool PlayerIsDead(PlayerAvatar __player)
	{
		if ((Object)(object)__player == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"player == null");
			}
			return true;
		}
		return (bool)fieldDeadSet.GetValue(__player);
	}

	private static bool CompleteLoading()
	{
		if ((Object)(object)LoadingUI.instance == (Object)null)
		{
			if (FairyMode.EnableLogging.Value)
			{
				FairyMode.mls.LogInfo((object)"LoadingUI.instance == null");
			}
			return false;
		}
		return (bool)fieldLevelAnimationCompleted.GetValue(LoadingUI.instance);
	}
}
public class Sync_Patch : MonoBehaviourPun
{
	public bool EnableMod = false;

	public float FlashlightIntensity = 0f;

	public void Permission()
	{
		if (!SemiFunc.IsMultiplayer())
		{
			PermissionRPC(FairyMode.EnableMod.Value, FairyMode.FlashlightIntensity.Value);
			return;
		}
		((MonoBehaviourPun)this).photonView.RPC("PermissionRPC", (RpcTarget)0, new object[2]
		{
			FairyMode.EnableMod.Value,
			FairyMode.FlashlightIntensity.Value
		});
	}

	[PunRPC]
	public void PermissionRPC(bool __EnableMod, float __FlashlightIntensity)
	{
		if (FairyMode.EnableLogging.Value)
		{
			FairyMode.mls.LogInfo((object)$"RPC catch {__EnableMod}");
		}
		Sync_Patch component = ((Component)PlayerAvatar.instance).GetComponent<Sync_Patch>();
		component.EnableMod = __EnableMod;
		component.FlashlightIntensity = __FlashlightIntensity;
	}
}