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 ProperPortals v1.4.3
ProperPortals.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using ConditionalConfigSync; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ProperPortals")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Crystal")] [assembly: AssemblyProduct("ProperPortals")] [assembly: AssemblyCopyright("Copyright © 2026 Crystal Ferrai")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("21b0fa01-fc7d-40f1-a2a5-d5c0881c5e3d")] [assembly: AssemblyFileVersion("1.4.3.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.4.3.0")] namespace ProperPortals; [BepInPlugin("dev.crystal.properportals", "Proper Portals", "1.4.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInProcess("valheim.exe")] [BepInProcess("valheim_server.exe")] public class ProperPortalsPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Inventory))] private static class Inventory_Patches { [HarmonyPatch("IsTeleportable")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> IsTeleportable_Transpiler(IEnumerable<CodeInstruction> instructions) { yield return new CodeInstruction(OpCodes.Ldc_I4_1, (object)null); yield return new CodeInstruction(OpCodes.Ret, (object)null); } } [HarmonyPatch(typeof(Hud))] private static class Hud_Patches { [HarmonyPatch("GetFadeDuration")] [HarmonyPrefix] private static bool GetFadeDuration_Prefix(Hud __instance, ref float __result, Player player) { if (player != null && ((Character)player).IsTeleporting()) { __result = FadeTime.Value; return false; } return true; } } [HarmonyPatch(typeof(Player))] private static class Player_Patches { [HarmonyPatch("UpdateTeleport")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> UpdateTeleport_Transpiler(IEnumerable<CodeInstruction> instructions) { foreach (CodeInstruction instruction in instructions) { if (instruction.opcode == OpCodes.Ldc_R4) { float num = (float)instruction.operand; if (num == 2f) { instruction.operand = FadeTime.Value; } else if (num == 8f) { instruction.operand = FadeTime.Value + MinPortalTime.Value; } else if (num == 15f) { instruction.operand = FadeTime.Value + MinPortalTime.Value + 0.5f; } } yield return instruction; } } } [HarmonyPatch(typeof(TeleportWorld))] private static class TeleportWorld_Patches { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void Awake_Postfix(TeleportWorld __instance) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (((Behaviour)__instance).enabled) { UpdateActivationRange(__instance); sPortals[((Component)__instance).GetComponent<ZNetView>().GetZDO().m_uid] = __instance; } } } [HarmonyPatch(typeof(ZDOMan))] private static class ZDOMan_Patches { [HarmonyPatch("HandleDestroyedZDO")] [HarmonyPrefix] private static void HandleDestroyedZDO_Prefix(ZDOMan __instance, ZDOID uid) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) sPortals.Remove(uid); } } public const string ModId = "dev.crystal.properportals"; public const string ModName = "Proper Portals"; public const string ModVersion = "1.4.3.0"; internal static readonly ConfigSync ConfigSync; public static ConfigEntry<bool> CarryAnything; public static ConfigEntry<float> FadeTime; public static ConfigEntry<float> MinPortalTime; public static ConfigEntry<float> ActivationRange; private static Harmony sInventoryHarmony; private static Harmony sHudHarmony; private static Harmony sPlayerHarmony; private static Harmony sTeleportWorldHarmony; private static Harmony sZDOManHarmony; private static Dictionary<ZDOID, TeleportWorld> sPortals; static ProperPortalsPlugin() { //IL_0005: 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_0015: 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_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_003e: Expected O, but got Unknown ConfigSync = new ConfigSync("dev.crystal.properportals") { DisplayName = "Proper Portals", CurrentVersion = "1.4.3.0", MinimumRequiredVersion = "1.4.3.0", ModRequired = true, ModRequirementMode = (ModRequirementMode)1 }; sPortals = new Dictionary<ZDOID, TeleportWorld>(); } private void Awake() { //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Expected O, but got Unknown //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Expected O, but got Unknown CarryAnything = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal", "CarryAnything", true, "Whether to allow using portals while carrying portal restricted items such as metals. Set false to use world setting. Set true to force allow. [The value will be enforced on a server.]"); CarryAnything.SettingChanged += CarryAnything_SettingChanged; ((ConditionalConfigSync)ConfigSync).AddConfigEntry<bool>(CarryAnything, (ConfigSyncMode)0); FadeTime = ((BaseUnityPlugin)this).Config.Bind<float>("Portal", "FadeTime", 0.5f, "The time it takes to fade the screen before teleporting. Teleporting does not start until after the screen fade completes. Game default is 1. [The value may be enforced on a server via sync policy.]"); FadeTime.SettingChanged += PortalTime_SettingChanged; ((ConditionalConfigSync)ConfigSync).AddConfigEntry<float>(FadeTime, (ConfigSyncMode)1, true); MinPortalTime = ((BaseUnityPlugin)this).Config.Bind<float>("Portal", "MinPortalTime", 0f, "The minimum time to wait for a teleport to complete, in seconds. It can take longer if the target location needs to be loaded. Increase this if you have the issue of dropping in before loading completes. Game default is 8. [The value may be enforced on a server via sync policy.]"); MinPortalTime.SettingChanged += PortalTime_SettingChanged; ((ConditionalConfigSync)ConfigSync).AddConfigEntry<float>(MinPortalTime, (ConfigSyncMode)1, true); ActivationRange = ((BaseUnityPlugin)this).Config.Bind<float>("Portal", "ActivationRange", 2f, "The distance at which a portal will start glowing and making noise when a player approaches it. Maximum accepted value is 10. Setting to 0 prevents portals from glowing or making noise at all. Game default is 3. [The value will be enforced on a server.]"); ActivationRange.SettingChanged += ActivationRange_SettingChanged; ((ConditionalConfigSync)ConfigSync).AddConfigEntry<float>(ActivationRange, (ConfigSyncMode)0); ClampConfig(); sInventoryHarmony = new Harmony("dev.crystal.properportals_Inventory"); sHudHarmony = new Harmony("dev.crystal.properportals_Hud"); sPlayerHarmony = new Harmony("dev.crystal.properportals_Player"); sTeleportWorldHarmony = new Harmony("dev.crystal.properportals_TeleportWorld"); sZDOManHarmony = new Harmony("dev.crystal.properportals_ZDOMan"); if (CarryAnything.Value) { sInventoryHarmony.PatchAll(typeof(Inventory_Patches)); } sHudHarmony.PatchAll(typeof(Hud_Patches)); sPlayerHarmony.PatchAll(typeof(Player_Patches)); sTeleportWorldHarmony.PatchAll(typeof(TeleportWorld_Patches)); sZDOManHarmony.PatchAll(typeof(ZDOMan_Patches)); } private void OnDestroy() { sInventoryHarmony.UnpatchSelf(); sHudHarmony.UnpatchSelf(); sPlayerHarmony.UnpatchSelf(); sTeleportWorldHarmony.UnpatchSelf(); sZDOManHarmony.UnpatchSelf(); sPortals.Clear(); } private static void ClampConfig() { if (FadeTime.Value < 0f) { FadeTime.Value = 0f; } if ((double)FadeTime.Value > 10.0) { FadeTime.Value = 10f; } if (MinPortalTime.Value < 0f) { MinPortalTime.Value = 0f; } if ((double)MinPortalTime.Value > 60.0) { MinPortalTime.Value = 60f; } if (ActivationRange.Value < 0f) { ActivationRange.Value = 0f; } if ((double)ActivationRange.Value > 10.0) { ActivationRange.Value = 10f; } } private void CarryAnything_SettingChanged(object sender, EventArgs e) { if (CarryAnything.Value) { sInventoryHarmony.PatchAll(typeof(Inventory_Patches)); } else { sInventoryHarmony.UnpatchSelf(); } } private void PortalTime_SettingChanged(object sender, EventArgs e) { ClampConfig(); sPlayerHarmony.UnpatchSelf(); sPlayerHarmony.PatchAll(typeof(Player_Patches)); } private void ActivationRange_SettingChanged(object sender, EventArgs e) { ClampConfig(); foreach (TeleportWorld value in sPortals.Values) { UpdateActivationRange(value); } } private static void UpdateActivationRange(TeleportWorld portal) { //IL_0021: 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_004c: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)portal)) { portal.m_activationRange = ActivationRange.Value; Transform proximityRoot = portal.m_proximityRoot; proximityRoot.localPosition = new Vector3(proximityRoot.localPosition.x, proximityRoot.localPosition.y, ActivationRange.Value * 0.5f + 0.25f); } } }