Decompiled source of DisableRoomTitle v0.1.1

BepInEx/plugins/DisableRoomTitle/DisableRoomTitle.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace DisableRoomTitle;

[BepInPlugin("whiteknuckle.disableroomtitle", "DisableRoomTitle", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static Harmony HarmonyInstance;

	internal static bool RoomTitleDisabled;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		HarmonyInstance = new Harmony("whiteknuckle.disableroomtitle");
		HarmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
		Log.LogInfo((object)"DisableRoomTitle v0.1.0 loaded");
	}

	private void OnApplicationQuit()
	{
		Log.LogInfo((object)"DisableRoomTitle quitting");
	}

	internal static void DisableRoomTitles()
	{
		RoomTitleDisabled = true;
		Log.LogInfo((object)"[DisableRoomTitle] Room title suppression enabled.");
	}

	internal static bool ShouldSuppressHeader(UT_TextScrawl scrawl)
	{
		if (!RoomTitleDisabled || (Object)(object)scrawl == (Object)null || (Object)(object)CL_UIManager.instance == (Object)null)
		{
			return false;
		}
		if ((Object)(object)scrawl != (Object)(object)CL_UIManager.instance.header)
		{
			return false;
		}
		StackFrame[] frames = new StackTrace().GetFrames();
		if (frames == null)
		{
			return false;
		}
		StackFrame[] array = frames;
		for (int i = 0; i < array.Length; i++)
		{
			Type type = array[i].GetMethod()?.DeclaringType;
			if (type == typeof(UT_ZoneTitler) || type == typeof(WorldLoader) || type == typeof(CL_GameManager))
			{
				return true;
			}
		}
		return false;
	}

	internal static bool ShouldSuppressHeaderText(UT_TextScrawl scrawl, string text)
	{
		if (!RoomTitleDisabled || (Object)(object)scrawl == (Object)null || (Object)(object)CL_UIManager.instance == (Object)null || (Object)(object)scrawl != (Object)(object)CL_UIManager.instance.header)
		{
			return false;
		}
		if (string.IsNullOrEmpty(text))
		{
			return false;
		}
		if (text == "ASCEND")
		{
			return true;
		}
		string text2 = (((Object)(object)CL_GameManager.gamemode != (Object)null) ? CL_GameManager.gamemode.introText : null);
		if (string.IsNullOrEmpty(text2))
		{
			return false;
		}
		if (!(text == text2))
		{
			return text == "<color=red>" + text2;
		}
		return true;
	}
}
[HarmonyPatch(typeof(WorldLoader), "Initialize")]
internal static class Patch_WorldLoader_Initialize
{
	private static void Postfix()
	{
		bool customSeed = WorldLoader.customSeed;
		int num = (((Object)(object)WorldLoader.instance != (Object)null) ? WorldLoader.instance.seed : 0);
		Plugin.Log.LogInfo((object)$"[DisableRoomTitle] World initialized. Seeded={customSeed}, Seed={num}");
		Plugin.DisableRoomTitles();
	}
}
[HarmonyPatch(typeof(UT_ZoneTitler), "Play")]
internal static class Patch_UT_ZoneTitler_Play
{
	private static bool Prefix(UT_ZoneTitler __instance)
	{
		if (!Plugin.RoomTitleDisabled)
		{
			return true;
		}
		Plugin.Log.LogInfo((object)("[DisableRoomTitle] Suppressed zone title trigger: Region='" + __instance.region + "', SubRegion='" + __instance.subRegion + "'"));
		return false;
	}
}
[HarmonyPatch(typeof(UT_TextScrawl), "ShowText")]
internal static class Patch_UT_TextScrawl_ShowText
{
	private static bool Prefix(UT_TextScrawl __instance, string s)
	{
		if (!Plugin.ShouldSuppressHeader(__instance) && !Plugin.ShouldSuppressHeaderText(__instance, s))
		{
			return true;
		}
		Plugin.Log.LogInfo((object)("[DisableRoomTitle] Suppressed header text: " + s));
		return false;
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "whiteknuckle.disableroomtitle";

	public const string PLUGIN_NAME = "DisableRoomTitle";

	public const string PLUGIN_VERSION = "0.1.0";
}