using System;
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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dolso;
using Dolso.RiskofOptions;
using EntityStates;
using EntityStates.Chef;
using HG;
using HG.Reflection;
using ItemStatistics;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using R2API;
using R2API.ContentManagement;
using R2API.ScriptableObjects;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Cleaverang")]
[assembly: AssemblyConfiguration("Release")]
[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);
}
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, [CallerMemberName] string callerName = "")
{
logger.LogError((object)string.Format($"ILCursor failure in {callerName}, skipping: {data}\n{c}"));
}
}
internal static class HookManager
{
internal delegate bool ConfigEnabled<T>(ConfigEntry<T> configEntry);
internal const BindingFlags allFlags = 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_002c: 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_0028: 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 args)
{
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_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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 methodFrom)
{
if (typeFrom == null || methodFrom == null)
{
return null;
}
IEnumerable<MethodInfo> enumerable = from predicate in typeFrom.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
where predicate.Name == methodFrom
select predicate;
if (enumerable.Count() == 1)
{
return enumerable.First();
}
if (enumerable.Count() == 0)
{
log.error($"Failed to find method: {typeFrom}.{methodFrom}");
}
else
{
log.error($"{enumerable.Count()} ambiguous matches found for: {typeFrom}.{methodFrom}");
foreach (MethodInfo item in enumerable)
{
log.error(item);
}
}
return null;
}
internal static MethodInfo GetMethod(Type typeFrom, string methodFrom, params Type[] parameters)
{
if (typeFrom == null || methodFrom == null)
{
return null;
}
MethodInfo? method = typeFrom.GetMethod(methodFrom, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, parameters, null);
if (method == null)
{
log.error($"Failed to find method: {typeFrom}.{methodFrom}_{parameters.Length}");
}
return method;
}
internal static void PriorityFirst()
{
ilHookConfig.Before = new string[1] { "*" };
onHookConfig.Before = new string[1] { "*" };
}
internal static void PriorityLast()
{
ilHookConfig.After = new string[1] { "*" };
onHookConfig.After = new string[1] { "*" };
}
internal static void PriorityNormal()
{
ilHookConfig.Before = null;
onHookConfig.Before = null;
ilHookConfig.After = null;
onHookConfig.After = null;
}
}
internal static class Utilities
{
private static GameObject _prefabParent;
internal static GameObject CreatePrefab(GameObject gameObject, string name = null)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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 MethodInfo MakeGenericMethod<T>(this Type type, string methodName, params Type[] parameters)
{
return type.GetMethod(methodName, parameters).MakeGenericMethod(typeof(T));
}
internal static MethodInfo MakeGenericGetComponentG<T>() where T : Component
{
return typeof(GameObject).GetMethod("GetComponent", Type.EmptyTypes).MakeGenericMethod(typeof(T));
}
internal static MethodInfo MakeGenericGetComponentC<T>() where T : Component
{
return typeof(Component).GetMethod("GetComponent", Type.EmptyTypes).MakeGenericMethod(typeof(T));
}
internal static Obj GetAddressable<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).WaitForCompletion();
}
internal static GameObject GetAddressable(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).WaitForCompletion();
}
internal static void GetAddressable<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 GetAddressable(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 AssetBundle LoadAssetBundle(string bundlePathName)
{
AssetBundle result = null;
try
{
result = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), bundlePathName));
}
catch (Exception ex)
{
log.error("Failed to load assetbundle\n" + ex);
}
return result;
}
}
}
namespace Dolso.RiskofOptions
{
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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
string path = ((!(directoryInfo.Name == "plugins")) ? directoryInfo.FullName : directoryInfo.Parent.FullName);
try
{
Texture2D val = new Texture2D(256, 256);
if (ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(path, "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 AddBool(ConfigEntry<bool> entry, string categoryName = "", string name = "")
{
//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_0025: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(entry, new CheckBoxConfig
{
category = categoryName,
name = name,
description = ((ConfigEntryBase)(object)entry).DescWithDefault()
}));
}
internal static void AddEnum<T>(ConfigEntry<T> entry) where T : Enum
{
//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_0017: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)entry, new ChoiceConfig
{
description = ((ConfigEntryBase)(object)entry).DescWithDefault()
}));
}
internal static void AddColor(ConfigEntry<Color> entry)
{
//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_0017: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
ModSettingsManager.AddOption((BaseOption)new ColorOption(entry, new ColorOptionConfig
{
description = ((ConfigEntryBase)(object)entry).DescWithDefault()
}));
}
internal static void AddKey(ConfigEntry<KeyboardShortcut> entry)
{
//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_0017: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
ModSettingsManager.AddOption((BaseOption)new KeyBindOption(entry, new KeyBindConfig
{
description = ((ConfigEntryBase)(object)entry).DescWithDefault()
}));
}
internal static void AddString(ConfigEntry<string> entry, bool restartRequired = false, 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_0008: 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_000f: 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_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(entry, new InputFieldConfig
{
submitOn = (SubmitEnum)6,
lineType = (LineType)0,
category = categoryName,
description = ((ConfigEntryBase)(object)entry).DescWithDefault(),
restartRequired = restartRequired
}));
}
internal static void AddFloatField(ConfigEntry<float> entry, float min = float.MinValue, float max = float.MaxValue, string format = "{0:f2}")
{
//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: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
FloatFieldConfig val = new FloatFieldConfig();
((NumericFieldConfig<float>)val).Min = min;
((NumericFieldConfig<float>)val).Max = max;
((NumericFieldConfig<float>)val).FormatString = format;
((BaseOptionConfig)val).description = ((ConfigEntryBase)(object)entry).DescWithDefault(format);
ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(entry, val));
}
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_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: 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 AddIntField(ConfigEntry<int> entry, int min = int.MinValue, int max = int.MaxValue)
{
//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: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Expected O, but got Unknown
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
IntFieldConfig val = new IntFieldConfig();
((NumericFieldConfig<int>)val).Min = min;
((NumericFieldConfig<int>)val).Max = max;
((BaseOptionConfig)val).description = ((ConfigEntryBase)(object)entry).DescWithDefault();
ModSettingsManager.AddOption((BaseOption)new IntFieldOption(entry, val));
}
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()
}));
}
internal static void AddOption(ConfigEntry<bool> entry)
{
AddBool(entry);
}
internal static void AddOption(ConfigEntry<bool> entry, string categoryName = "", string name = "")
{
AddBool(entry, categoryName, name);
}
internal static void AddOption<T>(ConfigEntry<T> entry) where T : Enum
{
AddEnum<T>(entry);
}
internal static void AddOption(ConfigEntry<Color> entry)
{
AddColor(entry);
}
internal static void AddOption(ConfigEntry<KeyboardShortcut> entry)
{
AddKey(entry);
}
internal static void AddOption(ConfigEntry<float> entry, float min, float max, string format = "{0:f2}")
{
AddFloatSlider(entry, min, max, format);
}
internal static void AddOption(ConfigEntry<int> entry)
{
AddIntField(entry);
}
internal static void AddOption(ConfigEntry<string> entry)
{
AddString(entry);
}
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
{
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("dolso.Cleaverang", "Cleaverang", "1.0.2")]
public class CleaverangPlugin : BaseUnityPlugin
{
public const string modguid = "dolso.Cleaverang";
internal const string version = "1.0.2";
internal static GameObject cleaverangPrefab;
internal static GameObject cleaverangBoostedPrefab;
internal static AssetBundle assetBundle;
internal static SkillDef cSkill;
internal static SkillDef cSkillBoosted;
internal static int cleaverangIndex;
internal static int cleaverangBoostedIndex;
private static R2APISerializableContentPack contentPack;
private void Awake()
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
log.start(((BaseUnityPlugin)this).Logger);
assetBundle = Utilities.LoadAssetBundle("cleaverang");
Config.DoConfig(((BaseUnityPlugin)this).Config);
contentPack = ScriptableObject.CreateInstance<R2APISerializableContentPack>();
((Object)contentPack).name = "dolso.Cleaverang";
R2APIContentManager.BepInModNameToSerializableContentPack.Add("dolso.Cleaverang", new ManagedSerializableContentPack(contentPack, true, Assembly.GetExecutingAssembly()));
Utilities.GetAddressable("RoR2/Base/Saw/Sawmerang.prefab", SetupProjs);
Utilities.GetAddressable("RoR2/DLC2/Chef/MuzzleflashChefDiceReturn.prefab", delegate(GameObject a)
{
ThrowCleaverang.muzzleFlashPrefab = a;
});
SetupSkillDefs();
ConfigEvents();
Hooks.DoHooks();
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
}
private static void SetupProjs(GameObject saw)
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
cleaverangPrefab = MakeCleaverangPrefab(saw, "DolsoCleaverang");
cleaverangBoostedPrefab = MakeCleaverangPrefab(saw, "DolsoCleaverangBoosted");
cleaverangBoostedPrefab.GetComponent<BoomerangProjectile>().canHitWorld = false;
ProjectileController component = cleaverangBoostedPrefab.GetComponent<ProjectileController>();
component.ghostPrefab = PrefabAPI.InstantiateClone(component.ghostPrefab, "DolsoCleaverangBoostedGhost", false);
MeshRenderer componentInChildren = component.ghostPrefab.GetComponentInChildren<MeshRenderer>();
((Renderer)componentInChildren).material = new Material(((Renderer)componentInChildren).material);
((Object)((Renderer)componentInChildren).material).name = "matSawmerangRed";
((Renderer)componentInChildren).material.mainTexture = assetBundle.LoadAsset<Texture>("texSawmerangRedDiffuse.png");
if (Chainloader.PluginInfos.ContainsKey("dolso.ItemStatistics"))
{
DoItemStatistics();
}
}
private static GameObject MakeCleaverangPrefab(GameObject addressable, string name)
{
GameObject val = PrefabAPI.InstantiateClone(addressable, name);
val.GetComponent<ProjectileOverlapAttack>().damageCoefficient = 3f;
val.GetComponent<ProjectileDotZone>().overlapProcCoefficient = Config.procCoef.Value;
val.GetComponent<ProjectileController>().allowPrediction = false;
val.GetComponent<BoomerangProjectile>().EnableNetworkClientCatchup = false;
ProjectileInflictTimedBuff debuff = val.AddComponent<ProjectileInflictTimedBuff>();
debuff.duration = 100f;
Utilities.GetAddressable<BuffDef>("RoR2/DLC2/Chef/Buffs/bdCookingChopped.asset", (Action<BuffDef>)delegate(BuffDef a)
{
debuff.buffDef = a;
});
ArrayUtils.ArrayAppend<GameObject>(ref contentPack.projectilePrefabs, ref val);
return val;
}
private static void DoItemStatistics()
{
//IL_0006: 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)
ItemStatisticsAPI.AddTrackerToPrefab(cleaverangPrefab, Index.op_Implicit((SkillSlot)0));
ItemStatisticsAPI.AddTrackerToPrefab(cleaverangBoostedPrefab, Index.op_Implicit((SkillSlot)3));
}
private static void SetupSkillDefs()
{
cSkill = LoadSkillDef("CleaverangSkill");
cSkillBoosted = LoadSkillDef("CleaverangBoostedSkill");
Utilities.GetAddressable<GameObject>("RoR2/DLC2/Chef/ChefBody.prefab", (Action<GameObject>)delegate(GameObject a)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
ref Variant[] variants = ref a.GetComponent<SkillLocator>().primary.skillFamily.variants;
Variant val = new Variant
{
skillDef = cSkill
};
((Variant)(ref val)).viewableNode = new Node(cSkill.skillNameToken, false, (Node)null);
ArrayUtils.ArrayAppend<Variant>(ref variants, ref val);
});
ArrayUtils.ArrayAppend<SerializableEntityStateType>(ref contentPack.entityStateTypes, ref cSkill.activationState);
}
private static SkillDef LoadSkillDef(string assetname)
{
//IL_0017: 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)
SkillDef val = assetBundle.LoadAsset<SkillDef>(assetname);
val.activationState = new SerializableEntityStateType(typeof(ThrowCleaverang));
val.baseRechargeInterval = Config.cooldown.Value;
ArrayUtils.ArrayAppend<SkillDef>(ref contentPack.skillDefs, ref val);
return val;
}
private static void OnLoad()
{
cleaverangIndex = ProjectileCatalog.FindProjectileIndex("DolsoCleaverang");
cleaverangBoostedIndex = ProjectileCatalog.FindProjectileIndex("DolsoCleaverangBoosted");
}
private static void ConfigEvents()
{
Config.cooldown.SettingChanged += delegate
{
cSkill.baseRechargeInterval = Config.cooldown.Value;
cSkillBoosted.baseRechargeInterval = Config.cooldown.Value;
};
Config.procCoef.SettingChanged += delegate
{
cleaverangPrefab.GetComponent<ProjectileDotZone>().overlapProcCoefficient = Config.procCoef.Value;
cleaverangBoostedPrefab.GetComponent<ProjectileDotZone>().overlapProcCoefficient = Config.procCoef.Value;
};
}
}
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_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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", 0.9f, "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.2", "Config version, if this is different from current version, resets config");
if (version.Value != "1.0.2")
{
configFile.Clear();
DoConfig(configFile);
}
else if (RiskofOptions.enabled)
{
DoRiskOfOptions();
}
}
internal static void DoRiskOfOptions()
{
RiskofOptions.SetSprite(CleaverangPlugin.assetBundle.LoadAsset<Sprite>("CleaverangIcon"));
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 Hooks
{
internal static void DoHooks()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
HookManager.Hook(typeof(YesChef), "OnEnter", (Delegate)new Action<Action<YesChef>, YesChef>(On_YesChef_OnEnter_AddOverride));
HookManager.Hook(typeof(GlobalEventManager), "ProcessHitEnemy", new Manipulator(IL_GlobalEventManager_OnHitEnemy_SetBleed));
HookManager.Hook(typeof(BoomerangProjectile), "Start", (Delegate)new Action<Action<BoomerangProjectile>, BoomerangProjectile>(OnBoomerangProjectile_Start_SetVelocity));
HookManager.Hook(typeof(BoomerangProjectile), "FixedUpdate", new Manipulator(IL_BoomerangProjectile_FixedUpdate_ChangeFlightPath));
}
private static void On_YesChef_OnEnter_AddOverride(Action<YesChef> orig, YesChef self)
{
if ((Object)(object)((EntityState)self).skillLocator.primary.skillDef == (Object)(object)CleaverangPlugin.cSkill)
{
self.primarySkillOverrideDef = CleaverangPlugin.cSkillBoosted;
}
orig(self);
}
private static void IL_GlobalEventManager_OnHitEnemy_SetBleed(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
int masterIndex = 5;
if (!val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchCallOrCallvirt(a, typeof(CharacterBody), "get_master")
}) || !val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchStloc(a, ref masterIndex)
}))
{
val.LogErrorCaller("master index", "IL_GlobalEventManager_OnHitEnemy_SetBleed");
return;
}
ILLabel branchFalse = null;
int sawFlagIndex = 111;
if (val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchLdsfld(a, typeof(Equipment), "Saw")
}) && val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchBneUn(a, ref branchFalse)
}) && val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchStloc(a, ref sawFlagIndex)
}))
{
val.Emit(OpCodes.Br, (object)branchFalse);
val.Emit(OpCodes.Ldarg_1);
Instruction prev = val.Prev;
val.Emit(OpCodes.Ldloc, masterIndex);
val.EmitDelegate<Func<DamageInfo, CharacterMaster, int>>((Func<DamageInfo, CharacterMaster, int>)delegate(DamageInfo damageInfo, CharacterMaster master)
{
ProjectileController component = damageInfo.inflictor.GetComponent<ProjectileController>();
return (Object.op_Implicit((Object)(object)component) && component.catalogIndex == CleaverangPlugin.cleaverangBoostedIndex && Util.CheckRoll(Config.bleedChance.Value, master)) ? 1 : 0;
});
val.Emit(OpCodes.Stloc, sawFlagIndex);
val.GotoPrev(new Func<Instruction, bool>[1]
{
(Instruction a) => ILPatternMatchingExt.MatchBneUn(a, branchFalse)
});
val.Next.Operand = prev;
}
else
{
val.LogErrorCaller("saw bleed", "IL_GlobalEventManager_OnHitEnemy_SetBleed");
}
}
private static void OnBoomerangProjectile_Start_SetVelocity(Action<BoomerangProjectile> orig, BoomerangProjectile self)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
orig(self);
if (self.projectileController.catalogIndex == CleaverangPlugin.cleaverangBoostedIndex)
{
self.rigidbody.velocity = self.travelSpeed * ((Component)self).transform.forward;
}
}
private static void IL_BoomerangProjectile_FixedUpdate_ChangeFlightPath(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: 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 == CleaverangPlugin.cleaverangBoostedIndex));
val.Emit(OpCodes.Brtrue, (object)val2);
val.Emit(OpCodes.Ldarg_0);
}
}
}
internal class ThrowCleaverang : BaseState
{
internal static GameObject muzzleFlashPrefab;
private float baseDuration;
private bool boosted;
public override void OnEnter()
{
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: 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_01a2: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: 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)
((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 = CleaverangPlugin.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(CleaverangPlugin.cleaverangPrefab, ((Ray)(ref aimRay)).origin, val);
}
}
}
private void FireSingleProjectile(GameObject prefab, Vector3 origin, Quaternion rotation)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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_001f: 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_0073: 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;
}
}
}