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 Territory v1.0.3
plugins/Territory.dll
Decompiled 5 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using BiomeLockAPI; using HarmonyLib; using JetBrains.Annotations; using LocalizationManager; using Microsoft.CodeAnalysis; using ServerSync; using Splatform; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.UI; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Core.ObjectPool; using YamlDotNet.Core.Tokens; using YamlDotNet.Helpers; using YamlDotNet.Serialization; using YamlDotNet.Serialization.BufferedDeserialization; using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators; using YamlDotNet.Serialization.Callbacks; using YamlDotNet.Serialization.Converters; using YamlDotNet.Serialization.EventEmitters; using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NodeDeserializers; using YamlDotNet.Serialization.NodeTypeResolvers; using YamlDotNet.Serialization.ObjectFactories; using YamlDotNet.Serialization.ObjectGraphTraversalStrategies; using YamlDotNet.Serialization.ObjectGraphVisitors; using YamlDotNet.Serialization.Schemas; using YamlDotNet.Serialization.TypeInspectors; using YamlDotNet.Serialization.TypeResolvers; using YamlDotNet.Serialization.Utilities; using YamlDotNet.Serialization.ValueDeserializers; [assembly: AssemblyTitle("Territory")] [assembly: AssemblyProduct("Territory")] [assembly: AssemblyInformationalVersion("1.0.3+a96529a43659e708247bf8868fa8d7340157abe7")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyCompany("Territory")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.0")] [module: <b282a9e6-3382-46f6-9ee2-073a4a860eb1>RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<cdab91c8-a785-4cc3-aab2-6f8e9236377f>Embedded] internal sealed class <cdab91c8-a785-4cc3-aab2-6f8e9236377f>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [<cdab91c8-a785-4cc3-aab2-6f8e9236377f>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [CompilerGenerated] internal sealed class <743ecad6-8c5d-431d-9706-069cf944ea12>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <743ecad6-8c5d-431d-9706-069cf944ea12>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <743ecad6-8c5d-431d-9706-069cf944ea12>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [<cdab91c8-a785-4cc3-aab2-6f8e9236377f>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class <5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContextAttribute : Attribute { public readonly byte Flag; public <5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [<cdab91c8-a785-4cc3-aab2-6f8e9236377f>Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class <b282a9e6-3382-46f6-9ee2-073a4a860eb1>RefSafetyRulesAttribute : Attribute { public readonly int Version; public <b282a9e6-3382-46f6-9ee2-073a4a860eb1>RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LocalizationManager { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [PublicAPI] public class Localizer { private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors; private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts; private static readonly ConditionalWeakTable<Localization, string> localizationLanguage; private static readonly List<WeakReference<Localization>> localizationObjects; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] private static BaseUnityPlugin _plugin; private static readonly List<string> fileExtensions; private static BaseUnityPlugin plugin { get { //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Expected O, but got Unknown if (_plugin == null) { IEnumerable<TypeInfo> source; try { source = Assembly.GetExecutingAssembly().DefinedTypes.ToList(); } catch (ReflectionTypeLoadException ex) { source = from t in ex.Types where t != null select t.GetTypeInfo(); } _plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] [method: <5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(2)] [field: <743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] public static event Action OnLocalizationComplete; private static void UpdatePlaceholderText(Localization localization, string key) { localizationLanguage.TryGetValue(localization, out var value); string text = loadedTexts[value][key]; if (PlaceholderProcessors.TryGetValue(key, out var value2)) { text = value2.Aggregate(text, [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value())); } localization.AddWord(key, text); } public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null) { if (convertConfigValue == null) { convertConfigValue = (T val) => val.ToString(); } if (!PlaceholderProcessors.ContainsKey(key)) { PlaceholderProcessors[key] = new Dictionary<string, Func<string>>(); } config.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { UpdatePlaceholder(); }; if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage())) { UpdatePlaceholder(); } void UpdatePlaceholder() { PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value); UpdatePlaceholderText(Localization.instance, key); } } public static void AddText(string key, string text) { List<WeakReference<Localization>> list = new List<WeakReference<Localization>>(); foreach (WeakReference<Localization> localizationObject in localizationObjects) { if (localizationObject.TryGetTarget(out var target)) { Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)]; if (!target.m_translations.ContainsKey(key)) { dictionary[key] = text; target.AddWord(key, text); } } else { list.Add(localizationObject); } } foreach (WeakReference<Localization> item in list) { localizationObjects.Remove(item); } } public static void Load() { _ = plugin; } public static void LoadLocalizationLater(Localization __instance) { LoadLocalization(Localization.instance, __instance.GetSelectedLanguage()); } public static void SafeCallLocalizeComplete() { Localizer.OnLocalizationComplete?.Invoke(); } private static void LoadLocalization(Localization __instance, string language) { if (!localizationLanguage.Remove(__instance)) { localizationObjects.Add(new WeakReference<Localization>(__instance)); } localizationLanguage.Add(__instance, language); Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories) where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0 select f) { string[] array = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' }); if (array.Length >= 2) { string text = array[1]; if (dictionary.ContainsKey(text)) { Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped.")); } else { dictionary[text] = item; } } } byte[] array2 = LoadTranslationFromAssembly("English"); if (array2 == null) { throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml."); } string input = Encoding.UTF8.GetString(array2).TrimStart(new char[1] { '\ufeff' }); Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(input); if (dictionary2 == null) { throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty."); } string text2 = null; if (language != "English") { if (dictionary.TryGetValue(language, out var value)) { text2 = File.ReadAllText(value); } else { byte[] array3 = LoadTranslationFromAssembly(language); if (array3 != null) { text2 = Encoding.UTF8.GetString(array3); } } } if (text2 == null && dictionary.TryGetValue("English", out var value2)) { text2 = File.ReadAllText(value2); } if (text2 != null) { text2 = text2.TrimStart(new char[1] { '\ufeff' }); foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>()) { dictionary2[item2.Key] = item2.Value; } } loadedTexts[language] = dictionary2; foreach (KeyValuePair<string, string> item3 in dictionary2) { UpdatePlaceholderText(__instance, item3.Key); } } static Localizer() { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Expected O, but got Unknown PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>(); loadedTexts = new Dictionary<string, Dictionary<string, string>>(); localizationLanguage = new ConditionalWeakTable<Localization, string>(); localizationObjects = new List<WeakReference<Localization>>(); fileExtensions = new List<string>(2) { ".json", ".yml" }; Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "SetupGui", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalizationLater", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "SafeCallLocalizeComplete", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } [return: <743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] private static byte[] LoadTranslationFromAssembly(string language) { foreach (string fileExtension in fileExtensions) { byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension); if (array != null) { return array; } } return null; } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(2)] public static byte[] ReadEmbeddedFileBytes([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] string resourceFileName, Assembly containingAssembly = null) { using MemoryStream memoryStream = new MemoryStream(); if ((object)containingAssembly == null) { containingAssembly = Assembly.GetCallingAssembly(); } string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal)); if (text != null) { containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream); } return (memoryStream.Length == 0L) ? null : memoryStream.ToArray(); } } public static class LocalizationManagerVersion { [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] public const string Version = "1.4.1"; } } namespace Territory { internal static class BiomeLockBypass { [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] private static readonly Func<Vector3, bool> Bypass = Inside; private static bool _linked; private static bool Inside(Vector3 position) { //IL_000c: 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_001b: Unknown result type (might be due to invalid IL or missing references) return TerritoryPlugin.BypassBiomeLock.Value && (TerritoryState.At(position) != null || TerritoryState.BiomeAt(position.x, position.z) != null); } internal static bool Locked(Biome biome) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) return !TerritoryPlugin.BypassBiomeLock.Value && !TerritoryState.LocalAdmin && API.IsBiomeLocked(biome); } internal static void Link() { if (!_linked && API.IsLoaded) { API.AddRestrictionBypass(Bypass); _linked = true; } } internal static void Unlink() { if (_linked) { API.RemoveRestrictionBypass(Bypass); _linked = false; } } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal static class TerritoryFiles { internal static float MaxTerritorySize = 500f; internal static readonly List<string> Skipped = new List<string>(); internal static string Folder => Path.Combine(Paths.ConfigPath, "Territory"); internal static List<Land> Load([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] string directory = null) { string path = directory ?? Folder; Directory.CreateDirectory(path); List<Land> list = new List<Land>(); Skipped.Clear(); foreach (string item in Directory.GetFiles(path, "*.cfg").OrderBy<string, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string p) => p, StringComparer.Ordinal)) { Land land = Parse(item); if (land.Enabled && land.AffectedSide > MaxTerritorySize) { Skipped.Add(item + ": territory ignored, affected area side " + Meters(land.AffectedSide) + " m exceeds MaxTerritorySize " + Meters(MaxTerritorySize) + " m (Size + 2 x the larger of ProtectionBorderWidth and GroundSlopeWidth)."); } else { if (list.Any([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (Land t) => t.ID == land.ID)) { throw new FormatException("Duplicate territory ID: " + land.ID); } list.Add(land); } } if (list.Count > 512) { throw new FormatException("Maximum " + 512 + " territories supported."); } return list; } private static Land Parse(string path) { Land land = new Land { FilePath = path }; int num = 0; string[] array = File.ReadAllLines(path); foreach (string text in array) { num++; string text2 = text.Trim(); if (text2.Length == 0 || text2.StartsWith("#") || text2.StartsWith(";")) { continue; } if (text2.StartsWith("[") && text2.EndsWith("]")) { if (land.ID.Length > 0) { throw new FormatException(path + ": exactly one territory section is allowed."); } land.ID = text2.Substring(1, text2.Length - 2); continue; } int num2 = text2.IndexOf('='); if (land.ID.Length == 0 || num2 <= 0) { throw new FormatException(path + ":" + num + ": invalid entry."); } string text3 = text2.Substring(0, num2).Trim(); if (land.Values.ContainsKey(text3)) { throw new FormatException(path + ":" + num + ": duplicate " + text3); } land.Values.Add(text3, text2.Substring(num2 + 1).Trim()); } try { land.Validate(); } catch (Exception ex) { throw new FormatException(path + ": " + ex.Message, ex); } return land; } private static string Meters(float value) { return value.ToString("0.##", CultureInfo.InvariantCulture); } internal static void Save(Land land, params string[] keys) { string text = File.ReadAllText(land.FilePath); foreach (string item in keys.Distinct<string>(StringComparer.Ordinal)) { Regex regex = new Regex("(?m)^[ \\t]*" + Regex.Escape(item) + "[ \\t]*=[^\\r\\n]*"); string entry = item + " = " + land.Values[item]; text = (regex.IsMatch(text) ? regex.Replace(text, [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (Match _) => entry) : (text.TrimEnd(Array.Empty<char>()) + Environment.NewLine + entry + Environment.NewLine)); } string text2 = land.FilePath + ".tmp"; File.WriteAllText(text2, text, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); File.Replace(text2, land.FilePath, null); } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal static class Identity { internal static string Local { get { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) IDistributionPlatform distributionPlatform = PlatformManager.DistributionPlatform; return (((distributionPlatform != null) ? distributionPlatform.LocalUser : null) == null) ? "" : ((object)((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID/*cast due to .constrained prefix*/).ToString(); } } internal unsafe static string Normalize(string raw) { raw = raw.Trim(); if (raw.Length == 0) { return ""; } if (raw.All(char.IsDigit)) { raw = "Steam_" + raw; } PlatformUserID val = default(PlatformUserID); if (raw.Length > 128 || !PlatformUserID.TryParse(raw, ref val)) { throw new FormatException("Invalid platform user ID: " + raw); } return ((object)(*(PlatformUserID*)(&val))/*cast due to .constrained prefix*/).ToString(); } } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] internal sealed class Land { internal const int MaxName = 24; internal string ID = ""; internal string FilePath = ""; internal Dictionary<string, string> Values = new Dictionary<string, string>(StringComparer.Ordinal); internal readonly Dictionary<string, float> Numbers = new Dictionary<string, float>(StringComparer.Ordinal); internal readonly HashSet<string> Flags = new HashSet<string>(StringComparer.Ordinal); internal HashSet<string> Members = new HashSet<string>(StringComparer.Ordinal); internal Dictionary<string, string> KnownNames = new Dictionary<string, string>(StringComparer.Ordinal); internal string Owner = ""; internal Vector3 Center; internal Biome Biome; internal bool Enabled; internal float HalfSize; internal float OuterHalfSize; internal float SlopeWidth; internal float GroundReach; internal string Name => Values["Name"]; internal string Signature => ID + "\t" + FilePath + "\t" + string.Join("\t", from p in Values.OrderBy<KeyValuePair<string, string>, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (KeyValuePair<string, string> p) => p.Key, StringComparer.Ordinal) select p.Key + "=" + p.Value); internal float AffectedSide => 2f * Math.Max(OuterHalfSize, GroundReach); internal float BiomeHalf => Math.Max(OuterHalfSize, GroundReach); internal bool On(string key) { return Flags.Contains(key); } internal float Number(string key) { return Numbers[key]; } internal bool Contains(Vector3 pos, bool main = false) { //IL_0013: 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) float num = (main ? HalfSize : OuterHalfSize); return Math.Abs(pos.x - Center.x) <= num && Math.Abs(pos.z - Center.z) <= num; } internal bool InBiome(float x, float z) { return Math.Abs(x - Center.x) <= BiomeHalf && Math.Abs(z - Center.z) <= BiomeHalf; } internal bool Touches(Vector3 center, float half) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Math.Abs(center.x - Center.x) <= half + OuterHalfSize && Math.Abs(center.z - Center.z) <= half + OuterHalfSize; } internal bool TouchesBiome(Vector3 center, float half) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Math.Abs(center.x - Center.x) <= half + BiomeHalf && Math.Abs(center.z - Center.z) <= half + BiomeHalf; } internal bool TouchesGround(Vector3 center, float half) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return Math.Abs(center.x - Center.x) <= half + GroundReach && Math.Abs(center.z - Center.z) <= half + GroundReach; } internal bool GroundAt(float x, float z, float natural, out float height) { float num = Math.Max(0f, Math.Abs(x - Center.x) - HalfSize); float num2 = Math.Max(0f, Math.Abs(z - Center.z) - HalfSize); height = natural; if (!On("ForceGroundHeight")) { return false; } float num3 = (height = Number("GroundHeight")); if (num <= 0f && num2 <= 0f) { return true; } if (SlopeWidth <= 0f) { return false; } float num4 = (float)Math.Sqrt(num * num + num2 * num2) / SlopeWidth; if (num4 >= 1f) { return false; } float num5 = num4 * num4 * (3f - 2f * num4); height = num3 + (natural - num3) * num5; return true; } internal bool Permitted(string id, bool admin = false) { return admin || (id.Length > 0 && ((Owner.Length > 0 && Owner == id) || Members.Contains(id))); } internal static bool ValidName(string name) { return !string.IsNullOrWhiteSpace(name) && name.Trim().Length <= 24 && !name.Any((char c) => char.IsControl(c) || c == '<' || c == '>'); } internal static string CleanName(string name) { string text = new string(name.Where((char c) => !char.IsControl(c) && c != ',' && c != ':' && c != '<' && c != '>' && c != '=').ToArray()).Trim(); return (text.Length > 32) ? text.Substring(0, 32).Trim() : text; } internal static string FormatNames(Dictionary<string, string> names) { return string.Join(", ", from p in names.Where([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (KeyValuePair<string, string> p) => CleanName(p.Value).Length > 0).OrderBy<KeyValuePair<string, string>, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (KeyValuePair<string, string> p) => p.Key, StringComparer.Ordinal) select p.Key + ":" + CleanName(p.Value)); } internal Land With(string key, string value) { Land land = new Land { ID = ID, FilePath = FilePath, Values = new Dictionary<string, string>(Values, StringComparer.Ordinal) }; land.Values[key] = value; land.Validate(); return land; } internal void Validate() { //IL_06af: Unknown result type (might be due to invalid IL or missing references) //IL_06cd: Unknown result type (might be due to invalid IL or missing references) //IL_06ce: Unknown result type (might be due to invalid IL or missing references) //IL_0461: Unknown result type (might be due to invalid IL or missing references) //IL_0466: Unknown result type (might be due to invalid IL or missing references) Flags.Clear(); Numbers.Clear(); if (ID.Length == 0 || ID.Length > 64 || ID.IndexOfAny(new char[4] { '[', ']', '\r', '\n' }) >= 0) { throw new FormatException("Invalid territory section identifier."); } foreach (string item in Values.Keys.Where(Schema.Removed.Contains).ToList()) { Values.Remove(item); } foreach (KeyValuePair<string, string> @default in Schema.Defaults) { if (!Values.ContainsKey(@default.Key)) { Values.Add(@default.Key, @default.Value); } string text = Values[@default.Key].Trim(); Values[@default.Key] = text; (float, float) value; if (Schema.Bools.Contains(@default.Key)) { if (!bool.TryParse(text, out var result)) { throw new FormatException(@default.Key + " must be true or false."); } if (result) { Flags.Add(@default.Key); } Values[@default.Key] = (result ? "true" : "false"); } else if (Schema.Ranges.TryGetValue(@default.Key, out value)) { if (!float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) || float.IsNaN(result2) || float.IsInfinity(result2) || result2 < value.Item1 || result2 > value.Item2) { throw new FormatException(@default.Key + " is outside its allowed range."); } if ((@default.Key == "MaxMembers" || @default.Key == "Priority") && (double)result2 != Math.Truncate(result2)) { throw new FormatException(@default.Key + " must be an integer."); } Numbers[@default.Key] = result2; } } foreach (string key in Values.Keys) { if (!Schema.Defaults.ContainsKey(key)) { throw new FormatException("Unknown or removed setting: " + key); } } if (Name.Length > 24) { Values["Name"] = Name.Substring(0, 24).Trim(); } if (!ValidName(Name)) { throw new FormatException("Name must contain 1-" + 24 + " plain text characters."); } string[] array = Values["Coordinates"].Split(new char[1] { ',' }); if (array.Length != 2 || !float.TryParse(array[0], NumberStyles.Float, CultureInfo.InvariantCulture, out var result3) || !float.TryParse(array[1], NumberStyles.Float, CultureInfo.InvariantCulture, out var result4) || float.IsNaN(result3) || float.IsNaN(result4) || float.IsInfinity(result3) || float.IsInfinity(result4) || Math.Abs(result3) > 20000f || Math.Abs(result4) > 20000f) { throw new FormatException("Coordinates must be finite X, Z values within +/-" + 20000f + " meters."); } Center = new Vector3(result3, 0f, result4); Owner = Identity.Normalize(Values["OwnerID"]); Values["OwnerID"] = Owner; Members = new HashSet<string>((from s in Values["Members"].Split(new char[1] { ',' }) where !string.IsNullOrWhiteSpace(s) select s).Select(Identity.Normalize), StringComparer.Ordinal); Members.Remove(Owner); if ((float)Members.Count > Number("MaxMembers")) { throw new FormatException("Members exceeds MaxMembers."); } Values["Members"] = string.Join(", ", Members.OrderBy<string, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string s) => s, StringComparer.Ordinal)); KnownNames = new Dictionary<string, string>(StringComparer.Ordinal); string[] array2 = Values["KnownNames"].Split(new char[1] { ',' }); foreach (string text2 in array2) { int num2 = text2.IndexOf(':'); if (num2 > 0) { string text3 = CleanName(text2.Substring(num2 + 1)); string text4; try { text4 = Identity.Normalize(text2.Substring(0, num2)); } catch (FormatException) { continue; } if (text3.Length > 0 && (text4 == Owner || Members.Contains(text4))) { KnownNames[text4] = text3; } } } Values["KnownNames"] = FormatNames(KnownNames); if (!Enum.TryParse<Biome>(Values["Biome"], ignoreCase: true, out Biome result5) || !Schema.Biomes.Contains(result5)) { throw new FormatException("Invalid Biome."); } Biome = result5; if (!Schema.GroundPaints.Contains(Values["GroundPaint"])) { throw new FormatException("Invalid GroundPaint."); } Enabled = On("Enabled"); HalfSize = Number("Size") / 2f; OuterHalfSize = HalfSize + (On("ProtectionBorderEnabled") ? Number("ProtectionBorderWidth") : 0f); SlopeWidth = (On("ForceGroundHeight") ? Number("GroundSlopeWidth") : 0f); GroundReach = HalfSize + SlopeWidth; } internal void Write(ZPackage pkg) { pkg.Write(ID); pkg.Write(Values.Count); foreach (KeyValuePair<string, string> item in Values.OrderBy<KeyValuePair<string, string>, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (KeyValuePair<string, string> p) => p.Key, StringComparer.Ordinal)) { pkg.Write(item.Key); pkg.Write(item.Value); } } internal static Land Read(ZPackage pkg) { Land land = new Land { ID = pkg.ReadString() }; int num = pkg.ReadInt(); if (num < 0 || num > Schema.Defaults.Count) { throw new FormatException("Invalid settings count."); } for (int i = 0; i < num; i++) { land.Values.Add(pkg.ReadString(), pkg.ReadString()); } land.Validate(); return land; } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal static class Schema { internal const float WorldLimit = 20000f; internal const int MaxTerritories = 512; internal static readonly HashSet<string> Bools = new HashSet<string>("Enabled ForceGroundHeight ProtectionBorderEnabled PushAway NoBuild NoPickaxe NoInteract NoAttack NoPortals NoInteractItems NoInteractCraftingStation NoInteractItemStands NoInteractChests NoInteractDoors NoInteractPortals NoMonsters NoBuildDamage NoStructureSupport InfiniteFuel InfiniteStamina InfiniteEitr NoDeathPenalty NoItemLoss ForceBiome CustomPaint".Split(new char[1] { ' ' }), StringComparer.Ordinal); internal static readonly HashSet<string> Removed = new HashSet<string>("OwnerEditableSettings PublicAccess MonstersAddStars AdditionalMonsterStars PvpOnly PveOnly GodMode IncreasedPlayerDamage PlayerDamageMultiplier IncreasedMonsterDamage MonsterDamageMultiplier MoveSpeedMultiplier DropMultiplier DropMultiplierValue PeriodicHeal PeriodicHealAmount PeriodicHealALL PeriodicHealAllAmount PeriodicDamage PeriodicDamageAmount PeriodicEffectInterval CustomEnvironment Environments SnowMask NoMist ForceWind WindIntensity ZoneMusic MusicName".Split(new char[1] { ' ' }), StringComparer.Ordinal); internal static readonly HashSet<string> OwnerFields = new HashSet<string>("Name Members PushAway".Split(new char[1] { ' ' }), StringComparer.Ordinal); internal static readonly string[] GroundPaints = new string[4] { "Grass", "Dirt", "Cultivated", "Paved" }; internal static readonly Biome[] DefaultOwnerBiomes; internal static Biome[] OwnerBiomes; internal static readonly HashSet<Biome> Biomes; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(new byte[] { 1, 1, 0 })] internal static readonly Dictionary<string, (float Min, float Max)> Ranges; internal static readonly Dictionary<string, string> Defaults; internal static Biome[] ParseOwnerBiomes(string list, out List<string> invalid) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) List<Biome> list2 = new List<Biome>(); invalid = new List<string>(); string[] array = list.Split(new char[1] { ',' }); foreach (string text in array) { string text2 = text.Trim(); if (text2.Length == 0) { continue; } if (text2.All(char.IsLetter) && Enum.TryParse<Biome>(text2, ignoreCase: true, out Biome result) && DefaultOwnerBiomes.Contains(result)) { if (!list2.Contains(result)) { list2.Add(result); } } else { invalid.Add(text2); } } return list2.ToArray(); } private static Dictionary<string, string> MakeDefaults() { Dictionary<string, string> dictionary = Bools.ToDictionary<string, string, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string k) => k, [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string _) => "false", StringComparer.Ordinal); foreach (KeyValuePair<string, (float, float)> range in Ranges) { dictionary[range.Key] = "0"; } dictionary["Enabled"] = "true"; dictionary["Name"] = "Territory"; dictionary["OwnerID"] = ""; dictionary["Members"] = ""; dictionary["KnownNames"] = ""; dictionary["MaxMembers"] = "10"; dictionary["Priority"] = "1"; dictionary["Size"] = "60"; dictionary["GroundHeight"] = "36"; dictionary["ProtectionBorderWidth"] = "10"; dictionary["Coordinates"] = "0, 0"; dictionary["MovementSpeedMultiplier"] = "1"; dictionary["Biome"] = "Meadows"; dictionary["GroundPaint"] = "Grass"; return dictionary; } static Schema() { Biome[] array = new Biome[7]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); DefaultOwnerBiomes = (Biome[])(object)array; OwnerBiomes = DefaultOwnerBiomes; Biome[] array2 = new Biome[9]; RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Biomes = new HashSet<Biome>((IEnumerable<Biome>)(object)array2); Ranges = new Dictionary<string, (float, float)> { ["MaxMembers"] = (0f, 1000f), ["Priority"] = (-100000f, 100000f), ["Size"] = (1f, 20000f), ["GroundHeight"] = (-10000f, 10000f), ["ProtectionBorderWidth"] = (0f, 10000f), ["GroundSlopeWidth"] = (0f, 500f), ["MovementSpeedMultiplier"] = (0f, 20f) }; Defaults = MakeDefaults(); } } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(2)] [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] internal static class TerritoryMap { [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] private static readonly Dictionary<int, Color> Originals = new Dictionary<int, Color>(); [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] private static readonly Dictionary<int, Color> OriginalHeights = new Dictionary<int, Color>(); private static Texture2D _texture; private static Texture2D _heights; private static Minimap _ready; private static TMP_Text _name; private static RawImage _image; [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal static void Ready(Minimap map, Texture2D heights) { _ready = map; _heights = heights; Paint(); ShowName(TerritoryRuntime.Current); } internal static void ShowName(Land land) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; TMP_Text val = instance?.m_biomeNameSmall; RawImage val2 = instance?.m_mapImageSmall; if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null)) { if ((Object)(object)_image != (Object)(object)val2 || (Object)(object)_name == (Object)null) { ResetName(); _image = val2; GameObject val3 = new GameObject("Territory Name", new Type[1] { typeof(RectTransform) }); val3.SetActive(false); val3.transform.SetParent(((Component)val2).transform, false); TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val4).font = val.font; ((TMP_Text)val4).fontSize = val.fontSize; ((TMP_Text)val4).fontStyle = val.fontStyle; ((Graphic)val4).raycastTarget = false; ((TMP_Text)val4).richText = false; ((Graphic)val4).color = TerritoryText.Lime; ((TMP_Text)val4).alignment = (TextAlignmentOptions)257; ((TMP_Text)val4).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)val4).overflowMode = (TextOverflowModes)1; RectTransform rectTransform = ((TMP_Text)val4).rectTransform; rectTransform.anchorMin = new Vector2(0f, 1f); rectTransform.anchorMax = new Vector2(1f, 1f); rectTransform.pivot = new Vector2(0f, 1f); rectTransform.offsetMin = new Vector2(8f, (0f - val.fontSize) * 1.4f - 6f); rectTransform.offsetMax = new Vector2(-8f, -6f); _name = (TMP_Text)(object)val4; } if (land == null) { ((Component)_name).gameObject.SetActive(false); return; } _name.text = land.Name; ((Component)_name).gameObject.SetActive(true); } } private static void ResetName() { if ((Object)(object)_name != (Object)null) { Object.Destroy((Object)(object)((Component)_name).gameObject); } _name = null; _image = null; } internal static void Paint() { //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_034f: Unknown result type (might be due to invalid IL or missing references) //IL_0320: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance != (Object)(object)_ready || (Object)(object)instance.m_mapTexture == (Object)null) { return; } if ((Object)(object)_texture != (Object)(object)instance.m_mapTexture) { Originals.Clear(); OriginalHeights.Clear(); _texture = instance.m_mapTexture; } int width = ((Texture)_texture).width; foreach (KeyValuePair<int, Color> original in Originals) { _texture.SetPixel(original.Key % width, original.Key / width, original.Value); } if ((Object)(object)_heights != (Object)null) { foreach (KeyValuePair<int, Color> originalHeight in OriginalHeights) { _heights.SetPixel(originalHeight.Key % width, originalHeight.Key / width, originalHeight.Value); } } bool flag = Originals.Count > 0; bool flag2 = OriginalHeights.Count > 0; Originals.Clear(); OriginalHeights.Clear(); if (TerritoryPlugin.ShowOnMap.Value) { foreach (Land item in TerritoryState.Lands.Where([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (Land t) => t.Enabled)) { int num = Utils.RoundToInt(item.Center.x / instance.m_pixelSize + (float)(instance.m_textureSize / 2)); int num2 = Utils.RoundToInt(item.Center.z / instance.m_pixelSize + (float)(instance.m_textureSize / 2)); int num3 = Mathf.CeilToInt(item.OuterHalfSize / instance.m_pixelSize); int num4 = Mathf.CeilToInt(item.HalfSize / instance.m_pixelSize); bool flag3 = item.On("ForceGroundHeight") && (Object)(object)_heights != (Object)null && ((Texture)_heights).width == width; for (int num5 = Mathf.Max(0, num2 - num3); num5 <= Mathf.Min(width - 1, num2 + num3); num5++) { for (int num6 = Mathf.Max(0, num - num3); num6 <= Mathf.Min(width - 1, num + num3); num6++) { int key = num5 * width + num6; if (!Originals.ContainsKey(key)) { Originals[key] = _texture.GetPixel(num6, num5); } _texture.SetPixel(num6, num5, Color.black); flag = true; if (flag3 && Math.Abs(num6 - num) <= num4 && Math.Abs(num5 - num2) <= num4) { if (!OriginalHeights.ContainsKey(key)) { OriginalHeights[key] = _heights.GetPixel(num6, num5); } _heights.SetPixel(num6, num5, new Color(item.Number("GroundHeight"), 0f, 0f, 1f)); flag2 = true; } } } } } if (flag) { _texture.Apply(); } if (flag2) { _heights.Apply(); } } internal static void Reset() { Originals.Clear(); OriginalHeights.Clear(); _texture = null; _heights = null; _ready = null; ResetName(); MapHover.Reset(); } } [HarmonyPatch(typeof(Minimap), "LoadMapData")] internal static class Minimap_LoadMapData_Paint { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Minimap __instance, Texture2D ___m_heightTexture) { TerritoryMap.Ready(__instance, ___m_heightTexture); } } [HarmonyPatch(typeof(Minimap), "GenerateWorldMap")] internal static class Minimap_GenerateWorldMap_Paint { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Minimap __instance, Texture2D ___m_heightTexture) { TerritoryMap.Reset(); TerritoryMap.Ready(__instance, ___m_heightTexture); } } [HarmonyPatch(typeof(Minimap), "Awake")] internal static class Minimap_Awake_Name { private static void Postfix() { TerritoryMap.ShowName(TerritoryRuntime.Current); } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(2)] internal static class MapHover { private static TMP_Text _label; private static TMP_Text _source; private static Land _shown; private static Vector3 _point; private static bool _explored; private static bool _captured; internal static void Begin() { _captured = false; } internal static void Capture(Vector3 point, bool explored) { //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) _point = point; _explored = explored; _captured = true; } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal static void Refresh(Minimap map) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_0121: Invalid comparison between Unknown and I4 //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: 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_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: 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_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: 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_0134: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) TMP_Text biomeNameLarge = map.m_biomeNameLarge; if ((Object)(object)biomeNameLarge == (Object)null) { return; } if ((Object)(object)_source != (Object)(object)biomeNameLarge || (Object)(object)_label == (Object)null) { Reset(); _source = biomeNameLarge; GameObject val = new GameObject("Territory Map Info", new Type[1] { typeof(RectTransform) }); val.SetActive(false); val.transform.SetParent(biomeNameLarge.transform, false); TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val2).font = biomeNameLarge.font; ((TMP_Text)val2).fontSize = biomeNameLarge.fontSize; ((TMP_Text)val2).fontStyle = biomeNameLarge.fontStyle; ((Graphic)val2).raycastTarget = false; ((TMP_Text)val2).richText = true; ((Graphic)val2).color = TerritoryText.Lime; ((TMP_Text)val2).horizontalAlignment = biomeNameLarge.horizontalAlignment; ((TMP_Text)val2).verticalAlignment = (VerticalAlignmentOptions)256; ((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0; ((TMP_Text)val2).overflowMode = (TextOverflowModes)0; _label = (TMP_Text)(object)val2; } Land land = ((TerritoryPlugin.ShowMapInfo.Value && (int)map.m_mode == 2 && _captured && _explored) ? TerritoryState.At(_point) : null); if (land == null) { if (((Component)_label).gameObject.activeSelf) { ((Component)_label).gameObject.SetActive(false); } _shown = null; return; } if (land != _shown) { _label.text = Describe(land); _shown = land; } RectTransform rectTransform = biomeNameLarge.rectTransform; RectTransform rectTransform2 = _label.rectTransform; Vector2 anchorMin = (rectTransform2.anchorMax = rectTransform.pivot); rectTransform2.anchorMin = anchorMin; rectTransform2.pivot = new Vector2(rectTransform.pivot.x, 1f); Rect rect = rectTransform.rect; rectTransform2.sizeDelta = new Vector2(((Rect)(ref rect)).width, biomeNameLarge.fontSize * 4f); float num; if (biomeNameLarge.text.Length <= 0) { num = 0f; } else { Bounds textBounds = biomeNameLarge.textBounds; num = ((Bounds)(ref textBounds)).min.y; } float num2 = num; rectTransform2.anchoredPosition = new Vector2(0f, num2 - biomeNameLarge.fontSize * 0.3f); if (!((Component)_label).gameObject.activeSelf) { ((Component)_label).gameObject.SetActive(true); } } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static string Describe(Land land) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<b>").Append(land.Name).Append("</b>\n<size=80%>"); stringBuilder.Append(TerritoryText.L("$territory_map_owner", TerritoryState.DisplayName(land, land.Owner))).Append('\n'); bool flag = TerritoryState.Permitted(land); stringBuilder.Append(TerritoryText.Paint(TerritoryText.L(flag ? "$territory_map_access" : "$territory_map_noaccess"), flag ? TerritoryText.Green : TerritoryText.Red)); return stringBuilder.Append("</size>").ToString(); } internal static void Reset() { if ((Object)(object)_label != (Object)null) { Object.Destroy((Object)(object)((Component)_label).gameObject); } _label = null; _source = null; _shown = null; } } [HarmonyPatch(typeof(Minimap), "UpdateBiome")] internal static class Minimap_UpdateBiome_Hover { private static void Prefix() { MapHover.Begin(); } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Minimap __instance) { MapHover.Refresh(__instance); } } [HarmonyPatch(typeof(Minimap), "IsExplored")] internal static class Minimap_IsExplored_Hover { private static void Postfix(Vector3 worldPos, bool __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) MapHover.Capture(worldPos, __result); } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] internal sealed class TerritoryError : Exception { internal readonly string Key; internal readonly string[] Args; internal TerritoryError(string key, params string[] args) : base(key) { Key = key; Args = args; } } [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] internal static class TerritoryNet { private const float RequestInterval = 0.25f; private static readonly Dictionary<ZRpc, float> LastRequest = new Dictionary<ZRpc, float>(); private static readonly Dictionary<string, float> LastTerrainChange = new Dictionary<string, float>(StringComparer.Ordinal); internal const float MaxDistance = 8f; private const string CommandRPC = "RD_Territory_Command"; private const string NoticeRPC = "RD_Territory_Notice"; private const string HelloRPC = "RD_Territory_Version"; private static readonly HashSet<ZRpc> Verified = new HashSet<ZRpc>(); internal static bool IsServer => (Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer(); internal static void Request(string id, string key = "", string value = "") { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(id); val.Write(key); val.Write(value); val.SetPos(0); if (IsServer) { ((MonoBehaviour)TerritoryPlugin.Instance).StartCoroutine(HandleNextFrame(val)); return; } ZNet instance = ZNet.instance; if (instance != null) { ZNetPeer serverPeer = instance.GetServerPeer(); if (serverPeer != null) { serverPeer.m_rpc.Invoke("RD_Territory_Command", new object[1] { val }); } } } private static IEnumerator HandleNextFrame(ZPackage pkg) { yield return null; Handle(null, pkg); } private static void Command(ZRpc rpc, ZPackage pkg) { if (IsServer) { if (LastRequest.TryGetValue(rpc, out var value) && Time.realtimeSinceStartup - value < 0.25f) { Reply(rpc, "$territory_err_wait"); return; } LastRequest[rpc] = Time.realtimeSinceStartup; Handle(rpc, pkg); } } private static bool Near(Vector3 position, Land land) { //IL_0000: 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) return Vector3.Distance(position, TerritoryRuntime.TotemPosition(land)) <= 8f; } private static bool Allowed(Land land, string caller, bool admin, string key) { bool flag = land.Owner.Length > 0 && land.Owner == caller; if (1 == 0) { } bool result = ((key == "OwnerID") ? admin : ((!(key == "Terrain")) ? (Schema.OwnerFields.Contains(key) && (admin || flag)) : ((admin || flag) && ((land.On("ForceBiome") && Schema.OwnerBiomes.Length != 0) || land.On("CustomPaint"))))); if (1 == 0) { } return result; } private static void Handle([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] ZRpc rpc, ZPackage pkg) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) try { ZNetPeer val = ((rpc == null) ? null : Peer(rpc)); if (rpc != null && (val == null || !val.IsReady())) { return; } string text = ((rpc == null) ? Identity.Local : Identity.Normalize(rpc.GetSocket().GetHostName())); bool flag = rpc == null || Admin(rpc); Vector3 position = val?.m_refPos ?? Vector3.zero; string id = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); if (id.Length > 64 || text2.Length > 64 || text3.Length > 256) { throw new TerritoryError("$territory_err_invalid"); } Land land = TerritoryState.Get(id) ?? throw new TerritoryError("$territory_err_missing"); if (!land.Enabled) { throw new TerritoryError("$territory_err_disabled"); } if (!flag && !Near(position, land)) { throw new TerritoryError("$territory_err_distance"); } if (text2.Length == 0) { return; } if (!Allowed(land, text, flag, text2)) { throw new TerritoryError("$territory_err_denied"); } List<Land> list = TerritoryFiles.Load(); int num = list.FindIndex((Land t) => t.ID == id); if (num < 0) { throw new TerritoryError("$territory_err_missing"); } land = list[num]; if (!land.Enabled) { throw new TerritoryError("$territory_err_disabled"); } if (!Allowed(land, text, flag, text2)) { throw new TerritoryError("$territory_err_denied"); } if (!flag && !Near(position, land)) { throw new TerritoryError("$territory_err_distance"); } Dictionary<string, string> dictionary = new Dictionary<string, string>(land.KnownNames, StringComparer.Ordinal); if (text2 == "OwnerID") { ChangeOwner(rpc, list, num, text3, dictionary); return; } if (text2 == "Terrain") { ChangeTerrain(rpc, list, num, text3, flag); return; } string key = "$territory_saved"; string[] args = Array.Empty<string>(); if (text2 == "Members") { string[] array = text3.Split(new char[1] { ':' }, 2); if (array.Length != 2 || (array[0] != "add" && array[0] != "remove")) { throw new TerritoryError("$territory_err_invalid"); } string text4 = ParseId(array[1]); if (text4 == land.Owner) { throw new TerritoryError("$territory_err_owner"); } HashSet<string> hashSet = new HashSet<string>(land.Members, StringComparer.Ordinal); if (array[0] == "add") { if (hashSet.Contains(text4)) { throw new TerritoryError("$territory_err_already"); } if ((float)hashSet.Count >= land.Number("MaxMembers")) { throw new TerritoryError("$territory_err_full"); } if (!TerritoryState.Online.TryGetValue(text4, out var value)) { throw new TerritoryError("$territory_err_offline"); } hashSet.Add(text4); dictionary[text4] = value; key = "$territory_member_added"; args = new string[1] { Land.CleanName(value) }; } else { if (!hashSet.Remove(text4)) { throw new TerritoryError("$territory_err_notmember"); } args = new string[1] { TerritoryState.Online.TryGetValue(text4, out var value2) ? Land.CleanName(value2) : (dictionary.TryGetValue(text4, out var value3) ? value3 : text4) }; dictionary.Remove(text4); key = "$territory_member_removed"; } text3 = string.Join(", ", hashSet.OrderBy<string, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string s) => s, StringComparer.Ordinal)); } else if (text2 == "Name") { text3 = text3.Trim(); if (!Land.ValidName(text3)) { throw new TerritoryError("$territory_err_name"); } } else if (text3 != "true" && text3 != "false") { throw new TerritoryError("$territory_err_invalid"); } if (land.Owner.Length > 0 && text == land.Owner && TerritoryState.Online.TryGetValue(text, out var value4)) { dictionary[text] = value4; } Land land2 = land.With(text2, text3).With("KnownNames", Land.FormatNames(dictionary)); TerritoryFiles.Save(land2, text2, "KnownNames"); list[num] = land2; TerritoryState.Apply(list); Broadcast(); Reply(rpc, key, args); } catch (TerritoryError territoryError) { TerritoryPlugin.Log.LogWarning((object)("Territory operation rejected: " + territoryError.Key)); Reply(rpc, territoryError.Key, territoryError.Args); } catch (FormatException ex) { TerritoryPlugin.Log.LogWarning((object)("Territory operation rejected: " + ex.Message)); Reply(rpc, "$territory_err_invalid"); } catch (Exception ex2) { TerritoryPlugin.Log.LogError((object)("Territory operation failed: " + ex2)); Reply(rpc, "$territory_err_save"); } } private static void ChangeOwner([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] ZRpc rpc, List<Land> latest, int index, string value, Dictionary<string, string> names) { Land land = latest[index]; string owner = ""; string[] args = Array.Empty<string>(); string key; if (value.StartsWith("set:", StringComparison.Ordinal)) { owner = ParseId(value.Substring(4)); if (owner == land.Owner) { throw new TerritoryError("$territory_err_owner_same"); } if (!TerritoryState.Online.TryGetValue(owner, out var value2)) { throw new TerritoryError("$territory_err_offline"); } names[owner] = value2; key = "$territory_owner_set"; args = new string[1] { Land.CleanName(value2) }; } else { if (!(value == "clear")) { throw new TerritoryError("$territory_err_invalid"); } if (land.Owner.Length == 0) { throw new TerritoryError("$territory_err_invalid"); } key = "$territory_owner_cleared"; } IOrderedEnumerable<string> values = land.Members.Where([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string m) => m != owner).OrderBy<string, string>([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string s) => s, StringComparer.Ordinal); Land land2 = land.With("OwnerID", owner).With("Members", string.Join(", ", values)).With("KnownNames", Land.FormatNames(names)); TerritoryFiles.Save(land2, "OwnerID", "Members", "KnownNames"); latest[index] = land2; TerritoryState.Apply(latest); Broadcast(); Reply(rpc, key, args); } private unsafe static void ChangeTerrain([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] ZRpc rpc, List<Land> latest, int index, string value, bool admin) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) Land land = latest[index]; string[] array = value.Split(new char[1] { ':' }); if (array.Length != 2 || !Enum.TryParse<Biome>(array[0], out Biome result)) { throw new TerritoryError("$territory_err_invalid"); } string text = array[1]; bool flag = result != land.Biome; bool flag2 = text != land.Values["GroundPaint"]; if (!flag && !flag2) { throw new TerritoryError("$territory_err_invalid"); } if (flag && (!land.On("ForceBiome") || !Schema.OwnerBiomes.Contains(result))) { throw new TerritoryError("$territory_err_denied"); } if (flag2 && (!land.On("CustomPaint") || !Schema.GroundPaints.Contains(text))) { throw new TerritoryError("$territory_err_denied"); } float realtimeSinceStartup = Time.realtimeSinceStartup; float num = Mathf.Max(0f, TerritoryPlugin.OwnerTerrainCooldown.Value) * 60f; if (!admin && LastTerrainChange.TryGetValue(land.ID, out var value2) && realtimeSinceStartup - value2 < num) { int num2 = Mathf.CeilToInt(num - (realtimeSinceStartup - value2)); throw new TerritoryError("$territory_err_cooldown", (num2 / 60).ToString(), (num2 % 60).ToString("00")); } Land land2 = land.With("Biome", ((object)(*(Biome*)(&result))/*cast due to .constrained prefix*/).ToString()).With("GroundPaint", text); TerritoryFiles.Save(land2, "Biome", "GroundPaint"); latest[index] = land2; LastTerrainChange[land.ID] = realtimeSinceStartup; TerritoryState.Apply(latest); Broadcast(); Reply(rpc, TerritoryPlugin.LiveTerrainRefresh.Value ? "$territory_terrain_saved" : "$territory_terrain_saved_reload"); } private static string ParseId(string raw) { string text; try { text = Identity.Normalize(raw); } catch (FormatException) { throw new TerritoryError("$territory_err_invalid"); } if (text.Length == 0) { throw new TerritoryError("$territory_err_invalid"); } return text; } private static void Reply([<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] ZRpc rpc, string key, params string[] args) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown if (rpc == null) { TerritoryMenu.Notice(key, args); return; } ZPackage val = new ZPackage(); val.Write(key); val.Write(args.Length); foreach (string text in args) { val.Write(text); } rpc.Invoke("RD_Territory_Notice", new object[1] { val }); } internal static void Reload() { try { TerritoryState.LocalAdmin = (Object)(object)Player.m_localPlayer != (Object)null; List<Land> lands = TerritoryFiles.Load(); foreach (string item in TerritoryFiles.Skipped) { TerritoryPlugin.Log.LogError((object)item); } if (!(TerritoryState.SignatureOf(lands) == TerritoryState.Signature) || TerritoryState.Lands.Count <= 0) { TerritoryState.Apply(lands); Broadcast(); } } catch (Exception ex) { TerritoryPlugin.Log.LogError((object)("CFG reload rejected; existing territories kept. " + ex.Message)); } } internal static void Register(ZNetPeer peer) { if (IsServer) { peer.m_rpc.Register<ZPackage>("RD_Territory_Command", (Action<ZRpc, ZPackage>)Command); peer.m_rpc.Register<string>("RD_Territory_Version", (Action<ZRpc, string>)([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (ZRpc rpc, [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(1)] string version) => { if (version == "1.0.3") { Verified.Add(rpc); } else { TerritoryPlugin.Log.LogWarning((object)"Peer rejected: Territory 1.0.3 is required."); rpc.Invoke("Error", new object[1] { 3 }); } })); } else { peer.m_rpc.Register<ZPackage>("RD_Territory_Notice", (Action<ZRpc, ZPackage>)ReceiveNotice); peer.m_rpc.Invoke("RD_Territory_Version", new object[1] { "1.0.3" }); } } internal static bool Accept(ZRpc rpc) { if (!IsServer || Verified.Contains(rpc)) { return true; } TerritoryPlugin.Log.LogWarning((object)"Peer rejected: Territory 1.0.3 is missing or mismatched."); rpc.Invoke("Error", new object[1] { 3 }); return false; } internal static void Forget(ZNetPeer peer) { LastRequest.Remove(peer.m_rpc); Verified.Remove(peer.m_rpc); } private static bool Admin(ZRpc rpc) { return ZNet.instance.IsAdmin(rpc.GetSocket().GetHostName()); } [return: <743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] internal static ZNetPeer Peer(ZRpc rpc) { return ((IEnumerable<ZNetPeer>)ZNet.instance.GetPeers()).FirstOrDefault((Func<ZNetPeer, bool>)([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (ZNetPeer p) => p.m_rpc == rpc)); } private static bool FromServer(ZRpc rpc) { return (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer() && ZNet.instance.GetPeers().Any([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (ZNetPeer p) => p.m_rpc == rpc); } internal static void Broadcast() { if (!IsServer) { return; } TerritoryState.Online.Clear(); TerritoryState.Admins.Clear(); foreach (ZNetPeer item in from p in ZNet.instance.GetPeers() where p.IsReady() select p) { string text = Identity.Normalize(item.m_socket.GetHostName()); TerritoryState.Online[text] = item.m_playerName; if (Admin(item.m_rpc)) { TerritoryState.Admins.Add(text); } } if ((Object)(object)Player.m_localPlayer != (Object)null) { TerritoryState.Online[Identity.Local] = Player.m_localPlayer.GetPlayerName(); TerritoryState.Admins.Add(Identity.Local); } RememberNames(); Publish(); TerritoryMenu.Refresh(); } private static void Publish() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (TerritoryPlugin.StateSync == null) { return; } ZPackage val = new ZPackage(); val.Write("1.0.3"); val.Write(TerritoryState.Lands.Count); foreach (Land land in TerritoryState.Lands) { land.Write(val); } val.Write(TerritoryState.Online.Count); foreach (KeyValuePair<string, string> item in TerritoryState.Online) { val.Write(item.Key); val.Write(item.Value); val.Write(TerritoryState.Admins.Contains(item.Key)); } TerritoryPlugin.StateSync.AssignLocalValue(Convert.ToBase64String(val.GetArray())); } private static void RememberNames() { string value2; string value3; List<string> list = (from land in TerritoryState.Lands where new string[1] { land.Owner }.Concat(land.Members).Any([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (string id) => id.Length > 0 && TerritoryState.Online.TryGetValue(id, out value2) && Land.CleanName(value2).Length > 0 && (!land.KnownNames.TryGetValue(id, out value3) || value3 != Land.CleanName(value2))) select land.ID).ToList(); if (list.Count == 0) { return; } try { List<Land> list2 = TerritoryFiles.Load(); bool flag = false; for (int num = 0; num < list2.Count; num++) { if (!list.Contains(list2[num].ID)) { continue; } Dictionary<string, string> dictionary = new Dictionary<string, string>(list2[num].KnownNames, StringComparer.Ordinal); foreach (string item in new string[1] { list2[num].Owner }.Concat(list2[num].Members)) { if (item.Length > 0 && TerritoryState.Online.TryGetValue(item, out var value) && Land.CleanName(value).Length > 0) { dictionary[item] = Land.CleanName(value); } } string text = Land.FormatNames(dictionary); if (!(text == list2[num].Values["KnownNames"])) { list2[num] = list2[num].With("KnownNames", text); TerritoryFiles.Save(list2[num], "KnownNames"); flag = true; } } if (flag) { TerritoryState.Apply(list2); } } catch (Exception ex) { TerritoryPlugin.Log.LogWarning((object)("Territory player names not recorded: " + ex.Message)); } } internal static void OnStateSynced() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown string text = TerritoryPlugin.StateSync?.Value ?? ""; if (IsServer || text.Length == 0) { return; } try { ZPackage val = new ZPackage(Convert.FromBase64String(text)); if (val.ReadString() != "1.0.3") { throw new FormatException("Server/client Territory versions differ."); } int num = val.ReadInt(); if (num < 0 || num > 512) { throw new FormatException("Invalid territory count."); } List<Land> list = new List<Land>(); for (int i = 0; i < num; i++) { list.Add(Land.Read(val)); } if (list.Select([<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (Land l) => l.ID).Distinct<string>(StringComparer.Ordinal).Count() != list.Count) { throw new FormatException("Duplicate territory ID."); } num = val.ReadInt(); if (num < 0 || num > 512) { throw new FormatException("Invalid player count."); } Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.Ordinal); HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal); for (int num2 = 0; num2 < num; num2++) { string text2 = Identity.Normalize(val.ReadString()); string value = val.ReadString(); dictionary[text2] = value; if (val.ReadBool()) { hashSet.Add(text2); } } TerritoryState.Online.Clear(); foreach (KeyValuePair<string, string> item in dictionary) { TerritoryState.Online.Add(item.Key, item.Value); } TerritoryState.Admins.Clear(); foreach (string item2 in hashSet) { TerritoryState.Admins.Add(item2); } TerritoryState.LocalAdmin = Identity.Local.Length > 0 && hashSet.Contains(Identity.Local); if (!TerritoryState.Synced) { TerritoryPlugin.Log.LogInfo((object)("Territory state received: " + list.Count + " territories.")); } TerritoryState.Synced = true; TerritoryState.Apply(list); } catch (Exception ex) { TerritoryPlugin.Log.LogError((object)("Server territory snapshot rejected: " + ex.Message)); TerritoryMenu.Notice("$territory_err_sync"); } } private static void ReceiveNotice(ZRpc rpc, ZPackage pkg) { if (!FromServer(rpc)) { return; } try { string text = pkg.ReadString(); int num = pkg.ReadInt(); if (text.StartsWith("$territory_", StringComparison.Ordinal) && text.Length <= 64 && num >= 0 && num <= 4) { string[] array = new string[num]; for (int i = 0; i < num; i++) { array[i] = Land.CleanName(pkg.ReadString()); } TerritoryMenu.Notice(text, array); } } catch (Exception ex) { TerritoryPlugin.Log.LogWarning((object)("Territory notice rejected: " + ex.Message)); } } internal static void Reset() { LastRequest.Clear(); LastTerrainChange.Clear(); Verified.Clear(); SupportCache.Clear(); TerritoryState.Reset(); } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class ZNet_Awake_Server { private static void Postfix() { if (TerritoryNet.IsServer) { TerritoryPlugin.Instance.Watch(); TerritoryNet.Reload(); } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] internal static class ZNet_OnNewConnection_Register { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(ZNetPeer peer) { TerritoryNet.Register(peer); } } [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] internal static class ZNet_RPC_PeerInfo_Verify { private static bool Prefix(ZRpc rpc) { return TerritoryNet.Accept(rpc); } private static void Postfix(ZRpc rpc) { if (TerritoryNet.IsServer) { ZNetPeer obj = TerritoryNet.Peer(rpc); if (obj != null && obj.IsReady()) { TerritoryNet.Broadcast(); } } } } [HarmonyPatch(typeof(ZNet), "Disconnect", new Type[] { typeof(ZNetPeer) })] internal static class ZNet_Disconnect_Forget { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Prefix(ZNetPeer peer) { TerritoryNet.Forget(peer); } private static void Postfix() { if (TerritoryNet.IsServer) { TerritoryNet.Broadcast(); } } } [HarmonyPatch(typeof(ZNet), "Shutdown")] internal static class ZNet_Shutdown_Reset { private static void Prefix() { TerritoryPlugin.Instance.Unwatch(); TerritoryRuntime.Reset(); TerritoryMenu.Close(); TerritoryNet.Reset(); } } [BepInDependency(/*Could not decode attribute arguments.*/)] [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(0)] [BepInPlugin("radamanto.Territory", "Territory", "1.0.3")] public sealed class TerritoryPlugin : BaseUnityPlugin { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] private sealed class ConfigurationManagerAttributes { public bool? Browsable = false; } private const float ConfigReloadQuietSeconds = 0.75f; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] internal static ConfigSync ConfigSync; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(new byte[] { 2, 1 })] internal static CustomSyncedValue<string> StateSync; internal static ConfigEntry<bool> ShowOnMap; internal static ConfigEntry<bool> ShowMapInfo; internal static ConfigEntry<bool> LiveTerrainRefresh; internal static ConfigEntry<bool> BypassBiomeLock; internal static ConfigEntry<float> MaxTerritorySize; internal static ConfigEntry<float> OwnerTerrainCooldown; internal static ConfigEntry<string> OwnerBiomes; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] private static ConfigEntry<bool> _serverConfigLocked; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] private FileSystemWatcher _configWatcher; private DateTime _lastCfgWriteUtc = DateTime.MinValue; private DateTime _ignoreEventsUntilUtc = DateTime.MinValue; private bool _reloadScheduled; public const string GUID = "radamanto.Territory"; public const string Version = "1.0.3"; internal static TerritoryPlugin Instance; internal static ManualLogSource Log; private Harmony _harmony = null; [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] private FileSystemWatcher _watcher; private long _changedTicks; private void SetupConfig() { //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; bool flag = false; try { ConfigSync = new ConfigSync(((BaseUnityPlugin)this).Info.Metadata.GUID) { DisplayName = ((BaseUnityPlugin)this).Info.Metadata.Name, CurrentVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString(), MinimumRequiredVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString(), ModRequired = true }; _serverConfigLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("01 - General", "LockConfiguration", true, new ConfigDescription("If true, the server locks synchronized configs.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = false } })); ConfigSync.AddLockingConfigEntry<bool>(_serverConfigLocked); StateSync = new CustomSyncedValue<string>(ConfigSync, "Territories", ""); StateSync.ValueChanged += TerritoryNet.OnStateSynced; flag = true; } catch (Exception ex) { Log.LogError((object)("[ConfigSync] " + ex)); } ShowOnMap = Cfg("01 - General", "ShowOnMap", defaultValue: true, "Paint territory areas on the map and minimap."); ShowOnMap.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { TerritoryMap.Paint(); }; ShowMapInfo = Cfg("01 - General", "ShowMapInfo", defaultValue: true, "Show territory name, owner and access when hovering it on the large map."); MaxTerritorySize = Cfg("01 - General", "MaxTerritorySize", 500f, "Largest allowed side in meters of the area a territory affects: Size plus twice the larger of ProtectionBorderWidth and GroundSlopeWidth. Territories above it are ignored with an error in the server log."); TerritoryFiles.MaxTerritorySize = Mathf.Max(1f, MaxTerritorySize.Value); MaxTerritorySize.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { TerritoryFiles.MaxTerritorySize = Mathf.Max(1f, MaxTerritorySize.Value); if (TerritoryNet.IsServer) { TerritoryNet.Reload(); } }; LiveTerrainRefresh = Cfg("01 - General", "LiveTerrainRefresh", defaultValue: false, "Rebuild the terrain of a territory right away when its terrain changes, both from the totem menu and from editing the territory CFG, for owners and administrators alike. When false, terrain changes only appear after leaving the area and coming back."); LiveTerrainRefresh.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { TerritoryMenu.Refresh(force: true); }; OwnerBiomes = Cfg("01 - General", "OwnerBiomes", string.Join(", ", Schema.DefaultOwnerBiomes), "Biomes the territory owner can choose at the totem, separated by commas, in menu order. Valid names: Meadows, BlackForest, Swamp, Mountain, Plains, Mistlands, DeepNorth. Empty hides the biome choice. Only offered when ForceBiome is enabled in the territory CFG. Follows LiveTerrainRefresh."); ApplyOwnerBiomes(); OwnerBiomes.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { ApplyOwnerBiomes(); TerritoryMenu.Refresh(force: true); }; OwnerTerrainCooldown = Cfg("01 - General", "OwnerTerrainCooldown", 5f, "Minutes the territory owner must wait between biome or ground changes made at the totem. Administrators are not limited."); BypassBiomeLock = Cfg("01 - General", "BiomeLockBypass", defaultValue: false, "Requires BiomeLock 1.2.1 or newer. When true, BiomeLock restrictions are lifted inside any territory. When false, BiomeLock applies inside territories as anywhere else, and the owner cannot choose at the totem a biome that BiomeLock has not unlocked for them yet. Administrators are not limited."); BypassBiomeLock.SettingChanged += [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(0)] (object _, EventArgs _) => { TerritoryMenu.Refresh(force: true); }; if (flag) { ((BaseUnityPlugin)this).Config.Save(); } ((BaseUnityPlugin)this).Config.SaveOnConfigSet = true; if (flag) { SetupConfigWatcher(); } } private static void ApplyOwnerBiomes() { Schema.OwnerBiomes = Schema.ParseOwnerBiomes(OwnerBiomes.Value, out var invalid); if (invalid.Count > 0) { Log.LogWarning((object)("OwnerBiomes ignores unknown or unavailable biomes: " + string.Join(", ", invalid))); } } private ConfigEntry<T> Cfg<[<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] T>(string section, string key, T defaultValue, string description, bool synced = true) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, new ConfigDescription(description + (synced ? " [Synced with Server]" : " [Not Synced with Server]"), (AcceptableValueBase)null, Array.Empty<object>())); SyncedConfigEntry<T> syncedConfigEntry = ConfigSync?.AddConfigEntry<T>(val); if (syncedConfigEntry != null) { syncedConfigEntry.SynchronizedConfig = synced; } return val; } private void SetupConfigWatcher() { DisposeConfigWatcher(); try { _configWatcher = new FileSystemWatcher(Paths.ConfigPath, Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath)) { IncludeSubdirectories = false, NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime), SynchronizingObject = ThreadingHelper.SynchronizingObject }; _configWatcher.Changed += OnConfigFileChanged; _configWatcher.Created += OnConfigFileChanged; _configWatcher.Renamed += OnConfigFileChanged; _configWatcher.EnableRaisingEvents = true; } catch (Exception ex) { Log.LogError((object)("[ConfigWatcher] " + ex)); _configWatcher = null; } } private void DisposeConfigWatcher() { if (_configWatcher != null) { _configWatcher.EnableRaisingEvents = false; _configWatcher.Dispose(); _configWatcher = null; } _reloadScheduled = false; } private void OnConfigFileChanged(object sender, FileSystemEventArgs e) { if (!(DateTime.UtcNow < _ignoreEventsUntilUtc)) { _lastCfgWriteUtc = DateTime.UtcNow; if (!_reloadScheduled) { _reloadScheduled = true; ((MonoBehaviour)this).StartCoroutine(ReloadConfigAfterQuietPeriod()); } } } private IEnumerator ReloadConfigAfterQuietPeriod() { while ((DateTime.UtcNow - _lastCfgWriteUtc).TotalSeconds < 0.75) { yield return null; } _reloadScheduled = false; FileSystemWatcher watcher = _configWatcher; if (watcher == null) { yield break; } watcher.EnableRaisingEvents = false; try { ((BaseUnityPlugin)this).Config.Reload(); _ignoreEventsUntilUtc = DateTime.UtcNow.AddSeconds(1.0); } catch (Exception ex) { Log.LogError((object)("[ConfigReload] " + ex)); } finally { if (_configWatcher == watcher) { watcher.EnableRaisingEvents = true; } } } private void Awake() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; Localizer.Load(); SetupConfig(); _harmony = new Harmony("radamanto.Territory"); _harmony.PatchAll(typeof(TerritoryPlugin).Assembly); Log.LogInfo((object)"Territory 1.0.3 loaded."); } internal void Watch() { if (_watcher != null) { return; } try { Directory.CreateDirectory(TerritoryFiles.Folder); _watcher = new FileSystemWatcher(TerritoryFiles.Folder, "*.cfg") { NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite) }; _watcher.Changed += FileChanged; _watcher.Created += FileChanged; _watcher.Deleted += FileChanged; _watcher.Renamed += FileChanged; _watcher.EnableRaisingEvents = true; ((MonoBehaviour)this).InvokeRepeating("DispatchChanges", 0.5f, 0.5f); Log.LogInfo((object)("Territory CFG directory: " + TerritoryFiles.Folder)); } catch (Exception ex) { _watcher?.Dispose(); _watcher = null; Log.LogError((object)("Territory CFG folder cannot be watched: " + ex.Message)); } } internal void Unwatch() { ((MonoBehaviour)this).CancelInvoke("DispatchChanges"); _watcher?.Dispose(); _watcher = null; Interlocked.Exchange(ref _changedTicks, 0L); } private void FileChanged(object sender, FileSystemEventArgs args) { Interlocked.Exchange(ref _changedTicks, DateTime.UtcNow.Ticks); } private void DispatchChanges() { long num = Interlocked.Read(in _changedTicks); if (num != 0L && DateTime.UtcNow.Ticks - num >= 10000000 && Interlocked.CompareExchange(ref _changedTicks, 0L, num) == num && TerritoryNet.IsServer) { TerritoryNet.Reload(); } } private void OnDestroy() { DisposeConfigWatcher(); Unwatch(); TerritoryRuntime.Reset(); BiomeLockBypass.Unlink(); TerritoryMenu.Close(); TerritoryMenu.DisposeInput(); TerritoryNet.Reset(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } [HarmonyPatch(typeof(Player), "TryPlacePiece")] internal static class Player_TryPlacePiece_NoBuild { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Player __instance, GameObject ___m_placementGhost, ref bool __result) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)___m_placementGhost == (Object)null || !Rules.Blocked(___m_placementGhost.transform.position, "NoBuild", (Character)(object)__instance)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(WearNTear), "Remove")] internal static class WearNTear_Remove_NoBuild { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(WearNTear __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return !Rules.Blocked(((Component)__instance).transform.position, "NoBuild", (Character)(object)Player.m_localPlayer); } } [HarmonyPatch(typeof(WearNTear), "Damage")] internal static class WearNTear_Damage_NoBuildDamage { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(WearNTear __instance) { return !Rules.Flag((Component)(object)__instance, "NoBuildDamage"); } } [HarmonyPatch(typeof(WearNTear), "ApplyDamage")] internal static class WearNTear_ApplyDamage_NoBuildDamage { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(WearNTear __instance, ref bool __result) { if (!Rules.Flag((Component)(object)__instance, "NoBuildDamage")) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(WearNTear), "HaveSupport")] internal static class WearNTear_HaveSupport_NoStructureSupport { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(WearNTear __instance, ref bool __result) { if (!__result && TerritoryState.Has("NoStructureSupport") && SupportCache.Get(__instance)) { __result = true; } } } [HarmonyPatch(typeof(WearNTear), "OnDestroy")] internal static class WearNTear_OnDestroy_SupportCache { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(WearNTear __instance) { SupportCache.Remove(__instance); } } [HarmonyPatch(typeof(Attack), "SpawnOnHitTerrain")] internal static class Attack_SpawnOnHitTerrain_NoPickaxe { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Vector3 hitPoint, Character character, ref GameObject __result) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (!Rules.Blocked(hitPoint, "NoPickaxe", (character is Player) ? character : null)) { return true; } __result = null; return false; } } [HarmonyPatch(typeof(MineRock), "Damage")] internal static class MineRock_Damage_NoPickaxe { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(MineRock __instance, HitData hit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return !Rules.Blocked(((Component)__instance).transform.position, "NoPickaxe", hit.GetAttacker()); } } [HarmonyPatch(typeof(MineRock5), "Damage")] internal static class MineRock5_Damage_NoPickaxe { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(MineRock5 __instance, HitData hit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return !Rules.Blocked(((Component)__instance).transform.position, "NoPickaxe", hit.GetAttacker()); } } internal static class OpenContainer { [<743ecad6-8c5d-431d-9706-069cf944ea12>Nullable(2)] internal static Container Current; internal static void HideIfBlocked() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)Current == (Object)null) && !((Object)(object)InventoryGui.instance == (Object)null)) { Vector3 position = ((Component)Current).transform.position; if (Rules.Blocked(position, "NoInteractChests", (Character)(object)localPlayer, notify: false) || Rules.Blocked(position, "NoInteract", (Character)(object)localPlayer, notify: false)) { InventoryGui.instance.Hide(); } } } } [HarmonyPatch(typeof(Container), "Interact")] internal static class Container_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Container __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractChests", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(InventoryGui), "Show")] internal static class InventoryGui_Show_Track { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Container ___m_currentContainer) { OpenContainer.Current = ___m_currentContainer; } } [HarmonyPatch(typeof(InventoryGui), "Hide")] internal static class InventoryGui_Hide_Track { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Container ___m_currentContainer) { OpenContainer.Current = ___m_currentContainer; } } [HarmonyPatch(typeof(InventoryGui), "CloseContainer")] internal static class InventoryGui_CloseContainer_Track { private static void Postfix() { OpenContainer.Current = null; } } [HarmonyPatch(typeof(Player), "Interact")] internal static class Player_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Player __instance, GameObject go) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)go == (Object)null || (Object)(object)go.GetComponentInParent<TerritoryTotem>() != (Object)null) { return true; } return !Rules.Blocked(go.transform.position, "NoInteract", (Character)(object)__instance); } } [HarmonyPatch(typeof(ItemDrop), "Interact")] internal static class ItemDrop_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(ItemDrop __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractItems", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(CraftingStation), "Interact")] internal static class CraftingStation_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(CraftingStation __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractCraftingStation", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(ItemStand), "Interact")] internal static class ItemStand_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(ItemStand __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractItemStands", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(ItemStand), "UseItem")] internal static class ItemStand_UseItem_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(ItemStand __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractItemStands", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(ArmorStand), "UseItem")] internal static class ArmorStand_UseItem_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(ArmorStand __instance, Humanoid user, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractItemStands", user)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Door), "Interact")] internal static class Door_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Door __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractDoors", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(TeleportWorld), "Interact")] internal static class TeleportWorld_Interact_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(TeleportWorld __instance, Humanoid __0, ref bool __result) { if (Rules.Interaction((Component)(object)__instance, "NoInteractPortals", __0)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Humanoid), "Pickup")] internal static class Humanoid_Pickup_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Humanoid __instance, GameObject go, ref bool __result) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null || (Object)(object)go == (Object)null || (!Rules.Blocked(go.transform.position, "NoInteractItems", (Character)(object)val) && !Rules.Blocked(go.transform.position, "NoInteract", (Character)(object)val))) { return true; } __result = false; return false; } } internal static class AutoPickup { internal static bool Active; } [HarmonyPatch(typeof(Player), "AutoPickup")] internal static class Player_AutoPickup_Scope { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Prefix(Player __instance) { AutoPickup.Active = (Object)(object)__instance == (Object)(object)Player.m_localPlayer; } private static void Finalizer() { AutoPickup.Active = false; } } [HarmonyPatch(typeof(ItemDrop), "CanPickup")] internal static class ItemDrop_CanPickup_NoInteract { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(ItemDrop __instance, ref bool __result) { //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_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) if (__result && AutoPickup.Active) { Player localPlayer = Player.m_localPlayer; Vector3 position = ((Component)__instance).transform.position; if (Rules.Blocked(position, "NoInteractItems", (Character)(object)localPlayer, notify: false) || Rules.Blocked(position, "NoInteract", (Character)(object)localPlayer, notify: false)) { __result = false; } } } } internal static class NoAccess { private const float Cooldown = 2f; private const float Lifetime = 2f; private static float _last = -10f; private static bool _material; internal static void Show(Vector3 position) { //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown //IL_0101: 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_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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) if (Time.time - _last < 2f) { return; } _last = Time.time; GameObject noAccessEffect = TerritoryRuntime.NoAccessEffect; if ((Object)(object)noAccessEffect != (Object)null) { if (!_material) { ZNetScene instance = ZNetScene.instance; object obj; if (instance == null) { obj = null; } else { GameObject prefab = instance.GetPrefab("vfx_lootspawn"); obj = ((prefab != null) ? prefab.GetComponent<ParticleSystemRenderer>() : null); } ParticleSystemRenderer val = (ParticleSystemRenderer)obj; ParticleSystemRenderer component = noAccessEffect.GetComponent<ParticleSystemRenderer>(); if ((Object)(object)val != (Object)null && (Object)(object)component != (Object)null) { ((Renderer)component).sharedMaterial = ((Renderer)val).sharedMaterial; _material = true; } } Object.Instantiate<GameObject>(noAccessEffect, position, Quaternion.identity); } MessageHud instance2 = MessageHud.instance; object obj2; if (instance2 == null) { obj2 = null; } else { TMP_Text messageText = instance2.m_messageText; obj2 = ((messageText != null) ? messageText.font : null); } TMP_FontAsset val2 = (TMP_FontAsset)obj2; if (!((Object)(object)val2 == (Object)null)) { GameObject val3 = new GameObject("Territory No Access"); val3.SetActive(false); val3.transform.position = position + Vector3.up * 1.5f; TextMeshPro val4 = val3.AddComponent<TextMeshPro>(); ((TMP_Text)val4).font = val2; ((TMP_Text)val4).fontSize = 4f; ((TMP_Text)val4).richText = false; ((TMP_Text)val4).alignment = (TextAlignmentOptions)514; ((TMP_Text)val4).textWrappingMode = (TextWrappingModes)0; ((Graphic)val4).color = TerritoryText.Red; ((TMP_Text)val4).text = TerritoryText.L("$territory_no_access"); ((TMP_Text)val4).rectTransform.sizeDelta = new Vector2(8f, 1.5f); Billboard val5 = val3.AddComponent<Billboard>(); val5.m_vertical = true; val5.m_invert = true; TimedDestruction val6 = val3.AddComponent<TimedDestruction>(); val6.m_timeout = 2f; val3.SetActive(true); val6.Trigger(); } } } [HarmonyPatch(typeof(Attack), "Start")] internal static class Attack_Start_NoAttack { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Humanoid character, ref bool __result) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) Player val = (Player)(object)((character is Player) ? character : null); if (val == null || !Rules.Blocked(((Component)val).transform.position, "NoAttack", (Character)(object)val)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Character), "Damage")] internal static class Character_Damage_NoAttack { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Character __instance, HitData hit) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return !Rules.Blocked(((Component)__instance).transform.position, "NoAttack", hit.GetAttacker(), notify: false); } } [HarmonyPatch(typeof(Player), "TeleportTo")] internal static class Player_TeleportTo_NoPortals { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefix(Player __instance, Vector3 pos, ref bool __result) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (!Rules.Blocked(((Component)__instance).transform.position, "NoPortals", (Character)(object)__instance) && !Rules.Blocked(pos, "NoPortals", (Character)(object)__instance) && !Rules.Blocked(pos, "PushAway", (Character)(object)__instance)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Player), "GetRunSpeedFactor")] internal static class Player_GetRunSpeedFactor_Speed { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Player __instance, ref float __result) { __result *= Rules.SpeedFactor(__instance); } } [HarmonyPatch(typeof(Player), "GetJogSpeedFactor")] internal static class Player_GetJogSpeedFactor_Speed { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static void Postfix(Player __instance, ref float __result) { __result *= Rules.SpeedFactor(__instance); } } [HarmonyPatch(typeof(Player), "UseStamina")] internal static class Player_UseStamina_InfiniteStamina { [<5f485384-64fb-47ad-b11a-1c4b0fe445fd>NullableContext(1)] private static bool Prefi