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.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: Guid("150BFDAF-FF35-4302-B7CC-BEDCE69118D5")] [assembly: ComVisible(false)] [assembly: AssemblyTrademark("")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyProduct("DedicatedServer")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyDescription("https://valheim.thunderstore.io/package/Smoothbrain/DedicatedServer")] [assembly: AssemblyTitle("DedicatedServer")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<4f8373b8-4619-431f-a513-7634e75db1e6>Embedded] internal sealed class <4f8373b8-4619-431f-a513-7634e75db1e6>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [<4f8373b8-4619-431f-a513-7634e75db1e6>Embedded] [CompilerGenerated] internal sealed class <873a314f-6a92-416b-bbc0-b39c6a04f241>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <873a314f-6a92-416b-bbc0-b39c6a04f241>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <873a314f-6a92-416b-bbc0-b39c6a04f241>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [<4f8373b8-4619-431f-a513-7634e75db1e6>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [CompilerGenerated] internal sealed class <3b98da5b-8cd7-4132-b167-109aca68824e>NullableContextAttribute : Attribute { public readonly byte Flag; public <3b98da5b-8cd7-4132-b167-109aca68824e>NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [<4f8373b8-4619-431f-a513-7634e75db1e6>Embedded] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace DedicatedServer { [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(1)] [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(0)] [BepInPlugin("org.bepinex.plugins.dedicatedserver", "DedicatedServer", "1.0.2")] [BepInIncompatibility("org.bepinex.plugins.valheim_plus")] public class DedicatedServer : BaseUnityPlugin { [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] private enum Toggle { On = 1, Off = 0 } [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] [HarmonyPatch] private static class SetServerAsOwner { [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(1)] private static IEnumerable TargetMethods() { return new MethodInfo[2] { AccessTools.DeclaredMethod(typeof(ZDO), "SetOwner", (Type[])null, (Type[])null), AccessTools.DeclaredMethod(typeof(ZDO), "SetOwnerInternal", (Type[])null, (Type[])null) }; } private static void Prefix(ref long uid) { if (uid == 0L && ZNet.instance.IsServer()) { uid = ZDOMan.instance.m_sessionID; } } } [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] [HarmonyPatch(typeof(ZDO), "Load")] private static class SetServerAsOwnerOnLoad { [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(1)] private static void Postfix(ZDO __instance) { if (ZNet.instance.IsServer() && !__instance.Owned) { __instance.SetOwnerInternal(ZDOMan.instance.m_sessionID); } } } [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] [HarmonyPatch(typeof(ZDOMan), "IsInPeerActiveArea")] private static class ActivateAreas { private static bool Prefix(ref bool __result, long uid) { if (uid == (ZNet.instance.IsServer() ? ZDOMan.GetSessionID() : ZNet.instance.GetServerPeer().m_uid)) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(ZDOMan), "ReleaseNearbyZDOS")] [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] private static class DoNotAssignPeerToZDO { private static bool Prefix(long uid) { return uid == ZDOMan.GetSessionID(); } } [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(0)] [HarmonyPatch(typeof(ZDOMan), "FindSectorObjects")] private static class LoadActiveAreas { [<3b98da5b-8cd7-4132-b167-109aca68824e>NullableContext(1)] private static bool Prefix(ZDOMan __instance, int area, int distantArea, List sectorObjects, [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(new byte[] { 2, 1 })] List distantSectorObjects = null) { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0102: 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_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) HashSet sectorPoints; HashSet distantSectorPoints; if (ZNet.instance.IsServer() && sectorObjects != __instance.m_tempSectorObjects) { sectorPoints = new HashSet(); distantSectorPoints = new HashSet(); foreach (ZNetPeer peer in ZNet.instance.m_peers) { AddSectorPoints(peer.GetRefPos()); } if (!ZNet.instance.IsDedicated()) { Player localPlayer = Player.m_localPlayer; AddSectorPoints((localPlayer != null) ? ((Component)localPlayer).transform.position : ZNet.instance.GetReferencePosition()); } foreach (Vector2i item in sectorPoints) { distantSectorPoints.Remove(item); ZoneSystem.instance.PokeLocalZone(item); if (ZoneSystem.instance.m_zones.ContainsKey(item)) { __instance.FindObjects(item, sectorObjects); } } foreach (ZDO sectorObject in sectorObjects) { if (sectorObject.Persistent && !sectorObject.Owner && !__instance.IsInPeerActiveArea(sectorObject.GetSector(), sectorObject.GetOwner())) { sectorObject.SetOwner(__instance.m_sessionID); } } List list = distantSectorObjects ?? sectorObjects; foreach (Vector2i item2 in distantSectorPoints) { ZoneSystem.instance.PokeLocalZone(item2); if (ZoneSystem.instance.m_zones.ContainsKey(item2)) { __instance.FindDistantObjects(item2, list); } } return false; } return true; void AddSectorPoints(Vector3 pos) { //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_000e: 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_0063: 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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00a4: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: 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_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) Vector2i zone = ZoneSystem.GetZone(pos); sectorPoints.Add(zone); for (int i = 1; i <= area; i++) { for (int j = zone.x - i; j <= zone.x + i; j++) { sectorPoints.Add(new Vector2i(j, zone.y - i)); sectorPoints.Add(new Vector2i(j, zone.y + i)); } for (int k = zone.y - i + 1; k <= zone.y + i - 1; k++) { sectorPoints.Add(new Vector2i(zone.x - i, k)); sectorPoints.Add(new Vector2i(zone.x + i, k)); } } for (int l = area + 1; l <= area + distantArea; l++) { for (int m = zone.x - l; m <= zone.x + l; m++) { distantSectorPoints.Add(new Vector2i(m, zone.y - l)); distantSectorPoints.Add(new Vector2i(m, zone.y + l)); } for (int n = zone.y - l + 1; n <= zone.y + l - 1; n++) { distantSectorPoints.Add(new Vector2i(zone.x - l, n)); distantSectorPoints.Add(new Vector2i(zone.x + l, n)); } } } } } [HarmonyPatch(typeof(SpawnSystem), "UpdateSpawning")] [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(0)] private static class RemoveLocalPlayerCheckFromSpawnSystem { [CompilerGenerated] private sealed class d__1 : IEnumerable, IEnumerable, IEnumerator, IDisposable, IEnumerator { private int <>1__state; private CodeInstruction <>2__current; private int <>l__initialThreadId; [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(new byte[] { 0, 1 })] private IEnumerable instructions; [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(new byte[] { 0, 1 })] public IEnumerable <>3__instructions; private bool 5__1; [<873a314f-6a92-416b-bbc0-b39c6a04f241>Nullable(0)] private List