Decompiled source of SomePerkMod v1.0.0

SomePerkMod.dll

Decompiled 21 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
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 SomePerkMod;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;

[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("SomePerkMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SomePerkMod")]
[assembly: AssemblyTitle("SomePerkMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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;
		}
	}
}
public static class modpextension
{
	public static Hand[] GetOpenHands(this ENT_Player plr)
	{
		List<Hand> list = new List<Hand>();
		Hand[] hands = plr.hands;
		foreach (Hand val in hands)
		{
			if (val.IsFree() && InputManager.GetButton(val.fireButton).Pressed)
			{
				list.Add(val);
			}
		}
		return list.ToArray();
	}

	public static Vector3 GetVelocity(this ENT_Player plr)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		return (Vector3)new Traverse((object)plr).Field("vel").GetValue();
	}
}
namespace SomePerkMod
{
	[BepInPlugin("SomePerkMod", "SomePerkMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
		}
	}
	public class Patches
	{
		private static AssetBundle bundle;

		[HarmonyPatch(typeof(CL_AssetManager), "InitializeAssetManager")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void AssetEntry(CL_AssetManager __instance)
		{
			if ((Object)(object)bundle == (Object)null)
			{
				string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "perkbundle1");
				bundle = AssetBundle.LoadFromFile(text);
			}
			Perk[] array = bundle.LoadAllAssets<Perk>();
			WKAssetDatabase baseAssetDatabase = CL_AssetManager.GetBaseAssetDatabase();
			Perk[] array2 = array;
			foreach (Perk item in array2)
			{
				if (!baseAssetDatabase.perkAssets.Contains(item))
				{
					baseAssetDatabase.perkAssets.Add(item);
				}
			}
			CL_AssetManager.RefreshDatabaseList();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SomePerkMod";

		public const string PLUGIN_NAME = "SomePerkMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace UnityBundleExport
{
	public class PerkModule_Bouncy : PerkModule
	{
		public static Harmony harmony;

		public AudioClip launchClip;

		public static UnityEvent onFall = new UnityEvent();

		public override void Initialize(Perk p)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			((PerkModule)this).Initialize(p);
			ENT_Player player = ENT_Player.GetPlayer();
			if (harmony == null)
			{
				harmony = new Harmony("module_bouncy");
				harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ENT_Player), "Damage", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PerkModule_Bouncy), "DamagePrefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ENT_Player), "FallingDamage", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PerkModule_Bouncy), "Transpiler", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			onFall.AddListener(new UnityAction(Fell));
		}

		public override void OnDestroy(Perk p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			((PerkModule)this).OnDestroy(p);
			onFall.RemoveListener(new UnityAction(Fell));
		}

		public static void DamagePrefix(ENT_Player __instance, ref DamageInfo info)
		{
			if (!(info.type != "falling"))
			{
				float num = Mathf.Clamp01(1f - ((GameEntity)__instance).curBuffs.GetBuff("fallDamageResist"));
				DamageInfo obj = info;
				obj.amount *= num;
			}
		}

		public void Fell()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			float buff = ((GameEntity)ENT_Player.playerObject).curBuffs.GetBuff("bounciness");
			if (!(buff <= 0f))
			{
				float currentFallDistance = ENT_Player.playerObject.GetCurrentFallDistance();
				if (!ENT_Player.playerObject.IsHanging() && !(currentFallDistance < 5f))
				{
					float num = buff * (currentFallDistance / 8f);
					Debug.Log((object)("applying: " + num));
					AudioManager.PlaySound(launchClip, ((Component)ENT_Player.playerObject).transform.position, Mathf.Clamp01(0.5f + Mathf.Min(0f, num - 1f) * 0.1f), 1f, 1f, false, 1f, (AudioMixerGroup)null, "");
					((GameEntity)ENT_Player.playerObject).AddForce(new Vector3(0f, num), "");
				}
			}
		}

		public static void FallingHandler()
		{
			onFall.Invoke();
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			int num = -1;
			Plugin.Logger.LogDebug((object)string.Join(Environment.NewLine, instructions));
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			bool flag = false;
			for (int i = 0; i < list.Count; i++)
			{
				if (flag && ((object)list[i]).ToString() == "stfld bool ENT_Player::falling")
				{
					Plugin.Logger.LogDebug((object)"found it");
					num = i;
					break;
				}
				flag = ((list[i].opcode == OpCodes.Ldc_I4_0) ? true : false);
			}
			if (num > -1)
			{
				list.Insert(num, CodeInstruction.Call((Expression<Action>)(() => FallingHandler())));
			}
			return list.AsEnumerable();
		}
	}
	public class PerkModule_DisableScoreUpload : PerkModule
	{
		public static Harmony harmony;

		public override void Initialize(Perk p)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			((PerkModule)this).Initialize(p);
			Buff item = new Buff
			{
				id = "buffDisableLeaderboard",
				amount = 2f,
				maxAmount = 2f
			};
			BuffContainer val = new BuffContainer
			{
				multiplier = 1f,
				id = "cheateralert",
				loseOverTime = false,
				buffs = new List<Buff> { item }
			};
			((GameEntity)p.player).curBuffs.AddBuff(val);
			if (harmony == null)
			{
				harmony = new Harmony("module_cheatperkmodule");
				harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(M_Gamemode), "Finish", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PerkModule_DisableScoreUpload), "CheatFinishInject", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static void CheatFinishInject()
		{
			if (((GameEntity)ENT_Player.playerObject).curBuffs.GetBuff("buffDisableLeaderboard") > 0f)
			{
				WorldLoader.customSeed = true;
			}
		}
	}
	public class PerkModule_DrainOpenGrip : PerkModule
	{
		public float gripLostPerSecond = 5f;

		private float currentLossPS = -69420f;

		public float gripLossIncreasePerSecond = 0f;

		public bool onlyWhileFalling = false;

		public bool bothHandsMustBeOpen = false;

		public override void Initialize(Perk p)
		{
			((PerkModule)this).Initialize(p);
			currentLossPS = gripLostPerSecond;
		}

		public override void Update()
		{
			if (onlyWhileFalling && (base.perk.player.IsGrounded(false) || base.perk.player.IsHanging()))
			{
				currentLossPS = Mathf.Clamp(currentLossPS - gripLossIncreasePerSecond * Time.deltaTime, gripLostPerSecond, float.PositiveInfinity);
				return;
			}
			Hand[] openHands = base.perk.player.GetOpenHands();
			if (openHands.Length == 0 || (bothHandsMustBeOpen && openHands.Length != base.perk.player.hands.Length))
			{
				currentLossPS = Mathf.Clamp(currentLossPS - gripLossIncreasePerSecond * Time.deltaTime, gripLostPerSecond, float.PositiveInfinity);
				return;
			}
			Hand[] array = openHands;
			foreach (Hand val in array)
			{
				val.AddGripStrength((0f - currentLossPS) * Time.deltaTime);
				currentLossPS += gripLossIncreasePerSecond * Time.deltaTime;
				if (val.GetGripStrength() < 0.1f)
				{
					val.grabWait += Time.deltaTime;
				}
			}
		}
	}
	public class PerkModule_ReversedReceptorsBehavior : PerkModule
	{
		public static Harmony harmony;

		public AnimationCurve buffCurve;

		public override void Initialize(Perk p)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			((PerkModule)this).Initialize(p);
			ENT_Player player = ENT_Player.GetPlayer();
			if (harmony == null)
			{
				harmony = new Harmony("module_reverserec");
				harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Hand), "GetStaminaDrainColor", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PerkModule_ReversedReceptorsBehavior), "StamInject", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public override void Update()
		{
			base.perk.buff.SetMultiplier(Mathf.Clamp01(buffCurve.Evaluate(1f - base.perk.player.GetLowestGripStrength() / base.perk.player.GetCurrentGripStrengthTimer(-1))));
		}

		public static void StamInject(ref Color __result)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player player = ENT_Player.GetPlayer();
			if (!((Object)(object)player == (Object)null) && player.HasPerk("modex_reverserec"))
			{
				__result = Color.white;
			}
		}
	}
	public class PerkModule_WebbedFingersBehavior : PerkModule
	{
		public override void Initialize(Perk p)
		{
			((PerkModule)this).Initialize(p);
		}

		public override void Update()
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Hand[] openHands = ENT_Player.GetPlayer().GetOpenHands();
			foreach (Hand val in openHands)
			{
				if (!(val.GetGripStrength() < 0.1f))
				{
					num++;
				}
			}
			base.perk.buff.SetMultiplier((num == base.perk.player.hands.Count()) ? 1f : 0f);
			base.perk.baseBuff.SetMultiplier((!base.perk.player.IsGrounded(false) && !base.perk.player.IsHanging() && Mathf.Abs(base.perk.player.GetVelocity().y) > 0.01f) ? 1f : 0f);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}