Decompiled source of LycanVoteMode v1.0.1

plugins/LycanVoteMode/LycanVoteMode.dll

Decompiled 2 days ago
using System;
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.Logging;
using Fusion;
using LycanVoteMode.Patch;
using Microsoft.CodeAnalysis;
using On;
using UnityEngine;
using UnityEngine.Scripting;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("LycanVoteMode")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LycanVoteMode")]
[assembly: AssemblyTitle("LycanVoteMode")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LycanVoteMode
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInPlugin("RedTenZ.LycanVoteMode", "LycanVoteMode", "1.0.0")]
	[BepInProcess("Lycans.exe")]
	public class LycanVoteMode : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "RedTenZ.LycanVoteMode";

		public const string PLUGIN_AUTHOR = "RedTenZ";

		public const string PLUGIN_NAME = "LycanVoteMode";

		public const string PLUGIN_VERSION = "1.0.0";

		private void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Log.Info("Plugin LycanVoteMode version 1.0.0 loaded successfully!");
			VotePatch.Patch();
			Log.Info("CancelVotePatch applied successfully!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LycanVoteMode";

		public const string PLUGIN_NAME = "LycanVoteMode";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LycanVoteMode.Patch
{
	[NetworkBehaviourWeaved(20)]
	public class CancelVoteRPC : NetworkBehaviour
	{
		[Rpc]
		public unsafe static void Rpc_RequestCancelVote(NetworkRunner runner, int playerIndex)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (NetworkBehaviourUtils.InvokeRpc)
				{
					NetworkBehaviourUtils.InvokeRpc = false;
				}
				else
				{
					if ((Object)(object)runner == (Object)null)
					{
						throw new ArgumentNullException("runner");
					}
					if ((int)runner.Stage == 4)
					{
						return;
					}
					if (runner.HasAnyActiveConnections())
					{
						int num = 24;
						SimulationMessage* ptr = SimulationMessage.Allocate(runner.Simulation, num);
						byte* data = SimulationMessage.GetData(ptr);
						int num2 = RpcHeader.Write(RpcHeader.Create(NetworkBehaviourUtils.GetRpcStaticIndexOrThrow("System.Void LycansModTemplate.Patch.CancelVoteRPC::Rpc_RequestCancelVote(Fusion.NetworkRunner,System.Int32)")), data);
						*(int*)(data + num2) = playerIndex;
						num2 += 4;
						((SimulationMessage)ptr).Offset = num2 * 8;
						((SimulationMessage)ptr).SetStatic();
						runner.SendRpc(ptr);
					}
				}
				Execute(playerIndex);
			}
			catch (Exception ex)
			{
				string text = "Rpc_CancelVote error: ";
				Log.Info(text + ex);
			}
		}

		[NetworkRpcStaticWeavedInvoker("System.Void LycansModTemplate.Patch.CancelVoteRPC::Rpc_RequestCancelVote(Fusion.NetworkRunner,System.Int32)")]
		[Preserve]
		protected unsafe static void Rpc_RequestCancelVote_0040Invoker(NetworkRunner runner, SimulationMessage* message)
		{
			byte* data = SimulationMessage.GetData(message);
			int num = (RpcHeader.ReadSize(data) + 3) & -4;
			int playerIndex = *(int*)(data + num);
			num += 4;
			NetworkBehaviourUtils.InvokeRpc = true;
			Rpc_RequestCancelVote(runner, playerIndex);
		}

		public static void Execute(int playerId)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Log.Info($"CancelVoteRPC.Execute called for player {playerId}");
			PlayerController player = PlayerRegistry.GetPlayer(PlayerRef.op_Implicit(playerId));
			if (!((Object)(object)player == (Object)null) && player.IdVoted != -1)
			{
				if (((SimulationBehaviour)player).HasStateAuthority)
				{
					GameManager.Instance.gameUI.ShowSkipVote(true);
				}
				player.IdVoted = -1;
				player.UpdateVoting(false);
			}
		}
	}
	internal class VotePatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Interact <0>__PlayerController_Interact;

			public static hook_OnVoteChanged <1>__PlayerController_OnVoteChanged;
		}

		public static void Patch()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			object obj = <>O.<0>__PlayerController_Interact;
			if (obj == null)
			{
				hook_Interact val = PlayerController_Interact;
				<>O.<0>__PlayerController_Interact = val;
				obj = (object)val;
			}
			PlayerController.Interact += (hook_Interact)obj;
			object obj2 = <>O.<1>__PlayerController_OnVoteChanged;
			if (obj2 == null)
			{
				hook_OnVoteChanged val2 = PlayerController_OnVoteChanged;
				<>O.<1>__PlayerController_OnVoteChanged = val2;
				obj2 = (object)val2;
			}
			PlayerController.OnVoteChanged += (hook_OnVoteChanged)obj2;
		}

		private static void PlayerController_OnVoteChanged(orig_OnVoteChanged orig, Changed<PlayerController> changed)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			PlayerController behaviour = changed.Behaviour;
			orig.Invoke(changed);
			PlayerRegistry.Where((Predicate<PlayerController>)((PlayerController p) => !NetworkBool.op_Implicit(p.IsDead))).ToList().ForEach(delegate(PlayerController p)
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				int count2 = PlayerRegistry.Where((Predicate<PlayerController>)delegate(PlayerController v)
				{
					//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)
					int idVoted = v.IdVoted;
					PlayerRef @ref = p.Ref;
					return idVoted == ((PlayerRef)(ref @ref)).PlayerId;
				}).ToList().Count;
				GameManager.Instance.gameUI.UpdatePlayerVotesCount(p.Ref, count2);
			});
			int count = PlayerRegistry.Where((Predicate<PlayerController>)((PlayerController p) => !NetworkBool.op_Implicit(p.IsDead) && p.IdVoted == -2)).ToList().Count;
			GameManager.Instance.gameUI.UpdateSkippedVotesCount(count);
		}

		private static void PlayerController_Interact(orig_Interact orig, PlayerController self, bool isPrimary)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameManager.State.Current == 4 && isPrimary)
			{
				TickTimer voteTimer = GameManager.Instance.VoteTimer;
				float valueOrDefault = ((TickTimer)(ref voteTimer)).RemainingTime(((SimulationBehaviour)GameManager.Instance).Runner).GetValueOrDefault();
				if (valueOrDefault > 10f && self.IdVoted != -1)
				{
					NetworkRunner runner = ((SimulationBehaviour)GameManager.Instance).Runner;
					PlayerRef @ref = self.Ref;
					CancelVoteRPC.Rpc_RequestCancelVote(runner, ((PlayerRef)(ref @ref)).PlayerId);
					return;
				}
			}
			orig.Invoke(self, isPrimary);
		}
	}
	internal class DelayStatePatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Server_DelaySetState <0>__GameState_Server_DelaySetState;
		}

		public static void Patch()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			object obj = <>O.<0>__GameState_Server_DelaySetState;
			if (obj == null)
			{
				hook_Server_DelaySetState val = GameState_Server_DelaySetState;
				<>O.<0>__GameState_Server_DelaySetState = val;
				obj = (object)val;
			}
			GameState.Server_DelaySetState += (hook_Server_DelaySetState)obj;
		}

		private static void GameState_Server_DelaySetState(orig_Server_DelaySetState orig, GameState self, EGameState newState, float delay)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if ((int)GameManager.State.Current == 4)
			{
				Log.Info("[DelayStatePatch] Bloqué le changement d'état pendant le Meeting");
			}
			else
			{
				orig.Invoke(self, newState, delay);
			}
		}
	}
	internal class EndGamePatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Rpc_EndGame <0>__GameManager_Rpc_EndGame;
		}

		public static void Patch()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			object obj = <>O.<0>__GameManager_Rpc_EndGame;
			if (obj == null)
			{
				hook_Rpc_EndGame val = GameManager_Rpc_EndGame;
				<>O.<0>__GameManager_Rpc_EndGame = val;
				obj = (object)val;
			}
			GameManager.Rpc_EndGame += (hook_Rpc_EndGame)obj;
		}

		private static void GameManager_Rpc_EndGame(orig_Rpc_EndGame orig, NetworkRunner runner, bool wolfWin)
		{
			Log.Info("[EndGamePatch] Rpc_EndGame bloqué. Rien ne sera exécuté.");
		}
	}
}