Decompiled source of FogPetrify v1.1.0

plugins/FogPetrify/com.github.LatinBrad.FogPetrify.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 ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.LatinBrad.FogPetrify")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("com.github.LatinBrad.FogPetrify")]
[assembly: AssemblyTitle("FogPetrify")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 FogPetrify
{
	[BepInPlugin("com.github.LatinBrad.FogPetrify", "FogPetrify", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static bool SyncedEnabled = true;

		internal static STATUSTYPE SyncedEffectType = (STATUSTYPE)13;

		internal static bool SyncedRandomEffect = false;

		internal static STATUSTYPE CurrentRandomEffect = (STATUSTYPE)13;

		internal static int SyncedEffectPerSecond = 1;

		internal static bool SyncedOnlyAffectFogCold = true;

		internal static float SyncedTimeBeforeMoving = 500f;

		internal static bool SyncedForceFullWait = false;

		internal static float SyncedFogSpeed = 0.3f;

		internal static float SyncedFogColorR = 0f;

		internal static float SyncedFogColorG = 0f;

		internal static float SyncedFogColorB = 0f;

		internal static float SyncedFogDistanceVisibilityOffset = 100f;

		internal static readonly STATUSTYPE[] RandomEffectPool;

		public const string Id = "com.github.LatinBrad.FogPetrify";

		internal static ManualLogSource Log { get; private set; } = null;

		internal static ConfigEntry<bool> Enabled { get; private set; } = null;

		internal static ConfigEntry<STATUSTYPE> EffectType { get; private set; } = null;

		internal static ConfigEntry<bool> RandomEffect { get; private set; } = null;

		internal static ConfigEntry<int> EffectPerSecond { get; private set; } = null;

		internal static ConfigEntry<bool> OnlyAffectFogCold { get; private set; } = null;

		internal static ConfigEntry<float> TimeBeforeMoving { get; private set; } = null;

		internal static ConfigEntry<bool> ForceFullWait { get; private set; } = null;

		internal static ConfigEntry<float> FogSpeed { get; private set; } = null;

		internal static ConfigEntry<float> FogColorR { get; private set; } = null;

		internal static ConfigEntry<float> FogColorG { get; private set; } = null;

		internal static ConfigEntry<float> FogColorB { get; private set; } = null;

		internal static ConfigEntry<float> FogDistanceVisibilityOffset { get; private set; } = null;

		public static string Name => "FogPetrify";

		public static string Version => "1.0.0";

		private void Awake()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Expected O, but got Unknown
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("FogPetrify", "Enabled", true, "Activa o desactiva todos los cambios de este mod. Si esta en false, la niebla se comporta 100% vanilla.");
			EffectType = ((BaseUnityPlugin)this).Config.Bind<STATUSTYPE>("FogPetrify", "1 - Effect Type", (STATUSTYPE)13, "Que efecto aplica la niebla mientras estas dentro de ella (se ignora si 'Random Effect' esta activado). Solo el HOST controla este valor; a los clientes se les sincroniza automaticamente.");
			RandomEffect = ((BaseUnityPlugin)this).Config.Bind<bool>("FogPetrify", "1.5 - Random Effect", false, "Si esta en true, se sortea UN efecto al azar (solo lo decide el host). Se sortea una sola vez por expedicion y se sincroniza a todos.");
			EffectPerSecond = ((BaseUnityPlugin)this).Config.Bind<int>("FogPetrify", "2 - Effect Per Second", 5, new ConfigDescription("Intensidad del efecto. Rango: 1 a 10. Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
			OnlyAffectFogCold = ((BaseUnityPlugin)this).Config.Bind<bool>("FogPetrify", "2.5 - Only Affect Fog (not night cold, etc.)", true, "Si esta en true, SOLO se reemplaza el frio que viene de la niebla. Solo el host lo controla.");
			TimeBeforeMoving = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "3 - Time Before Moving (seconds)", 500f, new ConfigDescription("Cuanto tiempo (en segundos reales) espera la niebla antes de avanzar. El valor vanilla original ronda los 500-1000s segun el nivel. Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1200f), Array.Empty<object>()));
			ForceFullWait = ((BaseUnityPlugin)this).Config.Bind<bool>("FogPetrify", "3.5 - Force Full Wait", false, "Si esta en true, la niebla SIEMPRE espera el tiempo completo de '3 - Time Before Moving' antes de avanzar, sin importar si el grupo ya se alejo bastante del punto de partida (que en el juego original hace que la niebla arranque antes). Solo el host lo controla.");
			FogSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "4 - Fog Speed", 0.3f, new ConfigDescription("Que tan rapido avanza la niebla (unidades por segundo). El valor vanilla original es 0.3-0.4. Numeros mas altos = avanza mas rapido. Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>()));
			FogColorR = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "5.1 - Fog Color Red", 0f, new ConfigDescription("Componente ROJO (0 a 1). Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			FogColorG = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "5.2 - Fog Color Green", 0f, new ConfigDescription("Componente VERDE (0 a 1). Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			FogColorB = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "5.3 - Fog Color Blue", 0f, new ConfigDescription("Componente AZUL (0 a 1). Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			FogDistanceVisibilityOffset = ((BaseUnityPlugin)this).Config.Bind<float>("FogPetrify", "6 - Fog Distance Visibility Offset", 100f, new ConfigDescription("Controla _DistanceVisibilityOffset. Default vanilla: 30. Rango: 0 a 500. Solo el host lo controla.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 500f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.SettingChanged += delegate
			{
				if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
				{
					ConfigNetworkSync.ApplyLocalConfigToSynced();
					ConfigNetworkSync.HostBroadcastIfMaster();
				}
			};
			ConfigNetworkSync.ApplyLocalConfigToSynced();
			PhotonNetwork.AddCallbackTarget((object)new ConfigNetworkSync());
			Harmony val = new Harmony("com.github.LatinBrad.FogPetrify");
			val.PatchAll(typeof(OrbFogHandler_AwakeLogPatch));
			val.PatchAll(typeof(OrbFogHandler_ControlPatch));
			val.PatchAll(typeof(OrbFogHandler_ForceFullWaitPatch));
			val.PatchAll(typeof(FogSphere_ColorPatch));
			val.PatchAll(typeof(CharacterAfflictions_AddStatus_Patch));
			Log.LogInfo((object)"FogPetrify cargado. Solo el host controla los valores; se sincronizan por Photon a todos los clientes.");
		}

		static Plugin()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			STATUSTYPE[] array = new STATUSTYPE[7];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			RandomEffectPool = (STATUSTYPE[])(object)array;
		}
	}
	public class ConfigNetworkSync : IInRoomCallbacks, IOnEventCallback
	{
		public const byte SyncEventCode = 99;

		internal static void ApplyLocalConfigToSynced()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Plugin.SyncedEnabled = Plugin.Enabled.Value;
			Plugin.SyncedEffectType = Plugin.EffectType.Value;
			Plugin.SyncedRandomEffect = Plugin.RandomEffect.Value;
			Plugin.SyncedEffectPerSecond = Plugin.EffectPerSecond.Value;
			Plugin.SyncedOnlyAffectFogCold = Plugin.OnlyAffectFogCold.Value;
			Plugin.SyncedTimeBeforeMoving = Plugin.TimeBeforeMoving.Value;
			Plugin.SyncedForceFullWait = Plugin.ForceFullWait.Value;
			Plugin.SyncedFogSpeed = Plugin.FogSpeed.Value;
			Plugin.SyncedFogColorR = Plugin.FogColorR.Value;
			Plugin.SyncedFogColorG = Plugin.FogColorG.Value;
			Plugin.SyncedFogColorB = Plugin.FogColorB.Value;
			Plugin.SyncedFogDistanceVisibilityOffset = Plugin.FogDistanceVisibilityOffset.Value;
		}

		internal static void HostBroadcastIfMaster()
		{
			if (PhotonNetwork.IsConnectedAndReady && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
			{
				BroadcastTo(null);
			}
		}

		private static void BroadcastTo(int? actorNumber)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected I4, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected I4, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[13]
			{
				Plugin.SyncedEnabled,
				(int)Plugin.SyncedEffectType,
				Plugin.SyncedRandomEffect,
				(int)Plugin.CurrentRandomEffect,
				Plugin.SyncedEffectPerSecond,
				Plugin.SyncedOnlyAffectFogCold,
				Plugin.SyncedTimeBeforeMoving,
				Plugin.SyncedFogSpeed,
				Plugin.SyncedFogColorR,
				Plugin.SyncedFogColorG,
				Plugin.SyncedFogColorB,
				Plugin.SyncedFogDistanceVisibilityOffset,
				Plugin.SyncedForceFullWait
			};
			object obj;
			if (!actorNumber.HasValue)
			{
				obj = (object)new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				};
			}
			else
			{
				RaiseEventOptions val = new RaiseEventOptions();
				val.TargetActors = new int[1] { actorNumber.Value };
				obj = val;
			}
			RaiseEventOptions val2 = (RaiseEventOptions)obj;
			SendOptions val3 = default(SendOptions);
			((SendOptions)(ref val3)).Reliability = true;
			SendOptions val4 = val3;
			PhotonNetwork.RaiseEvent((byte)99, (object)array, val2, val4);
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if (photonEvent.Code == 99 && photonEvent.CustomData is object[] array && array.Length >= 13)
			{
				Room currentRoom = PhotonNetwork.CurrentRoom;
				Player val = ((currentRoom != null) ? currentRoom.GetPlayer(photonEvent.Sender, false) : null);
				if (val != null && val.IsMasterClient)
				{
					Plugin.SyncedEnabled = (bool)array[0];
					Plugin.SyncedEffectType = (STATUSTYPE)(int)array[1];
					Plugin.SyncedRandomEffect = (bool)array[2];
					Plugin.CurrentRandomEffect = (STATUSTYPE)(int)array[3];
					Plugin.SyncedEffectPerSecond = (int)array[4];
					Plugin.SyncedOnlyAffectFogCold = (bool)array[5];
					Plugin.SyncedTimeBeforeMoving = (float)array[6];
					Plugin.SyncedFogSpeed = (float)array[7];
					Plugin.SyncedFogColorR = (float)array[8];
					Plugin.SyncedFogColorG = (float)array[9];
					Plugin.SyncedFogColorB = (float)array[10];
					Plugin.SyncedFogDistanceVisibilityOffset = (float)array[11];
					Plugin.SyncedForceFullWait = (bool)array[12];
					Plugin.Log.LogInfo((object)"[FogPetrify] Configuracion recibida del host y aplicada.");
				}
			}
		}

		public void OnPlayerEnteredRoom(Player newPlayer)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				ApplyLocalConfigToSynced();
				BroadcastTo(newPlayer.ActorNumber);
			}
		}

		public void OnPlayerLeftRoom(Player otherPlayer)
		{
		}

		public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
		{
		}

		public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
		{
		}

		public void OnMasterClientSwitched(Player newMasterClient)
		{
			if (newMasterClient.IsLocal)
			{
				ApplyLocalConfigToSynced();
				HostBroadcastIfMaster();
			}
		}
	}
	[HarmonyPatch(typeof(FogSphere), "SetSharderVars")]
	public static class FogSphere_ColorPatch
	{
		private static void Postfix(FogSphere __instance)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.SyncedEnabled && __instance.mpb != null && (Object)(object)__instance.rend != (Object)null)
			{
				Vector4 val = default(Vector4);
				((Vector4)(ref val))..ctor(Plugin.SyncedFogColorR, Plugin.SyncedFogColorG, Plugin.SyncedFogColorB, 0f);
				__instance.mpb.SetFloat("_DistanceVisibilityOffset", Plugin.SyncedFogDistanceVisibilityOffset);
				__instance.mpb.SetVector("_FogtintColor", val);
				__instance.rend.SetPropertyBlock(__instance.mpb);
			}
		}
	}
	[HarmonyPatch(typeof(OrbFogHandler), "Start")]
	public static class OrbFogHandler_AwakeLogPatch
	{
		private static void Postfix(OrbFogHandler __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.IsMasterClient && Plugin.SyncedRandomEffect)
			{
				int num = Random.Range(0, Plugin.RandomEffectPool.Length);
				Plugin.CurrentRandomEffect = Plugin.RandomEffectPool[num];
				ConfigNetworkSync.HostBroadcastIfMaster();
				Plugin.Log.LogInfo((object)"[FogPetrify] (HOST) Se sorteo un nuevo efecto aleatorio para esta expedicion y se sincronizo.");
			}
			Plugin.Log.LogInfo((object)("[FogPetrify] Niebla detectada (OrbFogHandler) -> Valores VANILLA: " + $"FogSpeed: {__instance.speed}, TimeBeforeMoving (maxWaitTime): {__instance.maxWaitTime}s"));
		}
	}
	[HarmonyPatch(typeof(OrbFogHandler), "Update")]
	public static class OrbFogHandler_ControlPatch
	{
		private static void Prefix(OrbFogHandler __instance)
		{
			if (Plugin.SyncedEnabled)
			{
				__instance.speed = Plugin.SyncedFogSpeed;
				__instance.maxWaitTime = Plugin.SyncedTimeBeforeMoving;
			}
		}
	}
	[HarmonyPatch(typeof(OrbFogHandler), "PlayersHaveMovedOn")]
	public static class OrbFogHandler_ForceFullWaitPatch
	{
		private static bool Prefix(ref bool __result)
		{
			if (!Plugin.SyncedEnabled || !Plugin.SyncedForceFullWait)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions), "AddStatus")]
	public static class CharacterAfflictions_AddStatus_Patch
	{
		private static float petrifyAccumulator;

		private static bool loggedOnce;

		private static bool Prefix(ref STATUSTYPE statusType, ref float amount)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Invalid comparison between Unknown and I4
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected I4, but got Unknown
			if (!Plugin.SyncedEnabled)
			{
				return true;
			}
			if ((int)statusType != 2)
			{
				return true;
			}
			if ((Object)(object)Character.localCharacter != (Object)null && Character.localCharacter.data.dead)
			{
				return true;
			}
			if (Plugin.SyncedOnlyAffectFogCold)
			{
				MethodBase method = new StackFrame(2).GetMethod();
				if (method == null || method.DeclaringType != typeof(FogSphere))
				{
					return true;
				}
			}
			if (!loggedOnce)
			{
				loggedOnce = true;
				Plugin.Log.LogInfo((object)"[FogPetrify] Intercepte un intento de aplicar frio (Cold). Se reemplaza por el efecto sincronizado del host.");
			}
			STATUSTYPE val = (Plugin.SyncedRandomEffect ? Plugin.CurrentRandomEffect : Plugin.SyncedEffectType);
			float num = (float)Plugin.SyncedEffectPerSecond * 0.01f;
			float num2 = num * Time.deltaTime;
			if ((int)val == 13)
			{
				petrifyAccumulator += num2;
				if (petrifyAccumulator < 0.01f)
				{
					return false;
				}
				num2 = petrifyAccumulator;
				petrifyAccumulator = 0f;
			}
			statusType = (STATUSTYPE)(int)val;
			amount = num2;
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}