using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using MonoMod.Cil;
using R2API.AutoVersionGen;
using R2API.Skills.Interop;
using RoR2;
using RoR2.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("R2API.Skills")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fe846a83ac8db6f273c862174a3c61ce5303103b")]
[assembly: AssemblyProduct("R2API.Skills")]
[assembly: AssemblyTitle("R2API.Skills")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
}
namespace R2API
{
[AutoVersion]
public static class SkillsAPI
{
[StructLayout(LayoutKind.Sequential, Size = 1)]
private struct GenericSkillComparer : IComparer<GenericSkill>
{
public readonly int Compare(GenericSkill x, GenericSkill y)
{
return x.GetOrderPriority() - y.GetOrderPriority();
}
}
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__LoadoutPanelControllerRebuildHook;
public static Manipulator <1>__LoadoutPanelControllerRowFromSkillSlotHook;
public static Manipulator <2>__CharacterSelectControllerBuildSkillStripDisplayDataHook;
public static <>F{00000058}<Loadout, BodyInfo, GenericSkill[], int[]> <3>__CharacterSelectControllerRemoveAndSortSkills;
public static Func<List<GenericSkill>, CharacterBody, int[]> <4>__LoadoutPanelControllerRemoveAndSortSkills;
public static Func<string, GenericSkill, string> <5>__LoadoutPanelControllerReplaceTitleToken;
}
public const string PluginGUID = "com.bepis.r2api.skills";
public const string PluginName = "R2API.Skills";
public const string PluginVersion = "1.0.0";
internal static void SetHooks()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_003b: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
object obj = <>O.<0>__LoadoutPanelControllerRebuildHook;
if (obj == null)
{
Manipulator val = LoadoutPanelControllerRebuildHook;
<>O.<0>__LoadoutPanelControllerRebuildHook = val;
obj = (object)val;
}
LoadoutPanelController.Rebuild += (Manipulator)obj;
object obj2 = <>O.<1>__LoadoutPanelControllerRowFromSkillSlotHook;
if (obj2 == null)
{
Manipulator val2 = LoadoutPanelControllerRowFromSkillSlotHook;
<>O.<1>__LoadoutPanelControllerRowFromSkillSlotHook = val2;
obj2 = (object)val2;
}
Row.FromSkillSlot += (Manipulator)obj2;
object obj3 = <>O.<2>__CharacterSelectControllerBuildSkillStripDisplayDataHook;
if (obj3 == null)
{
Manipulator val3 = CharacterSelectControllerBuildSkillStripDisplayDataHook;
<>O.<2>__CharacterSelectControllerBuildSkillStripDisplayDataHook = val3;
obj3 = (object)val3;
}
CharacterSelectController.BuildSkillStripDisplayData += (Manipulator)obj3;
}
internal static void UnsetHooks()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: 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_003b: Expected O, but got Unknown
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
object obj = <>O.<0>__LoadoutPanelControllerRebuildHook;
if (obj == null)
{
Manipulator val = LoadoutPanelControllerRebuildHook;
<>O.<0>__LoadoutPanelControllerRebuildHook = val;
obj = (object)val;
}
LoadoutPanelController.Rebuild -= (Manipulator)obj;
object obj2 = <>O.<1>__LoadoutPanelControllerRowFromSkillSlotHook;
if (obj2 == null)
{
Manipulator val2 = LoadoutPanelControllerRowFromSkillSlotHook;
<>O.<1>__LoadoutPanelControllerRowFromSkillSlotHook = val2;
obj2 = (object)val2;
}
Row.FromSkillSlot -= (Manipulator)obj2;
object obj3 = <>O.<2>__CharacterSelectControllerBuildSkillStripDisplayDataHook;
if (obj3 == null)
{
Manipulator val3 = CharacterSelectControllerBuildSkillStripDisplayDataHook;
<>O.<2>__CharacterSelectControllerBuildSkillStripDisplayDataHook = val3;
obj3 = (object)val3;
}
CharacterSelectController.BuildSkillStripDisplayData -= (Manipulator)obj3;
}
public static bool GetHideInLoadout(this GenericSkill genericSkill)
{
return GenericSkillInterop.GetHideInLoadout(genericSkill);
}
public static void SetHideInLoadout(this GenericSkill genericSkill, bool value)
{
GenericSkillInterop.SetHideInLoadout(genericSkill, value);
}
public static bool GetHideInCharacterSelectIfFirstSkillSelected(this GenericSkill genericSkill)
{
return GenericSkillInterop.GetHideInCharacterSelectIfFirstSkillSelected(genericSkill);
}
public static void SetHideInCharacterSelectIfFirstSkillSelected(this GenericSkill genericSkill, bool value)
{
GenericSkillInterop.SetHideInCharacterSelectIfFirstSkillSelected(genericSkill, value);
}
public static int GetOrderPriority(this GenericSkill genericSkill)
{
return GenericSkillInterop.GetOrderPriority(genericSkill);
}
public static void SetOrderPriority(this GenericSkill genericSkill, int value)
{
GenericSkillInterop.SetOrderPriority(genericSkill, value);
}
public static string GetLoadoutTitleTokenOverride(this GenericSkill genericSkill)
{
return GenericSkillInterop.GetLoadoutTitleTokenOverride(genericSkill);
}
public static void SetLoadoutTitleTokenOverride(this GenericSkill genericSkill, string value)
{
GenericSkillInterop.SetLoadoutTitleTokenOverride(genericSkill, value);
}
private static void CharacterSelectControllerBuildSkillStripDisplayDataHook(ILContext il)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
VariableDefinition val = new VariableDefinition((TypeReference)(object)TypeReferenceRocks.MakeArrayType(((MemberReference)il.Method).Module.TypeSystem.Int32));
il.Body.Variables.Add(val);
ILCursor val2 = new ILCursor(il);
int skillSlotsIndex = -1;
if (val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 2),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<BodyInfo>(x, "skillSlots"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref skillSlotsIndex)
}))
{
val2.Emit(OpCodes.Ldarg_1);
val2.Emit(OpCodes.Ldarg_2);
val2.Emit(OpCodes.Ldloca, skillSlotsIndex);
val2.EmitDelegate<<>F{00000058}<Loadout, BodyInfo, GenericSkill[], int[]>>((<>F{00000058}<Loadout, BodyInfo, GenericSkill[], int[]>)CharacterSelectControllerRemoveAndSortSkills);
val2.Emit(OpCodes.Stloc, val);
int num = default(int);
if (val2.TryGotoNext((MoveType)0, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<BodyLoadoutManager>(x, "GetSkillVariant")
}))
{
val2.Emit(OpCodes.Ldloc, val);
int index = val2.Index;
val2.Index = index + 1;
val2.Emit(OpCodes.Ldelem_I4);
}
else
{
SkillsPlugin.Logger.LogError((object)"Failed to apply CharacterSelectControllerBuildSkillStripDisplayDataHook 2");
}
}
else
{
SkillsPlugin.Logger.LogError((object)"Failed to apply CharacterSelectControllerBuildSkillStripDisplayDataHook 1");
}
}
private static void LoadoutPanelControllerRebuildHook(ILContext il)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
VariableDefinition val = new VariableDefinition((TypeReference)(object)TypeReferenceRocks.MakeArrayType(((MemberReference)il.Method).Module.TypeSystem.Int32));
il.Body.Variables.Add(val);
ILCursor val2 = new ILCursor(il);
int bodyIndex = -1;
int genericSkillsIndex = -1;
if (!val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, typeof(BodyCatalog), "GetBodyPrefabBodyComponent"),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref bodyIndex)
}))
{
SkillsPlugin.Logger.LogError((object)"Failed to apply LoadoutPanelControllerRebuildHook 1");
}
else if (val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)typeof(GetComponentsCache<GenericSkill>).GetMethod("GetGameObjectComponents")),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref genericSkillsIndex)
}))
{
val2.Emit(OpCodes.Ldloc, genericSkillsIndex);
val2.Emit(OpCodes.Ldloc, bodyIndex);
val2.EmitDelegate<Func<List<GenericSkill>, CharacterBody, int[]>>((Func<List<GenericSkill>, CharacterBody, int[]>)LoadoutPanelControllerRemoveAndSortSkills);
val2.Emit(OpCodes.Stloc, val);
int num2 = default(int);
int num = default(int);
if (val2.TryGotoNext((MoveType)0, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Row>(x, "FromSkillSlot")
}))
{
val2.Emit(OpCodes.Ldloc, val);
int index = val2.Index;
val2.Index = index + 1;
val2.Emit(OpCodes.Ldelem_I4);
}
else
{
SkillsPlugin.Logger.LogError((object)"Failed to apply LoadoutPanelControllerRebuildHook 3");
}
}
else
{
SkillsPlugin.Logger.LogError((object)"Failed to apply LoadoutPanelControllerRebuildHook 2");
}
}
private static void LoadoutPanelControllerRowFromSkillSlotHook(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
int num = default(int);
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
(Instruction x) => ILPatternMatchingExt.MatchNewobj<Row>(x)
}))
{
int index = val.Index;
val.Index = index + 1;
val.Emit(OpCodes.Ldarg_3);
val.EmitDelegate<Func<string, GenericSkill, string>>((Func<string, GenericSkill, string>)LoadoutPanelControllerReplaceTitleToken);
}
else
{
SkillsPlugin.Logger.LogError((object)"Failed to apply LoadoutPanelControllerRowFromSkillSlotHook");
}
}
private static int[] LoadoutPanelControllerRemoveAndSortSkills(List<GenericSkill> list, CharacterBody body)
{
IOrderedEnumerable<(GenericSkill, int)> source = from x in list.Select((GenericSkill skill, int index) => (skill, index))
where !x.skill.GetHideInLoadout()
orderby x.skill.GetOrderPriority()
select x;
int[] result = source.Select<(GenericSkill, int), int>(((GenericSkill skill, int index) x) => x.index).ToArray();
GenericSkill[] collection = source.Select<(GenericSkill, int), GenericSkill>(((GenericSkill skill, int index) x) => x.skill).ToArray();
list.Clear();
list.AddRange(collection);
return result;
}
private static int[] CharacterSelectControllerRemoveAndSortSkills(Loadout loadout, in BodyInfo bodyInfo, ref GenericSkill[] previousValue)
{
//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)
Loadout loadout2 = loadout;
BodyIndex bodyIndex = bodyInfo.bodyIndex;
IOrderedEnumerable<(GenericSkill, int)> source = from x in previousValue.Select((GenericSkill skill, int index) => (skill, index))
where !x.skill.GetHideInCharacterSelectIfFirstSkillSelected() || loadout2.bodyLoadoutManager.GetSkillVariant(bodyIndex, x.index) != 0
orderby x.skill.GetOrderPriority()
select x;
previousValue = source.Select<(GenericSkill, int), GenericSkill>(((GenericSkill skill, int index) x) => x.skill).ToArray();
return source.Select<(GenericSkill, int), int>(((GenericSkill skill, int index) x) => x.index).ToArray();
}
private static string LoadoutPanelControllerReplaceTitleToken(string token, GenericSkill skill)
{
string loadoutTitleTokenOverride = skill.GetLoadoutTitleTokenOverride();
if (!string.IsNullOrEmpty(loadoutTitleTokenOverride))
{
return loadoutTitleTokenOverride;
}
return token;
}
}
[BepInPlugin("com.bepis.r2api.skills", "R2API.Skills", "1.0.0")]
public sealed class SkillsPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
SkillsAPI.SetHooks();
}
private void OnDestroy()
{
SkillsAPI.UnsetHooks();
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}