using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Configuration; using Microsoft.CodeAnalysis; 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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ArgusMagnus")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyCopyright("ArgusMagnus")] [assembly: AssemblyDescription("Automatically update map tables with icons for portals and ships")] [assembly: AssemblyFileVersion("1.99.4.0")] [assembly: AssemblyInformationalVersion("1.99.4-beta+80c81ad250a0109e44b175db632e72dae9da8db5")] [assembly: AssemblyProduct("ServersideQoL.AutoMapTables")] [assembly: AssemblyTitle("ServersideQoL.AutoMapTables")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")] [assembly: AssemblyVersion("1.99.4.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.AutoMapTables { [BepInPlugin("ArgusMagnus.ServersideQoL.AutoMapTables", "ServersideQoL.AutoMapTables", "1.99.4")] public sealed class AutoMapTablesPlugin : ServersideQoLPluginBase { public static readonly int PluginGuidHash = StringExtensionMethods.GetStableHashCode("ArgusMagnus.ServersideQoL.AutoMapTables", true); public const string Author = "ArgusMagnus"; public const string PluginName = "ServersideQoL.AutoMapTables"; public const string PluginGuid = "ArgusMagnus.ServersideQoL.AutoMapTables"; public const string PluginVersion = "1.99.4"; public const string PluginInformationalVersion = "1.99.4-beta"; internal const string DependencyDirectory = "C:\\repos\\Valheim.ServersideQoL\\Dependencies\\"; private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639209323743054195L, default(TimeSpan)); protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger) { return new Config(configFile, logger); } protected override void RegisterProcessors(IProcessorCollection processors) { processors.Add().Add(); } private void Awake() { bool flag = true; ServersideQoLPluginBase.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.4-beta", BuildTimestamp.LocalDateTime)); } } public sealed class Config : ConfigBase { public sealed class LocalizationConfig { public string Updated { get; init; } = "$msg_mapsaved"; } public sealed class AdvancedConfig { public float MapTableUpdateInterval { get; init; } = 5f; } private const string Section = "AutoMapTables"; public override ConfigEntry Enabled { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated)null, "Enabled"); public ConfigEntry AutoUpdatePortals { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", true, "True to update map tables with portal pins", (AcceptableValueBase)null, (Deprecated)null, "AutoUpdatePortals"); public ConfigEntry AutoUpdatePortalsExclude { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", "", "Portals with a tag that matches this filter are not added to map tables", (AcceptableValueBase)null, (Deprecated)null, "AutoUpdatePortalsExclude"); public ConfigEntry AutoUpdatePortalsInclude { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", "*", "Only portals with a tag that matches this filter are added to map tables", (AcceptableValueBase)null, (Deprecated)null, "AutoUpdatePortalsInclude"); public ConfigEntry AutoUpdateShips { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", true, "True to update map tables with ship pins", (AcceptableValueBase)null, (Deprecated)null, "AutoUpdateShips"); public ConfigEntry UpdatedMessageType { get; } = ConfigBase.BindEx(cfg, "AutoMapTables", (MessageTypes)0, "Type of message to show when a map table is updated", (AcceptableValueBase)(object)AcceptableEnum.Default, (Deprecated)null, "UpdatedMessageType"); public YamlConfigEntry Localization { get; } = ConfigBase.BindYaml(cfg, "Localization"); public YamlConfigEntry Advanced { get; } = ConfigBase.BindYaml(cfg, "Advanced"); public Config(ConfigFile cfg, Logger logger) : base(cfg, logger) { } } [Processor("05450dd6-13bd-42cc-9bd3-b1eed5e501af")] public sealed class MapTableProcessor : Processor { public sealed record PrefabInfo(MapTable MapTable) : 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("MapTable = "); builder.Append(MapTable); return true; } [CompilerGenerated] public override int GetHashCode() { return ((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer.Default.GetHashCode(MapTable); } [CompilerGenerated] public sealed override bool Equals(ProcessorPrefabInfo? other) { return ((object)this).Equals((object?)other); } [CompilerGenerated] public bool Equals(PrefabInfo? other) { return (object)this == other || (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer.Default.Equals(MapTable, other.MapTable)); } [CompilerGenerated] private PrefabInfo(PrefabInfo original) : base((ProcessorPrefabInfo)(object)original) { MapTable = original.MapTable; } } private record Pin(long OwnerId, string Tag, Vector3 Pos, PinType Type, bool IsChecked, string Author) { [CompilerGenerated] public void Deconstruct(out long OwnerId, out string Tag, out Vector3 Pos, out PinType Type, out bool IsChecked, out string Author) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected I4, but got Unknown OwnerId = this.OwnerId; Tag = this.Tag; Pos = this.Pos; Type = (PinType)(int)this.Type; IsChecked = this.IsChecked; Author = this.Author; } } private readonly List _pins = new List(); private readonly List _existingPins = new List(); private byte[]? _emptyExplored; private int _pinsHash; private int _oldPinsHash; private Regex? _includePortalRegex; private Regex? _excludePortalRegex; private DateTimeOffset _pinsValidUntil; protected override void Initialize() { if (((ConfigBase)(object)ConfigBase.Instance).Enabled.Value) { string text = ConfigBase.Instance.AutoUpdatePortalsInclude.Value.Trim(); _includePortalRegex = (string.IsNullOrEmpty(text.Trim(new char[1] { '*' })) ? null : new Regex(Processor.ConvertToRegexPattern(text))); text = ConfigBase.Instance.AutoUpdatePortalsExclude.Value.Trim(); _excludePortalRegex = (string.IsNullOrEmpty(text) ? null : new Regex(Processor.ConvertToRegexPattern(text))); } else { _includePortalRegex = null; _excludePortalRegex = null; } _pins.Clear(); _existingPins.Clear(); } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList peers, PrefabInfo prefabInfo) { //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_04b1: Unknown result type (might be due to invalid IL or missing references) //IL_04b7: Expected O, but got Unknown //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Expected O, but got Unknown //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0374: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Invalid comparison between Unknown and I4 //IL_0601: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_03a0: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_0240: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_055c: Unknown result type (might be due to invalid IL or missing references) //IL_056a: Unknown result type (might be due to invalid IL or missing references) //IL_0574: Expected I4, but got Unknown //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_05ab: Unknown result type (might be due to invalid IL or missing references) //IL_05b0: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_05fd: Unknown result type (might be due to invalid IL or missing references) //IL_0453: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) DateTimeOffset utcNow = DateTimeOffset.UtcNow; if (_pinsValidUntil < utcNow) { _pins.Clear(); _pinsHash = 0; _pinsValidUntil = utcNow.AddSeconds(ConfigBase.Instance.Advanced.Value.MapTableUpdateInterval); } zdo.DelaySchedulingFor(ConfigBase.Instance.Advanced.Value.MapTableUpdateInterval); List pins = _pins; ZDOVars vars; if (pins != null && pins.Count == 0) { if (ConfigBase.Instance.AutoUpdatePortals.Value) { foreach (ServersideQoLZDO item in ZDOMan.instance.GetPortals().Values.SelectMany((List x) => x.Select((ZDO val3) => val3.ServersideQoLZDO))) { if (!item.IsModCreator()) { vars = item.Vars; string tag = ((ZDOVars)(ref vars)).GetTag(""); if ((_includePortalRegex?.IsMatch(tag) ?? true) && ((!(_excludePortalRegex?.IsMatch(tag))) ?? true)) { Pin pin = new Pin(AutoMapTablesPlugin.PluginGuidHash, tag, item.ZDO.GetPosition(), (PinType)6, IsChecked: false, "ArgusMagnus.ServersideQoL.AutoMapTables"); _pins.Add(pin); _oldPinsHash = (_oldPinsHash, pin).GetHashCode(); } } } } if (ConfigBase.Instance.AutoUpdateShips.Value) { foreach (ServersideQoLZDO ship in Processor.Instance().Ships) { Vector3 position = ship.ZDO.GetPosition(); ((Vector3)(ref position))..ctor(RoundToMultipleOf(position.x), RoundToMultipleOf(position.y), RoundToMultipleOf(position.z)); ShipProcessor.PrefabInfo processorPrefabInfo = ship.GetProcessorPrefabInfo(); Pin pin2 = new Pin(AutoMapTablesPlugin.PluginGuidHash, processorPrefabInfo.Piece.m_name ?? "", position, (PinType)10, IsChecked: false, "ArgusMagnus.ServersideQoL.AutoMapTables"); _pins.Add(pin2); _oldPinsHash = (_oldPinsHash, pin2).GetHashCode(); } } int oldPinsHash = _oldPinsHash; int pinsHash = _pinsHash; _pinsHash = oldPinsHash; _oldPinsHash = pinsHash; } if (_pinsHash == _oldPinsHash) { return (ProcessResult)32; } _existingPins.Clear(); vars = zdo.Vars; byte[] array = ((ZDOVars)(ref vars)).GetData((byte[])null); ZPackage val; if (array != null) { array = Utils.Decompress(array); val = new ZPackage(array); SharedMap val2 = (SharedMap)val.ReadInt(); if ((int)val2 != 3) { ((Processor)this).Logger.LogWarning((object)FormattableString.Invariant($"MapTable data version {val2:D} [{val2}] is not supported")); return (ProcessResult)0; } array = val.ReadByteArray(); if (array.Length != Minimap.instance.m_textureSize * Minimap.instance.m_textureSize) { ((Processor)this).Logger.LogWarning((object)"Invalid explored map data length"); array = null; } int num = val.ReadInt(); if (_existingPins.Capacity < num) { _existingPins.Capacity = num; } foreach (int item2 in Enumerable.Range(0, num)) { Pin pin3 = new Pin(val.ReadLong(), val.ReadString(), val.ReadVector3(), (PinType)val.ReadInt(), val.ReadBool(), val.ReadString()); if (pin3.OwnerId != AutoMapTablesPlugin.PluginGuidHash) { _existingPins.Add(pin3); } } } val = new ZPackage(); val.Write(3); val.Write(array ?? _emptyExplored ?? (_emptyExplored = new byte[Minimap.instance.m_textureSize * Minimap.instance.m_textureSize])); val.Write(_pins.Count + _existingPins.Count); foreach (Pin item3 in _pins.Concat(_existingPins)) { val.Write(item3.OwnerId); val.Write(item3.Tag); val.Write(item3.Pos); val.Write((int)item3.Type); val.Write(item3.IsChecked); val.Write(item3.Author); } vars = zdo.Vars; ((ZDOVars)(ref vars)).SetData(Utils.Compress(val.GetArray()), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoMapTables\\MapTableProcessor.cs", 141); Processor.ShowMessage((IEnumerable)peers, zdo, ConfigBase.Instance.Localization.Value.Updated, ConfigBase.Instance.UpdatedMessageType.Value, (TextType)0); return (ProcessResult)32; static float RoundToMultipleOf(float value) { return Mathf.Round(value / 5f) * 5f; } } } [Processor("5450041b-4bfe-4839-9a55-7762457b2a36")] public sealed class ShipProcessor : Processor { public sealed record PrefabInfo(Ship Ship, Piece Piece, ShipControlls ShipControls) : 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("Ship = "); builder.Append(Ship); builder.Append(", Piece = "); builder.Append(Piece); builder.Append(", ShipControls = "); builder.Append(ShipControls); return true; } [CompilerGenerated] public override int GetHashCode() { return ((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer.Default.GetHashCode(Ship)) * -1521134295 + EqualityComparer.Default.GetHashCode(Piece)) * -1521134295 + EqualityComparer.Default.GetHashCode(ShipControls); } [CompilerGenerated] public sealed override bool Equals(ProcessorPrefabInfo? other) { return ((object)this).Equals((object?)other); } [CompilerGenerated] public bool Equals(PrefabInfo? other) { return (object)this == other || (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer.Default.Equals(Ship, other.Ship) && EqualityComparer.Default.Equals(Piece, other.Piece) && EqualityComparer.Default.Equals(ShipControls, other.ShipControls)); } [CompilerGenerated] private PrefabInfo(PrefabInfo original) : base((ProcessorPrefabInfo)(object)original) { Ship = original.Ship; Piece = original.Piece; ShipControls = original.ShipControls; } } private readonly HashSet _ships = new HashSet(); public IReadOnlyCollection Ships => _ships; protected override void Initialize() { _ships.Clear(); foreach (ServersideQoLZDO item in from x in PrivateAccessor.GetObjects(ZDOMan.instance) select x.ServersideQoLZDO) { if ((object)base.GetPrefabInfo(item) != null && _ships.Add(item)) { item.Destroyed += OnShipDestroyed; } } } protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList peers, PrefabInfo prefabInfo) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (_ships.Add(zdo)) { zdo.Destroyed += OnShipDestroyed; } return (ProcessResult)2; } private void OnShipDestroyed(ServersideQoLZDO zdo) { _ships.Remove(zdo); } } }