using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Logging;
using DarthLilo.WhoVoted.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
using WhoVoted.Helpers;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DarthLilo.WhoVoted")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+281f347ae2d65e0f389e93dcd5a2c89d2a1070e4")]
[assembly: AssemblyProduct("WhoVoted")]
[assembly: AssemblyTitle("DarthLilo.WhoVoted")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
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 WhoVoted
{
[BepInPlugin("DarthLilo.WhoVoted", "WhoVoted", "1.0.2")]
public class WhoVoted : BaseUnityPlugin
{
private AssetBundle WhoVotedAssets;
public static GameObject NewSpecatingBoxPrefab;
public static WhoVoted Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "lilowhovotedassets");
WhoVotedAssets = AssetBundle.LoadFromFile(text);
if ((Object)(object)WhoVotedAssets == (Object)null)
{
Logger.LogError((object)"Could not find the required asset bundle! Please make sure the file \"lilobabymaneaterassets\" is in the same directory as this dll!");
}
NewSpecatingBoxPrefab = WhoVotedAssets.LoadAsset<GameObject>("Assets/WhoVoted/NewPlayerSpectateBox.prefab");
Patch();
Logger.LogInfo((object)"Running netcode patchers");
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
Logger.LogInfo((object)"DarthLilo.WhoVoted v1.0.2 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("DarthLilo.WhoVoted");
}
Logger.LogDebug((object)"Patching...");
Harmony.PatchAll();
Logger.LogDebug((object)"Finished patching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "DarthLilo.WhoVoted";
public const string PLUGIN_NAME = "WhoVoted";
public const string PLUGIN_VERSION = "1.0.2";
}
}
namespace WhoVoted.Patches
{
[HarmonyPatch(typeof(HUDManager))]
public class WhoVotedUIPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(HUDManager __instance)
{
__instance.spectatingPlayerBoxPrefab = WhoVoted.NewSpecatingBoxPrefab;
}
[HarmonyPatch("RemoveSpectateUI")]
[HarmonyPrefix]
private static void RemoveSpectateUIPatch(HUDManager __instance)
{
for (int i = 0; i < __instance.spectatingPlayerBoxes.Count; i++)
{
((Behaviour)((Component)((Component)__instance.spectatingPlayerBoxes.ElementAt(i).Key).gameObject.transform.Find("HasVoted")).gameObject.GetComponent<RawImage>()).enabled = false;
}
WhoVotedNetworkHelper.Instance.ClearVotedServerRpc();
}
[HarmonyPatch("UpdateBoxesSpectateUI")]
[HarmonyPostfix]
private static void SyncVotedClientsOnDeath(HUDManager __instance)
{
PlayerControllerB playerScript;
for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
{
playerScript = StartOfRound.Instance.allPlayerScripts[i];
if (WhoVotedNetworkHelper.VotedClients.ContainsKey(((NetworkBehaviour)playerScript).NetworkObjectId.ToString()))
{
Animator key = __instance.spectatingPlayerBoxes.FirstOrDefault<KeyValuePair<Animator, PlayerControllerB>>((KeyValuePair<Animator, PlayerControllerB> x) => (Object)(object)x.Value == (Object)(object)playerScript).Key;
if ((Object)(object)key != (Object)null)
{
GameObject gameObject = ((Component)((Component)key).gameObject.transform.Find("HasVoted")).gameObject;
((Behaviour)gameObject.GetComponent<RawImage>()).enabled = true;
}
}
}
}
}
[HarmonyPatch(typeof(TimeOfDay))]
public class WhoVotedPatch
{
[HarmonyPatch("VoteShipToLeaveEarly")]
[HarmonyPrefix]
private static void VoteShiptoLeaveEarlyPatch(TimeOfDay __instance)
{
if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.localPlayer != (Object)null && !__instance.votedShipToLeaveEarlyThisRound)
{
string inc_ulong = ((NetworkBehaviour)HUDManager.Instance.localPlayer).NetworkObjectId.ToString();
WhoVotedNetworkHelper.Instance.SyncWhoVotedServerRpc(inc_ulong);
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
public class GameNetworkManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch(GameNetworkManager __instance)
{
((Component)__instance).gameObject.AddComponent<WhoVotedNetworkHelper>();
((Component)__instance).gameObject.AddComponent<NetworkObject>();
WhoVoted.Logger.LogInfo((object)"Network Helper Added!");
}
}
}
namespace WhoVoted.Helpers
{
internal class WhoVotedNetworkHelper : NetworkBehaviour
{
public static Dictionary<string, bool> VotedClients = new Dictionary<string, bool>();
public static WhoVotedNetworkHelper Instance { get; private set; }
private void Start()
{
Instance = this;
WhoVoted.Logger.LogInfo((object)"WhoVotedNetworkHelper.Start() initialized!");
}
[ServerRpc(RequireOwnership = false)]
public void SyncWhoVotedServerRpc(string inc_ulong)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4037720139u, val, (RpcDelivery)0);
bool flag = inc_ulong != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(inc_ulong, false);
}
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4037720139u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
if (inc_ulong != null)
{
ulong num = ulong.Parse(inc_ulong);
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB playerScript in allPlayerScripts)
{
if (((NetworkBehaviour)playerScript).NetworkObjectId == num && (Object)(object)HUDManager.Instance != (Object)null && HUDManager.Instance.spectatingPlayerBoxes != null)
{
Animator key = HUDManager.Instance.spectatingPlayerBoxes.FirstOrDefault<KeyValuePair<Animator, PlayerControllerB>>((KeyValuePair<Animator, PlayerControllerB> x) => (Object)(object)x.Value == (Object)(object)playerScript).Key;
if ((Object)(object)key != (Object)null)
{
GameObject gameObject = ((Component)((Component)key).gameObject.transform.Find("HasVoted")).gameObject;
((Behaviour)gameObject.GetComponent<RawImage>()).enabled = true;
}
}
}
VotedClients[inc_ulong] = true;
SyncWhoVotedClientRpc(inc_ulong);
}
else
{
WhoVoted.Logger.LogError((object)"Received null ulong, skipping");
}
}
[ClientRpc]
public void SyncWhoVotedClientRpc(string inc_ulong)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2933124034u, val, (RpcDelivery)0);
bool flag = inc_ulong != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(inc_ulong, false);
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2933124034u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
{
return;
}
if (inc_ulong != null)
{
ulong num = ulong.Parse(inc_ulong);
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB playerScript in allPlayerScripts)
{
if (((NetworkBehaviour)playerScript).NetworkObjectId == num && (Object)(object)HUDManager.Instance != (Object)null && HUDManager.Instance.spectatingPlayerBoxes != null)
{
Animator key = HUDManager.Instance.spectatingPlayerBoxes.FirstOrDefault<KeyValuePair<Animator, PlayerControllerB>>((KeyValuePair<Animator, PlayerControllerB> x) => (Object)(object)x.Value == (Object)(object)playerScript).Key;
if ((Object)(object)key != (Object)null)
{
GameObject gameObject = ((Component)((Component)key).gameObject.transform.Find("HasVoted")).gameObject;
((Behaviour)gameObject.GetComponent<RawImage>()).enabled = true;
}
}
}
VotedClients[inc_ulong] = true;
}
else
{
WhoVoted.Logger.LogError((object)"Received null ulong, skipping");
}
}
[ServerRpc(RequireOwnership = false)]
public void ClearVotedServerRpc()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1817200921u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1817200921u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
VotedClients.Clear();
ClearVotedClientRpc();
}
}
}
[ClientRpc]
public void ClearVotedClientRpc()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2381302274u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2381302274u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
VotedClients.Clear();
}
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_WhoVotedNetworkHelper()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(4037720139u, new RpcReceiveHandler(__rpc_handler_4037720139));
NetworkManager.__rpc_func_table.Add(2933124034u, new RpcReceiveHandler(__rpc_handler_2933124034));
NetworkManager.__rpc_func_table.Add(1817200921u, new RpcReceiveHandler(__rpc_handler_1817200921));
NetworkManager.__rpc_func_table.Add(2381302274u, new RpcReceiveHandler(__rpc_handler_2381302274));
}
private static void __rpc_handler_4037720139(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string inc_ulong = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref inc_ulong, false);
}
target.__rpc_exec_stage = (__RpcExecStage)1;
((WhoVotedNetworkHelper)(object)target).SyncWhoVotedServerRpc(inc_ulong);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2933124034(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
bool flag = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
string inc_ulong = null;
if (flag)
{
((FastBufferReader)(ref reader)).ReadValueSafe(ref inc_ulong, false);
}
target.__rpc_exec_stage = (__RpcExecStage)2;
((WhoVotedNetworkHelper)(object)target).SyncWhoVotedClientRpc(inc_ulong);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1817200921(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = (__RpcExecStage)1;
((WhoVotedNetworkHelper)(object)target).ClearVotedServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2381302274(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
target.__rpc_exec_stage = (__RpcExecStage)2;
((WhoVotedNetworkHelper)(object)target).ClearVotedClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
protected internal override string __getTypeName()
{
return "WhoVotedNetworkHelper";
}
}
}
namespace DarthLilo.WhoVoted.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}