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 PortalCompanionInterdiction v1.0.24
PortalCompanionInterdiction.dll
Decompiled 5 days agousing System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("PortalCompanionInterdiction")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3")] [assembly: AssemblyProduct("PortalCompanionInterdiction")] [assembly: AssemblyTitle("PortalCompanionInterdiction")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.0")] [module: UnverifiableCode] namespace PortalCompanionInterdiction; [BepInPlugin("com.yourname.portalcompanioninterdiction", "Portal Companion Interdiction", "1.0.24")] [BepInProcess("valheim.exe")] public class PortalInterdictionPlugin : BaseUnityPlugin { private readonly Harmony harmony = new Harmony("com.yourname.portalcompanioninterdiction"); private void Awake() { harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Portal Companion Interdiction v1.0.24 (Odin's Enforcement) loaded successfully!"); } } [HarmonyPatch(typeof(Inventory), "IsTeleportable")] public static class InventoryCargoInterdictionPatch { [HarmonyPostfix] public static void Postfix(Inventory __instance, ref bool __result) { if (!__result) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Humanoid)localPlayer).GetInventory() != __instance) { return; } MonoBehaviour[] array = Object.FindObjectsByType<MonoBehaviour>((FindObjectsInactive)0, (FindObjectsSortMode)0); if (array == null) { return; } string text = localPlayer.GetPlayerID().ToString(); MonoBehaviour[] array2 = array; foreach (MonoBehaviour val in array2) { if ((Object)(object)val == (Object)null) { continue; } string name = ((object)val).GetType().Name; if (!name.Contains("CompanionAI")) { continue; } bool flag = false; ZNetView component = ((Component)val).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null && component.GetZDO() != null) { ZDO zDO = component.GetZDO(); string text2 = zDO.GetString(423985160, ""); if (zDO.GetBool(1424699564, true) && text2 == text) { flag = true; } } if (!flag) { object obj = ((object)val).GetType().GetField("m_followTarget", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(val) ?? ((object)val).GetType().GetField("m_follow", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(val); if (obj != null) { GameObject val2 = (GameObject)((obj is GameObject) ? obj : null); if (val2 != null && (Object)(object)val2 == (Object)(object)((Component)localPlayer).gameObject) { flag = true; goto IL_01f1; } } MethodInfo? method = ((object)val).GetType().GetMethod("IsFollowingPlayer"); object obj2; if ((object)method == null) { obj2 = null; } else { object[] parameters = (object[])(object)new Player[1] { localPlayer }; obj2 = method.Invoke(val, parameters); } if (obj2 is bool flag2) { flag = flag2; } } goto IL_01f1; IL_01f1: if (!flag) { continue; } Humanoid component2 = ((Component)val).GetComponent<Humanoid>(); Inventory val3 = ((component2 != null) ? component2.GetInventory() : null); if (val3 != null && !val3.IsTeleportable()) { __result = false; if ((Object)(object)MessageHud.instance != (Object)null) { MessageHud.instance.ShowMessage((MessageType)2, "Odin disapproves of this action!", 0, (Sprite)null, false); MessageHud.instance.ShowMessage((MessageType)1, "Your companion is carrying items restricted by the portal.", 0, (Sprite)null, false); } break; } } } }