Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PrecisionMoveGizmo v2.0.0
ValheimPrecisionMove.dll
Decompiled 4 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.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ValheimPrecisionMove")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ValheimPrecisionMove")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("7fbe3715-7ec4-4197-bb30-ab56d2875910")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("1.0.0.0")] namespace GemHunter1 { public abstract class BaseMethodHelper { public MethodInfo methodInfo; public BaseMethodHelper(Type type, string name) { methodInfo = type.GetMethod(name, BindingFlags.Instance | BindingFlags.NonPublic); } } public class MethodHelper : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public void Invoke(object instance) { methodInfo.Invoke(instance, Array.Empty<object>()); } } public class MethodHelper<Return> : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public Return Invoke(object instance) { return (Return)methodInfo.Invoke(instance, Array.Empty<object>()); } } public class MethodHelper<Return, T1> : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public Return Invoke(object instance, T1 t1) { return (Return)methodInfo.Invoke(instance, new object[1] { t1 }); } } public class MethodHelper<Return, T1, T2> : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public Return Invoke(object instance, T1 t1, T2 t2) { return (Return)methodInfo.Invoke(instance, new object[2] { t1, t2 }); } } public class MethodHelper<Return, T1, T2, T3> : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public Return Invoke(object instance, T1 t1, T2 t2, T3 t3) { return (Return)methodInfo.Invoke(instance, new object[3] { t1, t2, t3 }); } } public class MethodHelper<Return, T1, T2, T3, T4> : BaseMethodHelper { public MethodHelper(Type type, string name) : base(type, name) { } public Return Invoke(object instance, T1 t1, T2 t2, T3 t3, T4 t4) { return (Return)methodInfo.Invoke(instance, new object[4] { t1, t2, t3, t4 }); } } } namespace ValheimPrecisionMove { public static class ConfigExtensions { private class ActionDisposable : IDisposable { private Action _dispose; public ActionDisposable(Action dispose) { _dispose = dispose; } public void Dispose() { _dispose?.Invoke(); _dispose = null; } } public static DisposeOnDestroy DefaultDispose; public static ConfigEntry<T> Bind<T>(this ConfigFile config, string section, string key, T defaultValue, string description, int order) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0031: Expected O, but got Unknown return config.Bind<T>(new ConfigDefinition(section, key), defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = order } })); } public static IDisposable BindToProperty<TSetting>(this ConfigEntry<TSetting> configEntry, Action<TSetting> setter) { configEntry.SettingChanged += ConfigChanged; setter(configEntry.Value); ActionDisposable actionDisposable = new ActionDisposable(delegate { configEntry.SettingChanged -= ConfigChanged; }); if ((Object)(object)DefaultDispose != (Object)null) { DefaultDispose.Add(actionDisposable); } return actionDisposable; void ConfigChanged(object sender, EventArgs e) { setter(configEntry.Value); } } public static IDisposable BindToProperty<TSetting>(this ConfigEntry<TSetting> configEntry, Action<TSetting> setter, Func<TSetting> getter, Action<Action> subEvent, Action<Action> unsubEvent) { bool isUpdating = false; subEvent(PropertyChanged); configEntry.SettingChanged += ConfigChanged; setter(configEntry.Value); ActionDisposable actionDisposable = new ActionDisposable(delegate { configEntry.SettingChanged -= ConfigChanged; unsubEvent(PropertyChanged); }); if ((Object)(object)DefaultDispose != (Object)null) { DefaultDispose.Add(actionDisposable); } return actionDisposable; void ConfigChanged(object sender, EventArgs e) { if (!isUpdating) { isUpdating = true; setter(configEntry.Value); isUpdating = false; } } void PropertyChanged() { if (!isUpdating) { isUpdating = true; configEntry.Value = getter(); isUpdating = false; } } } } public class ConfigurationManagerAttributes { public int? Order; } public class DisposeOnDestroy : MonoBehaviour { private List<IDisposable> disposables = new List<IDisposable>(); internal void OnDestroy() { foreach (IDisposable disposable in disposables) { disposable?.Dispose(); } } public void Add(IDisposable disposable) { disposables.Add(disposable); } } public enum GizmoAxis { X, Y, Z, XY, XZ, YZ, View, All } public enum GizmoType { TranslateAxis, TranslatePlane, TranslateAll, RotateRing } public class GizmoHandle : MonoBehaviour { public GizmoType handleType; public GizmoAxis axis; public Vector3 customDirection; } public static class GizmoMeshFactory { public static Mesh CreateArrowMesh(float stemLength = 1.2f, float stemRadius = 0.03f, float coneLength = 0.3f, float coneRadius = 0.1f, int segments = 16) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_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_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh(); Vector3[] array = (Vector3[])(object)new Vector3[(segments + 1) * 4 + segments + 2]; int[] array2 = new int[segments * 12]; int num = 0; int num2 = 0; for (int i = 0; i <= segments; i++) { float num3 = (float)i / (float)segments * MathF.PI * 2f; float num4 = Mathf.Cos(num3) * stemRadius; float num5 = Mathf.Sin(num3) * stemRadius; array[num++] = new Vector3(num4, 0f, num5); array[num++] = new Vector3(num4, stemLength, num5); } for (int j = 0; j < segments; j++) { int num6 = j * 2; array2[num2++] = num6; array2[num2++] = num6 + 1; array2[num2++] = num6 + 3; array2[num2++] = num6; array2[num2++] = num6 + 3; array2[num2++] = num6 + 2; } int num7 = num; for (int k = 0; k <= segments; k++) { float num8 = (float)k / (float)segments * MathF.PI * 2f; float num9 = Mathf.Cos(num8) * coneRadius; float num10 = Mathf.Sin(num8) * coneRadius; array[num++] = new Vector3(num9, stemLength, num10); } int num11 = num; array[num++] = new Vector3(0f, stemLength + coneLength, 0f); for (int l = 0; l < segments; l++) { array2[num2++] = num7 + l; array2[num2++] = num11; array2[num2++] = num7 + l + 1; } val.vertices = array; val.triangles = array2; val.RecalculateNormals(); val.RecalculateBounds(); return val; } public static Mesh CreatePlaneMesh(float size = 0.35f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //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) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh(); val.vertices = (Vector3[])(object)new Vector3[4] { new Vector3(0f, 0f, 0f), new Vector3(size, 0f, 0f), new Vector3(size, 0f, size), new Vector3(0f, 0f, size) }; val.triangles = new int[12] { 0, 2, 1, 0, 3, 2, 0, 1, 2, 0, 2, 3 }; val.RecalculateNormals(); val.RecalculateBounds(); return val; } public static Mesh CreateTorusMesh(float radius = 1.2f, float thickness = 0.025f, int segments = 48, int tubeSegments = 12) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Mesh val = new Mesh(); Vector3[] array = (Vector3[])(object)new Vector3[(segments + 1) * (tubeSegments + 1)]; int[] array2 = new int[segments * tubeSegments * 6]; int num = 0; Vector3 val2 = default(Vector3); Vector3 val3 = default(Vector3); for (int i = 0; i <= segments; i++) { float num2 = (float)i / (float)segments * MathF.PI * 2f; ((Vector3)(ref val2))..ctor(Mathf.Cos(num2) * radius, 0f, Mathf.Sin(num2) * radius); for (int j = 0; j <= tubeSegments; j++) { float num3 = (float)j / (float)tubeSegments * MathF.PI * 2f; ((Vector3)(ref val3))..ctor(Mathf.Cos(num2) * Mathf.Cos(num3), Mathf.Sin(num3), Mathf.Sin(num2) * Mathf.Cos(num3)); array[num++] = val2 + val3 * thickness; } } int num4 = 0; for (int k = 0; k < segments; k++) { for (int l = 0; l < tubeSegments; l++) { int num5 = k * (tubeSegments + 1) + l; int num6 = (k + 1) * (tubeSegments + 1) + l; array2[num4++] = num5; array2[num4++] = num6; array2[num4++] = num6 + 1; array2[num4++] = num5; array2[num4++] = num6 + 1; array2[num4++] = num5 + 1; } } val.vertices = array; val.triangles = array2; val.RecalculateNormals(); val.RecalculateBounds(); return val; } public static Mesh CreateCubeMesh() { return Resources.GetBuiltinResource<Mesh>("Cube.fbx"); } public static Mesh CreateSpaceAnchorMesh() { //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_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown Mesh val = new Mesh { name = "SpaceAnchor_1m" }; List<Vector3> vertices = new List<Vector3>(); List<Vector3> normals = new List<Vector3>(); List<Vector2> uvs = new List<Vector2>(); List<int> triangles = new List<int>(); AddBox(Vector3.zero, new Vector3(1f, 0.2f, 0.2f)); AddBox(Vector3.zero, new Vector3(0.2f, 1f, 0.2f)); AddBox(Vector3.zero, new Vector3(0.2f, 0.2f, 1f)); val.SetVertices(vertices); val.SetNormals(normals); val.SetUVs(0, uvs); val.SetTriangles(triangles, 0); val.RecalculateBounds(); return val; void AddBox(Vector3 center, Vector3 size) { //IL_0000: 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) //IL_001a: 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_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_0042: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_011f: 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_0141: Unknown result type (might be due to invalid IL or missing references) float num = size.x * 0.5f; float num2 = size.y * 0.5f; float num3 = size.z * 0.5f; Vector3[] p = (Vector3[])(object)new Vector3[8] { center + new Vector3(0f - num, 0f - num2, 0f - num3), center + new Vector3(num, 0f - num2, 0f - num3), center + new Vector3(num, num2, 0f - num3), center + new Vector3(0f - num, num2, 0f - num3), center + new Vector3(0f - num, 0f - num2, num3), center + new Vector3(num, 0f - num2, num3), center + new Vector3(num, num2, num3), center + new Vector3(0f - num, num2, num3) }; Quad(4, 5, 6, 7, Vector3.forward); Quad(1, 0, 3, 2, Vector3.back); Quad(3, 2, 6, 7, Vector3.up); Quad(4, 5, 1, 0, Vector3.down); Quad(5, 1, 2, 6, Vector3.right); Quad(0, 4, 7, 3, Vector3.left); void Quad(int i0, int i1, int i2, int i3, Vector3 n) { //IL_001c: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_010b: Unknown result type (might be due to invalid IL or missing references) int count = vertices.Count; vertices.Add(p[i0]); vertices.Add(p[i1]); vertices.Add(p[i2]); vertices.Add(p[i3]); normals.Add(n); normals.Add(n); normals.Add(n); normals.Add(n); uvs.Add(new Vector2(0f, 0f)); uvs.Add(new Vector2(1f, 0f)); uvs.Add(new Vector2(1f, 1f)); uvs.Add(new Vector2(0f, 1f)); triangles.Add(count); triangles.Add(count + 2); triangles.Add(count + 1); triangles.Add(count); triangles.Add(count + 3); triangles.Add(count + 2); } } } } public class GizmoPrefabHelper : IDisposable { private const string PREFAB_NAME = "PrecisionMove"; private AssetBundle assetBundle; private GameObject prefab; private GameObject instance; private RuntimeGizmoController gizmoController; public GizmoPrefabHelper() { try { Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ValheimPrecisionMove.precisionmove"); assetBundle = AssetBundle.LoadFromStream(manifestResourceStream); prefab = assetBundle.LoadAsset<GameObject>("PrecisionMove"); if ((Object)(object)prefab != (Object)null) { PrecisionMove.logger.LogMessage((object)"PrecisionMove prefab loaded"); } else { PrecisionMove.logger.LogError((object)"Failed to load PrecisionMove prefab"); } } catch (Exception ex) { PrecisionMove.logger.LogError((object)("Failed to load prefab from assembly resources!\n" + ex.ToString())); } } public RuntimeGizmoController CreateFromPrefab() { if ((Object)(object)prefab == (Object)null) { PrecisionMove.logger.LogMessage((object)"Gizmo prefab is null"); return null; } GameObject val = Object.Instantiate<GameObject>(prefab); ((Object)val).name = "PrecisionMove"; instance = val; gizmoController = val.GetComponent<RuntimeGizmoController>(); if (!Object.op_Implicit((Object)(object)gizmoController)) { PrecisionMove.logger.LogError((object)"Failed to get RuntimeGizmoController from prefab"); return null; } PrecisionMove.logger.LogMessage((object)"Created gizmo from prefab"); return gizmoController; } public void Dispose() { if (Object.op_Implicit((Object)(object)instance)) { Object.Destroy((Object)(object)instance); } if ((Object)(object)assetBundle != (Object)null) { assetBundle.Unload(true); } gizmoController = null; instance = null; prefab = null; assetBundle = null; } } public interface IUndoCommand { void Undo(); void Redo(); } public class GizmoUndoManager : MonoBehaviour { [Header("References")] public RuntimeGizmoController gizmoController; [Header("Undo Settings")] public int maxUndoSteps = 30; [Header("Hotkeys")] public Key undoKey = (Key)7; public Key redoKey = (Key)8; private readonly LinkedList<IUndoCommand> undoStack = new LinkedList<IUndoCommand>(); private readonly Stack<IUndoCommand> redoStack = new Stack<IUndoCommand>(); public void RegisterCommand(IUndoCommand command) { if (command != null) { undoStack.AddLast(command); redoStack.Clear(); while (undoStack.Count > maxUndoSteps) { undoStack.RemoveFirst(); } } } public bool CanUndo() { return undoStack.Count > 0; } public bool CanRedo() { return redoStack.Count > 0; } public void Undo() { if (undoStack.Count != 0) { IUndoCommand value = undoStack.Last.Value; undoStack.RemoveLast(); value.Undo(); redoStack.Push(value); } } public void Redo() { if (redoStack.Count != 0) { IUndoCommand undoCommand = redoStack.Pop(); undoCommand.Redo(); undoStack.AddLast(undoCommand); } } public void RecordTransformChange(List<ISelectedObject> objects, Dictionary<ISelectedObject, Vector3> startPos, Dictionary<ISelectedObject, Quaternion> startRot) { //IL_004a: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) if (objects == null || objects.Count == 0) { return; } List<TransformUndoData> list = new List<TransformUndoData>(); bool flag = false; foreach (ISelectedObject @object in objects) { if (@object != null) { Transform transform = @object.GetTransform(); Vector3 val = (startPos.ContainsKey(@object) ? startPos[@object] : transform.position); Quaternion val2 = (startRot.ContainsKey(@object) ? startRot[@object] : transform.rotation); if (Vector3.Distance(val, transform.position) > 0.0001f || Quaternion.Angle(val2, transform.rotation) > 0.01f) { flag = true; } list.Add(new TransformUndoData { Target = @object, StartPos = val, StartRot = val2, EndPos = transform.position, EndRot = transform.rotation }); } } if (flag) { RegisterCommand(new TransformUndoCommand(list)); } } public void RecordSelectionChange(List<ISelectedObject> previousSelection, List<ISelectedObject> newSelection) { bool flag = previousSelection.Count != newSelection.Count; if (!flag) { for (int i = 0; i < previousSelection.Count; i++) { if (previousSelection[i] != newSelection[i]) { flag = true; break; } } } if (flag) { RegisterCommand(new SelectionUndoCommand(gizmoController, previousSelection, newSelection)); } } } public struct TransformUndoData { public ISelectedObject Target; public Vector3 StartPos; public Quaternion StartRot; public Vector3 EndPos; public Quaternion EndRot; } public class TransformUndoCommand : IUndoCommand { private readonly List<TransformUndoData> dataList; public TransformUndoCommand(List<TransformUndoData> data) { dataList = data; } public void Undo() { //IL_0025: 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) foreach (TransformUndoData data in dataList) { if (data.Target != null) { data.Target.SetPosition(data.StartPos); data.Target.SetRotation(data.StartRot); } } } public void Redo() { //IL_0025: 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) foreach (TransformUndoData data in dataList) { if (data.Target != null) { data.Target.SetPosition(data.EndPos); data.Target.SetRotation(data.EndRot); } } } } public class SelectionUndoCommand : IUndoCommand { private readonly RuntimeGizmoController gizmoController; private readonly List<ISelectedObject> oldSelection; private readonly List<ISelectedObject> newSelection; public SelectionUndoCommand(RuntimeGizmoController gizmoController, List<ISelectedObject> oldSelection, List<ISelectedObject> newSelection) { this.gizmoController = gizmoController; this.oldSelection = new List<ISelectedObject>(oldSelection); this.newSelection = new List<ISelectedObject>(newSelection); } public void Undo() { ApplySelection(oldSelection); } public void Redo() { ApplySelection(newSelection); } private void ApplySelection(List<ISelectedObject> selection) { gizmoController.selectionManager.ClearSelection(); if (Object.op_Implicit((Object)(object)gizmoController.selectionOutline)) { gizmoController.selectionOutline.OnSelectionCleared(RuntimeScreenSpaceOutline.Index.Primary, 0L); if (selection.Count == 0) { ((Behaviour)gizmoController.selectionOutline).enabled = false; } } foreach (ISelectedObject item in selection) { if (item != null) { gizmoController.selectionManager.AddToSelection(item.GetTransform()); if (Object.op_Implicit((Object)(object)gizmoController.selectionOutline) && gizmoController.IsSelectionOutlineEnabled) { ((Behaviour)gizmoController.selectionOutline).enabled = true; gizmoController.selectionOutline.OnObjectAdded(((Component)item.GetTransform()).gameObject, RuntimeScreenSpaceOutline.Index.Primary, 0L); } } } } } public interface ILoggerAdapter { void Log(object message); void LogWarning(object message); void LogError(object message); } public class DefaultLoggerAdapter : ILoggerAdapter { public void Log(object message) { Debug.Log(message); } public void LogWarning(object message) { Debug.LogWarning(message); } public void LogError(object message) { Debug.LogError(message); } } public abstract class PooledFactory<TInterface, TConcrete> where TConcrete : class, TInterface { private readonly Stack<TConcrete> _pool = new Stack<TConcrete>(); protected abstract TConcrete CreateInstance(); protected abstract void OnGet(TConcrete instance); protected abstract void OnRelease(TConcrete instance); public TInterface Get() { TConcrete val = ((_pool.Count <= 0) ? CreateInstance() : _pool.Pop()); OnGet(val); return (TInterface)val; } public void Release(TInterface item) { if (item is TConcrete val) { OnRelease(val); _pool.Push(val); } } } [BepInPlugin("GemHunter1.PrecisionMoveGizmo", "Precision Move Gizmo", "2.0.0")] public class PrecisionMove : BaseUnityPlugin { public enum ZDOAction { Move, Rotate, Scale } public enum ZDOSelectionAction { Deselect, Select, Clear } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] internal class GameCamera_UpdateMouseCaputre_Patch { public static bool Prefix() { //IL_0058: 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_0044: Invalid comparison between Unknown and I4 if (Keyboard.current == null || (Object)(object)Player.m_localPlayer == (Object)null) { _isMouseInteractPressed = false; return true; } ItemData val = Player_GetRightItem(Player.m_localPlayer); if (val == null || (val.m_equipped && (int)val.m_shared.m_itemType != 19)) { _isMouseInteractPressed = false; return true; } if (((ButtonControl)Keyboard.current[keybindEnableMouseInteract.Value]).isPressed) { ZCursor.LockState = (CursorLockMode)0; ZCursor.Show(); _isMouseInteractPressed = true; return false; } _isMouseInteractPressed = false; return true; } } [HarmonyPatch(typeof(GameCamera), "Awake")] internal class GameCamera_Awake_Patch { public static void Postfix(Camera ___m_camera) { _gameCamera = ___m_camera; if (Object.op_Implicit((Object)(object)instance.gizmoController)) { instance.gizmoController.mainCamera = _gameCamera; } } } [HarmonyPatch(typeof(WearNTear), "OnPlaced")] internal class WearNTear_OnPlaced_Patch { public static void Postfix(WearNTear __instance) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) if (IsDuplicating) { DuplicatingObjects.Add(((Component)__instance).transform); if (Object.op_Implicit((Object)(object)CurrentlyDuplicatedPiece)) { ZDO zDO = ((Component)__instance).gameObject.GetComponent<ZNetView>().GetZDO(); ((Component)__instance).transform.position = ((Component)CurrentlyDuplicatedPiece).transform.position; ((Component)__instance).transform.rotation = ((Component)CurrentlyDuplicatedPiece).transform.rotation; zDO.SetPosition(((Component)__instance).transform.position); zDO.SetRotation(((Component)__instance).transform.rotation); } } } } [HarmonyPatch(typeof(WearNTear), "HaveSupport")] internal class WearNTear_HaveSupport_Patch { public static bool Prefix(ref bool __result, WearNTear __instance) { if (Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)instance) && instance.HasSelection && instance.IsObjectSelected(((Component)__instance).gameObject)) { __result = true; return false; } return true; } } [HarmonyPatch(typeof(PlayerController), "LateUpdate")] internal class PlayerController_LateUpdate_Patch { public static bool Prefix() { return !_isMouseInteractPressed; } } [HarmonyPatch(typeof(GameCamera), "UpdateCamera")] internal class GameCamera_UpdateCamera_Patch { public static bool Prefix() { return !_isMouseInteractPressed; } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] internal class Player_UpdatePlacement_Patch { public static bool Prefix(Player __instance, ref Piece ___m_hoveringPiece, ref int ___m_removeRayMask) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) if (instance.HasActiveOrHoverGizmoHandle) { ___m_hoveringPiece = null; return false; } if (_isMouseInteractPressed) { if (Object.op_Implicit((Object)(object)_gameCamera) && Mouse.current != null) { Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue(); Ray val2 = _gameCamera.ScreenPointToRay(Vector2.op_Implicit(val)); ___m_hoveringPiece = null; RaycastHit val3 = default(RaycastHit); if (!Physics.Raycast(val2, ref val3, 50f, ___m_removeRayMask) || Vector3.Distance(((Character)__instance).m_eye.position, ((RaycastHit)(ref val3)).point) >= __instance.m_maxPlaceDistance) { return false; } Piece componentInParent = ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<Piece>(); if (!Object.op_Implicit((Object)(object)componentInParent)) { return false; } WearNTear component = ((Component)componentInParent).GetComponent<WearNTear>(); if (!Object.op_Implicit((Object)(object)component)) { return false; } component.Highlight(); } return false; } return true; } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] internal class Player_UpdatePlacementGhost_Patch { public static void Postfix(ref GameObject ___m_placementGhost) { if ((instance.HasActiveOrHoverGizmoHandle || _isMouseInteractPressed) && Object.op_Implicit((Object)(object)___m_placementGhost)) { ___m_placementGhost.SetActive(false); } } } [HarmonyPatch(typeof(Player), "Awake")] internal class Player_Awake_Patch { public static void Postfix(Player __instance, ZNetView ___m_nview) { try { if (!((Object)(object)__instance == (Object)(object)Player.m_localPlayer)) { if (Object.op_Implicit((Object)(object)___m_nview) && (Object)(object)ZNet.instance != (Object)null && ___m_nview.IsValid()) { long owner = ___m_nview.GetZDO().GetOwner(); instance._playerNetIDs.Add(__instance, owner); logger.LogInfo((object)$"Player {__instance.GetPlayerName()} has network ID: {owner}"); } else { logger.LogWarning((object)"Player ZNetView is not valid"); } } } catch (Exception ex) { logger.LogError((object)ex); } } } [HarmonyPatch(typeof(Player), "OnDestroy")] internal class Player_OnDestroy_Patch { public static void Prefix(Player __instance) { try { if (!((Object)(object)__instance == (Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.gizmoController)) { if (instance._playerNetIDs.TryGetValue(__instance, out var value)) { logger.LogInfo((object)$"Player {value} destroyed, clearing their selection"); instance.gizmoController.selectionManager.ClearSecondarySelection(value); } else { logger.LogWarning((object)"Player network ID not found in dictionary"); } } } catch (Exception ex) { logger.LogError((object)ex); } } } [HarmonyPatch(typeof(Game), "Start")] internal class Game_Start_Patch { public static void Prefix() { try { _onGameStart?.Invoke(); } catch (Exception ex) { logger.LogError((object)("Failed to perform onGameStart event: " + ex)); } } } [HarmonyPatch(typeof(Hud), "Awake")] public static class HUD_Awake_Patch { public static void Postfix(Hud __instance) { if ((Object)(object)__instance.m_hoverName != (Object)null) { ((Graphic)__instance.m_hoverName).raycastTarget = false; } else { logger.LogError((object)"Failed to patch HoverName text to not be raycast target"); } } } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static PopupButtonCallback <>9__78_1; public static Func<ISelectedObject, WearNTear> <>9__79_0; public static Func<WearNTear, bool> <>9__79_1; public static Func<ISelectedObject, GameObject> <>9__80_2; public static PopupButtonCallback <>9__80_1; public static Func<Piece, IEnumerable<Requirement>> <>9__84_0; public static Func<Requirement, string> <>9__84_1; public static Func<int, Requirement, int> <>9__84_3; public static Func<IGrouping<string, Requirement>, (string Name, int Count)> <>9__84_2; public static Func<ISelectedObject, Piece> <>9__85_0; public static Func<Piece, bool> <>9__85_1; public static Func<Piece, string> <>9__85_2; internal void <ResetSelectedPieces>b__78_1() { UnifiedPopup.Pop(); } internal WearNTear <RepairSelectedPieces>b__79_0(ISelectedObject x) { return ((Component)x.GetTransform()).gameObject.GetComponent<WearNTear>(); } internal bool <RepairSelectedPieces>b__79_1(WearNTear x) { return (Object)(object)x != (Object)null; } internal GameObject <DeleteSelectedPieces>b__80_2(ISelectedObject x) { return ((Component)x.GetTransform()).gameObject; } internal void <DeleteSelectedPieces>b__80_1() { UnifiedPopup.Pop(); } internal IEnumerable<Requirement> <HasAllRequirements>b__84_0(Piece x) { return x.m_resources; } internal string <HasAllRequirements>b__84_1(Requirement x) { return x.m_resItem.m_itemData.m_shared.m_name; } internal (string Name, int Count) <HasAllRequirements>b__84_2(IGrouping<string, Requirement> x) { return (Name: x.Key, Count: x.Aggregate(0, (int a, Requirement b) => a + b.m_amount)); } internal int <HasAllRequirements>b__84_3(int a, Requirement b) { return a + b.m_amount; } internal Piece <DuplicateSelectedPieces>b__85_0(ISelectedObject x) { return ((Component)x.GetTransform()).gameObject.GetComponent<Piece>(); } internal bool <DuplicateSelectedPieces>b__85_1(Piece x) { return (Object)(object)x != (Object)null; } internal string <DuplicateSelectedPieces>b__85_2(Piece x) { return x.m_name; } } private readonly Harmony harmony = new Harmony("GemHunter1.PrecisionMoveGizmo"); internal static ManualLogSource logger; internal static PrecisionMove instance; private const string GENERAL = "1 - General"; private const string OUTLINE = "2 - Outline"; private const string KEYBINDS = "3 - Keybinds"; private const string KEYBINDS_MOVEPAD = "4 - Keybinds Move"; private const string CURRENT_SETTINGS = "Z - Current Settings"; private const string RPC_ON_SELECTION_CHANGED = "PM_OnSelectionChanged"; private const string RPC_UPDATE_PIECE_POSITION = "PM_UpdatePiecePosition"; public static ConfigEntry<bool> boxSelectEnabled; public static ConfigEntry<bool> allowSelectAllLayersEnabled; public static ConfigEntry<bool> showUIWhenSelected; public static ConfigEntry<bool> viewAxisRotateEnabled; public static ConfigEntry<bool> viewAxisIsAllAxisRotateEnabled; public static ConfigEntry<decimal> maxInteractionDistance; public static ConfigEntry<decimal> gizmoHandleSize; public static ConfigEntry<decimal> uiCanvasScaleBias; public static ConfigEntry<bool> outlineEnabled; public static ConfigEntry<bool> outlineSecondaryEnabled; public static ConfigEntry<Color> outlineColor; public static ConfigEntry<Color> outlineSecondaryColor; public static ConfigEntry<int> outlineWidth; public static ConfigEntry<decimal> outlineDepthBias; public static ConfigEntry<Key> keybindEnableMouseInteract; public static ConfigEntry<Key> keybindToggleToolMode; public static ConfigEntry<Key> keybindTogglePivotMode; public static ConfigEntry<Key> keybindToggleTransformMode; public static ConfigEntry<Key> keybindToggleSnap; public static ConfigEntry<KeyboardShortcut> keybindUndo; public static ConfigEntry<KeyboardShortcut> keybindRedo; public static ConfigEntry<KeyboardShortcut> keybindReset; public static ConfigEntry<KeyboardShortcut> keybindDelete; public static ConfigEntry<KeyboardShortcut> keybindDuplicate; public static ConfigEntry<KeyboardShortcut> keybindRepair; public static ConfigEntry<bool> keybindNumpadEnabled; public static ConfigEntry<Key> keybindNumpadSelect; public static ConfigEntry<Key> keybindNumpadXUp; public static ConfigEntry<Key> keybindNumpadXDown; public static ConfigEntry<Key> keybindNumpadYUp; public static ConfigEntry<Key> keybindNumpadYDown; public static ConfigEntry<Key> keybindNumpadZUp; public static ConfigEntry<Key> keybindNumpadZDown; public static ConfigEntry<decimal> snapStepsMove; public static ConfigEntry<decimal> snapStepsRotate; public static ConfigEntry<bool> snapEnabled; public static ConfigEntry<RuntimeGizmoController.EToolMode> toolMode; public static ConfigEntry<RuntimeGizmoController.EPivotMode> pivotMode; public static ConfigEntry<RuntimeGizmoController.ETransformSpace> transformMode; private static Action _onGameStart; private static bool _isMouseInteractPressed = false; private static Camera _gameCamera; private GizmoPrefabHelper gizmoHelper; private RuntimeGizmoController gizmoController; private Canvas gizmoCanvas; private CanvasScaler gizmoCanvasScaler; internal static Func<Player, ItemData> Player_GetRightItem = AccessTools.MethodDelegate<Func<Player, ItemData>>(AccessTools.Method(typeof(Player), "GetRightItem", (Type[])null, (Type[])null), (object)null, true); internal static Action<WearNTear> WearNTear_UpdateSupport = AccessTools.MethodDelegate<Action<WearNTear>>(AccessTools.Method(typeof(WearNTear), "UpdateSupport", (Type[])null, (Type[])null), (object)null, true); internal static Action<WearNTear> WearNTear_ClearCachedSupport = AccessTools.MethodDelegate<Action<WearNTear>>(AccessTools.Method(typeof(WearNTear), "ClearCachedSupport", (Type[])null, (Type[])null), (object)null, true); internal static Action<WearNTear> WearNTear_SetupColliders = AccessTools.MethodDelegate<Action<WearNTear>>(AccessTools.Method(typeof(WearNTear), "SetupColliders", (Type[])null, (Type[])null), (object)null, true); internal static FieldRef<WearNTear, bool> WearNTear_m_clearCachedSupport = AccessTools.FieldRefAccess<WearNTear, bool>("m_clearCachedSupport"); internal static FieldRef<Player, ZSyncAnimation> Player_m_zanim = AccessTools.FieldRefAccess<Player, ZSyncAnimation>("m_zanim"); internal static FieldRef<Player, Inventory> Player_m_inventory = AccessTools.FieldRefAccess<Player, Inventory>("m_inventory"); private static bool IsDuplicating = false; private static List<Transform> DuplicatingObjects = new List<Transform>(); private static Piece CurrentlyDuplicatedPiece = null; private Dictionary<Player, long> _playerNetIDs = new Dictionary<Player, long>(); private float GuiScale => AccessTools.StaticFieldRefAccess<GuiScaler, float>("m_largeGuiScale"); private bool HasActiveOrHoverGizmoHandle { get { if (!((Object)(object)gizmoController != (Object)null)) { return false; } if (!gizmoController.HasActiveGizmoHandle) { return gizmoController.HasHoverGizmoHandle; } return true; } } private bool HasSelection { get { if (!((Object)(object)gizmoController != (Object)null)) { return false; } return gizmoController.SelectedObjects.Count > 0; } } private bool IsObjectSelected(GameObject go) { if (!((Object)(object)gizmoController != (Object)null)) { return false; } return gizmoController.SelectedObjects.Any((ISelectedObject x) => (Object)(object)((Component)x.GetTransform()).gameObject == (Object)(object)go); } internal void Awake() { //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0394: Unknown result type (might be due to invalid IL or missing references) //IL_03c7: Unknown result type (might be due to invalid IL or missing references) //IL_03f7: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) logger = ((BaseUnityPlugin)this).Logger; instance = this; harmony.PatchAll(); int num = 999; boxSelectEnabled = ((BaseUnityPlugin)this).Config.Bind("1 - General", "Box Select Enabled", defaultValue: true, "Is box selection with dragging cursor enabled", num--); allowSelectAllLayersEnabled = ((BaseUnityPlugin)this).Config.Bind("1 - General", "Allow Selecting Pieces On All Layers", defaultValue: true, "Allow selecting all pieces on all layers (such as ships and some fireplaces)", num--); showUIWhenSelected = ((BaseUnityPlugin)this).Config.Bind("1 - General", "Show UI Only When Selected", defaultValue: true, "Show UI only when there is any piece selected", num--); uiCanvasScaleBias = ((BaseUnityPlugin)this).Config.Bind("1 - General", "UI Canvas Scale", 1m, "Canvas scale for UI", num--); gizmoHandleSize = ((BaseUnityPlugin)this).Config.Bind("1 - General", "Gizmo Handle Size", 0.15m, "Size of the transform gizmo", num--); maxInteractionDistance = ((BaseUnityPlugin)this).Config.Bind("1 - General", "Max Interaction Distance", 50m, "Maximum interaction distance to piece (meters)", num--); viewAxisRotateEnabled = ((BaseUnityPlugin)this).Config.Bind("1 - General", "View Axis Rotate Handle Enabled", defaultValue: false, "Is gizmo handle for rotating in game camera view axis enabled", num--); viewAxisIsAllAxisRotateEnabled = ((BaseUnityPlugin)this).Config.Bind("1 - General", "View Axis Is All Axis Rotate (EXPERIMENTAL)", defaultValue: false, "The view axis handle will rotate in all 3 directions (trackball). SNAPPING DOES NOT WORK WITH THIS", num--); outlineEnabled = ((BaseUnityPlugin)this).Config.Bind("2 - Outline", "Selection Outline Enabled", defaultValue: true, "Is selection outline enabled", num--); outlineColor = ((BaseUnityPlugin)this).Config.Bind<Color>("2 - Outline", "Outline Color", new Color(1f, 0.5f, 0f, 1f), "Outline color", num--); outlineSecondaryEnabled = ((BaseUnityPlugin)this).Config.Bind("2 - Outline", "Selection Outline Of Other Players Enabled", defaultValue: true, "Is selection outline of objects selected by other players enabled", num--); outlineSecondaryColor = ((BaseUnityPlugin)this).Config.Bind<Color>("2 - Outline", "Outline Secondary Color", new Color(0f, 0.5f, 1f, 0.5f), "Outline color for objects selected by other players", num--); outlineWidth = ((BaseUnityPlugin)this).Config.Bind("2 - Outline", "Outline Pixel Width", 2, "Outline width", num--); outlineDepthBias = ((BaseUnityPlugin)this).Config.Bind("2 - Outline", "Outline Depth Bias", 0.005m, "Depth bias for occluded selection outline", num--); keybindEnableMouseInteract = ((BaseUnityPlugin)this).Config.Bind<Key>("3 - Keybinds", "Keybind Mouse Interact", (Key)53, "Keybind for unlocking mouse for selecting build piece and UI interaction", num--); keybindToggleToolMode = ((BaseUnityPlugin)this).Config.Bind<Key>("3 - Keybinds", "Keybind Toggle Tool Mode", (Key)70, "Keybind for toggling tool mode (Move, Rotate, Multi)", num--); keybindTogglePivotMode = ((BaseUnityPlugin)this).Config.Bind<Key>("3 - Keybinds", "Keybind Toggle Pivot Mode", (Key)68, "Keybind for toggling pivot mode (Pivot, Center)", num--); keybindToggleTransformMode = ((BaseUnityPlugin)this).Config.Bind<Key>("3 - Keybinds", "Keybind Toggle Transform Mode", (Key)67, "Keybind for toggling transform mode (Local, World)", num--); keybindToggleSnap = ((BaseUnityPlugin)this).Config.Bind<Key>("3 - Keybinds", "Keybind Toggle Snapping", (Key)66, "Keybind for toggling grid snapping", num--); keybindUndo = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Undo", new KeyboardShortcut((KeyCode)122, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Keybind for toggling grid snapping", num--); keybindRedo = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Redo", new KeyboardShortcut((KeyCode)122, (KeyCode[])(object)new KeyCode[2] { (KeyCode)304, (KeyCode)306 }), "Keybind for toggling grid snapping", num--); keybindReset = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Reset", new KeyboardShortcut((KeyCode)279, Array.Empty<KeyCode>()), "Keybind to reset position/rotation back to state at the time of selection", num--); keybindDelete = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Destroy", new KeyboardShortcut((KeyCode)127, Array.Empty<KeyCode>()), "Keybind for destroying selected build pieces", num--); keybindDuplicate = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Duplicate", new KeyboardShortcut((KeyCode)100, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Keybind for duplicating selected build pieces", num--); keybindRepair = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("3 - Keybinds", "Keybind Repair", new KeyboardShortcut((KeyCode)91, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Keybind for duplicating selected build pieces", num--); keybindNumpadEnabled = ((BaseUnityPlugin)this).Config.Bind("4 - Keybinds Move", "Keybinds for Move Enabled", defaultValue: true, "Are all these keybinds in this category enabled", num--); keybindNumpadSelect = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind Select", (Key)84, "Keybind for selecting pieces", num--); keybindNumpadXUp = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind XUp", (Key)90, "Keybind for X axis up/right (Red)", num--); keybindNumpadXDown = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind XDown", (Key)88, "Keybind for X axis down/left (Red)", num--); keybindNumpadYUp = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind YUp", (Key)93, "Keybind for Y axis up (Green)", num--); keybindNumpadYDown = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind YDown", (Key)91, "Keybind for Y axis down (Green)", num--); keybindNumpadZUp = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind ZUp", (Key)92, "Keybind for Z axis up/forward (Blue)", num--); keybindNumpadZDown = ((BaseUnityPlugin)this).Config.Bind<Key>("4 - Keybinds Move", "Keybind ZDown", (Key)89, "Keybind for Z axis down/back (Blue)", num--); toolMode = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Tool Mode", RuntimeGizmoController.EToolMode.Multi, "Current tool mode", num--); pivotMode = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Pivot Mode", RuntimeGizmoController.EPivotMode.Pivot, "Current pivot mode", num--); transformMode = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Transform Mode", RuntimeGizmoController.ETransformSpace.Local, "Current transform mode", num--); snapEnabled = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Snap Enabled", defaultValue: true, "Grid snapping enabled", num--); snapStepsMove = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Movement Grid Steps", 0.1m, "Movement grid snapping granularity [m]", num--); snapStepsRotate = ((BaseUnityPlugin)this).Config.Bind("Z - Current Settings", "Rotation Grid Steps", 32m, "Rotation grid snapping granularity [360°/x]", num--); gizmoHelper = new GizmoPrefabHelper(); _onGameStart = delegate { ZRoutedRpc.instance.Register<ZPackage>("PM_UpdatePiecePosition", (Action<long, ZPackage>)RPC_UpdatePiecePosition); ZRoutedRpc.instance.Register<ZPackage>("PM_OnSelectionChanged", (Action<long, ZPackage>)RPC_OnSelectionChanged); if (!Object.op_Implicit((Object)(object)gizmoController)) { gizmoController = gizmoHelper.CreateFromPrefab(); } if (!Object.op_Implicit((Object)(object)gizmoController)) { logger.LogError((object)"Failed to create RuntimeGizmoController"); } else { RuntimeGizmoController.logger = new ValheimLoggerAdatper(logger); gizmoCanvas = ((Component)gizmoController).GetComponentInChildren<Canvas>(true); gizmoCanvasScaler = ((Component)gizmoController).GetComponentInChildren<CanvasScaler>(true); ((Component)gizmoController).gameObject.SetActive(false); gizmoController.IsObjectSelectionEnabled = false; gizmoController.selectionManager.SetObjectSelector(new ValheimPieceObjectSelector(), new ValheimSelectedObjectFactory()); gizmoController.OnDeleteClicked += DeleteSelectedPieces; gizmoController.OnDuplicateClicked += DuplicateSelectedPieces; gizmoController.OnRepairClicked += RepairSelectedPieces; gizmoController.OnResetClicked += ResetSelectedPieces; gizmoController.selectionManager.OnSelectionCleared += OnSelectionCleared; gizmoController.selectionManager.OnSelectionAboutToBeCleared += OnSelectionAboutToBeCleared; ConfigExtensions.DefaultDispose = ((Component)gizmoController).gameObject.AddComponent<DisposeOnDestroy>(); boxSelectEnabled.BindToProperty(delegate(bool val) { gizmoController.selectionManager.enableBoxSelection = val; }); allowSelectAllLayersEnabled.BindToProperty(delegate(bool val) { gizmoController.selectionManager.AllowSelectingAllLayers = val; }); viewAxisRotateEnabled.BindToProperty(delegate(bool val) { gizmoController.IsViewAxisRotationEnabled = val; }); viewAxisIsAllAxisRotateEnabled.BindToProperty(delegate(bool val) { gizmoController.AllAxisRotationEnabled = val; }); maxInteractionDistance.BindToProperty(delegate(decimal val) { gizmoController.maxGizmoInteractDistance = (float)val; }); maxInteractionDistance.BindToProperty(delegate(decimal val) { gizmoController.selectionManager.maxSelectionDistance = (float)val; }); gizmoHandleSize.BindToProperty(delegate(decimal val) { gizmoController.handleScaleFactor = (float)val; }); outlineEnabled.BindToProperty(delegate(bool val) { gizmoController.IsSelectionOutlineEnabled = val; }); outlineColor.BindToProperty(delegate(Color val) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) gizmoController.selectionOutline.SetColor(val); }); outlineWidth.BindToProperty(delegate(int val) { gizmoController.selectionOutline.SetWidth(val); }); outlineDepthBias.BindToProperty(delegate(decimal val) { gizmoController.selectionOutline.SetDepthBias((float)val); }); outlineSecondaryEnabled.BindToProperty(delegate(bool val) { gizmoController.IsSecondarySelectionOutlineEnabled = val; if (!val) { gizmoController.selectionOutline.OnSelectionCleared(RuntimeScreenSpaceOutline.Index.Secondary, 0L); } }); outlineSecondaryColor.BindToProperty(delegate(Color val) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) gizmoController.selectionOutline.SetSecondaryColor(val); }); uiCanvasScaleBias.BindToProperty(delegate(decimal val) { try { float scaleFactor = (float)val * GuiScale; gizmoCanvasScaler.scaleFactor = scaleFactor; } catch (Exception ex) { logger.LogError((object)("Failed to set gizmo canvas scale: " + ex)); } }); Action<Action> subEvent = delegate(Action evt) { gizmoController.ModeSettingsChanged += evt; }; Action<Action> unsubEvent = delegate(Action evt) { gizmoController.ModeSettingsChanged -= evt; }; toolMode.BindToProperty(delegate(RuntimeGizmoController.EToolMode val) { gizmoController.ToolMode = val; }, () => gizmoController.ToolMode, subEvent, unsubEvent); pivotMode.BindToProperty(delegate(RuntimeGizmoController.EPivotMode val) { gizmoController.PivotMode = val; }, () => gizmoController.PivotMode, subEvent, unsubEvent); transformMode.BindToProperty(delegate(RuntimeGizmoController.ETransformSpace val) { gizmoController.TransformSpace = val; }, () => gizmoController.TransformSpace, subEvent, unsubEvent); snapEnabled.BindToProperty(delegate(bool val) { gizmoController.SnapModeEnabled = val; }, () => gizmoController.SnapModeEnabled, subEvent, unsubEvent); snapStepsMove.BindToProperty(delegate(decimal val) { gizmoController.MoveSnapSize = (float)val; }, () => (decimal)gizmoController.MoveSnapSize, subEvent, unsubEvent); snapStepsRotate.BindToProperty(delegate(decimal val) { int num2 = Mathf.ClosestPowerOfTwo((int)val); if ((decimal)num2 != val) { snapStepsRotate.Value = num2; } gizmoController.RotationSnapSize = 360f / (float)num2; }, () => 360m / (decimal)gizmoController.RotationSnapSize, subEvent, unsubEvent); } }; } internal void OnDestroy() { gizmoHelper.Dispose(); harmony.UnpatchSelf(); } internal void Update() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Invalid comparison between Unknown and I4 //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)gizmoController == (Object)null) { return; } ItemData val = Player_GetRightItem(Player.m_localPlayer); if (val == null || (val.m_equipped && (int)val.m_shared.m_itemType != 19)) { if (((Behaviour)gizmoController).isActiveAndEnabled) { ((Component)gizmoController).gameObject.SetActive(false); gizmoController.selectionManager.ClearSelection(); gizmoController.IsObjectSelectionEnabled = false; } return; } if (!((Behaviour)gizmoController).isActiveAndEnabled) { ((Component)gizmoController).gameObject.SetActive(true); } ((Component)gizmoController.uiManager).gameObject.SetActive(!showUIWhenSelected.Value || HasSelection || _isMouseInteractPressed); gizmoController.IsObjectSelectionEnabled = _isMouseInteractPressed; if (((ButtonControl)Keyboard.current[keybindToggleToolMode.Value]).wasPressedThisFrame) { gizmoController.ToggleToolMode(); } if (((ButtonControl)Keyboard.current[keybindTogglePivotMode.Value]).wasPressedThisFrame) { gizmoController.TogglePivotMode(); } if (((ButtonControl)Keyboard.current[keybindToggleTransformMode.Value]).wasPressedThisFrame) { gizmoController.ToggleTransformSpace(); } if (((ButtonControl)Keyboard.current[keybindToggleSnap.Value]).wasPressedThisFrame) { gizmoController.ToggleSnapMode(); } KeyboardShortcut value = keybindUndo.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { gizmoController.undoManager.Undo(); } value = keybindRedo.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { gizmoController.undoManager.Redo(); } if (HasSelection) { value = keybindDelete.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { DeleteSelectedPieces(); } } if (HasSelection) { value = keybindDuplicate.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { DuplicateSelectedPieces(); } } if (HasSelection) { value = keybindRepair.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { RepairSelectedPieces(); } } if (HasSelection) { value = keybindReset.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { ResetSelectedPieces(); } } UpdateNumpadMove(); } internal void FixedUpdate() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (HasSelection && gizmoController.selectionManager.IsPlayerOutOfRange(((Component)Player.m_localPlayer).transform.position, (float)maxInteractionDistance.Value)) { gizmoController.selectionManager.ClearSelection(); } } private void UpdateNumpadMove() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0125: 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) if (!keybindNumpadEnabled.Value) { return; } if (((ButtonControl)Keyboard.current[keybindNumpadSelect.Value]).wasPressedThisFrame) { Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue(); gizmoController.selectionManager.StartSelection(Vector2.op_Implicit(val)); gizmoController.selectionManager.PerformSelection(Vector2.op_Implicit(val)); } if (HasSelection) { if (((ButtonControl)Keyboard.current[keybindNumpadXUp.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.right); } else if (((ButtonControl)Keyboard.current[keybindNumpadXDown.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.left); } else if (((ButtonControl)Keyboard.current[keybindNumpadZUp.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.forward); } else if (((ButtonControl)Keyboard.current[keybindNumpadZDown.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.back); } else if (((ButtonControl)Keyboard.current[keybindNumpadYUp.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.up); } else if (((ButtonControl)Keyboard.current[keybindNumpadYDown.Value]).wasPressedThisFrame) { MoveOrRotatePiece(Vector3.down); } } } private void MoveOrRotatePiece(Vector3 direction) { //IL_0022: 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) RuntimeGizmoController.EToolMode eToolMode = gizmoController.ToolMode; if ((eToolMode == RuntimeGizmoController.EToolMode.Move || eToolMode == RuntimeGizmoController.EToolMode.Multi) ? true : false) { gizmoController.MoveSelectedOneSnap(direction); } else if (gizmoController.ToolMode == RuntimeGizmoController.EToolMode.Rotate) { gizmoController.RotateSelectedOneSnap(direction); } } private void ResetSelectedPieces() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown if (!HasSelection) { return; } int count = gizmoController.SelectedObjects.Count; string text = $"Reset position/rotation for {count} piece(s) back to their initial state?"; PopupButtonCallback val = delegate { UnifiedPopup.Pop(); gizmoController.ResetPiecesPose(); }; object obj = <>c.<>9__78_1; if (obj == null) { PopupButtonCallback val2 = delegate { UnifiedPopup.Pop(); }; <>c.<>9__78_1 = val2; obj = (object)val2; } UnifiedPopup.Push((PopupBase)new YesNoPopup("Reset Selected Pieces", text, val, (PopupButtonCallback)obj, true, false)); } private void RepairSelectedPieces() { if (!HasSelection) { return; } List<WearNTear> list = (from x in gizmoController.SelectedObjects select ((Component)x.GetTransform()).gameObject.GetComponent<WearNTear>() into x where (Object)(object)x != (Object)null select x).ToList(); int num = 0; foreach (WearNTear item in list) { if (item.Repair()) { num++; } } if (num > 0) { ItemData val = Player_GetRightItem(Player.m_localPlayer); Player.m_localPlayer.FaceLookDirection(); Player_m_zanim.Invoke(Player.m_localPlayer).SetTrigger(val.m_shared.m_attack.m_attackAnimation); ((Character)Player.m_localPlayer).Message((MessageType)2, $"Repaired {num} objects", 0, (Sprite)null, false); } else { ((Character)Player.m_localPlayer).Message((MessageType)1, "$msg_doesnotneedrepair", 0, (Sprite)null, false); } } private void DeleteSelectedPieces() { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown if (!HasSelection) { return; } int count = gizmoController.SelectedObjects.Count; string text = $"Are you sure you want to destroy {count} piece(s)?\nYOU CANNOT UNDO THIS!!!"; PopupButtonCallback val = delegate { UnifiedPopup.Pop(); List<GameObject> pieceGOs = gizmoController.SelectedObjects.Select((ISelectedObject x) => ((Component)x.GetTransform()).gameObject).ToList(); gizmoController.selectionManager.ClearSelection(); DestroyPieces(pieceGOs); }; object obj = <>c.<>9__80_1; if (obj == null) { PopupButtonCallback val2 = delegate { UnifiedPopup.Pop(); }; <>c.<>9__80_1 = val2; obj = (object)val2; } UnifiedPopup.Push((PopupBase)new YesNoPopup("Destroy Selected Pieces", text, val, (PopupButtonCallback)obj, true, false)); } private bool HasAllRequirements(List<Piece> pieces, out (string Name, int Count)? missing) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) if (pieces.Count == 0 || ZoneSystem.instance.GetGlobalKey(pieces[0].FreeBuildKey())) { missing = null; return true; } HashSet<string> hashSet = new HashSet<string>(); foreach (Piece piece in pieces) { if (hashSet.Add(piece.m_craftingStation.m_name) && !Object.op_Implicit((Object)(object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)piece).transform.position)) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)27)) { missing = (piece.m_craftingStation.m_name, 1); return false; } } Inventory val = Player_m_inventory.Invoke(Player.m_localPlayer); foreach (var item in from x in pieces.SelectMany((Piece x) => x.m_resources) group x by x.m_resItem.m_itemData.m_shared.m_name into x select (Name: x.Key, Count: x.Aggregate(0, (int a, Requirement b) => a + b.m_amount))) { if (val.CountItems(item.Name, -1, true) < item.Count) { missing = item; return false; } } missing = null; return true; } private void DuplicateSelectedPieces() { //IL_01b5: Unknown result type (might be due to invalid IL or missing references) if (!HasSelection) { return; } List<Piece> list = (from x in gizmoController.SelectedObjects select ((Component)x.GetTransform()).gameObject.GetComponent<Piece>() into x where (Object)(object)x != (Object)null select x).ToList(); if (!Player.m_localPlayer.PlacementCostDisabled && !HasAllRequirements(list, out (string, int)? missing)) { if (missing.HasValue) { ((Character)Player.m_localPlayer).Message((MessageType)2, $"$msg_missingrequirement\n({missing.Value.Item2}x {missing.Value.Item1})", 0, (Sprite)null, false); } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_missingrequirement", 0, (Sprite)null, false); } return; } DuplicatingObjects.Clear(); IsDuplicating = true; try { foreach (IGrouping<string, Piece> item in from x in list group x by x.m_name) { string prefabName = Utils.GetPrefabName(((Component)item.First()).gameObject); GameObject val = ((IEnumerable<GameObject>)Player.m_localPlayer.GetBuildTool().m_pieces).FirstOrDefault((Func<GameObject, bool>)((GameObject x) => ((Object)x).name == prefabName)); if (Object.op_Implicit((Object)(object)val)) { Piece component = val.GetComponent<Piece>(); if (Object.op_Implicit((Object)(object)component)) { if (Player.m_localPlayer.SetSelectedPiece(component)) { foreach (Piece item2 in item) { Piece val2 = (CurrentlyDuplicatedPiece = item2); if (Player.m_localPlayer.TryPlacePiece(component)) { if (!ZoneSystem.instance.GetGlobalKey(val2.FreeBuildKey())) { Player.m_localPlayer.ConsumeResources(val2.m_resources, 0, -1, 1); } } else { logger.LogWarning((object)"Failed to TryPlacePiece"); } } } else { logger.LogWarning((object)"Failed to SetSelectedPiece"); } } else { logger.LogError((object)"Failed to get Piece component in build prefab"); } } else { logger.LogError((object)("Failed to find prefab in BuildTool by name " + prefabName)); } } } finally { CurrentlyDuplicatedPiece = null; IsDuplicating = false; } int count = DuplicatingObjects.Count; try { gizmoController.selectionManager.ClearSelection(); gizmoController.selectionManager.AddToSelection((IEnumerable<Transform>)DuplicatingObjects); } finally { DuplicatingObjects.Clear(); } ((Character)Player.m_localPlayer).Message((MessageType)2, $"Duplicated {count} objects", 0, (Sprite)null, false); } private bool CheckCanRemovePiece(Piece piece) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) if (Player.m_localPlayer.PlacementCostDisabled || !((Object)(object)piece.m_craftingStation != (Object)null) || Object.op_Implicit((Object)(object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)this).transform.position)) || ZoneSystem.instance.GetGlobalKey((GlobalKeys)27)) { return true; } ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_missingstation", 0, (Sprite)null, false); return false; } private void DestroyPieces(List<GameObject> pieceGOs) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Expected O, but got Unknown foreach (GameObject pieceGO in pieceGOs) { Piece component = pieceGO.GetComponent<Piece>(); if ((Object)(object)component == (Object)null || !component.CanBeRemoved()) { continue; } if (Location.IsInsideNoBuildLocation(((Component)component).transform.position)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_nobuildzone", 0, (Sprite)null, false); } else if (!PrivateArea.CheckAccess(((Component)component).transform.position, 0f, true, false)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null, false); } else { if (!CheckCanRemovePiece(component)) { continue; } ZNetView component2 = ((Component)component).GetComponent<ZNetView>(); if ((Object)(object)component2 == (Object)null) { continue; } if (!component.CanBeRemoved()) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_cantremovenow", 0, (Sprite)null, false); continue; } IRemoved component3 = ((Component)component).GetComponent<IRemoved>(); if (component3 != null) { component3.OnRemoved(); } WearNTear component4 = ((Component)component).GetComponent<WearNTear>(); if (Object.op_Implicit((Object)(object)component4)) { component4.Remove(false); continue; } Character component5 = ((Component)component).GetComponent<Character>(); if ((Object)(object)component5 != (Object)null) { component5.Damage(new HitData(1E+10f)); continue; } ZLog.Log((object)("Removing non WNT object with hammer " + ((Object)component).name)); component2.ClaimOwnership(); component.DropResources((HitData)null); ZNetScene.instance.Destroy(((Component)component).gameObject); } } ((Character)Player.m_localPlayer).Message((MessageType)2, $"Destroyed {pieceGOs.Count} objects", 0, (Sprite)null, false); } public void OnSelectionAboutToBeCleared() { foreach (ValheimSelectedObject selectedObject in gizmoController.SelectedObjects) { if (Object.op_Implicit((Object)(object)selectedObject.wnt)) { selectedObject.wnt.ResetSupport(); } } } public void OnSelectionCleared() { SendRPCOnSelectionChanged(ZDOSelectionAction.Clear, null); } public void SendRPCOnSelectionChanged(ZDOSelectionAction action, ValheimSelectedObject so) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_001f: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) ZDOID val = ((so == null || so.zdo == null) ? ZDOID.None : so.zdo.m_uid); if (val == ZDOID.None && action != ZDOSelectionAction.Clear) { logger.LogError((object)"SendRPCOnSelectionChanged: ZDOID is None, but action is not Clear"); return; } ZPackage val2 = new ZPackage(); val2.Write((int)action); val2.Write(val); ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PM_OnSelectionChanged", new object[1] { val2 }); } public void RPC_OnSelectionChanged(long sender, ZPackage data) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) if (sender == ZDOMan.GetSessionID() || !Object.op_Implicit((Object)(object)gizmoController) || !gizmoController.IsSecondarySelectionOutlineEnabled) { return; } ZDOSelectionAction zDOSelectionAction = (ZDOSelectionAction)data.ReadInt(); ZDOID val = data.ReadZDOID(); if (val == ZDOID.None) { if (zDOSelectionAction == ZDOSelectionAction.Clear) { gizmoController.selectionManager.ClearSecondarySelection(sender); logger.LogMessage((object)"RPC deselected all selected pieces"); } return; } ZDO zDO = ZDOMan.instance.GetZDO(val); if (zDO == null) { logger.LogError((object)"RPC zdo not found"); return; } ZNetView val2 = ZNetScene.instance.FindInstance(zDO); if ((Object)(object)val2 == (Object)null) { logger.LogError((object)"RPC instance not found"); return; } switch (zDOSelectionAction) { case ZDOSelectionAction.Select: gizmoController.selectionManager.AddToSecondarySelection(((Component)val2).transform, sender); break; case ZDOSelectionAction.Deselect: gizmoController.selectionManager.RemoveFromSecondarySelection(((Component)val2).transform, sender); break; } } public void SendRPCUpdatePiece(ZDOAction action, ValheimSelectedObject so) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write(so.zdo.m_uid); val.Write((int)action); switch (action) { case ZDOAction.Move: val.Write(so.transform.position); break; case ZDOAction.Rotate: val.Write(so.transform.rotation); break; case ZDOAction.Scale: val.Write(so.transform.localScale); break; } val.Write(so.HasRigidbody); ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PM_UpdatePiecePosition", new object[1] { val }); } public void RPC_UpdatePiecePosition(long sender, ZPackage data) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) if (sender == ZDOMan.GetSessionID()) { return; } ZDOID val = data.ReadZDOID(); ZDO zDO = ZDOMan.instance.GetZDO(val); if (zDO == null) { logger.LogError((object)"RPC zdo not found"); return; } ZNetView val2 = ZNetScene.instance.FindInstance(zDO); if ((Object)(object)val2 == (Object)null) { logger.LogError((object)"RPC instance not found"); return; } switch ((ZDOAction)data.ReadInt()) { case ZDOAction.Move: { Vector3 position = data.ReadVector3(); ((Component)val2).transform.position = position; zDO.SetPosition(((Component)val2).transform.position); break; } case ZDOAction.Rotate: { Quaternion rotation = data.ReadQuaternion(); ((Component)val2).transform.rotation = rotation; zDO.SetRotation(((Component)val2).transform.rotation); break; } default: _ = 2; break; } if (data.ReadBool()) { Rigidbody component = ((Component)((Component)val2).transform).GetComponent<Rigidbody>(); if (Object.op_Implicit((Object)(object)component)) { component.ResetVelocities(); } } } public static bool CheckPieceCanBeMoved(Piece piece) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) if (Location.IsInsideNoBuildLocation(((Component)piece).transform.position)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_nobuildzone", 0, (Sprite)null, false); return false; } if (!PrivateArea.CheckAccess(((Component)piece).transform.position, 0f, true, false)) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null, false); return false; } if ((Object)(object)piece.m_craftingStation != (Object)null && (Object)(object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)Player.m_localPlayer).transform.position) == (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$msg_missingstation", 0, (Sprite)null, false); return false; } return true; } } public class RuntimeGizmoController : MonoBehaviour { public enum ETransformSpace { World, Local } public enum EPivotMode { Center, Pivot } public enum EToolMode { Move, Rotate, Multi } private class HandleData { public GizmoHandle Handle; public Renderer Renderer; public Color BaseColor; public Color BrightColor; } [Header("References")] public RuntimeSelectionManager selectionManager; public RuntimeScreenSpaceOutline selectionOutline; public GizmoUIManager uiManager; public GizmoUndoManager undoManager; [Header("Camera Reference")] public Camera mainCamera; [Header("Shader References")] public Shader ringShader; public Shader arrowShader; [Header("Settings")] public float handleScaleFactor = 0.15f; [SerializeField] private ETransformSpace _transformSpace; [SerializeField] private EPivotMode _pivotMode; [SerializeField] private EToolMode _toolMode = EToolMode.Multi; [SerializeField] private bool _snapModeEnabled; [Header("Snap Settings")] [SerializeField] [Tooltip("In meters")] private float _moveSnapSize = 0.5f; [SerializeField] [Tooltip("In degrees")] private float _rotationSnapSize = 11.25f; [Header("Rotation Ring Settings")] public float rotationRingRadius = 1.2f; public float rotationRingThickness = 0.025f; [Header("Interaction Settings")] public float pickPixelRadius = 18f; public float maxGizmoInteractDistance = 10f; private LayerMask gizmoLayer = LayerMask.op_Implicit(8); private Transform gizmoRoot; private Transform arrowXTransform; private Transform arrowYTransform; private Transform arrowZTransform; private Transform planeXYTransform; private Transform planeXZTransform; private Transform planeYZTransform; private Transform ringXTransform; private Transform ringYTransform; private Transform ringZTransform; private Transform ringViewTransform; private Transform centerHandleTransform; private GizmoHandle activeHandle; private GizmoHandle hoveredHandle; private List<HandleData> handleDataList = new List<HandleData>(); private MaterialPropertyBlock mpb; private Vector3 dragStartHitPoint; private Vector3 dragStartGizmoPos; private Quaternion dragStartGizmoRot; private Vector3 initialBoundingCenterPosition; private Dictionary<ISelectedObject, Vector3> initialObjPositions = new Dictionary<ISelectedObject, Vector3>(); private Dictionary<ISelectedObject, Quaternion> initialObjRotations = new Dictionary<ISelectedObject, Quaternion>(); private Vector3 rotationPlaneNormal; private Vector3 rotationStartDir; private float accumulatedRotationAngle; private Quaternion accumulatedSmoothViewRot; private float dragStartCamDistance; private readonly int PROP_COLOR = Shader.PropertyToID("_Color"); internal TooltipPanel changeTooltip; public static ILoggerAdapter logger = new DefaultLoggerAdapter(); private Transform debugGizmoSelectionBounds; private Transform debugGizmoSelectionBoundsRadius; private RaycastHit[] exactHits = (RaycastHit[])(object)new RaycastHit[4]; private RaycastHit[] sphereHits = (RaycastHit[])(object)new RaycastHit[4]; private float defaultMoveSnapSize = 0.5f; private float defaultRotationSnapSize = 22.5f; public ETransformSpace TransformSpace { get { return _transformSpace; } set { _transformSpace = value; this.ModeSettingsChanged?.Invoke(); } } public EPivotMode PivotMode { get { return _pivotMode; } set { _pivotMode = value; this.ModeSettingsChanged?.Invoke(); } } public EToolMode ToolMode { get { return _toolMode; } set { _toolMode = value; this.ModeSettingsChanged?.Invoke(); } } public bool SnapModeEnabled { get { return _snapModeEnabled; } set { _snapModeEnabled = value; this.ModeSettingsChanged?.Invoke(); } } public float MoveSnapSize { get { return _moveSnapSize; } set { _moveSnapSize = value; this.ModeSettingsChanged?.Invoke(); } } public float RotationSnapSize { get { return _rotationSnapSize; } set { _rotationSnapSize = value; this.ModeSettingsChanged?.Invoke(); } } public List<ISelectedObject> SelectedObjects => selectionManager.selectedObjects; public bool IsObjectSelectionEnabled { get; set; } = true; public bool HasActiveGizmoHandle => (Object)(object)activeHandle != (Object)null; public bool HasHoverGizmoHandle => (Object)(object)hoveredHandle != (Object)null; public bool IsSelectionOutlineEnabled { get; set; } = true; public bool IsSecondarySelectionOutlineEnabled { get; set; } = true; public bool IsViewAxisRotationEnabled { get; set; } public bool AllAxisRotationEnabled { get; set; } public bool DebugGizmoSelectionBoundsCenterEnabled { get; set; } public event Action ModeSettingsChanged; public event Action OnRepairClicked; public event Action OnDeleteClicked; public event Action OnDuplicateClicked; public event Action OnResetClicked; public void InvokeRepairClicked() { this.OnRepairClicked?.Invoke(); } public void InvokeDeleteClicked() { this.OnDeleteClicked?.Invoke(); } public void InvokeDuplicateClicked() { this.OnDuplicateClicked?.Invoke(); } public void InvokeResetClicked() { this.OnResetClicked?.Invoke(); } internal void Start() { //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown CaptureDefaultSnapSettings(); if ((Object)(object)mainCamera == (Object)null) { mainCamera = Camera.main; } if ((Object)(object)selectionManager == (Object)null) { selectionManager = ((Component)this).GetComponent<RuntimeSelectionManager>(); } if ((Object)(object)ringShader == (Object)null) { ringShader = Shader.Find("Gizmo/RuntimeRotationRing"); } if ((Object)(object)arrowShader == (Object)null) { arrowShader = Shader.Find("Gizmo/GizmoOverlay"); } changeTooltip = TooltipPanel.Get(TooltipPanel.Type.ChangeTooltip); ((Behaviour)selectionOutline).enabled = false; mpb = new MaterialPropertyBlock(); CreateGizmoStructure(); UpdateGizmoHandleLayerInteraction(); } internal void Update() { if (Mouse.current != null) { if ((Object)(object)mainCamera == (Object)null) { mainCamera = Camera.main; } UpdateGizmoTransform(); UpdateHoverState(); HandleInteraction(); UpdateHandleColors(); UpdateDebugDrawSelectionBounds(); } } internal void OnDisable() { if (Object.op_Implicit((Object)(object)gizmoRoot)) { ((Component)gizmoRoot).gameObject.SetActive(false); } if (Object.op_Implicit((Object)(object)changeTooltip)) { changeTooltip.Hide(); } } public void ToggleTransformSpace() { ETransformSpace transformSpace = ((TransformSpace == ETransformSpace.World) ? ETransformSpace.Local : ETransformSpace.World); TransformSpace = transformSpace; } public void TogglePivotMode() { EPivotMode pivotMode = ((PivotMode == EPivotMode.Center) ? EPivotMode.Pivot : EPivotMode.Center); PivotMode = pivotMode; } public void ToggleToolMode() { ToolMode = ToolMode switch { EToolMode.Move => EToolMode.Rotate, EToolMode.Rotate => EToolMode.Multi, _ => EToolMode.Move, }; } public void ToggleSnapMode() { SnapModeEnabled = !SnapModeEnabled; } public void CreateGizmoStructure() { //IL_0024: 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_0077: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028a: 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) if ((Object)(object)gizmoRoot != (Object)null) { Object.Destroy((Object)(object)((Component)gizmoRoot).gameObject); } gizmoRoot = new GameObject("RuntimeGizmoRoot").transform; handleDataList.Clear(); Mesh mesh = GizmoMeshFactory.CreateArrowMesh(); GameObject val = CreateHandle("Arrow_X", mesh, GizmoType.TranslateAxis, GizmoAxis.X, Quaternion.Euler(0f, 0f, -90f), Vector3.one, -3); GameObject val2 = CreateHandle("Arrow_Y", mesh, GizmoType.TranslateAxis, GizmoAxis.Y, Quaternion.identity, Vector3.one, -3); GameObject val3 = CreateHandle("Arrow_Z", mesh, GizmoType.TranslateAxis, GizmoAxis.Z, Quaternion.Euler(90f, 0f, 0f), Vector3.one, -3); arrowXTransform = val.transform; arrowYTransform = val2.transform; arrowZTransform = val3.transform; Mesh mesh2 = GizmoMeshFactory.CreatePlaneMesh(); GameObject val4 = CreateHandle("Plane_XY", mesh2, GizmoType.TranslatePlane, GizmoAxis.XY, Quaternion.Euler(-90f, 0f, 0f), Vector3.one, -2); GameObject val5 = CreateHandle("Plane_XZ", mesh2, GizmoType.TranslatePlane, GizmoAxis.XZ, Quaternion.identity, Vector3.one, -2); GameObject val6 = CreateHandle("Plane_YZ", mesh2, GizmoType.TranslatePlane, GizmoAxis.YZ, Quaternion.Euler(0f, 0f, 90f), Vector3.one, -2); planeXYTransform = val4.transform; planeXZTransform = val5.transform; planeYZTransform = val6.transform; GameObject val7 = CreateHandle("Center_Box", GizmoMeshFactory.CreateCubeMesh(), GizmoType.TranslateAll, GizmoAxis.All, Quaternion.identity, Vector3.one * 0.075f, -1); centerHandleTransform = val7.transform; Mesh mesh3 = GizmoMeshFactory.CreateTorusMesh(rotationRingRadius, rotationRingThickness); GameObject val8 = CreateHandle("Ring_X", mesh3, GizmoType.RotateRing, GizmoAxis.X, Quaternion.Euler(0f, 0f, -90f), Vector3.one); GameObject val9 = CreateHandle("Ring_Y", mesh3, GizmoType.RotateRing, GizmoAxis.Y, Quaternion.identity, Vector3.one); GameObject val10 = CreateHandle("Ring_Z", mesh3, GizmoType.RotateRing, GizmoAxis.Z, Quaternion.Euler(90f, 0f, 0f), Vector3.one); ringXTransform = val8.transform; ringYTransform = val9.transform; ringZTransform = val10.transform; GameObject val11 = CreateHandle("Ring_View", mesh3, GizmoType.RotateRing, GizmoAxis.View, Quaternion.identity, Vector3.one * 1.05f); ringViewTransform = val11.transform; ((Component)gizmoRoot).gameObject.SetActive(false); } private GameObject CreateHandle(string name, Mesh mesh, GizmoType type, GizmoAxis axis, Quaternion rotation, Vector3 scale, int queueOffset = 0) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown GameObject val = new GameObject(name); val.transform.SetParent(gizmoRoot); val.transform.localRotation = rotation; val.transform.localScale = scale; val.layer = Mathf.RoundToInt(Mathf.Log((float)((LayerMask)(ref gizmoLayer)).value, 2f)); bool isRing = type == GizmoType.RotateRing; Material sharedMaterial = CreateHandleMaterial(isRing, queueOffset); val.AddComponent<MeshFilter>().sharedMesh = mesh; MeshRenderer val2 = val.AddComponent<MeshRenderer>(); ((Renderer)val2).sharedMaterial = sharedMaterial; val.AddComponent<MeshCollider>().sharedMesh = mesh; GizmoHandle gizmoHandle = val.AddComponent<GizmoHandle>(); gizmoHandle.handleType = type; gizmoHandle.axis = axis; GetAxisColors(axis, out var baseColor, out var brightColor); handleDataList.Add(new HandleData { Handle = gizmoHandle, Renderer = (Renderer)(object)val2, BaseColor = baseColor, BrightColor = brightColor }); return val; } private Material CreateHandleMaterial(bool isRing, int queueOffset = 0) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown Material val = ((isRing && (Object)(object)ringShader != (Object)null) ? new Material(ringShader) : ((!((Object)(object)arrowShader != (Object)null)) ? new Material(Shader.Find("Unlit/Color")) : new Material(arrowShader))); val.renderQueue += queueOffset; return val; } private void GetAxisColors(GizmoAxis axis, out Color baseColor, out Color brightColor) { //IL_0040: 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_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might