Decompiled source of STA DrunkCompany v1.0.3

BepInEx/plugins/sta.drunkcompany.dll

Decompiled 2 months ago
using System;
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.Logging;
using DrunkCompany.Scripts;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StaticNetcodeLib;
using Unity.Netcode;
using UnityEngine;

[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("sta.drunkcompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+10f4a40b90a5cfe21a1e4342236c66824b2e52a6")]
[assembly: AssemblyProduct("DrunkCompany")]
[assembly: AssemblyTitle("sta.drunkcompany")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 DrunkCompany
{
	[BepInPlugin("sta.drunkcompany", "DrunkCompany", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class DrunkCompany : BaseUnityPlugin
	{
		public static DrunkCompany 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;
			Patch();
			Logger.LogInfo((object)"sta.drunkcompany v1.0.3 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("sta.drunkcompany");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "sta.drunkcompany";

		public const string PLUGIN_NAME = "DrunkCompany";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}
namespace DrunkCompany.Scripts
{
	[StaticNetcode]
	internal class NetworkM : MonoBehaviour
	{
		internal static List<PlayerControllerB> currentPlayers = new List<PlayerControllerB>();

		private static int[] colors = new int[6] { 31, 30, 0, 32, 29, 33 };

		internal static List<string> deadPlayers = new List<string>();

		public static List<string> PosterFolders = new List<string>();

		[ServerRpc]
		public static void DetermineTeamsServerRpc()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			int randomSeed = Random.Range(1, 10000);
			deadPlayers.Clear();
			currentPlayers.Clear();
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			PlayerControllerB[] array = allPlayerScripts;
			foreach (PlayerControllerB val in array)
			{
				if (val.isPlayerControlled && !val.isPlayerDead)
				{
					currentPlayers.Add(val);
				}
			}
			currentPlayers = Shuffle(currentPlayers, randomSeed);
			NetworkBehaviourReference val2 = NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)currentPlayers[0]);
			ShowHudMessageClientRpc(val2);
			SetPlayerSuitClientRpc(val2, 34);
			List<PlayerControllerB> list = currentPlayers.Skip(1).ToList();
			List<List<PlayerControllerB>> groupList = GetGroupList(list, 2);
			if (groupList[0].Count <= 1)
			{
				for (int j = 0; j < groupList.Count; j++)
				{
					if (groupList[j].Count == 1 && j > 0)
					{
						PlayerControllerB item = groupList[j][0];
						groupList.Remove(groupList[j]);
						if (j - 1 >= 0)
						{
							groupList[j - 1].Add(item);
						}
						break;
					}
				}
			}
			for (int k = 0; k < groupList.Count; k++)
			{
				int suitID = colors[k % colors.Length];
				foreach (PlayerControllerB item2 in groupList[k])
				{
					NetworkBehaviourReference player = NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)item2);
					SetPlayerSuitClientRpc(player, suitID);
				}
			}
		}

		private static List<PlayerControllerB> Shuffle(List<PlayerControllerB> list, int randomSeed)
		{
			Random rng = new Random(randomSeed);
			return list.OrderBy((PlayerControllerB x) => rng.Next()).ToList();
		}

		private static List<List<PlayerControllerB>> GetGroupList(List<PlayerControllerB> list, int numInGroup)
		{
			if (list.Count <= numInGroup)
			{
				return new List<List<PlayerControllerB>> { list };
			}
			return (from x in list.Select((PlayerControllerB player, int index) => new { player, index })
				group x by x.index / numInGroup into @group
				select @group.Select(x => x.player).ToList()).ToList();
		}

		[ClientRpc]
		public static void DeathWarningClientRpc(int playerId)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerId];
			DrunkCompany.Logger.LogDebug((object)$"This is the playerID: {playerId} and this is the player from current players: {val.playerUsername}");
			if (deadPlayers.Count() == 0)
			{
				HUDManager.Instance.DisplayTip(val.playerUsername, "The first person to die!", true, false, "LC_Tip1");
				deadPlayers.Add(val.playerUsername);
			}
		}

		[ClientRpc]
		public static void ShowHudMessageClientRpc(NetworkBehaviourReference captain)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			PlayerControllerB val = (PlayerControllerB)NetworkBehaviourReference.op_Implicit(captain);
			HUDManager.Instance.DisplayTip("The captain is", val.playerUsername ?? "", false, false, "LC_Tip1");
		}

		[ClientRpc]
		public static void SetPlayerSuitClientRpc(NetworkBehaviourReference player, int suitID)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			PlayerControllerB val = (PlayerControllerB)NetworkBehaviourReference.op_Implicit(player);
			Material suitMaterial = StartOfRound.Instance.unlockablesList.unlockables[suitID].suitMaterial;
			((Renderer)val.thisPlayerModel).material = suitMaterial;
			((Renderer)val.thisPlayerModelLOD1).material = suitMaterial;
			((Renderer)val.thisPlayerModelLOD2).material = suitMaterial;
			((Renderer)val.thisPlayerModelArms).material = suitMaterial;
			val.currentSuitID = suitID;
			DrunkCompany.Logger.LogDebug((object)$"This is the suitID: {suitID} and this is the player: {val}");
			deadPlayers.Clear();
		}
	}
}
namespace DrunkCompany.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("KillPlayerServerRpc")]
		[HarmonyPostfix]
		public static void SendingDeathWarning(ref int playerId)
		{
			DrunkCompany.Logger.LogDebug((object)$"This is the playerId from serverDeathWarning: {playerId}");
			NetworkM.DeathWarningClientRpc(playerId);
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartMatchLeverPatch
	{
		[HarmonyPatch("ResetStats")]
		[HarmonyPostfix]
		public static void SendingMessagePatch()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				NetworkM.DetermineTeamsServerRpc();
			}
		}
	}
	[HarmonyPatch(typeof(UnlockableSuit))]
	internal class UnlockableSuitPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitForPlayer")]
		private static bool SuppressCallIfNeeded(PlayerControllerB player, int suitID)
		{
			DrunkCompany.Logger.LogMessage((object)$"this function has ran {suitID}");
			return false;
		}
	}
}