using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Splatform;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ColorfulWards")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColorfulWards")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d1397ea5-483e-42f8-9fec-aa29755aaaf1")]
[assembly: AssemblyFileVersion("1.7.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.7.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace ComfyLib
{
public sealed class ExtendedColorConfigEntry
{
private static readonly Texture2D _colorTexture = GUIBuilder.CreateColorTexture(10, 10, Color.white);
private readonly HexColorTextField _hexInput = new HexColorTextField();
private readonly ColorPalette _colorPalette;
private bool _showSliders;
public ConfigEntry<Color> ConfigEntry { get; }
public Color Value { get; private set; }
public ColorFloatTextField RedInput { get; } = new ColorFloatTextField("R");
public ColorFloatTextField GreenInput { get; } = new ColorFloatTextField("G");
public ColorFloatTextField BlueInput { get; } = new ColorFloatTextField("B");
public ColorFloatTextField AlphaInput { get; } = new ColorFloatTextField("A");
public ExtendedColorConfigEntry(ConfigFile config, string section, string key, Color defaultValue, string description)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
ConfigEntry = config.BindInOrder<Color>(section, key, defaultValue, description, (Action<ConfigEntryBase>)Drawer, browsable: true, hideDefaultButton: false, hideSettingName: false, isAdvanced: false, readOnly: false);
SetValue(ConfigEntry.Value);
}
public ExtendedColorConfigEntry(ConfigFile config, string section, string key, Color defaultValue, string description, string colorPaletteKey)
: this(config, section, key, defaultValue, description)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
ConfigEntry<string> paletteConfigEntry = config.BindInOrder(section, colorPaletteKey, ColorUtility.ToHtmlStringRGBA(defaultValue) + ",FF0000FF,00FF00FF,0000FFFF", "Color palette for: [" + section + "] " + key, (Action<ConfigEntryBase>)null, browsable: false, hideDefaultButton: false, hideSettingName: false, isAdvanced: false, readOnly: false);
_colorPalette = new ColorPalette(this, paletteConfigEntry);
}
public void SetValue(Color value)
{
//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_0019: 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_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: 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)
ConfigEntry.Value = value;
Value = value;
RedInput.SetValue(value.r);
GreenInput.SetValue(value.g);
BlueInput.SetValue(value.b);
AlphaInput.SetValue(value.a);
_hexInput.SetValue(value);
}
public void Drawer(ConfigEntryBase configEntry)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: 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_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Invalid comparison between Unknown and I4
//IL_001b: 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_008e: 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_01b8: 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_01df: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
Color val = (Color)configEntry.BoxedValue;
if (GUIFocus.HasChanged() || GUIHelper.IsEnterPressed() || Value != val)
{
SetValue(val);
}
GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
_hexInput.DrawField();
GUILayout.Space(3f);
GUIHelper.BeginColor(val);
GUILayout.Label(string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
if ((int)Event.current.type == 7)
{
GUI.DrawTexture(GUILayoutUtility.GetLastRect(), (Texture)(object)_colorTexture);
}
GUIHelper.EndColor();
GUILayout.Space(3f);
if (GUILayout.Button(_showSliders ? "∨" : "≡", (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.MinWidth(40f),
GUILayout.ExpandWidth(false)
}))
{
_showSliders = !_showSliders;
}
GUILayout.EndHorizontal();
if (_showSliders)
{
GUILayout.Space(4f);
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
RedInput.DrawField();
GUILayout.Space(3f);
GreenInput.DrawField();
GUILayout.Space(3f);
BlueInput.DrawField();
GUILayout.Space(3f);
AlphaInput.DrawField();
GUILayout.EndHorizontal();
}
if (_colorPalette != null)
{
GUILayout.Space(5f);
_colorPalette.DrawColorPalette();
}
GUILayout.EndVertical();
Color val2 = default(Color);
((Color)(ref val2))..ctor(RedInput.CurrentValue, GreenInput.CurrentValue, BlueInput.CurrentValue, AlphaInput.CurrentValue);
if (val2 != val)
{
configEntry.BoxedValue = val2;
SetValue(val2);
}
else if (_hexInput.CurrentValue != val)
{
configEntry.BoxedValue = _hexInput.CurrentValue;
SetValue(_hexInput.CurrentValue);
}
}
}
public sealed class ColorPalette
{
private static readonly char[] _partSeparator = new char[1] { ',' };
private static readonly string _partJoiner = ",";
private static readonly Texture2D _colorTexture = GUIBuilder.CreateColorTexture(10, 10, Color.white);
private readonly ExtendedColorConfigEntry _colorConfigEntry;
private readonly ConfigEntry<string> _paletteConfigEntry;
private readonly List<Color> _paletteColors;
public ColorPalette(ExtendedColorConfigEntry colorConfigEntry, ConfigEntry<string> paletteConfigEntry)
{
_colorConfigEntry = colorConfigEntry;
_paletteConfigEntry = paletteConfigEntry;
_paletteColors = new List<Color>();
LoadPalette();
}
private void LoadPalette()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
_paletteColors.Clear();
string[] array = _paletteConfigEntry.Value.Split(_partSeparator, StringSplitOptions.RemoveEmptyEntries);
Color item = default(Color);
foreach (string text in array)
{
if (ColorUtility.TryParseHtmlString("#" + text, ref item))
{
_paletteColors.Add(item);
}
}
}
private void SavePalette()
{
((ConfigEntryBase)_paletteConfigEntry).BoxedValue = string.Join(_partJoiner, _paletteColors.Select((Color color) => ColorUtility.ToHtmlStringRGBA(color)));
}
private bool PaletteColorButtons(out int colorIndex)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
Texture2D background = GUI.skin.button.normal.background;
GUI.skin.button.normal.background = _colorTexture;
colorIndex = -1;
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
for (int i = 0; i < _paletteColors.Count; i++)
{
GUIHelper.BeginColor(_paletteColors[i]);
if (GUILayout.Button(string.Empty, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(20f),
GUILayout.ExpandWidth(false)
}))
{
colorIndex = i;
}
GUIHelper.EndColor();
if (i + 1 < _paletteColors.Count && (i + 1) % 8 == 0)
{
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
}
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
GUI.skin.button.normal.background = background;
return colorIndex >= 0;
}
private bool AddColorButton()
{
return GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.MinWidth(25f),
GUILayout.ExpandWidth(false)
});
}
private bool RemoveColorButton()
{
return GUILayout.Button("−", (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.MinWidth(25f),
GUILayout.ExpandWidth(false)
});
}
private bool ResetColorsButton()
{
return GUILayout.Button("❇", (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.MinWidth(25f),
GUILayout.ExpandWidth(false)
});
}
public void DrawColorPalette()
{
//IL_001e: 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)
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
if (AddColorButton())
{
_paletteColors.Add(_colorConfigEntry.Value);
SavePalette();
}
GUILayout.Space(2f);
if (PaletteColorButtons(out var colorIndex))
{
if (Event.current.button == 0)
{
_colorConfigEntry.SetValue(_paletteColors[colorIndex]);
}
else if (Event.current.button == 1 && colorIndex >= 0 && colorIndex < _paletteColors.Count)
{
_paletteColors.RemoveAt(colorIndex);
SavePalette();
}
}
GUILayout.FlexibleSpace();
if (_paletteColors.Count > 0)
{
if (RemoveColorButton())
{
_paletteColors.RemoveAt(_paletteColors.Count - 1);
SavePalette();
}
}
else if (ResetColorsButton())
{
((ConfigEntryBase)_paletteConfigEntry).BoxedValue = ((ConfigEntryBase)_paletteConfigEntry).DefaultValue;
LoadPalette();
}
GUILayout.EndHorizontal();
}
}
public sealed class ColorFloatTextField
{
private string _fieldText;
private Color _fieldColor;
public string Label { get; set; }
public float CurrentValue { get; private set; }
public float MinValue { get; private set; }
public float MaxValue { get; private set; }
public void SetValue(float value)
{
//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)
CurrentValue = Mathf.Clamp(value, MinValue, MaxValue);
_fieldText = value.ToString("F3", CultureInfo.InvariantCulture);
_fieldColor = GUI.color;
}
public void SetValueRange(float minValue, float maxValue)
{
MinValue = Mathf.Min(minValue, minValue);
MaxValue = Mathf.Max(maxValue, maxValue);
}
public ColorFloatTextField(string label)
{
Label = label;
SetValueRange(0f, 1f);
}
public void DrawField()
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
GUILayout.Label(Label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
GUIHelper.BeginColor(_fieldColor);
string text = GUILayout.TextField(_fieldText, (GUILayoutOption[])(object)new GUILayoutOption[3]
{
GUILayout.MinWidth(45f),
GUILayout.MaxWidth(55f),
GUILayout.ExpandWidth(true)
});
GUIHelper.EndColor();
GUILayout.EndHorizontal();
GUILayout.Space(2f);
float num = GUILayout.HorizontalSlider(CurrentValue, MinValue, MaxValue, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) });
GUILayout.EndVertical();
if (num != CurrentValue)
{
SetValue(num);
}
else if (!(text == _fieldText))
{
if (float.TryParse(text, NumberStyles.Any, CultureInfo.InvariantCulture, out var result) && result >= MinValue && result <= MaxValue)
{
CurrentValue = result;
_fieldColor = GUI.color;
}
else
{
_fieldColor = Color.red;
}
_fieldText = text;
}
}
}
public sealed class HexColorTextField
{
private Color _textColor = GUI.color;
public Color CurrentValue { get; private set; }
public string CurrentText { get; private set; }
public void SetValue(Color value)
{
//IL_0001: 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_0022: 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_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
CurrentValue = value;
CurrentText = "#" + ((value.a == 1f) ? ColorUtility.ToHtmlStringRGB(value) : ColorUtility.ToHtmlStringRGBA(value));
_textColor = GUI.color;
}
public void DrawField()
{
//IL_0001: 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)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
GUIHelper.BeginColor(_textColor);
string text = GUILayout.TextField(CurrentText, (GUILayoutOption[])(object)new GUILayoutOption[2]
{
GUILayout.Width(90f),
GUILayout.ExpandWidth(false)
});
GUIHelper.EndColor();
if (!(text == CurrentText))
{
CurrentText = text;
Color currentValue = default(Color);
if (ColorUtility.TryParseHtmlString(text, ref currentValue))
{
CurrentValue = currentValue;
}
else
{
_textColor = Color.red;
}
}
}
}
public static class GUIBuilder
{
public static Texture2D CreateColorTexture(int width, int height, Color color)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
return CreateColorTexture(width, height, color, 0, color);
}
public static Texture2D CreateColorTexture(int width, int height, Color color, int radius, Color outsideColor)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
//IL_005d: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
if (width <= 0 || height <= 0)
{
throw new ArgumentException("Texture width and height must be > 0.");
}
if (radius < 0 || radius > width || radius > height)
{
throw new ArgumentException("Texture radius must be >= 0 and < width/height.");
}
Texture2D val = new Texture2D(width, height, (TextureFormat)5, false);
((Object)val).name = $"w-{width}-h-{height}-rad-{radius}-color-{ColorId(color)}-ocolor-{ColorId(outsideColor)}";
((Texture)val).wrapMode = (TextureWrapMode)1;
((Texture)val).filterMode = (FilterMode)2;
Texture2D val2 = val;
Color[] array = (Color[])(object)new Color[width * height];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
array[i * width + j] = (IsCornerPixel(j, i, width, height, radius) ? outsideColor : color);
}
}
val2.SetPixels(array);
val2.Apply();
return val2;
}
private static string ColorId(Color color)
{
//IL_000d: 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_0029: 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)
return $"{color.r:F3}r-{color.g:F3}g-{color.b:F3}b-{color.a:F3}a";
}
private static bool IsCornerPixel(int x, int y, int w, int h, int rad)
{
if (rad == 0)
{
return false;
}
int num = Math.Min(x, w - x);
int num2 = Math.Min(y, h - y);
if (num == 0 && num2 == 0)
{
return true;
}
if (num > rad || num2 > rad)
{
return false;
}
num = rad - num;
num2 = rad - num2;
return Math.Round(Math.Sqrt(num * num + num2 * num2)) > (double)rad;
}
}
public static class GUIFocus
{
private static int _lastFrameCount;
private static int _lastHotControl;
private static int _lastKeyboardControl;
private static bool _hasChanged;
public static bool HasChanged()
{
int frameCount = Time.frameCount;
if (_lastFrameCount == frameCount)
{
return _hasChanged;
}
_lastFrameCount = frameCount;
int hotControl = GUIUtility.hotControl;
int keyboardControl = GUIUtility.keyboardControl;
_hasChanged = hotControl != _lastHotControl || keyboardControl != _lastKeyboardControl;
if (_hasChanged)
{
_lastHotControl = hotControl;
_lastKeyboardControl = keyboardControl;
}
return _hasChanged;
}
}
public static class GUIHelper
{
private static readonly Stack<Color> _colorStack = new Stack<Color>();
public static void BeginColor(Color color)
{
//IL_0005: 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)
_colorStack.Push(GUI.color);
GUI.color = color;
}
public static void EndColor()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
GUI.color = _colorStack.Pop();
}
public static bool IsEnterPressed()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Invalid comparison between Unknown and I4
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Invalid comparison between Unknown and I4
if (Event.current.isKey)
{
if ((int)Event.current.keyCode != 13)
{
return (int)Event.current.keyCode == 271;
}
return true;
}
return false;
}
}
public static class ConfigFileExtensions
{
internal sealed class ConfigurationManagerAttributes
{
public Action<ConfigEntryBase> CustomDrawer;
public bool? Browsable;
public bool? HideDefaultButton;
public bool? HideSettingName;
public bool? IsAdvanced;
public int? Order;
public bool? ReadOnly;
}
private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>();
private static int GetSettingOrder(string section)
{
if (!_sectionToSettingOrder.TryGetValue(section, out var value))
{
value = 0;
}
_sectionToSettingOrder[section] = value - 1;
return value;
}
public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1]
{
new ConfigurationManagerAttributes
{
Browsable = browsable,
CustomDrawer = null,
HideDefaultButton = hideDefaultButton,
HideSettingName = hideSettingName,
IsAdvanced = isAdvanced,
Order = GetSettingOrder(section),
ReadOnly = readOnly
}
}));
}
public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false)
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
{
new ConfigurationManagerAttributes
{
Browsable = browsable,
CustomDrawer = customDrawer,
HideDefaultButton = hideDefaultButton,
HideSettingName = hideSettingName,
IsAdvanced = isAdvanced,
Order = GetSettingOrder(section),
ReadOnly = readOnly
}
}));
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler)
{
configEntry.SettingChanged += delegate
{
settingChangedHandler();
};
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler)
{
configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
};
}
public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler)
{
configEntry.SettingChanged += delegate(object _, EventArgs eventArgs)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue);
};
}
}
public static class ColorExtensions
{
public static string GetColorHtmlString(this Color color)
{
//IL_0000: 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_000d: Unknown result type (might be due to invalid IL or missing references)
if (color.a != 1f)
{
return ColorUtility.ToHtmlStringRGBA(color);
}
return ColorUtility.ToHtmlStringRGB(color);
}
public static Color SetAlpha(this Color color, float alpha)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
color.a = alpha;
return color;
}
}
public static class GameObjectExtensions
{
public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out T component) where T : Component
{
component = gameObject.GetComponentInChildren<T>();
return Object.op_Implicit((Object)(object)component);
}
public static bool TryGetComponentInParent<T>(this GameObject gameObject, out T component) where T : Component
{
component = gameObject.GetComponentInParent<T>();
return Object.op_Implicit((Object)(object)component);
}
}
public static class ParticleSystemExtensions
{
public static void Restart(this ParticleSystem particleSystem)
{
particleSystem.Clear();
particleSystem.Simulate(0f);
particleSystem.Play();
}
}
public static class UnityExtensions
{
public static T Ref<T>(this T unityObject) where T : Object
{
if (!Object.op_Implicit((Object)(object)unityObject))
{
return default(T);
}
return unityObject;
}
}
public static class ZDOExtensions
{
public static bool TryGetFloat(this ZDO zdo, int keyHashCode, out float value)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (ZDOExtraData.s_floats.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(keyHashCode, ref value))
{
return true;
}
value = 0f;
return false;
}
public static bool TryGetVector3(this ZDO zdo, int keyHashCode, out Vector3 value)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
if (ZDOExtraData.s_vec3.TryGetValue(zdo.m_uid, out var value2) && value2.TryGetValue(keyHashCode, ref value))
{
return true;
}
value = default(Vector3);
return false;
}
}
}
namespace ColorfulWards
{
[BepInPlugin("redseiko.valheim.colorfulwards", "ColorfulWards", "1.7.0")]
public sealed class ColorfulWards : BaseUnityPlugin
{
public const string PluginGUID = "redseiko.valheim.colorfulwards";
public const string PluginName = "ColorfulWards";
public const string PluginVersion = "1.7.0";
private static ManualLogSource _logger;
private void Awake()
{
_logger = ((BaseUnityPlugin)this).Logger;
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.colorfulwards");
}
public static void LogInfo(object obj)
{
_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
}
public static void LogError(object obj)
{
_logger.LogError((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
}
}
public sealed class PrivateAreaColor : MonoBehaviour
{
public static readonly int ColorShaderId = Shader.PropertyToID("_Color");
public static readonly int EmissionColorShaderId = Shader.PropertyToID("_EmissionColor");
private PrivateArea _privateArea;
private ZNetView _netView;
private Color _currentColor;
private long _lastDataRevision;
private Light _pointLight;
private ParticleSystem _sparcsParticleSystem;
private ParticleSystem _flareParticleSystem;
private Renderer _glowMaterialRenderer;
private readonly MaterialPropertyBlock _propertyBlock = new MaterialPropertyBlock();
private void Start()
{
//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)
_privateArea = ((Component)this).GetComponent<PrivateArea>();
if (Object.op_Implicit((Object)(object)_privateArea) && Object.op_Implicit((Object)(object)_privateArea.m_nview) && _privateArea.m_nview.IsValid())
{
_netView = _privateArea.m_nview;
_currentColor = PrivateAreaManager.NoColor;
_lastDataRevision = -1L;
_pointLight = ((Component)((Component)this).transform.Find("WayEffect/Point light")).GetComponent<Light>();
_sparcsParticleSystem = ((Component)((Component)this).transform.Find("WayEffect/sparcs")).GetComponent<ParticleSystem>();
_flareParticleSystem = ((Component)((Component)this).transform.Find("WayEffect/flare")).GetComponent<ParticleSystem>();
_glowMaterialRenderer = ((Component)((Component)this).transform.Find("new/default")).GetComponent<Renderer>();
}
}
public void UpdateColors(bool forceUpdate = false)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//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)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)_netView) || !_netView.IsValid())
{
return;
}
long num = _netView.m_zdo.DataRevision;
if (!forceUpdate && _lastDataRevision >= num)
{
return;
}
_lastDataRevision = num;
if (_netView.m_zdo.TryGetVector3(PrivateAreaManager.PrivateAreaColorHashCode, out var value))
{
Color val = PrivateAreaManager.Vector3ToColor(value);
if (_netView.m_zdo.TryGetFloat(PrivateAreaManager.PrivateAreaColorAlphaHashCode, out var value2))
{
val.a = value2;
}
if (!(val == _currentColor))
{
SetPrivateAreaColors(val);
}
}
}
public void SetPrivateAreaColors(Color privateAreaColor)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: 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_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//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_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
_currentColor = privateAreaColor;
_pointLight.color = privateAreaColor;
_glowMaterialRenderer.GetPropertyBlock(_propertyBlock, 0);
_propertyBlock.SetColor(EmissionColorShaderId, privateAreaColor);
_glowMaterialRenderer.SetPropertyBlock(_propertyBlock, 0);
MainModule main = _sparcsParticleSystem.main;
((MainModule)(ref main)).startColor = new MinMaxGradient(privateAreaColor);
ColorOverLifetimeModule colorOverLifetime = _sparcsParticleSystem.colorOverLifetime;
((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(privateAreaColor);
_sparcsParticleSystem.Restart();
main = _flareParticleSystem.main;
((MainModule)(ref main)).startColor = new MinMaxGradient(privateAreaColor.SetAlpha(0.1f));
_flareParticleSystem.Restart();
}
}
public static class PrivateAreaManager
{
public static readonly Color NoColor = new Color(-1f, -1f, -1f);
public static readonly Vector3 NoColorVector3 = new Vector3(-1f, -1f, -1f);
public static readonly Vector3 BlackColorVector3 = new Vector3(0.00012345f, 0.00012345f, 0.00012345f);
public static readonly int PrivateAreaColorHashCode = StringExtensionMethods.GetStableHashCode("PrivateAreaColor");
public static readonly int PrivateAreaColorAlphaHashCode = StringExtensionMethods.GetStableHashCode("PrivateAreaColorAlpha");
public static readonly int WardLastColoredByHashCode = StringExtensionMethods.GetStableHashCode("WardLastColoredBy");
public static readonly int WardLastColoredByHostHashCode = StringExtensionMethods.GetStableHashCode("WardLastColoredByHost");
public static Vector3 ColorToVector3(Color color)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: 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_000d: 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_0019: 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)
if (!(color == Color.black))
{
return new Vector3(color.r, color.g, color.b);
}
return BlackColorVector3;
}
public static Color Vector3ToColor(Vector3 vector3)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: 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_000d: 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_0019: 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)
if (!(vector3 == BlackColorVector3))
{
return new Color(vector3.x, vector3.y, vector3.z);
}
return Color.black;
}
public static bool ChangePrivateAreaColor(PrivateArea targetPrivateArea)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return SetPrivateAreColor(targetPrivateArea, PluginConfig.TargetWardColor.Value);
}
public static bool SetPrivateAreColor(PrivateArea targetPrivateArea, Color targetColor)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)targetPrivateArea))
{
return false;
}
ZNetView nview = targetPrivateArea.m_nview;
if (!Object.op_Implicit((Object)(object)nview) || !nview.IsValid() || !targetPrivateArea.m_piece.IsCreator())
{
return false;
}
if (((Component)nview).gameObject.TryGetComponentInChildren<Container>(out Container component) && (component.m_inUse || nview.m_zdo.GetInt(ZDOVars.s_inUse, 0) == 1))
{
ColorfulWards.LogError("Container in target is currently in use!");
return false;
}
nview.ClaimOwnership();
SetPrivateAreaColorZDO(nview.m_zdo, targetColor);
EffectList flashEffect = targetPrivateArea.m_flashEffect;
if (flashEffect != null)
{
flashEffect.Create(((Component)targetPrivateArea).transform.position, Quaternion.identity, (Transform)null, 1f, -1);
}
PrivateAreaColor privateAreaColor = default(PrivateAreaColor);
if (((Component)targetPrivateArea).TryGetComponent<PrivateAreaColor>(ref privateAreaColor))
{
privateAreaColor.UpdateColors(forceUpdate: true);
}
return true;
}
public static void SetPrivateAreaColorZDO(ZDO zdo, Color targetWardColor)
{
//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_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
zdo.Set(PrivateAreaColorHashCode, ColorToVector3(targetWardColor));
zdo.Set(PrivateAreaColorAlphaHashCode, targetWardColor.a);
zdo.Set(WardLastColoredByHashCode, Player.m_localPlayer.GetPlayerID());
zdo.Set(WardLastColoredByHostHashCode, ((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID.m_userID);
}
}
[HarmonyPatch(typeof(Player))]
internal static class PlayerPatch
{
[HarmonyTranspiler]
[HarmonyPatch("Update")]
private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: 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_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Player), "UpdateHover", (Type[])null, (Type[])null), (string)null)
}).ThrowIfInvalid("Could not patch Player.Update()! (update-hover)")
.Advance(1)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldloc_1, (object)null),
new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerPatch), "UpdateHoverPostDelegate", (Type[])null, (Type[])null))
})
.InstructionEnumeration();
}
private static void UpdateHoverPostDelegate(bool takeInput)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
if (takeInput && PluginConfig.IsModEnabled.Value)
{
KeyboardShortcut value = PluginConfig.ChangeWardColorShortcut.Value;
if (((KeyboardShortcut)(ref value)).IsDown() && Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)Player.m_localPlayer.m_hovering) && Player.m_localPlayer.m_hovering.TryGetComponentInParent<PrivateArea>(out PrivateArea component))
{
PrivateAreaManager.ChangePrivateAreaColor(component);
}
}
}
}
[HarmonyPatch(typeof(PrivateArea))]
internal static class PrivateAreaPatch
{
[HarmonyTranspiler]
[HarmonyPatch("IsInside")]
private static IEnumerable<CodeInstruction> IsInsideTranspiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: 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
return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
{
new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Utils), "DistanceXZ", (Type[])null, (Type[])null), (string)null)
}).ThrowIfInvalid("Could not patch PrivateArea.IsInside()! (distance-xz)")
.SetOperandAndAdvance((object)AccessTools.Method(typeof(PrivateAreaPatch), "DistanceDelegate", (Type[])null, (Type[])null))
.InstructionEnumeration();
}
private static float DistanceDelegate(Vector3 point0, Vector3 point1)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0021: Unknown result type (might be due to invalid IL or missing references)
if (!PluginConfig.IsModEnabled.Value || !PluginConfig.UseRadiusForVerticalCheck.Value)
{
return Utils.DistanceXZ(point0, point1);
}
return Vector3.Distance(point0, point1);
}
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void AwakePostfix(PrivateArea __instance)
{
if (PluginConfig.IsModEnabled.Value && Object.op_Implicit((Object)(object)__instance))
{
AddPrivateAreaColor(__instance.m_nview);
}
}
private static void AddPrivateAreaColor(ZNetView netView)
{
PrivateAreaColor privateAreaColor = default(PrivateAreaColor);
if (Object.op_Implicit((Object)(object)netView) && netView.IsValid() && !((Component)netView).TryGetComponent<PrivateAreaColor>(ref privateAreaColor))
{
((Component)netView).gameObject.AddComponent<PrivateAreaColor>();
}
}
[HarmonyPostfix]
[HarmonyPatch("UpdateStatus")]
private static void UpdateStatusPostfix(PrivateArea __instance)
{
PrivateAreaColor privateAreaColor = default(PrivateAreaColor);
if (PluginConfig.IsModEnabled.Value && ((Component)__instance).TryGetComponent<PrivateAreaColor>(ref privateAreaColor))
{
privateAreaColor.UpdateColors();
}
}
[HarmonyPostfix]
[HarmonyPatch("GetHoverText")]
private static void GetHoverTextPostfix(PrivateArea __instance, ref string __result)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
if (PluginConfig.IsModEnabled.Value && PluginConfig.ShowChangeColorHoverText.Value && __instance.m_piece.IsCreator())
{
__result = string.Format("{0}\n[<color={1}>{2}</color>] Change ward color to: <color=#{3}>#{3}</color>", __result, "#FFA726", PluginConfig.ChangeWardColorShortcut.Value, PluginConfig.TargetWardColor.Value.GetColorHtmlString());
}
}
}
public static class PluginConfig
{
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static ConfigEntry<KeyboardShortcut> ChangeWardColorShortcut { get; private set; }
public static ExtendedColorConfigEntry TargetWardColor { get; private set; }
public static ConfigEntry<bool> UseRadiusForVerticalCheck { get; private set; }
public static ConfigEntry<bool> ShowChangeColorHoverText { get; private set; }
public static void BindConfig(ConfigFile config)
{
//IL_003c: 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)
IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod.");
ChangeWardColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "changeWardColorShortcut", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Keyboard shortcut to change (or clear) the color of the hovered ward.");
TargetWardColor = new ExtendedColorConfigEntry(config, "Color", "targetWardColor", Color.cyan, "Target color to set the ward glow effect to.", "targetWardColorPalette");
UseRadiusForVerticalCheck = config.BindInOrder("PrivateArea", "useRadiusForVerticalCheck", defaultValue: true, "Use the ward radius for access/permission checks vertically. Vanilla is infinite up/down.");
ShowChangeColorHoverText = config.BindInOrder("Hud", "showChangeColorHoverText", defaultValue: false, "Show the 'change color' text when hovering over a lightsoure.");
}
}
}