Decompiled source of Cleaverang v1.0.3

plugins/Cleaverang.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dolso;
using EntityStates;
using EntityStates.Chef;
using HG;
using HG.Reflection;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Projectile;
using RoR2.Skills;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Cleaverang")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Cleaverang")]
[assembly: AssemblyTitle("Cleaverang")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Dolso
{
	internal static class log
	{
		private static ManualLogSource logger;

		internal static void start(ManualLogSource logSource)
		{
			logger = logSource;
		}

		internal static void start(string name)
		{
			logger = Logger.CreateLogSource(name);
		}

		[Conditional("DEBUG")]
		internal static void debug(object data)
		{
			logger.LogDebug(data);
		}

		internal static void info(object data)
		{
			logger.LogInfo(data);
		}

		internal static void message(object data)
		{
			logger.LogMessage(data);
		}

		internal static void warning(object data)
		{
			logger.LogWarning(data);
		}

		internal static void error(object data)
		{
			logger.LogError(data);
		}

		internal static void fatal(object data)
		{
			logger.LogFatal(data);
		}

		internal static void LogError(this ILCursor c, object data)
		{
			logger.LogError((object)string.Format($"ILCursor failure, skipping: {data}\n{c}"));
		}

		internal static void LogErrorCaller(this ILCursor c, object data)
		{
			logger.LogError((object)string.Format($"ILCursor failed in {new StackFrame(1).GetMethod().Name}, skipping: {data}\n{c}"));
		}
	}
	internal static class HookManager
	{
		internal delegate bool ConfigEnabled<T>(ConfigEntry<T> configEntry);

		internal const BindingFlags allFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly ConfigEnabled<bool> boolConfigEnabled = (ConfigEntry<bool> configEntry) => configEntry.Value;

		private static ILHookConfig ilHookConfig = new ILHookConfig
		{
			ManualApply = true
		};

		private static HookConfig onHookConfig = new HookConfig
		{
			ManualApply = true
		};

		internal static void Hook(Type typeFrom, string methodFrom, Manipulator ilHook)
		{
			HookInternal(GetMethod(typeFrom, methodFrom), ilHook);
		}

		internal static void Hook(MethodBase methodFrom, Manipulator ilHook)
		{
			HookInternal(methodFrom, ilHook);
		}

		internal static void Hook(Delegate from, Manipulator ilHook)
		{
			HookInternal(from.Method, ilHook);
		}

		internal static void Hook(Type typeFrom, string methodFrom, Delegate onHook)
		{
			HookInternal(GetMethod(typeFrom, methodFrom), onHook.Method, onHook.Target);
		}

		internal static void Hook(MethodBase methodFrom, MethodInfo onHook)
		{
			HookInternal(methodFrom, onHook, null);
		}

		internal static void Hook(MethodBase methodFrom, Delegate onHook)
		{
			HookInternal(methodFrom, onHook.Method, onHook.Target);
		}

		internal static void Hook(Delegate from, Delegate onHook)
		{
			HookInternal(from.Method, onHook.Method, onHook.Target);
		}

		internal static void Hook(Type typeFrom, string methodFrom, Delegate onHook, object instance)
		{
			HookInternal(GetMethod(typeFrom, methodFrom), onHook.Method, instance);
		}

		internal static void Hook(MethodBase methodFrom, MethodInfo onHook, object target)
		{
			HookInternal(methodFrom, onHook, target);
		}

		private static void HookInternal(MethodBase methodFrom, Manipulator ilHook)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (methodFrom == null)
			{
				log.error("null methodFrom for hook: " + ((Delegate)(object)ilHook).Method.Name);
				return;
			}
			try
			{
				new ILHook(methodFrom, ilHook, ref ilHookConfig).Apply();
			}
			catch (Exception ex)
			{
				log.error($"Failed to apply ILHook: {methodFrom.DeclaringType}::{methodFrom.Name} - {((Delegate)(object)ilHook).Method.Name}\n{ex}");
			}
		}

		private static void HookInternal(MethodBase methodFrom, MethodInfo onHook, object target)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (methodFrom == null)
			{
				log.error("null methodFrom for hook: " + onHook.Name);
				return;
			}
			try
			{
				new Hook(methodFrom, onHook, target, ref onHookConfig).Apply();
			}
			catch (Exception ex)
			{
				log.error($"Failed to apply Hook: {methodFrom.DeclaringType}::{methodFrom.Name} - {onHook.Name}\n{ex}");
			}
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, Type typeFrom, string methodFrom, Manipulator ilHook)
		{
			configEntry.HookConfigInternal(boolConfigEnabled, GetMethod(typeFrom, methodFrom), (Delegate)(object)ilHook);
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, MethodBase methodFrom, Manipulator ilHook)
		{
			configEntry.HookConfigInternal(boolConfigEnabled, methodFrom, (Delegate)(object)ilHook);
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, Type typeFrom, string methodFrom, Delegate onHook)
		{
			configEntry.HookConfigInternal(boolConfigEnabled, GetMethod(typeFrom, methodFrom), onHook);
		}

		internal static void HookConfig(this ConfigEntry<bool> configEntry, MethodBase methodFrom, Delegate onHook)
		{
			configEntry.HookConfigInternal(boolConfigEnabled, methodFrom, onHook);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, Type typeFrom, string methodFrom, Manipulator ilHook)
		{
			configEntry.HookConfigInternal(enabled, GetMethod(typeFrom, methodFrom), (Delegate)(object)ilHook);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, MethodBase methodFrom, Manipulator ilHook)
		{
			configEntry.HookConfigInternal(enabled, methodFrom, (Delegate)(object)ilHook);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, Type typeFrom, string methodFrom, Delegate onHook)
		{
			configEntry.HookConfigInternal(enabled, GetMethod(typeFrom, methodFrom), onHook);
		}

		internal static void HookConfig<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, MethodBase methodFrom, Delegate onHook)
		{
			configEntry.HookConfigInternal(enabled, methodFrom, onHook);
		}

		private static void HookConfigInternal<T>(this ConfigEntry<T> configEntry, ConfigEnabled<T> enabled, MethodBase methodFrom, Delegate hook)
		{
			try
			{
				IDetour detour = ManualDetour(methodFrom, hook);
				configEntry.SettingChanged += delegate(object sender, EventArgs _)
				{
					UpdateHook(detour, enabled(sender as ConfigEntry<T>));
				};
				if (enabled(configEntry))
				{
					detour.Apply();
				}
			}
			catch (Exception ex)
			{
				log.error($"Failed to do config hook {methodFrom.DeclaringType}::{methodFrom.Name} - {hook.Method.Name}\n{ex}");
			}
		}

		private static void UpdateHook(IDetour hook, bool enabled)
		{
			if (enabled)
			{
				if (!hook.IsApplied)
				{
					hook.Apply();
				}
			}
			else if (hook.IsApplied)
			{
				hook.Undo();
			}
		}

		internal static IDetour ManualDetour(Type typeFrom, string methodFrom, Delegate hook)
		{
			return ManualDetour(GetMethod(typeFrom, methodFrom), hook);
		}

		internal static IDetour ManualDetour(MethodBase methodFrom, Delegate hook)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if (methodFrom == null)
			{
				log.error("null methodFrom for detour: " + hook.Method.Name);
			}
			else
			{
				try
				{
					Manipulator val = (Manipulator)(object)((hook is Manipulator) ? hook : null);
					if (val != null)
					{
						return (IDetour)new ILHook(methodFrom, val, ref ilHookConfig);
					}
					return (IDetour)new Hook(methodFrom, hook, ref onHookConfig);
				}
				catch (Exception ex)
				{
					log.error($"Failed to create detour {methodFrom.DeclaringType}::{methodFrom} - {hook.Method.Name}\n{ex}");
				}
			}
			return null;
		}

		internal static MethodInfo GetMethod(Type typeFrom, string methodName)
		{
			if (typeFrom == null || methodName == null)
			{
				log.error($"Null argument in GetMethod: type={typeFrom}, name={methodName}");
				return null;
			}
			MethodInfo[] array = (from predicate in typeFrom.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where predicate.Name == methodName
				select predicate).ToArray();
			switch (array.Length)
			{
			case 1:
				return array[0];
			case 0:
				log.error($"Failed to find method: {typeFrom}::{methodName}");
				return null;
			default:
			{
				log.error($"{array.Length} ambiguous matches found for: {typeFrom}::{methodName}");
				MethodInfo[] array2 = array;
				foreach (MethodInfo data in array2)
				{
					log.error(data);
				}
				return null;
			}
			}
		}

		internal static MethodInfo GetMethod(Type typeFrom, string methodName, params Type[] parameters)
		{
			if (typeFrom == null || methodName == null)
			{
				log.error($"Null argument in GetMethod: type={typeFrom}, name={methodName}");
				return null;
			}
			MethodInfo method = typeFrom.GetMethod(methodName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameters, null);
			if (method == null)
			{
				log.error($"Failed to find method: {typeFrom}::{methodName}_{parameters.Length}");
			}
			return method;
		}

		internal static void SetPriority(string[] before = null, string[] after = null)
		{
			ilHookConfig.Before = before;
			onHookConfig.Before = before;
			ilHookConfig.After = after;
			onHookConfig.After = after;
		}
	}
	internal static class Utilities
	{
		private static GameObject _prefabParent;

		internal static GameObject CreatePrefab(GameObject gameObject, string name = null)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_prefabParent))
			{
				_prefabParent = new GameObject("DolsoPrefabs");
				Object.DontDestroyOnLoad((Object)(object)_prefabParent);
				((Object)_prefabParent).hideFlags = (HideFlags)61;
				_prefabParent.SetActive(false);
			}
			GameObject val = Object.Instantiate<GameObject>(gameObject, _prefabParent.transform);
			if (name != null)
			{
				((Object)val).name = name;
			}
			return val;
		}

		internal static Task<Obj> GetAddressableAsync<Obj>(string addressable) where Obj : Object
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Addressables.LoadAssetAsync<Obj>((object)addressable).Task;
		}

		internal static Task<GameObject> GetAddressableAsync(string addressable)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Addressables.LoadAssetAsync<GameObject>((object)addressable).Task;
		}

		internal static void DoAddressable<Obj>(string addressable, Action<Obj> callback) where Obj : Object
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<Obj> val = Addressables.LoadAssetAsync<Obj>((object)addressable);
			val.Completed += delegate(AsyncOperationHandle<Obj> a)
			{
				callback(a.Result);
			};
		}

		internal static void DoAddressable(string addressable, Action<GameObject> callback)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)addressable);
			val.Completed += delegate(AsyncOperationHandle<GameObject> a)
			{
				callback(a.Result);
			};
		}

		internal static void AddressableAddComp<Comp>(string addressable) where Comp : Component
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)addressable);
			val.Completed += delegate(AsyncOperationHandle<GameObject> a)
			{
				a.Result.AddComponent<Comp>();
			};
		}

		internal static void AddressableAddComp<Comp>(string addressable, Action<Comp> callback) where Comp : Component
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)addressable);
			val.Completed += delegate(AsyncOperationHandle<GameObject> a)
			{
				callback(a.Result.AddComponent<Comp>());
			};
		}

		internal static void AddressableAddCompSingle<Comp>(string addressable) where Comp : Component
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)addressable);
			val.Completed += delegate(AsyncOperationHandle<GameObject> a)
			{
				if (!Object.op_Implicit((Object)(object)a.Result.GetComponent<Comp>()))
				{
					a.Result.AddComponent<Comp>();
				}
			};
		}
	}
	internal static class RiskofOptions
	{
		internal const string rooGuid = "com.rune580.riskofoptions";

		internal static bool enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		internal static void SetSprite(Sprite sprite)
		{
			ModSettingsManager.SetModIcon(sprite);
		}

		internal static void SetSpriteDefaultIcon()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				string fullName = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName;
				Texture2D val = new Texture2D(256, 256);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(fullName, "icon.png"))))
				{
					ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)));
				}
				else
				{
					log.error("Failed to load icon.png");
				}
			}
			catch (Exception ex)
			{
				log.error("Failed to load icon.png\n" + ex);
			}
		}

		internal static void AddOption<T>(ConfigEntry<T> entry)
		{
			AddOption<T>(entry, "", "", restartRequired: false);
		}

		internal static void AddOption<T>(ConfigEntry<T> entry, string categoryName = "", string name = "", bool restartRequired = false)
		{
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (!(typeof(T) == typeof(float)))
			{
				obj = ((!(typeof(T) == typeof(string))) ? ((!(typeof(T) == typeof(bool))) ? ((!(typeof(T) == typeof(int))) ? ((!(typeof(T) == typeof(Color))) ? ((!(typeof(T) == typeof(KeyboardShortcut))) ? ((object)((!typeof(T).IsEnum) ? ((ChoiceOption)null) : new ChoiceOption((ConfigEntryBase)(object)entry, new ChoiceConfig()))) : ((object)new KeyBindOption(entry as ConfigEntry<KeyboardShortcut>, new KeyBindConfig()))) : ((object)new ColorOption(entry as ConfigEntry<Color>, new ColorOptionConfig()))) : ((object)new IntFieldOption(entry as ConfigEntry<int>, new IntFieldConfig()))) : ((object)new CheckBoxOption(entry as ConfigEntry<bool>, new CheckBoxConfig()))) : ((object)new StringInputFieldOption(entry as ConfigEntry<string>, new InputFieldConfig
				{
					submitOn = (SubmitEnum)6,
					lineType = (LineType)0
				})));
			}
			else
			{
				ConfigEntry<float> obj2 = entry as ConfigEntry<float>;
				FloatFieldConfig val = new FloatFieldConfig();
				((NumericFieldConfig<float>)val).FormatString = "{0:f2}";
				((BaseOptionConfig)val).description = ((ConfigEntryBase)(object)entry).DescWithDefault("{0:f2}");
				obj = (object)new FloatFieldOption(obj2, val);
			}
			BaseOption val2 = (BaseOption)obj;
			if (val2 != null)
			{
				BaseOptionConfig config = val2.GetConfig();
				config.category = categoryName;
				config.name = name;
				config.restartRequired = restartRequired;
				if (config.description == "")
				{
					config.description = ((ConfigEntryBase)(object)entry).DescWithDefault();
				}
				ModSettingsManager.AddOption(val2);
			}
		}

		internal static void AddOption(ConfigEntry<float> entry, float min, float max, string format = "{0:f2}")
		{
			AddFloatSlider(entry, min, max, format);
		}

		internal static void AddFloatSlider(ConfigEntry<float> entry, float min, float max, string format = "{0:f2}", string categoryName = "")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new SliderOption(entry, new SliderConfig
			{
				min = min,
				max = max,
				FormatString = format,
				category = categoryName,
				description = ((ConfigEntryBase)(object)entry).DescWithDefault(format)
			}));
		}

		internal static void AddIntSlider(ConfigEntry<int> entry, int min, int max, string categoryName = "")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_002c: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(entry, new IntSliderConfig
			{
				min = min,
				max = max,
				category = categoryName,
				description = ((ConfigEntryBase)(object)entry).DescWithDefault()
			}));
		}

		private static string DescWithDefault(this ConfigEntryBase entry)
		{
			return $"{entry.Description.Description}\n[Default: {entry.DefaultValue}]";
		}

		private static string DescWithDefault(this ConfigEntryBase entry, string format)
		{
			return string.Format("{1}\n[Default: " + format + "]", entry.DefaultValue, entry.Description.Description);
		}
	}
}
namespace Cleaverang
{
	internal class Config
	{
		private static ConfigFile configFile;

		private static ConfigEntry<string> version;

		internal static ConfigEntry<float> damage;

		internal static ConfigEntry<float> bleedChance;

		internal static ConfigEntry<float> procCoef;

		internal static ConfigEntry<float> cooldown;

		internal static ConfigEntry<float> interval;

		internal static void DoConfig(ConfigFile bepConfigFile)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			configFile = bepConfigFile;
			damage = configFile.Bind<float>("Stats", "Damage", 0.8f, "Damage multiplier of hits");
			bleedChance = configFile.Bind<float>("Stats", "Bleed Chance", 40f, new ConfigDescription("Bleed chance of boosted (from Yes Chef) Cleaverangs", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			procCoef = configFile.Bind<float>("Stats", "Proc Coefficient", 1f, "Proc coefficient of the repeated hits");
			cooldown = configFile.Bind<float>("Stats", "Cooldown", 2.25f, "Cooldown of Cleaverang. For reference vanilla Dice cooldown is 1.75s");
			interval = configFile.Bind<float>("Stats", "Attack Interval", 0.5f, "Interval between attacks");
			version = configFile.Bind<string>("", "Config Version", "1.0.3", "Config version, if this is different from current version, resets config");
			if (version.Value != "1.0.3")
			{
				configFile.Clear();
				DoConfig(configFile);
			}
			else if (RiskofOptions.enabled)
			{
				DoRiskOfOptions();
			}
		}

		internal static void DoRiskOfOptions()
		{
			RiskofOptions.AddFloatSlider(damage, 0f, 1.5f);
			RiskofOptions.AddFloatSlider(bleedChance, 0f, 100f, "{0:f0}");
			RiskofOptions.AddFloatSlider(procCoef, 0f, 2f);
			RiskofOptions.AddFloatSlider(cooldown, 0.5f, 6f);
			RiskofOptions.AddFloatSlider(interval, 0f, 1.5f);
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void ReloadConfig(ConCommandArgs args)
		{
			configFile.Reload();
			Debug.Log((object)"Cleaverang config reloaded");
		}
	}
	internal class Content : IContentPackProvider
	{
		private static AssetBundle assetBundle;

		internal static ContentPack contentPack;

		internal static GameObject cleaverangPrefab;

		internal static GameObject cleaverangBoostedPrefab;

		internal static SkillDef cSkillDef;

		internal static SkillDef cBoostedSkillDef;

		public string identifier => "dolso.Cleaverang";

		private static string directory => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			AssetBundleCreateRequest assetBundleRequest = AssetBundle.LoadFromFileAsync(Path.Combine(directory, "cleaverang"));
			yield return LoadAsync((AsyncOperation)(object)assetBundleRequest, args);
			assetBundle = assetBundleRequest.assetBundle;
			AssetBundleRequest serializableContentPack = assetBundle.LoadAssetAsync<SerializableContentPack>("Cleaverang ContentPack");
			yield return LoadAsync((AsyncOperation)(object)serializableContentPack, args);
			Object asset = serializableContentPack.asset;
			contentPack = ((SerializableContentPack)((asset is SerializableContentPack) ? asset : null)).CreateContentPack();
			yield return DoProjectiles();
			yield return DoSkills();
			if (RiskofOptions.enabled)
			{
				yield return DoRiskOfOptions();
			}
			static IEnumerator LoadAsync(AsyncOperation request, LoadStaticContentAsyncArgs args)
			{
				while (!request.isDone)
				{
					args.ReportProgress(request.progress);
					yield return null;
				}
			}
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(contentPack, args.output);
			yield break;
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			yield break;
		}

		private static IEnumerator DoProjectiles()
		{
			AsyncOperationHandle<GameObject> sawAsync = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Saw/Sawmerang.prefab");
			AsyncOperationHandle<GameObject> muzzleFlashAsync = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Chef/MuzzleflashChefDiceReturn.prefab");
			AsyncOperationHandle<BuffDef> chefBuffAsync = Addressables.LoadAssetAsync<BuffDef>((object)"RoR2/DLC2/Chef/Buffs/bdCookingChopped.asset");
			AssetBundleRequest redMatAsync = assetBundle.LoadAssetAsync<Texture>("texSawmerangRedDiffuse");
			yield return sawAsync;
			yield return muzzleFlashAsync;
			yield return chefBuffAsync;
			yield return redMatAsync;
			ThrowCleaverang.muzzleFlashPrefab = muzzleFlashAsync.Result;
			GameObject saw = sawAsync.Result;
			GameObject c1 = (cleaverangPrefab = contentPack.projectilePrefabs.Find("CleaverangProjectile"));
			GameObject c2 = (cleaverangBoostedPrefab = contentPack.projectilePrefabs.Find("CleaverangBoostedProjectile"));
			ProjectileController sawComp = saw.GetComponent<ProjectileController>();
			ProjectileController comp2 = c1.GetComponent<ProjectileController>();
			ProjectileController comp7 = c2.GetComponent<ProjectileController>();
			comp2.ghostPrefab = sawComp.ghostPrefab;
			comp2.flightSoundLoop = (comp7.flightSoundLoop = sawComp.flightSoundLoop);
			comp7.ghostPrefab = Utilities.CreatePrefab(sawComp.ghostPrefab, "CleaverangBoostedGhost");
			MeshRenderer mesh = comp7.ghostPrefab.GetComponentInChildren<MeshRenderer>();
			Material val = new Material(((Renderer)mesh).material);
			((Object)val).name = "matSawmerangRed";
			? val2 = val;
			Object asset = redMatAsync.asset;
			((Material)val2).mainTexture = (Texture)(object)((asset is Texture) ? asset : null);
			((Renderer)mesh).material = val;
			BoomerangProjectile sawComp2 = saw.GetComponent<BoomerangProjectile>();
			BoomerangProjectile comp3 = c1.GetComponent<BoomerangProjectile>();
			BoomerangProjectile comp8 = c2.GetComponent<BoomerangProjectile>();
			comp3.impactSpark = (comp8.impactSpark = sawComp2.impactSpark);
			ProjectileDotZone sawComp3 = saw.GetComponent<ProjectileDotZone>();
			ProjectileDotZone comp4 = c1.GetComponent<ProjectileDotZone>();
			ProjectileDotZone comp10 = c2.GetComponent<ProjectileDotZone>();
			comp4.impactEffect = (comp10.impactEffect = sawComp3.impactEffect);
			comp4.overlapProcCoefficient = (comp10.overlapProcCoefficient = Config.procCoef.Value);
			ProjectileOverlapAttack sawComp4 = saw.GetComponent<ProjectileOverlapAttack>();
			ProjectileOverlapAttack comp5 = c1.GetComponent<ProjectileOverlapAttack>();
			ProjectileOverlapAttack comp9 = c2.GetComponent<ProjectileOverlapAttack>();
			comp5.impactEffect = (comp9.impactEffect = sawComp4.impactEffect);
			ProjectileInflictTimedBuff comp1 = c1.GetComponent<ProjectileInflictTimedBuff>();
			ProjectileInflictTimedBuff comp6 = c2.GetComponent<ProjectileInflictTimedBuff>();
			comp1.buffDef = (comp6.buffDef = chefBuffAsync.Result);
		}

		private static IEnumerator DoSkills()
		{
			AsyncOperationHandle<GameObject> chefBodyAsync = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/DLC2/Chef/ChefBody.prefab");
			yield return chefBodyAsync;
			cSkillDef = contentPack.skillDefs.Find("CleaverangSkillDef");
			cBoostedSkillDef = contentPack.skillDefs.Find("CleaverangBoostedSkillDef");
			cSkillDef.baseRechargeInterval = (cBoostedSkillDef.baseRechargeInterval = Config.cooldown.Value);
			cSkillDef.activationState = (cBoostedSkillDef.activationState = new SerializableEntityStateType(typeof(ThrowCleaverang)));
			contentPack.entityStateTypes.Add(new Type[1] { typeof(ThrowCleaverang) });
			ref Variant[] variants = ref chefBodyAsync.Result.GetComponent<SkillLocator>().primary.skillFamily.variants;
			Variant val = new Variant
			{
				skillDef = cSkillDef
			};
			((Variant)(ref val)).viewableNode = new Node(cSkillDef.skillNameToken, false, (Node)null);
			ArrayUtils.ArrayAppend<Variant>(ref variants, ref val);
		}

		private static IEnumerator DoRiskOfOptions()
		{
			AssetBundleRequest sprite = assetBundle.LoadAssetAsync<Sprite>("CleaverangIcon");
			yield return sprite;
			Object asset = sprite.asset;
			RiskofOptions.SetSprite((Sprite)(object)((asset is Sprite) ? asset : null));
		}
	}
	internal class Hooks
	{
		private static int cleaverangIndex;

		private static int cleaverangBoostedIndex;

		internal static void DoHooks()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			HookManager.Hook(typeof(YesChef), "OnEnter", (Delegate)new Action<Action<YesChef>, YesChef>(AddOverride_On_YesChef_OnEnter));
			HookManager.Hook(typeof(GlobalEventManager), "ProcessHitEnemy", new Manipulator(SetBleed_IL_GlobalEventManager_OnHitEnemy));
			HookManager.Hook(typeof(BoomerangProjectile), "Start", (Delegate)new Action<Action<BoomerangProjectile>, BoomerangProjectile>(SetVelocity_On_BoomerangProjectile_Start));
			HookManager.Hook(typeof(BoomerangProjectile), "FixedUpdate", new Manipulator(ChangeFlightPath_IL_BoomerangProjectile_FixedUpdate));
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnRoR2Loaded));
		}

		private static void OnRoR2Loaded()
		{
			cleaverangIndex = ProjectileCatalog.FindProjectileIndex("CleaverangProjectile");
			cleaverangBoostedIndex = ProjectileCatalog.FindProjectileIndex("CleaverangBoostedProjectile");
		}

		private static void AddOverride_On_YesChef_OnEnter(Action<YesChef> orig, YesChef self)
		{
			if ((Object)(object)((EntityState)self).skillLocator.primary.skillDef == (Object)(object)Content.cSkillDef)
			{
				self.primarySkillOverrideDef = Content.cBoostedSkillDef;
			}
			orig(self);
		}

		private static void SetBleed_IL_GlobalEventManager_OnHitEnemy(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			VariableDefinition val2 = ((IEnumerable<VariableDefinition>)val.Body.Variables).First((VariableDefinition a) => ((MemberReference)((VariableReference)a).VariableType).Name == typeof(CharacterMaster).Name);
			ILLabel branchFalse = null;
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction a) => ILPatternMatchingExt.MatchLdsfld(a, typeof(Equipment), "Saw")
			}) && val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction a) => ILPatternMatchingExt.MatchBneUn(a, ref branchFalse)
			}))
			{
				val.Emit(OpCodes.Ldarg_1);
				val.Emit(OpCodes.Ldloc, val2);
				val.EmitDelegate<Func<DamageInfo, CharacterMaster, bool>>((Func<DamageInfo, CharacterMaster, bool>)delegate(DamageInfo damageInfo, CharacterMaster master)
				{
					ProjectileController component = damageInfo.inflictor.GetComponent<ProjectileController>();
					return (!Object.op_Implicit((Object)(object)component) || (component.catalogIndex != cleaverangIndex && (component.catalogIndex != cleaverangBoostedIndex || Util.CheckRoll(Config.bleedChance.Value, master)))) ? true : false;
				});
				val.Emit(OpCodes.Brfalse, (object)branchFalse);
			}
			else
			{
				val.LogErrorCaller("saw bleed");
			}
		}

		private static void SetVelocity_On_BoomerangProjectile_Start(Action<BoomerangProjectile> orig, BoomerangProjectile self)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			orig(self);
			if (self.projectileController.catalogIndex == cleaverangBoostedIndex)
			{
				self.rigidbody.velocity = self.travelSpeed * ((Component)self).transform.forward;
			}
		}

		private static void ChangeFlightPath_IL_BoomerangProjectile_FixedUpdate(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction a) => ILPatternMatchingExt.MatchCallOrCallvirt(a, typeof(Rigidbody), "set_velocity")
			}))
			{
				return;
			}
			ILLabel val2 = val.MarkLabel();
			if (val.TryGotoPrev(new Func<Instruction, bool>[1]
			{
				(Instruction a) => ILPatternMatchingExt.MatchLdfld(a, typeof(BoomerangProjectile), "rigidbody")
			}))
			{
				val.EmitDelegate<Func<BoomerangProjectile, bool>>((Func<BoomerangProjectile, bool>)((BoomerangProjectile self) => self.projectileController.catalogIndex == cleaverangBoostedIndex));
				val.Emit(OpCodes.Brtrue, (object)val2);
				val.Emit(OpCodes.Ldarg_0);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("dolso.Cleaverang", "Cleaverang", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "dolso.Cleaverang";

		internal const string Version = "1.0.3";

		private void Awake()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			log.start(((BaseUnityPlugin)this).Logger);
			Config.DoConfig(((BaseUnityPlugin)this).Config);
			ConfigEvents();
			Hooks.DoHooks();
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(CollectContentPack);
			Language.collectLanguageRootFolders += CollectLanguageFolder;
		}

		private static void CollectContentPack(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)new Content());
		}

		private void CollectLanguageFolder(List<string> list)
		{
			list.Add(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Language"));
		}

		private static void ConfigEvents()
		{
			Config.cooldown.SettingChanged += delegate
			{
				Content.cSkillDef.baseRechargeInterval = Config.cooldown.Value;
				Content.cBoostedSkillDef.baseRechargeInterval = Config.cooldown.Value;
			};
			Config.procCoef.SettingChanged += delegate
			{
				Content.cleaverangPrefab.GetComponent<ProjectileDotZone>().overlapProcCoefficient = Config.procCoef.Value;
				Content.cleaverangBoostedPrefab.GetComponent<ProjectileDotZone>().overlapProcCoefficient = Config.procCoef.Value;
			};
		}
	}
	internal class ThrowCleaverang : BaseState
	{
		internal static GameObject muzzleFlashPrefab;

		private float baseDuration;

		private bool boosted;

		public override void OnEnter()
		{
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			((BaseState)this).OnEnter();
			boosted = ((EntityState)this).characterBody.HasBuff(Buffs.Boosted);
			if (boosted && NetworkServer.active)
			{
				((EntityState)this).characterBody.RemoveBuff(Buffs.Boosted);
			}
			baseDuration = Config.interval.Value;
			float num = baseDuration / base.attackSpeedStat;
			((BaseState)this).StartAimMode(num + 2f, false);
			if (boosted)
			{
				((EntityState)this).PlayAnimation("Gesture, Override", "FireSliceAndDice", "FireSliceAndDice.playbackRate", num, 0f);
				((EntityState)this).PlayAnimation("Gesture, Additive", "FireSliceAndDice", "FireSliceAndDice.playbackRate", num, 0f);
				Util.PlaySound("Play_chef_skill1_boosted_shoot", ((EntityState)this).gameObject);
			}
			else
			{
				((EntityState)this).PlayAnimation("Gesture, Override", "FireDice", "FireDice.playbackRate", num, 0f);
				((EntityState)this).PlayAnimation("Gesture, Additive", "FireDice", "FireDice.playbackRate", num, 0f);
				Util.PlaySound("Play_chef_skill1_shoot", ((EntityState)this).gameObject);
			}
			EffectManager.SimpleMuzzleFlash(muzzleFlashPrefab, ((Component)((EntityState)this).characterBody.aimOriginTransform).gameObject, "MouthMuzzle", false);
			if (((EntityState)this).isAuthority)
			{
				Ray aimRay = ((BaseState)this).GetAimRay();
				Quaternion val = Util.QuaternionSafeLookRotation(((Ray)(ref aimRay)).direction);
				if (boosted)
				{
					GameObject cleaverangBoostedPrefab = Content.cleaverangBoostedPrefab;
					float num2 = 15f;
					Quaternion val2 = Quaternion.AngleAxis(90f, ((Ray)(ref aimRay)).direction);
					Quaternion val3 = val * Quaternion.Euler(0f, num2, 0f);
					FireSingleProjectile(cleaverangBoostedPrefab, ((Ray)(ref aimRay)).origin, val);
					FireSingleProjectile(cleaverangBoostedPrefab, ((Ray)(ref aimRay)).origin, val3);
					val3 = val2 * val3;
					FireSingleProjectile(cleaverangBoostedPrefab, ((Ray)(ref aimRay)).origin, val3);
					val3 = val2 * val3;
					FireSingleProjectile(cleaverangBoostedPrefab, ((Ray)(ref aimRay)).origin, val3);
					val3 = val2 * val3;
					FireSingleProjectile(cleaverangBoostedPrefab, ((Ray)(ref aimRay)).origin, val3);
				}
				else
				{
					FireSingleProjectile(Content.cleaverangPrefab, ((Ray)(ref aimRay)).origin, val);
				}
			}
		}

		private void FireSingleProjectile(GameObject prefab, Vector3 origin, Quaternion rotation)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			ProjectileManager.instance.FireProjectile(new FireProjectileInfo
			{
				projectilePrefab = prefab,
				position = origin,
				rotation = rotation,
				owner = ((EntityState)this).gameObject,
				damage = base.damageStat * Config.damage.Value,
				crit = Util.CheckRoll(base.critStat, ((EntityState)this).characterBody.master),
				force = 0f
			});
		}

		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).isAuthority && ((EntityState)this).fixedAge >= baseDuration / ((EntityState)this).characterBody.attackSpeed)
			{
				((EntityState)this).outer.SetNextStateToMain();
			}
		}

		public override void OnExit()
		{
			ChefController component = ((EntityState)this).GetComponent<ChefController>();
			component.SetYesChefHeatState(false);
			if (((EntityState)this).isAuthority)
			{
				component.ClearSkillOverrides();
			}
			if (NetworkServer.active)
			{
				((EntityState)this).characterBody.RemoveBuff(Buffs.boostedFireEffect);
			}
			((EntityState)this).OnExit();
		}

		public override InterruptPriority GetMinimumInterruptPriority()
		{
			return (InterruptPriority)1;
		}
	}
}