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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0a1f15cca836a345a8ee85de4751c0e93e005d51")]
[assembly: AssemblyProduct("DrunkCompany")]
[assembly: AssemblyTitle("sta.drunkcompany")]
[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 DrunkCompany
{
[BepInPlugin("sta.drunkcompany", "DrunkCompany", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DrunkCompany : BaseUnityPlugin
{
private const string GUID = "sta.drunkcompany";
private const string NAME = "DrunkCompany";
private const string VERSION = "1.0.0";
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.0 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.0";
}
}
namespace DrunkCompany.Scripts
{
[StaticNetcode]
internal class NetworkManager : MonoBehaviour
{
internal static List<PlayerControllerB> currentPlayers = new List<PlayerControllerB>();
private static List<int> colors = new List<int> { 28, 29, 32, 30, 31, 0 };
internal static List<string> deadPlayers = new List<string>();
public static List<string> PosterFolders = new List<string>();
[ClientRpc]
public static void ShowHudMessageClientRpc(string name)
{
HUDManager.Instance.DisplayTip("The captain is", name ?? "", false, false, "LC_Tip1");
}
public static void DetermineTeams()
{
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);
PlayerControllerB val2 = currentPlayers[0];
ShowHudMessageClientRpc(val2.playerUsername);
SetPlayerSuit(val2, 33);
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.Count];
foreach (PlayerControllerB item2 in groupList[k])
{
SetPlayerSuit(item2, suitID);
}
}
}
private static List<PlayerControllerB> Shuffle(List<PlayerControllerB> list)
{
Random rng = new Random();
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 = currentPlayers[playerId];
if (deadPlayers.Count() == 0)
{
HUDManager.Instance.DisplayTip(val.playerUsername, "The first person to die!", true, false, "LC_Tip1");
deadPlayers.Add(val.playerUsername);
}
}
public static void SetPlayerSuit(PlayerControllerB player, int suitID)
{
Material suitMaterial = StartOfRound.Instance.unlockablesList.unlockables[suitID].suitMaterial;
((Renderer)player.thisPlayerModel).material = suitMaterial;
((Renderer)player.thisPlayerModelLOD1).material = suitMaterial;
((Renderer)player.thisPlayerModelLOD2).material = suitMaterial;
((Renderer)player.thisPlayerModelArms).material = suitMaterial;
player.currentSuitID = suitID;
}
}
}
namespace DrunkCompany.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("KillPlayerServerRpc")]
[HarmonyPrefix]
public static void SendingDeathWarning(ref int playerId)
{
NetworkManager.DeathWarningClientRpc(playerId);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartMatchLeverPatch
{
[HarmonyPatch("ResetStats")]
[HarmonyPrefix]
public static void SendingMessagePatch()
{
NetworkManager.DetermineTeams();
}
}
[HarmonyPatch(typeof(UnlockableSuit))]
internal class UnlockableSuitPatch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitForPlayer")]
private static bool SuppressCallIfNeeded(PlayerControllerB player, int suitID)
{
return false;
}
}
}