Decompiled source of Start with Fatality Board v1.0.0

BepInEx/Plugins/Start_with_Fatality_Board.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Start_with_Fatality_Board")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Start_with_Fatality_Board")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6532c80c-6ec0-4c06-adea-43ac677fd0fd")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Start_with_Fatality_Board
{
	[BepInPlugin("Hackattack242.Start_with_Fatality_Board", "Start_with_Fatality_Board", "1.0.0")]
	public class Start_with_fatality_board_base : BaseUnityPlugin
	{
		private const string mod_GUID = "Hackattack242.Start_with_Fatality_Board";

		private const string mod_name = "Start_with_Fatality_Board";

		private const string mod_version = "1.0.0";

		private readonly Harmony harmony = new Harmony("Hackattack242.Start_with_Fatality_Board");

		private static Start_with_fatality_board_base Instance;

		private ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("Start_with_Fatality_Board");
			logger.LogInfo((object)"Start_with_Fatality_Board has awoken");
			harmony.PatchAll();
			logger.LogInfo((object)"Patches Complete");
		}

		internal static void LogDebug(string message)
		{
			Instance.Log(message, (LogLevel)32);
		}

		internal static void LogInfo(string message)
		{
			Instance.Log(message, (LogLevel)16);
		}

		internal static void LogWarning(string message)
		{
			Instance.Log(message, (LogLevel)4);
		}

		internal static void LogError(string message)
		{
			Instance.Log(message, (LogLevel)2);
		}

		internal static void LogError(Exception ex)
		{
			Instance.Log(ex.Message + "\n" + ex.StackTrace, (LogLevel)2);
		}

		private void Log(string message, LogLevel logLevel)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			logger.Log(logLevel, (object)message);
		}
	}
}
namespace Start_with_Fatality_Board.Patches
{
	internal class Board_Patch
	{
		[HarmonyPatch(typeof(StartOfRound))]
		internal class NewSaveStartPatch
		{
			[HarmonyPatch("firstDayAnimation")]
			[HarmonyPostfix]
			internal static void UnlockFatalitiesSign()
			{
				if (StartOfRound.Instance.gameStats.daysSpent == 0 && !StartOfRound.Instance.isChallengeFile)
				{
					Start_with_fatality_board_base.LogInfo("New save detected, unlocking Fatalities Sign.");
					if (!GameNetworkManager.Instance.isHostingGame)
					{
						return;
					}
					List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
					{
						foreach (UnlockableItem item in unlockables)
						{
							string unlockableName = item.unlockableName;
							int num = unlockables.IndexOf(item);
							Start_with_fatality_board_base.LogDebug($"Checking unlockableName {unlockableName} and ID {num}.");
							if (CheckConfig(num, unlockableName))
							{
								break;
							}
						}
						return;
					}
				}
				Start_with_fatality_board_base.LogInfo("Not a new save, not unlocking Fatalities Sign.");
			}

			private static bool CheckConfig(int unlockableID, string unlockableName)
			{
				if (unlockableName.Equals("Fatalities Sign"))
				{
					Start_with_fatality_board_base.LogInfo($"Found Fatalities Sign with unlockableName {unlockableName} and ID {unlockableID}. Unlocking.");
					UnlockShipItem(StartOfRound.Instance, unlockableID, unlockableName);
					return true;
				}
				return false;
			}

			private static void UnlockShipItem(StartOfRound instance, int unlockableID, string name)
			{
				try
				{
					Start_with_fatality_board_base.LogInfo("Attempting to unlock " + name);
					MethodInfo method = ((object)instance).GetType().GetMethod("UnlockShipObject", BindingFlags.Instance | BindingFlags.NonPublic);
					method.Invoke(instance, new object[1] { unlockableID });
					Start_with_fatality_board_base.LogInfo("Spawning " + name);
				}
				catch (NullReferenceException arg)
				{
					Start_with_fatality_board_base.LogError($"Could not invoke UnlockShipObject method: {arg}");
				}
			}
		}
	}
}