Decompiled source of DogshitSols v0.1.4

DogshitSols.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DogshitSols.Features.ContactDamage;
using DogshitSols.Features.ContactDamage.HarmonyPatches;
using DogshitSols.Features.DashTweaks;
using DogshitSols.Features.DashTweaks.HarmonyPatches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DogshitSols")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Dogshit Sols")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+26c9118c4c05b375149cd41affbeca78ffcc1dfc")]
[assembly: AssemblyProduct("DogshitSols")]
[assembly: AssemblyTitle("DogshitSols")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 DogshitSols
{
	internal class ConfigurationManager
	{
		internal ConfigEntry<bool> LadyEClonesDamageEnabled;

		internal ConfigEntry<bool> DisableDashIFrames;

		internal event Action<bool>? OnLadyEClonesDamageEnabledChanged;

		public ConfigurationManager(ConfigFile config)
		{
			LadyEClonesDamageEnabled = config.Bind<bool>("General", "Lady E clones contact damage", true, "Whether Lady E clones have contact damage.");
			LadyEClonesDamageEnabled.SettingChanged += delegate
			{
				this.OnLadyEClonesDamageEnabledChanged?.Invoke(LadyEClonesDamageEnabled.Value);
			};
			DisableDashIFrames = config.Bind<bool>("General", "Disable dash i-frames", true, "Whether to disable dash i-frames.");
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("DogshitSols", "DogshitSols", "1.0.0")]
	public class DogshitSols : BaseUnityPlugin
	{
		private Harmony harmony;

		internal ConfigurationManager ConfigManager;

		internal static DogshitSols Instance { get; private set; }

		private void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			((Object)this).hideFlags = (HideFlags)61;
			Instance = this;
			ConfigManager = new ConfigurationManager(((BaseUnityPlugin)this).Config);
			harmony = Harmony.CreateAndPatchAll(typeof(DogshitSols).Assembly, (string)null);
			InitializeFeatures();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin DogshitSols is loaded!");
		}

		private void InitializeFeatures()
		{
			ContactDamageFeature.Initialize();
			DashTweaksFeature.Initialize();
		}

		private void OnDestroy()
		{
			DashTweaksFeature.Release();
			ContactDamageFeature.Release();
			harmony.UnpatchSelf();
		}
	}
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}

		internal static void Exception(Exception ex)
		{
			Error(ex.Message + ". " + ex.StackTrace);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DogshitSols";

		public const string PLUGIN_NAME = "DogshitSols";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DogshitSols.Features.DashTweaks
{
	internal static class DashTweaksFeature
	{
		private static GameObject? _playerTrapsDamageReceiver;

		private static GameObject? PlayerTrapsDamageReceiver
		{
			get
			{
				if ((Object)(object)Player.i == (Object)null)
				{
					_playerTrapsDamageReceiver = null;
					return _playerTrapsDamageReceiver;
				}
				if ((Object)(object)_playerTrapsDamageReceiver == (Object)null)
				{
					Transform val = ((Component)Player.i.GetHealth).transform.Find("TrapDamageReceiver");
					if ((Object)(object)val == (Object)null)
					{
						PlayerTrapsDamageReceiver = null;
						return _playerTrapsDamageReceiver;
					}
					_playerTrapsDamageReceiver = ((Component)val).gameObject;
					return _playerTrapsDamageReceiver;
				}
				return _playerTrapsDamageReceiver;
			}
			set
			{
				_playerTrapsDamageReceiver = value;
			}
		}

		internal static void Initialize()
		{
			PlayerRollStatePatches.OnStateEnterPostfix += HandleRollStateEnter;
			PlayerRollStatePatches.OnStateExitPostfix += HandleRollStateExit;
		}

		private static void HandleRollStateExit(PlayerRollState obj)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "A4_S5_DaoTrapHouse_Final")
			{
				GameObject? playerTrapsDamageReceiver = PlayerTrapsDamageReceiver;
				if (playerTrapsDamageReceiver != null)
				{
					playerTrapsDamageReceiver.SetActive(true);
				}
			}
		}

		private static void HandleRollStateEnter(PlayerRollState obj)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "A4_S5_DaoTrapHouse_Final")
			{
				GameObject? playerTrapsDamageReceiver = PlayerTrapsDamageReceiver;
				if (playerTrapsDamageReceiver != null)
				{
					playerTrapsDamageReceiver.SetActive(false);
				}
			}
		}

		internal static void Release()
		{
			PlayerRollStatePatches.OnStateEnterPostfix -= HandleRollStateEnter;
			PlayerRollStatePatches.OnStateExitPostfix -= HandleRollStateExit;
		}
	}
}
namespace DogshitSols.Features.DashTweaks.HarmonyPatches
{
	[HarmonyPatch(typeof(PlayerRollState))]
	internal static class PlayerRollStatePatches
	{
		private static MethodInfo _dogshitSolsGetInstanceMethod = typeof(DogshitSols).GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic).GetMethod;

		private static FieldInfo _dogshitSolsConfigManagerField = typeof(DogshitSols).GetField("ConfigManager", BindingFlags.Instance | BindingFlags.NonPublic);

		private static FieldInfo _configurationManagerDisableDashIFramesField = typeof(ConfigurationManager).GetField("DisableDashIFrames", BindingFlags.Instance | BindingFlags.NonPublic);

		private static MethodInfo _configEntryGetValueMethod = typeof(ConfigEntry<bool>).GetProperty("Value", BindingFlags.Instance | BindingFlags.Public).GetMethod;

		private static MethodInfo _playerIsWeakGetter = typeof(Player).GetProperty("IsWeak", BindingFlags.Instance | BindingFlags.Public).GetMethod;

		internal static event Action<PlayerRollState>? OnStateEnterPostfix;

		internal static event Action<PlayerRollState>? OnStateExitPostfix;

		[HarmonyPatch("OnStateEnter")]
		[HarmonyPostfix]
		private static void OnStateEnter_Postfix(PlayerRollState __instance)
		{
			try
			{
				PlayerRollStatePatches.OnStateEnterPostfix?.Invoke(__instance);
			}
			catch (Exception ex)
			{
				Log.Exception(ex);
			}
		}

		[HarmonyPatch("OnStateExit")]
		[HarmonyPostfix]
		private static void OnStateExit_Postfix(PlayerRollState __instance)
		{
			try
			{
				PlayerRollStatePatches.OnStateExitPostfix?.Invoke(__instance);
			}
			catch (Exception ex)
			{
				Log.Exception(ex);
			}
		}

		[HarmonyPatch("OnStateEnter")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> OnStateEnter_Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			Label? label2 = default(Label?);
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[4]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Callvirt, (object)_playerIsWeakGetter, (string)null),
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Branches(ci, ref label2)), (string)null)
			}).ThrowIfInvalid("first brtrue not found").Advance(3);
			Label label = (Label)val.Operand;
			val.Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[5]
			{
				new CodeInstruction(OpCodes.Call, (object)_dogshitSolsGetInstanceMethod),
				new CodeInstruction(OpCodes.Ldfld, (object)_dogshitSolsConfigManagerField),
				new CodeInstruction(OpCodes.Ldfld, (object)_configurationManagerDisableDashIFramesField),
				new CodeInstruction(OpCodes.Callvirt, (object)_configEntryGetValueMethod),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			});
			return val.InstructionEnumeration();
		}
	}
}
namespace DogshitSols.Features.ContactDamage
{
	internal static class ContactDamageFeature
	{
		private static GameObject? _contactDamageReceiver;

		private static FieldInfo _damageDealerParriableOwnerField = AccessTools.Field(typeof(DamageDealer), "_parriableOwner");

		private static FieldInfo _triggerDetectorAllValidEffectTypeField = AccessTools.Field(typeof(TriggerDetector), "_allValidEffectType");

		internal static void Initialize()
		{
			MonsterBasePatches.OnCheckInitPostfix += HandleMonsterInit;
			PlayerPatches.OnAwakePostfix += HandlePlayerAwake;
		}

		private static void HandlePlayerAwake(Player obj)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			PlayerHealth health = obj.health;
			_contactDamageReceiver = Object.Instantiate<GameObject>(((Component)((Component)health).transform.Find("DamageReceiver")).gameObject, ((Component)health).transform);
			_contactDamageReceiver.transform.localPosition = Vector3.zero;
			((Object)_contactDamageReceiver).name = "ContactDamageReceiver";
			_contactDamageReceiver.GetComponent<EffectReceiver>().effectType = (EffectType)4096;
			Collider2D component = ((Component)health).GetComponent<Collider2D>();
			EffectReceiver.EffectReceiverCache.RemoveAll(component);
			AutoAttributeManager.AutoReferenceAllChildren(((Component)health).gameObject);
			obj.fsm.Changed += HandlePlayerStateChanged;
		}

		private static void HandlePlayerStateChanged(PlayerStateType obj)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if ((Object)(object)_contactDamageReceiver == (Object)null)
			{
				return;
			}
			if ((int)obj != 3)
			{
				if ((int)obj != 54)
				{
					if ((int)obj == 60)
					{
						_contactDamageReceiver.SetActive(false);
					}
					else
					{
						_contactDamageReceiver.SetActive(true);
					}
				}
				else
				{
					_contactDamageReceiver.SetActive(false);
				}
			}
			else
			{
				_contactDamageReceiver.SetActive(false);
			}
		}

		private static void HandleMonsterInit(MonsterBase monster)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)monster == (Object)null)
			{
				return;
			}
			Transform val = monster.monsterCore?.logicRoot ?? null;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform val2 = ((Component)val).transform.Find("TouchDamage");
			if (!((Object)(object)val2 == (Object)null))
			{
				((Component)val2).gameObject.SetActive(true);
				DamageDealer componentInChildren = ((Component)val2).GetComponentInChildren<DamageDealer>(true);
				if (!((Object)(object)componentInChildren == (Object)null))
				{
					componentInChildren.effectDealer.IsClearHitOwnerWhenExit = true;
					componentInChildren.facingDetectionRule = (FacingDetectionRule)0;
					_damageDealerParriableOwnerField.SetValue(componentInChildren, null);
					EffectDealer componentInChildren2 = ((Component)val2).GetComponentInChildren<EffectDealer>(true);
					TriggerDetector componentInChildren3 = ((Component)val2).GetComponentInChildren<TriggerDetector>(true);
					componentInChildren2.type = (EffectType)4096;
					_triggerDetectorAllValidEffectTypeField.SetValue(componentInChildren3, (object)(EffectType)4096);
					EnemyInvincibilityWatcher enemyInvincibilityWatcher = ((Component)monster).gameObject.AddComponent<EnemyInvincibilityWatcher>();
					enemyInvincibilityWatcher.TouchDamageGameObject = ((Component)val2).gameObject;
					enemyInvincibilityWatcher.Monster = monster;
				}
			}
		}

		internal static void Release()
		{
			MonsterBasePatches.OnCheckInitPostfix -= HandleMonsterInit;
			PlayerPatches.OnAwakePostfix -= HandlePlayerAwake;
			if ((Object)(object)Player.i != (Object)null)
			{
				Player.i.fsm.Changed -= HandlePlayerStateChanged;
			}
		}
	}
	internal class EnemyInvincibilityWatcher : MonoBehaviour
	{
		internal GameObject TouchDamageGameObject;

		internal MonsterBase Monster;

		private GameObject? _correntDamageReceiver;

		private HashSet<string> LadyENames = new HashSet<string> { "StealthGameMonster_Boss_ButterFly Variant", "StealthGameMonster_Boss_ButterFly Variant (1)", "StealthGameMonster_Boss_ButterFly Variant (2)", "StealthGameMonster_Boss_ButterFly Variant (3)", "StealthGameMonster_Boss_ButterFly Variant (4)" };

		private void Awake()
		{
			DogshitSols.Instance.ConfigManager.OnLadyEClonesDamageEnabledChanged += HandleLadyEClonesDamageEnabledChanged;
		}

		private void OnDestroy()
		{
			DogshitSols.Instance.ConfigManager.OnLadyEClonesDamageEnabledChanged -= HandleLadyEClonesDamageEnabledChanged;
		}

		private void HandleLadyEClonesDamageEnabledChanged(bool _)
		{
			_correntDamageReceiver = null;
		}

		private void RememberDamageReceiver()
		{
			if ((Object)(object)Monster == (Object)null)
			{
				return;
			}
			if (DogshitSols.Instance.ConfigManager.LadyEClonesDamageEnabled.Value && LadyENames.Contains(((Object)Monster).name))
			{
				Transform val = ((Component)Monster.ChildAnimator).gameObject.transform.Find("CanHurt");
				_correntDamageReceiver = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
				return;
			}
			MonsterDecreasePostureReceiver? obj = ((IEnumerable<MonsterDecreasePostureReceiver>)Monster.damageReceivers).FirstOrDefault((Func<MonsterDecreasePostureReceiver, bool>)((MonsterDecreasePostureReceiver dr) => (Object)(object)dr != (Object)null && (Object)(object)((Component)dr).gameObject != (Object)null && ((Component)dr).gameObject.activeInHierarchy));
			_correntDamageReceiver = ((obj != null) ? ((Component)obj).gameObject : null);
		}

		private void Update()
		{
			if ((Object)(object)_correntDamageReceiver == (Object)null)
			{
				if (TouchDamageGameObject.activeInHierarchy)
				{
					TouchDamageGameObject.SetActive(false);
				}
				RememberDamageReceiver();
				return;
			}
			if (_correntDamageReceiver.activeInHierarchy && !TouchDamageGameObject.activeInHierarchy)
			{
				TouchDamageGameObject.SetActive(true);
			}
			if (!_correntDamageReceiver.activeInHierarchy && TouchDamageGameObject.activeInHierarchy)
			{
				TouchDamageGameObject.SetActive(false);
			}
		}
	}
}
namespace DogshitSols.Features.ContactDamage.HarmonyPatches
{
	[HarmonyPatch(typeof(MonsterBase))]
	internal static class MonsterBasePatches
	{
		internal static event Action<MonsterBase>? OnCheckInitPostfix;

		[HarmonyPatch("CheckInit")]
		[HarmonyPostfix]
		private static void CheckInit_Postfix(MonsterBase __instance)
		{
			try
			{
				MonsterBasePatches.OnCheckInitPostfix?.Invoke(__instance);
			}
			catch (Exception ex)
			{
				Log.Exception(ex);
			}
		}
	}
	[HarmonyPatch(typeof(Player))]
	internal static class PlayerPatches
	{
		internal static event Action<Player>? OnAwakePostfix;

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void Awake_Postfix(Player __instance)
		{
			try
			{
				PlayerPatches.OnAwakePostfix?.Invoke(__instance);
			}
			catch (Exception ex)
			{
				Log.Exception(ex);
			}
		}
	}
}