Decompiled source of ScalingStartCredits v1.0.3

ScalingStartCredits.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("ScalingStartCredits")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScalingStartCredits")]
[assembly: AssemblyTitle("ScalingStartCredits")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace ScalingStartCredits
{
	[BepInPlugin("sunnobunno.scalingstartcredits", "Scaling Start Credits", "1.0.1")]
	public class ScalingStartCreditsBase : BaseUnityPlugin
	{
		public const string modGUID = "sunnobunno.scalingstartcredits";

		public const string modName = "Scaling Start Credits";

		public const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("sunnobunno.scalingstartcredits");

		public static ScalingStartCreditsBase? Instance;

		internal ManualLogSource? mls;

		public ConfigEntry<int> configCreditIncrement;

		public ConfigEntry<int> configPlayerCountThreshold;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			BindConfiguration();
			mls = Logger.CreateLogSource("sunnobunno.scalingstartcredits");
			mls.LogInfo((object)"sunnobunno.scalingstartcredits is loading.");
			harmony.PatchAll();
			mls.LogInfo((object)"sunnobunno.scalingstartcredits is loaded.");
		}

		private void BindConfiguration()
		{
			configCreditIncrement = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Credit Increment", 15, "The amount of credits per player added to the starting group credits");
			configPlayerCountThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Player Threshold", 4, "The number of players required in the lobby before credits are added per new player.");
		}
	}
}
namespace ScalingStartCredits.Patches
{
	[HarmonyPatch(typeof(StartMatchLever))]
	internal class StartingCreditsPatch
	{
		private static ManualLogSource mls = Logger.CreateLogSource("sunnobunno.scalingstartcredits");

		private static int groupCreditIncreaseIncrement;

		private static int playerThreshold;

		private static int playerCount;

		private static int days;

		private static HUDManager hudManager;

		[HarmonyPatch("StartGame")]
		[HarmonyPrefix]
		private static void StartMatchLeverPatch(ref StartOfRound ___playersManager)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			groupCreditIncreaseIncrement = ScalingStartCreditsBase.Instance.configCreditIncrement.Value;
			playerThreshold = ScalingStartCreditsBase.Instance.configPlayerCountThreshold.Value;
			playerCount = ___playersManager.fullyLoadedPlayers.Count;
			days = ___playersManager.daysPlayersSurvivedInARow;
			bool flag = true;
			mls.LogInfo((object)$"Days: {days}");
			mls.LogInfo((object)$"Player Count: {playerCount}");
			if (days != 0)
			{
				mls.LogInfo((object)"No longer first day. Aborting");
				flag = false;
			}
			if (playerCount <= playerThreshold && flag)
			{
				mls.LogInfo((object)"Player threshold not met. Aborting");
				flag = false;
			}
			if (flag)
			{
				hudManager = (HUDManager)Object.FindObjectOfType(typeof(HUDManager));
				Terminal val = (Terminal)Object.FindObjectOfType(typeof(Terminal));
				int num = playerCount - playerThreshold;
				int num2 = num * groupCreditIncreaseIncrement;
				int num3 = val.groupCredits + num2;
				val.SyncGroupCreditsServerRpc(num3, val.numberOfItemsInDropship);
				mls.LogInfo((object)$"Credits Added for {num} players above threshold of {playerThreshold}: {num2}");
				mls.LogInfo((object)$"Group Credits: {val.groupCredits}");
				hudManager.AddTextToChatOnServer($"Credits Added for {num} players above threshold of {playerThreshold}: {num2}", -1);
				hudManager.AddTextToChatOnServer($"Group Credits: {val.groupCredits}", -1);
			}
		}
	}
}