Decompiled source of CopHealthModifierMono v1.1.0

Mods/CopHealthModifier.Mono.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using CopHealthModifier;
using Fxcpds;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using ScheduleOne.NPCs;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Police;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonID("CopHealthModifier")]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonInfo(typeof(Mod), "Cop Health Modifier", "1.1.0", "Foxcapades", null)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CopHealthModifier")]
[assembly: AssemblyConfiguration("Mono")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+354d28714084364f9ba7d627ba284d7fc1211843")]
[assembly: AssemblyProduct("CopHealthModifier")]
[assembly: AssemblyTitle("CopHealthModifier")]
[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 Fxcpds
{
	public abstract class FxMod : MelonMod
	{
		private static FxMod? instance;

		public static FxMod Instance => instance;

		public static Instance Logger => ((MelonBase)instance).LoggerInstance;

		protected string configPath => "MelonPreferences.cfg";

		public string ConfigPath => Path.Combine(MelonEnvironment.UserDataDirectory, configPath);

		public override void OnEarlyInitializeMelon()
		{
			instance = this;
		}

		public override void OnInitializeMelon()
		{
			Player.onPlayerSpawned = (Action<Player>)Delegate.Combine(Player.onPlayerSpawned, new Action<Player>(onPlayerSpawned));
		}

		public sealed override void OnPreferencesSaved(string filepath)
		{
			if (filepath.EndsWith(configPath))
			{
				onModPreferencesSaved();
			}
		}

		protected virtual void onModPreferencesSaved()
		{
		}

		private void onPlayerSpawned(Player player)
		{
			if (player.IsLocalPlayer)
			{
				onLocalPlayerLoaded(player);
			}
		}

		protected virtual void onLocalPlayerLoaded(Player player)
		{
		}
	}
	internal static class DebugTools
	{
		public static void Debug(this Instance logger, string message)
		{
		}

		public static void Debug(this Instance logger, string message, object? a1)
		{
		}

		public static void Debug(this Instance logger, string message, object? a1, object? a2)
		{
		}

		public static void Debug(this Instance logger, string message, object? a1, object? a2, object? a3)
		{
		}

		public static void Debug(this Instance logger, string message, object? a1, object? a2, object? a3, object? a4)
		{
		}
	}
	public sealed class NumberValidator<T> : ValueValidator where T : IComparable<T>
	{
		private readonly T min;

		private readonly T max;

		public NumberValidator(T min, T max)
		{
			this.min = min;
			this.max = max;
		}

		public override bool IsValid(object value)
		{
			T val = (T)value;
			return val.CompareTo(min) > -1 && val.CompareTo(max) < 1;
		}

		public override object EnsureValid(object value)
		{
			T val = (T)value;
			if (val.CompareTo(min) < 0)
			{
				return min;
			}
			if (val.CompareTo(max) > 0)
			{
				return max;
			}
			return value;
		}
	}
}
namespace CopHealthModifier
{
	public class Mod : FxMod
	{
		public const string MOD_NAME = "Cop Health Modifier";

		private const string MOD_PREF_NAME = "hpMultiplier";

		private static MelonPreferences_Entry<float>? multiplier;

		private static float defaultCopHealth;

		public override void OnInitializeMelon()
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("Cop Health Modifier", "Cop Health Modifier");
			multiplier = val.CreateEntry<float>("hpMultiplier", 1f, "Cop Health Multiplier", (string)null, false, false, (ValueValidator)(object)new NumberValidator<float>(0.1f, float.MaxValue), (string)null);
			base.OnInitializeMelon();
		}

		protected override void onLocalPlayerLoaded(Player player)
		{
			applyModifier();
		}

		protected override void onModPreferencesSaved()
		{
			applyModifier();
		}

		private void applyModifier()
		{
			if ((Object)(object)Player.Local == (Object)null)
			{
				return;
			}
			List<PoliceOfficer> officers = PoliceOfficer.Officers;
			if (officers.Count == 0)
			{
				((MelonBase)this).LoggerInstance.Error("No police officers found to modify!");
				return;
			}
			float value = multiplier.Value;
			float num = defaultCopHealth * value;
			foreach (PoliceOfficer item in officers)
			{
				if (defaultCopHealth == 0f)
				{
					defaultCopHealth = ((NPC)item).Health.MaxHealth;
					num = defaultCopHealth * value;
				}
				if ((int)((NPC)item).Health.MaxHealth * 100 != (int)num * 100)
				{
					((NPC)item).Health.MaxHealth = num;
					((NPC)item).Health.RestoreHealth();
				}
			}
		}
	}
}