using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using LethalNetworkAPI;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
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: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("jammees.lcmymango")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+09321faa128aedde9a27478d245de6acaadc2097")]
[assembly: AssemblyProduct("LCMyMango")]
[assembly: AssemblyTitle("jammees.lcmymango")]
[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 LCMyMango
{
[BepInPlugin("jammees.lcmymango", "LCMyMango", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class LCMyMango : BaseUnityPlugin
{
public static LCMyMango Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony Harmony { get; set; }
internal static MangoConfig MangoConfig { get; private set; }
internal static MangoConfigPrimitive HostConfig { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
MangoConfig = new MangoConfig(((BaseUnityPlugin)this).Config);
Patch();
if (RegisterLobbyCompatibility.HasLobbyCompatibility)
{
RegisterLobbyCompatibility.RegisterSelf();
}
Logger.LogInfo((object)"jammees.lcmymango 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("jammees.lcmymango");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
}
internal static class RegisterLobbyCompatibility
{
public static bool HasLobbyCompatibility => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");
public static void RegisterSelf()
{
PluginHelper.RegisterPlugin("jammees.lcmymango", new Version("1.0.0"), (CompatibilityLevel)3, (VersionStrictness)2);
LCMyMango.Logger.LogDebug((object)"Registered mod for LobbyCompatibility");
}
}
public class MangoConfigPrimitive
{
public float TimeUntilExplode;
public float ExplodeCooldown;
}
public class MangoConfigPacket
{
public enum PacketType
{
Request,
Receive
}
public MangoConfigPrimitive? Config;
public PacketType Type;
}
public class MangoConfig
{
private readonly ConfigEntry<float> _voiceThreshold;
private readonly ConfigEntry<float> _timeUntilExplode;
private readonly ConfigEntry<float> _explodeCooldown;
public float VoiceThreshold => _voiceThreshold.Value;
public float TimeUntilExplode => _timeUntilExplode.Value;
public float ExplodeCooldown => _explodeCooldown.Value;
public MangoConfig(ConfigFile cfg)
{
cfg.SaveOnConfigSet = false;
_voiceThreshold = cfg.Bind<float>("Voice", "VoiceThreshold", 0.2f, "The minimum voice loudness required to start considering whether to spawn a mine. Is not synced with the host.");
_timeUntilExplode = cfg.Bind<float>("Host", "TimeUntilExplode", 0.5f, "The minimum time required screaming to spawn a mine. Is synced with the host.");
_explodeCooldown = cfg.Bind<float>("Host", "ExplodeCooldown", 2f, "Minimum required time to wait until another mine can be spawned again. Is synced with the host.");
ClearOrphanedEntries(cfg);
cfg.Save();
cfg.SaveOnConfigSet = true;
}
private static void ClearOrphanedEntries(ConfigFile cfg)
{
PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
dictionary.Clear();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "jammees.lcmymango";
public const string PLUGIN_NAME = "LCMyMango";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace LCMyMango.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
public class PlayerControllerBPatch
{
private static bool _explodeCooldown;
private static float _timeSinceScreaming;
private static LNetworkMessage<ulong>? _explosionMessage;
private static LNetworkMessage<MangoConfigPacket>? _syncConfigMessage;
[HarmonyPatch(typeof(StartOfRound), "Awake")]
[HarmonyPostfix]
private static void OnClientJoined()
{
if (_explosionMessage == null)
{
_explosionMessage = LNetworkMessage<ulong>.Create("ExplodeRequest", (Action<ulong, ulong>)null, (Action<ulong>)null, (Action<ulong, ulong>)null);
}
LCMyMango.Logger.LogInfo((object)"Created client/server connection.");
if (_syncConfigMessage == null)
{
_syncConfigMessage = LNetworkMessage<MangoConfigPacket>.Create("SyncConfig", (Action<MangoConfigPacket, ulong>)null, (Action<MangoConfigPacket>)null, (Action<MangoConfigPacket, ulong>)null);
}
LCMyMango.Logger.LogInfo((object)"Created config sync connection.");
}
private static void SetupConnections()
{
_explosionMessage.OnServerReceived += OnServerExplosionRequest;
_syncConfigMessage.OnClientReceived += OnClientConfigReceived;
_syncConfigMessage.OnServerReceived += OnServerConfigRequest;
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void OnPlayerReady()
{
SetupConnections();
if (!NetworkManager.Singleton.IsHost)
{
_syncConfigMessage?.SendServer(new MangoConfigPacket
{
Type = MangoConfigPacket.PacketType.Request
});
}
else
{
SetHostConfigToLocal();
}
}
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
[HarmonyPostfix]
private static void OnClientStartDisconnecting()
{
_explosionMessage?.ClearSubscriptions();
_syncConfigMessage?.ClearSubscriptions();
LCMyMango.HostConfig = null;
LCMyMango.Logger.LogInfo((object)"Destroyed client/server connection.");
}
private static void OnClientConfigReceived(MangoConfigPacket packet)
{
if (!NetworkManager.Singleton.IsHost && packet.Type == MangoConfigPacket.PacketType.Receive)
{
_syncConfigMessage?.ClearSubscriptions();
MangoConfigPrimitive config = packet.Config;
if (config == null)
{
LCMyMango.Logger.LogError((object)"Failed to fetch/deserialize host config! Using client values!");
SetHostConfigToLocal();
return;
}
LCMyMango.Logger.LogDebug((object)$"CLIENT {config.TimeUntilExplode}, {config.ExplodeCooldown}");
LCMyMango.HostConfig = config;
LCMyMango.Logger.LogInfo((object)"Successfuly fetched host config!");
((MonoBehaviour)StartOfRound.Instance.localPlayerController).StartCoroutine(DisplaySyncNotice());
}
}
private static IEnumerator DisplaySyncNotice()
{
yield return (object)new WaitForSeconds(1.5f);
HUDManager.Instance.DisplayTip("LCMyMango", $"Successfully synced with host's config!\nTimeUntilExplode: {LCMyMango.HostConfig.TimeUntilExplode} seconds\nExplodeCooldown: {LCMyMango.HostConfig.ExplodeCooldown} seconds", false, false, "LC_Tip1");
}
private static void OnServerConfigRequest(MangoConfigPacket packet, ulong id)
{
LCMyMango.Logger.LogInfo((object)$"playerId: {id} requested a host config sync");
if (packet.Type == MangoConfigPacket.PacketType.Request)
{
LCMyMango.Logger.LogDebug((object)$"SERVER {LCMyMango.MangoConfig.TimeUntilExplode}, {LCMyMango.MangoConfig.ExplodeCooldown}");
MangoConfigPrimitive config = new MangoConfigPrimitive
{
TimeUntilExplode = LCMyMango.MangoConfig.TimeUntilExplode,
ExplodeCooldown = LCMyMango.MangoConfig.ExplodeCooldown
};
_syncConfigMessage?.SendClient(new MangoConfigPacket
{
Config = config,
Type = MangoConfigPacket.PacketType.Receive
}, id);
}
}
private static void OnServerExplosionRequest(ulong _, ulong clientID)
{
//IL_00d8: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
PlayerControllerB playerController = LethalNetworkExtensions.GetPlayerController(clientID);
if (playerController == null || playerController.isPlayerDead)
{
return;
}
if (!((NetworkBehaviour)playerController).IsHost)
{
LCMyMango.Logger.LogError((object)((((Object)playerController).name ?? "Unknown") + " tried to call server only method!"));
return;
}
LCMyMango.Logger.LogInfo((object)$"clientID: {clientID}");
SpawnableMapObject val = StartOfRound.Instance?.levels?.SelectMany((SelectableLevel x) => x.spawnableMapObjects).FirstOrDefault((Func<SpawnableMapObject, bool>)((SpawnableMapObject x) => ((Object)x.prefabToSpawn).name == "Landmine"));
if (val == null)
{
LCMyMango.Logger.LogError((object)"Failed to find landmine spawnable map object!");
return;
}
Vector3 val2 = ((Component)playerController).gameObject.transform.position - new Vector3(0f, 0.25f, 0f);
GameObject val3 = Object.Instantiate<GameObject>(val.prefabToSpawn, val2, Quaternion.identity);
Landmine componentInChildren = val3.GetComponentInChildren<Landmine>();
val3.GetComponent<NetworkObject>().Spawn(true);
componentInChildren.ExplodeMineServerRpc();
}
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPostfix]
private static void OnUpdatePatch(PlayerControllerB __instance)
{
if (_explodeCooldown || __instance.isPlayerDead)
{
return;
}
StartOfRound instance = StartOfRound.Instance;
VoicePlayerState val = instance.voiceChatModule.FindPlayer(instance.voiceChatModule.LocalPlayerName);
bool flag = val.IsSpeaking;
Settings settings = IngamePlayerSettings.Instance.settings;
if (settings != null && settings.pushToTalk)
{
PlayerInput playerInput = IngamePlayerSettings.Instance.playerInput;
bool? obj;
if (playerInput == null)
{
obj = null;
}
else
{
InputActionAsset actions = playerInput.actions;
if (actions == null)
{
obj = null;
}
else
{
InputAction obj2 = actions.FindAction("VoiceButton", false);
obj = ((obj2 != null) ? new bool?(obj2.IsPressed()) : null);
}
}
bool? flag2 = obj;
if (flag2.HasValue && !flag2.Value)
{
flag = false;
}
}
if (!flag || instance.averageVoiceAmplitude < LCMyMango.MangoConfig.VoiceThreshold)
{
_timeSinceScreaming = 0f;
return;
}
_timeSinceScreaming += Time.deltaTime;
if (_timeSinceScreaming >= LCMyMango.HostConfig.TimeUntilExplode)
{
_timeSinceScreaming = 0f;
_explodeCooldown = true;
((MonoBehaviour)__instance).StartCoroutine(ExplosionCooldownCoroutine());
LCMyMango.Logger.LogInfo((object)"Send server rpc");
_explosionMessage?.SendServer(__instance.actualClientId);
}
}
private static IEnumerator ExplosionCooldownCoroutine()
{
yield return (object)new WaitForSeconds(LCMyMango.HostConfig.ExplodeCooldown);
_explodeCooldown = false;
LCMyMango.Logger.LogInfo((object)"Waited");
}
private static void SetHostConfigToLocal()
{
MangoConfigPrimitive hostConfig = new MangoConfigPrimitive
{
TimeUntilExplode = LCMyMango.MangoConfig.TimeUntilExplode,
ExplodeCooldown = LCMyMango.MangoConfig.ExplodeCooldown
};
LCMyMango.HostConfig = hostConfig;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}