using System;
using System.Collections.Generic;
using System.Diagnostics;
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;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API.AutoVersionGen;
using R2API.ScriptableObjects;
using RoR2;
using UnityEngine;
[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.Colors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+e9ea73f05d82ba8fdebacfa23cfaf143584d236e")]
[assembly: AssemblyProduct("R2API.Colors")]
[assembly: AssemblyTitle("R2API.Colors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 ColorsAPI
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__ColorCatalogGetColorIL;
public static Manipulator <1>__ColorCatalogGetColorHexStringIL;
public static Manipulator <2>__GetColorIL;
public static Func<ColorIndex, Color32> <3>__ColorCatalogGetColor;
public static Func<ColorIndex, string> <4>__ColorCatalogGetColorHexString;
}
public const string PluginGUID = "com.bepis.r2api.colors";
public const string PluginName = "R2API.Colors";
private static List<SerializableDamageColor> addedSerializableDamageColors = new List<SerializableDamageColor>();
private static List<SerializableColorCatalogEntry> addedSerializableColors = new List<SerializableColorCatalogEntry>();
private static bool _hookEnabled = false;
public const string PluginVersion = "1.0.3";
[Obsolete("All submodules are automatically loaded and this property is now unused")]
public static bool Loaded => true;
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
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
if (!_hookEnabled)
{
object obj = <>O.<0>__ColorCatalogGetColorIL;
if (obj == null)
{
Manipulator val = ColorCatalogGetColorIL;
<>O.<0>__ColorCatalogGetColorIL = val;
obj = (object)val;
}
ColorCatalog.GetColor += (Manipulator)obj;
object obj2 = <>O.<1>__ColorCatalogGetColorHexStringIL;
if (obj2 == null)
{
Manipulator val2 = ColorCatalogGetColorHexStringIL;
<>O.<1>__ColorCatalogGetColorHexStringIL = val2;
obj2 = (object)val2;
}
ColorCatalog.GetColorHexString += (Manipulator)obj2;
object obj3 = <>O.<2>__GetColorIL;
if (obj3 == null)
{
Manipulator val3 = GetColorIL;
<>O.<2>__GetColorIL = val3;
obj3 = (object)val3;
}
DamageColor.FindColor += (Manipulator)obj3;
_hookEnabled = 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
//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>__ColorCatalogGetColorIL;
if (obj == null)
{
Manipulator val = ColorCatalogGetColorIL;
<>O.<0>__ColorCatalogGetColorIL = val;
obj = (object)val;
}
ColorCatalog.GetColor -= (Manipulator)obj;
object obj2 = <>O.<1>__ColorCatalogGetColorHexStringIL;
if (obj2 == null)
{
Manipulator val2 = ColorCatalogGetColorHexStringIL;
<>O.<1>__ColorCatalogGetColorHexStringIL = val2;
obj2 = (object)val2;
}
ColorCatalog.GetColorHexString -= (Manipulator)obj2;
object obj3 = <>O.<2>__GetColorIL;
if (obj3 == null)
{
Manipulator val3 = GetColorIL;
<>O.<2>__GetColorIL = val3;
obj3 = (object)val3;
}
DamageColor.FindColor -= (Manipulator)obj3;
_hookEnabled = false;
}
private static void GetColorIL(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0061: 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)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
FieldReference arrayToGetLength = null;
val.GotoNext(new Func<Instruction, bool>[1]
{
(Instruction inst) => ILPatternMatchingExt.MatchLdsfld(inst, ref arrayToGetLength)
});
val.GotoPrev((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction inst) => ILPatternMatchingExt.MatchLdarg(inst, 0)
});
val.Emit(OpCodes.Ldsfld, arrayToGetLength);
val.Emit(OpCodes.Ldlen);
val.Emit(OpCodes.Conv_I4);
int index = val.Index;
val.Index = index + 1;
val.Emit(OpCodes.Pop);
}
private static void ColorCatalogGetColorIL(ILContext il)
{
//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_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<ColorIndex, Color32>>((Func<ColorIndex, Color32>)ColorCatalogGetColor);
val.Emit(OpCodes.Ret);
}
private static Color32 ColorCatalogGetColor(ColorIndex colorIndex)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Expected I4, but got Unknown
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
int num = (int)colorIndex;
if (num < 0 || num > GetLength(ref ColorCatalog.indexToColor32))
{
num = 14;
}
return GetItem(ref ColorCatalog.indexToColor32, num);
}
private static void ColorCatalogGetColorHexStringIL(ILContext il)
{
//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_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<ColorIndex, string>>((Func<ColorIndex, string>)ColorCatalogGetColorHexString);
val.Emit(OpCodes.Ret);
}
private static string ColorCatalogGetColorHexString(ColorIndex colorIndex)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Expected I4, but got Unknown
int num = (int)colorIndex;
if (num < 0 || num > GetLength(ref ColorCatalog.indexToHexString))
{
num = 14;
}
return GetItem(ref ColorCatalog.indexToHexString, num);
}
public static DamageColorIndex RegisterDamageColor(Color color)
{
SetHooks();
byte num = (byte)DamageColor.colors.Length;
ArrayUtils.ArrayAppend<Color>(ref DamageColor.colors, ref color);
return (DamageColorIndex)num;
}
public static void AddSerializableDamageColor(SerializableDamageColor serializableDamageColor)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
if (addedSerializableDamageColors.Contains(serializableDamageColor))
{
ColorsPlugin.Logger.LogError((object)$"Attempted to add SerializableDamageColor {serializableDamageColor} twice! aborting.");
}
else
{
serializableDamageColor.DamageColorIndex = RegisterDamageColor(serializableDamageColor.color);
}
}
public static ColorIndex RegisterColor(Color color)
{
//IL_0014: 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_001a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
int length = GetLength(ref ColorCatalog.indexToColor32);
Color32 val = Color32.op_Implicit(color);
ArrayUtils.ArrayAppend<Color32>(ref ColorCatalog.indexToColor32, ref val);
string text = Util.RGBToHex(Color32.op_Implicit(color));
ArrayUtils.ArrayAppend<string>(ref ColorCatalog.indexToHexString, ref text);
return (ColorIndex)length;
}
public static void AddSerializableColor(SerializableColorCatalogEntry serializableColor)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
SetHooks();
if (addedSerializableColors.Contains(serializableColor))
{
ColorsPlugin.Logger.LogError((object)$"Attempted to add SerializableColor {serializableColor} twice! aborting.");
}
else
{
serializableColor.ColorIndex = RegisterColor(Color32.op_Implicit(serializableColor.color32));
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetLength<T>(ref T[] array)
{
return array.Length;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static T GetItem<T>(ref T[] array, int i)
{
return array[i];
}
}
[BepInPlugin("com.bepis.r2api.colors", "R2API.Colors", "1.0.3")]
public sealed class ColorsPlugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
}
private void OnDestroy()
{
ColorsAPI.UnsetHooks();
}
}
}
namespace R2API.AutoVersionGen
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal class AutoVersionAttribute : Attribute
{
}
}
namespace R2API.ScriptableObjects
{
[CreateAssetMenu(fileName = "New ColorCatalogEntry", menuName = "R2API/Colors/ColorCatalogEntry")]
public class SerializableColorCatalogEntry : ScriptableObject
{
public Color32 color32;
public ColorIndex ColorIndex { get; internal set; } = (ColorIndex)(-1);
}
[CreateAssetMenu(fileName = "New DamageColor", menuName = "R2API/Colors/DamageColor")]
public class SerializableDamageColor : ScriptableObject
{
public Color color;
public DamageColorIndex DamageColorIndex { get; internal set; }
}
}