Decompiled source of MiscellaneousFixes v1.7.1

MiscFixes.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
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 Pigeon.Movement;
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("DBR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+ed08de125bd7bb7c8cefa075a7f09a84131c2cc1")]
[assembly: AssemblyProduct("Miscellaneous Fixes")]
[assembly: AssemblyTitle("MiscFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 MiscFixes
{
	[MycoMod(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("DBR.MiscFixes", "MiscFixes", "1.7.1")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(VoltaicGrenade), "Update")]
		public static class VoltaicGrenadeUpdatePatch
		{
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Expected O, but got Unknown
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				FieldInfo fieldInfo = AccessTools.Field(typeof(VoltaicGrenade), "grenadeData");
				FieldInfo fieldInfo2 = AccessTools.Field(fieldInfo.FieldType, "igniteExplosionDamage");
				for (int i = 0; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false))
					{
						list[i - 3] = new CodeInstruction(OpCodes.Ldflda, (object)fieldInfo);
						list.RemoveRange(i - 2, 2);
						Logger.LogInfo((object)"[Live Wire] Successfully replaced igniteExplosionDamage access");
						break;
					}
				}
				return list;
			}
		}

		[HarmonyPatch(typeof(UpgradeProperty_ThrowableCooldown), "GetStatData")]
		public static class ShieldBlocksDisplayFix
		{
			private static bool Prefix(UpgradeProperty_ThrowableCooldown __instance, UpgradeInstance upgrade, ref IEnumerator<StatData> __result)
			{
				object obj;
				if (upgrade == null)
				{
					obj = null;
				}
				else
				{
					Upgrade upgrade2 = upgrade.Upgrade;
					obj = ((upgrade2 != null) ? upgrade2.APIName : null);
				}
				if ((string?)obj == "ShieldBlocks")
				{
					__result = GetStatData(__instance, UpgradeProperty.GetPatternSizeRatio(upgrade, false));
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(UpgradeProperty_ThrowableCooldown), "Apply")]
		public static class ShieldBlocksApplyFix
		{
			private static bool Prefix(UpgradeProperty_ThrowableCooldown __instance, UpgradeInstance upgrade, IGear gear)
			{
				object obj;
				if (upgrade == null)
				{
					obj = null;
				}
				else
				{
					Upgrade upgrade2 = upgrade.Upgrade;
					obj = ((upgrade2 != null) ? upgrade2.APIName : null);
				}
				if ((string?)obj == "ShieldBlocks")
				{
					IActivatedAbility val = (IActivatedAbility)(object)((gear is IActivatedAbility) ? gear : null);
					if (val != null)
					{
						ref CooldownData cooldownData = ref val.CooldownData;
						cooldownData.rechargeDuration *= 1f / GetAdjustedValue(__instance.rechargeDuration.data.max, UpgradeProperty.GetPatternSizeRatio(upgrade, false));
						cooldownData.maxCharges += (int)__instance.maxCharges.data.max;
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(AcceleratorGun), "OnBurstFinished")]
		public static class RocketDamagePatch
		{
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				for (int i = 0; i < list.Count - 4; i++)
				{
					if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Ldflda && list[i + 2].opcode == OpCodes.Ldfld && list[i + 3].opcode == OpCodes.Conv_R4 && list[i + 4].opcode == OpCodes.Div)
					{
						list.RemoveRange(i, 5);
						Logger.LogInfo((object)"[Oxythane's Promise] Successfully removed damage bullet division");
						break;
					}
				}
				for (int j = 0; j < list.Count - 4; j++)
				{
					if (list[j].opcode == OpCodes.Ldarg_0 && list[j + 1].opcode == OpCodes.Ldflda && list[j + 2].opcode == OpCodes.Ldfld && list[j + 3].opcode == OpCodes.Conv_R4 && list[j + 4].opcode == OpCodes.Div)
					{
						list.RemoveRange(j, 5);
						Logger.LogInfo((object)"[Oxythane's Promise] Successfully removed range bullet division");
						break;
					}
				}
				return list;
			}
		}

		[HarmonyPatch]
		public static class AcceleratorSpeedDamageFix
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				yield return AccessTools.Method(typeof(AcceleratorGun), "GetSpeedToDamageMultiplier", Array.Empty<Type>(), (Type[])null);
				yield return AccessTools.Method(typeof(AcceleratorGun), "GetSpeedToDamageMultiplier", new Type[1] { typeof(float).MakeByRefType() }, (Type[])null);
			}

			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase method)
			{
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Expected O, but got Unknown
				MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(Player), "DefaultMoveSpeed");
				MethodInfo methodInfo2 = AccessTools.PropertyGetter(typeof(Player), "WalkSpeed");
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				for (int i = 0; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(list[i], methodInfo))
					{
						list[i] = new CodeInstruction(OpCodes.Callvirt, (object)methodInfo2);
						Logger.LogInfo((object)$"[Inertia Accelerant] Successfully replaced DefaultMoveSpeed with WalkSpeed in {method}");
					}
				}
				return list;
			}
		}

		[HarmonyPatch(typeof(SetFlagsPlayerUpgrade), "Apply")]
		public static class WithYouFix
		{
			[HarmonyPrefix]
			private static void Prefix(UpgradeInstance instance)
			{
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					Upgrade upgrade = instance.Upgrade;
					obj = ((upgrade != null) ? upgrade.APIName : null);
				}
				if ((string?)obj == "With You")
				{
					Upgrade upgrade2 = instance.Upgrade;
					SetFlagsPlayerUpgrade val = (SetFlagsPlayerUpgrade)(object)((upgrade2 is SetFlagsPlayerUpgrade) ? upgrade2 : null);
					if (val != null)
					{
						FieldRef<SetFlagsPlayerUpgrade, PlayerUpgradeFlagField> val2 = AccessTools.FieldRefAccess<SetFlagsPlayerUpgrade, PlayerUpgradeFlagField>("flags");
						val2.Invoke(val).flags = (PlayerUpgradeFlags)16;
					}
				}
			}
		}

		[HarmonyPatch(typeof(GunData), "UpdateWantsToFire")]
		public static class FireWhileSprintingSpawnFix
		{
			public static void Postfix(Player player, ref bool __result, ref GunData __instance, bool isAiming, bool reloading, float lastPressedFireTime, float lastFireTime)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Invalid comparison between Unknown and I4
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Invalid comparison between Unknown and I4
				if (!__result && (int)__instance.fireConstraints.canFireWhileSprinting == 1 && !player.IsSprinting && player.IsRunning && !isAiming && ((int)__instance.fireConstraints.canReloadWhileSprinting != 2 || !reloading) && Time.time - Mathf.Max(lastFireTime, lastPressedFireTime) > 0.5f)
				{
					player.ResumeSprint();
				}
			}
		}

		internal static ManualLogSource Logger;

		public const string PLUGIN_GUID = "DBR.MiscFixes";

		public const string PLUGIN_NAME = "MiscFixes";

		public const string PLUGIN_VERSION = "1.7.1";

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin DBR.MiscFixes is loaded");
			Harmony val = new Harmony("DBR.MiscFixes");
			try
			{
				val.PatchAll();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error applying patches: " + ex.Message));
			}
		}

		private static IEnumerator<StatData> GetStatData(UpgradeProperty_ThrowableCooldown instance, float ratio)
		{
			StatData val = StatData.Create(TextBlocks.GetString("recharge_s"), GetAdjustedValue(instance.rechargeDuration.data.max, ratio), (OverrideType)2, (LabelType)1, (string)null);
			yield return ((StatData)(ref val)).WithPatternRatio(ratio, false);
			yield return StatData.Create(TextBlocks.GetString("recharge_max"), instance.maxCharges.data.max, (OverrideType)1, (LabelType)1, (string)null);
		}

		private static float GetAdjustedValue(float value, float ratio)
		{
			return 1f + (1f / value - 1f) * ratio;
		}
	}
}