using System;
using System.Collections;
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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComfyLib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ColorfulPieces")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColorfulPieces")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bfaa6b86-51a5-42a3-83a5-af812a989c5a")]
[assembly: AssemblyFileVersion("1.17.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.17.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.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 ComfyArgs
{
public static readonly Regex CommandRegex = new Regex("^(?<command>\\w[\\w-]*)(?:\\s+--(?:(?<arg>\\w[\\w-]*)=(?:\"(?<value>[^\"]*?)\"|(?<value>\\S+))|no(?<argfalse>\\w[\\w-]*)|(?<argtrue>\\w[\\w-]*)))*");
public static readonly char[] CommaSeparator = new char[1] { ',' };
public readonly Dictionary<string, string> ArgsValueByName = new Dictionary<string, string>();
public ConsoleEventArgs Args { get; }
public string Command { get; private set; }
public ComfyArgs(ConsoleEventArgs args)
{
Args = args;
ParseArgs(args.FullLine);
}
private void ParseArgs(string line)
{
Match match = CommandRegex.Match(line);
Command = match.Groups["command"].Value;
foreach (Capture capture3 in match.Groups["argtrue"].Captures)
{
ArgsValueByName[capture3.Value] = "true";
}
foreach (Capture capture4 in match.Groups["argfalse"].Captures)
{
ArgsValueByName[capture4.Value] = "false";
}
CaptureCollection captures = match.Groups["arg"].Captures;
CaptureCollection captures2 = match.Groups["value"].Captures;
for (int i = 0; i < captures.Count; i++)
{
ArgsValueByName[captures[i].Value] = ((i < captures2.Count) ? captures2[i].Value : string.Empty);
}
}
public bool TryGetValue(string argName, out string argValue)
{
return ArgsValueByName.TryGetValue(argName, out argValue);
}
public bool TryGetValue(string argName, string argShortName, out string argValue)
{
if (!ArgsValueByName.TryGetValue(argName, out argValue))
{
return ArgsValueByName.TryGetValue(argShortName, out argValue);
}
return true;
}
public bool TryGetValue<T>(string argName, out T argValue)
{
argValue = default(T);
if (ArgsValueByName.TryGetValue(argName, out var value))
{
return value.TryParseValue<T>(out argValue);
}
return false;
}
public bool TryGetValue<T>(string argName, string argShortName, out T argValue)
{
argValue = default(T);
if (ArgsValueByName.TryGetValue(argName, out var value) || ArgsValueByName.TryGetValue(argShortName, out value))
{
return value.TryParseValue<T>(out argValue);
}
return false;
}
public bool TryGetListValue<T>(string argName, string argShortName, out List<T> argListValue)
{
if (!ArgsValueByName.TryGetValue(argName, out var value) && !ArgsValueByName.TryGetValue(argShortName, out value))
{
argListValue = null;
return false;
}
string[] array = value.Split(CommaSeparator, StringSplitOptions.RemoveEmptyEntries);
argListValue = new List<T>(array.Length);
for (int i = 0; i < array.Length; i++)
{
if (!array[i].TryParseValue<T>(out var value2))
{
return false;
}
argListValue.Add(value2);
}
return true;
}
public bool GetOptionalValue<T>(string argName, out T? argValue)
{
argValue = default(T);
if (ArgsValueByName.TryGetValue(argName, out var value))
{
return value.TryParseValue<T>(out argValue);
}
return true;
}
public bool GetOptionalValue<T>(string argName, string argShortName, out T? argValue)
{
argValue = default(T);
if (ArgsValueByName.TryGetValue(argName, out var value) || ArgsValueByName.TryGetValue(argShortName, out value))
{
return value.TryParseValue<T>(out argValue);
}
return true;
}
}
[AttributeUsage(AttributeTargets.Method)]
public sealed class ComfyCommand : Attribute
{
}
public static class ComfyCommandUtils
{
private static readonly List<ConsoleCommand> _commands = new List<ConsoleCommand>();
public static void ToggleCommands(bool toggleOn)
{
DeregisterCommands(_commands);
_commands.Clear();
if (toggleOn)
{
_commands.AddRange(RegisterCommands(Assembly.GetExecutingAssembly()));
}
UpdateCommandLists();
}
private static void UpdateCommandLists()
{
Terminal[] array = Object.FindObjectsOfType<Terminal>(true);
for (int i = 0; i < array.Length; i++)
{
array[i].updateCommandList();
}
}
private static void DeregisterCommands(List<ConsoleCommand> commands)
{
foreach (ConsoleCommand command in commands)
{
if (Terminal.commands[command.Command] == command)
{
Terminal.commands.Remove(command.Command);
}
}
}
private static IEnumerable<ConsoleCommand> RegisterCommands(Assembly assembly)
{
return (from method in assembly.GetTypes().SelectMany((Type type) => type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
where method.GetCustomAttributes(typeof(ComfyCommand), inherit: false).Length != 0
select method).SelectMany(RegisterCommands);
}
private static IEnumerable<ConsoleCommand> RegisterCommands(MethodInfo method)
{
if (IsRegisterCommandMethod(method))
{
yield return (ConsoleCommand)method.Invoke(null, null);
}
else
{
if (!IsRegisterCommandsMethod(method))
{
yield break;
}
foreach (ConsoleCommand item in (IEnumerable<ConsoleCommand>)method.Invoke(null, null))
{
yield return item;
}
}
}
private static bool IsRegisterCommandMethod(MethodInfo method)
{
if (method.GetParameters().Length == 0)
{
return typeof(ConsoleCommand).IsAssignableFrom(method.ReturnType);
}
return false;
}
private static bool IsRegisterCommandsMethod(MethodInfo method)
{
if (method.GetParameters().Length == 0)
{
return typeof(IEnumerable<ConsoleCommand>).IsAssignableFrom(method.ReturnType);
}
return false;
}
}
public static class StringExtensions
{
public static readonly char[] CommaSeparator = new char[1] { ',' };
public static readonly char[] ColonSeparator = new char[1] { ':' };
public static bool TryParseValue<T>(this string text, out T value)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
try
{
Vector2 value2;
Vector3 value3;
ZDOID value4;
if (typeof(T) == typeof(string))
{
value = (T)(object)text;
}
else if (typeof(T) == typeof(Vector2) && text.TryParseVector2(out value2))
{
value = (T)(object)value2;
}
else if (typeof(T) == typeof(Vector3) && text.TryParseVector3(out value3))
{
value = (T)(object)value3;
}
else if (typeof(T) == typeof(ZDOID) && text.TryParseZDOID(out value4))
{
value = (T)(object)value4;
}
else if (typeof(T).IsEnum)
{
value = (T)Enum.Parse(typeof(T), text);
}
else
{
value = (T)Convert.ChangeType(text, typeof(T));
}
return true;
}
catch (Exception arg)
{
Debug.LogError((object)$"Failed to convert value '{text}' to type {typeof(T)}: {arg}");
}
value = default(T);
return false;
}
public static bool TryParseVector2(this string text, out Vector2 value)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
string[] array = text.Split(CommaSeparator, 2, StringSplitOptions.RemoveEmptyEntries);
if (array.Length == 2 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
{
value = new Vector2(result, result2);
return true;
}
value = default(Vector2);
return false;
}
public static bool TryParseVector3(this string text, out Vector3 value)
{
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
string[] array = text.Split(CommaSeparator, 3, StringSplitOptions.RemoveEmptyEntries);
if (array.Length == 3 && float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && float.TryParse(array[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
{
value = new Vector3(result, result2, result3);
return true;
}
value = default(Vector3);
return false;
}
public static bool TryParseZDOID(this string text, out ZDOID value)
{
//IL_0048: 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_0040: Unknown result type (might be due to invalid IL or missing references)
string[] array = text.Split(ColonSeparator, 2, StringSplitOptions.RemoveEmptyEntries);
if (array.Length == 2 && long.TryParse(array[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && uint.TryParse(array[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out var result2))
{
value = new ZDOID(result, result2);
return true;
}
value = default(ZDOID);
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 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 ChatExtensions
{
public static void AddMessage(this Chat chat, object obj)
{
if (Object.op_Implicit((Object)(object)chat))
{
((Terminal)chat).AddString($"{obj}");
chat.m_hideTimer = 0f;
}
}
}
public static class ComponentExtensions
{
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 ObjectExtensions
{
public static T FirstByNameOrThrow<T>(this T[] unityObjects, string name) where T : Object
{
foreach (T val in unityObjects)
{
if (((Object)val).name == name)
{
return val;
}
}
throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}");
}
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 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;
}
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;
}
}
}
namespace ColorfulPieces
{
[BepInPlugin("redseiko.valheim.colorfulpieces", "ColorfulPieces", "1.17.0")]
public sealed class ColorfulPieces : BaseUnityPlugin
{
public const string PluginGUID = "redseiko.valheim.colorfulpieces";
public const string PluginName = "ColorfulPieces";
public const string PluginVersion = "1.17.0";
private static ManualLogSource _logger;
private void Awake()
{
_logger = ((BaseUnityPlugin)this).Logger;
PluginConfig.BindConfig(((BaseUnityPlugin)this).Config);
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.colorfulpieces");
}
public static void LogInfo(object obj)
{
_logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
Chat.m_instance.AddMessage(obj);
}
public static void LogError(object obj)
{
_logger.LogError((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}");
Chat.m_instance.AddMessage(obj);
}
}
public interface IPieceColorRenderer
{
void SetColors(GameObject targetObject, Color color, Color emissionColor);
void ClearColors(GameObject targetObject);
}
public sealed class DefaultPieceColorRenderer : IPieceColorRenderer
{
public static DefaultPieceColorRenderer Instance { get; } = new DefaultPieceColorRenderer();
public void SetColors(GameObject targetObject, Color color, Color emissionColor)
{
//IL_0010: 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)
MaterialMan.s_instance.GetPropertyContainer(targetObject).SetPropertyValue<Color>(ShaderProps._Color, color).SetPropertyValue<Color>(ShaderProps._EmissionColor, emissionColor);
}
public void ClearColors(GameObject targetObject)
{
MaterialMan.s_instance.ResetValue(targetObject, ShaderProps._Color);
MaterialMan.s_instance.ResetValue(targetObject, ShaderProps._EmissionColor);
}
}
public sealed class PortalWoodPieceColorRenderer : IPieceColorRenderer
{
public static PortalWoodPieceColorRenderer Instance { get; } = new PortalWoodPieceColorRenderer();
public void SetColors(GameObject targetObject, Color color, Color emissionColor)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
MaterialMan.s_instance.GetPropertyContainer(targetObject).SetPropertyValue<Color>(ShaderProps._Color, color);
}
public void ClearColors(GameObject targetObject)
{
MaterialMan.s_instance.ResetValue(targetObject, ShaderProps._Color);
}
}
public static class ShortcutUtils
{
public static bool OnChangePieceColorShortcut(GameObject hovering)
{
if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component) && Object.op_Implicit((Object)(object)component))
{
ColorfulUtils.ChangePieceColorAction(component);
return true;
}
return false;
}
public static bool OnClearPieceColorShortcut(GameObject hovering)
{
if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component) && Object.op_Implicit((Object)(object)component))
{
ColorfulUtils.ClearPieceColorAction(component);
return true;
}
return false;
}
public static bool OnCopyPieceColorShortcut(GameObject hovering)
{
if (hovering.TryGetComponentInParent<WearNTear>(out WearNTear component) && Object.op_Implicit((Object)(object)component))
{
ColorfulUtils.CopyPieceColorAction(component.m_nview);
return true;
}
return false;
}
}
public static class ColorfulConstants
{
public static readonly int PieceColorHashCode = StringExtensionMethods.GetStableHashCode("PieceColor");
public static readonly int PieceEmissionColorFactorHashCode = StringExtensionMethods.GetStableHashCode("PieceEmissionColorFactor");
public static readonly int PieceLastColoredByHashCode = StringExtensionMethods.GetStableHashCode("PieceLastColoredBy");
public static readonly int PieceLastColoredByHostHashCode = StringExtensionMethods.GetStableHashCode("PieceLastColoredByHost");
public static readonly int GuardStoneHashCode = StringExtensionMethods.GetStableHashCode("guard_stone");
public static readonly int PortalWoodHashCode = StringExtensionMethods.GetStableHashCode("portal_wood");
public static readonly Vector3 NoColorVector3 = new Vector3(-1f, -1f, -1f);
public static readonly float NoEmissionColorFactor = -1f;
public static readonly Vector3 ColorBlackVector3 = new Vector3(0.00012345f, 0.00012345f, 0.00012345f);
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 ColorBlackVector3;
}
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 == ColorBlackVector3))
{
return new Color(vector3.x, vector3.y, vector3.z);
}
return Color.black;
}
}
public static class ColorfulUtils
{
private static readonly List<Piece> _piecesCache = new List<Piece>();
public static void ChangePieceColorAction(WearNTear wearNTear)
{
//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)
SetPieceColor(wearNTear, ColorfulConstants.ColorToVector3(PluginConfig.TargetPieceColor.Value), PluginConfig.TargetPieceEmissionColorFactor.Value);
}
public static void ClearPieceColorAction(WearNTear wearNTear)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
SetPieceColor(wearNTear, ColorfulConstants.NoColorVector3, ColorfulConstants.NoEmissionColorFactor);
}
public static void SetPieceColor(WearNTear wearNTear, Vector3 colorVector3, float emissionColorFactor)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
if (!TryClaimOwnership(wearNTear.m_nview))
{
return;
}
SetPieceColorZDO(wearNTear.m_nview.m_zdo, colorVector3, emissionColorFactor);
PieceColor pieceColor = default(PieceColor);
if (((Component)wearNTear).TryGetComponent<PieceColor>(ref pieceColor))
{
pieceColor.UpdateColors();
}
Piece obj = wearNTear.m_piece.Ref<Piece>();
if (obj != null)
{
EffectList placeEffect = obj.m_placeEffect;
if (placeEffect != null)
{
placeEffect.Create(((Component)wearNTear).transform.position, ((Component)wearNTear).transform.rotation, (Transform)null, 1f, -1);
}
}
}
public static void SetPieceColorZDO(ZDO zdo, Vector3 colorVector3, float emissionColorFactor)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
zdo.Set(ColorfulConstants.PieceColorHashCode, colorVector3);
zdo.Set(ColorfulConstants.PieceEmissionColorFactorHashCode, emissionColorFactor);
zdo.Set(ColorfulConstants.PieceLastColoredByHashCode, Player.m_localPlayer.GetPlayerID());
zdo.Set(ColorfulConstants.PieceLastColoredByHostHashCode, PrivilegeManager.GetNetworkUserId());
}
public static bool TryClaimOwnership(ZNetView netView)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)netView) || !netView.IsValid())
{
return false;
}
if (!PrivateArea.CheckAccess(((Component)netView).transform.position, 0f, true, false))
{
return false;
}
if (((Component)netView).gameObject.TryGetComponentInChildren<Container>(out Container component) && (component.m_inUse || netView.m_zdo.GetInt(ZDOVars.s_inUse, 0) == 1))
{
ColorfulPieces.LogError("Container in target is currently in use!");
return false;
}
netView.ClaimOwnership();
return true;
}
public static bool CopyPieceColorAction(ZNetView netView)
{
//IL_0026: 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_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)netView) || !netView.IsValid() || !netView.m_zdo.TryGetVector3(ColorfulConstants.PieceColorHashCode, out var value))
{
return false;
}
Color val = ColorfulConstants.Vector3ToColor(value);
PluginConfig.TargetPieceColor.SetValue(val);
if (netView.m_zdo.TryGetFloat(ColorfulConstants.PieceEmissionColorFactorHashCode, out var value2))
{
PluginConfig.TargetPieceEmissionColorFactor.Value = value2;
}
MessageHud obj = MessageHud.m_instance.Ref<MessageHud>();
if (obj != null)
{
obj.ShowMessage((MessageType)1, $"Copied piece color: #{ColorUtility.ToHtmlStringRGB(val)} (f: {PluginConfig.TargetPieceEmissionColorFactor.Value})", 0, (Sprite)null);
}
return true;
}
public static IEnumerator ChangeColorsInRadiusCoroutine(Vector3 position, float radius, IReadOnlyCollection<int> prefabHashCodes)
{
yield return null;
_piecesCache.Clear();
GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, radius, _piecesCache);
_piecesCache.RemoveAll((Piece piece) => !Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)piece.m_nview) || !piece.m_nview.IsValid());
if (prefabHashCodes.Count() > 0)
{
_piecesCache.RemoveAll((Piece piece) => !prefabHashCodes.Contains(piece.m_nview.m_zdo.m_prefab));
}
long changeColorCount = 0L;
WearNTear val = default(WearNTear);
foreach (Piece piece2 in _piecesCache)
{
if (changeColorCount % 5 == 0L)
{
yield return null;
}
if (Object.op_Implicit((Object)(object)piece2) && ((Component)piece2).TryGetComponent<WearNTear>(ref val) && Object.op_Implicit((Object)(object)val))
{
ChangePieceColorAction(val);
changeColorCount++;
}
}
ColorfulPieces.LogInfo($"Changed color of {changeColorCount} pieces within {radius} meters.");
_piecesCache.Clear();
}
public static IEnumerator ClearColorsInRadiusCoroutine(Vector3 position, float radius, IReadOnlyCollection<int> prefabHashCodes)
{
yield return null;
_piecesCache.Clear();
GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, radius, _piecesCache);
_piecesCache.RemoveAll((Piece piece) => !Object.op_Implicit((Object)(object)piece) || !Object.op_Implicit((Object)(object)piece.m_nview) || !piece.m_nview.IsValid());
if (prefabHashCodes.Count() > 0)
{
_piecesCache.RemoveAll((Piece piece) => !prefabHashCodes.Contains(piece.m_nview.m_zdo.m_prefab));
}
long clearColorCount = 0L;
WearNTear val = default(WearNTear);
foreach (Piece piece2 in _piecesCache)
{
if (clearColorCount % 5 == 0L)
{
yield return null;
}
if (Object.op_Implicit((Object)(object)piece2) && ((Component)piece2).TryGetComponent<WearNTear>(ref val) && Object.op_Implicit((Object)(object)val))
{
ClearPieceColorAction(val);
clearColorCount++;
}
}
ColorfulPieces.LogInfo($"Cleared colors from {clearColorCount} pieces within {radius} meters.");
_piecesCache.Clear();
}
public static void GetAllPiecesInRadius(Vector3 position, float radius, List<Piece> pieces)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
foreach (Piece s_allPiece in Piece.s_allPieces)
{
if (((Component)s_allPiece).gameObject.layer != Piece.s_ghostLayer && !(Vector3.Distance(position, ((Component)s_allPiece).transform.position) >= radius))
{
pieces.Add(s_allPiece);
}
}
}
}
public static class ChangeColorCommand
{
[CompilerGenerated]
private static class <>O
{
public static ConsoleEventFailable <0>__RunLegacy;
public static ConsoleEventFailable <1>__Run;
}
[ComfyCommand]
public static IEnumerable<ConsoleCommand> Register()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0022: 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_002d: Expected O, but got Unknown
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: 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
ConsoleCommand[] array = new ConsoleCommand[2];
object obj = <>O.<0>__RunLegacy;
if (obj == null)
{
ConsoleEventFailable val = RunLegacy;
<>O.<0>__RunLegacy = val;
obj = (object)val;
}
array[0] = new ConsoleCommand("changecolor", "(ColorfulPieces) Changes the color of all pieces within radius of player to the currently set color.", (ConsoleEventFailable)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj2 = <>O.<1>__Run;
if (obj2 == null)
{
ConsoleEventFailable val2 = Run;
<>O.<1>__Run = val2;
obj2 = (object)val2;
}
array[1] = new ConsoleCommand("change-color", "(ColorfulPieces) change-color --radius=<r> [--prefab=<name1>] [--position=<x,y,z>]", (ConsoleEventFailable)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
return new <>z__ReadOnlyArray<ConsoleCommand>((ConsoleCommand[])(object)array);
}
public static object RunLegacy(ConsoleEventArgs args)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if (args.Length < 2 || !float.TryParse(args.Args[1], out var result) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
return false;
}
((MonoBehaviour)Game.instance).StartCoroutine(ColorfulUtils.ChangeColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, result, (IReadOnlyCollection<int>)(object)Array.Empty<int>()));
return true;
}
public static object Run(ConsoleEventArgs args)
{
return Run(new ComfyArgs(args));
}
public static bool Run(ComfyArgs args)
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
ColorfulPieces.LogInfo(args.Args.FullLine);
if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
ColorfulPieces.LogError("Missing local player.");
return false;
}
if (!args.TryGetValue("radius", "r", out float argValue))
{
ColorfulPieces.LogError("Missing --radius arg.");
return false;
}
if (argValue < 0f)
{
ColorfulPieces.LogError("Invalid --radius arg, cannot be less than 0.");
return false;
}
HashSet<int> hashSet = new HashSet<int>();
if (args.TryGetListValue("prefab", "p", out List<string> argListValue))
{
foreach (string item in argListValue)
{
hashSet.Add(StringExtensionMethods.GetStableHashCode(item));
}
}
if (!args.TryGetValue("position", "pos", out Vector3 argValue2))
{
argValue2 = ((Component)Player.m_localPlayer).transform.position;
}
((MonoBehaviour)Game.instance).StartCoroutine(ColorfulUtils.ChangeColorsInRadiusCoroutine(argValue2, argValue, hashSet));
return true;
}
}
public static class ClearColorCommand
{
[CompilerGenerated]
private static class <>O
{
public static ConsoleEventFailable <0>__RunLegacy;
public static ConsoleEventFailable <1>__Run;
}
[ComfyCommand]
public static IEnumerable<ConsoleCommand> Register()
{
object obj = <>O.<0>__RunLegacy;
if (obj == null)
{
ConsoleEventFailable val = RunLegacy;
<>O.<0>__RunLegacy = val;
obj = (object)val;
}
yield return new ConsoleCommand("clearcolor", "(ColorfulPieces) Clears all colors applied to all pieces within radius of player.", (ConsoleEventFailable)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
object obj2 = <>O.<1>__Run;
if (obj2 == null)
{
ConsoleEventFailable val2 = Run;
<>O.<1>__Run = val2;
obj2 = (object)val2;
}
yield return new ConsoleCommand("clear-color", "(ColorfulPieces) clear-color --radius=<r> [--prefab=<name1>] [--position=<x,y,z>]", (ConsoleEventFailable)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
}
public static object RunLegacy(ConsoleEventArgs args)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
if (args.Length < 2 || !float.TryParse(args.Args[1], out var result) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
return false;
}
((MonoBehaviour)Game.instance).StartCoroutine(ColorfulUtils.ClearColorsInRadiusCoroutine(((Component)Player.m_localPlayer).transform.position, result, (IReadOnlyCollection<int>)(object)Array.Empty<int>()));
return true;
}
public static object Run(ConsoleEventArgs args)
{
return Run(new ComfyArgs(args));
}
public static bool Run(ComfyArgs args)
{
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
ColorfulPieces.LogInfo(args.Args.FullLine);
if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
{
ColorfulPieces.LogError("Missing local player.");
return false;
}
if (!args.TryGetValue("radius", "r", out float argValue))
{
ColorfulPieces.LogError("Missing --radius arg.");
return false;
}
if (argValue < 0f)
{
ColorfulPieces.LogError("Invalid --radius arg, cannot be less than 0.");
return false;
}
HashSet<int> hashSet = new HashSet<int>();
if (args.TryGetListValue("prefab", "p", out List<string> argListValue))
{
foreach (string item in argListValue)
{
hashSet.Add(StringExtensionMethods.GetStableHashCode(item));
}
}
if (!args.TryGetValue("position", "pos", out Vector3 argValue2))
{
argValue2 = ((Component)Player.m_localPlayer).transform.position;
}
((MonoBehaviour)Game.instance).StartCoroutine(ColorfulUtils.ClearColorsInRadiusCoroutine(argValue2, argValue, hashSet));
return true;
}
}
public sealed class PieceColor : MonoBehaviour
{
public static readonly List<PieceColor> PieceColorCache = new List<PieceColor>();
private IPieceColorRenderer _pieceColorRenderer;
private int _cacheIndex;
private long _lastDataRevision;
private Vector3 _lastColorVec3;
private float _lastEmissionColorFactor;
private Color _lastColor;
private Color _lastEmissionColor;
private ZNetView _netView;
public Color TargetColor { get; set; } = Color.clear;
public float TargetEmissionColorFactor { get; set; }
private void Awake()
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
_lastDataRevision = -1L;
_lastColorVec3 = ColorfulConstants.NoColorVector3;
_lastEmissionColorFactor = ColorfulConstants.NoEmissionColorFactor;
_cacheIndex = -1;
if (((Component)this).TryGetComponent<ZNetView>(ref _netView) && Object.op_Implicit((Object)(object)_netView) && _netView.IsValid())
{
PieceColorCache.Add(this);
_cacheIndex = PieceColorCache.Count - 1;
_pieceColorRenderer = GetPieceColorRenderer(_netView.m_zdo.m_prefab);
}
}
private void OnDestroy()
{
if (_cacheIndex >= 0 && _cacheIndex < PieceColorCache.Count)
{
PieceColorCache[_cacheIndex] = PieceColorCache[PieceColorCache.Count - 1];
PieceColorCache[_cacheIndex]._cacheIndex = _cacheIndex;
PieceColorCache.RemoveAt(PieceColorCache.Count - 1);
}
}
public void UpdateColors(bool forceUpdate = false)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: 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_00fa: 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_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)_netView) || !_netView.IsValid() || (!forceUpdate && _lastDataRevision >= _netView.m_zdo.DataRevision))
{
return;
}
bool flag = true;
_lastDataRevision = _netView.m_zdo.DataRevision;
if (!_netView.m_zdo.TryGetVector3(ColorfulConstants.PieceColorHashCode, out var value) || value == ColorfulConstants.NoColorVector3)
{
value = ColorfulConstants.NoColorVector3;
flag = false;
}
if (!_netView.m_zdo.TryGetFloat(ColorfulConstants.PieceEmissionColorFactorHashCode, out var value2) || value2 == ColorfulConstants.NoEmissionColorFactor)
{
value2 = ColorfulConstants.NoEmissionColorFactor;
flag = false;
}
if (forceUpdate || !(value == _lastColorVec3) || value2 != _lastEmissionColorFactor)
{
_lastColorVec3 = value;
_lastEmissionColorFactor = value2;
if (flag)
{
TargetColor = ColorfulConstants.Vector3ToColor(value);
TargetEmissionColorFactor = value2;
_pieceColorRenderer.SetColors(((Component)this).gameObject, TargetColor, TargetColor * TargetEmissionColorFactor);
}
else
{
TargetColor = Color.clear;
TargetEmissionColorFactor = 0f;
_pieceColorRenderer.ClearColors(((Component)this).gameObject);
}
_lastColor = TargetColor;
_lastEmissionColor = TargetColor * TargetEmissionColorFactor;
}
}
public void OverrideColors(Color color, Color emissionColor)
{
//IL_0000: 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_001e: 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)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: 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)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if (!(color == _lastColor) || !(emissionColor == _lastEmissionColor))
{
_lastColor = color;
_lastEmissionColor = emissionColor;
_pieceColorRenderer.SetColors(((Component)this).gameObject, color, emissionColor);
}
}
private static IPieceColorRenderer GetPieceColorRenderer(int prefabHash)
{
if (prefabHash != ColorfulConstants.GuardStoneHashCode && prefabHash == ColorfulConstants.PortalWoodHashCode)
{
return PortalWoodPieceColorRenderer.Instance;
}
return DefaultPieceColorRenderer.Instance;
}
}
public sealed class PieceColorUpdater : MonoBehaviour
{
private void Awake()
{
((MonoBehaviour)this).StartCoroutine(UpdatePieceColors());
}
private IEnumerator UpdatePieceColors()
{
WaitForSeconds waitInterval = new WaitForSeconds(PluginConfig.UpdateColorsWaitInterval.Value);
while (true)
{
int frameLimit = PluginConfig.UpdateColorsFrameLimit.Value;
int index = 0;
while (index < PieceColor.PieceColorCache.Count)
{
for (int i = 0; i < frameLimit; i++)
{
if (PieceColor.PieceColorCache.Count <= 0)
{
break;
}
if (index >= PieceColor.PieceColorCache.Count)
{
break;
}
PieceColor.PieceColorCache[index].UpdateColors();
index++;
}
yield return null;
}
yield return waitInterval;
}
}
}
public static class PluginConfig
{
public static ConfigEntry<bool> IsModEnabled { get; private set; }
public static ConfigEntry<KeyboardShortcut> ChangePieceColorShortcut { get; private set; }
public static ConfigEntry<KeyboardShortcut> ClearPieceColorShortcut { get; private set; }
public static ConfigEntry<KeyboardShortcut> CopyPieceColorShortcut { get; private set; }
public static ExtendedColorConfigEntry TargetPieceColor { get; private set; }
public static ConfigEntry<float> TargetPieceEmissionColorFactor { get; private set; }
public static ConfigEntry<bool> ShowChangeRemoveColorPrompt { get; private set; }
public static ConfigEntry<int> ColorPromptFontSize { get; private set; }
public static ConfigEntry<int> UpdateColorsFrameLimit { get; private set; }
public static ConfigEntry<float> UpdateColorsWaitInterval { get; private set; }
public static ExtendedColorConfigEntry PieceStabilityMinColor { get; private set; }
public static ExtendedColorConfigEntry PieceStabilityMaxColor { get; private set; }
public static void BindConfig(ConfigFile config)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: 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.");
IsModEnabled.OnSettingChanged<bool>(ComfyCommandUtils.ToggleCommands);
ChangePieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "changePieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Shortcut to change the color of the hovered piece.");
ClearPieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "clearPieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Shortcut to clear the color of the hovered piece.");
CopyPieceColorShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "copyPieceColorShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Shortcut to copy the color of the hovered piece.");
TargetPieceColor = new ExtendedColorConfigEntry(config, "Color", "targetPieceColor", Color.cyan, "Target color to set the piece material to.", "targetPieceColorPalette");
TargetPieceColor.AlphaInput.SetValueRange(1f, 1f);
TargetPieceEmissionColorFactor = config.BindInOrder("Color", "targetPieceEmissionColorFactor", 0.4f, "Factor to multiply the target color by and set as emission color.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.8f));
ShowChangeRemoveColorPrompt = config.BindInOrder("Hud", "showChangeRemoveColorPrompt", defaultValue: false, "Show the 'change/remove/copy' color text prompt.");
ColorPromptFontSize = config.BindInOrder("Hud", "colorPromptFontSize", 16, "Font size for the 'change/remove/copy' color text prompt.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 32));
BindUpdateColorsConfig(config);
BindPieceStabilityColorsConfig(config);
}
private static void BindUpdateColorsConfig(ConfigFile config)
{
UpdateColorsFrameLimit = config.BindInOrder("UpdateColors", "updateColorsFrameLimit", 100, "Limit for how many PieceColor.UpdateColors to process per update frame.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 250));
UpdateColorsWaitInterval = config.BindInOrder("UpdateColors", "updateColorsWaitInterval", 5f, "Interval to wait after each PieceColor.UpdateColors loop. *Restart required!*", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 10f));
}
private static void BindPieceStabilityColorsConfig(ConfigFile config)
{
//IL_000b: 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)
PieceStabilityMinColor = new ExtendedColorConfigEntry(config, "PieceStabilityColors", "pieceStabilityMinColor", Color.red, "Color for the Piece Stability highlighting gradient to use for minimum stability.");
PieceStabilityMaxColor = new ExtendedColorConfigEntry(config, "PieceStabilityColors", "pieceStabilityMaxColor", Color.green, "Color for the Piece Stability highlighting gradient to use for maximum stability.");
}
}
public static class MaterialManExtensions
{
public static PropertyContainer GetPropertyContainer(this MaterialMan materialManager, GameObject gameObject)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
int instanceID = ((Object)gameObject).GetInstanceID();
if (!materialManager.m_blocks.TryGetValue(instanceID, out var value))
{
gameObject.AddComponent<MaterialManNotifier>();
value = new PropertyContainer(gameObject, materialManager.m_propertyBlock);
PropertyContainer obj = value;
obj.MarkDirty = (Action<PropertyContainer>)Delegate.Combine(obj.MarkDirty, new Action<PropertyContainer>(materialManager.QueuePropertyUpdate));
materialManager.m_blocks.Add(instanceID, value);
}
return value;
}
public static PropertyContainer SetPropertyValue<T>(this PropertyContainer propertyContainer, int propertyId, T propertyValue)
{
propertyContainer.SetValue<T>(propertyId, propertyValue);
return propertyContainer;
}
}
[HarmonyPatch(typeof(Hud))]
internal static class HudPatch
{
public static readonly string HoverNameTextTemplate = "{0}{1}<size={8}>[<color={2}>{3}</color>] Change color: <color=#{4}>#{4}</color> (<color=#{4}>{5}</color>)\n[<color={6}>{7}</color>] Clear color\n</size>";
[HarmonyPostfix]
[HarmonyPatch("UpdateCrosshair")]
private static void UpdateCrosshairPostfix(Hud __instance, Player player)
{
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
if (PluginConfig.IsModEnabled.Value && PluginConfig.ShowChangeRemoveColorPrompt.Value && Object.op_Implicit((Object)(object)player.m_hovering) && player.m_hovering.TryGetComponentInParent<WearNTear>(out WearNTear component) && Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_nview) && component.m_nview.IsValid())
{
((TMP_Text)__instance.m_hoverName).text = string.Format(HoverNameTextTemplate, ((TMP_Text)__instance.m_hoverName).text, (((TMP_Text)__instance.m_hoverName).text.Length > 0) ? "\n" : string.Empty, "#FFA726", PluginConfig.ChangePieceColorShortcut.Value, ColorUtility.ToHtmlStringRGB(PluginConfig.TargetPieceColor.Value), PluginConfig.TargetPieceEmissionColorFactor.Value.ToString("N2"), "#EF5350", PluginConfig.ClearPieceColorShortcut.Value, PluginConfig.ColorPromptFontSize.Value);
}
}
}
[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
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()! (UpdateHover)")
.Advance(1)
.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
{
new CodeInstruction(OpCodes.Ldloc_1, (object)null),
Transpilers.EmitDelegate<Action<bool>>((Action<bool>)UpdateHoverPostDelegate)
})
.InstructionEnumeration();
}
private static void UpdateHoverPostDelegate(bool takeInput)
{
//IL_0022: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: 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)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
if (takeInput && PluginConfig.IsModEnabled.Value && Player.m_localPlayer.TryGetHovering(out var hovering))
{
KeyboardShortcut value = PluginConfig.ChangePieceColorShortcut.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ShortcutUtils.OnChangePieceColorShortcut(hovering);
}
value = PluginConfig.ClearPieceColorShortcut.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ShortcutUtils.OnClearPieceColorShortcut(hovering);
}
value = PluginConfig.CopyPieceColorShortcut.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
ShortcutUtils.OnCopyPieceColorShortcut(hovering);
}
}
}
private static bool TryGetHovering(this Player player, out GameObject hovering)
{
hovering = (Object.op_Implicit((Object)(object)player) ? player.m_hovering : null);
return Object.op_Implicit((Object)(object)hovering);
}
}
[HarmonyPatch(typeof(StaticPhysics))]
internal static class StaticPhysicsPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void Awake(StaticPhysics __instance)
{
PieceColor pieceColor = default(PieceColor);
if (PluginConfig.IsModEnabled.Value && !((Component)__instance).gameObject.TryGetComponent<PieceColor>(ref pieceColor))
{
((Component)__instance).gameObject.AddComponent<PieceColor>();
}
}
}
[HarmonyPatch(typeof(Terminal))]
internal static class TerminalPatch
{
[HarmonyPrefix]
[HarmonyPatch("InitTerminal")]
private static void InitTerminalPrefix(ref bool __state)
{
__state = Terminal.m_terminalInitialized;
}
[HarmonyPostfix]
[HarmonyPatch("InitTerminal")]
private static void InitTerminalPostfix(bool __state)
{
if (!__state)
{
ComfyCommandUtils.ToggleCommands(PluginConfig.IsModEnabled.Value);
}
}
}
[HarmonyPatch(typeof(Game))]
internal static class GamePatch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void StartPostfix(Game __instance)
{
if (PluginConfig.IsModEnabled.Value)
{
((Component)__instance).gameObject.AddComponent<PieceColorUpdater>();
}
}
}
[HarmonyPatch(typeof(WearNTear))]
internal static class WearNTearPatch
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void AwakePostfix(WearNTear __instance)
{
if (PluginConfig.IsModEnabled.Value)
{
((Component)__instance).gameObject.AddComponent<PieceColor>();
}
}
[HarmonyPrefix]
[HarmonyPatch("Highlight")]
private static bool HighlightPrefix(WearNTear __instance)
{
//IL_001c: 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)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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)
PieceColor pieceColor = default(PieceColor);
if (PluginConfig.IsModEnabled.Value && ((Component)__instance).TryGetComponent<PieceColor>(ref pieceColor))
{
Color supportColor = GetSupportColor(__instance.GetSupportColorValue());
pieceColor.OverrideColors(supportColor, supportColor * 0.4f);
((MonoBehaviour)__instance).CancelInvoke("ResetHighlight");
((MonoBehaviour)__instance).Invoke("ResetHighlight", 0.2f);
return false;
}
return true;
}
private static Color GetSupportColor(float supportColorValue)
{
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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)
Color val = default(Color);
((Color)(ref val))..ctor(0.6f, 0.8f, 1f);
if (supportColorValue >= 0f)
{
val = Color.Lerp(PluginConfig.PieceStabilityMinColor.Value, PluginConfig.PieceStabilityMaxColor.Value, supportColorValue);
float num = default(float);
float num2 = default(float);
float num3 = default(float);
Color.RGBToHSV(val, ref num, ref num2, ref num3);
float num4 = Mathf.Lerp(1f, 0.5f, supportColorValue);
float num5 = Mathf.Lerp(1.2f, 0.9f, supportColorValue);
val = Color.HSVToRGB(num, num4, num5);
}
return val;
}
[HarmonyPrefix]
[HarmonyPatch("ResetHighlight")]
private static bool ResetHighlightPrefix(WearNTear __instance)
{
PieceColor pieceColor = default(PieceColor);
if (PluginConfig.IsModEnabled.Value && ((Component)__instance).TryGetComponent<PieceColor>(ref pieceColor))
{
pieceColor.UpdateColors(forceUpdate: true);
return false;
}
return true;
}
}
}
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
int ICollection.Count => _items.Length;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => _items.Length;
T IReadOnlyList<T>.this[int index] => _items[index];
int ICollection<T>.Count => _items.Length;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlyArray(T[] items)
{
_items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_items).GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_items).CopyTo(array, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return ((IList)_items).Contains(value);
}
int IList.IndexOf(object value)
{
return ((IList)_items).IndexOf(value);
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_items).GetEnumerator();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return ((ICollection<T>)_items).Contains(item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
((ICollection<T>)_items).CopyTo(array, arrayIndex);
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
return ((IList<T>)_items).IndexOf(item);
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}