Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BetrValheim v5.1.12
plugins/BetrValheim.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using BetrValheim.Backpacks; using BetrValheim.Bees; using BetrValheim.Collect; using BetrValheim.Config; using BetrValheim.Cooking; using BetrValheim.Core; using BetrValheim.Crafting; using BetrValheim.Drawers; using BetrValheim.Feeding; using BetrValheim.Info; using BetrValheim.Items; using BetrValheim.Markers; using BetrValheim.Portals; using BetrValheim.Refill; using BetrValheim.Storage; using BetrValheim.Timers; using BetrValheim.UI; using BetrValheim.Visuals; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.GUI; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.UI; using UnityEngine.InputSystem.Utilities; using UnityEngine.Rendering; using UnityEngine.TextCore.LowLevel; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("DezzyCode")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("DezzyCode")] [assembly: AssemblyDescription("Craft from containers and auto-fill refineries and production stations.")] [assembly: AssemblyFileVersion("5.1.12.0")] [assembly: AssemblyInformationalVersion("5.1.12+631ce655b702ca87aad88911da497739df988084")] [assembly: AssemblyProduct("BetrValheim")] [assembly: AssemblyTitle("BetrValheim")] [assembly: AssemblyVersion("5.1.12.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BetrValheim { [BepInPlugin("dezzycode.valheim.betrvalheim", "BetrValheim", "5.1.12")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal sealed class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class SceneAwake { private static void Postfix() { OnWorldChanged(); } } [HarmonyPatch(typeof(ObjectDB), "Awake")] private static class ObjectDbAwake { private static void Postfix() { ItemNames.Invalidate(); DrawerItems.Reset(); ItemSources.InvalidateCounts(); } } [HarmonyPatch(typeof(Game), "Logout")] private static class GameLogout { private static void Prefix() { OnWorldChanged(); } } public const string Guid = "dezzycode.valheim.betrvalheim"; public const string Name = "BetrValheim"; public const string Version = "5.1.12"; private Harmony _harmony; public static readonly List<string> PatchFailures = new List<string>(); public static Plugin Instance { get; private set; } public static bool Active { get { if (Cfg.ModEnabled != null && Cfg.ModEnabled.Value && (Object)(object)ZNetScene.instance != (Object)null) { return (Object)(object)Player.m_localPlayer != (Object)null; } return false; } } private void Awake() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown Instance = this; Log.Init(((BaseUnityPlugin)this).Logger); Cfg.AdoptOldFile(((BaseUnityPlugin)this).Config); Cfg.Bind(((BaseUnityPlugin)this).Config); RegisterKeys(); ((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged; Filters.Init(); PortalNetwork.Init(); MutedMist.Init(); MutedSails.Init(); HiddenHelmet.Init(); CraftingSearch.Init(); MinimapLogo.Init(); ExtraInventory.InitHudPosition(); ExtraInventory.InitPagesPosition(); CornerHud.Init(); Compass.Init(); BetrSkills.Init(); _harmony = new Harmony("dezzycode.valheim.betrvalheim"); ApplyPatches(); HookCompat(); GUIManager.OnCustomGUIAvailable += BetrValheimPanel.Build; SynchronizationManager.OnConfigurationSynchronized += OnConfigSynchronized; if (PatchFailures.Count == 0) { Log.Info("BetrValheim 5.1.12 loaded, all patches applied."); return; } Log.Error(string.Format("{0} {1} loaded with {2} failed patch(es): ", "BetrValheim", "5.1.12", PatchFailures.Count) + string.Join(", ", PatchFailures.ToArray())); Log.Error("The affected feature is off. Please report this log line."); } private void ApplyPatches() { PatchFailures.Clear(); Type[] types = typeof(Plugin).Assembly.GetTypes(); foreach (Type type in types) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0) { try { _harmony.CreateClassProcessor(type).Patch(); Log.Debug("Patched " + type.FullName + "."); } catch (Exception ex) { PatchFailures.Add(type.Name); Log.Error("Patch " + type.FullName + " failed: " + ex.Message); } } } } private static void HookCompat() { Type[] types = typeof(Plugin).Assembly.GetTypes(); foreach (Type type in types) { if (type.Namespace != "BetrValheim.Compat") { continue; } MethodInfo method = type.GetMethod("Hook", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (!(method == null)) { try { method.Invoke(null, null); } catch (Exception ex) { Log.Error("Compat " + type.Name + " could not hook in: " + (ex.InnerException ?? ex).Message); } } } } private void Start() { DrawerPiece.Register(); BeeBoxPiece.Register(); FeedingTroughPiece.Register(); BackpackItem.Register(); TravelRune.Register(); ItemTuning.Init(); ExtraInventory.InitBackpackSlot(); } private void OnDestroy() { GUIManager.OnCustomGUIAvailable -= BetrValheimPanel.Build; SynchronizationManager.OnConfigurationSynchronized -= OnConfigSynchronized; ((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged; BetrValheimPanel.Destroy(); ExtraInventory.DestroyHud(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private static void OnConfigSynchronized(object sender, ConfigurationSynchronizationEventArgs args) { if (args.UpdatedPluginGUIDs == null || args.UpdatedPluginGUIDs.Contains("dezzycode.valheim.betrvalheim")) { ItemSources.InvalidateCounts(); Log.Info(args.InitialSynchronization ? "Server configuration received." : "Server configuration updated."); BetrValheimPanel.RefreshValues(); Refiller.Reset(); Collector.Reset(); } } private static void OnSettingChanged(object sender, SettingChangedEventArgs args) { ItemSources.InvalidateCounts(); } private void LateUpdate() { if (!GUIManager.IsHeadless()) { UiMotion.Late(); } } private void Update() { PortalNetwork.Tick(); TeleportSync.Tick(); if (!GUIManager.IsHeadless()) { BetrUi.Tick(); UiMotion.Tick(); BetrValheimPanel.Tick(); BetrValheimPanel.CloseOnEscapeWithoutMenu(); CornerHud.Tick(); Compass.Tick(); MinimapClock.Tick(); HudLook.Tick(); HudFonts.Tick(); ExtraInventory.Tick(); QuickStack.Tick(); MarkerKeys.Tick(); FetchMaterials.Tick(); DeathRespawn.Tick(); StationChoice.Tick(); ChestRulesWindow.Tick(); DrawerIndex.TickAll(); if (HotkeyPressed()) { BetrValheimPanel.Toggle(); } Refiller.Tick(Player.m_localPlayer); Collector.Tick(Player.m_localPlayer); LazyHarvest.Tick(Player.m_localPlayer); } } private static bool HotkeyPressed() { if (GUIManager.IsHeadless() || Cfg.ToggleKey == null || ZInput.instance == null) { return false; } if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return false; } if (ChestRulesWindow.IsVisible) { return false; } return OwnKeys.IsDown(Cfg.ToggleKey); } private static void RegisterKeys() { ExtraInventory.RegisterSlotKeys(); OwnKeys.Register(Cfg.QuickStackKey, () => Active && Cfg.QuickStackEnabled.Value && QuickStack.KeysAllowed()); OwnKeys.Register(Cfg.RestockKey, () => Active && Cfg.RestockEnabled.Value && QuickStack.KeysAllowed()); OwnKeys.Register(Cfg.FetchMaterialsKey, FetchMaterials.Allowed); OwnKeys.Register(Cfg.MarkerKey, () => Active && MarkerKeys.Enabled && !MarkerPrompt.IsVisible && QuickStack.KeysAllowed()); OwnKeys.Register(Cfg.ToggleKey, () => ((Object)(object)Chat.instance == (Object)null || !Chat.instance.HasFocus()) && !BetrValheimPanel.KeyTaken); } public static void OnWorldChanged() { ContainerIndex.Clear(); StationIndex.Clear(); StationKinds.ClearCache(); ItemNames.Invalidate(); DrawerItems.Reset(); ItemSources.InvalidateCounts(); Prefab.ClearCache(); Refiller.Reset(); Collector.Reset(); BatchCrafting.Reset(); CraftingScope.Reset(); } } } namespace BetrValheim.World { internal static class FloatingItems { [HarmonyPatch(typeof(ItemDrop), "Awake")] private static class AddPatch { private static void Prefix(ItemDrop __instance) { if (!On) { return; } GameObject gameObject = ((Component)__instance).gameObject; if (!((Object)(object)gameObject.GetComponent<Floating>() != (Object)null) && !((Object)(object)gameObject.GetComponent<Rigidbody>() == (Object)null) && !((Object)(object)gameObject.GetComponent<ZNetView>() == (Object)null) && !Sinks(gameObject)) { Floating val = gameObject.AddComponent<Floating>(); Floating val2 = Template(); if (!((Object)(object)val2 == (Object)null)) { val.m_waterLevelOffset = val2.m_waterLevelOffset; val.m_forceDistance = val2.m_forceDistance; val.m_force = val2.m_force; val.m_balanceForceFraction = val2.m_balanceForceFraction; val.m_damping = val2.m_damping; val.m_impactEffects = val2.m_impactEffects; } } } } private static readonly HashSet<string> Exceptions = new HashSet<string>(StringComparer.OrdinalIgnoreCase); private static string _exceptionsFrom; private static Floating _template; private static bool _templateLooked; private static bool On { get { if (Cfg.ModEnabled != null && Cfg.ModEnabled.Value && Cfg.FloatingItems != null) { return Cfg.FloatingItems.Value; } return false; } } private static Floating Template() { if (_templateLooked && (Object)(object)_template != (Object)null) { return _template; } _templateLooked = true; GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab("Wood") : null); _template = (((Object)(object)val != (Object)null) ? val.GetComponent<Floating>() : null); return _template; } private static bool Sinks(GameObject go) { string text = Cfg.FloatingExceptions.Value ?? string.Empty; if ((object)text != _exceptionsFrom) { _exceptionsFrom = text; Exceptions.Clear(); string[] array = text.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length > 0) { Exceptions.Add(text2); } } } if (Exceptions.Count > 0) { return Exceptions.Contains(Prefab.NameOf(go)); } return false; } } internal static class InstantLoot { [HarmonyPatch(typeof(Ragdoll), "Setup")] private static class SetupPatch { private static void Postfix(Ragdoll __instance) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_006d: Unknown result type (might be due to invalid IL or missing references) if (!On) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner()) { ZDO zDO = component.GetZDO(); if (zDO.GetInt(ZDOVars.s_drops, 0) > 0) { Vector3 arg = (((Object)(object)__instance.m_lootSpawnJoint != (Object)null) ? __instance.m_lootSpawnJoint.transform.position : __instance.GetAverageBodyPosition()); SpawnLoot(__instance, arg); zDO.Set(ZDOVars.s_drops, 0, false); } } } } private static readonly Action<Ragdoll, Vector3> SpawnLoot = AccessTools.MethodDelegate<Action<Ragdoll, Vector3>>(AccessTools.Method(typeof(Ragdoll), "SpawnLoot", (Type[])null, (Type[])null), (object)null, true); private static bool On { get { if (Cfg.ModEnabled != null && Cfg.ModEnabled.Value && Cfg.InstantLoot != null) { return Cfg.InstantLoot.Value; } return false; } } } internal static class Regrowth { [HarmonyPatch(typeof(Container), "CheckForChanges")] private static class NoteEmptyPatch { private static void Postfix(Container __instance) { if (!ChestsOn) { return; } ZNetView val = ContainerView.Invoke(__instance); if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner()) { return; } Inventory val2 = ContainerInventory.Invoke(__instance); if (val2 != null && WorldChest(__instance, ContainerPiece.Invoke(__instance))) { ZDO zDO = val.GetZDO(); bool flag = val2.NrOfItems() == 0; long num = zDO.GetLong("BetrValheim_regrow_empty", 0L); if (flag && num == 0L) { zDO.Set("BetrValheim_regrow_empty", ZNet.instance.GetTime().Ticks); } else if (!flag && num != 0L) { zDO.Set("BetrValheim_regrow_empty", 0L); } } } } [HarmonyPatch(typeof(Container), "Awake")] private static class RefillPatch { private static void Prefix(Container __instance) { if (ChestsOn) { ZNetView val = (Object.op_Implicit((Object)(object)__instance.m_rootObjectOverride) ? ((Component)__instance.m_rootObjectOverride).GetComponent<ZNetView>() : ((Component)__instance).GetComponent<ZNetView>()); ZDO val2 = (((Object)(object)val != (Object)null) ? val.GetZDO() : null); if (val2 != null && val.IsOwner() && WorldChest(__instance, ((Component)__instance).GetComponent<Piece>()) && val2.GetBool(ZDOVars.s_addedDefaultItems, false) && DaysOver(val2, "BetrValheim_regrow_empty") && StoredEmpty(val2)) { val2.Set(ZDOVars.s_addedDefaultItems, false); val2.Set("BetrValheim_regrow_empty", 0L); } } } } [HarmonyPatch(typeof(CreatureSpawner), "UpdateSpawner")] private static class NoteGonePatch { private static void Prefix(CreatureSpawner __instance) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Invalid comparison between Unknown and I4 //IL_0058: Unknown result type (might be due to invalid IL or missing references) if (!CampsOn) { return; } ZNetView val = SpawnerView.Invoke(__instance); if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner() || !OnceSpawner(__instance)) { return; } ZDO zDO = val.GetZDO(); ZDOConnection connection = zDO.GetConnection(); if (connection != null && (int)connection.m_type == 3) { bool flag = ZDOMan.instance.GetZDO(connection.m_target) == null; long num = zDO.GetLong("BetrValheim_regrow_gone", 0L); if (flag && num == 0L) { zDO.Set("BetrValheim_regrow_gone", ZNet.instance.GetTime().Ticks); } else if (!flag && num != 0L) { zDO.Set("BetrValheim_regrow_gone", 0L); } } } } [HarmonyPatch(typeof(CreatureSpawner), "Awake")] private static class ReturnPatch { private static void Prefix(CreatureSpawner __instance) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Invalid comparison between Unknown and I4 //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) if (!CampsOn) { return; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val != null && component.IsOwner() && OnceSpawner(__instance) && DaysOver(val, "BetrValheim_regrow_gone")) { ZDOConnection connection = val.GetConnection(); if (connection != null && (int)connection.m_type == 3 && ZDOMan.instance.GetZDO(connection.m_target) == null) { val.SetConnection((ConnectionType)0, ZDOID.None); val.Set("BetrValheim_regrow_gone", 0L); } } } } private const string EmptySince = "BetrValheim_regrow_empty"; private const string GoneSince = "BetrValheim_regrow_gone"; private static readonly FieldRef<Container, ZNetView> ContainerView = AccessTools.FieldRefAccess<Container, ZNetView>("m_nview"); private static readonly FieldRef<Container, Inventory> ContainerInventory = AccessTools.FieldRefAccess<Container, Inventory>("m_inventory"); private static readonly FieldRef<Container, Piece> ContainerPiece = AccessTools.FieldRefAccess<Container, Piece>("m_piece"); private static readonly FieldRef<CreatureSpawner, ZNetView> SpawnerView = AccessTools.FieldRefAccess<CreatureSpawner, ZNetView>("m_nview"); private static readonly Dictionary<GameObject, bool> Returns = new Dictionary<GameObject, bool>(); private static bool Active { get { if (Cfg.ModEnabled != null && Cfg.ModEnabled.Value) { return (Object)(object)ZNet.instance != (Object)null; } return false; } } private static bool ChestsOn { get { if (Active) { return Cfg.RegrowChests.Value; } return false; } } private static bool CampsOn { get { if (Active) { return Cfg.RegrowCamps.Value; } return false; } } private static bool DaysOver(ZDO zdo, string key) { long num = zdo.GetLong(key, 0L); if (num == 0L) { return false; } long num2 = (((Object)(object)EnvMan.instance != (Object)null) ? EnvMan.instance.m_dayLengthSec : 1200); return (double)(ZNet.instance.GetTime().Ticks - num) / 10000000.0 >= (double)Cfg.RegrowDays.Value * (double)num2; } private static bool WorldChest(Container chest, Piece piece) { if (chest.m_autoDestroyEmpty || chest.m_defaultItems == null || chest.m_defaultItems.m_drops == null || chest.m_defaultItems.m_drops.Count == 0) { return false; } if ((Object)(object)piece != (Object)null && piece.GetCreator() != 0L) { return false; } return (Object)(object)((Component)chest).GetComponent<TombStone>() == (Object)null; } private static bool StoredEmpty(ZDO zdo) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown byte[] byteArray = zdo.GetByteArray(ZDOVars.s_items, (byte[])null); if (byteArray == null || byteArray.Length == 0) { return true; } try { ZPackage val = new ZPackage(byteArray); return ((val.ReadInt() >= 108) ? val.ReadUShort() : val.ReadInt()) == 0; } catch (Exception) { return false; } } private static bool OnceSpawner(CreatureSpawner spawner) { if (spawner.m_respawnTimeMinuts <= 0f && (Object)(object)spawner.m_creaturePrefab != (Object)null) { return MayReturn(spawner.m_creaturePrefab); } return false; } private static bool MayReturn(GameObject prefab) { if (Returns.TryGetValue(prefab, out var value)) { return value; } bool flag = false; Character component = prefab.GetComponent<Character>(); if ((Object)(object)component != (Object)null && !component.m_boss && string.IsNullOrEmpty(component.m_bossEvent) && string.IsNullOrEmpty(component.m_defeatSetGlobalKey)) { flag = true; CharacterDrop component2 = prefab.GetComponent<CharacterDrop>(); if ((Object)(object)component2 != (Object)null) { foreach (Drop drop in component2.m_drops) { ItemDrop val = (((Object)(object)drop?.m_prefab != (Object)null) ? drop.m_prefab.GetComponent<ItemDrop>() : null); if (!((Object)(object)val == (Object)null)) { SharedData shared = val.m_itemData.m_shared; if (shared.m_questItem || !shared.m_teleportable) { flag = false; break; } } } } } Returns[prefab] = flag; return flag; } } } namespace BetrValheim.Visuals { internal static class HiddenHelmet { [HarmonyPatch(typeof(VisEquipment), "SetHelmetItem")] private static class SetHelmetPatch { private static void Prefix(VisEquipment __instance, ref int itemHash) { if (itemHash != 0 && !Cfg.ShowHelmet.Value && IsOwn(__instance)) { itemHash = 0; } } } private static readonly FieldRef<Humanoid, ItemData> HelmetOf = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_helmetItem"); internal static void Init() { Cfg.ShowHelmet.SettingChanged += delegate { Refresh(); }; } private static bool IsOwn(VisEquipment equipment) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { return (Object)(object)((Component)equipment).gameObject == (Object)(object)((Component)localPlayer).gameObject; } return false; } private static void Refresh() { Player localPlayer = Player.m_localPlayer; VisEquipment val = (((Object)(object)localPlayer != (Object)null) ? ((Component)localPlayer).GetComponent<VisEquipment>() : null); if (!((Object)(object)val == (Object)null)) { ItemData val2 = HelmetOf.Invoke((Humanoid)(object)localPlayer); val.SetHelmetItem(((Object)(object)val2?.m_dropPrefab != (Object)null) ? StringExtensionMethods.GetStableHashCode(((Object)val2.m_dropPrefab).name) : 0); } } } internal static class MutedMist { [HarmonyPatch(typeof(ParticleMist), "Awake")] private static class MistAwakePatch { private static void Postfix() { Apply(); } } private static ParticleMist _mist; private static Material _material; private static float _originalAlpha; private static float Opacity { get { if (Cfg.MistOpacity == null) { return 1f; } return Mathf.Clamp01((float)Cfg.MistOpacity.Value / 100f); } } internal static void Init() { Cfg.MistOpacity.SettingChanged += delegate { Apply(); }; } private static void Apply() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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) ParticleMist instance = ParticleMist.instance; if ((Object)(object)instance == (Object)null) { return; } if ((Object)(object)instance != (Object)(object)_mist) { _mist = null; _material = null; if (Opacity >= 1f) { return; } ParticleSystemRenderer component = ((Component)instance).GetComponent<ParticleSystemRenderer>(); if ((Object)(object)component == (Object)null) { return; } _mist = instance; _material = ((Renderer)component).material; _originalAlpha = _material.color.a; } if (!((Object)(object)_material == (Object)null)) { Color color = _material.color; color.a = _originalAlpha * Opacity; _material.color = color; } } } internal static class MutedSails { private sealed class SailState : MonoBehaviour { public bool Swapped; public SkinnedMeshRenderer[] Renderers; public Material[][] Originals; } [HarmonyPatch(typeof(Ship), "OnEnable")] private static class ShipEnablePatch { private static void Postfix(Ship __instance) { if (_everTransparent || Opacity < 1f) { Pending.Add(__instance); } } } [HarmonyPatch(typeof(Ship), "OnDisable")] private static class ShipDisablePatch { private static void Postfix(Ship __instance) { Pending.Remove(__instance); } } [HarmonyPatch(typeof(Ship), "UpdateSailSize")] private static class SailSizePatch { private static void Postfix(Ship __instance) { if (Pending.Count != 0 && Pending.Remove(__instance)) { Apply(__instance, ((Component)__instance).GetComponent<SailState>()); } } } private const string ShaderName = "Custom/LitParticles"; private static readonly HashSet<Ship> Pending = new HashSet<Ship>(); private static bool _everTransparent; private static Shader _shader; private static bool _shaderMissing; private static readonly Dictionary<Material, Material> Transparent = new Dictionary<Material, Material>(); private static readonly Dictionary<Material, Color> BaseColors = new Dictionary<Material, Color>(); private static float Opacity { get { if (Cfg.SailOpacity == null) { return 1f; } return Mathf.Clamp01((float)Cfg.SailOpacity.Value / 100f); } } internal static void Init() { Cfg.SailOpacity.SettingChanged += delegate { UpdateAlpha(); foreach (IMonoUpdater instance in Ship.Instances) { Ship val = (Ship)(object)((instance is Ship) ? instance : null); if (val != null && (Object)(object)val != (Object)null) { Pending.Add(val); } } }; } private static void Apply(Ship ship, SailState state) { if (Player.IsPlacementGhost(((Component)ship).gameObject)) { return; } if ((Object)(object)state == (Object)null) { state = ((Component)ship).gameObject.AddComponent<SailState>(); state.Renderers = SailRenderers(ship); } bool flag = Opacity < 1f; if (flag == state.Swapped) { return; } if (flag) { if (!EnsureShader()) { return; } state.Originals = new Material[state.Renderers.Length][]; for (int i = 0; i < state.Renderers.Length; i++) { SkinnedMeshRenderer val = state.Renderers[i]; if (!((Object)(object)val == (Object)null)) { Material[] sharedMaterials = ((Renderer)val).sharedMaterials; state.Originals[i] = sharedMaterials; Material[] array = (Material[])(object)new Material[sharedMaterials.Length]; for (int j = 0; j < sharedMaterials.Length; j++) { array[j] = TransparentCopy(sharedMaterials[j]); } ((Renderer)val).sharedMaterials = array; } } _everTransparent = true; } else { for (int k = 0; k < state.Renderers.Length; k++) { SkinnedMeshRenderer val2 = state.Renderers[k]; if ((Object)(object)val2 != (Object)null && state.Originals != null && state.Originals[k] != null) { ((Renderer)val2).sharedMaterials = state.Originals[k]; } } state.Originals = null; } state.Swapped = flag; if ((Object)(object)ship.m_sailCloth != (Object)null) { ship.m_sailCloth.SetParameterChange(); } } private static SkinnedMeshRenderer[] SailRenderers(Ship ship) { List<SkinnedMeshRenderer> list = new List<SkinnedMeshRenderer>(); if ((Object)(object)ship.m_sailCloth != (Object)null) { list.AddRange(((Component)ship.m_sailCloth).GetComponentsInChildren<SkinnedMeshRenderer>(true)); } if ((Object)(object)ship.m_sailObject != (Object)null) { SkinnedMeshRenderer[] componentsInChildren = ship.m_sailObject.GetComponentsInChildren<SkinnedMeshRenderer>(true); foreach (SkinnedMeshRenderer item in componentsInChildren) { if (!list.Contains(item)) { list.Add(item); } } } return list.ToArray(); } private static bool EnsureShader() { if ((Object)(object)_shader != (Object)null) { return true; } if (_shaderMissing) { return false; } _shader = Cache.GetPrefab<Shader>("Custom/LitParticles") ?? Shader.Find("Custom/LitParticles"); if ((Object)(object)_shader != (Object)null) { return true; } _shaderMissing = true; Log.Warning("The game has no shader Custom/LitParticles; sails stay as they are."); return false; } private static Material TransparentCopy(Material original) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)original == (Object)null) { return null; } if (Transparent.TryGetValue(original, out var value) && (Object)(object)value != (Object)null) { return value; } value = new Material(_shader) { name = ((Object)original).name + " (BetrValheim transparent)" }; if (original.HasProperty("_MainTex")) { value.SetTexture("_MainTex", original.GetTexture("_MainTex")); value.SetTextureScale("_MainTex", original.GetTextureScale("_MainTex")); value.SetTextureOffset("_MainTex", original.GetTextureOffset("_MainTex")); } Color val = (original.HasProperty("_Color") ? original.GetColor("_Color") : Color.white); BaseColors[value] = val; value.color = WithAlpha(val); Transparent[original] = value; return value; } private static Color WithAlpha(Color baseColor) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) baseColor.a *= Opacity; return baseColor; } private static void UpdateAlpha() { //IL_0033: 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) foreach (Material value2 in Transparent.Values) { if ((Object)(object)value2 != (Object)null && BaseColors.TryGetValue(value2, out var value)) { value2.color = WithAlpha(value); } } } } } namespace BetrValheim.UI { internal static class ActionRing { [HarmonyPatch(typeof(Hud), "UpdateActionProgress")] private static class UpdatePatch { private static void Postfix(Hud __instance, Player player) { try { Update(__instance, player); } catch (Exception ex) { Log.Warning("The action ring could not be drawn: " + ex.Message); _look = BetrUi.Version; } } } private const float Lower = 40f; private const float Size = 64f; private static Hud _hud; private static RectTransform _root; private static RectTransform _ring; private static RectTransform _word; private static Image _fill; private static int _look = -1; private static float _shown = -1f; private static Vector2 _rootPlace; private static Vector2 _wordPlace; private static Vector2 _wordMin; private static Vector2 _wordMax; private static Vector2 _wordSize; private static readonly List<Image> Hidden = new List<Image>(); private static Sprite _ringSprite; private static void Update(Hud hud, Player player) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown if ((Object)(object)hud.m_actionBarRoot == (Object)null) { return; } if ((Object)(object)_hud != (Object)(object)hud) { _hud = hud; _root = (RectTransform)hud.m_actionBarRoot.transform; _word = (((Object)(object)hud.m_actionName != (Object)null) ? hud.m_actionName.rectTransform : null); _ring = null; _look = -1; Hidden.Clear(); } if (_look != BetrUi.Version) { _look = BetrUi.Version; Switch(BetrUi.On); } if (BetrUi.On && ((Component)_root).gameObject.activeSelf && !((Object)(object)_fill == (Object)null) && !((Object)(object)player == (Object)null)) { string text = default(string); float num = default(float); MinorActionData val = default(MinorActionData); player.GetActionProgress(ref text, ref num, ref val); if (!Mathf.Approximately(num, _shown)) { _shown = num; _fill.fillAmount = Mathf.Clamp01(num); } } } private static void Switch(bool on) { //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_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) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0232: 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_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_019e: 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) if (on) { if ((Object)(object)_ring == (Object)null) { _rootPlace = _root.anchoredPosition; if ((Object)(object)_word != (Object)null) { _wordPlace = _word.anchoredPosition; _wordMin = _word.anchorMin; _wordMax = _word.anchorMax; _wordSize = _word.sizeDelta; } Image[] componentsInChildren = ((Component)_root).GetComponentsInChildren<Image>(true); foreach (Image val in componentsInChildren) { if (((Behaviour)val).enabled) { Hidden.Add(val); } } _ring = MakeRing(); if ((Object)(object)_word != (Object)null) { BetrUiSkin.Dress(((Component)_word).gameObject); } } foreach (Image item in Hidden) { if ((Object)(object)item != (Object)null) { ((Behaviour)item).enabled = false; } } ((Component)_ring).gameObject.SetActive(true); _root.anchoredPosition = _rootPlace - new Vector2(0f, 40f); if ((Object)(object)_word != (Object)null) { RectTransform word = _word; RectTransform word2 = _word; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); word2.anchorMax = val2; word.anchorMin = val2; _word.sizeDelta = new Vector2(Mathf.Max(_wordSize.x, 240f), Mathf.Max(_wordSize.y, 28f)); _word.anchoredPosition = new Vector2(0f, -50f); } _shown = -1f; } else { if (!((Object)(object)_ring != (Object)null)) { return; } ((Component)_ring).gameObject.SetActive(false); foreach (Image item2 in Hidden) { if ((Object)(object)item2 != (Object)null) { ((Behaviour)item2).enabled = true; } } _root.anchoredPosition = _rootPlace; if ((Object)(object)_word != (Object)null) { _word.anchorMin = _wordMin; _word.anchorMax = _wordMax; _word.sizeDelta = _wordSize; _word.anchoredPosition = _wordPlace; } } } private static RectTransform MakeRing() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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) //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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00c5: Expected O, but got Unknown RectTransform val = (RectTransform)new GameObject("BetrUI ActionRing", new Type[1] { typeof(RectTransform) }) { layer = 5 }.transform; ((Transform)val).SetParent((Transform)(object)_root, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); val.pivot = val2; Vector2 anchorMin = (val.anchorMax = val2); val.anchorMin = anchorMin; val.sizeDelta = new Vector2(64f, 64f); val.anchoredPosition = Vector2.zero; ((Transform)val).SetAsFirstSibling(); Part(val, "Track", new Color(0f, 0f, 0f, 0.55f), filled: false); _fill = Part(val, "Fill", BetrUi.Accent, filled: true); return val; } private static Image Part(RectTransform parent, string name, Color colour, bool filled) { //IL_0021: 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_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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: 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: 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) GameObject val = new GameObject(name, new Type[2] { typeof(RectTransform), typeof(Image) }) { layer = 5 }; RectTransform val2 = (RectTransform)val.transform; ((Transform)val2).SetParent((Transform)(object)parent, false); val2.anchorMin = Vector2.zero; val2.anchorMax = Vector2.one; Vector2 offsetMin = (val2.offsetMax = Vector2.zero); val2.offsetMin = offsetMin; Image component = val.GetComponent<Image>(); component.sprite = RingSprite(); ((Graphic)component).color = colour; ((Graphic)component).raycastTarget = false; component.preserveAspect = true; if (filled) { component.type = (Type)3; component.fillMethod = (FillMethod)4; component.fillOrigin = 2; component.fillClockwise = true; component.fillAmount = 0f; } return component; } private static Sprite RingSprite() { //IL_001f: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ringSprite != (Object)null) { return _ringSprite; } Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Color32[] array = (Color32[])(object)new Color32[16384]; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { float num = (float)j + 0.5f - 64f; float num2 = (float)i + 0.5f - 64f; float num3 = Mathf.Sqrt(num * num + num2 * num2); float num4 = Mathf.Clamp01(62.5f - num3) * Mathf.Clamp01(num3 - 46f + 0.5f); array[i * 128 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num4 * 255f)); } } val.SetPixels32(array); val.Apply(false, true); _ringSprite = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f); ((Object)_ringSprite).name = "BetrUI action ring"; return _ringSprite; } } internal static class AutoEquipArmor { private struct Running { public Player Player; public MinorActionData Action; } [HarmonyPatch(typeof(Humanoid), "Pickup")] private static class Pickup { private static void Prefix(Humanoid __instance, GameObject go, bool autoequip, out ItemDrop __state) { __state = null; if (On && autoequip && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)go == (Object)null)) { ItemDrop component = go.GetComponent<ItemDrop>(); if (Armor(component?.m_itemData)) { __state = component; } } } [HarmonyPriority(0)] private static void Postfix(Humanoid __instance, bool __result, ItemDrop __state) { if (__result && __state?.m_itemData != null) { TryQueue((Player)(object)((__instance is Player) ? __instance : null), __state.m_itemData, fromGrave: false); } } } private struct Piece { public string Name; public int Quality; public int Variant; } [HarmonyPatch(typeof(Player), "CreateTombStone")] private static class DeathPatch { [HarmonyPriority(800)] private static void Prefix(Player __instance) { if (!Plugin.Active || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } try { Carried.Clear(); ExtraInventory.CarriedItems(__instance, Carried); foreach (ItemData item in Carried) { item.m_customData?.Remove("ew_worn"); if (item.m_equipped && Gear(item)) { if (item.m_customData == null) { item.m_customData = new Dictionary<string, string>(); } item.m_customData["ew_worn"] = "1"; } } } finally { Carried.Clear(); } } } [HarmonyPatch(typeof(Container), "RPC_TakeAllResponse")] private static class GravePatch { private static void Prefix(Container __instance, bool granted) { FromGrave.Clear(); if (!On || !granted || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)((Component)__instance).GetComponent<TombStone>() == (Object)null) { return; } Inventory inventory = __instance.GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { if (Armor(allItem) || (WornAtDeath(allItem) && Gear(allItem))) { FromGrave.Add(new Piece { Name = allItem.m_shared.m_name, Quality = allItem.m_quality, Variant = allItem.m_variant }); } } } private static void Postfix() { if (FromGrave.Count == 0) { return; } Player localPlayer = Player.m_localPlayer; try { if ((Object)(object)localPlayer == (Object)null) { return; } Carried.Clear(); ExtraInventory.CarriedItems(localPlayer, Carried); foreach (Piece item in FromGrave) { foreach (ItemData item2 in Carried) { if (!item2.m_equipped && item2.m_shared.m_name == item.Name && item2.m_quality == item.Quality && item2.m_variant == item.Variant && (Armor(item2) || Gear(item2))) { TryQueue(localPlayer, item2, fromGrave: true); break; } } } foreach (ItemData item3 in Carried) { item3.m_customData?.Remove("ew_worn"); } } finally { FromGrave.Clear(); Carried.Clear(); } } } [HarmonyPatch(typeof(Player), "UpdateActionQueue")] private static class QueueContext { private static void Prefix(Player __instance, out Running __state) { __state = _running; _running = default(Running); if (_everQueued && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { List<MinorActionData> list = Actions.Invoke(__instance); if (list.Count > 0 && Automatic.TryGetValue(list[0], out var _)) { _running = new Running { Player = __instance, Action = list[0] }; } } } private static void Finalizer(Running __state) { _running = __state; } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] private static class PreserveWorn { [HarmonyPriority(800)] private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result) { //IL_0072: Unknown result type (might be due to invalid IL or missing references) MinorActionData action = _running.Action; if (action == null || (Object)(object)_running.Player != (Object)(object)__instance || action.m_item != item || !Automatic.Remove(action)) { return true; } if (On && !((Character)_running.Player).IsDead() && ExtraInventory.Holding(_running.Player, item) != null && Worn(_running.Player, item.m_shared.m_itemType) == null) { return true; } __result = false; return false; } } private static readonly Action<Player, ItemData> Queue = AccessTools.MethodDelegate<Action<Player, ItemData>>(AccessTools.Method(typeof(Player), "QueueEquipAction", (Type[])null, (Type[])null), (object)null, true); private static readonly FieldRef<Player, List<MinorActionData>> Actions = AccessTools.FieldRefAccess<Player, List<MinorActionData>>("m_actionQueue"); private static readonly FieldRef<Humanoid, ItemData> Helmet = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_helmetItem"); private static readonly FieldRef<Humanoid, ItemData> Chest = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_chestItem"); private static readonly FieldRef<Humanoid, ItemData> Legs = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_legItem"); private static readonly FieldRef<Humanoid, ItemData> Shoulder = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_shoulderItem"); private static readonly FieldRef<Humanoid, ItemData> Right = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_rightItem"); private static readonly FieldRef<Humanoid, ItemData> Left = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_leftItem"); private static readonly FieldRef<Humanoid, ItemData> Utility = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_utilityItem"); private static readonly FieldRef<Humanoid, ItemData> Trinket = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_trinketItem"); private static readonly ConditionalWeakTable<MinorActionData, object> Automatic = new ConditionalWeakTable<MinorActionData, object>(); private static readonly object Marker = new object(); private static bool _everQueued; private static Running _running; private const string WornKey = "ew_worn"; private static readonly List<Piece> FromGrave = new List<Piece>(4); private static readonly List<ItemData> Carried = new List<ItemData>(64); private static bool On { get { if (Cfg.AutoEquipArmor != null && Cfg.AutoEquipArmor.Value) { return Plugin.Active; } return false; } } private static bool Armor(ItemData item) { //IL_0016: 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_001c: 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_0020: Invalid comparison between Unknown and I4 //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 if (item?.m_shared == null) { return false; } ItemType itemType = item.m_shared.m_itemType; if (itemType - 6 > 1 && (int)itemType != 11) { if ((int)itemType == 17) { return !BackpackItem.Is(item); } return false; } return true; } private static bool Gear(ItemData item) { //IL_0024: 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_002a: 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_002e: Invalid comparison between Unknown and I4 //IL_0030: 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_0065: Expected I4, but got Unknown if (item?.m_shared == null || item.m_shared.m_maxStackSize > 1) { return false; } ItemType itemType = item.m_shared.m_itemType; if (itemType - 3 > 2) { switch (itemType - 14) { case 0: case 1: case 4: case 5: case 8: case 10: break; default: return false; } } return true; } private static ItemData Worn(Player player, ItemType type) { //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_0060: Expected I4, but got Unknown switch (type - 3) { case 3: return Helmet.Invoke((Humanoid)(object)player); case 4: return Chest.Invoke((Humanoid)(object)player); case 8: return Legs.Invoke((Humanoid)(object)player); case 14: return Shoulder.Invoke((Humanoid)(object)player); case 1: case 2: case 19: return Left.Invoke((Humanoid)(object)player); case 0: case 12: case 16: return Right.Invoke((Humanoid)(object)player); case 11: return Right.Invoke((Humanoid)(object)player) ?? Left.Invoke((Humanoid)(object)player); case 15: return Utility.Invoke((Humanoid)(object)player); case 21: return Trinket.Invoke((Humanoid)(object)player); default: return null; } } private static bool WornAtDeath(ItemData item) { if (item?.m_customData != null) { return item.m_customData.ContainsKey("ew_worn"); } return false; } private static void TryQueue(Player player, ItemData item, bool fromGrave) { //IL_006a: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Invalid comparison between Unknown and I4 //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) if (!On || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.m_localPlayer || ((Character)player).IsDead() || (!Armor(item) && (!fromGrave || !Gear(item))) || item.m_equipped || (item.m_shared.m_useDurability && item.m_durability <= 0f) || ExtraInventory.Holding(player, item) == null || Worn(player, item.m_shared.m_itemType) != null) { return; } List<MinorActionData> list = Actions.Invoke(player); foreach (MinorActionData item2 in list) { if (((int)item2.m_type == 0 || (int)item2.m_type == 1) && item2.m_item?.m_shared?.m_itemType == (ItemType?)item.m_shared.m_itemType) { return; } } if (item.m_shared.m_equipDuration <= 0f) { ((Humanoid)player).EquipItem(item, true); return; } Queue(player, item); if (list.Count != 0) { MinorActionData val = list[list.Count - 1]; if ((int)val.m_type == 0 && val.m_item == item) { Automatic.Add(val, Marker); _everQueued = true; } } } } internal static class BetrUi { private static readonly Color WindowColour = Rgb(44, 32, 23); private static readonly Color EdgeColour = Rgb(24, 17, 12); private static readonly Color InsetColour = Rgb(33, 24, 17); private static readonly Color ButtonColour = Rgb(62, 46, 33); private static readonly Color ButtonHover = Rgb(82, 61, 44); private static readonly Color ButtonDown = Rgb(50, 37, 27); private static readonly Color LitColour = Rgb(196, 124, 52); private static readonly Color LitHover = Rgb(214, 140, 64); private static readonly Color FieldColour = Rgb(17, 12, 8); private static readonly Color HandleColour = Rgb(96, 72, 52); public static readonly Color Danger = Rgb(232, 72, 56); public static readonly Color DangerDeep = Rgb(150, 46, 36); public static readonly Color Light = Rgb(255, 219, 168); private static bool _cursorOn; private static Texture2D _cursor; private const float CursorScale = 1.25f; private const string RegularFile = "Oswald-Regular.ttf"; private const string BoldFile = "Oswald-SemiBold.ttf"; private static TMP_FontAsset _oswald; private static TMP_FontAsset _gameFont; private static TMP_FontAsset _gameSerif; private static bool _oswaldMissing; private static Material _gameOutlined; private static Material _serifOutlined; private static Material _edgePattern; private const string Letters = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~°·ÀÄÖ×Üßàáâãäçéêíóôõöúü–—’“”„…→"; private const string Cyrillic = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя«»"; private static Sprite _round; private static Sprite _ring; private static Sprite _arrow; private static TextMeshProUGUI _measure; private static GameObject _sfx; private static GameObject _selectSfx; public const float TallLines = -22f; public static bool On { get { if (Cfg.BetrUi != null) { return Cfg.BetrUi.Value; } return false; } } public static Sprite BoxSprite => Round(); public static Color ChosenFill => Rgb(92, 68, 46); public static Color PanelColour => WindowColour; public static Color SlotColour => FieldColour; public static Color Accent { get { //IL_001e: 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) if (!On) { return GUIManager.Instance.ValheimOrange; } return Rgb(240, 160, 70); } } public static Color ControlText { get { //IL_0021: 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) if (!On) { return GUIManager.Instance.ValheimBeige; } return Rgb(238, 228, 210); } } public static Color Text { get { //IL_001c: 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) if (!On) { return Color.white; } return Rgb(238, 228, 210); } } public static Color Muted { get { //IL_001c: 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) if (!On) { return Color.white; } return Rgb(170, 154, 132); } } public static Color Heading { get { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!On) { return new Color(1f, 0.718f, 0.361f); } return Rgb(240, 160, 70); } } public static Color Hint { get { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!On) { return new Color(0.84f, 0.78f, 0.6f); } return Rgb(214, 190, 150); } } public static Color Idle { get { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) if (!On) { return new Color(0.85f, 0.83f, 0.78f); } return Rgb(200, 188, 168); } } public static int Version { get; private set; } private static TMP_FontAsset Font { get { if (!On || !((Object)(object)Oswald() != (Object)null)) { return GameFont(); } return _oswald; } } private static Color Rgb(int r, int g, int b) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f, 1f); } public static void Tick() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) bool flag = On; if (flag == _cursorOn) { return; } _cursorOn = flag; Version++; BetrUiSkin.SwitchAll(flag); if (!GUIManager.IsHeadless()) { if (flag) { Cursor.SetCursor(CursorTexture(), new Vector2(2f, 2f) * 1.25f, (CursorMode)0); } else { Cursor.SetCursor((Texture2D)null, Vector2.zero, (CursorMode)0); } } } private static Texture2D CursorTexture() { //IL_0025: 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_0040: 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_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: 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_00bf: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011b: 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_012d: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Expected O, but got Unknown //IL_02bc: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_cursor != (Object)null) { return _cursor; } Vector2[] array = (Vector2[])(object)new Vector2[8] { new Vector2(2f, 2f), new Vector2(11.87f, 7.85f), new Vector2(16.7f, 13.72f), new Vector2(15.96f, 19.92f), new Vector2(12.62f, 20.4f), new Vector2(10.54f, 23.05f), new Vector2(4.8f, 20.59f), new Vector2(2.13f, 13.47f) }; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(10.44f, 16.61f); Vector2[] polygon = (Vector2[])(object)new Vector2[5] { array[0], array[1], array[2], array[3], val }; Vector2[] polygon2 = Grown(array, new Vector2(9.58f, 15.12f), 1.12f); Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)18, (byte)12, (byte)8, byte.MaxValue); Color32 val3 = default(Color32); ((Color32)(ref val3))..ctor((byte)95, (byte)90, (byte)85, byte.MaxValue); Color32 val4 = default(Color32); ((Color32)(ref val4))..ctor((byte)240, (byte)170, (byte)90, byte.MaxValue); Color32[] array2 = (Color32[])(object)new Color32[1024]; for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num = 0f; float num2 = 0f; float num3 = 0f; float num4 = 0f; for (int k = 0; k < 4; k++) { for (int l = 0; l < 4; l++) { Vector2 point = new Vector2((float)j + ((float)l + 0.5f) / 4f, (float)(32 - i) - ((float)k + 0.5f) / 4f) / 1.25f; Color32 val5; if (Inside(array, point)) { val5 = (Ridge(array[0], val, point) ? val2 : (Inside(polygon, point) ? val4 : val3)); } else { if (!Inside(polygon2, point)) { continue; } val5 = val2; } num += (float)(int)val5.r; num2 += (float)(int)val5.g; num3 += (float)(int)val5.b; num4 += 1f; } } if (!(num4 <= 0f)) { array2[i * 32 + j] = new Color32((byte)(num / num4), (byte)(num2 / num4), (byte)(num3 / num4), (byte)(num4 / 16f * 255f)); } } } _cursor = new Texture2D(32, 32, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1, name = "BetrUI cursor" }; _cursor.SetPixels32(array2); _cursor.Apply(false, false); return _cursor; } private static bool Ridge(Vector2 from, Vector2 to, Vector2 point) { //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_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) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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) //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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Vector2 val = to - from; float num = Mathf.Clamp01(Vector2.Dot(point - from, val) / ((Vector2)(ref val)).sqrMagnitude); Vector2 val2 = from + val * num - point; return ((Vector2)(ref val2)).sqrMagnitude < 0.0625f; } private static Vector2[] Grown(Vector2[] points, Vector2 centre, float factor) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) Vector2[] array = (Vector2[])(object)new Vector2[points.Length]; for (int i = 0; i < points.Length; i++) { array[i] = centre + (points[i] - centre) * factor; } return array; } private static bool Inside(Vector2[] polygon, Vector2 point) { //IL_000e: 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_0016: 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_001d: 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_002b: 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_003c: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0065: 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) bool flag = false; int num = 0; int num2 = polygon.Length - 1; while (num < polygon.Length) { Vector2 val = polygon[num]; Vector2 val2 = polygon[num2]; if (val.y > point.y != val2.y > point.y && point.x < (val2.x - val.x) * (point.y - val.y) / (val2.y - val.y) + val.x) { flag = !flag; } num2 = num++; } return flag; } private static TMP_FontAsset GameFont() { if ((Object)(object)_gameFont == (Object)null) { _gameFont = GUIManager.Instance.TMP_AveriaSansLibre; } if ((Object)(object)_gameFont == (Object)null) { _gameFont = Cache.GetPrefab<TMP_FontAsset>("Valheim-AveriaSansLibre"); } return _gameFont; } internal static Material GameEdgePattern() { if ((Object)(object)_edgePattern != (Object)null) { return _edgePattern; } Material val = Cache.GetPrefab<Material>("Valheim-AveriaSansLibre - Outline"); if ((Object)(object)val == (Object)null) { TMP_FontAsset obj = GameFont(); val = ((obj != null) ? ((TMP_Asset)obj).material : null); } return _edgePattern = val; } private static TMP_FontAsset GameSerif() { if ((Object)(object)_gameSerif == (Object)null) { _gameSerif = Cache.GetPrefab<TMP_FontAsset>("Valheim-AveriaSerifLibre"); } if (!((Object)(object)_gameSerif != (Object)null)) { return GameFont(); } return _gameSerif; } private static TMP_FontAsset Oswald() { //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_oswald != (Object)null || _oswaldMissing) { return _oswald; } _oswald = FromFile("Oswald-Regular.ttf"); if ((Object)(object)_oswald == (Object)null) { _oswaldMissing = true; Log.Warning("Oswald-Regular.ttf is not beside the plugin; BetrUI uses the game's font."); return null; } TMP_FontAsset val = FromFile("Oswald-SemiBold.ttf"); if ((Object)(object)val != (Object)null && _oswald.fontWeightTable != null && _oswald.fontWeightTable.Length > 7) { TMP_FontWeightPair val2 = _oswald.fontWeightTable[7]; val2.regularTypeface = val; _oswald.fontWeightTable[7] = val2; } TMP_FontAsset val3 = GameFont(); if ((Object)(object)val3 != (Object)null) { if (_oswald.fallbackFontAssetTable == null) { _oswald.fallbackFontAssetTable = new List<TMP_FontAsset>(); } _oswald.fallbackFontAssetTable.Add(val3); if ((Object)(object)val != (Object)null) { if (val.fallbackFontAssetTable == null) { val.fallbackFontAssetTable = new List<TMP_FontAsset>(); } val.fallbackFontAssetTable.Add(val3); } } Warm(_oswald); Warm(val); return _oswald; } private static void Warm(TMP_FontAsset font) { if ((Object)(object)font == (Object)null) { return; } try { string text = default(string); font.TryAddCharacters(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~°·ÀÄÖ×Üßàáâãäçéêíóôõöúü–—’“”„…→", ref text, false); if (Loc.Current == "Russian") { font.TryAddCharacters("АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя«»", ref text, false); } } catch (Exception ex) { Log.Warning("Could not prepare the letters of " + ((Object)font).name + ": " + ex.Message); } } private static TMP_FontAsset FromFile(string name) { string text = Packed.AsFile(name); if (text == null) { return null; } try { TMP_FontAsset val = TMP_FontAsset.CreateFontAsset(text, 0, 72, 7, (GlyphRenderMode)4165, 1024, 1024); if ((Object)(object)val != (Object)null) { ((Object)val).name = Path.GetFileNameWithoutExtension(name); } return val; } catch (Exception ex) { Log.Warning("Could not read " + name + ": " + ex.Message); return null; } } private static Material Outlined(TMP_FontAsset font, string name, ref Material cached) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_0097: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)cached != (Object)null) { return cached; } if ((Object)(object)font == (Object)null || (Object)(object)((TMP_Asset)font).material == (Object)null) { return null; } Material prefab = Cache.GetPrefab<Material>(name); if ((Object)(object)prefab != (Object)null && (Object)(object)prefab.mainTexture == (Object)(object)((TMP_Asset)font).material.mainTexture) { return cached = prefab; } cached = new Material(((TMP_Asset)font).material) { name = "BetrValheim " + name }; cached.EnableKeyword(ShaderUtilities.Keyword_Outline); cached.SetFloat(ShaderUtilities.ID_OutlineWidth, 0.1f); cached.SetColor(ShaderUtilities.ID_OutlineColor, Color.black); return cached; } private static Sprite Round() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0131: 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_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_round != (Object)null) { return _round; } Texture2D val = new Texture2D(24, 24, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Color32[] array = (Color32[])(object)new Color32[576]; for (int i = 0; i < 24; i++) { for (int j = 0; j < 24; j++) { float num = Mathf.Max(0f, Mathf.Max(8f - ((float)j + 0.5f), (float)j + 0.5f - 16f)); float num2 = Mathf.Max(0f, Mathf.Max(8f - ((float)i + 0.5f), (float)i + 0.5f - 16f)); float num3 = Mathf.Clamp01(8.5f - Mathf.Sqrt(num * num + num2 * num2)); array[i * 24 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * 255f)); } } val.SetPixels32(array); val.Apply(false, true); _round = Sprite.Create(val, new Rect(0f, 0f, 24f, 24f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(10f, 10f, 10f, 10f)); ((Object)_round).name = "BetrUI round"; return _round; } private static Sprite Ring() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0197: 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_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_ring != (Object)null) { return _ring; } Texture2D val = new Texture2D(24, 24, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Color32[] array = (Color32[])(object)new Color32[576]; for (int i = 0; i < 24; i++) { for (int j = 0; j < 24; j++) { float num = Mathf.Max(0f, Mathf.Max(8f - ((float)j + 0.5f), (float)j + 0.5f - 16f)); float num2 = Mathf.Max(0f, Mathf.Max(8f - ((float)i + 0.5f), (float)i + 0.5f - 16f)); float num3 = Mathf.Sqrt(num * num + num2 * num2); float num4 = Mathf.Clamp01(8.5f - num3); float num5 = Mathf.Min(Mathf.Min((float)j + 0.5f, (float)(24 - j) - 0.5f), Mathf.Min((float)i + 0.5f, (float)(24 - i) - 0.5f)); float num6 = Mathf.Clamp01(((num3 > 0f) ? (8f - num3) : num5) - 2f + 0.5f); array[i * 24 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(num4 - num6) * 255f)); } } val.SetPixels32(array); val.Apply(false, true); _ring = Sprite.Create(val, new Rect(0f, 0f, 24f, 24f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(10f, 10f, 10f, 10f)); ((Object)_ring).name = "BetrUI ring"; return _ring; } internal static Sprite Arrow() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_arrow != (Object)null) { return _arrow; } Texture2D val = new Texture2D(16, 16, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; Color32[] array = (Color32[])(object)new Color32[256]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { float num = (float)i + 0.5f; float num2 = (float)j + 0.5f; float num3 = Mathf.Min((num - 3f) * (2f / 3f) - Mathf.Abs(num2 - 8f), Mathf.Min(num - 3f, 12f - num) * 2f); array[i * 16 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(num3 + 0.5f) * 255f)); } } val.SetPixels32(array); val.Apply(false, true); _arrow = Sprite.Create(val, new Rect(0f, 0f, 16f, 16f), new Vector2(0.5f, 0.5f), 100f); ((Object)_arrow).name = "BetrUI arrow"; return _arrow; } private static void Flat(Image image, Color colour) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)image == (Object)null)) { image.sprite = Round(); image.type = (Type)1; image.pixelsPerUnitMultiplier = 1f; ((Graphic)image).color = colour; } } private static void Tint(Selectable control, ColorBlock block) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)control == (Object)null)) { if ((Object)(object)control.targetGraphic != (Object)null) { control.targetGraphic.canvasRenderer.SetColor((control.IsInteractable() ? ((ColorBlock)(ref block)).normalColor : ((ColorBlock)(ref block)).disabledColor) * ((ColorBlock)(ref block)).colorMultiplier); } control.colors = block; } } private static ColorBlock Colours(Color normal, Color hover, Color down) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001a: 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_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_0057: Unknown result type (might be due to invalid IL or missing references) ColorBlock result = default(ColorBlock); ((ColorBlock)(ref result)).normalColor = normal; ((ColorBlock)(ref result)).highlightedColor = hover; ((ColorBlock)(ref result)).pressedColor = down; ((ColorBlock)(ref result)).selectedColor = normal; ((ColorBlock)(ref result)).disabledColor = Color.Lerp(normal, InsetColour, 0.6f); ((ColorBlock)(ref result)).colorMultiplier = 1f; ((ColorBlock)(ref result)).fadeDuration = 0.08f; return result; } public static TMP_Text Label(string text, Transform parent, float size, bool bold, Color colour, bool body = false) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Text", new Type[1] { typeof(RectTransform) }) { layer = 5 }; val.transform.SetParent(parent, false); TextMeshProUGUI obj = AddText(val); Dress((TMP_Text)(object)obj, size, bold, colour, !body, body); ((TMP_Text)obj).text = text ?? string.Empty; ((Graphic)obj).raycastTarget = false; ((TMP_Text)obj).enableWordWrapping = false; ((TMP_Text)obj).overflowMode = (TextOverflowModes)0; ((TMP_Text)obj).alignment = (TextAlignmentOptions)514; return (TMP_Text)(object)obj; } public static void Dress(TMP_Text label, float size, bool bold, Color colour, bool capitals = true, bool body = true) { //IL_00a9: 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_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) if (On && (Object)(object)Oswald() != (Object)null) { label.font = _oswald; } else if (body) { TMP_FontAsset val = GameFont(); if ((Object)(object)val != (Object)null) { label.font = val; } Material val2 = Outlined(val, "Valheim-AveriaSansLibre - Outline", ref _gameOutlined); if ((Object)(object)val2 != (Object)null) { label.fontSharedMaterial = val2; } } else { TMP_FontAsset val3 = GameSerif(); if ((Object)(object)val3 != (Object)null) { label.font = val3; } Material val4 = Outlined(val3, "Valheim-AveriaSerifLibre - Outline", ref _serifOutlined); if ((Object)(object)val4 != (Object)null) { label.fontSharedMaterial = val4; } bold = true; } label.fontSize = size; FontStyles val5 = (FontStyles)(bold ? 1 : 0); if (On && capitals) { val5 = (FontStyles)(val5 | 0x10); } label.fontStyle = val5; ((Graphic)label).color = colour; } private static TextMeshProUGUI AddText(GameObject go) { bool activeSelf = go.activeSelf; if (activeSelf) { go.SetActive(false); } TextMeshProUGUI val = go.AddComponent<TextMeshProUGUI>(); TMP_FontAsset font = Font; if ((Object)(object)font != (Object)null) { ((TMP_Text)val).font = font; } if (activeSelf) { go.SetActive(true); } return val; } private static TMP_FontAsset SwapDefault(TMP_FontAsset font) { if ((Object)(object)TMP_Settings.instance == (Object)null) { return null; } TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset; if ((Object)(object)font != (Object)null || (Object)(object)defaultFontAsset != (Object)null) { TMP_Settings.defaultFontAsset = font; } return defaultFontAsset; } public static Vector2 Measure(TMP_Text like, string value, float width) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Expected O, but got Unknown //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)like == (Object)null) { return Vector2.zero; } if ((Object)(object)_measure == (Object)null) { Transform val = (((Object)(object)GUIManager.CustomGUIFront != (Object)null) ? GUIManager.CustomGUIFront.transform : null); if ((Object)(object)val == (Object)null) { return like.GetPreferredValues(value, width, float.PositiveInfinity); } GameObject val2 = new GameObject("BetrUI Measure", new Type[1] { typeof(RectTransform) }) { layer = 5 }; val2.transform.SetParent(val, false); ((RectTransform)val2.transform).anchoredPosition = new Vector2(-100000f, -100000f); _measure = AddText(val2); ((Graphic)_measure).raycastTarget = false; ((Graphic)_measure).color = new Color(0f, 0f, 0f, 0f); } ((TMP_Text)_measure).font = like.font; ((TMP_Text)_measure).fontSize = like.fontSize; ((TMP_Text)_measure).fontStyle = like.fontStyle; ((TMP_Text)_measure).richText = like.richText; ((TMP_Text)_measure).characterSpacing = like.characterSpacing; ((TMP_Text)_measure).wordSpacing = like.wordSpacing; ((TMP_Text)_measure).lineSpacing = like.lineSpacing; ((TMP_Text)_measure).enableWordWrapping = like.enableWordWrapping; ((TMP_Text)_measure).enableAutoSizing = false; return ((TMP_Text)_measure).GetPreferredValues(value ?? string.Empty, width, float.PositiveInfinity); } public static void TitleLook(TMP_Text title) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) if (!On && !((Object)(object)title == (Object)null)) { TMP_FontAsset val = Cache.GetPrefab<TMP_FontAsset>("Valheim-Norsebold"); if ((Object)(object)val == (Object)null) { val = GUIManager.Instance.TMP_Norse; } if (!((Object)(object)val == (Object)null)) { title.font = val; Material prefab = Cache.GetPrefab<Material>("Valheim-Norsebold - Outline"); title.fontSharedMaterial = (((Object)(object)prefab != (Object)null && (Object)(object)prefab.mainTexture == (Object)(object)((TMP_Asset)val).material.mainTexture) ? prefab : ((TMP_Asset)val).material); ((Graphic)title).color = Heading; title.fontStyle = (FontStyles)0; } } } public static TextAlignmentOptions Align(TextAnchor anchor) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected I4, but got Unknown return (TextAlignmentOptions)((int)anchor switch { 0 => 257, 1 => 258, 2 => 260, 3 => 513, 5 => 516, 6 => 1025, 7 => 1026, 8 => 1028, _ => 514, }); } public static GameObject Window(Transform parent, float width, float height, bool draggable = true) { //IL_000e: 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) return Window(parent, width, height, draggable, new Vector2(0.5f, 0.5f), Vector2.zero); } public static GameObject Window(Transform parent, float width, float height, bool draggable, Vector2 anchor, Vector2 position) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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_000f: 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) if (!On) { return GUIManager.Instance.CreateWoodpanel(parent, anchor, anchor, position, width, height, draggable); } GameObject val = new GameObject("BetrUI Window", new Type[2] { typeof(RectTransform), typeof(Image) }); val.layer = 5; val.transform.SetParent(parent, false); RectTransform val2 = (RectTransform)val.transform; Vector2 anchorMin = (val2.anchorMax = anchor); val2.anchorMin = anchorMin; val2.pivot = new Vector2(0.5f, 0.5f); val2.sizeDelta = new Vector2(width, height); val2.anchoredPosition = position; Image component = val.GetComponent<Image>(); component.sprite = null; ((Graphic)component).color = new Color(0f, 0f, 0f, 0f); BetrUiDecor.OwnWindow(val.transform, WindowColour); if (draggable) { val.AddComponent<DragWindowCntrl>(); } UiMotion.Appear.On(val); return val; } public static void Inset(Transform parent, RectTransform over) { //IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_006b: 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) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) if (On && !((Object)(object)over == (Object)null)) { GameObject val = new GameObject("BetrUI Inset", new Type[2] { typeof(RectTransform), typeof(Image) }) { layer = 5 }; val.transform.SetParent(parent, false); val.transform.SetSiblingIndex(((Transform)over).GetSiblingIndex()); RectTransform val2 = (RectTransform)val.transform; val2.anchorMin = over.anchorMin; val2.anchorMax = over.anchorMax; val2.pivot = over.pivot; val2.offsetMin = over.offsetMin; val2.offsetMax = over.offsetMax; Image component = val.GetComponent<Image>(); Flat(component, InsetColour); ((Graphic)component).raycastTarget = false; } } public static Button Button(string text, Transform parent, float width, float height, float size = 16f) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) GameObject val; if (!On) { val = GUIManager.Instance.CreateButton(string.Empty, parent, Vector2.zero, Vector2.zero, Vector2.zero, width, height); Text componentInChildren = val.GetComponentInChildren<Text>(true); if ((Object)(object)componentInChildren != (Object)null) { Object.DestroyImmediate((Object)(object)((Component)componentInChildren).gameObject); } } else { val = new GameObject("BetrUI Button", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Button) }); val.layer = 5; val.transform.SetParent(parent, false); ((RectTransform)val.transform).sizeDelta = new Vector2(width, height); Image component = val.GetComponent<Image>(); Flat(component, Color.white); BetrUiDecor.Shade((Graphic)(object)component, on: true); Button component2 = val.GetComponent<Button>(); ((Selectable)component2).targetGraphic = (Graphic)(object)component; Tint((Selectable)(object)component2, Colours(ButtonColour, ButtonHover, ButtonDown)); ButtonSfx obj = val.AddComponent<ButtonSfx>(); if ((Object)(object)_sfx == (Object)null) { _sfx = Cache.GetPrefab<GameObject>("sfx_gui_button"); } if ((Object)(object)_selectSfx == (Object)null) { _selectSfx = Cache.GetPrefab<GameObject>("sfx_gui_select"); } obj.m_sfxPrefab = _sfx; obj.m_selectSfxPrefab = _selectSfx; } Button component3 = val.GetComponent<Button>(); Navigation navigation = default(Navigation); ((Navigation)(ref navigation)).mode = (Mode)0; ((Selectable)component3).navigation = navigation; TMP_Text obj2 = Label(text, val.transform, size, On, On ? ControlText : Accent); RectTransform rectTransform = obj2.rectTransform; rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.offsetMin = new Vector2(6f, 2f); rectTransform.offsetMax = new Vector2(-6f, -2f); obj2.alignment = (TextAlignmentOptions)514; return val.GetComponent<Button>(); } public static void Reface(TMP_Text text, FontStyles style) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) Reface(text, style, capitals: true); } public static void Reface(TMP_Text text, FontStyles style, bool capitals) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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_0065: Unknown result type (might be due to invalid IL or missing referen