using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("SkyTree")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SkyTree")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("32aa79ea-acbc-40b2-955c-3bac3a852367")] [assembly: AssemblyFileVersion("1.6.1")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.6.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SkyTree { public class PluginConfig { public static ConfigEntry IsModEnabled { get; private set; } public static void BindConfig(ConfigFile config) { IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); IsModEnabled.OnSettingChanged(YggdrasilManager.ToggleYggdrasil); } } public static class YggdrasilManager { public const int SkyboxLayer = 19; public const int StaticSolidLayer = 15; public static GameObject YggdrasilRoot { get; private set; } public static GameObject YggdrasilBranch { get; private set; } public static MeshCollider YggdrasilBranchCollider { get; private set; } public static void Reset() { YggdrasilRoot = null; YggdrasilBranch = null; YggdrasilBranchCollider = null; } public static void SetYggdrasilLayer(int layer) { YggdrasilRoot.layer = layer; YggdrasilBranch.layer = layer; } public static void ToggleYggdrasil(bool toggleOn) { if (toggleOn) { SetYggdrasilSolid(EnvMan.s_instance); } else { SetYggdrasilSkybox(); } } public static void SetYggdrasilSolid(EnvMan environmentManager) { if (Object.op_Implicit((Object)(object)environmentManager)) { YggdrasilRoot = ((Component)((Component)environmentManager).transform.Find("YggdrasilBranch")).gameObject; YggdrasilBranch = ((Component)YggdrasilRoot.transform.Find("branch")).gameObject; string text = $"{15}:{LayerMask.LayerToName(15)}"; int layer = YggdrasilRoot.layer; string text2 = $"{layer}:{LayerMask.LayerToName(layer)}"; SkyTree.LogInfo("Setting YggdrasilBranch layer from " + text2 + " to " + text + "."); YggdrasilRoot.layer = 15; layer = YggdrasilBranch.layer; text2 = $"{layer}:{LayerMask.LayerToName(layer)}"; SkyTree.LogInfo("Setting YggdrasilBranch/branch layer from " + text2 + " to " + text + "."); YggdrasilBranch.layer = 15; MeshFilter val = default(MeshFilter); MeshCollider val2 = default(MeshCollider); if (YggdrasilBranch.TryGetComponent(ref val) && !YggdrasilBranch.TryGetComponent(ref val2)) { SkyTree.LogInfo("Adding collider to YggdrasilBranch/branch."); YggdrasilBranchCollider = YggdrasilBranch.gameObject.AddComponent(); YggdrasilBranchCollider.cookingOptions = (MeshColliderCookingOptions)30; YggdrasilBranchCollider.sharedMesh = val.sharedMesh; } } } public static void SetYggdrasilSkybox() { if (Object.op_Implicit((Object)(object)YggdrasilBranch)) { YggdrasilBranch.layer = 19; MeshCollider val = default(MeshCollider); if (YggdrasilBranch.TryGetComponent(ref val)) { Object.Destroy((Object)(object)val); } } if (Object.op_Implicit((Object)(object)YggdrasilRoot)) { YggdrasilRoot.layer = 19; } } public static bool IsBlockedDelegate(int blockRayMask, Vector3 point) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) point.y += 2000f; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(point, Vector3.down, ref val, 10000f, blockRayMask)) { return false; } if ((Object)(object)((RaycastHit)(ref val)).collider != (Object)(object)YggdrasilBranchCollider) { return true; } point.y = Mathf.Min(((RaycastHit)(ref val)).point.y - 0.1f, 1000f); return Physics.Raycast(point, Vector3.down, 10000f, blockRayMask); } } [HarmonyPatch(typeof(EnvMan))] internal static class EnvManPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix(EnvMan __instance) { if (PluginConfig.IsModEnabled.Value) { YggdrasilManager.SetYggdrasilSolid(__instance); } } [HarmonyPrefix] [HarmonyPatch("OnDestroy")] private static void OnDestroyPrefix() { YggdrasilManager.Reset(); } } [HarmonyPatch(typeof(ZoneSystem))] internal static class ZoneSystemPatch { [HarmonyPrefix] [HarmonyPatch("SpawnZone")] private static void SpawnZonePrefix() { if (PluginConfig.IsModEnabled.Value) { YggdrasilManager.SetYggdrasilLayer(19); } } [HarmonyPostfix] [HarmonyPatch("SpawnZone")] private static void SpawnZonePostfix() { if (PluginConfig.IsModEnabled.Value) { YggdrasilManager.SetYggdrasilLayer(15); } } [HarmonyPrefix] [HarmonyPatch("IsBlocked")] private static bool IsBlockedPrefix(ZoneSystem __instance, Vector3 p, ref bool __result) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (PluginConfig.IsModEnabled.Value) { __result = YggdrasilManager.IsBlockedDelegate(__instance.m_blockRayMask, p); return false; } return true; } } [BepInPlugin("redseiko.valheim.skytree", "SkyTree", "1.6.1")] public sealed class SkyTree : BaseUnityPlugin { public const string PluginGuid = "redseiko.valheim.skytree"; public const string PluginName = "SkyTree"; public const string PluginVersion = "1.6.1"; private static ManualLogSource _logger; private void Awake() { PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); _logger = ((BaseUnityPlugin)this).Logger; Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.skytree"); } public static void LogInfo(object obj) { _logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } public static void LogWarning(object obj) { _logger.LogWarning((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } } } namespace ComfyLib { public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary _sectionToSettingOrder = new Dictionary(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry BindInOrder(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static ConfigEntry BindInOrder(this ConfigFile config, string section, string key, T defaultValue, string description, Action customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged(this ConfigEntry configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged(this ConfigEntry configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged(this ConfigEntry configEntry, Action> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry)(object)((SettingChangedEventArgs)eventArgs).ChangedSetting); }; } } public static class ComponentExtensions { public static bool TryGetComponentInChildren(this Component parentComponent, out T component) where T : Component { component = parentComponent.GetComponentInChildren(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInChildren(this GameObject gameObject, out T component) where T : Component { component = gameObject.GetComponentInChildren(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInParent(this Component childComponent, out T component) where T : Component { component = childComponent.GetComponentInParent(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInParent(this GameObject gameObject, out T component) where T : Component { component = gameObject.GetComponentInParent(); return Object.op_Implicit((Object)(object)component); } } public static class ObjectExtensions { public static T FirstByNameOrThrow(this T[] unityObjects, string name) where T : Object { foreach (T val in unityObjects) { if (((Object)val).name == name) { return val; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } }