Decompiled source of JesterUs v1.0.3

JesterUs.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using InnerNet;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("JesterUs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("JesterUs")]
[assembly: AssemblyTitle("JesterUs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 JesterUs
{
	public static class JesterManager
	{
		public static byte JesterId { get; private set; } = byte.MaxValue;


		public static bool IsJester(byte playerId)
		{
			if (JesterId != byte.MaxValue)
			{
				return playerId == JesterId;
			}
			return false;
		}

		public static bool IsJester(PlayerControl player)
		{
			return IsJester(player.PlayerId);
		}

		public static void SetJester(byte playerId)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			JesterId = playerId;
			ManualLogSource log = JesterUsPlugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[JesterUs] Spieler-ID ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<byte>(playerId);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ist der Jester.");
			}
			log.LogInfo(val);
		}

		public static void Reset()
		{
			JesterId = byte.MaxValue;
		}

		public static void AssignJester()
		{
			Reset();
			List<byte> list = new List<byte>();
			for (int i = 0; i < GameData.Instance.AllPlayers.Count; i++)
			{
				NetworkedPlayerInfo val = GameData.Instance.AllPlayers[i];
				if (!val.Disconnected && (Object)(object)val.Role != (Object)null && !val.Role.IsImpostor)
				{
					list.Add(val.PlayerId);
				}
			}
			if (list.Count == 0)
			{
				JesterUsPlugin.Log.LogWarning((object)"[JesterUs] Keine Crewmate-Kandidaten für Jester gefunden!");
				return;
			}
			int num = list.Count * 31;
			foreach (byte item in list)
			{
				num ^= item * 17;
			}
			Random random = new Random(num);
			SetJester(list[random.Next(list.Count)]);
		}
	}
	[HarmonyPatch(typeof(RoleManager), "SelectRoles")]
	public static class RoleAssignPatch
	{
		public static void Postfix()
		{
			JesterManager.AssignJester();
		}
	}
	[HarmonyPatch(typeof(IntroCutscene), "CoBegin")]
	public static class IntroPatch
	{
		[HarmonyPatch(typeof(AmongUsClient), "OnGameJoined")]
		public static class ResetIntroPatch
		{
			public static void Postfix()
			{
			}
		}

		public static void Postfix(IntroCutscene __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			if (JesterManager.IsJester(PlayerControl.LocalPlayer))
			{
				Color32 val = default(Color32);
				((Color32)(ref val))..ctor((byte)115, (byte)0, (byte)216, byte.MaxValue);
				if ((Object)(object)__instance.TeamTitle != (Object)null)
				{
					((TMP_Text)__instance.TeamTitle).text = "Jester";
					((Graphic)__instance.TeamTitle).color = Color32.op_Implicit(val);
				}
				if ((Object)(object)__instance.ImpostorText != (Object)null)
				{
					((TMP_Text)__instance.ImpostorText).text = "Lass dich rausvoten um zu gewinnen!";
				}
				if ((Object)(object)__instance.BackgroundBar != (Object)null)
				{
					((Renderer)__instance.BackgroundBar).material.color = Color32.op_Implicit(val);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ExileController), "Begin")]
	public static class ExilePatch
	{
		public static bool JesterWon;

		public static void Postfix([HarmonyArgument(0)] NetworkedPlayerInfo? exiled)
		{
			if (((InnerNetClient)AmongUsClient.Instance).AmHost && !((Object)(object)exiled == (Object)null) && JesterManager.IsJester(exiled.PlayerId))
			{
				JesterUsPlugin.Log.LogInfo((object)"[JesterUs] Jester wurde rausgevoted → Jester gewinnt!");
				JesterWon = true;
				GameManager.Instance.RpcEndGame((GameOverReason)100, false);
			}
		}
	}
	[HarmonyPatch(typeof(EndGameManager), "Start")]
	public static class EndGamePatch
	{
		public static void Postfix(EndGameManager __instance)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (ExilePatch.JesterWon)
			{
				ExilePatch.JesterWon = false;
				Color32 val = default(Color32);
				((Color32)(ref val))..ctor((byte)115, (byte)0, (byte)216, byte.MaxValue);
				((TMP_Text)__instance.WinText).text = "Jester gewinnt!";
				((Graphic)__instance.WinText).color = Color32.op_Implicit(val);
				((Renderer)__instance.BackgroundBar).material.color = Color32.op_Implicit(val);
			}
		}
	}
	[BepInPlugin("com.icystudios.jesterus", "JesterUs", "1.0.1")]
	public class JesterUsPlugin : BasePlugin
	{
		public const string Id = "com.icystudios.jesterus";

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


		internal static Harmony Harmony { get; } = new Harmony("com.icystudios.jesterus");


		public override void Load()
		{
			Log = ((BasePlugin)this).Log;
			Harmony.PatchAll();
			Log.LogInfo((object)"JesterUs v1.0.0 geladen!");
		}
	}
}