Decompiled source of ScalingTumbleLaunch v1.0.1

RepoTumbleDLL2.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ScalingTumbleLaunch
{
	[BepInPlugin("sirinfinity.ScalingTumbleLaunch", "Scaling Tumble Launch", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ScalingTumbleLaunchBase : BaseUnityPlugin
	{
		public enum ScalingMethod
		{
			BetterTumble,
			Linear,
			SquareRoot,
			CubeRoot,
			Logarithmic,
			Quadratic,
			Cubic
		}

		private const string ModGUID = "sirinfinity.ScalingTumbleLaunch";

		private const string ModName = "Scaling Tumble Launch";

		private const string ModVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("sirinfinity.ScalingTumbleLaunch");

		internal static ManualLogSource mls;

		public static ConfigEntry<bool> NoSelfDamage;

		public static ConfigEntry<float> DamageScale;

		public static ConfigEntry<ScalingMethod> DamageScalingMethod;

		private void Awake()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			mls = ((BaseUnityPlugin)this).Logger;
			mls.LogInfo((object)"Scaling Tumble Launch is active");
			NoSelfDamage = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "Disable self-damage", true, "Prevents tumble launch from damaging yourself.");
			DamageScale = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "Damage scale", 1.2f, new ConfigDescription("Adjusts the damage scaling factor.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 100f), Array.Empty<object>()));
			DamageScalingMethod = ((BaseUnityPlugin)this).Config.Bind<ScalingMethod>("Gameplay", "Damage scaling method", ScalingMethod.Linear, "Controls how Tumble Launch upgrades scale damage. BetterTumble ignores upgrade count and uses Damage scale as a flat multiplier.");
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		public static float GetDamageMultiplier(int launchUpgradeCount)
		{
			int num = Mathf.Max(launchUpgradeCount, 0);
			float value = DamageScale.Value;
			return DamageScalingMethod.Value switch
			{
				ScalingMethod.BetterTumble => value, 
				ScalingMethod.Linear => value * (float)Mathf.Max(num, 1), 
				ScalingMethod.SquareRoot => value * Mathf.Sqrt((float)Mathf.Max(num, 1)), 
				ScalingMethod.CubeRoot => value * Mathf.Pow((float)Mathf.Max(num, 1), 1f / 3f), 
				ScalingMethod.Logarithmic => value * Mathf.Log((float)(Mathf.Max(num, 1) + 1), 2f), 
				ScalingMethod.Quadratic => value * (float)Mathf.Max(num * num, 1), 
				ScalingMethod.Cubic => value * (float)Mathf.Max(num * num * num, 1), 
				_ => value * (float)Mathf.Max(num, 1), 
			};
		}
	}
}
namespace ScalingTumbleLaunch.Patches
{
	[HarmonyPatch(typeof(HurtCollider))]
	internal class HurtColliderPatch
	{
		public class ModifiedDamage : MonoBehaviour
		{
			public int baseDamage;
		}

		[HarmonyPatch("EnemyHurt")]
		[HarmonyPrefix]
		private static void EnemyHurtPrefix(HurtCollider __instance, out int __state)
		{
			__state = __instance.enemyDamage;
			PlayerTumble componentInParent = ((Component)__instance).GetComponentInParent<PlayerTumble>();
			if (!((Object)(object)componentInParent == (Object)null) && __instance.enemyDamage > 0)
			{
				ModifiedDamage modifiedDamage = default(ModifiedDamage);
				if (!((Component)__instance).TryGetComponent<ModifiedDamage>(ref modifiedDamage))
				{
					modifiedDamage = ((Component)__instance).gameObject.AddComponent<ModifiedDamage>();
					modifiedDamage.baseDamage = __instance.enemyDamage;
				}
				int launchUpgradeCount = GetLaunchUpgradeCount(componentInParent);
				float damageMultiplier = ScalingTumbleLaunchBase.GetDamageMultiplier(launchUpgradeCount);
				ScalingTumbleLaunchBase.mls.LogInfo((object)($"Mode: {ScalingTumbleLaunchBase.DamageScalingMethod.Value}, " + $"Launch upgrades: {launchUpgradeCount}, " + $"Scale: {ScalingTumbleLaunchBase.DamageScale.Value}, " + $"Final multiplier: {damageMultiplier}"));
				__instance.enemyDamage = Mathf.RoundToInt((float)modifiedDamage.baseDamage * damageMultiplier);
			}
		}

		[HarmonyPatch("EnemyHurt")]
		[HarmonyPostfix]
		private static void EnemyHurtPostfix(HurtCollider __instance, int __state)
		{
			__instance.enemyDamage = __state;
		}

		private static int GetLaunchUpgradeCount(PlayerTumble playerTumble)
		{
			PlayerAvatar playerAvatar = playerTumble.playerAvatar;
			if ((Object)(object)playerAvatar == (Object)null || (Object)(object)StatsManager.instance == (Object)null)
			{
				return 0;
			}
			string text = SemiFunc.PlayerGetSteamID(playerAvatar);
			if (string.IsNullOrEmpty(text))
			{
				return 0;
			}
			Dictionary<string, int> dictionary = StatsManager.instance.FetchPlayerUpgrades(text);
			if (dictionary == null)
			{
				return 0;
			}
			if (dictionary.TryGetValue("playerUpgradeLaunch", out var value))
			{
				return value;
			}
			if (dictionary.TryGetValue("Launch", out value))
			{
				return value;
			}
			return 0;
		}
	}
	[HarmonyPatch(typeof(PlayerTumble))]
	internal class PlayerTumblePatch
	{
		[HarmonyPatch("HitEnemy")]
		[HarmonyPrefix]
		private static bool HitEnemyPrefix()
		{
			return !ScalingTumbleLaunchBase.NoSelfDamage.Value;
		}
	}
}