Decompiled source of OnePunchMod v1.0.0

BepInEx/plugins/OnePunchMod.dll

Decompiled an hour 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.Logging;
using Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("OnePunchMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OnePunchMod")]
[assembly: AssemblyTitle("OnePunchMod")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OnePunchMod
{
	[HarmonyPatch(typeof(Punch), "PunchSuccess")]
	internal static class PunchDamagePatch
	{
		private const float OnePunchDamage = 1E+09f;

		private static void Prefix(Punch __instance, ref float ___damage, out float __state)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			__state = ___damage;
			if ((int)__instance.type == 0 && ((ConfigValueElement<bool>)(object)Plugin.FeedbackerOnePunch).Value)
			{
				___damage = 1E+09f;
			}
			else if ((int)__instance.type == 1 && ((ConfigValueElement<bool>)(object)Plugin.KnuckleblasterOnePunch).Value)
			{
				___damage = 1E+09f;
			}
		}

		private static Exception Finalizer(Exception __exception, ref float ___damage, float __state)
		{
			___damage = __state;
			return __exception;
		}
	}
	[HarmonyPatch(typeof(HookArm), "FixedUpdate")]
	internal static class WhiplashDamagePatch
	{
		internal static float GetWhiplashDamage()
		{
			return ((ConfigValueElement<bool>)(object)Plugin.WhiplashOnePunch).Value ? 1E+09f : 0.2f;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo methodInfo = AccessTools.Method(typeof(WhiplashDamagePatch), "GetWhiplashDamage", (Type[])null, (Type[])null);
			int num = 0;
			for (int i = 0; i + 6 < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_R4 && list[i].operand is float num2 && Math.Abs(num2 - 0.2f) < 0.0001f && list[i + 1].opcode == OpCodes.Ldc_I4_0 && list[i + 2].opcode == OpCodes.Ldc_R4 && list[i + 3].opcode == OpCodes.Ldnull && list[i + 4].opcode == OpCodes.Ldc_I4_0 && list[i + 5].opcode == OpCodes.Ldc_I4_0 && list[i + 6].opcode == OpCodes.Callvirt && list[i + 6].operand is MethodInfo { Name: "DeliverDamage" } methodInfo2 && methodInfo2.DeclaringType == typeof(EnemyIdentifier))
				{
					list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo);
					num++;
				}
			}
			Plugin.Log.LogInfo((object)("Whiplash patch matched " + num + " normal-hit location(s)."));
			return list;
		}
	}
	[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
	internal static class OneBillionStyleKillPatch
	{
		private const int StylePointsPerKill = 1000000000;

		private static readonly ConditionalWeakTable<EnemyIdentifier, object> AwardedKills = new ConditionalWeakTable<EnemyIdentifier, object>();

		private static void Prefix(EnemyIdentifier __instance, out float __state)
		{
			__state = (((Object)(object)__instance != (Object)null) ? __instance.health : 0f);
		}

		private static void Postfix(EnemyIdentifier __instance, float __state, GameObject sourceWeapon)
		{
			if (!((ConfigValueElement<bool>)(object)Plugin.OneBillionStylePerKill).Value || (Object)(object)__instance == (Object)null || __state <= 0f || !__instance.dead || __instance.health >= __state)
			{
				return;
			}
			string hitter = __instance.hitter;
			int num;
			switch (hitter)
			{
			default:
				num = ((hitter == "hammer") ? 1 : 0);
				break;
			case "punch":
			case "heavypunch":
			case "ground slam":
				num = 1;
				break;
			}
			bool flag = (byte)num != 0;
			if ((!((Object)(object)sourceWeapon == (Object)null) || flag) && !AwardedKills.TryGetValue(__instance, out var _))
			{
				StyleHUD instance = MonoSingleton<StyleHUD>.Instance;
				if (!((Object)(object)instance == (Object)null))
				{
					AwardedKills.Add(__instance, new object());
					instance.AddPoints(1000000000, "ultrakill.finishedoff", (GameObject)null, __instance, -1, "", "");
					Plugin.Log.LogInfo((object)"Awarded 1 billion style points for an enemy kill.");
				}
			}
		}
	}
	[BepInPlugin("com.onepunch.ultrakill", "One Punch Bot", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigBuilder config;

		[Configgable("One Punch", "Feedbacker One Punch", 0, null)]
		public static ConfigToggle FeedbackerOnePunch = new ConfigToggle(false);

		[Configgable("One Punch", "Knuckleblaster One Punch", 0, null)]
		public static ConfigToggle KnuckleblasterOnePunch = new ConfigToggle(false);

		[Configgable("One Punch", "Whiplash One Punch", 0, null)]
		public static ConfigToggle WhiplashOnePunch = new ConfigToggle(false);

		[Configgable("One Punch", "One Billion Style Per Kill", 0, null)]
		public static ConfigToggle OneBillionStylePerKill = new ConfigToggle(false);

		private Harmony harmony;

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			config = new ConfigBuilder("com.onepunch.ultrakill", "One Punch Bot");
			config.BuildAll();
			harmony = new Harmony("com.onepunch.ultrakill");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"One Punch Bot 1.0.0 initialized.");
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}