using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyMetadata("ValheimManagedFolder", "/home/runner/work/DynamicTeleportAreas/DynamicTeleportAreas/env_mock/valheim_Data/Managed")] [assembly: AssemblyMetadata("BepInExCoreFolder", "/home/runner/work/DynamicTeleportAreas/DynamicTeleportAreas/env_mock/BepInEx/core")] [assembly: AssemblyCompany("DynamicTeleportAreas")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Dynamic Loaded Area Adjuster for Portal Transitions")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+1f1a7f1064925d1397fc40279a6a2068650ff4ad")] [assembly: AssemblyProduct("DynamicTeleportAreas")] [assembly: AssemblyTitle("DynamicTeleportAreas")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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 DynamicTeleportAreas { [BepInPlugin("com.arifogel.dynamicteleportareas", "DynamicTeleportAreas", "1.0.1")] public class DynamicTeleportAreasPlugin : BaseUnityPlugin { private const string PluginGuid = "com.arifogel.dynamicteleportareas"; private const string PluginName = "DynamicTeleportAreas"; private const string PluginVersion = "1.0.1"; private static DynamicTeleportAreasPlugin s_instance; public static bool SuppressNotifications; internal static ConfigEntry Enabled; private static ConfigEntry s_enableMessageHudNotifications; private static ConfigEntry s_normalLoadedArea; private static ConfigEntry s_normalGeneratedArea; internal static ConfigEntry TeleportLoadedArea; internal static ConfigEntry TeleportGeneratedArea; private static ConfigEntry s_frameDelayCount; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) s_instance = this; InitConfiguration(); new Harmony("com.arifogel.dynamicteleportareas").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"DynamicTeleportAreas initialized and configs bound."); } private void InitConfiguration() { Enabled = ((BaseUnityPlugin)this).Config.Bind("1 - Global Settings", "Enabled", true, "Turns the mod on or off."); s_enableMessageHudNotifications = ((BaseUnityPlugin)this).Config.Bind("1 - Global Settings", "MessageHudNotifications", false, "When Enabled, on-screen notifications are shown at top-left when this mod changes Loaded/Generated areas during portal transitions."); s_normalLoadedArea = ((BaseUnityPlugin)this).Config.Bind("2 - Standard Gameplay Environment", "NormalLoadedArea", 4, "Your preferred high visibility distance for objects and structures while running around."); s_normalGeneratedArea = ((BaseUnityPlugin)this).Config.Bind("2 - Standard Gameplay Environment", "NormalGeneratedArea", 6, "Your preferred high visibility distance for the terrain and mountains in the far distance."); TeleportLoadedArea = ((BaseUnityPlugin)this).Config.Bind("3 - Portal Transition Environment", "PortalLoadedArea", 2, "The temporary lower object/structure visibility distance used during the portal loading screen."); TeleportGeneratedArea = ((BaseUnityPlugin)this).Config.Bind("3 - Portal Transition Environment", "PortalGeneratedArea", 4, "The temporary lower terrain rendering distance used during the portal loading screen."); s_frameDelayCount = ((BaseUnityPlugin)this).Config.Bind("4 - Engine Timing Controls", "FrameDelayCount", 30, "How many animation frames the mod waits after you exit a portal before it starts expanding your view distance back to your high settings."); } public static void SetRenderLimits(int loaded, int generated) { //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Expected O, but got Unknown //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown if (s_instance == null) { return; } if (!s_enableMessageHudNotifications.Value) { SuppressNotifications = true; } try { if ((Object)(object)Console.instance != (Object)null) { ((Terminal)Console.instance).TryRunCommand($"render_config loaded_zones {loaded}", false, false); ((Terminal)Console.instance).TryRunCommand($"render_config loaded_area {loaded}", false, false); ((Terminal)Console.instance).TryRunCommand($"render_config generated_zones {generated}", false, false); ((Terminal)Console.instance).TryRunCommand($"render_config generated_area {generated}", false, false); ((Terminal)Console.instance).TryRunCommand($"render_config distant_area {generated}", false, false); } } finally { SuppressNotifications = false; } if (Chainloader.PluginInfos.TryGetValue("valheim.jerekuusela.render_limits", out var value)) { IDictionary config = (IDictionary)value.Instance.Config; ConfigDefinition key = new ConfigDefinition("1. Zones", "Loaded zones"); ConfigDefinition key2 = new ConfigDefinition("General", "loaded_area"); ConfigDefinition key3 = new ConfigDefinition("1. Zones", "Generated zones"); ConfigDefinition key4 = new ConfigDefinition("General", "distant_area"); ConfigEntryBase value3; if (config.TryGetValue(key, out var value2)) { value2.BoxedValue = loaded; } else if (config.TryGetValue(key2, out value3)) { value3.BoxedValue = loaded; } ConfigEntryBase value5; if (config.TryGetValue(key3, out var value4)) { value4.BoxedValue = generated; } else if (config.TryGetValue(key4, out value5)) { value5.BoxedValue = generated; } } } public static void TriggerExpansion() { if ((Object)(object)s_instance != (Object)null) { ((MonoBehaviour)s_instance).StartCoroutine(StreamDelayedZonesRoutine()); } } private static IEnumerator StreamDelayedZonesRoutine() { int targetDelay = s_frameDelayCount.Value; for (int i = 0; i < targetDelay; i++) { yield return null; } SetRenderLimits(s_normalLoadedArea.Value, s_normalGeneratedArea.Value); } } [HarmonyPatch(typeof(Player), "TeleportTo")] internal static class PatchPortalEnter { internal static void Prefix() { if (DynamicTeleportAreasPlugin.Enabled.Value) { DynamicTeleportAreasPlugin.SetRenderLimits(DynamicTeleportAreasPlugin.TeleportLoadedArea.Value, DynamicTeleportAreasPlugin.TeleportGeneratedArea.Value); } } } [HarmonyPatch(typeof(Player), "UpdateTeleport")] internal static class PatchPortalExit { private static bool s_wasTeleporting; internal static void Postfix(Player __instance) { if (DynamicTeleportAreasPlugin.Enabled.Value) { if (((Character)__instance).IsTeleporting()) { s_wasTeleporting = true; } else if (s_wasTeleporting) { s_wasTeleporting = false; DynamicTeleportAreasPlugin.TriggerExpansion(); } } } } [HarmonyPatch(typeof(MessageHud), "ShowMessage")] internal static class PatchMessageHudSilence { internal static bool Prefix() { return !DynamicTeleportAreasPlugin.SuppressNotifications; } } [HarmonyPatch(typeof(Chat), "AddString")] internal static class PatchChatSilence { internal static bool Prefix() { return !DynamicTeleportAreasPlugin.SuppressNotifications; } } }