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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
[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.eigeen.lethal.SummonMeteorShower")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SummonMeteorShower")]
[assembly: AssemblyTitle("com.eigeen.lethal.SummonMeteorShower")]
[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.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 Plugin
{
[BepInPlugin("com.eigeen.lethal.SummonMeteorShower", "SummonMeteorShower", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal ConfigEntry<bool> configMeteorEnable;
internal ConfigEntry<float> configMeteorProbability;
public static Plugin Instance { get; private set; }
public static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
internal static MethodInfo? Chat { get; private set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
configMeteorEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Meteor", "Enable", false, "Enable modifications to meteor shower event");
configMeteorProbability = ((BaseUnityPlugin)this).Config.Bind<float>("Meteor", "Probability", 0.007f, "The probability of meteor shower events per day\nValue: 0.0 - 1.0");
if ((double)configMeteorProbability.Value < 0.0 || (double)configMeteorProbability.Value > 1.0)
{
Logger.LogWarning((object)$"configMeteorProbability has invalid value: {configMeteorProbability.Value}. Will be replaced with the default value.");
configMeteorProbability.Value = (float)((ConfigEntryBase)configMeteorProbability).DefaultValue;
}
Chat = AccessTools.Method(typeof(HUDManager), "AddChatMessage", (Type[])null, (Type[])null);
Patch();
Logger.LogInfo((object)"com.eigeen.lethal.SummonMeteorShower v1.0.0 has loaded!");
}
internal static void Patch()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("com.eigeen.lethal.SummonMeteorShower");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
public static void SendChatMessage(string message)
{
HUDManager instance = HUDManager.Instance;
instance.lastChatMessage = "";
Chat?.Invoke(instance, new object[2] { message, "" });
}
public static void StartMeteorEvent()
{
TimeOfDay instance = TimeOfDay.Instance;
instance.meteorShowerAtTime = -1f;
instance.MeteorWeather.SetStartMeteorShower();
Logger.LogDebug((object)"SetStartMeteorShower");
}
public static void StopMeteorEvent()
{
TimeOfDay instance = TimeOfDay.Instance;
instance.MeteorWeather.ResetMeteorWeather();
Logger.LogDebug((object)"ResetMeteorWeather");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.eigeen.lethal.SummonMeteorShower";
public const string PLUGIN_NAME = "SummonMeteorShower";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace Plugin.Utils
{
public class MeteorRandomizer
{
private readonly Random _random;
private int _activeChanceValue;
public float AtTime { get; private set; }
public MeteorRandomizer(int seed)
{
_random = new Random(seed + 28);
_activeChanceValue = _random.Next(0, 1000);
AtTime = (float)_random.Next(5, 80) / 100f;
}
public bool IsEventActive(float prob)
{
if (_activeChanceValue < (int)(prob * 1000f))
{
return true;
}
return false;
}
}
}
namespace Plugin.Patches
{
[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
internal class SubmitChatPatch
{
private static bool Prefix(HUDManager __instance, ref CallbackContext context)
{
if (!((CallbackContext)(ref context)).performed)
{
return true;
}
if (string.IsNullOrEmpty(__instance.chatTextField.text))
{
return true;
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if ((Object)(object)localPlayerController == (Object)null)
{
return true;
}
StartOfRound playersManager = localPlayerController.playersManager;
if ((Object)(object)playersManager == (Object)null)
{
return true;
}
switch (__instance.chatTextField.text)
{
case "/meteor":
ResetTextbox(__instance, localPlayerController);
if (!CanCallEvents(localPlayerController))
{
return false;
}
if (IsMeteorEventRunning())
{
StopMeteorEvent();
}
else
{
StartMeteorEvent();
}
return false;
case "/meteor start":
ResetTextbox(__instance, localPlayerController);
if (!CanCallEvents(localPlayerController))
{
return false;
}
StartMeteorEvent();
return false;
case "/meteor stop":
ResetTextbox(__instance, localPlayerController);
if (!CanCallEvents(localPlayerController))
{
return false;
}
StopMeteorEvent();
return false;
default:
return true;
}
}
private static void ResetTextbox(HUDManager manager, PlayerControllerB local)
{
local.isTypingChat = false;
manager.chatTextField.text = "";
EventSystem.current.SetSelectedGameObject((GameObject)null);
manager.PingHUDElement(manager.Chat, 2f, 1f, 0.2f);
((Behaviour)manager.typingIndicator).enabled = false;
}
private static bool CanCallEvents(PlayerControllerB local)
{
StartOfRound playersManager = local.playersManager;
if (!GameNetworkManager.Instance.isHostingGame)
{
Plugin.SendChatMessage("Only the host can summon events.");
Plugin.Logger.LogError((object)"Only the host can summon events.");
return false;
}
if (local.isInHangarShipRoom && playersManager.inShipPhase && !playersManager.travellingToNewLevel)
{
Plugin.SendChatMessage("Cannot summon events: ship must be in planet.");
Plugin.Logger.LogError((object)"Cannot summon events: ship must be in planet.");
return false;
}
return true;
}
private static void StartMeteorEvent()
{
Plugin.StartMeteorEvent();
Plugin.SendChatMessage("Start meteor shower event.");
Plugin.Logger.LogInfo((object)"Start meteor shower event.");
}
private static void StopMeteorEvent()
{
Plugin.StopMeteorEvent();
Plugin.SendChatMessage("Stop meteor shower event.");
Plugin.Logger.LogInfo((object)"Stop meteor shower event.");
}
private static bool IsMeteorEventRunning()
{
return TimeOfDay.Instance.MeteorWeather.meteorsEnabled;
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal class TimeOfDayPatch
{
[HarmonyPatch("DecideRandomDayEvents")]
[HarmonyPrefix]
private static void DecideRandomDayEventsPatch(TimeOfDay __instance)
{
if (Plugin.Instance.configMeteorEnable.Value && (float)__instance.overrideMeteorChance == -1f)
{
__instance.overrideMeteorChance = (int)(Plugin.Instance.configMeteorProbability.Value * 1000f);
}
}
}
}