Decompiled source of Double Trouble v1.0.0

DoubleTrouble.dll

Decompiled 6 months ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DoubleTrouble.Behaviors;
using DoubleTrouble.NetcodePatcher;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sehelitar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Sehelitar @ https://sehelitar.tv")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3cad7d97011d8a4730c16d0223aafecbc6b36250")]
[assembly: AssemblyProduct("DoubleTrouble")]
[assembly: AssemblyTitle("DoubleTrouble")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 DoubleTrouble
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Locale
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("DoubleTrouble.Locale", typeof(Locale).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static string LandingInfoDiff => ResourceManager.GetString("LandingInfoDiff", resourceCulture);

		internal static string LandingInfoOverall => ResourceManager.GetString("LandingInfoOverall", resourceCulture);

		internal static string ResultLose => ResourceManager.GetString("ResultLose", resourceCulture);

		internal static string ResultWin => ResourceManager.GetString("ResultWin", resourceCulture);

		internal static string SpectateResultLose => ResourceManager.GetString("SpectateResultLose", resourceCulture);

		internal static string SpectateResultWin => ResourceManager.GetString("SpectateResultWin", resourceCulture);

		internal static string Title => ResourceManager.GetString("Title", resourceCulture);

		internal Locale()
		{
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Locale_fr
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("DoubleTrouble.Locale.fr", typeof(Locale_fr).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static string LandingInfoDiff => ResourceManager.GetString("LandingInfoDiff", resourceCulture);

		internal static string LandingInfoOverall => ResourceManager.GetString("LandingInfoOverall", resourceCulture);

		internal static string ResultLose => ResourceManager.GetString("ResultLose", resourceCulture);

		internal static string ResultWin => ResourceManager.GetString("ResultWin", resourceCulture);

		internal static string SpectateResultLose => ResourceManager.GetString("SpectateResultLose", resourceCulture);

		internal static string SpectateResultWin => ResourceManager.GetString("SpectateResultWin", resourceCulture);

		internal static string Title => ResourceManager.GetString("Title", resourceCulture);

		internal Locale_fr()
		{
		}
	}
	[BepInPlugin("DoubleTrouble", "DoubleTrouble", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private static Harmony _globalHarmony;

		internal static ManualLogSource Log { get; private set; }

		internal static PluginConfigStruct GameConfig { get; private set; }

		private void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin DoubleTrouble is loaded!");
			PatchNetwork();
			_globalHarmony = new Harmony("DoubleTrouble");
			_globalHarmony.PatchAll();
			PluginConfigStruct gameConfig = default(PluginConfigStruct);
			gameConfig.DoubleTroubleEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("DoubleTrouble", "Enable", true, "Active l'évènement du \"quitte ou double\".");
			gameConfig.DoubleTroubleProbability = ((BaseUnityPlugin)this).Config.Bind<double>("DoubleTrouble", "Probability", 20.0, "Pourcentage de change qu'un évènement \"quitte ou double\" se lance (entre 0 et 100).");
			gameConfig.DoubleTroubleOverall = ((BaseUnityPlugin)this).Config.Bind<bool>("DoubleTrouble", "Overall", true, "Si activé, le quitte ou double se basera sur le nombre total de crédits au lieu de ce qui vient d'être vendu.");
			GameConfig = gameConfig;
		}

		private static void PatchNetwork()
		{
			try
			{
				Type[] types = Assembly.GetExecutingAssembly().GetTypes();
				foreach (Type type in types)
				{
					MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
						{
							Log.LogInfo((object)("Initialize network patch for " + type.FullName));
							methodInfo.Invoke(null, null);
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
	internal struct PluginConfigStruct
	{
		public ConfigEntry<bool> DoubleTroubleEnable;

		public ConfigEntry<double> DoubleTroubleProbability;

		public ConfigEntry<bool> DoubleTroubleOverall;
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DoubleTrouble";

		public const string PLUGIN_NAME = "DoubleTrouble";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DoubleTrouble.Patches
{
	[HarmonyPatch(typeof(DepositItemsDesk))]
	public class DepositItemsDeskPatch
	{
		[HarmonyPatch("SellAndDisplayItemProfits")]
		[HarmonyPostfix]
		private static void SellAndDisplayItemProfits(int profit)
		{
			DoubleTroubleService instance = DoubleTroubleService.Instance;
			if (instance != null && instance.IsActive)
			{
				DoubleTroubleService.Instance.SoldAmount += profit;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		private static void StartOfRoundStartGame()
		{
			DoubleTroubleService.Instance?.BeginEvent();
		}

		[HarmonyPatch("ShipLeave")]
		[HarmonyPostfix]
		private static void StartOfRoundShipLeave()
		{
			DoubleTroubleService.Instance?.EndEvent();
		}

		[HarmonyPatch("ShipLeaveAutomatically")]
		[HarmonyPostfix]
		private static void StartOfRoundShipLeaveAutomatically()
		{
			DoubleTroubleService.Instance?.EndEvent();
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void TerminalAwake(ref Terminal __instance)
		{
			((Component)__instance).gameObject.AddComponent<DoubleTroubleService>();
		}
	}
}
namespace DoubleTrouble.Behaviors
{
	[RequireComponent(typeof(Terminal))]
	internal class DoubleTroubleService : NetworkBehaviour
	{
		public bool IsActive { get; private set; }

		public bool IsOverall { get; private set; } = true;


		public bool ProbabilityOverride { get; set; }

		public int SoldAmount { get; internal set; }

		public static DoubleTroubleService Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		internal void BeginEvent()
		{
			if (((NetworkBehaviour)this).IsServer && Plugin.GameConfig.DoubleTroubleEnable.Value && !RoundManager.Instance.currentLevel.planetHasTime && (ProbabilityOverride || ShouldLaunchEvent()))
			{
				IsActive = true;
				IsOverall = Plugin.GameConfig.DoubleTroubleOverall.Value;
				ProbabilityOverride = false;
				SoldAmount = 0;
				AnnounceEventClientRpc(IsOverall);
			}
		}

		private static bool ShouldLaunchEvent()
		{
			double value = Plugin.GameConfig.DoubleTroubleProbability.Value;
			return (double)Random.RandomRangeInt(0, 100) <= value;
		}

		internal void EndEvent()
		{
			if (!((NetworkBehaviour)this).IsServer || !IsActive)
			{
				return;
			}
			IsActive = false;
			bool flag = (double)Random.Range(0f, 1f) >= 0.5;
			Terminal component = ((Component)this).GetComponent<Terminal>();
			bool value = Plugin.GameConfig.DoubleTroubleOverall.Value;
			int groupCredits = component.groupCredits;
			if (value)
			{
				if (flag)
				{
					component.groupCredits *= 2;
				}
				else
				{
					component.groupCredits /= 2;
				}
			}
			else if (flag)
			{
				component.groupCredits += SoldAmount;
			}
			else
			{
				component.groupCredits -= Convert.ToInt32((float)SoldAmount / 2f);
			}
			AnnounceResultClientRpc(groupCredits, component.groupCredits);
		}

		[ClientRpc]
		private void AnnounceEventClientRpc(bool isOverall)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1055199686u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref isOverall, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1055199686u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip(Locale.Title, isOverall ? Locale.LandingInfoOverall : Locale.LandingInfoDiff, false, false, "LC_Tip1");
				}
			}
		}

		[ClientRpc]
		private void AnnounceResultClientRpc(int amountBefore, int amountAfter)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2420471262u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, amountBefore);
				BytePacker.WriteValueBitPacked(val2, amountAfter);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2420471262u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				((Component)this).GetComponent<Terminal>().groupCredits = amountAfter;
				HUDManager instance = HUDManager.Instance;
				if (instance != null)
				{
					instance.DisplayTip(Locale.Title, (amountBefore > amountAfter) ? string.Format(Locale.ResultLose, amountAfter - amountBefore) : string.Format(Locale.ResultWin, amountAfter - amountBefore), false, false, "LC_Tip1");
				}
				HUDManager instance2 = HUDManager.Instance;
				if (instance2 != null)
				{
					instance2.DisplaySpectatorTip((amountBefore > amountAfter) ? string.Format(Locale.SpectateResultLose, amountAfter - amountBefore) : string.Format(Locale.SpectateResultWin, amountAfter - amountBefore));
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_DoubleTroubleService()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1055199686u, new RpcReceiveHandler(__rpc_handler_1055199686));
			NetworkManager.__rpc_func_table.Add(2420471262u, new RpcReceiveHandler(__rpc_handler_2420471262));
		}

		private static void __rpc_handler_1055199686(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool isOverall = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref isOverall, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((DoubleTroubleService)(object)target).AnnounceEventClientRpc(isOverall);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2420471262(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int amountBefore = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amountBefore);
				int amountAfter = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amountAfter);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((DoubleTroubleService)(object)target).AnnounceResultClientRpc(amountBefore, amountAfter);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "DoubleTroubleService";
		}
	}
}
namespace DoubleTrouble.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}