Decompiled source of NoMoreControlCompany v1.0.0

NoMoreControlCompany/NoMoreControlCompany.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Steamworks.Data;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NoMoreControlCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("NoMoreControlCompany")]
[assembly: AssemblyCopyright("Copyright © HP 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f6e56950-dfe2-4ca4-8123-966b7a30b09a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.nomorecontrolcompanymod", "Control Company Mod", "1.0.0")]
[BepInProcess("Lethal Company.exe")]
public class ControlCompanyMod : BaseUnityPlugin
{
	internal static class Patcher
	{
		internal static void ApplyPatches(Harmony harmony)
		{
			harmony.PatchAll(Assembly.GetExecutingAssembly());
		}
	}

	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnPlayerConnectedClientRpc")]
		private static void PatchOnPlayerConnected()
		{
			CoroutineManager.StartCoroutine(Detector.StartDetection());
		}
	}

	[HarmonyPatch(typeof(MenuManager))]
	[HarmonyPatch("Awake")]
	private class AwakePatch
	{
		public static bool SendNotification { get; set; } = true;


		private static void Postfix()
		{
			SendNotification = true;
		}
	}

	internal static class Detector
	{
		private static bool SendFalseNotification = true;

		public static IEnumerator StartDetection()
		{
			yield return (object)new WaitForSeconds(1f);
			if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
			{
				yield break;
			}
			string lobbyName = GameNetworkManager.Instance.steamLobbyName;
			if (lobbyName != null)
			{
				if (Enumerable.Contains(lobbyName, '\u200b') && AwakePatch.SendNotification)
				{
					SendUITip("WARNING:", "The host is using Control Company", warning: true);
					AwakePatch.SendNotification = false;
				}
				else if (SendFalseNotification && AwakePatch.SendNotification)
				{
					SendUITip("INFO:", "The host is not using Control Company", warning: false);
					AwakePatch.SendNotification = false;
				}
			}
		}

		internal static void SendUITip(string header, string message, bool warning)
		{
			HUDManager instance = HUDManager.Instance;
			if (instance != null)
			{
				instance.DisplayTip(header, message, warning, false, "LC_Tip1");
			}
		}
	}

	internal static class CoroutineManager
	{
		internal class CoroutineManagerBehaviour : MonoBehaviour
		{
		}

		private static MonoBehaviour _instance;

		private static MonoBehaviour instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_instance == (Object)null)
				{
					_instance = (MonoBehaviour)(object)new GameObject("CoroutineManager").AddComponent<CoroutineManagerBehaviour>();
				}
				return _instance;
			}
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			MonoBehaviour obj = instance;
			return ((obj != null) ? obj.StartCoroutine(routine) : null) ?? throw new Exception("CoroutineManager instance is null");
		}
	}

	[HarmonyPatch(typeof(SteamLobbyManager))]
	[HarmonyPatch("loadLobbyListAndFilter")]
	internal class LobbyListPatch
	{
		internal static readonly MethodInfo LoadLobbyListAndFilterMethod = AccessTools.Method(typeof(SteamLobbyManager), "loadLobbyListAndFilter", (Type[])null, (Type[])null);

		[HarmonyPrefix]
		private static void ModifyLobbyNames(ref Lobby[] ___currentLobbyList)
		{
			//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)
			for (int i = 0; i < ___currentLobbyList.Length; i++)
			{
				Lobby val = ___currentLobbyList[i];
				string text = ((Lobby)(ref val)).GetData("name");
				if (Enumerable.Contains(text, '\u200b'))
				{
					if (text.Contains("[MODDED]"))
					{
						text = text.Replace("[MODDED]", "[CC + MODDED]");
					}
					else if (!text.Contains("[CC]"))
					{
						text = "[CC] " + text;
					}
					((Lobby)(ref val)).SetData("name", text);
				}
			}
		}
	}

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony harmony = new Harmony("com.nomorecontrolcompanymod");
		Patcher.ApplyPatches(harmony);
	}
}