using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using StolenRealmModAPI;
using UnityEngine;
using UnityEngine.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("PortraitColorDot")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+52158c7d25a1953ef0dc1b873b569982776fd2a0")]
[assembly: AssemblyProduct("PortraitColorDot")]
[assembly: AssemblyTitle("PortraitColorDot")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 PortraitColorDot
{
internal class ColorDot : MonoBehaviour
{
private const string DotName = "PortraitColorDot";
private static readonly FieldRef<Portrait, Image> PlayerColorIndicator = AccessTools.FieldRefAccess<Portrait, Image>("playerColorIndicator");
private static Sprite _circleSprite;
private Portrait _portrait;
private Image _image;
private int _layoutVersion = -1;
public static ColorDot Attach(Portrait portrait)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)portrait == (Object)null)
{
return null;
}
Transform val = ((Component)portrait).transform.Find("PortraitColorDot");
if ((Object)(object)val != (Object)null)
{
return ((Component)val).GetComponent<ColorDot>();
}
GameObject val2 = new GameObject("PortraitColorDot", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(((Component)portrait).transform, false);
val2.transform.SetAsLastSibling();
val2.AddComponent<LayoutElement>().ignoreLayout = true;
Image val3 = val2.AddComponent<Image>();
val3.sprite = CircleSprite();
((Graphic)val3).raycastTarget = false;
ColorDot colorDot = val2.AddComponent<ColorDot>();
colorDot._portrait = portrait;
colorDot._image = val3;
colorDot.ApplyLayout();
colorDot.Sync();
return colorDot;
}
private void LateUpdate()
{
if (_layoutVersion != Plugin.LayoutVersion)
{
ApplyLayout();
}
Sync();
}
public void Sync()
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: 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_0079: 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_008a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_portrait == (Object)null) && !((Object)(object)_image == (Object)null))
{
Image val = PlayerColorIndicator.Invoke(_portrait);
bool flag = Plugin.Enabled.Value && (Object)(object)val != (Object)null && _portrait.Character != null;
((Behaviour)_image).enabled = flag;
if (flag)
{
Color color = ((Graphic)val).color;
((Graphic)_image).color = new Color(color.r, color.g, color.b, 1f);
}
}
}
private void ApplyLayout()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
_layoutVersion = Plugin.LayoutVersion;
RectTransform val = (RectTransform)((Component)this).transform;
float value = Plugin.DotSize.Value;
float value2 = Plugin.DotInset.Value;
Vector2 val2 = default(Vector2);
switch (Plugin.DotCorner.Value)
{
case Corner.TopLeft:
((Vector2)(ref val2))..ctor(0f, 1f);
break;
case Corner.BottomLeft:
((Vector2)(ref val2))..ctor(0f, 0f);
break;
case Corner.BottomRight:
((Vector2)(ref val2))..ctor(1f, 0f);
break;
default:
((Vector2)(ref val2))..ctor(1f, 1f);
break;
}
Vector2 val3 = (val.pivot = val2);
Vector2 anchorMin = (val.anchorMax = val3);
val.anchorMin = anchorMin;
val.sizeDelta = new Vector2(value, value);
val.anchoredPosition = new Vector2((val2.x == 0f) ? value2 : (0f - value2), (val2.y == 0f) ? value2 : (0f - value2));
}
private static Sprite CircleSprite()
{
//IL_0019: 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_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_circleSprite != (Object)null)
{
return _circleSprite;
}
Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
{
filterMode = (FilterMode)1,
wrapMode = (TextureWrapMode)1
};
float num = 32f;
Color32[] array = (Color32[])(object)new Color32[4096];
for (int i = 0; i < 64; i++)
{
for (int j = 0; j < 64; j++)
{
float num2 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(num, num));
float num3 = Mathf.Clamp01(num - num2);
float num4 = Mathf.Clamp01(num - 6f - num2);
byte b = (byte)(20f + 235f * num4);
array[i * 64 + j] = new Color32(b, b, b, (byte)(255f * num3));
}
}
val.SetPixels32(array);
val.Apply();
_circleSprite = Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f);
((Object)_circleSprite).name = "PortraitColorDot";
return _circleSprite;
}
}
[BepInPlugin("com.helvetica.portraitcolordot", "Portrait Color Dot", "0.3.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : StolenRealmMod
{
public const string PluginGuid = "com.helvetica.portraitcolordot";
public const string PluginName = "Portrait Color Dot";
public const string PluginVersion = "0.3.0";
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> DotSize;
internal static ConfigEntry<Corner> DotCorner;
internal static ConfigEntry<float> DotInset;
internal static int LayoutVersion;
protected override void OnModLoaded()
{
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Expected O, but got Unknown
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the colored player dot on party portraits.");
DotSize = ((BaseUnityPlugin)this).Config.Bind<float>("Dot", "Size", 18f, new ConfigDescription("Diameter of the color dot, in UI pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 48f), Array.Empty<object>()));
DotCorner = ((BaseUnityPlugin)this).Config.Bind<Corner>("Dot", "Corner", Corner.TopRight, "Which corner of the portrait the dot sits in.");
DotInset = ((BaseUnityPlugin)this).Config.Bind<float>("Dot", "Inset", 4f, new ConfigDescription("Distance from the portrait's edges, in UI pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 24f), Array.Empty<object>()));
DotSize.SettingChanged += delegate
{
LayoutVersion++;
};
DotCorner.SettingChanged += delegate
{
LayoutVersion++;
};
DotInset.SettingChanged += delegate
{
LayoutVersion++;
};
((BaseUnityPlugin)this).Logger.LogInfo((object)"Portrait Color Dot v0.3.0 loaded.");
}
}
public enum Corner
{
TopLeft,
TopRight,
BottomLeft,
BottomRight
}
[HarmonyPatch(typeof(Portrait), "Start")]
internal static class Portrait_Start_Patch
{
private static void Postfix(Portrait __instance)
{
ColorDot.Attach(__instance);
}
}
[HarmonyPatch(typeof(Portrait), "UpdatePlayerColor")]
internal static class Portrait_UpdatePlayerColor_Patch
{
private static void Postfix(Portrait __instance)
{
ColorDot.Attach(__instance)?.Sync();
}
}
}