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 ServersideQoL SmartDefense v2.0.0
ServersideQoL.SmartDefense.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using ServersideQoL.Processors; using ServersideQoL.Utilities; 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: AssemblyCompany("ArgusMagnus")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("ArgusMagnus")] [assembly: AssemblyDescription("Ballista don't target players or tames and reload from nearby containers.")] [assembly: AssemblyFileVersion("2.0.0.0")] [assembly: AssemblyInformationalVersion("2.0.0+cdafe98fecdc9c33d99ba13f064e37dcaca41712")] [assembly: AssemblyProduct("ServersideQoL.SmartDefense")] [assembly: AssemblyTitle("ServersideQoL.SmartDefense")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")] [assembly: AssemblyVersion("2.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [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 ServersideQoL.SmartDefense { public sealed class Config : ConfigBase<Config> { public sealed class TurretsConfig { public ConfigEntry<bool> DontTargetPlayers { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to stop ballistas from targeting players", (AcceptableValueBase)null, (Deprecated<Config>)null, "DontTargetPlayers"); public ConfigEntry<bool> DontTargetTames { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to stop ballistas from targeting tames", (AcceptableValueBase)null, (Deprecated<Config>)null, "DontTargetTames"); public ConfigEntry<bool> LoadFromContainers { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to automatically load ballistas from containers", (AcceptableValueBase)null, (Deprecated<Config>)null, "LoadFromContainers"); public ConfigEntry<float> LoadFromContainersRange { get; } = ConfigBase<Config>.BindEx<float>(cfg, section, 4f, "Required proximity of a container to a ballista to be used as ammo source", (AcceptableValueBase)null, (Deprecated<Config>)null, "LoadFromContainersRange"); public int? FeedFromContainersMaxRange => Shared.FeedFromContainersMaxRange?.Value; public ConfigEntry<float> LoadFromContainersMinPlayerDistance { get; } = ConfigBase<Config>.BindEx<float>(cfg, section, 4f, "Min distance all players must have to a ballista", (AcceptableValueBase)null, (Deprecated<Config>)null, "LoadFromContainersMinPlayerDistance"); public ConfigEntry<MessageTypes> AmmoAddedMessageType { get; } = ConfigBase<Config>.BindEx<MessageTypes>(cfg, section, (MessageTypes)0, "Type of message to show when ammo is added to a turret", (AcceptableValueBase)(object)AcceptableEnum<MessageTypes>.Default, (Deprecated<Config>)null, "AmmoAddedMessageType"); public ConfigEntry<MessageTypes> NoAmmoMessageType { get; } = ConfigBase<Config>.BindEx<MessageTypes>(cfg, section, (MessageTypes)0, "Type of message to show when there is no ammo to add to a turret", (AcceptableValueBase)(object)AcceptableEnum<MessageTypes>.Default, (Deprecated<Config>)null, "NoAmmoMessageType"); public TurretsConfig(ConfigFile cfg, [CallerMemberName] string section = null) { } } public sealed class TrapsConfig { public ConfigEntry<bool> DisableTriggeredByPlayers { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to stop traps from being triggered by players", (AcceptableValueBase)null, (Deprecated<Config>)null, "DisableTriggeredByPlayers"); public ConfigEntry<bool> DisableFriendlyFire { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to stop traps from damaging players and tames. Does not work reliably (yet).", (AcceptableValueBase)null, (Deprecated<Config>)null, "DisableFriendlyFire"); public ConfigEntry<float> SelfDamageMultiplier { get; } = ConfigBase<Config>.BindEx<float>(cfg, section, 1f, "Multiply the damage the trap takes when it is triggered by this factor. 0 to make the trap take no damage", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, float.PositiveInfinity), (Deprecated<Config>)null, "SelfDamageMultiplier"); public ConfigEntry<bool> AutoRearm { get; } = ConfigBase<Config>.BindEx<bool>(cfg, section, true, "True to automatically rearm traps when they are triggered", (AcceptableValueBase)null, (Deprecated<Config>)null, "AutoRearm"); public TrapsConfig(ConfigFile cfg, [CallerMemberName] string section = null) { } } public sealed class LocalizationConfig { public sealed class TurretsConfig { private string AmmoAdded { get; init; } = "{0}: $msg_added {1} {2}x"; public string NoAmmoFound { get; init; } = "<color=red>$msg_noturretammo"; public string FormatAmmoAdded(string turretName, string itemName, int count) { return string.Format(AmmoAdded, turretName, itemName, count); } } public TurretsConfig Turrets { get; init; } = new TurretsConfig(); } public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "SmartDefense", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled"); public TurretsConfig Turrets { get; } = new TurretsConfig(cfg, "Turrets"); public TrapsConfig Traps { get; } = new TrapsConfig(cfg, "Traps"); public YamlConfigEntry<LocalizationConfig> Localization { get; } = ConfigBase<Config>.BindYaml<LocalizationConfig>(cfg, "Localization"); public Config(ConfigFile cfg, Logger logger) : base(cfg, logger) { } } [BepInPlugin("ArgusMagnus.ServersideQoL.SmartDefense", "ServersideQoL.SmartDefense", "2.0.0")] public sealed class SmartDefensePlugin : ServersideQoLPluginBase<SmartDefensePlugin, Config> { public const string Author = "ArgusMagnus"; public const string PluginName = "ServersideQoL.SmartDefense"; public const string PluginGuid = "ArgusMagnus.ServersideQoL.SmartDefense"; public const string PluginVersion = "2.0.0"; public const string PluginInformationalVersion = "2.0.0"; private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639245732011738877L, default(TimeSpan)); protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger) { return new Config(configFile, logger); } protected override void RegisterProcessors(IProcessorCollection processors) { processors.Add<TurretProcessor>().Add<TrapsProcessor>(); } private void Awake() { } } [Processor("983b37e4-1777-42b0-be4a-90b72e2f96d8")] public sealed class TrapsProcessor : Processor<TrapsProcessor.PrefabInfo> { public sealed record PrefabInfo(Aoe Aoe, Piece Piece, PieceTable PieceTable, Trap? Trap) : ProcessorPrefabInfo() { [CompilerGenerated] public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("PrefabInfo"); stringBuilder.Append(" { "); if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder)) { stringBuilder.Append(' '); } stringBuilder.Append('}'); return stringBuilder.ToString(); } [CompilerGenerated] protected override bool PrintMembers(StringBuilder builder) { if (((ProcessorPrefabInfo)this).PrintMembers(builder)) { builder.Append(", "); } builder.Append("Aoe = "); builder.Append(Aoe); builder.Append(", Piece = "); builder.Append(Piece); builder.Append(", PieceTable = "); builder.Append(PieceTable); builder.Append(", Trap = "); builder.Append(Trap); return true; } [CompilerGenerated] public override int GetHashCode() { return (((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Aoe>.Default.GetHashCode(Aoe)) * -1521134295 + EqualityComparer<Piece>.Default.GetHashCode(Piece)) * -1521134295 + EqualityComparer<PieceTable>.Default.GetHashCode(PieceTable)) * -1521134295 + EqualityComparer<Trap>.Default.GetHashCode(Trap); } [CompilerGenerated] public sealed override bool Equals(ProcessorPrefabInfo? other) { return ((object)this).Equals((object?)other); } [CompilerGenerated] public bool Equals(PrefabInfo? other) { if ((object)this != other) { if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Aoe>.Default.Equals(Aoe, other.Aoe) && EqualityComparer<Piece>.Default.Equals(Piece, other.Piece) && EqualityComparer<PieceTable>.Default.Equals(PieceTable, other.PieceTable)) { return EqualityComparer<Trap>.Default.Equals(Trap, other.Trap); } return false; } return true; } [CompilerGenerated] private PrefabInfo(PrefabInfo original) : base((ProcessorPrefabInfo)(object)original) { Aoe = original.Aoe; Piece = original.Piece; PieceTable = original.PieceTable; Trap = original.Trap; } } public const string Id = "983b37e4-1777-42b0-be4a-90b72e2f96d8"; private readonly Dictionary<ServersideQoLZDO, Timestamp> _rearmAfter = new Dictionary<ServersideQoLZDO, Timestamp>(); protected override void Initialize() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) _rearmAfter.Clear(); Intercept.UpdateInterception(Trap.OnStateChanged, (Delegate)new Action<ServersideQoLZDO, int, long>(RPC_OnStateChanged), ConfigBase<Config>.Instance.Traps.AutoRearm.Value); } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0199: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: 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) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) if (ConfigBase<Config>.Instance.Traps.AutoRearm.Value && _rearmAfter.Remove(zdo, out var value)) { Timestamp now = Timestamp.Now; if (now < value) { _rearmAfter.Add(zdo, value); return ((Processor)this).ScheduleReprocessing(((Timestamp)(ref value)).Seconds - ((Timestamp)(ref now)).Seconds); } if (prefabInfo.Trap != null) { RPC.RequestStateChange(zdo, 1); } return (ProcessResult)0; } ZDOVars vars = zdo.Vars; PlayerID val = default(PlayerID); val = ((ZDOVars)(ref vars)).GetCreator(val); if (((PlayerID)(ref val)).Value == 0L) { return (ProcessResult)2; } ProcessResult val2 = (ProcessResult)0; if (prefabInfo.Trap != null) { if (!ConfigBase<Config>.Instance.Traps.DisableTriggeredByPlayers.Value) { zdo.Fields<Trap>().Reset((Func<Expression<Func<Trap, bool>>>)(() => (Trap x) => x.m_triggeredByPlayers), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TrapsProcessor.cs", 45); } else if (zdo.Fields<Trap>().UpdateValue((Func<Expression<Func<Trap, bool>>>)(() => (Trap x) => x.m_triggeredByPlayers), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TrapsProcessor.cs", 46)) { val2 = (ProcessResult)(val2 | 8); } } ComponentFieldAccessor<Aoe> val3 = zdo.Fields<Aoe>(); if (!ConfigBase<Config>.Instance.Traps.DisableFriendlyFire.Value) { val3.Reset((Func<Expression<Func<Aoe, bool>>>)(() => (Aoe x) => x.m_hitFriendly), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TrapsProcessor.cs", 52); } else if (val3.UpdateValue((Func<Expression<Func<Aoe, bool>>>)(() => (Aoe x) => x.m_hitFriendly), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TrapsProcessor.cs", 53)) { val2 = (ProcessResult)(val2 | 8); } if (val3.UpdateValue((Func<Expression<Func<Aoe, float>>>)(() => (Aoe x) => x.m_damageSelf), prefabInfo.Aoe.m_damageSelf * ConfigBase<Config>.Instance.Traps.SelfDamageMultiplier.Value, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TrapsProcessor.cs", 56)) { val2 = (ProcessResult)(val2 | 8); } if (!ConfigBase<Config>.Instance.Traps.AutoRearm.Value) { val2 = (ProcessResult)(val2 | 2); } return val2; } private void RPC_OnStateChanged(ServersideQoLZDO zdo, int state, long idOfClientModifyingState) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) if (state == 0) { Trap val = Processor<PrefabInfo>.GetProcessorPrefabInfo(zdo)?.Trap; if (val != null) { Dictionary<ServersideQoLZDO, Timestamp> rearmAfter = _rearmAfter; Timestamp now = Timestamp.Now; rearmAfter[zdo] = ((Timestamp)(ref now)).AddSeconds((float)val.m_rearmCooldown); } } } } [Processor("bd1d9b45-ebcc-4217-a4a8-129c4a8be605")] [DependsOn<ContainerRegistryProcessor>] public sealed class TurretProcessor : Processor<TurretProcessor.PrefabInfo> { public sealed record PrefabInfo(Turret Turret, Piece Piece, PieceTable PieceTable) : ProcessorPrefabInfo() { [CompilerGenerated] public override string ToString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("PrefabInfo"); stringBuilder.Append(" { "); if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder)) { stringBuilder.Append(' '); } stringBuilder.Append('}'); return stringBuilder.ToString(); } [CompilerGenerated] protected override bool PrintMembers(StringBuilder builder) { if (((ProcessorPrefabInfo)this).PrintMembers(builder)) { builder.Append(", "); } builder.Append("Turret = "); builder.Append(Turret); builder.Append(", Piece = "); builder.Append(Piece); builder.Append(", PieceTable = "); builder.Append(PieceTable); return true; } [CompilerGenerated] public override int GetHashCode() { return ((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Turret>.Default.GetHashCode(Turret)) * -1521134295 + EqualityComparer<Piece>.Default.GetHashCode(Piece)) * -1521134295 + EqualityComparer<PieceTable>.Default.GetHashCode(PieceTable); } [CompilerGenerated] public sealed override bool Equals(ProcessorPrefabInfo? other) { return ((object)this).Equals((object?)other); } [CompilerGenerated] public bool Equals(PrefabInfo? other) { if ((object)this != other) { if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Turret>.Default.Equals(Turret, other.Turret) && EqualityComparer<Piece>.Default.Equals(Piece, other.Piece)) { return EqualityComparer<PieceTable>.Default.Equals(PieceTable, other.PieceTable); } return false; } return true; } [CompilerGenerated] private PrefabInfo(PrefabInfo original) : base((ProcessorPrefabInfo)(object)original) { Turret = original.Turret; Piece = original.Piece; PieceTable = original.PieceTable; } } public const string Id = "bd1d9b45-ebcc-4217-a4a8-129c4a8be605"; private SectorDictionary<HashSet<ServersideQoLZDO>>? _turrets; private SectorDictionary<SharedItemDataKey, HashSet<ServersideQoLZDO>>? _containersByItemName; protected override void Initialize() { Processor.Instance<ContainerRegistryProcessor>().ContainerChanged -= OnContainerChanged; if (ConfigBase<Config>.Instance.Turrets.LoadFromContainers.Value) { _turrets = new SectorDictionary<HashSet<ServersideQoLZDO>>(Mathf.Max(ConfigBase<Config>.Instance.Turrets.LoadFromContainersRange.Value, (float)ConfigBase<Config>.Instance.Turrets.FeedFromContainersMaxRange.GetValueOrDefault())); _containersByItemName = Processor.Instance<ContainerRegistryProcessor>().GetContainersByItemName(_turrets.SectorWidth); Processor.Instance<ContainerRegistryProcessor>().ContainerChanged += OnContainerChanged; } else { _turrets = null; _containersByItemName = null; } } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0195: 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_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_071f: Unknown result type (might be due to invalid IL or missing references) //IL_0772: Unknown result type (might be due to invalid IL or missing references) //IL_0759: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03c4: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_0529: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_053a: Unknown result type (might be due to invalid IL or missing references) //IL_054b: Unknown result type (might be due to invalid IL or missing references) //IL_0550: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_05fc: Unknown result type (might be due to invalid IL or missing references) //IL_0611: Unknown result type (might be due to invalid IL or missing references) //IL_0616: Unknown result type (might be due to invalid IL or missing references) ZDOVars vars = zdo.Vars; PlayerID val = default(PlayerID); val = ((ZDOVars)(ref vars)).GetCreator(val); if (((PlayerID)(ref val)).Value == 0L) { return (ProcessResult)2; } ProcessResult val2 = (ProcessResult)0; ComponentFieldAccessor<Turret> val3 = zdo.Fields<Turret>(); if (!ConfigBase<Config>.Instance.Turrets.DontTargetPlayers.Value) { val3.Reset((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetPlayers), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 44); } else if (val3.UpdateValue((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetPlayers), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 45)) { val2 = (ProcessResult)(val2 | 8); } if (!ConfigBase<Config>.Instance.Turrets.DontTargetTames.Value) { val3.Reset((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetTamed), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 49); } else if (val3.UpdateValue((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetTamed), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 50)) { val2 = (ProcessResult)(val2 | 8); } if (!ConfigBase<Config>.Instance.Turrets.DontTargetTames.Value) { val3.Reset((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetTamedConfig), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 54); } else if (val3.UpdateValue((Func<Expression<Func<Turret, bool>>>)(() => (Turret x) => x.m_targetTamedConfig), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 55)) { val2 = (ProcessResult)(val2 | 8); } if (!ConfigBase<Config>.Instance.Turrets.LoadFromContainers.Value) { return (ProcessResult)(val2 | 2); } if (_turrets == null || _containersByItemName == null) { return (ProcessResult)(val2 | 2); } if (!Processor.CheckMinDistance(peers, zdo, ConfigBase<Config>.Instance.Turrets.LoadFromContainersMinPlayerDistance.Value)) { return (ProcessResult)(val2 | ((Processor)this).ScheduleReprocessing(0f)); } int num = val3.GetInt((Func<Expression<Func<Turret, int>>>)(() => (Turret x) => x.m_maxAmmo), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 70); vars = zdo.Vars; int num2 = ((ZDOVars)(ref vars)).GetAmmo(0); int num3 = num - num2; if (num3 < num / 2) { return val2; } object obj; if (num2 <= 0) { obj = null; } else { vars = zdo.Vars; obj = ((ZDOVars)(ref vars)).GetAmmoType(""); } string text = (string)obj; ItemData val4 = null; int num4 = 0; List<ServersideQoLZDO> list = null; List<ItemData> list2 = null; foreach (ItemDrop ammoItem in prefabInfo.Turret.m_allowedAmmo.Select((AmmoType x) => x.m_ammo)) { if (!string.IsNullOrEmpty(text) && ((Object)ammoItem).name != text) { continue; } AdjacentEnumerator<SharedItemDataKey, HashSet<ServersideQoLZDO>> enumerator2 = _containersByItemName.EnumerateAdjacent((zdo.ZDO.GetPosition(), SharedItemDataKey.op_Implicit(ammoItem.m_itemData.m_shared))).GetEnumerator(); try { while (enumerator2.MoveNext()) { HashSet<ServersideQoLZDO> current = enumerator2.Current; list?.Clear(); foreach (ServersideQoLZDO item in current) { ContainerState state = Processor.Instance<ContainerRegistryProcessor>().GetState(item); if (state == null) { (list ?? (list = new List<ServersideQoLZDO>())).Add(item); continue; } float num5 = state.FeedRange ?? ConfigBase<Config>.Instance.Turrets.LoadFromContainersRange.Value; num5 *= num5; if (num5 == 0f || Utils.DistanceSqr(zdo.ZDO.GetPosition(), item.ZDO.GetPosition()) > num5) { continue; } vars = item.Vars; if (((ZDOVars)(ref vars)).GetInUse(false)) { continue; } IInventory inventory = state.GetInventory(); list2?.Clear(); int num6 = 0; bool flag = false; bool flag2 = false; foreach (ItemData item2 in from x in inventory.Items where new ItemDataKey(x) == ItemDataKey.op_Implicit(ammoItem.m_itemData) orderby x.m_stack select x) { flag = flag || (item2 != null && item2.m_stack > 0); int num7 = Math.Min(num3, item2.m_stack); if (num7 != 0) { if (!item.IsOwnerOrUnassigned()) { flag2 = true; break; } text = ((Object)ammoItem).name; val4 = ammoItem.m_itemData; num6 += num7; item2.m_stack -= num7; if (item2.m_stack == 0) { (list2 ?? (list2 = new List<ItemData>())).Add(item2); } num3 -= num7; if (num3 == 0) { break; } } } if (flag2) { ProcessResult val5 = val2; ContainerRegistryProcessor obj2 = Processor.Instance<ContainerRegistryProcessor>(); val = default(PlayerID); val2 = (ProcessResult)(val5 | ((Processor)this).ScheduleReprocessing(obj2.RequestOwnership(item, val, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 139))); continue; } if (num6 == 0) { if (!flag) { (list ?? (list = new List<ServersideQoLZDO>())).Add(item); } continue; } if (list2 != null && list2.Count > 0) { foreach (ItemData item3 in list2) { inventory.Items.Remove(item3); } List<ItemData> items = inventory.Items; if (items != null && items.Count == 0) { (list ?? (list = new List<ServersideQoLZDO>())).Add(item); } } num2 += num6; vars = zdo.Vars; ((ZDOVars)(ref vars)).SetAmmo(num2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 160); vars = zdo.Vars; ((ZDOVars)(ref vars)).SetAmmoType(text, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.SmartDefense\\TurretProcessor.cs", 161); inventory.Save(); num4 += num6; if (num3 != 0) { continue; } break; } if (list != null) { foreach (ServersideQoLZDO item4 in list) { current.Remove(item4); } } if (num3 == 0) { break; } } } finally { ((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose(); } if (num3 == 0) { break; } } if (num4 != 0) { Processor.ShowMessage((IEnumerable<Peer>)peers, zdo, ConfigBase<Config>.Instance.Localization.Value.Turrets.FormatAmmoAdded(prefabInfo.Piece.m_name, val4.m_shared.m_name, num4), ConfigBase<Config>.Instance.Turrets.AmmoAddedMessageType.Value, (TextType)0); } else if (num2 == 0) { Processor.ShowMessage((IEnumerable<Peer>)peers, zdo, ConfigBase<Config>.Instance.Localization.Value.Turrets.NoAmmoFound, ConfigBase<Config>.Instance.Turrets.NoAmmoMessageType.Value, (TextType)7); } SectorDictionary.TryAdd(_turrets, zdo, true); return val2; } private void OnContainerChanged(ServersideQoLZDO containerZdo, ContainerState state) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) if (_turrets == null) { throw new Exception("bug"); } float num = state.FeedRange ?? ConfigBase<Config>.Instance.Turrets.LoadFromContainersRange.Value; num *= num; if (num == 0f) { return; } IInventory inventory = state.GetInventory(); if (inventory == null) { return; } List<ItemData> items = inventory.Items; if (items == null || items.Count <= 0) { return; } AdjacentEnumerator<HashSet<ServersideQoLZDO>> enumerator = _turrets.EnumerateAdjacent(containerZdo.ZDO.GetPosition()).GetEnumerator(); try { while (enumerator.MoveNext()) { HashSet<ServersideQoLZDO> current = enumerator.Current; foreach (ServersideQoLZDO item in current) { if (Utils.DistanceSqr(item.ZDO.GetPosition(), containerZdo.ZDO.GetPosition()) <= num) { ((Processor)this).ScheduleReprocessing(item, 0f); } } } } finally { ((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } } } }