Decompiled source of LateCompany v1.0.18

BepInEx/plugins/LateCompanyV1.0.17.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("LateCompany")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+394f6e913ae93b8bc416d40547f3b1a710f49a92")]
[assembly: AssemblyProduct("LateCompany")]
[assembly: AssemblyTitle("LateCompany")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 LateCompany
{
	public static class PluginInfo
	{
		public const string GUID = "twig.latecompany";

		public const string PrintName = "Late Company";

		public const string Version = "1.0.17";
	}
	[BepInPlugin("twig.latecompany", "Late Company", "1.0.17")]
	internal class Plugin : BaseUnityPlugin
	{
		public static bool LobbyJoinable = true;

		public void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("twig.latecompany");
			val.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.Log((LogLevel)16, (object)"Late Company loaded!");
		}

		public static void SetLobbyJoinable(bool joinable)
		{
			LobbyJoinable = joinable;
			GameNetworkManager.Instance.SetLobbyJoinable(joinable);
			QuickMenuManager val = Object.FindObjectOfType<QuickMenuManager>();
			if (Object.op_Implicit((Object)(object)val))
			{
				val.inviteFriendsTextAlpha.alpha = (joinable ? 1f : 0.2f);
			}
		}
	}
}
namespace LateCompany.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager), "LeaveLobbyAtGameStart")]
	[HarmonyWrapSafe]
	internal static class LeaveLobbyAtGameStart_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "ConnectionApproval")]
	[HarmonyWrapSafe]
	internal static class ConnectionApproval_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(ref ConnectionApprovalRequest request, ref ConnectionApprovalResponse response)
		{
			if (request.ClientNetworkId != NetworkManager.Singleton.LocalClientId && Plugin.LobbyJoinable && response.Reason == "Game has already started!")
			{
				response.Reason = "";
				response.Approved = true;
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "DisableInviteFriendsButton")]
	internal static class DisableInviteFriendsButton_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return false;
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "InviteFriendsButton")]
	internal static class InviteFriendsButton_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			if (Plugin.LobbyJoinable && !GameNetworkManager.Instance.disableSteam)
			{
				GameNetworkManager.Instance.InviteFriendsUI();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerConnectedClientRpc")]
	[HarmonyWrapSafe]
	internal static class OnPlayerConnectedClientRpc_Patch
	{
		internal static void UpdateControlledState()
		{
			for (int i = 0; i < StartOfRound.Instance.connectedPlayersAmount + 1; i++)
			{
				if ((i == 0 || !((NetworkBehaviour)StartOfRound.Instance.allPlayerScripts[i]).IsOwnedByServer) && !StartOfRound.Instance.allPlayerScripts[i].isPlayerDead)
				{
					StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled = true;
				}
			}
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>();
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			foreach (CodeInstruction instruction in instructions)
			{
				if (!flag3)
				{
					if (!flag && instruction.opcode == OpCodes.Call && instruction.operand != null && instruction.operand.ToString() == "System.Collections.IEnumerator setPlayerToSpawnPosition(UnityEngine.Transform, UnityEngine.Vector3)")
					{
						flag = true;
					}
					else
					{
						if (flag && instruction.opcode == OpCodes.Ldc_I4_0)
						{
							flag2 = true;
							continue;
						}
						if (flag2 && instruction.opcode == OpCodes.Ldloc_0)
						{
							flag2 = false;
							flag3 = true;
							list.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(OnPlayerConnectedClientRpc_Patch), "UpdateControlledState", new Type[0], (Type[])null)));
						}
					}
				}
				if (!flag2)
				{
					list.Add(instruction);
				}
			}
			if (!flag3)
			{
				Debug.LogError((object)"Failed to transpile StartOfRound::OnPlayerConnectedClientRpc");
			}
			return list.AsEnumerable();
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			if (StartOfRound.Instance.connectedPlayersAmount + 1 >= StartOfRound.Instance.allPlayerScripts.Length)
			{
				Plugin.SetLobbyJoinable(joinable: false);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
	[HarmonyWrapSafe]
	internal static class OnPlayerDC_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(int playerObjectNumber)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if (StartOfRound.Instance.inShipPhase)
			{
				Plugin.SetLobbyJoinable(joinable: true);
			}
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObjectNumber];
			val.activatingItem = false;
			val.bleedingHeavily = false;
			val.clampLooking = false;
			val.criticallyInjured = false;
			val.Crouch(false);
			val.disableInteract = false;
			val.DisableJetpackControlsLocally();
			val.disableLookInput = false;
			val.disableMoveInput = false;
			val.DisablePlayerModel(((Component)val).gameObject, true, true);
			val.disableSyncInAnimation = false;
			val.externalForceAutoFade = Vector3.zero;
			val.freeRotationInInteractAnimation = false;
			val.hasBeenCriticallyInjured = false;
			val.health = 100;
			((Behaviour)val.helmetLight).enabled = false;
			val.holdingWalkieTalkie = false;
			val.inAnimationWithEnemy = null;
			val.inShockingMinigame = false;
			val.inSpecialInteractAnimation = false;
			val.inVehicleAnimation = false;
			val.isClimbingLadder = false;
			val.isSinking = false;
			val.isUnderwater = false;
			Animator mapRadarDotAnimator = val.mapRadarDotAnimator;
			if (mapRadarDotAnimator != null)
			{
				mapRadarDotAnimator.SetBool("dead", false);
			}
			Animator playerBodyAnimator = val.playerBodyAnimator;
			if (playerBodyAnimator != null)
			{
				playerBodyAnimator.SetBool("Limp", false);
			}
			val.ResetZAndXRotation();
			val.sinkingValue = 0f;
			val.speakingToWalkieTalkie = false;
			AudioSource statusEffectAudio = val.statusEffectAudio;
			if (statusEffectAudio != null)
			{
				statusEffectAudio.Stop();
			}
			((Collider)val.thisController).enabled = true;
			((Component)val).transform.SetParent(StartOfRound.Instance.playersContainer);
			val.twoHanded = false;
			val.voiceMuffledByEnemy = false;
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "SetShipReadyToLand")]
	internal static class SetShipReadyToLand_Patch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			if (StartOfRound.Instance.connectedPlayersAmount + 1 < StartOfRound.Instance.allPlayerScripts.Length)
			{
				Plugin.SetLobbyJoinable(joinable: true);
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "StartGame")]
	internal static class StartGame_Patch
	{
		[HarmonyPrefix]
		private static void Prefix()
		{
			Plugin.SetLobbyJoinable(joinable: false);
		}
	}
}