using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
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.Logging;
using HG;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API.AutoVersionGen;
using R2API.ContentManagement;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
[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.Elites")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: AssemblyInformationalVersion("1.0.6+3d1ec1017ef52f11eeb98a2c663a2a57335b3e1e")]
[assembly: AssemblyProduct("R2API.Elites")]
[assembly: AssemblyTitle("R2API.Elites")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.6.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
{
public class CustomElite
{
public EliteDef? EliteDef;
public Texture2D? EliteRamp;
public IEnumerable<EliteTierDef> EliteTierDefs;
public CustomElite(string? name, EquipmentDef equipmentDef, Color32 color, string? modifierToken, IEnumerable<EliteTierDef> eliteTierDefs)
{
//IL_002f: 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)
EliteDef = ScriptableObject.CreateInstance<EliteDef>();
((Object)EliteDef).name = name;
EliteDef.eliteEquipmentDef = equipmentDef;
EliteDef.color = color;
EliteDef.modifierToken = modifierToken;
EliteTierDefs = eliteTierDefs;
}
public CustomElite(string? name, EquipmentDef equipmentDef, Color32 color, string? modifierToken, IEnumerable<EliteTierDef> eliteTierDefs, Texture2D eliteRamp)
{
//IL_002f: 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)
EliteDef = ScriptableObject.CreateInstance<EliteDef>();
((Object)EliteDef).name = name;
EliteDef.eliteEquipmentDef = equipmentDef;
EliteDef.color = color;
EliteDef.modifierToken = modifierToken;
EliteTierDefs = eliteTierDefs;
EliteRamp = eliteRamp;
}
public CustomElite(EliteDef? eliteDef, IEnumerable<EliteTierDef> eliteTierDefs)
{
EliteDef = eliteDef;
EliteTierDefs = eliteTierDefs;
}
public CustomElite(EliteDef? eliteDef, IEnumerable<EliteTierDef> eliteTierDefs, Texture2D eliteRamp)
{
EliteDef = eliteDef;
EliteTierDefs = eliteTierDefs;
EliteRamp = eliteRamp;
}
}
[AutoVersion]
public static class EliteAPI
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__RetrieveVanillaEliteTierCount;
public static hook_Init <1>__UseOurCombatDirectorInitInstead;
public static Action <2>__AddElitesToGame;
}
public const string PluginGUID = "com.bepis.r2api.elites";
public const string PluginName = "R2API.Elites";
public static ObservableCollection<CustomElite?>? EliteDefinitions;
private static bool _hooksEnabled;
private static bool _combatDirectorInitialized;
public static int VanillaEliteTierCount;
private static readonly List<EliteTierDef> CustomEliteTierDefs;
public const string PluginVersion = "1.0.6";
[Obsolete("All submodules are automatically loaded and this property is now unused")]
public static bool Loaded => true;
public static EliteTierDef[] VanillaEliteTiers { get; private set; }
public static EliteTierDef VanillaFirstTierDef { get; private set; }
public static EliteTierDef VanillaEliteOnlyFirstTierDef { get; private set; }
public static int CustomEliteTierCount => CustomEliteTierDefs.Count;
static EliteAPI()
{
EliteDefinitions = new ObservableCollection<CustomElite>();
_hooksEnabled = false;
CustomEliteTierDefs = new List<EliteTierDef>();
CombatDirectorInitNoTimingIssue();
VanillaEliteTiers = RetrieveVanillaEliteTiers();
VanillaFirstTierDef = RetrieveFirstVanillaTierDef();
VanillaEliteOnlyFirstTierDef = RetrieveVanillaEliteOnlyFirstTierDef();
ElitesPlugin.Logger.LogDebug((object)"EliteAPI.cctor finished.");
}
internal static void SetHooks()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
if (!_hooksEnabled)
{
object obj = <>O.<0>__RetrieveVanillaEliteTierCount;
if (obj == null)
{
Manipulator val = RetrieveVanillaEliteTierCount;
<>O.<0>__RetrieveVanillaEliteTierCount = val;
obj = (object)val;
}
CombatDirector.Init += (Manipulator)obj;
object obj2 = <>O.<1>__UseOurCombatDirectorInitInstead;
if (obj2 == null)
{
hook_Init val2 = UseOurCombatDirectorInitInstead;
<>O.<1>__UseOurCombatDirectorInitInstead = val2;
obj2 = (object)val2;
}
CombatDirector.Init += (hook_Init)obj2;
R2APIContentPackProvider.WhenAddingContentPacks = (Action)Delegate.Combine(R2APIContentPackProvider.WhenAddingContentPacks, new Action(AddElitesToGame));
_hooksEnabled = true;
}
}
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
object obj = <>O.<0>__RetrieveVanillaEliteTierCount;
if (obj == null)
{
Manipulator val = RetrieveVanillaEliteTierCount;
<>O.<0>__RetrieveVanillaEliteTierCount = val;
obj = (object)val;
}
CombatDirector.Init -= (Manipulator)obj;
object obj2 = <>O.<1>__UseOurCombatDirectorInitInstead;
if (obj2 == null)
{
hook_Init val2 = UseOurCombatDirectorInitInstead;
<>O.<1>__UseOurCombatDirectorInitInstead = val2;
obj2 = (object)val2;
}
CombatDirector.Init -= (hook_Init)obj2;
R2APIContentPackProvider.WhenAddingContentPacks = (Action)Delegate.Remove(R2APIContentPackProvider.WhenAddingContentPacks, new Action(AddElitesToGame));
_hooksEnabled = false;
}
private static void UseOurCombatDirectorInitInstead(orig_Init orig)
{
CombatDirectorInitNoTimingIssue();
}
private static void CombatDirectorInitNoTimingIssue()
{
//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)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: 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_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Expected O, but got Unknown
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: 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_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: 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_01bf: Expected O, but got Unknown
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: 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_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Expected O, but got Unknown
//IL_0299: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Expected O, but got Unknown
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_032f: Unknown result type (might be due to invalid IL or missing references)
if (!_combatDirectorInitialized)
{
List<EliteTierDef> list = new List<EliteTierDef>();
EliteTierDef item = new EliteTierDef
{
costMultiplier = 1f,
eliteTypes = (EliteDef[])(object)new EliteDef[1],
isAvailable = (EliteRules rules) => CombatDirector.NotEliteOnlyArtifactActive(),
canSelectWithoutAvailableEliteDef = true
};
list.Add(item);
EliteTierDef val = new EliteTierDef();
val.costMultiplier = CombatDirector.baseEliteCostMultiplier;
val.eliteTypes = (EliteDef[])(object)new EliteDef[4]
{
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLightning/edLightning.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteIce/edIce.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteFire/edFire.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC1/EliteEarth/edEarth.asset").WaitForCompletion()
};
val.isAvailable = (EliteRules rules) => CombatDirector.NotEliteOnlyArtifactActive() && (int)rules == 0 && Run.instance.stageClearCount < 2;
val.canSelectWithoutAvailableEliteDef = false;
item = val;
list.Add(item);
val = new EliteTierDef();
val.costMultiplier = Mathf.LerpUnclamped(1f, CombatDirector.baseEliteCostMultiplier, 0.5f);
val.eliteTypes = (EliteDef[])(object)new EliteDef[4]
{
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLightning/edLightningHonor.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteIce/edIceHonor.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteFire/edFireHonor.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC1/EliteEarth/edEarthHonor.asset").WaitForCompletion()
};
val.isAvailable = (EliteRules rules) => CombatDirector.IsEliteOnlyArtifactActive();
val.canSelectWithoutAvailableEliteDef = false;
item = val;
list.Add(item);
val = new EliteTierDef();
val.costMultiplier = CombatDirector.baseEliteCostMultiplier;
val.eliteTypes = (EliteDef[])(object)new EliteDef[5]
{
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLightning/edLightning.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteIce/edIce.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteFire/edFire.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC1/EliteEarth/edEarth.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC2/Elites/EliteAurelionite/edAurelionite.asset").WaitForCompletion()
};
val.isAvailable = (EliteRules rules) => CombatDirector.NotEliteOnlyArtifactActive() && (int)rules == 0 && Run.instance.stageClearCount >= 2;
val.canSelectWithoutAvailableEliteDef = false;
item = val;
list.Add(item);
val = new EliteTierDef();
val.costMultiplier = CombatDirector.baseEliteCostMultiplier * 6f;
val.eliteTypes = (EliteDef[])(object)new EliteDef[3]
{
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/ElitePoison/edPoison.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteHaunted/edHaunted.asset").WaitForCompletion(),
Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC2/Elites/EliteBead/edBead.asset").WaitForCompletion()
};
val.isAvailable = (EliteRules rules) => Run.instance.loopClearCount > 0 && (int)rules == 0;
val.canSelectWithoutAvailableEliteDef = false;
item = val;
list.Add(item);
val = new EliteTierDef();
val.costMultiplier = CombatDirector.baseEliteCostMultiplier;
val.eliteTypes = (EliteDef[])(object)new EliteDef[1] { Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLunar/edLunar.asset").WaitForCompletion() };
val.isAvailable = (EliteRules rules) => (int)rules == 2;
val.canSelectWithoutAvailableEliteDef = false;
item = val;
list.Add(item);
CombatDirector.eliteTiers = list.ToArray();
_combatDirectorInitialized = true;
}
}
private static void AddElitesToGame()
{
foreach (CustomElite customElite in EliteDefinitions)
{
foreach (EliteTierDef eliteTierDef in customElite.EliteTierDefs)
{
if (eliteTierDef.eliteTypes == null)
{
eliteTierDef.eliteTypes = Array.Empty<EliteDef>();
}
else if (eliteTierDef.eliteTypes.Any((EliteDef e) => (Object)(object)e == (Object)(object)customElite.EliteDef))
{
continue;
}
ArrayUtils.ArrayAppend<EliteDef>(ref eliteTierDef.eliteTypes, ref customElite.EliteDef);
}
if (Object.op_Implicit((Object)(object)customElite.EliteRamp))
{
EliteRamp.AddRamp(customElite.EliteDef, customElite.EliteRamp);
}
}
}
private static void RetrieveVanillaEliteTierCount(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (!new ILCursor(il).TryGotoNext(new Func<Instruction, bool>[2]
{
(Instruction i) => ILPatternMatchingExt.MatchLdcI4(i, ref VanillaEliteTierCount),
(Instruction i) => ILPatternMatchingExt.MatchNewarr<EliteTierDef>(i)
}))
{
ElitesPlugin.Logger.LogError((object)"Failed finding IL Instructions. Aborting RetrieveVanillaEliteTierCount IL Hook");
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool Add(CustomElite? elite)
{
SetHooks();
return AddInternal(elite, Assembly.GetCallingAssembly());
}
internal static bool AddInternal(CustomElite customElite, Assembly addingAssembly)
{
if (!Object.op_Implicit((Object)(object)customElite.EliteDef))
{
throw new ArgumentNullException("customElite.EliteDef");
}
if (!CatalogBlockers.GetAvailability<EliteDef>())
{
ElitesPlugin.Logger.LogError((object)("Too late ! Tried to add elite: " + customElite.EliteDef.modifierToken + " after the EliteCatalog has initialized!"));
return false;
}
if (customElite.EliteTierDefs == null || customElite.EliteTierDefs.Count() <= 0)
{
throw new ArgumentNullException("customElite.EliteTierDefs");
}
R2APIContentManager.HandleContentAddition(addingAssembly, (Object)(object)customElite.EliteDef);
EliteDefinitions.Add(customElite);
return true;
}
private static EliteTierDef[] RetrieveVanillaEliteTiers()
{
return CombatDirector.eliteTiers;
}
private static EliteTierDef RetrieveFirstVanillaTierDef()
{
return CombatDirector.eliteTiers[1];
}
private static EliteTierDef RetrieveVanillaEliteOnlyFirstTierDef()
{
return CombatDirector.eliteTiers[2];
}
public static EliteTierDef?[]? GetCombatDirectorEliteTiers()
{
SetHooks();
return CombatDirector.eliteTiers;
}
public static void OverrideCombatDirectorEliteTiers(EliteTierDef?[]? newEliteTiers)
{
SetHooks();
CombatDirector.eliteTiers = newEliteTiers;
}
public static int AppendCustomEliteTier(EliteTierDef? eliteTierDef)
{
SetHooks();
return AddCustomEliteTier(eliteTierDef, -1);
}
public static int AddCustomEliteTier(EliteTierDef? eliteTierDef)
{
EliteTierDef eliteTierDef2 = eliteTierDef;
SetHooks();
int num = Array.FindIndex(GetCombatDirectorEliteTiers(), (EliteTierDef x) => x.costMultiplier >= eliteTierDef2.costMultiplier);
if (num >= 0)
{
return AddCustomEliteTier(eliteTierDef2, num);
}
return AppendCustomEliteTier(eliteTierDef2);
}
public static int AddCustomEliteTier(EliteTierDef? eliteTierDef, int indexToInsertAt = -1)
{
SetHooks();
_ = VanillaEliteTierCount;
_ = CustomEliteTierCount;
EliteTierDef[] combatDirectorEliteTiers = GetCombatDirectorEliteTiers();
if (combatDirectorEliteTiers != null)
{
if (indexToInsertAt == -1)
{
indexToInsertAt = combatDirectorEliteTiers.Length;
ArrayUtils.ArrayAppend<EliteTierDef>(ref combatDirectorEliteTiers, ref eliteTierDef);
}
else
{
ArrayUtils.ArrayInsert<EliteTierDef>(ref combatDirectorEliteTiers, indexToInsertAt, ref eliteTierDef);
}
OverrideCombatDirectorEliteTiers(combatDirectorEliteTiers);
}
CustomEliteTierDefs.Add(eliteTierDef);
ElitesPlugin.Logger.LogInfo((object)$"Custom Elite Tier : (Index : {indexToInsertAt}) added");
return indexToInsertAt;
}
}
public static class EliteRamp
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__UpdateRampProperly;
public static Action <1>__SetupDictionary;
public static Action<CharacterModel> <2>__UpdateRampProperly;
}
private static List<(EliteDef, Texture2D)> elitesAndRamps = new List<(EliteDef, Texture2D)>();
private static Dictionary<EliteIndex, Texture2D> eliteIndexToTexture = new Dictionary<EliteIndex, Texture2D>();
private static Texture2D vanillaEliteRamp;
private static bool _hooksEnabled = false;
private static int EliteRampPropertyID => Shader.PropertyToID("_EliteRamp");
internal static void SetHooks()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
if (!_hooksEnabled)
{
object obj = <>O.<0>__UpdateRampProperly;
if (obj == null)
{
Manipulator val = UpdateRampProperly;
<>O.<0>__UpdateRampProperly = val;
obj = (object)val;
}
CharacterModel.UpdateMaterials += (Manipulator)obj;
RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(SetupDictionary));
vanillaEliteRamp = Addressables.LoadAssetAsync<Texture2D>((object)"RoR2/Base/Common/GlobalTextures/texRampElites.psd").WaitForCompletion();
_hooksEnabled = true;
}
}
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
object obj = <>O.<0>__UpdateRampProperly;
if (obj == null)
{
Manipulator val = UpdateRampProperly;
<>O.<0>__UpdateRampProperly = val;
obj = (object)val;
}
CharacterModel.UpdateMaterials -= (Manipulator)obj;
RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(SetupDictionary));
vanillaEliteRamp = null;
_hooksEnabled = false;
}
private static void UpdateRampProperly(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
bool flag = val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterModel>(x, "propertyStorage"),
(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(CommonShaderProperties), "_EliteIndex")
});
bool flag2 = val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<MaterialPropertyBlock>(x, "SetFloat")
});
if (flag && flag2)
{
val.Emit(OpCodes.Ldarg, 0);
val.EmitDelegate<Action<CharacterModel>>((Action<CharacterModel>)UpdateRampProperly);
}
else
{
ElitesPlugin.Logger.LogError((object)"Elite Ramp ILHook failed");
}
static void UpdateRampProperly(CharacterModel charModel)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
if ((int)charModel.myEliteIndex != -1 && eliteIndexToTexture.TryGetValue(charModel.myEliteIndex, out Texture2D value))
{
charModel.propertyStorage.SetTexture(EliteRampPropertyID, (Texture)(object)value);
}
else
{
charModel.propertyStorage.SetTexture(EliteRampPropertyID, (Texture)(object)vanillaEliteRamp);
}
}
}
private static void SetupDictionary()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
foreach (var (val, value) in elitesAndRamps)
{
eliteIndexToTexture[val.eliteIndex] = value;
}
elitesAndRamps.Clear();
}
public static void AddRamp(EliteDef eliteDef, Texture2D ramp)
{
SetHooks();
try
{
eliteDef.shaderEliteRampIndex = 0;
elitesAndRamps.Add((eliteDef, ramp));
}
catch (Exception ex)
{
ElitesPlugin.Logger.LogError((object)ex);
}
}
public static bool TryGetRamp(EliteIndex eliteIndex, out Texture2D ramp)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
ramp = null;
if ((int)eliteIndex != -1)
{
return eliteIndexToTexture.TryGetValue(eliteIndex, out ramp);
}
return false;
}
public static void AddRampToMultipleElites(IEnumerable<EliteDef> eliteDefs, Texture2D ramp)
{
SetHooks();
foreach (EliteDef eliteDef in eliteDefs)
{
AddRamp(eliteDef, ramp);
}
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.bepis.r2api.elites", "R2API.Elites", "1.0.6")]
public sealed class ElitesPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
EliteAPI.SetHooks();
EliteRamp.SetHooks();
}
private void OnDestroy()
{
EliteAPI.UnsetHooks();
EliteRamp.UnsetHooks();
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}