Decompiled source of SetDeathTimer v1.0.1

SetDeathTimer.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BoplFixedMath;
using HarmonyLib;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("death")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("modify sudden death timer")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("death")]
[assembly: AssemblyTitle("death")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace death;

[BepInPlugin("com.pirre.deathtimer", "death", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private static int timeBeforeSuddenDeathValue;

	private void Awake()
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin death is loaded!");
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		string text = Path.Combine(directoryName, "SetDeathTimer.cfg");
		if (File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Loading configuration from " + text));
			ConfigFile val = new ConfigFile(text, true);
			timeBeforeSuddenDeathValue = val.Bind<int>("Settings", "TimeBeforeSuddenDeath", 60, "Time before sudden death in seconds").Value;
		}
		else
		{
			timeBeforeSuddenDeathValue = 60;
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"No config file found, using default value of {timeBeforeSuddenDeathValue} seconds.");
		}
		Harmony val2 = new Harmony("com.pirre.deathtimer");
		val2.PatchAll();
	}

	public static int GetTimeBeforeSuddenDeath()
	{
		return timeBeforeSuddenDeathValue;
	}
}
[HarmonyPatch(typeof(GameSessionHandler))]
public class GameSessionHandlerPatch
{
	private static FieldInfo timeBeforeSuddenDeathField = AccessTools.Field(typeof(GameSessionHandler), "TimeBeforeSuddenDeath");

	[HarmonyPostfix]
	[HarmonyPatch("UpdateSim")]
	public static void AfterUpdateSim(GameSessionHandler __instance)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		if (timeBeforeSuddenDeathField != null)
		{
			Fix val = (Fix)timeBeforeSuddenDeathField.GetValue(__instance);
			if (val == new Fix(120))
			{
				int timeBeforeSuddenDeath = Plugin.GetTimeBeforeSuddenDeath();
				timeBeforeSuddenDeathField.SetValue(__instance, (object)new Fix(timeBeforeSuddenDeath));
				Debug.Log((object)$"TimeBeforeSuddenDeath has been set to {timeBeforeSuddenDeath} seconds!");
			}
		}
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "death";

	public const string PLUGIN_NAME = "death";

	public const string PLUGIN_VERSION = "1.0.0";
}