using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; 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; using UnityEngine.EventSystems; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ComfySigns")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ComfySigns")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("1a56448b-9dac-4352-a528-d9e3f64f992e")] [assembly: AssemblyFileVersion("1.12.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.12.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 ComfySigns { [BepInPlugin("redseiko.valheim.comfysigns", "ComfySigns", "1.12.0")] public sealed class ComfySigns : BaseUnityPlugin { public const string PluginGuid = "redseiko.valheim.comfysigns"; public const string PluginName = "ComfySigns"; public const string PluginVersion = "1.12.0"; private static ManualLogSource _logger; private void Awake() { _logger = ((BaseUnityPlugin)this).Logger; ComfyConfigUtils.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.comfysigns"); } public static void LogInfo(object obj) { _logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } public static void LogWarning(object obj) { _logger.LogWarning((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } } public static class PluginConfig { public static ConfigFile CurrentConfig { get; private set; } public static ConfigEntry IsModEnabled { get; private set; } public static ConfigEntry UseFallbackFonts { get; private set; } public static ConfigEntry SuppressUnicodeNotFoundWarning { get; private set; } public static ConfigEntry SignDefaultTextFontAsset { get; private set; } public static ConfigEntry SignDefaultTextFontColor { get; private set; } public static ConfigEntry SignTextMaximumRenderDistance { get; private set; } public static ConfigEntry SignTextIgnoreSizeTags { get; private set; } public static ConfigEntry SignCanvasLocalPositionOffset { get; private set; } public static ConfigEntry SignEffectMaximumRenderDistance { get; private set; } public static ConfigEntry SignEffectEnablePartyEffect { get; private set; } [ComfyConfig] public static void BindConfig(ConfigFile config) { CurrentConfig = config; IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); UseFallbackFonts = config.BindInOrder("Fonts", "useFallbackFonts", defaultValue: true, "Use fallback fonts to support additional characters."); } [ComfyConfig(typeof(FejdStartup), "Awake")] public static void BindLoggingConfig(ConfigFile config) { SuppressUnicodeNotFoundWarning = config.BindInOrder("Logging", "suppressUnicodeNotFoundWarning", defaultValue: true, "Hide 'The character with Unicode value ... was not found...' log warnings."); SuppressUnicodeNotFoundWarning.OnSettingChanged(SetWarningsDisabled); SetWarningsDisabled(SuppressUnicodeNotFoundWarning.Value); } private static void SetWarningsDisabled(bool warningsDiabled) { TMP_Settings.instance.m_warningsDisabled = warningsDiabled; } [ComfyConfig(typeof(FejdStartup), "Awake")] public static void BindSignConfig(ConfigFile config) { //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) string[] array = (from f in Resources.FindObjectsOfTypeAll() select ((Object)f).name into f orderby f select f).Concat(from f in Resources.FindObjectsOfTypeAll() select ((Object)f).name into f orderby f select f).ToArray(); SignDefaultTextFontAsset = config.BindInOrder("Sign.Text", "defaultTextFontAsset", "Valheim-Norse", "Sign.m_textWidget.fontAsset (TMP) default value.", (AcceptableValueBase)(object)new AcceptableValueList(array)); SignDefaultTextFontAsset.OnSettingChanged(SignUtils.OnSignConfigChanged); SignDefaultTextFontColor = config.BindInOrder("Sign.Text", "defaultTextFontColor", Color.white, "Sign.m_textWidget.color default value."); SignDefaultTextFontColor.OnSettingChanged(SignUtils.OnSignConfigChanged); SignTextMaximumRenderDistance = config.BindInOrder("Sign.Text.Render", "maximumRenderDistance", 192f, "Maximum distance that signs can be from player to render sign text.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 192f)); SignTextIgnoreSizeTags = config.Bind("Sign.Text.Tags", "ignoreSizeTags", false, "if set, ignore any and all tags in sign text when rendered locally."); SignTextIgnoreSizeTags.OnSettingChanged(SignUtils.OnSignTextTagsConfigChanged); SignCanvasLocalPositionOffset = config.Bind("Sign.Canvas", "localPositionOffset", new Vector3(0f, 0f, 0.03f), "Sign.Canvas.localPosition offset value (changes require restart)."); } [ComfyConfig(typeof(FejdStartup), "Awake")] public static void BindSignEffectConfig(ConfigFile config) { SignEffectMaximumRenderDistance = config.BindInOrder("SignEffect", "maximumRenderDistance", 64f, "Maximum distance that signs can be from player to render sign effects.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 128f)); SignEffectMaximumRenderDistance.OnSettingChanged(SignUtils.OnSignEffectConfigChanged); SignEffectEnablePartyEffect = config.BindInOrder("SignEffect.Party", "enablePartyEffect", defaultValue: false, "Enables the 'Party' Sign effect for signs using the party tag."); SignEffectEnablePartyEffect.OnSettingChanged(SignUtils.OnSignEffectConfigChanged); } } public static class SignUtils { public static readonly Regex SizeRegex = new Regex("]*>", RegexOptions.Compiled | RegexOptions.CultureInvariant, TimeSpan.FromMilliseconds(100.0)); public static void AddFallbackFont(TMP_FontAsset font, TMP_FontAsset fallbackFont) { if (Object.op_Implicit((Object)(object)font) && Object.op_Implicit((Object)(object)fallbackFont) && !((Object)(object)fallbackFont == (Object)(object)font)) { if (font.fallbackFontAssets == null) { font.fallbackFontAssets = new List(1) { fallbackFont }; } else if (!font.fallbackFontAssets.Contains(fallbackFont)) { font.fallbackFontAssets.Add(fallbackFont); } } } public static void AddFallbackFonts(TMP_FontAsset font) { AddFallbackFont(font, UIFonts.GetFontAsset("Valheim-Norse")); AddFallbackFont(font, UIFonts.GetFontAsset("Valheim-Norsebold")); AddFallbackFont(font, UIFonts.GetFontAsset("Fallback-NotoSansNormal")); } public static bool HasSignEffect(TMP_Text textComponent, string effectId) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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_0043: Unknown result type (might be due to invalid IL or missing references) if (textComponent.text.Length <= 0 || !textComponent.text.StartsWith("(); foreach (Sign val in array) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.m_nview) && val.m_nview.IsValid() && Object.op_Implicit((Object)(object)val.m_textWidget)) { ProcessSignEffect(val); } } } public static void OnSignTextTagsConfigChanged() { Sign[] array = Resources.FindObjectsOfTypeAll(); foreach (Sign val in array) { if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.m_nview) && val.m_nview.IsValid() && Object.op_Implicit((Object)(object)val.m_textWidget)) { if (PluginConfig.SignTextIgnoreSizeTags.Value) { ProcessSignText(val); } else { ((TMP_Text)val.m_textWidget).text = val.m_currentText; } } } } public static void ProcessSignEffect(Sign sign) { VertexColorCycler vertexColorCycler2 = default(VertexColorCycler); if (((Behaviour)sign.m_textWidget).enabled && HasSignEffect((TMP_Text)(object)sign.m_textWidget, "party") && ShouldRenderSignEffect(sign)) { VertexColorCycler vertexColorCycler = default(VertexColorCycler); if (!((Component)sign.m_textWidget).gameObject.TryGetComponent(ref vertexColorCycler)) { ((Component)sign.m_textWidget).gameObject.AddComponent(); } } else if (((Component)sign.m_textWidget).gameObject.TryGetComponent(ref vertexColorCycler2)) { Object.Destroy((Object)(object)vertexColorCycler2); ((TMP_Text)sign.m_textWidget).ForceMeshUpdate(true, false); } } public static void ProcessSignText(Sign sign) { if (PluginConfig.SignTextIgnoreSizeTags.Value && SizeRegex.IsMatch(((TMP_Text)sign.m_textWidget).text)) { ((TMP_Text)sign.m_textWidget).text = SizeRegex.Replace(((TMP_Text)sign.m_textWidget).text, string.Empty); } } public static void SetupSignFont(Sign sign, TMP_FontAsset fontAsset, Color color) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)((TMP_Text)sign.m_textWidget).font != (Object)(object)fontAsset) { ((TMP_Text)sign.m_textWidget).font = fontAsset; } if ((Object)(object)((TMP_Text)sign.m_textWidget).fontSharedMaterial != (Object)(object)((TMP_Asset)fontAsset).material) { ((TMP_Text)sign.m_textWidget).fontSharedMaterial = ((TMP_Asset)fontAsset).material; } ((Graphic)sign.m_textWidget).color = color; } public static void SetupSignPrefabs(ZNetScene netScene) { //IL_001e: 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_0070: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)netScene)) { return; } TMP_FontAsset fontAsset = UIFonts.GetFontAsset(PluginConfig.SignDefaultTextFontAsset.Value); Color value = PluginConfig.SignDefaultTextFontColor.Value; if (PluginConfig.UseFallbackFonts.Value) { ComfySigns.LogInfo("Adding fallback fonts to font: " + ((Object)fontAsset).name); AddFallbackFonts(fontAsset); } Sign sign = default(Sign); foreach (GameObject value2 in netScene.m_namedPrefabs.Values) { if (value2.TryGetComponent(ref sign)) { SetupSignFont(sign, fontAsset, value); } } Sign sign2 = default(Sign); foreach (ZNetView value3 in netScene.m_instances.Values) { if (((Component)value3).TryGetComponent(ref sign2)) { SetupSignFont(sign2, fontAsset, value); } } } public static bool ShouldRenderSignText(Sign sign) { //IL_0012: 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 (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return Vector3.Distance(((Component)sign).transform.position, ((Component)Player.m_localPlayer).transform.position) <= PluginConfig.SignTextMaximumRenderDistance.Value; } return false; } public static bool ShouldRenderSignEffect(Sign sign) { //IL_0022: 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) if (PluginConfig.SignEffectEnablePartyEffect.Value && Object.op_Implicit((Object)(object)Player.m_localPlayer)) { return Vector3.Distance(((Component)Player.m_localPlayer).transform.position, ((Component)sign).transform.position) <= PluginConfig.SignEffectMaximumRenderDistance.Value; } return false; } } public sealed class TextInputPanelDragger : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler { private RectTransform _rectTransform; private Vector2 _lastMousePosition; private void Start() { _rectTransform = ((Component)this).GetComponent(); } public void OnBeginDrag(PointerEventData eventData) { //IL_0002: 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) _lastMousePosition = eventData.position; } public void OnDrag(PointerEventData eventData) { //IL_0001: 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_000c: 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) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) Vector2 val = eventData.position - _lastMousePosition; RectTransform rectTransform = _rectTransform; ((Transform)rectTransform).position = ((Transform)rectTransform).position + new Vector3(val.x, val.y, 0f); _lastMousePosition = eventData.position; } public void OnEndDrag(PointerEventData eventData) { } } public sealed class VertexColorCycler : MonoBehaviour { [CompilerGenerated] private sealed class d__5 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public VertexColorCycler <>4__this; private TMP_TextInfo 5__2; private int 5__3; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__5(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0111: 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_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; VertexColorCycler vertexColorCycler = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; 5__2 = vertexColorCycler._textComponent.textInfo; 5__3 = 0; break; case 1: <>1__state = -1; break; case 2: <>1__state = -1; break; } int characterCount = 5__2.characterCount; if (characterCount == 0) { <>2__current = _longWait; <>1__state = 1; return true; } int materialReferenceIndex = 5__2.characterInfo[5__3].materialReferenceIndex; Color32[] colors = 5__2.meshInfo[materialReferenceIndex].colors32; int vertexIndex = 5__2.characterInfo[5__3].vertexIndex; if (5__2.characterInfo[5__3].isVisible) { Color32 val = default(Color32); ((Color32)(ref val))..ctor((byte)Random.Range(0, 255), (byte)Random.Range(0, 255), (byte)Random.Range(0, 255), byte.MaxValue); colors[vertexIndex] = val; colors[vertexIndex + 1] = val; colors[vertexIndex + 2] = val; colors[vertexIndex + 3] = val; vertexColorCycler._textComponent.UpdateVertexData((TMP_VertexDataUpdateFlags)16); } int num2 = 5__3; 5__3 = (5__3 + 1) % characterCount; <>2__current = ((num2 < 5__3) ? _shortWait : _longWait); <>1__state = 2; return true; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static readonly WaitForSeconds _longWait = new WaitForSeconds(1f); private static readonly WaitForSeconds _shortWait = new WaitForSeconds(0.05f); private TMP_Text _textComponent; private void Awake() { _textComponent = ((Component)this).GetComponent(); } private void Start() { ((MonoBehaviour)this).StartCoroutine(AnimateVertexColors()); } [IteratorStateMachine(typeof(d__5))] private IEnumerator AnimateVertexColors() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__5(0) { <>4__this = this }; } } [HarmonyPatch(typeof(Sign))] internal static class SignPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(Sign __instance) { //IL_002d: 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_003c: Unknown result type (might be due to invalid IL or missing references) if (PluginConfig.IsModEnabled.Value) { __instance.m_characterLimit = 999; if (((Component)(object)__instance.m_textWidget).TryGetComponentInParent(out Canvas component)) { Transform transform = ((Component)component).transform; transform.localPosition += PluginConfig.SignCanvasLocalPositionOffset.Value; } } } [HarmonyPostfix] [HarmonyPatch("SetText")] private static void SetTextPostfix(Sign __instance) { if (PluginConfig.IsModEnabled.Value) { SignUtils.ProcessSignText(__instance); SignUtils.ProcessSignEffect(__instance); } } [HarmonyPostfix] [HarmonyPatch("UpdateText")] private static void UpdateTextPostfix(Sign __instance) { if (PluginConfig.IsModEnabled.Value) { ((Behaviour)__instance.m_textWidget).enabled = SignUtils.ShouldRenderSignText(__instance); SignUtils.ProcessSignEffect(__instance); } } [HarmonyPostfix] [HarmonyPatch("OnCheckPermissionCompleted")] private static void CanAccessResultFuncPostfix(Sign __instance) { if (PluginConfig.IsModEnabled.Value) { SignUtils.ProcessSignText(__instance); } } } [HarmonyPatch(typeof(TextInput))] internal static class TextInputPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(TextInput __instance) { if (PluginConfig.IsModEnabled.Value && Object.op_Implicit((Object)(object)__instance.m_inputField)) { __instance.m_panel.GetOrAddComponent(); ((TMP_InputField)__instance.m_inputField).richText = false; } } } [HarmonyPatch(typeof(ZNetScene))] internal static class ZNetScenePatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(ZNetScene __instance) { if (PluginConfig.IsModEnabled.Value) { SignUtils.SetupSignPrefabs(__instance); } } } } namespace ComfyLib { [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public sealed class ComfyConfigAttribute : Attribute { internal readonly MethodBase TargetMethod; public ComfyConfigAttribute() { TargetMethod = null; } public ComfyConfigAttribute(Type lateBindType, string lateBindMethodName) { TargetMethod = AccessTools.Method(lateBindType, lateBindMethodName, (Type[])null, (Type[])null); } } [HarmonyPatch] public static class ComfyConfigUtils { private sealed class ConfigBinder { public readonly ConfigFile ConfigFile; public readonly MethodBase TargetMethod; public readonly MethodBase BindConfigMethod; public ConfigBinder(ConfigFile configFile, MethodBase targetMethod, MethodBase bindConfigMethod) { ConfigFile = configFile; TargetMethod = targetMethod; BindConfigMethod = bindConfigMethod; } } private static readonly Dictionary> _configBinders = new Dictionary>(); private static IEnumerable TargetMethods() { return _configBinders.Keys; } private static void Postfix(MethodBase __originalMethod) { if (_configBinders.Count <= 0 || !_configBinders.TryGetValue(__originalMethod, out var value)) { return; } foreach (ConfigBinder item in value) { item.BindConfigMethod.Invoke(null, new object[1] { item.ConfigFile }); } value.Clear(); _configBinders.Remove(__originalMethod); } public static void BindConfig(ConfigFile config) { foreach (MethodInfo bindConfigMethod in GetBindConfigMethods(Assembly.GetExecutingAssembly())) { ComfyConfigAttribute customAttribute = bindConfigMethod.GetCustomAttribute(inherit: false); if (customAttribute.TargetMethod == null) { bindConfigMethod.Invoke(null, new object[1] { config }); } else { AddConfigBinder(config, customAttribute.TargetMethod, bindConfigMethod); } } } private static void AddConfigBinder(ConfigFile configFile, MethodBase targetMethod, MethodBase bindConfigMethod) { if (!_configBinders.TryGetValue(targetMethod, out var value)) { value = new List(); _configBinders[targetMethod] = value; } value.Add(new ConfigBinder(configFile, targetMethod, bindConfigMethod)); } private static List GetBindConfigMethods(Assembly assembly) { List list = new List(); Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { MethodInfo[] methods = types[i].GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.GetCustomAttribute(inherit: false) != null) { ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length == 1 && parameters[0].ParameterType == typeof(ConfigFile)) { list.Add(methodInfo); } } } } return list; } } public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary _sectionToSettingOrder = new Dictionary(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry BindInOrder(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(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 BindInOrder(this ConfigFile config, string section, string key, T defaultValue, string description, Action 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(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(this ConfigEntry configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged(this ConfigEntry configEntry, Action 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(this ConfigEntry configEntry, Action> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry)(object)((SettingChangedEventArgs)eventArgs).ChangedSetting); }; } } public static class ComponentExtensions { public static bool TryGetComponentInParent(this Component source, out T component) where T : Component { component = source.GetComponentInParent(); return Object.op_Implicit((Object)(object)component); } } public static class GameObjectExtensions { public static T GetOrAddComponent(this GameObject gameObject) where T : Component { T result = default(T); if (!gameObject.TryGetComponent(ref result)) { return gameObject.AddComponent(); } return result; } } public static class ObjectExtensions { public static T FirstByNameOrDefault(this IEnumerable unityObjects, string name) where T : Object { foreach (T unityObject in unityObjects) { if (((Object)unityObject).name == name) { return unityObject; } } return default(T); } public static T FirstByNameOrThrow(this IEnumerable unityObjects, string name) where T : Object { foreach (T unityObject in unityObjects) { if (((Object)unityObject).name == name) { return unityObject; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } public static class RectMask2DExtensions { public static RectMask2D SetPadding(this RectMask2D rectMask, float left, float top, float right, float bottom) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) rectMask.padding = new Vector4(left, bottom, right, top); return rectMask; } public static RectMask2D SetSoftness(this RectMask2D rectMask, int horizontal, int vertical) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) rectMask.softness = new Vector2Int(horizontal, vertical); return rectMask; } } public static class TMPInputFieldExtensions { public static TMP_InputField SetRichText(this TMP_InputField inputField, bool richText) { inputField.richText = richText; return inputField; } public static TMP_InputField SetTextViewport(this TMP_InputField inputField, RectTransform viewport) { inputField.textViewport = viewport; return inputField; } } public static class TextMeshProUGUIExtensions { public static TextMeshProUGUI SetColor(this TextMeshProUGUI text, Color color) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (((Graphic)text).color != color) { ((Graphic)text).color = color; } return text; } public static TextMeshProUGUI SetFont(this TextMeshProUGUI text, TMP_FontAsset font) { if ((Object)(object)((TMP_Text)text).font != (Object)(object)font) { ((TMP_Text)text).font = font; } return text; } } public static class UIFonts { public static readonly Dictionary FontCache = new Dictionary(); public const string ValheimAveriaSansLibre = "Valheim-AveriaSansLibre"; public const string ValheimNorse = "Valheim-Norse"; public const string ValheimNorsebold = "Valheim-Norsebold"; public const string FallbackNotoSansNormal = "Fallback-NotoSansNormal"; public static readonly Dictionary FontAssetCache = new Dictionary(); public static Font GetFont(string fontName) { if (!FontCache.TryGetValue(fontName, out var value)) { value = ((IEnumerable)Resources.FindObjectsOfTypeAll()).FirstByNameOrThrow(fontName); FontCache[fontName] = value; } return value; } public static TMP_FontAsset GetFontAsset(string fontName) { if (!FontAssetCache.TryGetValue(fontName, out var value)) { value = ((IEnumerable)Resources.FindObjectsOfTypeAll()).FirstByNameOrDefault(fontName); if (!Object.op_Implicit((Object)(object)value)) { value = TMP_FontAsset.CreateFontAsset(GetFont(fontName)); ((Object)value).name = fontName; } FontAssetCache[fontName] = value; } return value; } } }