Decompiled source of Infinity Hammer v1.76.0
InfinityHammer.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using Data; using HarmonyLib; using InfinityHammer; using InfinityTools; using Microsoft.CodeAnalysis; using ServerDevcommands; using Service; using SoftReferenceableAssets; using TMPro; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; using WorldEditCommands; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("InfinityHammer")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+359b83888cd0f03ce60db6cf18b44a231df7d02b")] [assembly: AssemblyProduct("InfinityHammer")] [assembly: AssemblyTitle("InfinityHammer")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Service { public class ConfigWrapper { private readonly ConfigFile ConfigFile; private readonly Dictionary<string, Action<Terminal, string>> SettingHandlers = new Dictionary<string, Action<Terminal, string>>(); private readonly List<Action> Binders = new List<Action>(); private bool BindsDone; private static readonly HashSet<string> Truthies = new HashSet<string> { "1", "t", "true", "yes", "on" }; private static readonly HashSet<string> Falsies = new HashSet<string> { "0", "f", "false", "no", "off" }; public ConfigWrapper(string command, ConfigFile configFile) { //IL_0030: 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: Expected O, but got Unknown //IL_004e: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) ConfigFile = configFile; new ConsoleCommand(command, "[key] [value] - Toggles or sets a config value.", (ConsoleEvent)delegate(ConsoleEventArgs args) { if (args.Length >= 2 && SettingHandlers.TryGetValue(args[1].ToLower(), out Action<Terminal, string> value)) { if (args.Length == 2) { value(args.Context, ""); } else { value(args.Context, string.Join(" ", args.Args, 2, args.Length - 2)); } } }, false, false, false, false, false, (ConsoleOptionsFetcher)(() => SettingHandlers.Keys.ToList()), false, false, false); } private ConfigEntry<T> Create<T>(string group, string name, T value, ConfigDescription description) { return ConfigFile.Bind<T>(group, name, value, description); } private ConfigEntry<T> Create<T>(string group, string name, T value, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return Create(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } public ConfigEntry<T> Bind<T>(string group, string name, T value, ConfigDescription description) { ConfigEntry<T> val = Create(group, name, value, description); if (val is ConfigEntry<bool> setting) { Register(setting); } else if (val is ConfigEntry<KeyboardShortcut> setting2) { Register(setting2); } else { Register<T>(val); } return val; } public ConfigEntry<string> BindList(string group, string name, string value, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return Bind(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } public ConfigEntry<string> BindList(string group, string name, string value, ConfigDescription description) { ConfigEntry<string> val = Create(group, name, value, description); RegisterList(val); return val; } public ConfigEntry<KeyboardShortcut> BindCommand(string command, string group, string name, KeyboardShortcut value, string description, string mode = "") { //IL_001c: Unknown result type (might be due to invalid IL or missing references) string command2 = command; return BindCommand(() => command2, group, name, value, description, mode); } public ConfigEntry<KeyboardShortcut> BindCommand(Func<string> command, string group, string name, KeyboardShortcut value, string description, string mode) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) return BindCommand(command, group, name, value, description, "", mode); } public ConfigEntry<KeyboardShortcut> BindCommand(Func<string> command, string group, string name, KeyboardShortcut value, string description, string offCommand, string mode) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) Func<string> command2 = command; string text = ToKey(name); string text2 = "_bind_" + text; Helper.Command(text2, description, (ConsoleEvent)delegate(ConsoleEventArgs args) { string text3 = command2(); if (args.Length == 1) { args.Context.TryRunCommand(text3, false, false); } else { string args2 = HammerHelper.GetArgs(args[0], args); args.Context.TryRunCommand(text3 + " " + args2, false, false); } }); ConfigEntry<KeyboardShortcut> val = Create<KeyboardShortcut>(group, name, value, description); RegisterCommand(val, text2, offCommand, mode); return val; } public ConfigEntry<KeyboardShortcut> BindWheelCommand(string command, string group, string name, KeyboardShortcut value, string description, string mode = "") { //IL_001c: Unknown result type (might be due to invalid IL or missing references) string command2 = command; return BindWheelCommand(() => command2, group, name, value, description, mode); } public ConfigEntry<KeyboardShortcut> BindWheelCommand(Func<string> command, string group, string name, KeyboardShortcut value, string description, string mode = "") { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0038: Unknown result type (might be due to invalid IL or missing references) Func<string> command2 = command; string text = ToKey(name); string text2 = "_bind_" + text; Helper.Command(text2, description, (ConsoleEvent)delegate(ConsoleEventArgs args) { string text3 = command2(); if (args.Length == 1) { args.Context.TryRunCommand(text3, false, false); } else { string args2 = HammerHelper.GetArgs(args[0], args); args.Context.TryRunCommand(text3 + " " + args2, false, false); } }); ConfigEntry<KeyboardShortcut> val = Create<KeyboardShortcut>(group, name, value, description); RegisterWheelCommand(val, text2, "", mode); return val; } public ConfigEntry<T> Bind<T>(string group, string name, T value, string description) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return Bind(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>())); } private static void AddMessage(Terminal context, string message) { context.AddString(message); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, message, 0, (Sprite)null); } } public void Bind() { if (BindsDone) { return; } BindsDone = true; foreach (Action binder in Binders) { binder(); } } private void Register(ConfigEntry<bool> setting) { ConfigEntry<bool> setting2 = setting; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { Toggle(terminal, setting2, name, value); }); } public static string GetKeys(KeyboardShortcut key) { //IL_0002: 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) if ((int)((KeyboardShortcut)(ref key)).MainKey == 0) { return "unbound"; } KeyCode mainKey = ((KeyboardShortcut)(ref key)).MainKey; string text = ((object)(KeyCode)(ref mainKey)).ToString().ToLower(); if (((KeyboardShortcut)(ref key)).Modifiers.Count() > 0) { text = text + "," + string.Join(",", ((KeyboardShortcut)(ref key)).Modifiers); } return text; } private void UpdateKey(KeyboardShortcut key, string command, string offCommand, string mode) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)Chat.instance)) { BindsDone = false; } else { BindManager.SetTemporaryBind(GetKeys(key), mode, command, offCommand); } } private string ToKey(string name) { return name.ToLower().Replace(' ', '_').Replace("(", "") .Replace(")", ""); } private void RegisterCommand(ConfigEntry<KeyboardShortcut> setting, string command, string offCommand, string mode) { ConfigEntry<KeyboardShortcut> setting2 = setting; string command2 = command; string offCommand2 = offCommand; string mode2 = mode; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); setting2.SettingChanged += delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) UpdateKey(setting2.Value, command2, offCommand2, mode2); }; Binders.Add(delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) UpdateKey(setting2.Value, command2, offCommand2, mode2); }); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { SetKey(terminal, setting2, name, value); }); } private void UpdateWheelKey(KeyboardShortcut key, string command, string offCommand, string mode) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)Chat.instance)) { BindsDone = false; return; } List<string> list = new List<string>(); if ((int)((KeyboardShortcut)(ref key)).MainKey != 0 || mode == "command") { list.Add("wheel"); list.Add(GetKeys(key)); } BindManager.SetTemporaryBind(string.Join(",", list), mode, command, offCommand); } private void RegisterWheelCommand(ConfigEntry<KeyboardShortcut> setting, string command, string offCommand, string mode) { ConfigEntry<KeyboardShortcut> setting2 = setting; string command2 = command; string offCommand2 = offCommand; string mode2 = mode; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); setting2.SettingChanged += delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) UpdateWheelKey(setting2.Value, command2, offCommand2, mode2); }; Binders.Add(delegate { //IL_000c: Unknown result type (might be due to invalid IL or missing references) UpdateWheelKey(setting2.Value, command2, offCommand2, mode2); }); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { SetKey(terminal, setting2, name, value); }); } private void Register(ConfigEntry<KeyboardShortcut> setting) { ConfigEntry<KeyboardShortcut> setting2 = setting; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { SetKey(terminal, setting2, name, value); }); } private void RegisterList(ConfigEntry<string> setting) { ConfigEntry<string> setting2 = setting; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { ToggleFlag(terminal, setting2, name, value); }); } private void Register<T>(ConfigEntry<T> setting) { ConfigEntry<T> setting2 = setting; string name = ((ConfigEntryBase)setting2).Definition.Key; string key = ToKey(name); SettingHandlers.Add(key, delegate(Terminal terminal, string value) { SetValue<T>(terminal, setting2, name, value); }); } private static string State(bool value) { if (!value) { return "disabled"; } return "enabled"; } private static string Flag(bool value) { if (!value) { return "Added"; } return "Removed"; } private static bool IsTruthy(string value) { return Truthies.Contains(value); } private static bool IsFalsy(string value) { return Falsies.Contains(value); } private static void Toggle(Terminal context, ConfigEntry<bool> setting, string name, string value) { if (value == "") { setting.Value = !setting.Value; } else if (IsTruthy(value)) { setting.Value = true; } else if (IsFalsy(value)) { setting.Value = false; } AddMessage(context, name + " " + State(setting.Value) + "."); } private static void SetKey(Terminal context, ConfigEntry<KeyboardShortcut> setting, string name, string value) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) if (value == "") { AddMessage(context, $"{name}: {setting.Value}."); return; } if (!Enum.TryParse<KeyCode>(value, ignoreCase: true, out KeyCode result)) { throw new InvalidOperationException("'" + value + "' is not a valid UnityEngine.KeyCode."); } setting.Value = new KeyboardShortcut(result, Array.Empty<KeyCode>()); AddMessage(context, name + " set to " + value + "."); } public static int TryParseInt(string value, int defaultValue) { if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return result; } return defaultValue; } public static int TryParseInt(ConfigEntry<string> setting) { if (int.TryParse(setting.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return result; } return TryParseInt((string)((ConfigEntryBase)setting).DefaultValue, 0); } private static float TryParseFloat(string value, float defaultValue) { if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return result; } return defaultValue; } public static float TryParseFloat(ConfigEntry<string> setting) { if (float.TryParse(setting.Value, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return result; } return TryParseFloat((string)((ConfigEntryBase)setting).DefaultValue, 0f); } private static HashSet<string> ParseList(string value) { return (from s in value.Split(new char[1] { ',' }) select s.Trim().ToLower()).ToHashSet(); } private static void ToggleFlag(Terminal context, ConfigEntry<string> setting, string name, string value) { if (value == "") { AddMessage(context, name + ": " + setting.Value + "\"."); return; } HashSet<string> hashSet = ParseList(setting.Value); foreach (string item in ParseList(value)) { bool flag = hashSet.Contains(item); if (flag) { hashSet.Remove(item); } else { hashSet.Add(item); } setting.Value = string.Join(",", hashSet); AddMessage(context, name + ": " + Flag(flag) + " \"" + item + "\"."); } } private static void SetValue<T>(Terminal context, ConfigEntry<T> setting, string name, string value) { if (value == "") { AddMessage(context, $"{name}: {setting.Value}."); return; } if (value.Contains("/")) { string[] array = value.Split(new char[1] { '/' }); value = array[0]; for (int i = 0; i < array.Length - 1; i++) { T value2 = setting.Value; if (string.Equals((value2 != null) ? value2.ToString() : null, array[i], StringComparison.OrdinalIgnoreCase)) { value = array[i + 1]; break; } } } setting.Value = (T)(object)value; AddMessage(context, name + " set to " + value + "."); } } public class Log { private static ManualLogSource Logger; public static void Init(ManualLogSource logger) { Logger = logger; } public static void Error(string message) { Logger.LogError((object)message); } public static void Warning(string message) { Logger.LogWarning((object)message); } public static void Info(string message) { Logger.LogInfo((object)message); } public static void Debug(string message) { Logger.LogDebug((object)message); } } } namespace InfinityTools { public abstract class BaseRuler : MonoBehaviour { private static LayerMask Mask = LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "terrain" })); private static GameObject? basePrefab; public static bool SnapToGround = true; public bool Visible = true; private GameObject? Center; protected List<GameObject> Segments = new List<GameObject>(); public static float Offset = 0f; private readonly List<GameObject> OffsetSegments = new List<GameObject>(); private static GameObject BasePrefab => basePrefab ?? (basePrefab = GetBasePrefab()); protected static Vector3 BaseScale => BasePrefab.transform.localScale; private static GameObject GetBasePrefab() { GameObject prefab = ZNetScene.instance.GetPrefab("piece_workbench"); if (!Object.op_Implicit((Object)(object)prefab)) { throw new InvalidOperationException("Error: Unable to find the workbench object."); } return prefab.GetComponentInChildren<CircleProjector>().m_prefab; } public void OnDestroy() { foreach (GameObject segment in Segments) { Object.Destroy((Object)(object)segment); } foreach (GameObject offsetSegment in OffsetSegments) { Object.Destroy((Object)(object)offsetSegment); } Object.Destroy((Object)(object)Center); Center = null; Segments.Clear(); OffsetSegments.Clear(); } public void Update() { if (!Visible) { CreateSegments(0); CreateOffsetSegments(0); return; } CreateLines(); if (SnapToGround) { Snap(); } CreateOffsetSegments(Segments.Count); CreateOffsetLines(); } protected void CreateSegments(int count) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) if (Segments.Count == count) { return; } foreach (GameObject segment in Segments) { Object.Destroy((Object)(object)segment); } Segments.Clear(); Object.Destroy((Object)(object)Center); if (count != 0) { Center = Object.Instantiate<GameObject>(BasePrefab, ((Component)this).transform); Center.transform.localPosition = Vector3.zero; Center.transform.localRotation = Quaternion.identity; Center.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); for (int i = 0; i < count; i++) { Segments.Add(Object.Instantiate<GameObject>(BasePrefab, ((Component)this).transform)); } } } protected abstract void CreateLines(); private void Snap() { //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) foreach (GameObject segment in Segments) { segment.transform.position = Snap(segment.transform.position); } } private Vector3 Snap(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_0045: 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) RaycastHit val = default(RaycastHit); if (Physics.Raycast(pos + Vector3.up * 500f, Vector3.down, ref val, 1000f, ((LayerMask)(ref Mask)).value)) { pos.y = ((RaycastHit)(ref val)).point.y; } return pos; } private void CreateOffsetSegments(int count) { //IL_0070: 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) if (Mathf.Approximately(Offset, 0f)) { count = 0; } if (OffsetSegments.Count == count) { return; } foreach (GameObject offsetSegment in OffsetSegments) { Object.Destroy((Object)(object)offsetSegment); } OffsetSegments.Clear(); for (int i = 0; i < count; i++) { OffsetSegments.Add(Object.Instantiate<GameObject>(BasePrefab, Vector3.zero, Quaternion.identity, ((Component)this).transform)); } } private void CreateOffsetLines() { //IL_0029: 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_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0069: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < OffsetSegments.Count; i++) { GameObject val = Segments[i]; GameObject obj = OffsetSegments[i]; obj.transform.localPosition = val.transform.localPosition + Vector3.up * Offset; obj.transform.localRotation = val.transform.localRotation; obj.transform.localScale = val.transform.localScale; obj.SetActive(val.activeSelf); } } protected Transform Get(int index) { return Segments[index].transform; } protected void Set(int index, Vector3 pos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) Get(index).localPosition = pos; } protected void SetRot(int index, Vector3 rot) { //IL_0007: 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) //IL_000d: Unknown result type (might be due to invalid IL or missing references) Get(index).localRotation = Quaternion.LookRotation(rot, Vector3.up); } } public class CircleRuler : BaseRuler { public float Radius = 20f; private readonly float Speed = 0.1f; protected override void CreateLines() { int count = Math.Max(3, (int)(Radius * 4f)); CreateSegments(count); UpdateLines(); } private void UpdateLines() { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) int count = Segments.Count; float num = (float)Math.PI * 2f / (float)count; float num2 = Time.time * Speed; Vector3 pos = default(Vector3); for (int i = 0; i < count; i++) { float num3 = (float)i * num + num2; ((Vector3)(ref pos))..ctor(Mathf.Sin(num3) * Radius, 0f, Mathf.Cos(num3) * Radius); Set(i, pos); } for (int j = 0; j < count; j++) { GameObject obj = ((j == 0) ? Segments[Segments.Count - 1] : Segments[j - 1]); GameObject val = ((j == Segments.Count - 1) ? Segments[0] : Segments[j + 1]); Vector3 val2 = obj.transform.localPosition - val.transform.localPosition; Vector3 normalized = ((Vector3)(ref val2)).normalized; SetRot(j, normalized); } } } public class RectangleRuler : BaseRuler { public float Width = 20f; public float Depth = 20f; private void EdgeFix(int index, float percent, float max, float start, float end, Vector3 direction) { //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_0034: 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_0040: 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_0052: 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_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_0094: 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_00a6: 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) float num = percent * max; Transform val = Get(index); Vector3 baseScale = BaseRuler.BaseScale; if (num - start < 0.5f) { baseScale.z *= num - start + 0.5f; val.localPosition += direction * (0.5f - baseScale.z / 2f); } if (end - num < 0.5f) { baseScale.z *= Mathf.Max(0f, end - num + 0.5f); val.localPosition -= direction * (0.5f - baseScale.z / 2f); } if (baseScale.z == 0f) { ((Component)val).gameObject.SetActive(false); } else { ((Component)val).gameObject.SetActive(true); } val.localScale = baseScale; } protected override void CreateLines() { float num = 2f * Width + 2f * Depth; int num2 = Math.Max(3, (int)num); int num3 = (int)Mathf.Max(2f, Mathf.Ceil((float)num2 * Depth / num)); int num4 = (int)Mathf.Max(2f, Mathf.Ceil((float)num2 * Width / num)); num2 = 2 * (num3 + num4); CreateSegments(num2); UpdateLines(num4, num3); } private void UpdateLines(int w, int d) { //IL_0015: 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_0055: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0331: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_0344: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) int count = Segments.Count; int num = 0; int num2 = 0; while (num2 < d) { SetRot(num, Vector3.forward); num2++; num++; } int num3 = 0; while (num3 < w) { SetRot(num, Vector3.right); num3++; num++; } int num4 = 0; while (num4 < d) { SetRot(num, Vector3.back); num4++; num++; } int num5 = 0; while (num5 < w) { SetRot(num, Vector3.left); num5++; num++; } num = 0; float num6 = Time.time * 0.025f * (float)(count - 4); float num7 = 0.5f; Vector3 val = Width * Vector3.left - (Depth + num7) * Vector3.forward; float num8 = 0.5f; float end = num8 + 2f * Depth; float num9 = 2f * Depth * (float)d / (float)(d - 1); float num10 = num6 / (float)d; int num11 = 0; while (num11 < d) { float num12 = ((float)num11 / (float)d + num10) % 1f; Vector3 pos = val + num12 * num9 * Vector3.forward; Set(num, pos); EdgeFix(num, num12, num9, num8, end, Vector3.forward); num11++; num++; } val = Depth * Vector3.forward - (Width + num7) * Vector3.right; end = num8 + 2f * Width; num9 = 2f * Width * (float)w / (float)(w - 1); num10 = num6 / (float)w; int num13 = 0; while (num13 < w) { float num14 = ((float)num13 / (float)w + num10) % 1f; Vector3 pos2 = val + num14 * num9 * Vector3.right; Set(num, pos2); EdgeFix(num, num14, num9, num8, end, Vector3.right); num13++; num++; } val = Width * Vector3.right - (Depth + num7) * Vector3.back; end = num8 + 2f * Depth; num9 = 2f * Depth * (float)d / (float)(d - 1); num10 = num6 / (float)d; int num15 = 0; while (num15 < d) { float num16 = ((float)num15 / (float)d + num10) % 1f; Vector3 pos3 = val + num16 * num9 * Vector3.back; Set(num, pos3); EdgeFix(num, num16, num9, num8, end, Vector3.back); num15++; num++; } val = Depth * Vector3.back - (Width + num7) * Vector3.left; end = num8 + 2f * Width; num9 = 2f * Width * (float)w / (float)(w - 1); num10 = num6 / (float)w; int num17 = 0; while (num17 < w) { float num18 = ((float)num17 / (float)w + num10) % 1f; Vector3 pos4 = val + num18 * num9 * Vector3.left; Set(num, pos4); EdgeFix(num, num18, num9, num8, end, Vector3.left); num17++; num++; } } } public class RulerParameters { public bool Radius; public bool Ring; public bool Width; public bool Grid; public bool Depth; public bool Height; public bool RotateWithPlayer; public bool IsTargeted; public bool IsId; } public enum RulerShape { Circle, Ring, Frame, Square, Rectangle } public class Ruler { public static RulerShape Shape; public static GameObject? Projector; public static GameObject? Circle; public static GameObject? Ring; public static GameObject? Rectangle; public static GameObject? Square; public static GameObject? Frame; public static bool IsActive => (Object)(object)Projector != (Object)null; public static void SanityCheckShape() { if (Shape == RulerShape.Circle && (!Object.op_Implicit((Object)(object)Circle) || !Configuration.ShapeCircle)) { Shape = RulerShape.Ring; } if (Shape == RulerShape.Ring && (!Object.op_Implicit((Object)(object)Ring) || !Configuration.ShapeRing)) { Shape = RulerShape.Square; } if (Shape == RulerShape.Square && (!Object.op_Implicit((Object)(object)Square) || !Configuration.ShapeSquare)) { Shape = RulerShape.Frame; } if (Shape == RulerShape.Frame && (!Object.op_Implicit((Object)(object)Frame) || !Configuration.ShapeFrame)) { Shape = RulerShape.Rectangle; } if (Shape == RulerShape.Rectangle && (!Object.op_Implicit((Object)(object)Rectangle) || !Configuration.ShapeRectangle)) { Shape = RulerShape.Circle; } } private static void SetTerrainGrid(float width, float height) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) float num = width - Mathf.Floor(width); float num2 = height - Mathf.Floor(height); bool flag = 0.25f < num && num < 0.75f; bool flag2 = 0.25f < num2 && num2 < 0.75f; Grid.SetPreciseMode(new Vector3(flag ? 0f : 0.5f, 0f, flag2 ? 0f : 0.5f)); } private static void BuildCircle(GameObject obj, float radius) { CircleRuler component = obj.GetComponent<CircleRuler>(); component.Visible = obj.activeSelf; component.Radius = radius; } private static void BuildRectangle(GameObject obj, float width, float depth) { RectangleRuler component = obj.GetComponent<RectangleRuler>(); component.Visible = obj.activeSelf; component.Width = width; component.Depth = depth; } public static void Update() { //IL_00dd: 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_007e: 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_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: 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_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0380: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03d5: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)Projector == (Object)null || !Object.op_Implicit((Object)(object)localPlayer) || !(Selection.Get() is ToolSelection toolSelection)) { return; } GameObject placementGhost = localPlayer.m_placementGhost; Transform transform = ((Component)localPlayer).transform; Projector.SetActive(Object.op_Implicit((Object)(object)placementGhost)); if (!Object.op_Implicit((Object)(object)placementGhost)) { return; } Transform transform2 = placementGhost.transform; ScalingData scalingData = Scaling.Get(); Tool tool = toolSelection.Tool; if (tool.IsTargetEdge) { Vector3 position = default(Vector3); ((Vector3)(ref position))..ctor((transform.position.x + transform2.position.x) / 2f, transform2.position.y, (transform.position.z + transform2.position.z) / 2f); Projector.transform.position = position; } else { Projector.transform.position = transform2.position; } Quaternion rotation = transform2.rotation; float num = ((Quaternion)(ref rotation)).eulerAngles.y; if (tool.RotateWithPlayer) { num = Vector3.SignedAngle(Vector3.forward, Utils.DirectionXZ(transform2.position - transform.position), Vector3.up); } if (toolSelection.TerrainGrid) { num = 0f; } Projector.transform.rotation = Quaternion.Euler(0f, num, 0f); if (tool.IsTargetEdge) { float scaleZ = Utils.DistanceXZ(transform.position, transform2.position) / 2f; scalingData.SetScaleZ(scaleZ); } SanityCheckShape(); RulerShape shape = Shape; if (toolSelection.TerrainGrid) { scalingData.SetPrecisionXZ(0.5f, 0.5f); } if ((Object)(object)Circle != (Object)null) { Circle.SetActive(shape == RulerShape.Circle || shape == RulerShape.Ring); BuildCircle(Circle, scalingData.X); if (Circle.activeSelf && toolSelection.TerrainGrid) { SetTerrainGrid(scalingData.X, scalingData.X); } } if ((Object)(object)Circle != (Object)null && (Object)(object)Ring != (Object)null) { Ring.SetActive(shape == RulerShape.Ring); BuildCircle(Ring, scalingData.Z); } if ((Object)(object)Square != (Object)null) { Square.SetActive(shape == RulerShape.Square || shape == RulerShape.Frame); BuildRectangle(Square, scalingData.X, scalingData.X); if (Square.activeSelf && toolSelection.TerrainGrid) { SetTerrainGrid(scalingData.X, scalingData.X); } } if ((Object)(object)Square != (Object)null && (Object)(object)Frame != (Object)null) { Frame.SetActive(shape == RulerShape.Frame); BuildRectangle(Frame, scalingData.Z, scalingData.Z); if (Frame.activeSelf && toolSelection.TerrainGrid) { SetTerrainGrid(scalingData.Z, scalingData.Z); } } if ((Object)(object)Rectangle != (Object)null) { Rectangle.SetActive(shape == RulerShape.Rectangle); BuildRectangle(Rectangle, scalingData.X, scalingData.Z); if (Rectangle.activeSelf && toolSelection.TerrainGrid) { SetTerrainGrid(scalingData.X, scalingData.Z); } } if (tool.Highlight) { if (shape == RulerShape.Circle) { HighlightCircle(Projector.transform.position, scalingData.X, scalingData.Y); } if (shape == RulerShape.Ring) { HighlightRing(Projector.transform.position, scalingData.X, scalingData.Z, scalingData.Y); } if (shape == RulerShape.Square) { HighlightRectangle(Projector.transform.position, num, scalingData.X, scalingData.X, scalingData.Y); } if (shape == RulerShape.Frame) { HighlightFrame(Projector.transform.position, num, scalingData.X, scalingData.Z, scalingData.Y); } if (shape == RulerShape.Rectangle) { HighlightRectangle(Projector.transform.position, num, scalingData.X, scalingData.Z, scalingData.Y); } } BaseRuler.SnapToGround = toolSelection.Tool.SnapGround; BaseRuler.Offset = (toolSelection.Tool.Height ? scalingData.Y : 0f); } public static string DescriptionScale(ToolSelection selection) { if ((Object)(object)Projector == (Object)null) { return ""; } Tool tool = selection.Tool; ScalingData scalingData = Scaling.Get(); string text = (tool.Height ? (", h: " + Format2(scalingData.Y)) : ""); switch (Shape) { case RulerShape.Rectangle: return "w: " + Format2(scalingData.X) + ", d: " + Format2(scalingData.Z) + text; case RulerShape.Square: return "w: " + Format2(scalingData.X) + text; case RulerShape.Circle: return "r: " + Format2(scalingData.X) + text; case RulerShape.Ring: { float f3 = Mathf.Min(scalingData.X, scalingData.Z); float f4 = Mathf.Max(scalingData.X, scalingData.Z); return "r: " + Format2(f3) + "-" + Format2(f4) + text; } case RulerShape.Frame: { float f = Mathf.Min(scalingData.X, scalingData.Z); float f2 = Mathf.Max(scalingData.X, scalingData.Z); return "w: " + Format2(f) + "-" + Format2(f2) + text; } default: return ""; } } public static string DescriptionPosition() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_005f: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Projector == (Object)null) { return ""; } Vector3 position = Projector.transform.position; return "x: " + Format1(position.x) + ", z: " + Format1(position.z) + ", y: " + Format1(position.y); } private static string Format1(float f) { return f.ToString("F1", CultureInfo.InvariantCulture); } private static string Format2(float f) { return f.ToString("F2", CultureInfo.InvariantCulture); } private static GameObject InitializeGameObject() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown Projector = new GameObject { layer = LayerMask.NameToLayer("character_trigger") }; return Projector; } private static GameObject CreateCircle(GameObject obj) { GameObject obj2 = CreateChild(obj); obj2.AddComponent<CircleRuler>(); return obj2; } private static GameObject CreateRectangle(GameObject obj) { GameObject obj2 = CreateChild(obj); obj2.AddComponent<RectangleRuler>(); return obj2; } private static GameObject CreateChild(GameObject obj) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_001c: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown GameObject val = new GameObject(); val.transform.SetParent(obj.transform); val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; return val; } public static void Constrain(Range<float?> size, Range<float?> height) { ScalingData scalingData = Scaling.Get(); if (size.Min.HasValue && size.Max.HasValue) { scalingData.SetScaleX(Mathf.Clamp(scalingData.X, size.Min.Value, size.Max.Value)); scalingData.SetScaleZ(Mathf.Clamp(scalingData.Z, size.Min.Value, size.Max.Value)); } if (height.Min.HasValue && height.Max.HasValue) { scalingData.SetScaleY(Mathf.Clamp(scalingData.Y, height.Min.Value, height.Max.Value)); } } public static void InitializeProjector(Tool tool, GameObject obj) { if (tool.Width) { Square = CreateRectangle(obj); } if (tool.Frame) { Frame = CreateRectangle(obj); } if (tool.Width && tool.Depth) { Rectangle = CreateRectangle(obj); } if (tool.Radius) { Circle = CreateCircle(obj); } if (tool.Ring) { Ring = CreateCircle(obj); } } public static void Create(Tool tool) { Remove(); if (tool.Radius || tool.Width || tool.Depth) { InitializeProjector(tool, InitializeGameObject()); } } public static void Remove() { if ((Object)(object)Projector != (Object)null) { Object.Destroy((Object)(object)Projector); } Projector = null; if ((Object)(object)Circle != (Object)null) { Object.Destroy((Object)(object)Circle); } Circle = null; if ((Object)(object)Ring != (Object)null) { Object.Destroy((Object)(object)Ring); } Ring = null; if ((Object)(object)Frame != (Object)null) { Object.Destroy((Object)(object)Frame); } Frame = null; if ((Object)(object)Rectangle != (Object)null) { Object.Destroy((Object)(object)Rectangle); } Rectangle = null; if ((Object)(object)Square != (Object)null) { Object.Destroy((Object)(object)Square); } Square = null; } private static void HighlightCircle(Vector3 center, float radius, float height) { //IL_0049: 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) Range<float> val = new Range<float>(radius); foreach (WearNTear s_allInstance in WearNTear.s_allInstances) { if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, val, height)) { s_allInstance.Highlight(); } } } private static void HighlightRing(Vector3 center, float radius1, float radius2, float height) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Min(radius1, radius2); float num2 = Mathf.Max(radius1, radius2); Range<float> val = new Range<float>(num, num2); foreach (WearNTear s_allInstance in WearNTear.s_allInstances) { if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, val, height)) { s_allInstance.Highlight(); } } } private static void HighlightRectangle(Vector3 center, float angle, float width, float depth, float height) { //IL_0050: 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) Range<float> val = new Range<float>(width); Range<float> val2 = new Range<float>(depth); foreach (WearNTear s_allInstance in WearNTear.s_allInstances) { if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, angle, val, val2, height)) { s_allInstance.Highlight(); } } } private static void HighlightFrame(Vector3 center, float angle, float size1, float size2, float height) { //IL_0057: 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) float num = Mathf.Min(size1, size2); Mathf.Max(size1, size2); Range<float> val = new Range<float>(num); foreach (WearNTear s_allInstance in WearNTear.s_allInstances) { if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, angle, val, val, height)) { s_allInstance.Highlight(); } } } } [HarmonyPatch(typeof(Player), "UpdateWearNTearHover")] public class UpdateWearNTearHover { private static bool Prefix() { return !Ruler.IsActive; } } [HarmonyPatch(typeof(Hud), "SetupPieceInfo")] public class AddExtraInfo { private static Vector2? DefaultOffset; private static Vector2? ToolOffset; private static string DescriptionHover() { if (Object.op_Implicit((Object)(object)Ruler.Projector)) { return ""; } ZNetView hovered = Selector.GetHovered(Configuration.Range, Array.Empty<string>(), Configuration.IgnoredIds); string text = (((Object)(object)hovered == (Object)null) ? "" : Utils.GetPrefabName(((Component)hovered).gameObject)); return "id: " + text; } private static string Description(ToolSelection selection) { if (Hud.instance.m_pieceSelectionWindow.activeSelf) { return ""; } string[] source = new string[3] { DescriptionHover(), Ruler.DescriptionScale(selection), Ruler.DescriptionPosition() }; return string.Join("\n", source.Where((string s) => s != "")); } private static void Prefix(Hud __instance) { //IL_0019: 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_005e: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) RectTransform rectTransform = __instance.m_pieceDescription.rectTransform; if (!DefaultOffset.HasValue) { DefaultOffset = rectTransform.offsetMin; } if (!ToolOffset.HasValue) { ToolOffset = new Vector2(rectTransform.offsetMin.x, -160f); } if (rectTransform.offsetMin != DefaultOffset.Value) { rectTransform.offsetMin = DefaultOffset.Value; } } private static void Postfix(Hud __instance, Piece piece) { //IL_0032: 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_004e: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)piece) || !(Selection.Get() is ToolSelection selection) || !ToolOffset.HasValue) { return; } RectTransform rectTransform = __instance.m_pieceDescription.rectTransform; if (rectTransform.offsetMin != ToolOffset.Value) { rectTransform.offsetMin = ToolOffset.Value; } if (!Hud.instance.m_pieceSelectionWindow.activeSelf) { string text = Description(selection); if (__instance.m_pieceDescription.text != "") { text = "\n" + text; } TMP_Text pieceDescription = __instance.m_pieceDescription; pieceDescription.text += text; } } } public class ToolCmdCommand { [CompilerGenerated] private static class <>O { public static ConsoleEvent <0>__Execute; } public ToolCmdCommand() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown object obj = <>O.<0>__Execute; if (obj == null) { ConsoleEvent val = Execute; <>O.<0>__Execute = val; obj = (object)val; } Helper.Command("tool_cmd", "[command] - Selects a command to be used when placed.", (ConsoleEvent)obj); AutoComplete.RegisterEmpty("tool_cmd"); AutoComplete.Offsets["tool_cmd"] = 0; } protected static void Execute(ConsoleEventArgs args) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) Helper.ArgsCheck(args, 2, "Missing the command."); if (!Hammer.HasAny()) { Hammer.Equip(); } string args2 = HammerHelper.GetArgs("tool_cmd", args); Tool tool = new Tool(new ToolData { name = "Command", command = args2, description = args2 }); Selection.CreateGhost(new ToolSelection(tool)); Hammer.SelectEmpty(); PlaceRotation.Set(Quaternion.identity); HammerHelper.Message(args.Context, "Selected command " + tool.Name + "."); } } public class ToolCommand { [CompilerGenerated] private static class <>O { public static ConsoleEvent <0>__Execute; } public ToolCommand() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown object obj = <>O.<0>__Execute; if (obj == null) { ConsoleEvent val = Execute; <>O.<0>__Execute = val; obj = (object)val; } Helper.Command("tool", "[tool] - Selects a tool to be used when placed.", (ConsoleEvent)obj); AutoComplete.Register("tool", (Func<int, int, List<string>>)((int index, int subIndex) => (from tool in ToolManager.GetAll() select tool.Name).ToList())); } protected static void Execute(ConsoleEventArgs args) { //IL_0068: Unknown result type (might be due to invalid IL or missing references) Helper.ArgsCheck(args, 2, "Missing the tool name."); if (!Hammer.HasAny()) { Hammer.Equip(); } string args2 = HammerHelper.GetArgs("tool", args); if (!ToolManager.TryGetTool(Hammer.Get(), args2, out Tool tool)) { tool = new Tool(new ToolData { name = "Command", command = args2, description = args2 }); } Hammer.SelectRepair(); Selection.CreateGhost(new ToolSelection(tool)); PlaceRotation.Set(Quaternion.identity); HammerHelper.Message(args.Context, "Selected tool " + tool.Name + "."); } } public class ToolData { [DefaultValue("")] public string name = ""; [DefaultValue("")] public string description = ""; [DefaultValue("")] public string icon = ""; public string command = ""; public CommandData[]? commands; [DefaultValue("")] public string continuous = ""; [DefaultValue("")] public string initialHeight = ""; [DefaultValue("")] public string initialSize = ""; [DefaultValue("")] public string initialShape = ""; [DefaultValue("false")] public string targetEdge = "false"; [DefaultValue("false")] public string snapGround = "false"; [DefaultValue("false")] public string snapPiece = "false"; [DefaultValue("")] public string playerHeight = ""; [DefaultValue("false")] public string highlight = "false"; [DefaultValue("false")] public string terrainGrid = "false"; [DefaultValue(null)] public bool? instant; [DefaultValue(null)] public int? tabIndex; [DefaultValue(null)] public int? index; } public class CommandData { public string command = ""; public string keys = ""; } public class Tool { public string Name; private List<CommandValue> Commands; private readonly string description; private readonly string iconName; private Sprite? icon; private readonly string continuous; public float? InitialHeight; public float? InitialSize; public string InitialShape; private readonly string snapGround; private readonly string playerHeight; private readonly string highlight; private readonly string terrainGrid; private readonly string snapPiece; public bool Instant; public int? TabIndex; public int? Index; public bool Radius; public bool Ring; public bool Width; public bool Frame; public bool Depth; public bool Height; public bool RotateWithPlayer; private readonly string targetEdge; public bool IsId; public string Description => DisplayKeys(description); public Sprite? Icon => icon ?? (icon = HammerHelper.FindSprite(iconName)); public bool Continuous { get { if (!(continuous == "true")) { return HammerHelper.IsDown(continuous); } return true; } } public bool SnapGround { get { if (!(snapGround == "true")) { return HammerHelper.IsDown(snapGround); } return true; } } public bool PlayerHeight { get { if (!(playerHeight == "true")) { return HammerHelper.IsDown(playerHeight); } return true; } } public bool Highlight { get { if (!(highlight == "true")) { return HammerHelper.IsDown(highlight); } return true; } } public bool TerrainGrid { get { if (!(terrainGrid == "true")) { return HammerHelper.IsDown(terrainGrid); } return true; } } public bool SnapPiece { get { if (!(snapPiece == "true")) { return HammerHelper.IsDown(snapPiece); } return true; } } public bool IsTargetEdge { get { if (!(targetEdge == "true")) { return HammerHelper.IsDown(targetEdge); } return true; } } public Tool(ToolData data) { Name = data.name; description = data.description.Replace("\\n", "\n"); iconName = data.icon; continuous = data.continuous; InitialHeight = ((data.initialHeight == "") ? null : new float?(Parse.Float(data.initialHeight, 0f))); InitialSize = ((data.initialSize == "") ? null : new float?(Parse.Float(data.initialSize, 0f))); InitialShape = data.initialShape; snapGround = data.snapGround; playerHeight = data.playerHeight; highlight = data.highlight; terrainGrid = data.terrainGrid; snapPiece = data.snapPiece; TabIndex = data.tabIndex; targetEdge = data.targetEdge; Index = data.index; Commands = ((data.commands == null) ? GetCommands(data.command) : data.commands.Select((CommandData c) => new CommandValue(c.command, c.keys)).ToList()); Instant = Commands.All((CommandValue c) => !c.Command.Contains("<") && !c.Command.Contains("hammer ")); Instant = ((!data.instant.HasValue) ? Instant : data.instant.Value); RotateWithPlayer = true; foreach (CommandValue command in Commands) { ParseParameters(command.Command); } } public string GetCommand() { IEnumerable<CommandValue> source = Commands.Where((CommandValue c) => c.IsDown()); return string.Join("; ", source.Select((CommandValue c) => c.Command)); } private void ParseParameters(string command) { string[] array = command.Split(new char[1] { ' ' }).ToArray(); for (int i = 0; i < array.Length; i++) { if (array[i].Contains("<id>")) { IsId = true; } if (array[i].Contains("<a>")) { RotateWithPlayer = false; } if (array[i].Contains("<r>")) { Radius = true; } if (array[i].Contains("<r2>")) { Ring = true; } if (array[i].Contains("<w>")) { Width = true; } if (array[i].Contains("<w2>")) { Frame = true; } if (array[i].Contains("<d>")) { Depth = true; } if (array[i].Contains("<h>")) { Height = true; } } } private List<CommandValue> GetCommands(string rawCommand) { string[] array = rawCommand.Split(new char[1] { ';' }); Commands = new List<CommandValue>(); string[] array2 = array; foreach (string text in array2) { int num = text.IndexOf("keys=", StringComparison.Ordinal); if (num == -1) { Commands.Add(new CommandValue(text, "")); continue; } int num2 = text.IndexOf(" ", num + 5, StringComparison.Ordinal); if (num2 == -1) { num2 = text.Length; } string keys = text.Substring(num + 5, num2 - num - 5); string command = text.Substring(0, num - 1) + text.Substring(num2); Commands.Add(new CommandValue(command, keys)); } return Commands; } private static string DisplayKeys(string text) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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) InputBinding val = ((IEnumerable<InputBinding>)(object)ZInput.instance.GetButtonDef("AltPlace").ButtonAction.bindings).FirstOrDefault(); string text2 = ""; text2 = ZInput.instance.MapKeyFromPath(((InputBinding)(ref val)).effectivePath).ToLowerInvariant(); return text.Replace("<mod1>", Configuration.ModifierKey1()).Replace("<mod2>", Configuration.ModifierKey2()).Replace("<alt>", text2); } } public class CommandValue { public string Command = Plain(MultiCommands.Split(ReplaceHelpers(command))); public string[] Keys; public string[] BannedKeys; public CommandValue(string command, string keys) { List<string> list = new List<string>(); list.AddRange(from k in Parse.Split(keys, ',') where k[0] != '-' select k); Keys = list.ToArray(); List<string> list2 = new List<string>(); list2.AddRange(from k in Parse.Split(keys, ',') where k[0] == '-' select k.Substring(1)); BannedKeys = list2.ToArray(); base..ctor(); } public bool IsDown() { if (Keys.All(HammerHelper.IsDown)) { return !BannedKeys.Any(HammerHelper.IsDown); } return false; } private static string ReplaceHelpers(string command) { return command.Replace("hoe_", "tool_").Replace("hammer_command", "").Replace("<area>", "from=<x>,<z>,<y> circle=<r>-<r2> angle=<a> rect=<w>-<w2>,<d> ignore=<ignore> id=<include>") .Replace("<place>", "from=<x>,<z>,<y>") .Replace("<to>", "to=<x>,<z>,<y> circle=<r>-<r2> rect=<w>-<w2>,<d>"); } private static string Plain(string[] commands) { for (int i = 0; i < commands.Length; i++) { commands[i] = Aliasing.Plain(commands[i]); } return string.Join("; ", commands); } } public class InitialData { public static string Get() { return "hammer:\n- name: Pipette\n description: |-\n Press <mod1> to pick up.\n Press <mod2> to freeze.\n icon: hammer\n command: hammer pick=<mod1> freeze=<mod2>\n index: 1\n- name: Building pipette\n description: |-\n Select entire buildings.\n Press <mod1> to pick up.\n Press <mod2> to freeze.\n icon: hammer\n command: hammer connect pick=<mod1> freeze=<mod2>\n- name: Area pipette\n description: |-\n Select multiple objects.\n Press <mod1> to pick up.\n Press <mod2> to freeze.\n icon: hammer\n command: hammer pick=<mod1> freeze=<mod2> height=<h> <area>\n initialHeight: 0\n highlight: true\nhoe:\n- name: Level\n description: |-\n Flattens terrain.\n Hold <mod1> to smooth.\n Hold <mod2> for free mode.\n Hold <alt> for player height.\n icon: mud_road\n command: terrain level smooth=<mod1>?.5:0 <area>\n index: 10\n terrainGrid: -<mod2>\n playerHeight: <alt>\n- name: Raise\n description: |-\n Raises terrain.\n Hold <mod1> to smooth.\n Hold <mod2> for free mode.\n icon: raise\n command: terrain raise=<h> smooth=<mod1>?.5:0 <area>\n initialHeight: 0.2\n terrainGrid: -<mod2>\n snapGround : true\n- name: Pave\n description: |-\n Paves terrain.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: paved_road\n command: terrain paint=paved <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: Grass\n description: |-\n Grass.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: replant\n command: terrain paint=grass <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: Dirt\n description: |-\n Dirt.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: Hoe\n command: terrain paint=dirt <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: Cultivate\n description: |-\n Cultivates terrain.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: cultivate\n command: terrain paint=cultivated <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: DarkGrass\n description: |-\n Dark Grass.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: trophyabomination\n command: terrain paint=grass_dark <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: PatchyGrass\n description: |-\n Patchy Grass.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: iron_wall_2x2\n command: terrain paint=patches <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: MossyPaving\n description: |-\n Paving with moss.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: trophygreydwarfshaman\n command: terrain paint=paved_moss <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: DarkPaving\n description: |-\n Dark Paving.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: tar\n command: terrain paint=paved_dark <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: Reset\n description: |-\n Resets terrain.\n Hold <mod1> for single use.\n Hold <mod2> for free mode.\n icon: Hoe\n command: terrain reset <area>\n continuous: -<mod1>\n terrainGrid: -<mod2>\n snapGround : true\n- name: Slope\n description: Slope between you and aim point.\n icon: wood_wall_roof_45\n command: terrain slope <to>\n targetEdge: true\n initialShape: rectangle\n- name: Remove\n description: |-\n Removes objects.\n Hold <mod1> to also reset the terrain.\n icon: softdeath\n commands:\n - command: object remove id=* <area>\n - command: terrain reset <area>\n keys: <mod1>\n highlight: true\n- name: Tame\n description: |-\n Tames creatures.\n Hold <mod1> to untame\n icon: Carrot\n commands:\n - command: object tame <area>\n keys: -<mod1>\n - command: object wild <area>\n keys: <mod1>\n"; } } public class ToolExportCommand { [CompilerGenerated] private static class <>O { public static ConsoleEvent <0>__Execute; } public ToolExportCommand() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown object obj = <>O.<0>__Execute; if (obj == null) { ConsoleEvent val = Execute; <>O.<0>__Execute = val; obj = (object)val; } Helper.Command("tool_export", "[name] - Exports a tool", (ConsoleEvent)obj); AutoComplete.Register("tool_export", (Func<int, int, List<string>>)((int index, int subIndex) => (from tool in ToolManager.GetAll() select tool.Name).ToList())); } protected static void Execute(ConsoleEventArgs args) { Helper.ArgsCheck(args, 2, "Missing the tool name."); string args2 = HammerHelper.GetArgs("tool_export", args); string text = ToolManager.Export(Hammer.Get(), args2); if (string.IsNullOrEmpty(text)) { HammerHelper.Message(args.Context, "Unable to find the tool " + args2 + "."); return; } GUIUtility.systemCopyBuffer = text; HammerHelper.Message(args.Context, "Exported tool " + args2 + " to the clipboard."); } } public class ToolImportCommand { [CompilerGenerated] private static class <>O { public static ConsoleEvent <0>__Execute; } public ToolImportCommand() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown object obj = <>O.<0>__Execute; if (obj == null) { ConsoleEvent val = Execute; <>O.<0>__Execute = val; obj = (object)val; } Helper.Command("tool_import", "[hammer/hoe/etc[data] - Imports a new tool.", (ConsoleEvent)obj); AutoComplete.Register("tool_import", (Func<int, int, List<string>>)delegate(int index, int subIndex) { if (index == 0) { Dictionary<string, List<Tool>>.KeyCollection keys = ToolManager.Tools.Keys; List<string> list = new List<string>(keys.Count); list.AddRange(keys); return list; } return ParameterInfo.Create("Tool data"); }); } protected static void Execute(ConsoleEventArgs args) { Helper.ArgsCheck(args, 2, "Missing the equipment."); Helper.ArgsCheck(args, 3, "Missing the tool data."); string text = args[1]; string args2 = HammerHelper.GetArgs("tool_import " + text, args); ToolData toolData = ToolManager.Import(text, args2); HammerHelper.Message(args.Context, "Imported tool " + toolData.name + " to " + text + "."); } } [HarmonyPatch] public class ToolManager { public const string CmdMod1 = "<mod1>"; public const string CmdMod2 = "<mod2>"; public const string CmdAlt = "<alt>"; public static string FilePath = Path.Combine(Paths.ConfigPath, "infinity_tools.yaml"); public static string Pattern = "infinity_tools.yaml"; private static Dictionary<string, List<ToolData>> ToolData = new Dictionary<string, List<ToolData>>(); public static Dictionary<string, List<Tool>> Tools = new Dictionary<string, List<Tool>>(); public static void CreateFile() { if (!File.Exists(FilePath)) { File.WriteAllText(FilePath, InitialData.Get()); } } public static void ToFile() { string contents = Yaml.Serializer().Serialize((object)ToolData); File.WriteAllText(FilePath, contents); } public static ToolData Import(string equipment, string tool) { ToolData toolData = Yaml.Deserialize<ToolData>(tool.Replace("\\n", "\n"), "Import"); Add(equipment, toolData); return toolData; } public static void Add(string equipment, ToolData tool) { if (!ToolData.ContainsKey(equipment)) { ToolData.Add(equipment, new List<ToolData>()); } ToolData[equipment].Add(tool); ToFile(); } public static string Export(string equipment, string name) { if (!TryGetToolData(equipment, name, out ToolData tool) && !TryGetToolData(name, out tool, out equipment)) { return ""; } string text = Yaml.Serializer().Serialize((object)tool).Replace("\r\n", "\\n") .Replace("\n", "\\n"); return "tool_import " + equipment + " " + text; } public static bool TryGetTool(string equipment, string name, out Tool tool) { string name2 = name; tool = null; if (Tools.TryGetValue(equipment, out List<Tool> value)) { tool = value.FirstOrDefault((Tool tool) => string.Equals(tool.Name, name2, StringComparison.OrdinalIgnoreCase)); } if (tool == null) { tool = Tools.Values.SelectMany((List<Tool> tool) => tool).FirstOrDefault((Tool tool) => string.Equals(tool.Name, name2, StringComparison.OrdinalIgnoreCase)); } return tool != null; } public static bool TryGetToolData(string equipment, string name, out ToolData tool) { string name2 = name; tool = null; if (ToolData.TryGetValue(equipment, out List<ToolData> value)) { tool = value.FirstOrDefault((ToolData tool) => string.Equals(tool.name, name2, StringComparison.OrdinalIgnoreCase)); return tool != null; } return tool != null; } public static bool TryGetToolData(string name, out ToolData tool, out string equipment) { tool = null; equipment = ""; foreach (KeyValuePair<string, List<ToolData>> toolDatum in ToolData) { foreach (ToolData item in toolDatum.Value) { if (string.Equals(item.name, name, StringComparison.OrdinalIgnoreCase)) { tool = item; equipment = toolDatum.Key; return true; } } } return false; } public static List<Tool> Get(string equipment) { if (!Tools.TryGetValue(equipment, out List<Tool> value)) { return new List<Tool>(); } return value; } public static List<Tool> GetAll() { return Tools.SelectMany<KeyValuePair<string, List<Tool>>, Tool>((KeyValuePair<string, List<Tool>> kvp) => kvp.Value).ToList(); } public static void FromFile() { Dictionary<string, List<ToolData>> dictionary = Yaml.Read<ToolData>(Pattern, (Func<string, string, Dictionary<string, ToolData[]>>)Yaml.Deserialize<Dictionary<string, ToolData[]>>); if (dictionary.Count == 0) { CreateFile(); return; } try { int num = dictionary.Values.SelectMany((List<ToolData> x) => x).Count(); if (num == 0) { Log.Warning("Failed to load any tools."); return; } ToolData = dictionary.ToDictionary((KeyValuePair<string, List<ToolData>> kvp) => kvp.Key.ToLower(), (KeyValuePair<string, List<ToolData>> kvp) => kvp.Value); Tools = dictionary.ToDictionary((KeyValuePair<string, List<ToolData>> kvp) => kvp.Key.ToLower(), (KeyValuePair<string, List<ToolData>> kvp) => kvp.Value.Select((ToolData s) => new Tool(s)).ToList()); Log.Info($"Reloading {num} tools."); Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { localPlayer.UpdateAvailablePiecesList(); } } catch (Exception ex) { Log.Error(ex.StackTrace); } } public static void SetupWatcher() { Yaml.SetupWatcher(Pattern, (Action)FromFile); } } public class ToolShapeCommand { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__0_1; internal void <.ctor>b__0_1(ConsoleEventArgs args) { if (!(Selection.Get() is ToolSelection)) { return; } if (args.Length > 1) { string text = args[1].ToLower(); if (text == RulerShape.Circle.ToString().ToLower()) { Ruler.Shape = RulerShape.Circle; } else if (text == RulerShape.Ring.ToString().ToLower()) { Ruler.Shape = RulerShape.Ring; } else if (text == RulerShape.Rectangle.ToString().ToLower()) { Ruler.Shape = RulerShape.Rectangle; } else if (text == RulerShape.Frame.ToString().ToLower()) { Ruler.Shape = RulerShape.Frame; } else { if (!(text == RulerShape.Square.ToString().ToLower())) { return; } Ruler.Shape = RulerShape.Square; } } else { if (Ruler.Shape == RulerShape.Circle) { Ruler.Shape = RulerShape.Ring; } else if (Ruler.Shape == RulerShape.Ring) { Ruler.Shape = RulerShape.Square; } else if (Ruler.Shape == RulerShape.Square) { Ruler.Shape = RulerShape.Frame; } else if (Ruler.Shape == RulerShape.Frame) { Ruler.Shape = RulerShape.Rectangle; } else if (Ruler.Shape == RulerShape.Rectangle) { Ruler.Shape = RulerShape.Circle; } Ruler.SanityCheckShape(); } HammerHelper.Message(args.Context, $"Selection shape set to {Ruler.Shape}."); } } public ToolShapeCommand() { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected O, but got Unknown List<string> shapes = new List<string>(3) { RulerShape.Circle.ToString(), RulerShape.Rectangle.ToString(), RulerShape.Square.ToString() }; AutoComplete.Register("tool_shape", (Func<int, int, List<string>>)((int index, int subIndex) => (index != 0) ? ParameterInfo.None : shapes)); object obj = <>c.<>9__0_1; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { if (Selection.Get() is ToolSelection) { if (args.Length > 1) { string text = args[1].ToLower(); if (text == RulerShape.Circle.ToString().ToLower()) { Ruler.Shape = RulerShape.Circle; } else if (text == RulerShape.Ring.ToString().ToLower()) { Ruler.Shape = RulerShape.Ring; } else if (text == RulerShape.Rectangle.ToString().ToLower()) { Ruler.Shape = RulerShape.Rectangle; } else if (text == RulerShape.Frame.ToString().ToLower()) { Ruler.Shape = RulerShape.Frame; } else { if (!(text == RulerShape.Square.ToString().ToLower())) { return; } Ruler.Shape = RulerShape.Square; } } else { if (Ruler.Shape == RulerShape.Circle) { Ruler.Shape = RulerShape.Ring; } else if (Ruler.Shape == RulerShape.Ring) { Ruler.Shape = RulerShape.Square; } else if (Ruler.Shape == RulerShape.Square) { Ruler.Shape = RulerShape.Frame; } else if (Ruler.Shape == RulerShape.Frame) { Ruler.Shape = RulerShape.Rectangle; } else if (Ruler.Shape == RulerShape.Rectangle) { Ruler.Shape = RulerShape.Circle; } Ruler.SanityCheckShape(); } HammerHelper.Message(args.Context, $"Selection shape set to {Ruler.Shape}."); } }; <>c.<>9__0_1 = val; obj = (object)val; } Helper.Command("tool_shape", "[shape] - Toggles or sets the selection shape.", (ConsoleEvent)obj); } } public class ConfigurationLegacy { public static ConfigEntry<bool> configShapeCircle; public static ConfigEntry<bool> configShapeRing; public static ConfigEntry<bool> configShapeSquare; public static ConfigEntry<bool> configShapeRectangle; public static ConfigEntry<bool> configShapeFrame; public static ConfigEntry<bool> configShowCommandValues; public static ConfigEntry<KeyboardShortcut> shapeKey; public static ConfigEntry<KeyboardShortcut> commandRadius; public static ConfigEntry<KeyboardShortcut> commandRotate; public static ConfigEntry<KeyboardShortcut> commandDepth; public static ConfigEntry<KeyboardShortcut> commandHeight; public static ConfigEntry<KeyboardShortcut> commandModifier1; public static ConfigEntry<KeyboardShortcut> commandModifier2; public static ConfigEntry<string> commandHeightAmount; public static ConfigWrapper Wrapper; public static bool ShapeCircle => configShapeCircle.Value; public static bool ShapeRing => configShapeRing.Value; public static bool ShapeSquare => configShapeSquare.Value; public static bool ShapeRectangle => configShapeRectangle.Value; public static bool ShapeFrame => configShapeFrame.Value; public static bool AlwaysShowCommand => configShowCommandValues.Value; public static string ModifierKey1() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (commandModifier1 == null) { return "leftalt"; } return ConfigWrapper.GetKeys(commandModifier1.Value); } public static string ModifierKey2() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) if (commandModifier2 == null) { return "leftcontrol"; } return ConfigWrapper.GetKeys(commandModifier2.Value); } public static void Init(ConfigWrapper wrapper) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) Wrapper = wrapper; string group = "1. General"; configShowCommandValues = wrapper.Bind(group, "Show command values", value: false, "Always shows the command in the tool descriptions."); configShapeCircle = wrapper.Bind(group, "Shape circle", value: true, "Enables circle shape for commands."); configShapeRing = wrapper.Bind(group, "Shape ring", value: false, "Enables ring shape for commands."); configShapeRectangle = wrapper.Bind(group, "Shape rectangle", value: true, "Enables rectangle shape for commands."); configShapeSquare = wrapper.Bind(group, "Shape square", value: true, "Enables square shape for commands."); configShapeFrame = wrapper.Bind(group, "Shape frame", value: false, "Enables frame shape for commands."); commandHeightAmount = wrapper.Bind(group, "Command height amount", "0.1", "Meters to move."); group = "2. Binds"; commandModifier1 = wrapper.Bind<KeyboardShortcut>(group, "Command modifier 1", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), ""); commandModifier2 = wrapper.Bind<KeyboardShortcut>(group, "Command modifier 2", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), ""); shapeKey = wrapper.BindCommand("tool_shape", group, "Change shape", new KeyboardShortcut((KeyCode)113, Array.Empty<KeyCode>()), "Changes the selection shape.", "command"); commandRadius = wrapper.BindWheelCommand(() => "hammer_zoom_x " + (Selection.Get().TerrainGrid ? "0.5" : "1"), group, "Command radius (mouse wheel)", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Changes the command radius.", "command"); commandDepth = wrapper.BindWheelCommand(() => "hammer_zoom_z " + (Selection.Get().TerrainGrid ? "0.5" : "1"), group, "Command depth (mouse wheel)", new KeyboardShortcut((KeyCode)304, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Changes the command rectangle depth.", "command"); commandHeight = wrapper.BindWheelCommand(() => "hammer_zoom_y " + commandHeightAmount.Value, group, "Command height (mouse wheel)", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Changes the command height.", "command"); commandRotate = wrapper.BindWheelCommand("hammer_rotate", group, "Command rotation (mouse wheel)", new KeyboardShortcut((KeyCode)304, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Changes the command rotation.", "command"); } } public class ToolSelection : BaseSelection { public Tool Tool; public override float SnapMultiplier => 2f; public override bool IsTool => true; public override bool Continuous => Tool.Continuous; public override bool PlayerHeight => Tool.PlayerHeight; public override bool TerrainGrid => Tool.TerrainGrid; public ToolSelection(Tool tool) { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) Tool = tool; ScalingData scalingData = Scaling.Get(tool: true); if (tool.InitialHeight.HasValue) { scalingData.SetScaleY(tool.InitialHeight.Value); } if (tool.InitialSize.HasValue) { scalingData.SetScaleX(tool.InitialSize.Value); scalingData.SetScaleZ(tool.InitialSize.Value); } if (tool.InitialShape != "") { Ruler.Shape = (Enum.TryParse<RulerShape>(tool.InitialShape, ignoreCase: true, out var result) ? result : RulerShape.Circle); } SelectedPrefab = new GameObject(); Piece obj = SelectedPrefab.AddComponent<Piece>(); obj.m_name = tool.Name; obj.m_icon = tool.Icon; obj.m_description = tool.Description; obj.m_clipEverything = true; if (tool.SnapPiece) { Snapping.CreateSnapPoint(SelectedPrefab, Vector3.zero, "Snap"); } Ruler.Create(tool); } public override float MaxPlaceDistance(float value) { return 1000f; } public override bool IsScalingSupported() { return true; } public override void AfterPlace(GameObject obj) { HandleCommand(obj); } private void HandleCommand(GameObject obj) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) PlacedCommand placedCommand = obj.AddComponent<PlacedCommand>(); Transform transform = HammerHelper.GetPlacementGhost().transform; string newValue = transform.position.x.ToString(CultureInfo.InvariantCulture); string newValue2 = transform.position.y.ToString(CultureInfo.InvariantCulture); string newValue3 = transform.position.z.ToString(CultureInfo.InvariantCulture); ScalingData scalingData = Scaling.Get(); string text = scalingData.X.ToString(CultureInfo.InvariantCulture); string text2 = Mathf.Min(scalingData.X, scalingData.Z).ToString(CultureInfo.InvariantCulture); string text3 = Mathf.Max(scalingData.X, scalingData.Z).ToString(CultureInfo.InvariantCulture); string newValue4 = scalingData.Z.ToString(CultureInfo.InvariantCulture); string text4 = scalingData.X.ToString(CultureInfo.InvariantCulture); RulerShape shape = Ruler.Shape; if (shape == RulerShape.Circle) { text2 = text; text3 = text; } if (shape != RulerShape.Rectangle) { newValue4 = text4; } if (shape == RulerShape.Square) { text2 = text; text3 = text; } if (shape == RulerShape.Rectangle) { text2 = text4; text3 = text4; } string newValue5 = scalingData.Y.ToString(CultureInfo.InvariantCulture); Quaternion rotation = transform.rotation; string newValue6 = ((Quaternion)(ref rotation)).eulerAngles.y.ToString(CultureInfo.InvariantCulture); if (TerrainGrid) { newValue6 = "0"; } string text5 = Tool.GetCommand(); if (text5.Contains("<r>") && (text5.Contains("<w>") || text5.Contains("<d>"))) { text5 = RemoveUnusedShapeParameters(text5, shape); } if (text5.Contains("<id>")) { ZNetView hovered = Selector.GetHovered(Configuration.Range, Array.Empty<string>(), Configuration.IgnoredIds); if ((Object)(object)hovered == (Object)null) { Helper.AddError((Terminal)(object)Console.instance, "Nothing is being hovered.", true); return; } text5 = text5.Replace("<id>", Utils.GetPrefabName(((Component)hovered).gameObject)); } text5 = ((shape != RulerShape.Frame) ? text5.Replace("<d>", newValue4) : text5.Replace("<d>", text2 + "-" + text3)); text5 = text5.Replace("<r>", text); text5 = text5.Replace("<r2>", text3); text5 = text5.Replace("<w>", text4); text5 = text5.Replace("<w2>", text3); text5 = text5.Replace("<a>", newValue6); text5 = text5.Replace("<x>", newValue); text5 = text5.Replace("<y>", newValue2); text5 = text5.Replace("<z>", newValue3); text5 = text5.Replace("<h>", newValue5); text5 = text5.Replace("<ignore>", Configuration.configToolIgnoredIds.Value); text5 = text5.Replace("<include>", Configuration.configToolIncludedIds.Value); if (!Configuration.DisableMessages) { ((Terminal)Console.instance).AddString("Hammering command: " + text5); } placedCommand.Command = text5; } private string RemoveUnusedShapeParameters(string command, RulerShape shape) { bool flag = shape == RulerShape.Circle || shape == RulerShape.Ring; string[] array = MultiCommands.Split(command); for (int i = 0; i < array.Length; i++) { List<string> list = array[i].Split(new char[1] { ' ' }).ToList(); for (int num = list.Count - 1; num > -1; num--) { if (flag && (list[num].Contains("<w>") || list[num].Contains("<d>"))) { list.RemoveAt(num); } if (!flag && list[num].Contains("<r>")) { list.RemoveAt(num); } } array[i] = string.Join(" ", list); } return string.Join("; ", array); } public override void Activate() { base.Activate(); BindCommand.SetMode("command"); Ruler.Create(Tool); } public override void Deactivate() { base.Deactivate(); Ruler.Remove(); BindCommand.SetMode(""); } } public class PlacedCommand : MonoBehaviour { public string Command = ""; public void Start() { if (Command != "") { ((Terminal)Console.instance).TryRunCommand(Command, false, false); } Object.Destroy((Object)(object)((Component)this).gameObject); } } } namespace InfinityHammer { public static class CoverCheck { public const float CoverRayCastLength = 30f; public const float CoverRaycastStart = 0.5f; public const float CoverBedLimit = 0.8f; public const float CoverCraftingStationLimit = 0.7f; public const float CoverFermenterLimit = 0.7f; public const float CoverFireplaceLimit = 0.7f; public const string FORMAT = "0.##"; public static string CurrentCover = ""; public static Vector3 GetCoverPoint(CraftingStation obj) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return obj.m_roofCheckPoint.position; } public static Vector3 GetCoverPoint(Fermenter obj) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return obj.m_roofCheckPoint.position; } public static Vector3 GetCoverPoint(Beehive obj) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return obj.m_coverPoint.position; } public static Vector3 GetCoverPoint(Fireplace obj) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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) return ((Component)obj).transform.position + Vector3.up * obj.m_coverCheckOffset; } public static Vector3 GetCoverPoint(Bed obj) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return obj.GetSpawnPoint(); } public static Vector3 GetCoverPoint(Windmill obj) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return ((Component)obj.m_propeller).transform.position; } public static bool ChecksCover(Fireplace obj) { if ((Object)(object)obj.m_enabledObjectLow != (Object)null) { return (Object)(object)obj.m_enabledObjectHigh != (Object)null; } return false; } public static string String(string value, string color = "white") { return "<color=" + color + ">" + value + "</color>"; } public static string Percent(double value, string color = "white") { return String(value.ToString("P0"), color); } public static string JoinLines(IEnumerable<string> lines) { return string.Join(". ", lines.Where((string line) => line != "")); } public static void CheckCover(GameObject obj) { CurrentCover = ""; GetCover(obj.GetComponent<Beehive>()); GetCover(obj.GetComponent<Fermenter>()); GetCover(obj.GetComponent<Fireplace>()); GetCover(obj.GetComponent<Bed>()); GetCover(obj.GetComponent<CraftingStation>()); GetCover(obj.GetComponent<Windmill>()); } public static void GetCover(Beehive obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), obj.m_maxCover, checkRoof: false, minLimit: false); } } public static void GetCover(Fermenter obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), 0.7f); } } public static void GetCover(Fireplace obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), 0.7f, checkRoof: false); } } public static void GetCover(Bed obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), 0.8f); } } public static void GetCover(CraftingStation obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), 0.7f); } } public static void GetCover(Windmill obj) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)obj)) { GetCover(GetCoverPoint(obj), 0f, checkRoof: false); } } public static void GetCover(Vector3 position, float limit, bool checkRoof = true, bool minLimit = true) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) List<string> list = new List<string>(); float num = default(float); bool flag = default(bool); Cover.GetCoverForPoint(position, ref num, ref flag, 0.5f); string text = Percent(num) + " cover"; if (limit > 0f) { bool flag2 = (minLimit ? (num < limit) : (num > limit)); text = text + " (" + Percent(limit, flag2 ? "yellow" : "white") + ")"; } list.Add(text); if (checkRoof && !flag) { list.Add(String("Missing roof", "yellow")); } CurrentCover = JoinLines(list); } } public class CustomHealth { private static readonly int HashFields = StringExtensionMethods.GetStableHashCode("HasFields"); private static readonly int HashFieldsDestructible = StringExtensionMethods.GetStableHashCode("HasFieldsDestructible"); private static readonly int HashFieldsMineRock = StringExtensionMethods.GetStableHashCode("HasFieldsMineRock"); private static readonly int HashFieldsMineRock5 = StringExtensionMethods.GetStableHashCode("HasFieldsMineRock5"); private static readonly int HashFieldsTreeBase = StringExtensionMethods.GetStableHashCode("HasFieldsTreeBase"); private static readonly int HashFieldsTreeLog = StringExtensionMethods.GetStableHashCode("HasFieldsTreeLog"); private static readonly int HashToolTierDestructible = StringExtensionMethods.GetStableHashCode("Destructible.m_minToolTier"); private static readonly int HashHealthMineRock = StringExtensionMethods.GetStableHashCode("MineRock.m_health"); private static readonly int HashToolTierMineRock = StringExtensionMethods.GetStableHashCode("MineRock.m_minToolTier"); private static readonly int HashToolTierMineRock5 = StringExtensionMethods.GetStableHashCode("MineRock5.m_minToolTier"); private static readonly int HashToolTierTreeBase = StringExtensionMethods.GetStableHashCode("TreeBase.m_minToolTier"); private static readonly int HashToolTierTreeLog = StringExtensionMethods.GetStableHashCode("TreeLog.m_minToolTier"); private static readonly int HashFieldsWearNTear = StringExtensionMethods.GetStableHashCode("HasFieldsWearNTear"); public static readonly int HashMaxHealth = StringExtensionMethods.GetStableHashCode("WearNTear.m_health"); public static float SetHealth(ZNetView obj, bool isRepair) { ZDO zDO = obj.GetZDO(); if (Configuration.Invulnerability == "Off" && Configuration.OverwriteHealth == 0f) { return SetDefaultHealth(obj, zDO, isRepair); } if (Configuration.Invulnerability == "Off" || Configuration.Invulnerability == "Legacy") { return SetCustomHealth(obj, zDO); } return SetInfiniteHealth(obj, zDO); } private static float SetDefaultHealth(ZNetView obj, ZDO zdo, bool isRepair) { if (!isRepair) { return 0f; } float num = 0f; Character character = default(Character); if (((Component)obj).TryGetComponent<Character>(ref character)) { num += SetDefaultHealth(zdo, character); } Destructible destructible = default(Destructible); if (((Component)obj).TryGetComponent<Destructible>(ref destructible)) { num += SetDefaultHealth(zdo, destructible); } TreeBase treeBase = default(TreeBase); if (((Component)obj).TryGetComponent<TreeBase>(ref treeBase)) { num += SetDefaultHealth(zdo, treeBase); } TreeLog treeLog = default(TreeLog); if (((Component)obj).TryGetComponent<TreeLog>(ref treeLog)) { num += SetDefaultHealth(zdo, treeLog); } MineRock mineRock = default(MineRock); if (((Component)obj).TryGetComponent<MineRock>(ref mineRock)) { num += SetDefaultHealth(zdo, mineRock); } MineRock5 mineRock2 = default(MineRock5); if (((Component)obj).TryGetComponent<MineRock5>(ref mineRock2)) { num += SetDefaultHealth(zdo, mineRock2); } WearNTear wear = default(WearNTear); if (((Component)obj).TryGetComponent<WearNTear>(ref wear)) { num += SetDefaultHealth(zdo, wear); } return num; } private static float SetDefaultHealth(ZDO zdo, Destructible destructible) { float @float = zdo.GetFloat(ZDOVars.s_health, destructible.m_health); zdo.RemoveFloat(ZDOVars.s_health); if (