Decompiled source of Fix Playercount v1.2.3

FixPlayercount.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using MonoMod.RuntimeDetour;
using Multitudes;
using On.RoR2;
using R2API.Utils;
using RoR2;
using TPDespair.ZetArtifacts;

[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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FixPlayercount")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FixPlayercount")]
[assembly: AssemblyTitle("FixPlayercount")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FixPlayercount;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Moffein.FixPlayercount", "Fix Playercount", "1.2.2")]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class FixPlayercount : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static hook_Start <>9__4_0;

		internal void <Awake>b__4_0(orig_Start orig, Stage self)
		{
			stageMaxPlayers = 0;
			orig.Invoke(self);
		}
	}

	private static bool MultitudesLoaded = false;

	private static bool ZetArtifactsLoaded = false;

	public static bool UpdateOnStageStart = false;

	public static int stageMaxPlayers = 0;

	public void Awake()
	{
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//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)
		//IL_0085: Expected O, but got Unknown
		UpdateOnStageStart = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Update on Stage Start", false, "Only update playerount on stage start. This will make it so that the game will ignore player disconnects and will use the maximum connected players during the stage to determine difficulty/item drop calculations.").Value;
		if (Chainloader.PluginInfos.ContainsKey("dev.wildbook.multitudes"))
		{
			MultitudesLoaded = true;
		}
		if (Chainloader.PluginInfos.ContainsKey("com.TPDespair.ZetArtifacts"))
		{
			ZetArtifactsLoaded = true;
		}
		if (UpdateOnStageStart)
		{
			object obj = <>c.<>9__4_0;
			if (obj == null)
			{
				hook_Start val = delegate(orig_Start orig, Stage self)
				{
					stageMaxPlayers = 0;
					orig.Invoke(self);
				};
				<>c.<>9__4_0 = val;
				obj = (object)val;
			}
			Stage.Start += (hook_Start)obj;
		}
		Hook val2 = new Hook((MethodBase)Reflection.GetMethodCached(typeof(Run), "get_participatingPlayerCount"), Reflection.GetMethodCached(typeof(FixPlayercount), "GetParticipatingPlayerCountHook"));
	}

	private static int GetParticipatingPlayerCountHook(Run self)
	{
		return GetConnectedPlayers();
	}

	private static int GetConnectedPlayers()
	{
		int num = 0;
		foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
		{
			if (instance.isConnected)
			{
				num++;
			}
		}
		if (MultitudesLoaded)
		{
			num = ApplyMultitudes(num);
		}
		if (ZetArtifactsLoaded)
		{
			num = ApplyZetMultitudesArtifact(num);
		}
		if (UpdateOnStageStart)
		{
			if (num > stageMaxPlayers)
			{
				stageMaxPlayers = num;
			}
			else
			{
				num = stageMaxPlayers;
			}
		}
		return num;
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static int ApplyMultitudes(int origPlayerCount)
	{
		return origPlayerCount * Multitudes.Multiplier;
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private static int ApplyZetMultitudesArtifact(int origPlayerCount)
	{
		if (ZetMultifact.Enabled && RunArtifactManager.instance.IsArtifactEnabled(Artifacts.ZetMultifact))
		{
			return origPlayerCount * Math.Max(2, ZetArtifactsPlugin.MultifactMultiplier.Value);
		}
		return origPlayerCount;
	}
}