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 Creative World v1.4.0
DigiCreative.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: AssemblyCompany("DigiCreative")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("DigiCreative")] [assembly: AssemblyTitle("DigiCreative")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace DigiCreative { internal class BuildMaterials : MonoBehaviour { private sealed class Line { public string Name; public Sprite Icon; public int Amount; } internal static ConfigEntry<bool> On; private static BuildMaterials _instance; private static bool _busy; private const float RowHeight = 40f; internal static void Bind(ConfigFile config) { On = config.Bind<bool>("7 - Build Materials", "Build Materials tool", true, "A Build Materials tool in the hammer menu (Building tab, at the end). Click a building piece with it: a window lists every material the whole building connected to it costs, with the totals."); } internal static void Register() { Tools.Add("buildmaterials", "Build Materials", "Click a building piece: a list of every material the whole building connected to it costs, with the totals, and how many of each piece.", "piece_chest_wood", () => On.Value, delegate(Player player) { if ((Object)(object)_instance != (Object)null && !_busy && !Windows.IsOpen) { ((MonoBehaviour)_instance).StartCoroutine(Count(player)); } }); } private void Awake() { _instance = this; } private static IEnumerator Count(Player player) { Piece start = player.GetHoveringPiece(); if ((Object)(object)start == (Object)null || !start.IsPlacedByPlayer()) { ((Character)player).Message((MessageType)2, "Aim at a piece of the building", 0, (Sprite)null, false); yield break; } _busy = true; try { List<Piece> found = new List<Piece>(); int steps = 0; foreach (Piece item in Tools.Building(start, found)) { _ = item; int num = steps + 1; steps = num; if (num % 150 == 0) { yield return null; } } List<string> list = (from p in found where (Object)(object)p != (Object)null select Utils.GetPrefabName(((Component)p).gameObject)).ToList(); string text = Localization.instance.Localize(start.m_name); Show((list.Count == 1) ? ("1 piece: " + text) : (Number(list.Count) + " pieces, connected to the " + text + " you clicked"), list); } finally { _busy = false; } } internal static void Show(string subtitle, List<string> prefabs) { Dictionary<string, Line> dictionary = new Dictionary<string, Line>(); Dictionary<string, Line> dictionary2 = new Dictionary<string, Line>(); SortedSet<string> sortedSet = new SortedSet<string>(); float num = 0f; foreach (string prefab in prefabs) { Piece val = Tools.PieceOf(prefab); if ((Object)(object)val == (Object)null) { continue; } Add(dictionary2, prefab, Localization.instance.Localize(val.m_name), val.m_icon, 1); if ((Object)(object)val.m_craftingStation != (Object)null) { sortedSet.Add(Localization.instance.Localize(val.m_craftingStation.m_name)); } if (val.m_resources == null) { continue; } Requirement[] resources = val.m_resources; foreach (Requirement val2 in resources) { if (!((Object)(object)val2?.m_resItem == (Object)null) && val2.m_amount > 0) { ItemData itemData = val2.m_resItem.m_itemData; Add(dictionary, ((Object)val2.m_resItem).name, Localization.instance.Localize(itemData.m_shared.m_name), itemData.GetIcon(), val2.m_amount); num += itemData.m_shared.m_weight * (float)val2.m_amount; } } } string footer = "Total weight " + Number(Mathf.RoundToInt(num)) + ((sortedSet.Count > 0) ? (" · Needs " + string.Join(", ", sortedSet)) : ""); Windows.Window window = Windows.Open("Build Materials", subtitle, 720f, 800f, footer, 80f); if (window != null) { float num2 = Section(window, 0f, "Materials", "Total", (from l in dictionary.Values orderby l.Amount descending, l.Name select l).ToList()); num2 = Section(window, num2 + 12f, "Pieces", "Count", (from l in dictionary2.Values orderby l.Amount descending, l.Name select l).ToList()); Windows.Done(window, num2); } } private static void Add(Dictionary<string, Line> lines, string key, string name, Sprite icon, int amount) { if (!lines.TryGetValue(key, out var value)) { Line obj = new Line { Name = name, Icon = icon }; value = obj; lines[key] = obj; } value.Amount += amount; } internal static string Number(int n) { return n.ToString("N0", CultureInfo.InvariantCulture); } private static float Section(Windows.Window w, float y, string title, string column, List<Line> lines) { //IL_0031: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) float rowWidth = w.RowWidth; RectTransform val = Windows.Rect("Heading", (Transform)(object)w.Content); Windows.Place(val, 0f, y, rowWidth, 34f); Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val, title, 22f, Windows.Gold, (TextAlignmentOptions)513)).rectTransform, 12f, 2f, rowWidth - 160f, 30f); Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val, column, 19f, Windows.Gold, (TextAlignmentOptions)516)).rectTransform, rowWidth - 150f, 4f, 136f, 28f); RectTransform obj = Windows.Rect("Line", (Transform)(object)val); Windows.Place(obj, 8f, 33f, rowWidth - 16f, 1f); ((Graphic)((Component)obj).gameObject.AddComponent<Image>()).color = new Color(Windows.Gold.r, Windows.Gold.g, Windows.Gold.b, 0.4f); y += 36f; if (lines.Count == 0) { RectTransform obj2 = Windows.Rect("None", (Transform)(object)w.Content); Windows.Place(obj2, 0f, y, rowWidth, 40f); Windows.Place(((TMP_Text)Windows.Text((Transform)(object)obj2, "nothing", 19f, Windows.Dim, (TextAlignmentOptions)513)).rectTransform, 52f, 6f, rowWidth - 60f, 28f); return y + 40f; } for (int i = 0; i < lines.Count; i++) { RectTransform val2 = Windows.Rect("Row", (Transform)(object)w.Content); Windows.Place(val2, 0f, y, rowWidth, 40f); ((Graphic)((Component)val2).gameObject.AddComponent<Image>()).color = ((i % 2 == 0) ? Windows.RowEven : Windows.RowOdd); if ((Object)(object)lines[i].Icon != (Object)null) { Windows.Picture(val2, lines[i].Icon, 10f, 4f, 32f, 32f); } Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, lines[i].Name, 20f, Windows.Body, (TextAlignmentOptions)513)).rectTransform, 52f, 6f, rowWidth - 210f, 28f); Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, Number(lines[i].Amount), 20f, Windows.Body, (TextAlignmentOptions)516)).rectTransform, rowWidth - 150f, 6f, 136f, 28f); y += 40f; } return y; } } internal class Mirror : MonoBehaviour { internal sealed class Line { public Vector3 Origin; public Vector3 Normal; public float Side(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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) return Vector3.Dot(p - Origin, Normal); } public Vector3 Pos(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) return p - 2f * Side(p) * Normal; } public Vector3 Dir(Vector3 d) { //IL_0000: 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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) return d - 2f * Vector3.Dot(d, Normal) * Normal; } } internal struct Placement { public string Name; public Vector3 Pos; public Quaternion Rot; } internal enum Sym { LeftRight, FrontBack, Diagonal, AntiDiagonal } internal sealed class Plan { public string Name; public Sym Sym; } internal static Func<bool> InCreative = () => false; internal static ConfigEntry<bool> On; internal static ConfigEntry<KeyboardShortcut> PointKey; internal static ConfigEntry<KeyboardShortcut> SecondKey; internal static ConfigEntry<KeyboardShortcut> BuildingKey; internal static ConfigEntry<KeyboardShortcut> ClearKey; internal static readonly Line[] Lines = new Line[2]; internal static bool Mirroring; private static Vector3 _first; private static int _settingLine = -1; private static bool _busy; private readonly LineRenderer[] _ground = (LineRenderer[])(object)new LineRenderer[2]; private readonly LineRenderer[] _post = (LineRenderer[])(object)new LineRenderer[2]; private static readonly List<Transform> Snaps = new List<Transform>(); private static readonly Color[] LineColours = (Color[])(object)new Color[2] { new Color(0.2f, 0.9f, 1f, 0.85f), new Color(1f, 0.6f, 0.15f, 0.85f) }; private static readonly Dictionary<string, Plan> Plans = new Dictionary<string, Plan>(); private static readonly Func<Vector3, Vector3> FlipLeftRight = (Vector3 v) => new Vector3(0f - v.x, v.y, v.z); private static readonly Func<Vector3, Vector3> FlipFrontBack = (Vector3 v) => new Vector3(v.x, v.y, 0f - v.z); private static readonly Func<Vector3, Vector3> FlipDiagonal = (Vector3 v) => new Vector3(v.z, v.y, v.x); private static readonly Func<Vector3, Vector3> FlipAntiDiagonal = (Vector3 v) => new Vector3(0f - v.z, v.y, 0f - v.x); private static bool HasLine { get { if (Lines[0] == null) { return Lines[1] != null; } return true; } } internal static bool Active { get { if (HasLine && On != null && On.Value) { return InCreative(); } return false; } } private static IEnumerable<Line> ActiveLines => Lines.Where((Line l) => l != null); internal static void Bind(ConfigFile config) { //IL_002d: 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_008b: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Invalid comparison between Unknown and I4 //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Invalid comparison between Unknown and I4 //IL_00f0: 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_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Invalid comparison between Unknown and I4 //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) On = config.Bind<bool>("5 - Mirror", "Mirror building", true, "With the hammer out: N on a point and N on a second point sets a mirror line through both (snapped to the nearest snap point); Alt+N the same for a second line. Then every piece you place or remove is mirrored too (with two lines: in all four quarters), Shift+N on a building copies that side to the others (clearing them first), Ctrl+N removes the lines."); PointKey = config.Bind<KeyboardShortcut>("5 - Mirror", "Line key", new KeyboardShortcut((KeyCode)110, Array.Empty<KeyCode>()), "On a building piece: the mirror line runs through its middle, along its axis closest to where you look. On the ground: press on a first and a second point."); SecondKey = config.Bind<KeyboardShortcut>("5 - Mirror", "Second line key", new KeyboardShortcut((KeyCode)110, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "The same for a second mirror line, e.g. across the first one: then every piece is placed in all four quarters."); BuildingKey = config.Bind<KeyboardShortcut>("5 - Mirror", "Mirror building key", new KeyboardShortcut((KeyCode)110, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Aim at a building and press: every piece connected to it is mirrored to the other side of the line (with two lines: to the other three quarters)."); ClearKey = config.Bind<KeyboardShortcut>("5 - Mirror", "Clear line key", new KeyboardShortcut((KeyCode)110, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Removes the mirror lines: no more mirroring."); KeyboardShortcut value = PointKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 121) { PointKey.Value = new KeyboardShortcut((KeyCode)110, Array.Empty<KeyCode>()); } value = BuildingKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 121) { BuildingKey.Value = new KeyboardShortcut((KeyCode)110, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }); } value = ClearKey.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 121) { ClearKey.Value = new KeyboardShortcut((KeyCode)110, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }); } } internal static void Patch(Harmony harmony) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown harmony.Patch((MethodBase)AccessTools.Method(typeof(Player), "PlacePiece", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Mirror), "Placed", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(WearNTear), "Remove", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Mirror), "Removing", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static Quaternion MirrorRot(Quaternion r, Plan plan, Line line) { //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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) return Quaternion.LookRotation(line.Dir((Vector3)(plan.Sym switch { Sym.FrontBack => -(r * Vector3.forward), Sym.Diagonal => r * Vector3.right, Sym.AntiDiagonal => -(r * Vector3.right), _ => r * Vector3.forward, })), line.Dir(r * Vector3.up)); } internal static Placement Reflect(Placement p, Line line) { //IL_0025: 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_002f: 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_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) Plan plan = PlanFor(p.Name); return new Placement { Name = plan.Name, Pos = line.Pos(p.Pos), Rot = MirrorRot(p.Rot, plan, line) }; } internal static List<Placement> Images(Placement p) { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) List<Placement> list = new List<Placement>(); List<Line> list2 = ActiveLines.ToList(); List<Line[]> list3 = new List<Line[]>(); foreach (Line item in list2) { list3.Add(new Line[1] { item }); } if (list2.Count == 2) { list3.Add(new Line[2] { list2[0], list2[1] }); } foreach (Line[] item2 in list3) { Placement image = p; Line[] array = item2; foreach (Line line in array) { image = Reflect(image, line); } Vector3 val = image.Pos - p.Pos; if (!(((Vector3)(ref val)).sqrMagnitude < 0.0025f) && !list.Any(delegate(Placement r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = r.Pos - image.Pos; return ((Vector3)(ref val2)).sqrMagnitude < 0.0025f; })) { list.Add(image); } } return list; } internal static Plan PlanFor(string name) { //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) if (Plans.TryGetValue(name, out var value)) { return value; } value = new Plan { Name = name }; Plans[name] = value; Piece val = PieceOf(name); List<Vector3> list = SnapsOf(val); if (list.Count < 2) { return value; } float num = Mismatch(list, list, FlipLeftRight); if (num < 0.05f) { return value; } float num2 = Mismatch(list, list, FlipDiagonal); float num3 = Mismatch(list, list, FlipAntiDiagonal); if (num2 < 0.05f || num3 < 0.05f) { value.Sym = ((num2 <= num3) ? Sym.Diagonal : Sym.AntiDiagonal); return value; } string text = Materials(val); foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { Piece val2 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Piece>() : null); if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2 == (Object)(object)val) && val2.m_category == val.m_category && !(Materials(val2) != text)) { List<Vector3> list2 = SnapsOf(val2); if (list2.Count == list.Count && Mismatch(list, list2, FlipLeftRight) < 0.05f && Mismatch(list2, list, FlipLeftRight) < 0.05f) { value.Name = ((Object)prefab).name; return value; } } } float num4 = Mismatch(list, list, FlipFrontBack); float num5 = num; if (num4 + 0.01f < num5) { num5 = num4; value.Sym = Sym.FrontBack; } if (num2 + 0.01f < num5) { num5 = num2; value.Sym = Sym.Diagonal; } if (num3 + 0.01f < num5) { value.Sym = Sym.AntiDiagonal; } return value; } private static Piece PieceOf(string name) { GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(name) : null); if (!((Object)(object)val != (Object)null)) { return null; } return val.GetComponent<Piece>(); } internal static List<Vector3> SnapsOf(Piece piece) { //IL_0043: 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) List<Vector3> list = new List<Vector3>(); if ((Object)(object)piece == (Object)null) { return list; } Snaps.Clear(); piece.GetSnapPoints(Snaps); foreach (Transform snap in Snaps) { list.Add(((Component)piece).transform.InverseTransformPoint(snap.position)); } return list; } private static string Materials(Piece piece) { if (!((Object)(object)piece == (Object)null) && piece.m_resources != null) { return string.Join(",", from r in piece.m_resources where (Object)(object)r?.m_resItem != (Object)null select ((Object)r.m_resItem).name + "x" + r.m_amount into s orderby s select s); } return ""; } private static float Mismatch(List<Vector3> points, List<Vector3> other, Func<Vector3, Vector3> flip) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_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) float num = 0f; foreach (Vector3 point in points) { Vector3 val = flip(point); float num2 = float.MaxValue; foreach (Vector3 item in other) { float num3 = num2; Vector3 val2 = val - item; num2 = Mathf.Min(num3, ((Vector3)(ref val2)).sqrMagnitude); } num += Mathf.Sqrt(num2); } return num; } private static Piece FindTwin(string name, Vector3 at, Piece except) { //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_0038: Unknown result type (might be due to invalid IL or missing references) foreach (Piece s_allPiece in Piece.s_allPieces) { if ((Object)(object)s_allPiece != (Object)null && (Object)(object)s_allPiece != (Object)(object)except) { Vector3 val = ((Component)s_allPiece).transform.position - at; if (((Vector3)(ref val)).sqrMagnitude < 0.0025f && Utils.GetPrefabName(((Component)s_allPiece).gameObject) == name) { return s_allPiece; } } } return null; } private static void Placed(Player __instance, Piece piece, Vector3 pos, Quaternion rot) { //IL_0041: 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_004a: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) if (Mirroring || !Active || (Object)(object)piece == (Object)null || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } foreach (Placement item in Images(new Placement { Name = Utils.GetPrefabName(((Component)piece).gameObject), Pos = pos, Rot = rot })) { if (!((Object)(object)FindTwin(item.Name, item.Pos, null) != (Object)null)) { Piece val = PieceOf(item.Name) ?? piece; Mirroring = true; try { __instance.PlacePiece(val, item.Pos, item.Rot, false, false); } finally { Mirroring = false; } } } } private static void Removing(WearNTear __instance) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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) if (Mirroring || !Active || (Object)(object)__instance == (Object)null) { return; } Piece component = ((Component)__instance).GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { return; } foreach (Placement item in Images(new Placement { Name = Utils.GetPrefabName(((Component)component).gameObject), Pos = ((Component)component).transform.position, Rot = ((Component)component).transform.rotation })) { Piece val = FindTwin(item.Name, item.Pos, component); WearNTear val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<WearNTear>() : null); if (!((Object)(object)val2 == (Object)null)) { Mirroring = true; try { val2.Remove(false); } finally { Mirroring = false; } } } } private static bool Typing() { if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Minimap.IsOpen() && !Hud.IsPieceSelectionVisible()) { if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_buildUi != (Object)null) { return Hud.instance.m_buildUi.SearchFieldFocused; } return false; } return true; } private static void Say(Player player, string text) { ((Character)player).Message((MessageType)2, text, 0, (Sprite)null, false); } private void Update() { //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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; bool flag = (Object)(object)localPlayer != (Object)null && On != null && On.Value && InCreative() && ((Character)localPlayer).InPlaceMode(); ShowLines(flag); if (!flag || Typing()) { return; } KeyboardShortcut value = ClearKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { Lines[0] = (Lines[1] = null); _settingLine = -1; Say(localPlayer, "Mirror lines removed"); return; } value = BuildingKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { if (!HasLine) { Say(localPlayer, $"Set a mirror line first: {PointKey.Value} on two points"); } else if (!_busy) { ((MonoBehaviour)this).StartCoroutine(MirrorBuilding(localPlayer)); } return; } value = SecondKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { SetLine(localPlayer, 1, SecondKey.Value); return; } value = PointKey.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { SetLine(localPlayer, 0, PointKey.Value); } } private static void SetLine(Player player, int index, KeyboardShortcut key) { //IL_0282: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_0288: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0271: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0062: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: 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_01cf: Unknown result type (might be due to invalid IL or missing references) string text = ((index == 0) ? "Mirror line" : "Second mirror line"); if (!Aim(out var point, out var piece, snapToPoints: false)) { Say(player, "Aim at a building piece or the ground"); return; } Vector3 val3; if ((Object)(object)piece != (Object)null && piece.IsPlacedByPlayer()) { Vector3 forward = ((Component)GameCamera.instance).transform.forward; forward.y = 0f; Vector3 right = ((Component)piece).transform.right; right.y = 0f; Vector3 forward2 = ((Component)piece).transform.forward; forward2.y = 0f; Vector3 val = ((Mathf.Abs(Vector3.Dot(((Vector3)(ref right)).normalized, ((Vector3)(ref forward)).normalized)) > Mathf.Abs(Vector3.Dot(((Vector3)(ref forward2)).normalized, ((Vector3)(ref forward)).normalized))) ? right : forward2); if (((Vector3)(ref val)).sqrMagnitude < 0.01f) { val = Vector3.forward; } Bounds val2 = BoundsOf(piece); Vector3 center = ((Bounds)(ref val2)).center; center.y = ((Component)piece).transform.position.y; val3 = Vector3.Cross(Vector3.up, ((Vector3)(ref val)).normalized); Vector3 normalized = ((Vector3)(ref val3)).normalized; float num = Vector3.Dot(point - center, normalized); float num2 = 0f; Snaps.Clear(); piece.GetSnapPoints(Snaps); foreach (Transform snap in Snaps) { float num3 = Vector3.Dot(snap.position - center, normalized); if (Mathf.Abs(num3 - num) < Mathf.Abs(num2 - num)) { num2 = num3; } } Lines[index] = new Line { Origin = center + normalized * num2, Normal = normalized }; _settingLine = -1; string text2 = ((Mathf.Abs(num2) < 0.05f) ? "through the middle of" : "along the edge of"); Say(player, text + " set " + text2 + " the " + Localization.instance.Localize(piece.m_name) + ". " + Hint()); return; } Aim(out point, out var _); if (_settingLine != index) { _first = point; _settingLine = index; Say(player, $"{text}: first point set. Now {key} on the second point (or {key} on a piece: a line through its middle)"); return; } Vector3 val4 = point - _first; val4.y = 0f; if (((Vector3)(ref val4)).magnitude < 0.2f) { Say(player, "The second point is too close to the first"); return; } Line[] lines = Lines; Line obj = new Line { Origin = _first }; val3 = Vector3.Cross(Vector3.up, ((Vector3)(ref val4)).normalized); obj.Normal = ((Vector3)(ref val3)).normalized; lines[index] = obj; _settingLine = -1; Say(player, text + " set: placing and removing is mirrored. " + Hint()); } private static string Hint() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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) int num = ActiveLines.Count(); string text = ((num == 1) ? $" {SecondKey.Value}: a second line (four quarters)." : " Both lines: every piece goes into all four quarters."); if (num == 2) { float num2 = Vector3.Angle(Lines[0].Normal, Lines[1].Normal); if (Mathf.Abs(num2 - 90f) > 2f && Mathf.Abs(num2 - 90f) < 88f) { text += " (The lines are not square to each other, so the quarters do not match up.)"; } } return $"{BuildingKey.Value}: copy a whole side. {ClearKey.Value}: remove the lines.{text}"; } private static bool Aim(out Vector3 point, out Piece piece, bool snapToPoints = true) { //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_0069: 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_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_00e9: 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_0107: 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) point = Vector3.zero; piece = null; GameCamera instance = GameCamera.instance; if ((Object)(object)instance == (Object)null) { return false; } int mask = LayerMask.GetMask(new string[7] { "Default", "static_solid", "terrain", "piece", "piece_nonsolid", "vehicle", "Default_small" }); RaycastHit val = default(RaycastHit); if (!Physics.Raycast(((Component)instance).transform.position, ((Component)instance).transform.forward, ref val, 200f, mask)) { return false; } point = ((RaycastHit)(ref val)).point; piece = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); if ((Object)(object)piece == (Object)null || !snapToPoints) { return true; } Snaps.Clear(); piece.GetSnapPoints(Snaps); float num = 1f; foreach (Transform snap in Snaps) { float num2 = Vector3.Distance(snap.position, ((RaycastHit)(ref val)).point); if (num2 < num) { num = num2; point = snap.position; } } return true; } private void ShowLines(bool hammer) { //IL_0099: 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_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: 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_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0187: 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_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) Vector3 val2 = default(Vector3); for (int i = 0; i < 2; i++) { Line line = Lines[i]; bool flag = _settingLine == i; if (!hammer || (line == null && !flag)) { if ((Object)(object)_ground[i] != (Object)null) { ((Renderer)_ground[i]).enabled = false; } if ((Object)(object)_post[i] != (Object)null) { ((Renderer)_post[i]).enabled = false; } continue; } if ((Object)(object)_ground[i] == (Object)null) { _ground[i] = NewLine("Digi mirror line " + (i + 1), LineColours[i]); _post[i] = NewLine("Digi mirror post " + (i + 1), LineColours[i]); if ((Object)(object)_ground[i] == (Object)null || (Object)(object)_post[i] == (Object)null) { break; } } if (line != null) { Vector3 val = Vector3.Cross(line.Normal, Vector3.up); Vector3 normalized = ((Vector3)(ref val)).normalized; ((Vector3)(ref val2))..ctor(0f, 0.05f, 0f); ((Renderer)_ground[i]).enabled = true; _ground[i].SetPosition(0, line.Origin - normalized * 150f + val2); _ground[i].SetPosition(1, line.Origin + normalized * 150f + val2); } else { ((Renderer)_ground[i]).enabled = false; } Vector3 val3 = ((line != null && !flag) ? line.Origin : _first); ((Renderer)_post[i]).enabled = true; _post[i].SetPosition(0, val3); _post[i].SetPosition(1, val3 + Vector3.up * 30f); } } private LineRenderer NewLine(string name, Color colour) { //IL_0025: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Unlit/Color"); if ((Object)(object)val == (Object)null) { return null; } GameObject val2 = new GameObject(name); val2.transform.SetParent(((Component)this).transform, false); LineRenderer obj = val2.AddComponent<LineRenderer>(); ((Renderer)obj).material = new Material(val); Color startColor = (obj.endColor = colour); obj.startColor = startColor; float startWidth = (obj.endWidth = 0.08f); obj.startWidth = startWidth; obj.positionCount = 2; obj.useWorldSpace = true; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)obj).receiveShadows = false; return obj; } private void OnDestroy() { foreach (LineRenderer item in _ground.Concat(_post)) { if ((Object)(object)item != (Object)null) { Object.Destroy((Object)(object)((Component)item).gameObject); } } } private static Bounds BoundsOf(Piece piece) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(((Component)piece).transform.position, Vector3.zero); Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { if (val.enabled && !val.isTrigger) { ((Bounds)(ref result)).Encapsulate(val.bounds); } } return result; } private static Vector3Int Cell(Vector3 p) { //IL_0000: 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_000b: Unknown result type (might be due to invalid IL or missing references) return Vector3Int.FloorToInt(p * 4f); } private IEnumerator MirrorBuilding(Player player) { if (!Aim(out var _, out var start) || (Object)(object)start == (Object)null || !start.IsPlacedByPlayer()) { Say(player, "Aim at a piece of the building to mirror"); yield break; } _busy = true; HashSet<Piece> found = new HashSet<Piece> { start }; Queue<Piece> queue = new Queue<Piece>(); queue.Enqueue(start); Collider[] hits = (Collider[])(object)new Collider[128]; int mask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); int steps = 0; while (queue.Count > 0 && found.Count < 20000) { Piece val = queue.Dequeue(); if ((Object)(object)val == (Object)null) { continue; } Bounds val2 = BoundsOf(val); int num = Physics.OverlapBoxNonAlloc(((Bounds)(ref val2)).center, ((Bounds)(ref val2)).extents + Vector3.one * 0.1f, hits, Quaternion.identity, mask); for (int i = 0; i < num; i++) { Piece val3 = (((Object)(object)hits[i] != (Object)null) ? ((Component)hits[i]).GetComponentInParent<Piece>() : null); if ((Object)(object)val3 != (Object)null && val3.IsPlacedByPlayer() && found.Add(val3)) { queue.Enqueue(val3); } } int num2 = steps + 1; steps = num2; if (num2 % 150 == 0) { yield return null; } } List<Line> lines = ActiveLines.ToList(); float[] signs = new float[lines.Count]; for (int j = 0; j < lines.Count; j++) { float num3 = lines[j].Side(((Component)start).transform.position); if (Mathf.Abs(num3) < 0.05f) { num3 = lines[j].Side(((Component)player).transform.position); } if (Mathf.Abs(num3) < 0.05f) { _busy = false; Say(player, "Aim at a piece on the side you want to copy"); yield break; } signs[j] = Mathf.Sign(num3); } List<Piece> source = found.Where((Piece val7) => (Object)(object)val7 != (Object)null && !Outside(((Component)val7).transform.position)).ToList(); Bounds val4 = default(Bounds); bool flag = true; Vector3 pos = default(Vector3); foreach (Piece item in source) { Bounds val5 = BoundsOf(item); for (int num4 = 0; num4 < 8; num4++) { ((Vector3)(ref pos))..ctor(((num4 & 1) == 0) ? ((Bounds)(ref val5)).min.x : ((Bounds)(ref val5)).max.x, ((num4 & 2) == 0) ? ((Bounds)(ref val5)).min.y : ((Bounds)(ref val5)).max.y, ((num4 & 4) == 0) ? ((Bounds)(ref val5)).min.z : ((Bounds)(ref val5)).max.z); foreach (Placement item2 in Images(new Placement { Name = "", Pos = pos, Rot = Quaternion.identity }, placesOnly: true)) { if (flag) { val4 = new Bounds(item2.Pos, Vector3.zero); flag = false; } else { ((Bounds)(ref val4)).Encapsulate(item2.Pos); } } } } ((Bounds)(ref val4)).Expand(new Vector3(1f, 1f, 1f)); HashSet<Piece> hashSet = new HashSet<Piece>(found.Where((Piece val7) => (Object)(object)val7 != (Object)null && Outside(((Component)val7).transform.position))); if (!flag) { foreach (Piece s_allPiece in Piece.s_allPieces) { if ((Object)(object)s_allPiece != (Object)null && s_allPiece.IsPlacedByPlayer() && Outside(((Component)s_allPiece).transform.position) && ((Bounds)(ref val4)).Contains(((Component)s_allPiece).transform.position)) { hashSet.Add(s_allPiece); } } } int removed = 0; foreach (Piece item3 in hashSet.ToList()) { if ((Object)(object)item3 == (Object)null) { continue; } Mirroring = true; try { WearNTear component = ((Component)item3).GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.Remove(true); } else { ZNetScene.instance.Destroy(((Component)item3).gameObject); } } finally { Mirroring = false; } removed++; if (removed % 60 == 0) { yield return null; } } yield return null; yield return null; Dictionary<Vector3Int, List<Piece>> index = new Dictionary<Vector3Int, List<Piece>>(); foreach (Piece s_allPiece2 in Piece.s_allPieces) { if (!((Object)(object)s_allPiece2 == (Object)null)) { Vector3Int key = Cell(((Component)s_allPiece2).transform.position); if (!index.TryGetValue(key, out var value)) { value = (index[key] = new List<Piece>()); } value.Add(s_allPiece2); } } int placed = 0; int skipped = 0; foreach (Piece item4 in source) { if ((Object)(object)item4 == (Object)null) { continue; } Placement p = new Placement { Name = Utils.GetPrefabName(((Component)item4).gameObject), Pos = ((Component)item4).transform.position, Rot = ((Component)item4).transform.rotation }; foreach (Placement item5 in Images(p)) { if (HasTwin(index, item5.Name, item5.Pos)) { skipped++; continue; } Piece val6 = PieceOf(item5.Name); if (!((Object)(object)val6 == (Object)null)) { Mirroring = true; try { player.PlacePiece(val6, item5.Pos, item5.Rot, false, false); } finally { Mirroring = false; } placed++; if (placed % 40 == 0) { yield return null; } } } } _busy = false; string text = ((lines.Count == 2) ? "the other three quarters" : "the other side"); Say(player, $"Copied {placed} pieces to {text} (cleared {removed} there first; {found.Count} in the building)"); bool Outside(Vector3 p2) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) for (int k = 0; k < lines.Count; k++) { if (lines[k].Side(p2) * signs[k] <= -0.05f) { return true; } } return false; } } private static List<Placement> Images(Placement p, bool placesOnly) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) if (!placesOnly) { return Images(p); } List<Placement> list = new List<Placement>(); List<Line> list2 = ActiveLines.ToList(); foreach (Line item in list2) { list.Add(new Placement { Pos = item.Pos(p.Pos) }); } if (list2.Count == 2) { list.Add(new Placement { Pos = list2[1].Pos(list2[0].Pos(p.Pos)) }); } return list; } private static bool HasTwin(Dictionary<Vector3Int, List<Piece>> index, string name, Vector3 at) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_006b: 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_0071: 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) Vector3Int val = Cell(at); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { for (int k = -1; k <= 1; k++) { if (!index.TryGetValue(new Vector3Int(((Vector3Int)(ref val)).x + i, ((Vector3Int)(ref val)).y + j, ((Vector3Int)(ref val)).z + k), out var value)) { continue; } foreach (Piece item in value) { if ((Object)(object)item != (Object)null) { Vector3 val2 = ((Component)item).transform.position - at; if (((Vector3)(ref val2)).sqrMagnitude < 0.0025f && Utils.GetPrefabName(((Component)item).gameObject) == name) { return true; } } } } } } return false; } } [BepInPlugin("digi.valheim.creativeworld", "Digi's Creative World", "1.4.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "digi.valheim.creativeworld"; public const string Name = "Digi's Creative World"; public const string Version = "1.4.0"; private static ConfigEntry<string> _worlds; private static ConfigEntry<float> _radius; private static ConfigEntry<float> _edge; private static ConfigEntry<float> _height; private static ConfigEntry<float> _centerX; private static ConfigEntry<float> _centerZ; private static ConfigEntry<bool> _fly; private static ConfigEntry<bool> _god; private static ConfigEntry<bool> _noCost; private static ConfigEntry<bool> _tools; private static ConfigEntry<bool> _hammer; private static ConfigEntry<bool> _noEnemies; private static ConfigEntry<bool> _noAnimals; private static ConfigEntry<bool> _noTrees; private static ConfigEntry<bool> _noGrass; private static ConfigEntry<bool> _onlyTemple; private static ConfigEntry<bool> _alwaysDay; private static ConfigEntry<bool> _noRain; private static ConfigEntry<bool> _noFog; private static ConfigEntry<bool> _stamina; private static ConfigEntry<bool> _noDrops; private static ConfigEntry<bool> _through; private static ConfigEntry<bool> _noDebris; private static bool _noclip; private static int _cameraMask; private static float _waterDistance; private static ConfigEntry<float> _timeOfDay; private static ConfigEntry<float> _flySpeed; private static ConfigEntry<float> _flyRunSpeed; private static ConfigEntry<KeyboardShortcut> _laterKey; private static ConfigEntry<KeyboardShortcut> _earlierKey; private static bool _heldTime; private static bool _heldWeather; private static volatile bool _active; private static float _r; private static float _rEdge; private static float _edgeLen; private static float _h; private static float _cx; private static float _cz; private static bool _gaveHammer; private static float _lastJump = -10f; private static float _timer; private void Awake() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Expected O, but got Unknown //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Expected O, but got Unknown //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_040e: Expected O, but got Unknown //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_045b: Unknown result type (might be due to invalid IL or missing references) _worlds = ((BaseUnityPlugin)this).Config.Bind<string>("1 - World", "World name", "Creative", "Worlds with this name are creative worlds (several names: separate with commas). Make a NEW world with this name: trees, grass and locations are only left out when an area is generated for the first time."); _radius = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Terrain", "Flat radius", 1500f, new ConfigDescription("Radius of the flat area around the centre, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(100f, 5000f), Array.Empty<object>())); _edge = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Terrain", "Edge", 200f, new ConfigDescription("Over how many metres past the flat area the ground eases back into the normal land.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(20f, 1000f), Array.Empty<object>())); _height = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Terrain", "Ground height", 6f, new ConfigDescription("Height of the flat ground above the sea, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>())); _centerX = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Terrain", "Centre X", 0f, "Centre of the flat area (east-west). 0, 0 is the middle of the world, where you spawn."); _centerZ = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Terrain", "Centre Z", 0f, "Centre of the flat area (north-south)."); _noTrees = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Terrain", "No trees and rocks", true, "No trees, rocks, bushes, ore or plants in the flat area and its edge."); _noGrass = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Terrain", "No grass", true, "No grass in the flat area and its edge."); _onlyTemple = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Terrain", "Only the spawn temple", true, "No locations (ruins, altars, dungeons, traders) in the flat area and its edge, except the spawn temple."); _noCost = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Free building", true, "Every building piece unlocked and free, no workbench needed (the game's no-cost mode; crafting is free too)."); _fly = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Fly", true, "Double-tap jump to fly or land. Flying: Space up, Left Ctrl down, run key = faster."); _flySpeed = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Player", "Fly speed", 8f, new ConfigDescription("How fast you fly, in metres a second (the game's own is 20).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>())); _flyRunSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Player", "Fly speed running", 20f, new ConfigDescription("How fast you fly while holding the run key, in metres a second (the game's own is 50; steps of 2.5).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2.5f, 150f), Array.Empty<object>())); _through = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Fly through everything", true, "While flying you pass through the ground, buildings and everything else, and the camera does too."); _god = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No damage", true, "You take no damage (also no fall damage)."); _tools = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Tools never wear", true, "Hammer, hoe, cultivator and other tools stay at full durability."); _stamina = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Infinite stamina", true, "Running, jumping, swimming and building use no stamina."); _noDrops = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No drops", true, "Removing or breaking a building piece (or anything else) drops nothing."); _noDebris = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No debris", true, "A destroyed or removed building piece disappears at once instead of falling apart into loose pieces."); _hammer = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "Give a hammer", true, "Puts a hammer in your inventory when you arrive without one."); _noEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No enemies", true, "No enemies spawn in the creative world (greydwarfs, skeletons, trolls, raids, bosses' minions, ...)."); _noAnimals = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No animals", true, "No animals spawn in the creative world (deer, boars, hares, necks, fish, birds, ...)."); ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Player", "No creatures", true, ""); if (!val.Value) { ConfigEntry<bool> noEnemies = _noEnemies; bool value = (_noAnimals.Value = false); noEnemies.Value = value; } ((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val).Definition); ((BaseUnityPlugin)this).Config.Save(); _alwaysDay = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Weather", "Always day", true, "The time of day stands still at Time of day (noon unless you change it). Off: the time runs as normal."); _timeOfDay = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Weather", "Time of day", 0.5f, new ConfigDescription("The time it stands still at: 0 midnight, 0.25 sunrise (6:00), 0.5 noon, 0.75 sunset (18:00); it is night before about 0.22 and after about 0.78. Changes at once; Page Up / Page Down move it an hour.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); _laterKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("4 - Weather", "Later key", new KeyboardShortcut((KeyCode)280, Array.Empty<KeyCode>()), "One hour later (also switches Always day on, so the time stays there)."); _earlierKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("4 - Weather", "Earlier key", new KeyboardShortcut((KeyCode)281, Array.Empty<KeyCode>()), "One hour earlier (also switches Always day on)."); _noRain = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Weather", "No rain", true, "Always clear weather: no rain, storms or snow."); _noFog = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Weather", "No fog", true, "No fog at all, so you see to the horizon."); Harmony harmony = Harmony.CreateAndPatchAll(typeof(Plugin), "digi.valheim.creativeworld"); Mirror.InCreative = () => _active; Mirror.Bind(((BaseUnityPlugin)this).Config); Mirror.Patch(harmony); ((Component)this).gameObject.AddComponent<Mirror>(); Tools.InCreative = () => _active; Tools.Log = ((BaseUnityPlugin)this).Logger; Tools.Patch(harmony); Windows.Patch(harmony); ((Component)this).gameObject.AddComponent<Windows>(); BuildMaterials.Bind(((BaseUnityPlugin)this).Config); BuildMaterials.Register(); ((Component)this).gameObject.AddComponent<BuildMaterials>(); WoodSwap.Bind(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger); WoodSwap.Register(); ((Component)this).gameObject.AddComponent<WoodSwap>(); Schematics.Bind(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger); Schematics.Register(); ((Component)this).gameObject.AddComponent<Schematics>(); ((Component)this).gameObject.AddComponent<Tools>(); } private static bool IsCreative(World world) { if (world == null || world.m_menu) { return false; } string[] array = (_worlds.Value ?? "").Split(new char[1] { ',' }); foreach (string text in array) { if (text.Trim().Length > 0 && string.Equals(text.Trim(), world.m_name, StringComparison.OrdinalIgnoreCase)) { return true; } } return false; } [HarmonyPatch(typeof(WorldGenerator), "Initialize")] [HarmonyPostfix] private static void WorldStarted(World world) { _r = _radius.Value; _edgeLen = _edge.Value; _rEdge = _r + _edgeLen; _h = (((Object)(object)ZoneSystem.instance != (Object)null) ? (ZoneSystem.instance.m_waterLevel + _height.Value) : (30f + _height.Value)); _cx = _centerX.Value; _cz = _centerZ.Value; _active = IsCreative(world); _gaveHammer = false; _heldTime = (_heldWeather = false); if (_active) { Logger.CreateLogSource("Digi's Creative World").LogInfo((object)$"creative world '{world.m_name}': flat {_r} m around ({_cx}, {_cz}) at {_h} m"); } } private static float Weight(float x, float z) { float num = x - _cx; float num2 = z - _cz; float num3 = num * num + num2 * num2; if (num3 <= _r * _r) { return 1f; } if (num3 >= _rEdge * _rEdge) { return 0f; } float num4 = 1f - (Mathf.Sqrt(num3) - _r) / _edgeLen; return num4 * num4 * (3f - 2f * num4); } private static bool Inside(Vector3 p, float extra) { //IL_0000: 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) return InArea(p.x, p.z, extra); } private static bool InArea(float x, float z, float extra) { float num = x - _cx; float num2 = z - _cz; float num3 = _rEdge + extra; return num * num + num2 * num2 < num3 * num3; } [HarmonyPatch(typeof(WorldGenerator), "GetBiome", new Type[] { typeof(float), typeof(float), typeof(float), typeof(bool) })] [HarmonyPostfix] private static void Biome(float wx, float wy, ref Biome __result) { if (_active && InArea(wx, wy, 0f)) { __result = (Biome)1; } } [HarmonyPatch(typeof(WorldGenerator), "GetBiomeHeight")] [HarmonyPostfix] private static void Height(float wx, float wy, ref float __result) { if (_active) { float num = Weight(wx, wy); if (num > 0f) { __result = Mathf.Lerp(__result, _h, num); } } } [HarmonyPatch(typeof(ZoneSystem), "PlaceVegetation")] [HarmonyPrefix] private static bool Vegetation(Vector3 zoneCenterPos) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) if (_active && _noTrees.Value) { return !Inside(zoneCenterPos, 46f); } return true; } [HarmonyPatch(typeof(ZoneSystem), "PlaceLocations")] [HarmonyPrefix] private static bool Locations(ZoneSystem __instance, Vector2s zoneID) { //IL_001d: 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: 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_0043: 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_0072: Unknown result type (might be due to invalid IL or missing references) if (!_active || !_onlyTemple.Value) { return true; } if (!__instance.m_locationInstances.TryGetValue(zoneID, out var value) || value.m_placed) { return true; } if (!Inside(value.m_position, 0f) || value.m_location?.m_prefabName == "StartTemple") { return true; } value.m_placed = true; __instance.m_locationInstances[zoneID] = value; return false; } [HarmonyPatch(typeof(ClutterSystem), "GetPatchBiomes")] [HarmonyPostfix] private static void Grass(Vector3 center, ref Biome __result) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) if (_active && _noGrass.Value && Inside(center, 0f)) { __result = (Biome)0; } } [HarmonyPatch(typeof(EnvMan), "SetEnv")] [HarmonyPostfix] [HarmonyPriority(0)] private static void Fog() { if (_active && _noFog.Value) { RenderSettings.fogDensity = 0f; } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] [HarmonyPostfix] [HarmonyPriority(0)] private static void CanBuild(Player __instance, RequirementMode mode, ref bool __result) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (!__result && _active && (int)mode == 0 && __instance.m_noPlacementCost && (Object)(object)__instance == (Object)(object)Player.m_localPlayer) { __result = true; } } [HarmonyPatch(typeof(BuildUiPieceButton), "UpdateRequirements")] [HarmonyPostfix] [HarmonyPriority(0)] private static void ButtonColour(BuildUiPieceButton __instance) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (_active && (Object)(object)localPlayer != (Object)null && localPlayer.m_noPlacementCost && (Object)(object)__instance.m_icon != (Object)null) { ((Graphic)__instance.m_icon).color = Color.white; } } [HarmonyPatch(typeof(Piece), "DropResources")] [HarmonyPrefix] private static bool PieceDrops() { if (_active) { return !_noDrops.Value; } return true; } [HarmonyPatch(typeof(WearNTear), "RPC_CreateFragments")] [HarmonyPrefix] private static bool Fragments() { if (_active) { return !_noDebris.Value; } return true; } [HarmonyPatch(typeof(DropOnDestroyed), "OnDestroyed")] [HarmonyPrefix] private static bool ObjectDrops() { if (_active) { return !_noDrops.Value; } return true; } private static bool Blocked(GameObject prefab) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 if (!_active || (Object)(object)prefab == (Object)null) { return false; } Character component = prefab.GetComponent<Character>(); if (!((Object)(object)component == (Object)null) && (int)component.m_faction != 1) { return _noEnemies.Value; } return _noAnimals.Value; } [HarmonyPatch(typeof(SpawnSystem), "Spawn")] [HarmonyPrefix] private static bool RandomSpawn(SpawnData critter) { return !Blocked(critter?.m_prefab); } [HarmonyPatch(typeof(CreatureSpawner), "Spawn")] [HarmonyPrefix] private static bool PointSpawn(CreatureSpawner __instance) { return !Blocked(__instance.m_creaturePrefab); } [HarmonyPatch(typeof(SpawnArea), "SelectWeightedPrefab")] [HarmonyPostfix] private static void NestSpawn(ref SpawnData __result) { if (__result != null && Blocked(__result.m_prefab)) { __result = null; } } [HarmonyPatch(typeof(Player), "UseStamina")] [HarmonyPrefix] private static bool Stamina(Player __instance) { if (_active && _stamina.Value) { return !((Object)(object)__instance == (Object)(object)Player.m_localPlayer); } return true; } private void Update() { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Invalid comparison between Unknown and I4 Player localPlayer = Player.m_localPlayer; Noclip(localPlayer); if (!_active || (Object)(object)localPlayer == (Object)null || (Object)(object)ZNet.instance == (Object)null) { return; } if (_fly.Value && !Typing() && (ZInput.GetButtonDown("Jump") || ZInput.GetButtonDown("JoyJump"))) { if (Time.time - _lastJump < 0.35f) { localPlayer.ToggleDebugFly(); _lastJump = -10f; } else { _lastJump = Time.time; } } if (((Character)localPlayer).IsDebugFlying()) { Character.m_debugFlySpeed = Mathf.Max(1, Mathf.RoundToInt(((Character)localPlayer).m_run ? (_flyRunSpeed.Value / 2.5f) : _flySpeed.Value)); } if (!Typing()) { KeyboardShortcut value = _laterKey.Value; int num; if (!((KeyboardShortcut)(ref value)).IsDown()) { value = _earlierKey.Value; num = (((KeyboardShortcut)(ref value)).IsDown() ? (-1) : 0); } else { num = 1; } int num2 = num; if (num2 != 0) { float num3 = Mathf.Round(_timeOfDay.Value * 24f) + (float)num2; num3 = (num3 % 24f + 24f) % 24f; _timeOfDay.Value = num3 / 24f; _alwaysDay.Value = true; _timer = 1f; ((Character)localPlayer).Message((MessageType)1, $"Time {num3:00}:00", 0, (Sprite)null, false); } } _timer += Time.deltaTime; if (_timer < 0.5f) { return; } _timer = 0f; if (_noCost.Value && !localPlayer.m_noPlacementCost) { localPlayer.SetNoPlacementCost(true); } EnvMan instance = EnvMan.instance; if ((Object)(object)instance != (Object)null) { if (_alwaysDay.Value) { instance.m_debugTimeOfDay = true; instance.m_debugTime = _timeOfDay.Value; _heldTime = true; } else if (_heldTime) { instance.m_debugTimeOfDay = false; _heldTime = false; } if (_noRain.Value) { if (instance.m_forceEnv != "Clear") { instance.SetForceEnvironment("Clear"); } _heldWeather = true; } else if (_heldWeather) { instance.SetForceEnvironment(""); _heldWeather = false; } } if (_god.Value && !((Character)localPlayer).InGodMode()) { localPlayer.SetGodMode(true); } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (_tools.Value) { foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem.m_shared.m_useDurability && (int)allItem.m_shared.m_itemType == 19 && allItem.m_durability < allItem.GetMaxDurability()) { allItem.m_durability = allItem.GetMaxDurability(); } } } if (!_hammer.Value || _gaveHammer || ((Character)localPlayer).IsTeleporting() || ((Character)localPlayer).InIntro()) { return; } _gaveHammer = true; if (!inventory.GetAllItems().Any((ItemData i) => (Object)(object)i.m_dropPrefab != (Object)null && ((Object)i.m_dropPrefab).name == "Hammer")) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer"); if ((Object)(object)itemPrefab != (Object)null) { inventory.AddItem(itemPrefab, 1); } } } private void LateUpdate() { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Hud instance = Hud.instance; if (!_active || (Object)(object)localPlayer == (Object)null || !localPlayer.m_noPlacementCost || (Object)(object)instance == (Object)null || !Hud.IsPieceSelectionVisible()) { return; } if ((Object)(object)instance.m_buildUi != (Object)null) { foreach (BuildUiPieceButton pieceButton in instance.m_buildUi.m_pieceButtons) { if ((Object)(object)pieceButton != (Object)null && (Object)(object)pieceButton.m_icon != (Object)null && ((Graphic)pieceButton.m_icon).color != Color.white) { ((Graphic)pieceButton.m_icon).color = Color.white; } } } foreach (PieceIconData pieceIcon in instance.m_pieceIcons) { if ((Object)(object)pieceIcon?.m_icon != (Object)null && ((Graphic)pieceIcon.m_icon).color != Color.white) { ((Graphic)pieceIcon.m_icon).color = Color.white; } } } [HarmonyPatch(typeof(Character), "UnderWorldCheck")] [HarmonyPrefix] private static bool UnderWorld(Character __instance) { if (_noclip) { return !((Object)(object)__instance == (Object)(object)Player.m_localPlayer); } return true; } private static void Noclip(Player player) { //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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) bool flag = _active && _through.Value && (Object)(object)player != (Object)null && ((Character)player).IsDebugFlying(); if (flag == _noclip) { return; } _noclip = flag; if ((Object)(object)player != (Object)null && (Object)(object)((Character)player).m_body != (Object)null) { ((Character)player).m_body.detectCollisions = !flag; } GameCamera instance = GameCamera.instance; if ((Object)(object)instance != (Object)null) { if (flag) { _cameraMask = ((LayerMask)(ref instance.m_blockCameraMask)).value; instance.m_blockCameraMask = LayerMask.op_Implicit(0); _waterDistance = instance.m_minWaterDistance; instance.m_minWaterDistance = -100000f; } else { if (_cameraMask != 0) { instance.m_blockCameraMask = LayerMask.op_Implicit(_cameraMask); } if (_waterDistance > -1000f) { instance.m_minWaterDistance = _waterDistance; } } } if (flag || (Object)(object)player == (Object)null || (Object)(object)ZoneSystem.instance == (Object)null) { return; } Vector3 position = ((Component)player).transform.position; float groundHeight = ZoneSystem.instance.GetGroundHeight(position); if (!(position.y >= groundHeight - 0.3f)) { position.y = groundHeight + 0.2f; ((Component)player).transform.position = position; if (!((Object)(object)((Character)player).m_body == (Object)null)) { ((Character)player).m_body.position = position; ((Character)player).m_body.linearVelocity = Vector3.zero; } } } private static bool Typing() { if ((!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible()) { return Minimap.IsOpen(); } return true; } } internal class Schematics : MonoBehaviour { internal sealed class Entry { public string Prefab; public Vector3 Pos; public Quaternion Rot; } internal sealed class Schematic { public string Name; public string File; public string Saved = ""; public int Count; public Vector3 Size; public readonly List<Entry> Pieces = new List<Entry>(); } private sealed class NameBox : TextReceiver { public Action<string> Done; public string GetText() { return ""; } public void SetText(string text) { Done?.Invoke(text); } } internal static ConfigEntry<bool> On; internal static ConfigEntry<KeyboardShortcut> LibraryKey; internal static ConfigEntry<KeyboardShortcut> FreeKey; internal static ConfigEntry<int> GhostPieces; private static Schematics _instance; private static ManualLogSource _log; private const string PlaceTool = "piece_digi_schematics"; private const int PictureSize = 256; private const int PastePerFrame = 150; private const float RowHeight = 116f; private static readonly CultureInfo Inv = CultureInfo.InvariantCulture; private static readonly Color GhostTint = new Color(0.12f, 0.3f, 0.4f); private static bool _busy; private static bool _pasting; private static bool _building; private static bool _aimValid; private static bool _mirrored; private static Schematic _chosen; private static List<Entry> _entries; private static List<Vector3> _snaps; private static GameObject _ghost; private static int _ghostGeneration; private static Vector3 _pos; private static Quaternion _rot; private static float _wheel; private static readonly Dictionary<string, List<Vector3>> PrefabSnaps = new Dictionary<string, List<Vector3>>(); private static readonly Dictionary<string, Sprite> Pictures = new Dictionary<string, Sprite>(); private static readonly List<Transform> Targets = new List<Transform>(); private static readonly List<Piece> TargetPieces = new List<Piece>(); private static readonly EffectList NoEffects = new EffectList { m_effectPrefabs = (EffectData[])(object)new EffectData[0] }; private static readonly Type ImageConversion = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule"); private static readonly MethodInfo EncodeToPng = ImageConversion?.GetMethod("EncodeToPNG", new Type[1] { typeof(Texture2D) }); private static readonly MethodInfo LoadImage = ImageConversion?.GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); private static string Folder => Path.Combine(Paths.ConfigPath, "DigiCreative", "Schematics"); internal static void Bind(ConfigFile config, ManualLogSource log) { //IL_0036: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Expected O, but got Unknown _log = log; On = config.Bind<bool>("8 - Schematics", "Schematic tools", true, "Save Schematic and Schematics in the hammer menu (Building tab, at the end): save a building to a file and paste it again, with a picture of each in the list and a ghost of the building while you place it."); LibraryKey = config.Bind<KeyboardShortcut>("8 - Schematics", "Library key", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Hold this while clicking with the Schematics tool: the list of schematics opens again (to pick another one)."); FreeKey = config.Bind<KeyboardShortcut>("8 - Schematics", "Free placement key", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "Hold this while placing a schematic: it does not snap onto the building you aim at."); GhostPieces = config.Bind<int>("8 - Schematics", "Ghost pieces", 1500, new ConfigDescription("Most pieces the ghost shows while you place a schematic. A bigger one shows that many, spread over it, and a box around it; pasting always places all.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 10000), Array.Empty<object>())); } internal static void Register() { //IL_0070: Unknown result type (might be due to invalid IL or missing references) Tools.Add("schematicsave", "Save Schematic", "Click a building: every piece connected to the one you click is saved as a schematic, with a picture. You give it a name.", "piece_cartographytable", () => On.Value, delegate(Player player) { if ((Object)(object)_instance != (Object)null && !_busy && !Windows.IsOpen) { ((MonoBehaviour)_instance).StartCoroutine(Save(player)); } }); Tools.Add("schematics", "Schematics", "Click: your saved schematics. After Place the building follows your aim; the scroll wheel turns it, a click pastes " + $"it. Hold {LibraryKey.Value} and click for the list again.", "Hammer", () => On.Value, delegate(Player player) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!_pasting && !Windows.IsOpen) { if (_chosen != null) { KeyboardShortcut value = LibraryKey.Value; if (!((KeyboardShortcut)(ref value)).IsPressed()) { if (_aimValid && (Object)(object)_ghost != (Object)null && !_building && (Object)(object)_instance != (Object)null) { ((MonoBehaviour)_instance).StartCoroutine(Paste(player)); } return; } } OpenLibrary(); } }); } private void Awake() { _instance = this; } private void OnDestroy() { DropGhost(); } private static IEnumerator Save(Player player) { Piece hoveringPiece = player.GetHoveringPiece(); if ((Object)(object)hoveringPiece == (Object)null || !hoveringPiece.IsPlacedByPlayer()) { ((Character)player).Message((MessageType)2, "Aim at a piece of the building to save", 0, (Sprite)null, false); yield break; } _busy = true; List<Piece> found = new List<Piece>(); try { int steps = 0; foreach (Piece item in Tools.Building(hoveringPiece, found)) { _ = item; int num = steps + 1; steps = num; if (num % 150 == 0) { yield return null; } } } finally { _busy = false; } List<Piece> list = found.Where((Piece p) => (Object)(object)p != (Object)null).ToList(); if (list.Count == 0) { yield break; } Bounds bounds = Tools.BoundsOf(list[0]); foreach (Piece item2 in list) { ((Bounds)(ref bounds)).Encapsulate(Tools.BoundsOf(item2)); } Vector3 anchor = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z); List<Entry> entries = list.Select((Piece p) => new Entry { Prefab = Utils.GetPrefabName(((Component)p).gameObject), Pos = ((Component)p).transform.position - anchor, Rot = ((Component)p).transform.rotation }).ToList(); byte[] picture = Photo(bounds); Vector3 size = ((Bounds)(ref bounds)).size; if (!((Object)(object)TextInput.instance == (Object)null)) { TextInput.instance.RequestText((TextReceiver)(object)new NameBox { Done = delegate(string name) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) Store(player, name, entries, size, picture); } }, $"Name of the schematic ({entries.Count} pieces)", 40); } } private static void Store(Player player, string name, List<Entry> entries, Vector3 size, byte[] picture) { //IL_0141: 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) //IL_016d: Unknown result type (might be due to invalid IL or missing references) char[] bad = Path.GetInvalidFileNameChars().Concat(new char[2] { ';', '=' }).ToArray(); string text = new string((from c in (name ?? "").Trim() select (!bad.Contains(c)) ? c : '_').ToArray()).Trim(); if (text.Length == 0) { return; } try { Directory.CreateDirectory(Folder); string text2 = Path.Combine(Folder, text + ".schematic"); int num = 2; while (File.Exists(text2)) { text2 = Path.Combine(Folder, $"{text} {num}.schematic"); num++; } string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("# Digi's Creative World schematic"); stringBuilder.AppendLine("name=" + fileNameWithoutExtension); stringBuilder.AppendLine("saved=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm", Inv)); stringBuilder.AppendLine("pieces=" + entries.Count); stringBuilder.AppendLine("size=" + F(size.x) + " " + F(size.y) + " " + F(size.z)); stringBuilder.AppendLine("# prefab;x;y;z;qx;qy;qz;qw (metres from the middle of the bottom, world directions)"); foreach (Entry entry in entries) { stringBuilder.Append(entry.Prefab).Append(';').Append(F(entry.Pos.x)) .Append(';') .Append(F(entry.Pos.y)) .Append(';') .Append(F(entry.Pos.z)) .Append(';') .Append(Q(entry.Rot.x)) .Append(';') .Append(Q(entry.Rot.y)) .Append(';') .Append(Q(entry.Rot.z)) .Append(';') .Append(Q(entry.Rot.w)) .AppendLine(); } File.WriteAllText(text2, stringBuilder.ToString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); if (picture != null) { File.WriteAllBytes(Path.ChangeExtension(text2, ".png"), picture); } ((Character)player).Message((MessageType)2, "Saved schematic " + fileNameWithoutExtension + ": " + BuildMaterials.Number(entries.Count) + " pieces", 0, (Sprite)null, false); ManualLogSource log = _log; if (log != null) { log.LogInfo((object)$"Saved schematic {text2}: {entries.Count} pieces"); } } catch (Exception ex) { ((Character)player).Message((MessageType)2, "Could not save the schematic (see the log)", 0, (Sprite)null, false); ManualLogSource log2 = _log; if (log2 != null) { log2.LogError((object)("Saving a schematic failed: " + ex)); } } } private static string F(float v) { return v.ToString("0.####", Inv); } private static string Q(float v) { return v.ToString("0.######", Inv); } private static byte[] Photo(Bounds bounds) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_00b2: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) Camera mainCamera = Utils.GetMainCamera(); if ((Object)(object)mainCamera == (Object)null) { return null; } GameObject val = null; RenderTexture val2 = null; Texture2D val3 = null; try { val = new GameObject("DigiCreative_SchematicCamera"); Camera val4 = val.AddComponent<Camera>(); val4.CopyFrom(mainCamera); ((Behaviour)val4).enabled = false; val4.cullingMask = mainCamera.cullingMask & ~LayerMask.GetMask(new string[8] { "UI", "character", "character_net", "character_ghost", "character_noenv", "player", "ghost", "item" }); val4.fieldOfView = 35f; val4.aspect = 1f; Vector3 forward = ((Component)mainCamera).transform.forward; forward.y = 0f; if (((Vector3)(ref forward)).sqrMagnitude < 0.01f) { forward = Vector3.forward; } Vector3 val5 = Quaternion.AngleAxis(30f, Vector3.Cross(Vector3.up, ((Vector3)(ref forward)).normalized)) * ((Vector3)(ref forward)).normalized; Vector3 extents = ((Bounds)(ref bounds)).extents; float num = Mathf.Max(((Vector3)(ref extents)).magnitude, 1f); float num2 = num / Mathf.Sin(val4.fieldOfView * 0.5f * ((float)Math.PI / 180f)) * 1.05f; ((Component)val4).transform.position = ((Bounds)(ref bounds)).center - val5 * num2; ((Component)val4).transform.rotation = Quaternion.LookRotation(val5); val4.nearClipPlane = Mathf.Max(0.1f, num2 - num - 1f); val4.farClipPlane = num2 + num * 3f + 100f; val2 = (val4.targetTexture = RenderTexture.GetTemporary(256, 256, 24, (RenderTextureFormat)0)); val4.Render(); val4.targetTexture = null; RenderTexture active = RenderTexture.active; RenderTexture.active = val2; val3 = new Texture2D(256, 256, (TextureFormat)3, false); val3.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0); val3.Apply(); RenderTexture.active = active; return EncodeToPng?.Invoke(null, new object[1] { val3 }) as byte[]; } catch (Exception ex) { ManualLogSource log = _log; if (log != null) { log.LogWarning((object)("No picture for the schematic: " + ex.Message)); } return null; } finally { if ((Object)(object)val2 != (Object)null) { RenderTexture.ReleaseTemporary(val2); } if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } if ((Object)(object)val3 != (Object)null) { Object.Destroy((Object)(object)val3); } } } private static Schematic Load(string file, bool pieces) { //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) Schematic schematic = new Schematic { File = file, Name = Path.GetFileNameWithoutExtension(file) }; Quaternion val = default(Quaternion); foreach (string item in File.ReadLines(file)) { string text = item.Trim(); if (text.Length == 0 || text[0] == '#') { continue; } if (text.IndexOf(';') < 0) { int num = text.IndexOf('='); if (num <= 0) { continue; } string text2 = text.Substring(0, num).Trim(); string text3 = text.Substring(num + 1).Trim(); if (text2 == "name" && text3.Length > 0) { schematic.Name = text3; continue; } switch (text2) { case "saved": schematic.Saved = text3; break; case "pieces": int.TryParse(text3, NumberStyles.Integer, Inv, out schematic.Count); break; case "size": { string[] array = text3.Split(new char[1] { ' ' }); if (array.Length == 3) { schematic.Size = new Vector3(P(array[0]), P(array[1]), P(array[2])); } break; } } } else { if (!pieces) { break; } string[] array2 = text.Split(new char[1] { ';' }); if (array2.Length >= 8 && array2[0].Length != 0) { ((Quaternion)(ref val))..ctor(P(array2[4]), P(array2[5]), P(array2[6]), P(array2[7])); schematic.Pieces.Add(new Entry { Prefab = array2[0], Pos = new Vector3(P(array2[1]), P(array2[2]), P(array2[3])), Rot = ((val.x == 0f && val.y == 0f && val.z == 0f && val.w == 0f) ? Quaternion.identity : ((Quaternion)(ref val)).normalized) }); } } } if (pieces) { schematic.Count = schematic.Pieces.Count; } return schematic; } private static float P(string s) { if (!float.TryParse(s, NumberStyles.Float, Inv, out var result)) { return 0f; } return result; } private static Sprite PictureOf(string file) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_00c0: 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) string text = Path.ChangeExtension(file, ".png"); if (!File.Exists(text)) { return null; } string key = text + "|" + File.GetLastWriteTimeUtc(text).Ticks