Decompiled source of MoreTerrainTypes v1.0.2
plugins/MoreTerrainTypes/TerrainHoe.dll
Decompiled 5 hours 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.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using JetBrains.Annotations; using LocalizationManager; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; 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: AssemblyFileVersion("1.0.1")] [assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")] [assembly: ComVisible(false)] [assembly: AssemblyTrademark("")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyProduct("TerrainHoe")] [assembly: AssemblyCompany("RustyMods")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyDescription("")] [assembly: AssemblyTitle("TerrainHoe")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<a485bfb1-f3d8-4b65-8027-34691fd28cac>Embedded] internal sealed class <a485bfb1-f3d8-4b65-8027-34691fd28cac>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<a485bfb1-f3d8-4b65-8027-34691fd28cac>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } } namespace LocalizationManager { [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; 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((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t))); } return _plugin; } } 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, (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value())); } localization.AddWord(key, text); } public static void AddPlaceholder<[<b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>Nullable(1)] T>(string key, string placeholder, ConfigEntry<T> config, 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 += delegate { 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() { LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage()); } 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 text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[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[] array = LoadTranslationFromAssembly("English"); if (array == 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."); } Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array)); 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.ContainsKey(language)) { text2 = File.ReadAllText(dictionary[language]); } else { byte[] array2 = LoadTranslationFromAssembly(language); if (array2 != null) { text2 = Encoding.UTF8.GetString(array2); } } } if (text2 == null && dictionary.ContainsKey("English")) { text2 = File.ReadAllText(dictionary["English"]); } if (text2 != null) { 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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> { ".json", ".yml" }; Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager"); val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static byte[] LoadTranslationFromAssembly(string language) { foreach (string fileExtension in fileExtensions) { byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension); if (array != null) { return array; } } return null; } public static byte[] ReadEmbeddedFileBytes(string resourceFileName, Assembly containingAssembly = null) { using MemoryStream memoryStream = new MemoryStream(); if ((object)containingAssembly == null) { containingAssembly = Assembly.GetCallingAssembly(); } string text = containingAssembly.GetManifestResourceNames().FirstOrDefault((string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal)); if (text != null) { containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream); } return (memoryStream.Length == 0L) ? null : memoryStream.ToArray(); } } } namespace TerrainHoe { [PublicAPI] public static class API { public static Biome GetBiome(Vector3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: 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) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) if (!TerrainColors.TryFindTerrainColors(position, out var instance) || !instance.m_initialized) { return WorldGenerator.instance.GetBiome(position); } return instance.GetBiome(instance.m_terrainComp.m_hmap, position); } public static Biome GetHeightmapBiome(Heightmap hmap, Vector3 position) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0036: Unknown result type (might be due to invalid IL or missing references) if (!TerrainColors.TryFindTerrainColors(position, out var instance) || !instance.m_initialized) { return hmap.GetBiome(position, 0.02f, false); } return instance.GetBiome(hmap, position); } } public static class TerrainHoe_API { private const string Namespace = "TerrainHoe"; private const string ClassName = "API"; private const string Assembly = "TerrainHoe"; private const string TypeNameAssembly = "TerrainHoe.API, TerrainHoe"; private static readonly bool isLoaded; private static readonly MethodInfo API_GetBiome; private static readonly MethodInfo API_GetHeightmapBiome; public static bool IsLoaded() { return isLoaded; } static TerrainHoe_API() { isLoaded = false; Type type = Type.GetType("TerrainHoe.API, TerrainHoe"); if (!(type == null)) { isLoaded = true; API_GetBiome = type.GetMethod("GetBiome", BindingFlags.Static | BindingFlags.Public); API_GetHeightmapBiome = type.GetMethod("GetHeightmapBiome", BindingFlags.Static | BindingFlags.Public); } } public static Biome GetBiome(Vector3 position) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) return (Biome)(API_GetBiome.Invoke(null, new object[1] { position }) ?? ((object)(Biome)0)); } public static Biome GetBiome(Heightmap heightmap, Vector3 position) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) return (Biome)(API_GetHeightmapBiome.Invoke(null, new object[2] { heightmap, position }) ?? ((object)heightmap.GetBiome(position, 0.02f, false))); } } public static class SpriteManager { private static readonly MethodInfo LoadImage; private static readonly Dictionary<string, Sprite> sprites; static SpriteManager() { LoadImage = AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }, (Type[])null); sprites = new Dictionary<string, Sprite>(); } public static Sprite GetSprite(string fileName, string folderName = "icons") { //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) if (sprites.TryGetValue(fileName, out var value)) { return value; } Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = "TerrainHoe." + folderName + "." + fileName; using Stream stream = executingAssembly.GetManifestResourceStream(name); if (stream == null) { return null; } byte[] array = new byte[stream.Length]; stream.Read(array, 0, array.Length); Texture2D val = new Texture2D(2, 2); value = (val.LoadImage4x(array) ? Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero) : null); if ((Object)(object)value != (Object)null) { ((Object)value).name = fileName; sprites.Add(fileName, value); return value; } throw new Exception("Invalid sprite file: " + fileName); } public static bool LoadImage4x(this Texture2D tex, byte[] data) { return (bool)LoadImage.Invoke(null, new object[2] { tex, data }); } } public enum Toggle { On = 1, Off = 0 } public static class ConfigManager { private const string ConfigFileName = "RustyMods.TerrainHoe.cfg"; private static readonly string ConfigFileFullPath; public static readonly ConfigSync ConfigSync; private static readonly ISerializer serializer; private static readonly IDeserializer deserializer; public static readonly string ConfigFolderPath; public static object configManager; private static ConfigEntry<Toggle> _serverConfigLocked; static ConfigManager() { _serverConfigLocked = null; string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + "RustyMods.TerrainHoe.cfg"; ConfigSync = new ConfigSync("RustyMods.TerrainHoe") { DisplayName = "TerrainHoe", CurrentVersion = "1.0.1", MinimumRequiredVersion = "1.0.1" }; serializer = new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull | DefaultValuesHandling.OmitDefaults | DefaultValuesHandling.OmitEmptyCollections).DisableAliases().Build(); deserializer = new DeserializerBuilder().IgnoreUnmatchedProperties().Build(); ConfigFolderPath = Path.Combine(Paths.ConfigPath, "TerrainHoe"); } public static void Start() { _serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only."); ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked); SetupWatcher(); } public static T Deserialize<T>(string data) { return deserializer.Deserialize<T>(data); } public static string Serialize<T>(T obj) { if (obj == null) { return ""; } using StringWriter stringWriter = new StringWriter(); serializer.Serialize(stringWriter, obj, obj.GetType()); return stringWriter.ToString(); } public static void OnFejdStartup() { Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager"); configManager = ((type == null) ? null : Chainloader.ManagerObject.GetComponent(type)); } public static string GetFolderPath() { if (!Directory.Exists(ConfigFolderPath)) { Directory.CreateDirectory(ConfigFolderPath); } return ConfigFolderPath; } private static void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, "RustyMods.TerrainHoe.cfg"); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private static void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { TerrainHoe.LogDebug("ReadConfigValues called"); ((BaseUnityPlugin)TerrainHoe.instance).Config.Reload(); } catch { TerrainHoe.LogError("There was an issue loading your RustyMods.TerrainHoe.cfg"); TerrainHoe.LogError("Please check your config entries for spelling and format!"); } } public static ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Expected O, but got Unknown ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags); ConfigEntry<T> val2 = ((BaseUnityPlugin)TerrainHoe.instance).Config.Bind<T>(group, name, value, val); SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2); syncedConfigEntry.SynchronizedConfig = synchronizedSetting; return val2; } public static ConfigEntry<T> config<T>(string group, string name, T value, string description, bool synchronizedSetting = true) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting); } } public class ConfigurationManagerAttributes { [UsedImplicitly] public int? Order; [UsedImplicitly] public bool? Browsable; [<b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>Nullable(2)] [UsedImplicitly] public string Category; [<b7eb70a3-841b-4bfd-8edd-ac8a17ae44ae>Nullable(new byte[] { 2, 1 })] [UsedImplicitly] public Action<ConfigEntryBase> CustomDrawer; } [Serializable] public struct Requirement { public string itemName; public int amount; public bool recover; public Requirement() { itemName = ""; amount = 1; recover = false; } public Requirement(string itemName, int amount = 1, bool recover = true) { this.itemName = itemName; this.amount = amount; this.recover = recover; } } public class PieceRequirements { public readonly List<Requirement> Requirements; public static readonly ConfigurationManagerAttributes attributes = new ConfigurationManagerAttributes { CustomDrawer = DrawConfigTable }; public PieceRequirements(List<Requirement> reqs) { Requirements = reqs; } public PieceRequirements(params Requirement[] reqs) { Requirements = reqs.ToList(); } public PieceRequirements(Requirement[] reqs) { Requirements = new List<Requirement>(); foreach (Requirement val in reqs) { Requirements.Add(new Requirement { itemName = ((Object)val.m_resItem).name, amount = val.m_amount, recover = val.m_recover }); } } public PieceRequirements(string reqs) { Requirements = reqs.Split(new char[1] { ';' }).Select(delegate(string r) { string[] parts = r.Split(new char[1] { ',' }); return new Requirement { itemName = parts.GetString(0), amount = parts.GetInt(1, 1), recover = parts.GetBool(2, defaultValue: true) }; }).ToList(); } public Requirement[] ToPieceRequirement(string requester = "") { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown Dictionary<string, Requirement> dictionary = new Dictionary<string, Requirement>(); for (int i = 0; i < Requirements.Count; i++) { Requirement requirement = Requirements[i]; if (!string.IsNullOrEmpty(requirement.itemName)) { ItemDrop itemDrop = requirement.itemName.GetItemDrop(requester); if (!((Object)(object)itemDrop == (Object)null)) { dictionary[requirement.itemName] = new Requirement { m_amount = requirement.amount, m_recover = requirement.recover, m_resItem = itemDrop }; } } } return dictionary.Values.ToArray(); } public override string ToString() { return string.Join(";", Requirements.Select((Requirement r) => $"{r.itemName},{r.amount},{r.recover}")); } public string ToCustomString() { return string.Join(";", Requirements.Select((Requirement r) => $"{r.itemName},{r.amount}")); } private static void DrawConfigTable(ConfigEntryBase cfg) { //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Expected O, but got Unknown //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Expected O, but got Unknown //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Expected O, but got Unknown bool valueOrDefault = cfg.Description.Tags.Select((object a) => (a.GetType().Name == "ConfigurationManagerAttributes") ? ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a)) : null).FirstOrDefault((bool? v) => v.HasValue).GetValueOrDefault(); List<Requirement> requirements = new PieceRequirements((string)cfg.BoxedValue).Requirements; List<Requirement> list = new List<Requirement>(); bool flag = false; GUILayout.BeginVertical(Array.Empty<GUILayoutOption>()); foreach (Requirement item in requirements) { GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>()); int num = item.amount; if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField) { fixedWidth = 40f }, Array.Empty<GUILayoutOption>()), out var result) && result != num && !valueOrDefault) { num = result; flag = true; } string text = GUILayout.TextField(item.itemName, new GUIStyle(GUI.skin.textField), Array.Empty<GUILayoutOption>()); string text2 = (valueOrDefault ? item.itemName : text); flag = flag || text2 != item.itemName; bool flag2 = item.recover; if (GUILayout.Toggle(item.recover, "Recover", new GUIStyle(GUI.skin.toggle) { fixedWidth = 67f }, Array.Empty<GUILayoutOption>()) != item.recover) { flag2 = !flag2; flag = true; } if (GUILayout.Button("x", new GUIStyle(GUI.skin.button) { fixedWidth = 21f }, Array.Empty<GUILayoutOption>()) && !valueOrDefault) { flag = true; } else { list.Add(new Requirement { amount = num, itemName = text2, recover = flag2 }); } if (GUILayout.Button("+", new GUIStyle(GUI.skin.button) { fixedWidth = 21f }, Array.Empty<GUILayoutOption>()) && !valueOrDefault) { flag = true; list.Add(new Requirement { amount = 1, itemName = "", recover = false }); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (flag) { cfg.BoxedValue = new PieceRequirements(list).ToString(); } } } public static class Extensions { public static ItemDrop GetItemDrop(this string name, string requester = "") { GameObject prefab = PrefabManager.GetPrefab(name); ItemDrop val = ((prefab != null) ? prefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { if (!string.IsNullOrEmpty(requester)) { TerrainHoe.LogWarning("[ " + requester + " ] The requirement item '" + name + "' does not exist."); } else { TerrainHoe.LogWarning("The requirement item '" + name + "' does not exist."); } } return val; } public static int GetInt(this string[] parts, int index, int defaultValue = 0) { if (parts.Length - 1 < index) { return defaultValue; } int result; return int.TryParse(parts[index].Trim(), out result) ? result : 0; } public static float GetFloat(this string[] parts, int index, float defaultValue = 0f) { if (parts.Length - 1 < index) { return defaultValue; } float result; return float.TryParse(parts[index].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out result) ? result : defaultValue; } public static bool GetBool(this string[] parts, int index, bool defaultValue = false) { if (parts.Length - 1 < index) { return defaultValue; } bool result; return bool.TryParse(parts[index].Trim(), out result) ? result : defaultValue; } public static string GetString(this string[] parts, int index, string defaultValue = "") { if (parts.Length - 1 < index) { return defaultValue; } return parts[index].Trim(); } } public static class PrefabManager { [HarmonyPatch(typeof(FejdStartup), "Awake")] public static class FejdStartup_Awake_Patch { private static void Prefix(FejdStartup __instance) { _ZNetScene = __instance.m_objectDBPrefab.GetComponent<ZNetScene>(); TerrainHoe.OnFejdStartup(); ConfigManager.OnFejdStartup(); } } [HarmonyPatch(typeof(ZNetScene), "Awake")] private static class ZNetScene_Awake_Patch { private static void Postfix() { Localizer.Load(); } } private static ZNetScene _ZNetScene; private static readonly GameObject root; public static Transform transform => root.transform; static PrefabManager() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown root = new GameObject("root"); Object.DontDestroyOnLoad((Object)(object)root); root.SetActive(false); } internal static GameObject GetPrefab(string prefabName) { if ((Object)(object)ZNetScene.instance != (Object)null) { GameObject prefab = ZNetScene.instance.GetPrefab(prefabName); if ((Object)(object)prefab != (Object)null) { return prefab; } } if ((Object)(object)_ZNetScene != (Object)null) { GameObject prefab = _ZNetScene.m_prefabs.Find((GameObject p) => ((Object)p).name == prefabName); if ((Object)(object)prefab != (Object)null) { return prefab; } } return null; } } [BepInPlugin("RustyMods.TerrainHoe", "TerrainHoe", "1.0.1")] public class TerrainHoe : BaseUnityPlugin { public const string ModName = "TerrainHoe"; public const string ModVersion = "1.0.1"; public const string Author = "RustyMods"; public const string ModGUID = "RustyMods.TerrainHoe"; public static string ConnectionError = ""; public readonly Harmony _harmony = new Harmony("RustyMods.TerrainHoe"); public static TerrainHoe instance; private static bool toolsLoaded; public void Awake() { instance = this; ConfigManager.Start(); PaintMan.Init(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); _harmony.PatchAll(executingAssembly); } private void OnDestroy() { ((BaseUnityPlugin)this).Config.Save(); } public static void OnFejdStartup() { if (!toolsLoaded) { new Lava("piece_paint_lava", "$piece_lava"); new AshlandsGrass("piece_paint_ashlands_grass", "$piece_ashlands_grass"); new PavedGrass("piece_paint_paved_grass", "$piece_paved_grass"); new PavedDark("piece_paint_paved_cultivated", "$piece_paved_dark"); new MistlandsGrass("piece_paint_mistlands", "$piece_mistlands_grass"); new MistlandsDirt("piece_paint_mistlands_dirt", "$piece_mistlands_dirt"); new BlackForestGrass("piece_paint_blackforest_grass", "$piece_blackforest_grass"); new PlainsGrass("piece_paint_plains_grass", "$piece_plains_grass"); new Snow("piece_paint_snow", "$piece_snow"); new SwampGrass("piece_paint_swamp_grass", "$piece_swamp_grass"); new MeadowsGrass("piece_paint_meadows_grass", "$piece_meadows_grass"); new Reset("piece_paint_reset", "$piece_reset_all"); toolsLoaded = true; } } public static void LogDebug(string msg) { ((BaseUnityPlugin)instance).Logger.LogDebug((object)msg); } public static void LogError(string msg) { ((BaseUnityPlugin)instance).Logger.LogError((object)msg); } public static void LogWarning(string msg) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)msg); } public static void LogInfo(string msg) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)msg); } public static void LogFatal(string msg) { ((BaseUnityPlugin)instance).Logger.LogFatal((object)msg); } } public static class PaintMan { [HarmonyPatch(typeof(Player), "SetupPlacementGhost")] private static class Player_SetupPlacementGhost_Patch { private static void Postfix(Player __instance) { Piece val = default(Piece); if (!((Object)(object)__instance.m_placementGhost == (Object)null) && __instance.m_placementGhost.TryGetComponent<Piece>(ref val) && IPaint.TryGetPaintTool(val.m_name, out var _)) { __instance.m_placementGhost.AddComponent<PaintOptions>(); } } } [HarmonyPatch(typeof(Hud), "SetupPieceInfo")] private static class Hud_SetupPieceInfo_Patch { private static void Postfix(Hud __instance, Piece piece) { if (!((Object)(object)piece == (Object)null) && IPaint.IsPaintTool(piece) && (Object)(object)PaintOptions.instance != (Object)null) { __instance.m_pieceDescription.text = PaintOptions.instance.m_pieceInfo; } } } private static readonly Dictionary<string, PaintType> paintTypes; private static readonly Dictionary<PaintType, string> customPaintTypes; static PaintMan() { paintTypes = new Dictionary<string, PaintType>(); customPaintTypes = new Dictionary<PaintType, string>(); } public static void Init() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Expected O, but got Unknown //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Expected O, but got Unknown //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Expected O, but got Unknown //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Expected O, but got Unknown //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Expected O, but got Unknown //IL_0291: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Expected O, but got Unknown //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Expected O, but got Unknown Harmony harmony = TerrainHoe.instance._harmony; harmony.Patch((MethodBase)AccessTools.Method(typeof(Enum), "GetValues", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_Enum_GetValues", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Enum), "GetNames", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_Enum_GetNames", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Enum), "GetName", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_Enum_GetName", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(TerrainComp), "PaintCleared", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_TerrainComp_PaintCleared", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(TerrainComp), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_TerrainComp_Awake", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(TerrainComp), "Initialize", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_TerrainComp_Initialize", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(TerrainComp), "Save", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_TerrainComp_Save", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(TerrainComp), "Load", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_TerrainComp_Load", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Heightmap), "RebuildRenderMesh", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Transpile_Heightmap_RebuildRenderMesh", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(ClutterSystem), "GetPatchBiomes", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_ClutterSystem_GetPatchBiomes", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(ClutterSystem), "GetGroundInfo", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_ClutterSystem_GetGroundInfo", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(Character), "UpdateLava", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(PaintMan), "Patch_Character_UpdateLava", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } public static bool TryGetPaintType(string name, out PaintType paintType) { if (Enum.TryParse<PaintType>(name, ignoreCase: true, out paintType)) { return true; } if (paintTypes.TryGetValue(name, out paintType)) { return true; } return false; } public static PaintType GetPaintType(string name) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) if (Enum.TryParse<PaintType>(name, ignoreCase: true, out PaintType result)) { return result; } if (paintTypes.TryGetValue(name, out result)) { return result; } Dictionary<PaintType, string> dictionary = GetPaintTypes(); foreach (KeyValuePair<PaintType, string> item in dictionary) { if (item.Value != name) { continue; } result = item.Key; paintTypes[name] = result; return result; } result = (PaintType)StringExtensionMethods.GetStableHashCode(name); paintTypes[name] = result; customPaintTypes[result] = name; return result; } private static Dictionary<PaintType, string> GetPaintTypes() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) Array values = Enum.GetValues(typeof(PaintType)); string[] names = Enum.GetNames(typeof(PaintType)); Dictionary<PaintType, string> dictionary = new Dictionary<PaintType, string>(); for (int i = 0; i < values.Length; i++) { dictionary[(PaintType)values.GetValue(i)] = names[i]; } foreach (KeyValuePair<PaintType, string> customPaintType in customPaintTypes) { dictionary[customPaintType.Key] = customPaintType.Value; } return dictionary; } private static void Patch_Enum_GetValues(Type enumType, ref Array __result) { if (!(enumType != typeof(PaintType)) && paintTypes.Count != 0) { PaintType[] array = (PaintType[])(object)new PaintType[__result.Length + paintTypes.Count]; __result.CopyTo(array, 0); paintTypes.Values.CopyTo(array, __result.Length); __result = array; } } private static bool Patch_Enum_GetName(Type enumType, object value, ref string __result) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (enumType != typeof(PaintType)) { return true; } if (customPaintTypes.TryGetValue((PaintType)value, out var value2)) { __result = value2; return false; } return true; } private static void Patch_Enum_GetNames(Type enumType, ref string[] __result) { if (!(enumType != typeof(PaintType)) && paintTypes.Count != 0) { __result = CollectionExtensions.AddRangeToArray<string>(__result, paintTypes.Keys.ToArray()); } } private static bool Patch_TerrainComp_PaintCleared(TerrainComp __instance, Vector3 worldPos, float radius, PaintType paintType, bool heightCheck, bool apply) { //IL_0001: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) if (!IPaint.TryGetPaintTool(paintType, out var paintTool)) { return true; } TerrainColors component = ((Component)__instance).GetComponent<TerrainColors>(); worldPos.x -= 0.5f; worldPos.z -= 0.5f; float heightOffset = worldPos.y - ((Component)__instance).transform.position.y; int num = default(int); int num2 = default(int); __instance.m_hmap.WorldToVertexMask(worldPos, ref num, ref num2); float num3 = radius / __instance.m_hmap.m_scale; int num4 = Mathf.CeilToInt(num3); Vector2 centerVertex = default(Vector2); ((Vector2)(ref centerVertex))..ctor((float)num, (float)num2); for (int i = num2 - num4; i <= num2 + num4; i++) { UpdatePaints(__instance, component, paintTool, centerVertex, num, num4, i, heightCheck, heightOffset, num3); } return false; } private static void UpdatePaints(TerrainComp comp, TerrainColors terrainColors, IPaint paint, Vector2 centerVertex, int centerVertex_x, int vertexSearchRadius, int vertex_y, bool heightCheck, float heightOffset, float radiusInVertices) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) for (int i = centerVertex_x - vertexSearchRadius; i <= centerVertex_x + vertexSearchRadius; i++) { UpdatePaint(comp, terrainColors, paint, Vector2.op_Implicit(centerVertex), i, vertex_y, heightCheck, heightOffset, radiusInVertices); } } private static void UpdatePaint(TerrainComp comp, TerrainColors terrainColors, IPaint paint, Vector3 centerVertex, int vertex_x, int vertex_y, bool heightCheck, float heightOffset, float radiusInVertices) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) float distanceFromCenter = Vector2.Distance(Vector2.op_Implicit(centerVertex), new Vector2((float)vertex_x, (float)vertex_y)); int num = comp.m_width + 1; bool flag = vertex_x >= 0 && vertex_y >= 0 && vertex_x < num && vertex_y < num; bool flag2 = !heightCheck || comp.m_hmap.GetHeight(vertex_x, vertex_y) <= heightOffset; if (flag && flag2) { int num2 = vertex_y * num + vertex_x; PaintMask(comp, paint, num2, vertex_x, vertex_y, distanceFromCenter, radiusInVertices); PaintTerrain(terrainColors, paint, num2, vertex_x, vertex_y, distanceFromCenter, radiusInVertices); if (paint.reset) { comp.m_modifiedHeight[num2] = false; comp.m_levelDelta[num2] = 0f; comp.m_smoothDelta[num2] = 0f; } } } private static void PaintMask(TerrainComp comp, IPaint paint, int index, int vertex_x, int vertex_y, float distanceFromCenter, float radiusInVertices) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) if (paint.reset) { comp.m_modifiedPaint[index] = false; comp.m_paintMask[index] = new Color(0f, 0f, 0f, 1f); return; } Color paintMask = comp.m_hmap.GetPaintMask(vertex_x, vertex_y); Color val; if (paint.blend) { float num = Mathf.Pow(1f - Mathf.Clamp01(distanceFromCenter / radiusInVertices), 0.1f); float a = paintMask.a; val = Color.Lerp(paintMask, paint.GetColor(), num); if (!paint.overrideAlpha) { val.a = a; } } else { val = paint.GetColor(); if (!paint.overrideAlpha) { val.a = paintMask.a; } } comp.m_modifiedPaint[index] = true; comp.m_paintMask[index] = val; } private static void PaintTerrain(TerrainColors colors, IPaint paint, int index, int vertex_x, int vertex_y, float distanceFromCenter, float radiusInVertices) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0066: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) if (!paint.isBiomePaint || (Object)(object)colors == (Object)null) { return; } if (paint.reset) { colors.ResetTerrain(index); return; } Color32 color; if (paint.blendTerrain) { float num = Mathf.Pow(1f - Mathf.Clamp01(distanceFromCenter / radiusInVertices), 0.1f); Color32 currentBiomeColor = colors.GetCurrentBiomeColor(index, vertex_x, vertex_y); color = Color32.Lerp(currentBiomeColor, paint.GetBiomeColor(), num); } else { color = paint.GetBiomeColor(); } colors.SetBiomeColor(index, color); } private static void Patch_TerrainComp_Awake(TerrainComp __instance) { ((Component)__instance).gameObject.AddComponent<TerrainColors>(); } private static void Patch_TerrainComp_Initialize(TerrainComp __instance) { ((Component)__instance).GetComponent<TerrainColors>()?.Initialize(); } private static void Patch_TerrainComp_Save(TerrainComp __instance) { ((Component)__instance).GetComponent<TerrainColors>()?.Save(); } private static void Patch_TerrainComp_Load(TerrainComp __instance) { ((Component)__instance).GetComponent<TerrainColors>()?.Load(); } private static IEnumerable<CodeInstruction> Transpile_Heightmap_RebuildRenderMesh(IEnumerable<CodeInstruction> instructions) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Expected O, but got Unknown MethodInfo methodInfo = AccessTools.Method(typeof(Mesh), "GetVertices", (Type[])null, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(PaintMan), "Apply_TerrainColor_Modifiers", (Type[])null, (Type[])null); CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Call, (object)methodInfo2) }; return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Callvirt, (object)methodInfo, (string)null) }).Insert(array) .InstructionEnumeration(); } private static void Apply_TerrainColor_Modifiers(Heightmap heightmap) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (heightmap.m_isDistantLod || !TerrainColors.TryFindTerrainColors(((Component)heightmap).transform.position, out var instance) || !instance.m_initialized) { return; } int num = heightmap.m_width + 1; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int num2 = i * num + j; if (instance.m_modifiedTerrain[num2]) { Color32 value = instance.m_terrainMask[num2]; Heightmap.s_tempColors[num2] = value; } } } } private static Biome GetBiomeFromMesh(this Heightmap hm, Vector3 point, float oceanLevel = 0.02f, bool waterAlwaysOcean = false) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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) //IL_005e: Unknown result type (might be due to invalid IL or missing references) if (hm.m_isDistantLod || waterAlwaysOcean) { return WorldGenerator.instance.GetBiome(point.x, point.z, oceanLevel, waterAlwaysOcean); } if (!TerrainColors.TryFindTerrainColors(((Component)hm).transform.position, out var instance)) { return hm.GetBiome(point, 0.02f, false); } return instance.GetBiome(hm, point); } private static Biome FindBiomeClutterByMesh(Vector3 point) { //IL_0012: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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) if (Object.op_Implicit((Object)(object)ZoneSystem.instance) && !ZoneSystem.instance.IsZoneLoaded(point)) { return (Biome)0; } Heightmap val = Heightmap.FindHeightmap(point); if ((Object)(object)val == (Object)null) { return (Biome)0; } return val.GetBiomeFromMesh(point); } private static Biome GetPatchBiomesByMesh(Vector3 center, float halfSize) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0016: 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) //IL_0020: 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) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009e: 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) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Invalid comparison between Unknown and I4 //IL_00a8: Unknown result type (might be due to invalid IL or missing references) Biome val = FindBiomeClutterByMesh(new Vector3(center.x - halfSize, 0f, center.z - halfSize)); Biome val2 = FindBiomeClutterByMesh(new Vector3(center.x + halfSize, 0f, center.z - halfSize)); Biome val3 = FindBiomeClutterByMesh(new Vector3(center.x - halfSize, 0f, center.z + halfSize)); Biome val4 = FindBiomeClutterByMesh(new Vector3(center.x - halfSize, 0f, center.z + halfSize)); if ((int)val == 0 || (int)val2 == 0 || (int)val3 == 0 || (int)val4 == 0) { return (Biome)0; } return (Biome)(val | val2 | val4 | val3); } private static bool GetGroundInfoByMesh(this ClutterSystem cs, Vector3 p, out Vector3 point, out Vector3 normal, out Heightmap hmap, out Biome biome) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected I4, but got Unknown Vector3 val = p + Vector3.up * 500f; RaycastHit val2 = default(RaycastHit); if (Physics.Raycast(val, Vector3.down, ref val2, 1000f, cs.m_placeRayMask)) { point = ((RaycastHit)(ref val2)).point; normal = ((RaycastHit)(ref val2)).normal; hmap = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<Heightmap>(); biome = (Biome)(int)hmap.GetBiomeFromMesh(point); return true; } point = p; normal = Vector3.up; hmap = null; biome = (Biome)0; return false; } private static bool Patch_ClutterSystem_GetPatchBiomes(Vector3 center, float halfSize, ref Biome __result) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected I4, but got Unknown __result = (Biome)(int)GetPatchBiomesByMesh(center, halfSize); return (int)__result == 0; } private static bool Patch_ClutterSystem_GetGroundInfo(ClutterSystem __instance, Vector3 p, out Vector3 point, out Vector3 normal, out Heightmap hmap, out Biome biome, ref bool __result) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) __result = __instance.GetGroundInfoByMesh(p, out point, out normal, out hmap, out biome); return (int)biome == 0; } private static void Patch_Character_UpdateLava(Character __instance, float dt) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) if (__instance.m_tolerateFire || !TerrainColors.TryFindTerrainColors(((Component)__instance).transform.position, out var instance) || !instance.m_initialized) { return; } int num = default(int); int num2 = default(int); instance.m_terrainComp.m_hmap.WorldToVertex(((Component)__instance).transform.position, ref num, ref num2); int num3 = num2 * (instance.m_width + 1) + num; if (!instance.m_modifiedTerrain[num3]) { if (!WorldGenerator.IsAshlands(((Component)__instance).transform.position.x, ((Component)__instance).transform.position.z)) { __instance.m_lavaHeatLevel -= dt * __instance.m_heatCooldownBase; } } else { Color32 val = instance.m_terrainMask[num3]; Color val2 = instance.m_terrainComp.m_paintMask[num3]; if (val.r > 200 && val.a > 200 && val2.a > 0.6f) { __instance.m_lavaHeatLevel += dt * __instance.m_heatBuildupBase * (1f - __instance.GetEquipmentHeatResistanceModifier()); } else { __instance.m_lavaHeatLevel -= dt * __instance.m_heatCooldownBase; } } __instance.m_lavaHeatLevel = Mathf.Clamp(__instance.m_lavaHeatLevel, 0f, 1f); } } public class AshlandsGrass : IPaint { public AshlandsGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("AshlandsGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; overrideAlpha = true; piece.m_icon = SpriteManager.GetSprite("ashlands_grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 0f); } public override Color32 GetBiomeColor() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue); } public override Biome GetBiome() { return (Biome)32; } } public class BlackForestGrass : IPaint { public BlackForestGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("BlackForestGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("forest_grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, (byte)0, byte.MaxValue, (byte)0); } public override Biome GetBiome() { return (Biome)8; } } public static class PaintVars { public static readonly int TerrainColors = StringExtensionMethods.GetStableHashCode("TerrainHoe.Paint.BiomeColors"); } public abstract class IPaint { public static readonly Dictionary<Piece, IPaint> m_paintTools = new Dictionary<Piece, IPaint>(); private static readonly Dictionary<PaintType, IPaint> m_paintMask = new Dictionary<PaintType, IPaint>(); private static readonly Dictionary<string, IPaint> m_paintToolNamed = new Dictionary<string, IPaint>(); protected readonly Piece piece; public readonly TerrainOp terrainOp; public bool adminOnly; public bool overrideAlpha = true; public bool blend = true; public bool isBiomePaint; public bool blendTerrain = true; public bool reset; private readonly ConfigEntry<string> recipe; public static bool IsPaintTool(Piece piece) { return m_paintTools.ContainsKey(piece); } public static bool TryGetPaintTool(PaintType type, out IPaint paintTool) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return m_paintMask.TryGetValue(type, out paintTool); } public static bool TryGetPaintTool(Piece piece, out IPaint paintTool) { return m_paintTools.TryGetValue(piece, out paintTool); } public static bool TryGetPaintTool(string name, out IPaint paintTool) { return m_paintToolNamed.TryGetValue(name, out paintTool); } protected IPaint(string id, string name, PaintType type, int index = 1) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) ItemDrop component = PrefabManager.GetPrefab("Cultivator").GetComponent<ItemDrop>(); List<GameObject> pieces = component.m_itemData.m_shared.m_buildPieces.m_pieces; GameObject val = pieces[1]; GameObject val2 = Object.Instantiate<GameObject>(val.gameObject, PrefabManager.transform); ((Object)val2).name = id; piece = val2.GetComponent<Piece>(); piece.m_name = name; piece.m_description = name + "_desc"; piece.m_vegetationGroundOnly = false; piece.m_category = (PieceCategory)0; terrainOp = val2.GetComponent<TerrainOp>(); terrainOp.m_settings.m_paintType = type; terrainOp.m_settings.m_level = false; terrainOp.m_settings.m_smooth = false; terrainOp.m_settings.m_raise = false; terrainOp.m_settings.m_smoothPower = 0f; recipe = ConfigManager.config(id, "Cost", "", new ConfigDescription("Define tool requirements", (AcceptableValueBase)null, new object[1] { PieceRequirements.attributes })); piece.m_resources = new PieceRequirements(recipe.Value).ToPieceRequirement(); recipe.SettingChanged += delegate { piece.m_resources = new PieceRequirements(recipe.Value).ToPieceRequirement(); }; m_paintTools[piece] = this; m_paintMask[type] = this; m_paintToolNamed[piece.m_name] = this; terrainOp.m_settings.m_paintRadius = 5f; GameObject prefab = PrefabManager.GetPrefab("dverger_guardstone"); PrivateArea component2 = prefab.GetComponent<PrivateArea>(); GameObject gameObject = ((Component)component2.m_areaMarker).gameObject; GameObject val3 = Object.Instantiate<GameObject>(gameObject, ((Component)piece).transform); val3.transform.localPosition = Vector3.zero; val3.transform.localRotation = Quaternion.identity; ((Object)val3).name = "projector"; val3.SetActive(true); component.m_itemData.m_shared.m_buildPieces.m_pieces.Insert(index, val2); } public abstract Color GetColor(); public virtual Color32 GetBiomeColor() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return default(Color32); } public virtual Biome GetBiome() { return (Biome)0; } } public class Lava : IPaint { public Lava(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("Lava"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; overrideAlpha = true; piece.m_icon = SpriteManager.GetSprite("lava_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue); } public override Biome GetBiome() { return (Biome)32; } } public class MeadowsGrass : IPaint { public MeadowsGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("MeadowsGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_0004: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, (byte)0, (byte)0, (byte)0); } public override Biome GetBiome() { return (Biome)1; } } public class MistlandsGrass : IPaint { public MistlandsGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("Mistlands"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, (byte)0, byte.MaxValue, byte.MaxValue); } public override Biome GetBiome() { return (Biome)512; } } public class MistlandsDirt : IPaint { public MistlandsDirt(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("MistlandsDirt"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("mistlands_dirt_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(1f, 0f, 0f, 0f); } public override Color32 GetBiomeColor() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, (byte)0, byte.MaxValue, byte.MaxValue); } public override Biome GetBiome() { return (Biome)512; } } public class PaintOptions : MonoBehaviour { public static PaintOptions instance; public Piece m_piece; public float radius; public ParticleSystem m_ring; public ParticleSystem m_particles; public CircleProjector projector; private IPaint m_tool; public string m_pieceInfo = ""; private float m_minRadius = 5f; private float m_maxRadius = 20f; private float m_maxSmooth = 10f; private float m_maxRaiseDelta = 20f; public void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) TerrainOp val = default(TerrainOp); if (!((Component)this).TryGetComponent<TerrainOp>(ref val) || !IPaint.TryGetPaintTool(val.m_settings.m_paintType, out m_tool)) { TerrainHoe.LogWarning("Invalid paint tool"); Object.Destroy((Object)(object)this); } m_piece = ((Component)this).GetComponent<Piece>(); radius = m_tool.terrainOp.m_settings.m_paintRadius; m_ring = ((Component)((Component)this).transform.Find("_GhostOnly")).GetComponent<ParticleSystem>(); m_particles = ((Component)((Component)this).transform.Find("_GhostOnly/particles")).GetComponent<ParticleSystem>(); projector = ((Component)this).GetComponentInChildren<CircleProjector>(true); projector.m_radius = radius; projector.m_mask = LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "terrain" })); projector.m_nrOfSegments = Mathf.CeilToInt(radius / 2f); UpdateHudPieceInfo(); instance = this; } public void OnDestroy() { if ((Object)(object)instance == (Object)(object)this) { instance = null; } } public void FixedUpdate() { if (Object.op_Implicit((Object)(object)Player.m_localPlayer)) { float mouseScrollWheel = ZInput.GetMouseScrollWheel(); if (UpdateSmooth(mouseScrollWheel) || UpdateRadius(mouseScrollWheel) || UpdateRaise(mouseScrollWheel) || UpdateLevel(mouseScrollWheel)) { UpdateHudPieceInfo(); } } } public void UpdateHudPieceInfo() { if (Object.op_Implicit((Object)(object)Hud.instance)) { StringBuilder stringBuilder = new StringBuilder(256); stringBuilder.Append(m_piece.m_description); stringBuilder.AppendFormat("\n[<color=orange>{0}</color> + <color=orange>{1}</color>] +- radius\n[<color=orange>{0}</color> + <color=orange>{2}</color>] +- smooth\n[<color=orange>{0}</color> + <color=orange>{3}</color>] +- raise\n[<color=orange>{0}</color> + <color=orange>{4}</color>] +- level\n", "Scroll", (object)(KeyCode)304, (object)(KeyCode)113, (object)(KeyCode)102, (object)(KeyCode)108); stringBuilder.Append($"SmoothPower: <color=orange>{m_tool.terrainOp.m_settings.m_smoothPower}</color>"); stringBuilder.Append($", RaisePower: <color=orange>{m_tool.terrainOp.m_settings.m_raisePower}</color>"); stringBuilder.Append($", RaiseDelta: <color=orange>{m_tool.terrainOp.m_settings.m_raiseDelta}</color>"); stringBuilder.Append($", LevelOffset: <color=orange>{m_tool.terrainOp.m_settings.m_levelOffset}</color>"); m_pieceInfo = Localization.instance.Localize(stringBuilder.ToString()); } } private bool UpdateRadius(float scroll) { if (!ZInput.GetKey((KeyCode)304, true)) { return false; } bool flag = false; if (scroll > Player.m_localPlayer.m_scrollAmountThreshold) { radius = Mathf.Clamp(radius + 0.5f, m_minRadius, m_maxRadius); flag = true; } if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold) { radius = Mathf.Clamp(radius - 0.5f, m_minRadius, m_maxRadius); flag = true; } if (!flag) { return false; } m_tool.terrainOp.m_settings.m_levelRadius = radius; m_tool.terrainOp.m_settings.m_raiseRadius = radius; m_tool.terrainOp.m_settings.m_paintRadius = radius; m_tool.terrainOp.m_settings.m_smoothRadius = radius + 1f; projector.m_radius = radius; projector.m_nrOfSegments = Math.Max(Mathf.CeilToInt(radius), 4); return true; } private bool UpdateSmooth(float scroll) { if (!ZInput.GetKey((KeyCode)113, true)) { return false; } bool flag = false; if (scroll > Player.m_localPlayer.m_scrollAmountThreshold) { m_tool.terrainOp.m_settings.m_smoothPower = Mathf.Clamp(m_tool.terrainOp.m_settings.m_smoothPower + 0.5f, 0f, m_maxSmooth); flag = true; } if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold) { m_tool.terrainOp.m_settings.m_smoothPower = Mathf.Clamp(m_tool.terrainOp.m_settings.m_smoothPower - 0.5f, 0f, m_maxSmooth); flag = true; } if (!flag) { return false; } m_tool.terrainOp.m_settings.m_smooth = m_tool.terrainOp.m_settings.m_smoothPower > 0f; return true; } private bool UpdateRaise(float scroll) { if (!ZInput.GetKey((KeyCode)102, true)) { return false; } bool flag = false; if (scroll > Player.m_localPlayer.m_scrollAmountThreshold) { m_tool.terrainOp.m_settings.m_raisePower = Mathf.Clamp01(m_tool.terrainOp.m_settings.m_raisePower + 0.1f); m_tool.terrainOp.m_settings.m_raiseDelta = Mathf.Clamp(m_tool.terrainOp.m_settings.m_raiseDelta + 0.5f, 0f, m_maxRaiseDelta); flag = true; } if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold) { m_tool.terrainOp.m_settings.m_raisePower = Mathf.Clamp01(m_tool.terrainOp.m_settings.m_raisePower - 0.1f); m_tool.terrainOp.m_settings.m_raiseDelta = Mathf.Clamp(m_tool.terrainOp.m_settings.m_raiseDelta - 0.5f, 0f, m_maxRaiseDelta); flag = true; } if (!flag) { return false; } m_tool.terrainOp.m_settings.m_raise = m_tool.terrainOp.m_settings.m_raiseDelta > 0f; return true; } private bool UpdateLevel(float scroll) { if (!ZInput.GetKey((KeyCode)108, true)) { return false; } bool flag = false; if (scroll > Player.m_localPlayer.m_scrollAmountThreshold) { Settings settings = m_tool.terrainOp.m_settings; settings.m_levelOffset += 1f; flag = true; } if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold) { Settings settings2 = m_tool.terrainOp.m_settings; settings2.m_levelOffset -= 1f; flag = true; } if (!flag) { return false; } m_tool.terrainOp.m_settings.m_level = m_tool.terrainOp.m_settings.m_levelOffset != 0f; return true; } } public class PavedDark : IPaint { public PavedDark(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("PavedCultivated"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) piece.m_icon = SpriteManager.GetSprite("paved_dark_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 1f, 0.5f, 1f); } } public class PavedGrass : IPaint { public PavedGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("PavedGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) piece.m_icon = SpriteManager.GetSprite("paved_grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0.5f, 0.5f); } } public class PlainsGrass : IPaint { public PlainsGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("PlainsGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("plains_grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue); } public override Biome GetBiome() { return (Biome)16; } } public class Reset : IPaint { public Reset(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("ResetAll"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; reset = true; piece.m_icon = SpriteManager.GetSprite("reset_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } } public class Snow : IPaint { public Snow(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("Snow"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("snow_icon.png"); } public override Color GetColor() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Color.clear; } public override Color32 GetBiomeColor() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return new Color32((byte)0, byte.MaxValue, (byte)0, (byte)0); } public override Biome GetBiome() { return (Biome)4; } } public class SwampGrass : IPaint { public SwampGrass(string id, string name, int index = 1) : base(id, name, PaintMan.GetPaintType("SwampGrass"), index) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) isBiomePaint = true; piece.m_icon = SpriteManager.GetSprite("swamp_grass_icon.png"); } public override Color GetColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) return new Color(0f, 0f, 0f, 1f); } public override Color32 GetBiomeColor() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) return new Color32(byte.MaxValue, (byte)0, (byte)0, (byte)0); } public override Biome GetBiome() { return (Biome)2; } } public class TerrainColors : MonoBehaviour { private static readonly List<TerrainColors> instances = new List<TerrainColors>(); public int m_width; public bool[] m_modifiedTerrain; public Color32[] m_terrainMask; public bool m_initialized; public TerrainComp m_terrainComp; public ZNetView m_nview; public void Awake() { m_nview = ((Component)this).GetComponent<ZNetView>(); m_terrainComp = ((Component)this).GetComponent<TerrainComp>(); instances.Add(this); } public void OnDestroy() { instances.Remove(this); } public void Initialize() { m_width = m_terrainComp.m_hmap.m_width; int num = m_width + 1; m_modifiedTerrain = new bool[num * num]; m_terrainMask = (Color32[])(object)new Color32[num * num]; m_initialized = true; } public void Save() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0091: 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) if (!m_initialized || !m_nview.IsValid() || !m_nview.IsOwner()) { return; } ZPackage val = new ZPackage(); val.Write(m_modifiedTerrain.Length); for (int i = 0; i < m_modifiedTerrain.Length; i++) { bool flag = m_modifiedTerrain[i]; val.Write(flag); if (flag) { Color32 val2 = m_terrainMask[i]; val.Write(val2.r); val.Write(val2.g); val.Write(val2.b); val.Write(val2.a); } } byte[] array = Utils.Compress(val.GetArray()); m_nview.GetZDO().Set(PaintVars.TerrainColors, array); } public void Load() { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_00a9: 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_0093: Unknown result type (might be due to invalid IL or missing references) byte[] byteArray = m_nview.GetZDO().GetByteArray(PaintVars.TerrainColors, (byte[])null); if (byteArray == null) { return; } byte[] array = Utils.Decompress(byteArray); ZPackage val = new ZPackage(array); int num = val.ReadInt(); for (int i = 0; i < num; i++) { bool flag = val.ReadBool(); m_modifiedTerrain[i] = flag; if (flag) { byte b = val.ReadByte(); byte b2 = val.ReadByte(); byte b3 = val.ReadByte(); byte b4 = val.ReadByte(); m_terrainMask[i] = new Color32(b, b2, b3, b4); } else { m_terrainMask[i] = default(Color32); } } } public void SetBiomeColor(int index, Color32 color) { //IL_0020: 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) if (m_initialized) { m_modifiedTerrain[index] = true; m_terrainMask[index] = color; } } public void ResetTerrain(int index) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) if (m_initialized) { m_modifiedTerrain[index] = false; m_terrainMask[index] = default(Color32); } } public void ApplyToHeightmap(Heightmap hm) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) if (!m_initialized) { return; } List<Color32> list = new List<Color32>(); hm.m_renderMesh.GetColors(list); int num = hm.m_width + 1; for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int num2 = i * num + j; if (m_modifiedTerrain[num2]) { Color32 value = m_terrainMask[num2]; list[num2] = value; } } } hm.m_renderMesh.SetColors(list); } public Color32 GetCurrentBiomeColor(int index, int x, int y) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) //IL_0016: 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) //IL_003a: Unknown result type (might be due to invalid IL or missing references) if (m_modifiedTerrain[index]) { return m_terrainMask[index]; } return Color32.op_Implicit(m_terrainComp.m_hmap.GetBiomeColor((float)x, (float)y)); } public Biome GetBiome(Heightmap hm, Vector3 point) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_0068: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) if (hm.m_isDistantLod) { return hm.GetBiome(point, 0.02f, false); } int num = default(int); int num2 = default(int); hm.WorldToVertex(point, ref num, ref num2); int num3 = num2 * (hm.m_width + 1) + num; if (!m_modifiedTerrain[num3]) { return hm.GetBiome(point, 0.02f, false); } Color32 val = m_terrainMask[num3]; if (val.r > 200 && val.a > 200) { return (Biome)32; } if (val.b > 200 && val.a > 200) { return (Biome)512; } if (val.r > 200) { return (Biome)2; } if (val.g > 200) { return (Biome)68; } if (val.b > 200) { return (Biome)8; } if (val.a > 200) { return (Biome)16; } return (Biome)1; } public static bool TryFindTerrainColors(Vector3 pos, out TerrainColors instance) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < instances.Count; i++) { TerrainColors terrainColors = instances[i]; float num = terrainColors.m_terrainComp.m_size / 2f; Vector3 position = ((Component)terrainColors).transform.position; if (pos.x >= position.x - num && pos.x <= position.x + num && pos.z >= position.z - num && pos.z <= position.z + num) { instance = terrainColors; return true; } } instance = null; return false; } public static TerrainColors FindTerrainColors(Vector3 pos) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: 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) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < instances.Count; i++) { TerrainColors terrainColors = instances[i]; float num = terrainColors.m_terrainComp.m_size / 2f; Vector3 position = ((Component)terrainColors).transform.position; if (pos.x >= position.x - num && pos.x <= position.x + num && pos.z >= position.z - num && pos.z <= position.z + num) { return terrainColors; } } return null; } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] public static class RegisterAndCheckVersion { private static void Prefix(ZNetPeer peer, ref ZNet __instance) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown TerrainHoe.LogDebug("Registering version RPC handler"); peer.m_rpc.Register<ZPackage>("TerrainHoe_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_TerrainHoe_Version); TerrainHoe.LogDebug("Invoking version check"); ZPackage val = new ZPackage(); val.Write("1.0.1"); peer.m_rpc.Invoke("TerrainHoe_VersionCheck", new object[1] { val }); } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] public static class VerifyClient { private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance) { if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc)) { return true; } TerrainHoe.LogWarning("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"); rpc.Invoke("Error", new object[1] { 3 }); return false; } private static void Postfix(ZNet __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "TerrainHoeRequestAdminSync", new object[1] { (object)new ZPackage() }); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] public class ShowConnectionError { private static void Postfix(FejdStartup __instance) { if (__instance.m_connectionFailedPanel.activeSelf) { __instance.m_connectionFailedError.fontSizeMax = 25f; __instance.m_connectionFailedError.fontSizeMin = 15f; TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + TerrainHoe.ConnectionError; } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] public static class RemoveDisconnectedPeerFromVerified { private static void Prefix(ZNetPeer peer, ref ZNet __instance) { if (__instance.IsServer()) { TerrainHoe.LogInfo("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"); RpcHandlers.ValidatedPeers.Remove(peer.m_rpc); } } } public static class RpcHandlers { public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>(); public static void RPC_TerrainHoe_Version(ZRpc rpc, ZPackage pkg) { string text = pkg.ReadString(); TerrainHoe.LogInfo("Version check, local: 1.0.1, remote: " + text); if (text != "1.0.1") { TerrainHoe.ConnectionError = "TerrainHoe Installed: 1.0.1\n Needed: " + text; if (ZNet.instance.IsServer()) { TerrainHoe.LogWarning("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."); rpc.Invoke("Error", new object[1] { 3 }); } } else if (!ZNet.instance.IsServer()) { TerrainHoe.LogInfo("Received same version from server!"); } else { TerrainHoe.LogInfo("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"); ValidatedPeers.Add(rpc); } } } } namespace Microsoft.CodeAnalysis { [<a1c463ef-6f54-4cd0-adaa-b4b631f05ebe>Embedded] [CompilerGenerated] internal sealed class <a1c463ef-6f54-4cd0-adaa-b4b631f05ebe>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [CompilerGenerated] [<a1c463ef-6f54-4cd0-adaa-b4b631f05ebe>Embedded] internal sealed class <4711ad37-8433-49c6-b462-753e64fd3686>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <4711ad37-8433-49c6-b462-753e64fd3686>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <4711ad37-8433-49c6-b462-753e64fd3686>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [<a1c463ef-6f54-4cd0-adaa-b4b631f05ebe>Embedded] [CompilerGenerated] internal sealed class <1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContextAttribute : Attribute { public readonly byte Flag; public <1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [<a1c463ef-6f54-4cd0-adaa-b4b631f05ebe>Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class <adc80266-f38d-4125-8508-016705a72ddd>RefSafetyRulesAttribute : Attribute { public readonly int Version; public <adc80266-f38d-4125-8508-016705a72ddd>RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServerSync { [PublicAPI] [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(0)] [<1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContext(1)] internal abstract class OwnConfigEntryBase { [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(2)] public object LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(0)] [<1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContext(1)] [PublicAPI] internal class SyncedConfigEntry<[<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(2)] T> : OwnConfigEntryBase { public readonly ConfigEntry<T> SourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public SyncedConfigEntry(ConfigEntry<T> sourceConfig) { SourceConfig = sourceConfig; base..ctor(); } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } [<1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContext(2)] [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(0)] internal abstract class CustomSyncedValueBase { public object LocalBaseValue; [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(1)] public readonly string Identifier; [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(1)] public readonly Type Type; private object boxedValue; protected bool localIsOwner; public readonly int Priority; public object BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action ValueChanged; [<1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContext(1)] protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } [PublicAPI] [<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(0)] [<1fcbfb43-e3d1-4df4-93be-fc849cc19324>NullableContext(1)] internal sealed class CustomSyncedValue<[<4711ad37-8433-49c6-b462-753e64fd3686>Nullable(2)] T> : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(