Decompiled source of HardcoreMode v1.0.0

BepInEx/plugins/HardcoreMode.dll

Decompiled 4 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Localization;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: IgnoresAccessChecksTo("ALINE")]
[assembly: IgnoresAccessChecksTo("Core")]
[assembly: IgnoresAccessChecksTo("DOTween")]
[assembly: IgnoresAccessChecksTo("Global.Localization.Core")]
[assembly: IgnoresAccessChecksTo("MainMenuAssembly")]
[assembly: IgnoresAccessChecksTo("SPZGameAssembly")]
[assembly: AssemblyCompany("HardcoreMode")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HardcoreMode")]
[assembly: AssemblyTitle("HardcoreMode")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Shapez2HardcoreMode
{
	[BepInPlugin("HardcoreMode", "HardcoreMode", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static string AUTHOR = "UnmatchedBracket";

		internal static GameCore gamecore;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("HardcoreMode").PatchAll();
		}

		internal static bool InValidSavegame()
		{
			if ((Object)(object)gamecore != (Object)null && gamecore.SavegameOptionsManager != null)
			{
				return !gamecore.SavegameOptionsManager.Options.MenuMode;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(GameCore), "PreInit")]
	internal class GameCorePatch
	{
		private static void Postfix(GameCore __instance)
		{
			if ((Object)(object)Plugin.gamecore == (Object)null)
			{
				Plugin.Logger.LogInfo((object)"Obtained GameCore instance");
			}
			Plugin.gamecore = __instance;
		}
	}
	[HarmonyPatch(typeof(BeltPortSenderToHubSimulationRenderer))]
	internal class JudgementPatch
	{
		[HarmonyPatch("UpdateDeliveryIndicator")]
		[HarmonyPostfix]
		private static void UpdateDeliveryIndicatorPatch(Data data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (Plugin.InValidSavegame() && (int)data.LastItemType == 1)
			{
				Plugin.gamecore.ReturnToMenu();
				SavegameReference val = Globals.Savegames.FindMostRecentSavegameEntryByUid(Plugin.gamecore.SavegameOptionsManager.Options.Uid);
				Globals.Savegames.DeleteSavegame(val);
			}
		}
	}
	[HarmonyPatch(typeof(PreloaderDevAgreementState))]
	internal class LoadingScreenPatch
	{
		private static Transform FindChildOptional(Transform parent, string key)
		{
			if ((Object)(object)parent == (Object)null)
			{
				return null;
			}
			return parent.Find(key);
		}

		private static void ChangeTextOf(GameObject obj, string txt)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			HUDLocalizedText component = obj.GetComponent<HUDLocalizedText>();
			if ((Object)(object)component != (Object)null)
			{
				Plugin.Logger.LogInfo((object)(((Object)obj).name + "'s text found"));
				component.Text = (IText)new RawText(txt);
			}
			else
			{
				Plugin.Logger.LogError((object)(((Object)obj).name + "'s text NOT found"));
			}
		}

		[HarmonyPatch("OnEnterState")]
		[HarmonyPrefix]
		private static bool OnEnterStatePatch(PreloaderDevAgreementState __instance)
		{
			Transform val = GameObject.Find("PreloaderDevAgreementState(Clone)").transform.Find("Panel");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogError((object)"No panel");
				return false;
			}
			Transform val2 = val.Find("HUDLargeHeader");
			if ((Object)(object)val2 != (Object)null)
			{
				ChangeTextOf(((Component)val2).gameObject, "HardcoreMode Warning");
			}
			else
			{
				Plugin.Logger.LogError((object)"HUDLargeHeader not present");
			}
			Transform val3 = val.Find("HUDRegularTextOnPanel");
			if ((Object)(object)val3 != (Object)null)
			{
				ChangeTextOf(((Component)val3).gameObject, "You are using the <b><nobr><b><mark=#00000055><color=#ff9e16>HardcoreMode</color></mark></b></nobr></b> mod. You are very likely to lose any saves you load.\nPlease confirm:");
			}
			else
			{
				Plugin.Logger.LogError((object)"HUDLargeHeader not present");
			}
			Transform val4 = FindChildOptional(val.Find("GameObject"), "HUDRegularTextOnPanel (1)");
			if ((Object)(object)val4 != (Object)null)
			{
				ChangeTextOf(((Component)val4).gameObject, "I will not open any savegames I would like to keep with this mod.");
			}
			else
			{
				Plugin.Logger.LogError((object)"HUDLargeHeader not present");
			}
			Transform val5 = FindChildOptional(val.Find("GameObject (1)"), "HUDRegularTextOnPanel (1)");
			if ((Object)(object)val5 != (Object)null)
			{
				ChangeTextOf(((Component)val5).gameObject, "I am willing to lose any save I <i>do</i> load with this mod.");
			}
			else
			{
				Plugin.Logger.LogError((object)"HUDLargeHeader not present");
			}
			Transform val6 = FindChildOptional(val.Find("BtnContinue"), "Text");
			if ((Object)(object)val6 != (Object)null)
			{
				ChangeTextOf(((Component)val6).gameObject, "OKAY");
			}
			else
			{
				Plugin.Logger.LogError((object)"BtnContinue.Text not present");
			}
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HardcoreMode";

		public const string PLUGIN_NAME = "HardcoreMode";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}