Decompiled source of ScaledPenalties v1.0.0

ScaledPenalty.dll

Decompiled a year ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using ScaledPenalty.Patches;
using TMPro;
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("ScaledPenalty")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScaledPenalty")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e8870669-b0ef-4cbe-9e1f-9bf284a2670d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ScaledPenalty
{
	[BepInPlugin("Migis.ScaledPenaltyMod", "Scaled Penalty Mod", "1.0.0.0")]
	public class ClassPenaltyBase : BaseUnityPlugin
	{
		private const string modGUID = "Migis.ScaledPenaltyMod";

		private const string modName = "Scaled Penalty Mod";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("Migis.ScaledPenaltyMod");

		private static ClassPenaltyBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Migis.ScaledPenaltyMod");
			mls.LogInfo((object)"Scaled Penalty Mod Awoken");
			harmony.PatchAll(typeof(ClassPenaltyBase));
			harmony.PatchAll(typeof(HUDManagerPatch));
		}
	}
}
namespace ScaledPenalty.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch(typeof(HUDManager), "ApplyPenalty")]
		[HarmonyPrefix]
		public static bool ApplyPenalty(ref EndOfGameStatUIElements ___statsUIElements, ref StartOfRound ___playersManager, int playersDead, int bodiesInsured)
		{
			ManualLogSource val = Logger.CreateLogSource("Migis.ScaledPenaltyMod");
			val.LogInfo((object)"Inside Game!");
			val.LogInfo((object)("Connected Players: " + ___playersManager.connectedPlayersAmount));
			val.LogInfo((object)("Connected Players+1: " + (___playersManager.connectedPlayersAmount + 1)));
			float num = 1f / ((float)___playersManager.connectedPlayersAmount + 1f);
			val.LogInfo((object)("Calculated Penalty Per Player: " + num));
			Terminal val2 = Object.FindObjectOfType<Terminal>();
			int groupCredits = val2.groupCredits;
			bodiesInsured = Mathf.Max(bodiesInsured, 0);
			for (int i = 0; i < playersDead - bodiesInsured; i++)
			{
				val2.groupCredits -= (int)((float)groupCredits * num);
			}
			val2.groupCredits = Mathf.Max(val2.groupCredits, 0);
			((TMP_Text)___statsUIElements.penaltyAddition).text = $"{playersDead} casualties: -{num * 100f * (float)(playersDead - bodiesInsured)}%\n({bodiesInsured} friends recovered)";
			((TMP_Text)___statsUIElements.penaltyTotal).text = $"DUE: ${groupCredits - val2.groupCredits}";
			Debug.Log((object)$"New group credits after penalty: {val2.groupCredits}");
			return false;
		}
	}
}