Decompiled source of BlackBox Fixer v1.1.0

EmpressBlackboxFixer.dll

Decompiled 8 hours ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using REPOLib.Modules;
using TMPro;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressBlackboxFixer")]
[assembly: AssemblyTitle("EmpressBlackboxFixer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BlackboxFixer
{
	[BepInPlugin("Fixes.Blackbox", "Blackbox Fixer", "1.3.2")]
	public class BlackboxFixer : BaseUnityPlugin
	{
		public static ManualLogSource Log;

		public static Harmony MyHarmony;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			MyHarmony = new Harmony("Fixes.Blackbox");
			MyHarmony.Patch((MethodBase)AccessTools.Method(typeof(GameObject), "AddComponent", new Type[1] { typeof(Type) }, (Type[])null), new HarmonyMethod(typeof(FixerPatches), "AddComponent_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			try
			{
				Type type = AccessTools.TypeByName("Blackbox.MonitorTest");
				if (type != null)
				{
					MyHarmony.Patch((MethodBase)AccessTools.Method(type, "setText", (Type[])null, (Type[])null), new HarmonyMethod(typeof(FixerPatches), "SafeSetText", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not patch MonitorTest (UI might be buggy): " + ex.Message));
			}
			Log.LogInfo((object)"Blackbox Fixer: Quarantine Trap armed.");
		}
	}
	public static class FixerPatches
	{
		public static bool AddComponent_Prefix(GameObject __instance, Type componentType, ref Component __result)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			if (((Object)__instance).name == "Blackbox_Quarantine")
			{
				return true;
			}
			if (componentType.FullName == "Blackbox.Blackbox")
			{
				BlackboxFixer.Log.LogInfo((object)"Blackbox detected! Diverting to Quarantine...");
				try
				{
					GameObject val = new GameObject("Blackbox_Quarantine");
					val.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)val);
					Component val2 = val.AddComponent(componentType);
					InitializeBlackbox((BaseUnityPlugin)(object)((val2 is BaseUnityPlugin) ? val2 : null), componentType);
					__result = val2;
					return false;
				}
				catch (Exception ex)
				{
					BlackboxFixer.Log.LogError((object)("Quarantine failed: " + ex.Message));
					return true;
				}
			}
			return true;
		}

		private static void InitializeBlackbox(BaseUnityPlugin plugin, Type modType)
		{
			try
			{
				Traverse val = Traverse.Create((object)plugin);
				MethodInfo method = typeof(BaseUnityPlugin).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(plugin, null);
				}
				val.Property("Instance", (object[])null).SetValue((object)plugin);
				((Component)plugin).gameObject.transform.parent = null;
				((Object)((Component)plugin).gameObject).hideFlags = (HideFlags)61;
				string location = modType.Assembly.Location;
				string text = Path.Combine(Path.GetDirectoryName(location), "mydamagecanvasbundle");
				if (File.Exists(text))
				{
					AssetBundle val2 = null;
					foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
					{
						if (((Object)allLoadedAssetBundle).name == "mydamagecanvasbundle")
						{
							val2 = allLoadedAssetBundle;
						}
					}
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = AssetBundle.LoadFromFile(text);
					}
					if ((Object)(object)val2 != (Object)null)
					{
						GameObject val3 = val2.LoadAsset<GameObject>("DamageCanvasMultiplayerShop");
						GameObject val4 = val2.LoadAsset<GameObject>("DamageCanvasMultiplayer");
						if ((Object)(object)val3 != (Object)null)
						{
							NetworkPrefabs.RegisterNetworkPrefab(val3);
						}
						if ((Object)(object)val4 != (Object)null)
						{
							NetworkPrefabs.RegisterNetworkPrefab(val4);
						}
						val.Field("itemDmgMonitorShop").SetValue((object)val3);
						val.Field("itemDmgMonitorLevel").SetValue((object)val4);
					}
				}
				else
				{
					BlackboxFixer.Log.LogError((object)("AssetBundle not found at: " + text));
				}
				val.Method("Patch", Array.Empty<object>()).GetValue();
				BlackboxFixer.Log.LogInfo((object)"Blackbox initialized in Quarantine Mode.");
			}
			catch (Exception arg)
			{
				BlackboxFixer.Log.LogError((object)$"Manual Init Failed: {arg}");
			}
		}

		public static bool SafeSetText(MonoBehaviour __instance, string text)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return false;
			}
			TextMeshProUGUI componentInChildren = ((Component)__instance).GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = text;
			}
			return false;
		}
	}
}