Decompiled source of ShootTheDoor v1.0.0

Localia.ShootTheDoor.dll

Decompiled 6 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Gear;
using HarmonyLib;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using SemanticVersioning;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShootTheDoor")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShootTheDoor")]
[assembly: AssemblyTitle("ShootTheDoor")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShootTheDoor
{
	[BepInPlugin("Localia.ShootTheDoor", "ShootTheDoor", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class EntryPoint : BasePlugin
	{
		private Harmony m_Harmony;

		internal static float damage_multi = 0.1f;

		public override void Load()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			m_Harmony = new Harmony("Localia.ShootTheDoor");
			m_Harmony.PatchAll();
			Logs.Info("OK");
			if (MTFOUtil.IsLoaded && MTFOUtil.CustomPath != string.Empty)
			{
				string text = Path.Combine(MTFOUtil.CustomPath, "ShootTheDoor");
				Logs.Info("CustomPath = " + text);
				if (!Directory.Exists(text))
				{
					Directory.CreateDirectory(text);
				}
				ConfigFile val = new ConfigFile(Path.Combine(text, "ShootTheDoor.cfg"), true);
				ConfigEntry<float> val2 = val.Bind<float>("Config", "Door Bullet Damage Multi", 0.1f, "Set the damage multiplier.");
				damage_multi = val2.Value;
				Logs.Info($"Load config damage multi = {damage_multi}");
			}
		}
	}
	internal static class Logs
	{
		private static readonly ManualLogSource _logger;

		static Logs()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_logger = new ManualLogSource("Localia.ShootTheDoor");
			Logger.Sources.Add((ILogSource)(object)_logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(object data)
		{
			_logger.LogMessage((object)Format(data));
		}

		public static void Verbose(object data)
		{
			_logger.LogDebug((object)Format(data));
		}

		public static void Debug(object data)
		{
			_logger.LogDebug((object)Format(data));
		}

		public static void Error(object data)
		{
			_logger.LogError((object)Format(data));
		}
	}
	[HarmonyPatch(typeof(BulletWeapon))]
	internal static class Patch_BulletWeapon
	{
		[HarmonyPatch("BulletHit")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void Patch_BulletWeapon_BulletHit(bool __result, WeaponHitData __0, bool __1, float __2, uint __3, bool __4)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__0.owner == (Object)null || !((Agent)__0.owner).IsLocallyOwned)
			{
				return;
			}
			RaycastHit rayHit = __0.rayHit;
			Collider collider = ((RaycastHit)(ref rayHit)).collider;
			if ((Object)(object)collider == (Object)null)
			{
				return;
			}
			rayHit = __0.rayHit;
			GameObject gameObject = ((Component)((RaycastHit)(ref rayHit)).collider).gameObject;
			if ((Object)(object)gameObject == (Object)null || gameObject.layer != LayerManager.LAYER_DYNAMIC)
			{
				return;
			}
			LG_WeakDoor_Destruction componentInParent = gameObject.GetComponentInParent<LG_WeakDoor_Destruction>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				if (!componentInParent.SkinnedDoorEnabled)
				{
					componentInParent.EnableSkinnedDoor();
				}
				rayHit = __0.rayHit;
				float num = ((RaycastHit)(ref rayHit)).distance + __2;
				float num2 = __0.damage;
				if (num > __0.damageFalloff.x)
				{
					float num3 = (num - __0.damageFalloff.x) / (__0.damageFalloff.y - __0.damageFalloff.x);
					num3 = Mathf.Max(1f - num3, BulletWeapon.s_falloffMin);
					num2 *= num3;
				}
				num2 *= EntryPoint.damage_multi;
				LG_WeakDoor component = ((Component)componentInParent).gameObject.GetComponent<LG_WeakDoor>();
				if (component != null)
				{
					iLG_Door_Sync sync = component.m_sync;
					float num4 = num2;
					rayHit = __0.rayHit;
					sync.AttemptDoorInteraction((eDoorInteractionType)7, num4, 0f, ((RaycastHit)(ref rayHit)).point, (Agent)null);
				}
			}
		}
	}
	public static class MTFOUtil
	{
		public const string PLUGIN_GUID = "com.dak.MTFO";

		public const BindingFlags PUBLIC_STATIC = BindingFlags.Static | BindingFlags.Public;

		public static string GameDataPath { get; private set; }

		public static string CustomPath { get; private set; }

		public static bool HasCustomContent { get; private set; }

		public static bool IsLoaded { get; private set; }

		public static string BasePath { get; private set; }

		static MTFOUtil()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			GameDataPath = string.Empty;
			CustomPath = string.Empty;
			HasCustomContent = false;
			IsLoaded = false;
			if (((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("com.dak.MTFO", out var value))
			{
				Version version = value.Metadata.Version;
				if (version >= new Version("4.3.5", false))
				{
					InitMTFO_V5(value);
				}
			}
		}

		private static void InitMTFO_V5(PluginInfo info)
		{
			try
			{
				Assembly assembly = ((info == null) ? null : info.Instance?.GetType()?.Assembly) ?? null;
				if ((object)assembly == null)
				{
					throw new Exception("Assembly is Missing!");
				}
				Type[] types = assembly.GetTypes();
				Type type = types.First((Type t) => t.Name == "ConfigManager");
				if ((object)type == null)
				{
					throw new Exception("Unable to Find ConfigManager Class");
				}
				FieldInfo field = type.GetField("GameDataPath", BindingFlags.Static | BindingFlags.Public);
				FieldInfo field2 = type.GetField("CustomPath", BindingFlags.Static | BindingFlags.Public);
				FieldInfo field3 = type.GetField("HasCustomContent", BindingFlags.Static | BindingFlags.Public);
				if ((object)field == null)
				{
					throw new Exception("Unable to Find Field: GameDataPath");
				}
				if ((object)field2 == null)
				{
					throw new Exception("Unable to Find Field: CustomPath");
				}
				if ((object)field3 == null)
				{
					throw new Exception("Unable to Find Field: HasCustomContent");
				}
				GameDataPath = (string)field.GetValue(null);
				CustomPath = (string)field2.GetValue(null);
				HasCustomContent = (bool)field3.GetValue(null);
				BasePath = Path.Combine(CustomPath, "ShootTheDoor");
				IsLoaded = true;
			}
			catch (Exception value)
			{
				Logs.Error($"Exception thrown while reading metadata from MTFO (V{info.Metadata.Version}): \n{value}");
			}
		}
	}
}