Decompiled source of GridLock v1.3.0
GridLock.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text.Json; using System.Text.RegularExpressions; using AskaGridLock.Core; using AskaGridLock.Core.Laser; using AskaShared.Game; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.Injection; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using Microsoft.CodeAnalysis; using SSSGame; using SSSGame.Network; using SandSailorStudio; using SandSailorStudio.Localization; using SandSailorStudio.TerrainTools; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("GridLock")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.0")] [assembly: AssemblyInformationalVersion("1.3.0+c6eb963f77be580a311a7da92b30a76bfc3fa1af")] [assembly: AssemblyProduct("Grid Lock")] [assembly: AssemblyTitle("GridLock")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.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; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte flag) { NullableFlags = new byte[1] { flag }; } public NullableAttribute(byte[] flags) { NullableFlags = flags; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte flag) { Flag = flag; } } } namespace AskaGridLock { internal static class GridLockConfig { private static ConfigEntry<bool> _enabled; private static ConfigEntry<double> _spacing; private static ConfigEntry<double> _rotationStep; private static ConfigEntry<bool> _snapRoads; private const double DefaultPostSnapRadius = 1.0; private static ConfigEntry<bool> _laserEnabled; private static ConfigEntry<double> _laserExtensionLength; private static ConfigEntry<double> _alignmentDetectionDistance; private static ConfigEntry<double> _alignmentTolerance; private static ConfigEntry<double> _laserVisualThickness; private static ConfigEntry<double> _laserGlowIntensity; private static ConfigEntry<double> _snapIndicatorSize; private static ConfigEntry<double> _laserHeightLimit; private static ConfigEntry<double> _snapIndicatorRadius; private static ConfigEntry<double> _minFootprintHalfExtent; private static ConfigEntry<bool> _alignmentSnap; private static ConfigEntry<double> _alignmentSnapCapture; private static ConfigEntry<double> _laserHaloScale; private static ConfigEntry<bool> _laserPulse; private static ConfigEntry<double> _snapIndicatorThickness; private const double SquareSize = 2.0; internal static ConfigEntry<KeyCode> FreeMoveKey; internal static bool Enabled { get { if (_enabled != null) { return _enabled.Value; } return false; } } internal static bool SnapRoads { get { if (_snapRoads != null) { return _snapRoads.Value; } return false; } } internal static bool SnapTerrain => true; internal static bool SnapSkewed => true; internal static GridConfig Grid { get; private set; } internal static bool LaserEnabled { get { if (Enabled && _laserEnabled != null) { return _laserEnabled.Value; } return false; } } internal static LaserConfig Laser { get; private set; } internal static int Version { get; private set; } internal static bool AlignmentSnapEnabled { get { if (_alignmentSnap != null) { return _alignmentSnap.Value; } return true; } } internal static bool LaserPulseEnabled { get { if (_laserPulse != null) { return _laserPulse.Value; } return false; } } internal static void Init(ConfigFile config) { _enabled = config.Bind<bool>("Grid", "Enabled", true, "Master switch. When false the mod snaps nothing."); _spacing = config.Bind<double>("Grid", "Spacing", 0.5, "Minimum snap increment, in terraforming squares. One square is 2 world units, so the world snap step is Spacing * 2 (default 0.5 = 1.0 units)."); _rotationStep = config.Bind<double>("Grid", "RotationStep", 15.0, "Rotation snap increment in degrees."); _snapRoads = config.Bind<bool>("Grid", "SnapRoads", true, "Snap the points of paths, roads, ramparts, and moats to the grid. Set false to lay them the vanilla way."); _laserEnabled = config.Bind<bool>("Laser", "Enabled", true, "Draw the alignment laser overlay while a build ghost is live. The [Grid] Enabled master switch gates it as well."); _laserExtensionLength = config.Bind<double>("Laser", "LaserExtensionLength", 10.0, "How far each footprint edge's laser reaches past the structure, in world units. Clamped to 0.5..20."); _alignmentDetectionDistance = config.Bind<double>("Laser", "AlignmentDetectionDistance", 20.0, Advanced("Radius around the ghost, in world units, within which already-placed structures contribute alignment guides. Clamped to 1..50.")); _alignmentTolerance = config.Bind<double>("Laser", "AlignmentTolerance", 0.05, Advanced("Largest perpendicular gap between two edge lines that still counts as aligned, in world units. Clamped to 0.001..0.5.")); _laserVisualThickness = config.Bind<double>("Laser", "LaserVisualThickness", 0.05, "Laser line width in world units. Clamped to 0.005..0.5."); _laserGlowIntensity = config.Bind<double>("Laser", "LaserGlowIntensity", 1.5, "Sets the halo strength: halo alpha is 0.25 times this value, clamped to 0.05..1. Does not affect the laser's core line. Clamped to 0.1..5."); _snapIndicatorSize = config.Bind<double>("Laser", "SnapIndicatorSize", 0.08, Advanced("Total length of each cross segment of a red snap-point indicator, in world units. Clamped to 0.01..0.5.")); _laserHeightLimit = config.Bind<double>("Laser", "LaserHeightLimit", 3.0, Advanced("Highest a draped line may float above the ground it follows, in world units. A ghost hovering further above the terrain than this keeps its lines on the ground rather than in the air with it. Clamped to 0.25..20.")); _snapIndicatorRadius = config.Bind<double>("Laser", "SnapIndicatorRadius", 15.0, Advanced("Half-width, in world units, of the square of red snap crosses drawn around the ghost. 15 covers a 31x31 square of intersections on the default 1-unit grid. Clamped to 1..50.")); _minFootprintHalfExtent = config.Bind<double>("Laser", "MinFootprintHalfExtent", 0.75, Advanced("Smallest footprint half extent, in world units, that still draws guides. A placed structure below this on both axes - a flag, marker, or small prop - contributes nothing. 0 excludes nothing. Clamped to 0..5.")); _alignmentSnap = config.Bind<bool>("Laser", "AlignmentSnap", true, Advanced("Pull an angled build ghost onto a parallel guide of an already-placed structure, so a row of rotated structures can share a wall line the square grid cannot land on. Never applies to a cardinal (0/90/180/270) ghost, to fences, gates, and hedges, or while the free-move key is held.")); _alignmentSnapCapture = config.Bind<double>("Laser", "AlignmentSnapCapture", 0.5, Advanced("Largest perpendicular gap, in world units, at which a ghost edge is pulled onto a parallel guide; it is also the distance at which the pull releases as you move away. Clamped to 0.05..2.")); _laserHaloScale = config.Bind<double>("Laser", "LaserHaloScale", 4.0, Advanced("Width of the soft halo drawn under each laser, as a multiple of LaserVisualThickness. Unitless, so 4 draws a halo four times as wide as the line inside it. 0 draws the line on its own. Clamped to 0..10.")); _laserPulse = config.Bind<bool>("Laser", "LaserPulse", false, Advanced("Pulse the brightness of every laser's inner line by 8%, one cycle per second. Off by default; the halo and the snap crosses never pulse.")); _snapIndicatorThickness = config.Bind<double>("Laser", "SnapIndicatorThickness", 0.02, Advanced("Line width of the red snap crosses, in world units, independent of LaserVisualThickness. Clamped to 0.005..0.2.")); FreeMoveKey = config.Bind<KeyCode>("Grid", "FreeMoveKey", (KeyCode)304, "Hold to move the ghost freely off the grid, preserving its current rotation. Release to re-snap to the nearest grid pose."); Rebuild(); config.SettingChanged += delegate { Rebuild(); }; config.ConfigReloaded += delegate { Rebuild(); }; } private static ConfigDescription Advanced(string description) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { "Advanced" }); } private static void Rebuild() { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0223: Expected O, but got Unknown //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Expected O, but got Unknown //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Expected O, but got Unknown //IL_035b: Unknown result type (might be due to invalid IL or missing references) //IL_0361: Expected O, but got Unknown //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Expected O, but got Unknown //IL_042f: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Expected O, but got Unknown //IL_0499: Unknown result type (might be due to invalid IL or missing references) //IL_049f: Expected O, but got Unknown //IL_0503: Unknown result type (might be due to invalid IL or missing references) //IL_0509: Expected O, but got Unknown //IL_056d: Unknown result type (might be due to invalid IL or missing references) //IL_0573: Expected O, but got Unknown //IL_05d7: Unknown result type (might be due to invalid IL or missing references) //IL_05dd: Expected O, but got Unknown //IL_0641: Unknown result type (might be due to invalid IL or missing references) //IL_0647: Expected O, but got Unknown //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_06b1: Expected O, but got Unknown GridConfig gridConfig = (Grid = new GridConfig(_spacing.Value, _rotationStep.Value, 2.0, 1.0)); bool flag = default(bool); if (gridConfig.Spacing != _spacing.Value) { ManualLogSource log = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(32, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] Spacing "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_spacing.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(gridConfig.Spacing); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log.LogInfo(val); } if (gridConfig.RotationStep != _rotationStep.Value) { ManualLogSource log2 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] RotationStep "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_rotationStep.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(gridConfig.RotationStep); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log2.LogInfo(val); } if (gridConfig.PostSnapRadius != 1.0) { ManualLogSource log3 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] PostSnapRadius "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(1.0); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(gridConfig.PostSnapRadius); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log3.LogInfo(val); } LaserConfig laserConfig = (Laser = new LaserConfig(_laserExtensionLength.Value, _alignmentDetectionDistance.Value, _alignmentTolerance.Value, _laserVisualThickness.Value, _laserGlowIntensity.Value, _snapIndicatorSize.Value, _laserHeightLimit.Value, _snapIndicatorRadius.Value, _minFootprintHalfExtent.Value, _alignmentSnapCapture.Value, _laserHaloScale.Value, _snapIndicatorThickness.Value)); Version++; if (laserConfig.ExtensionLength != _laserExtensionLength.Value) { ManualLogSource log4 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(45, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] LaserExtensionLength "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_laserExtensionLength.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.ExtensionLength); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log4.LogInfo(val); } if (laserConfig.DetectionDistance != _alignmentDetectionDistance.Value) { ManualLogSource log5 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(51, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] AlignmentDetectionDistance "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_alignmentDetectionDistance.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.DetectionDistance); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log5.LogInfo(val); } if (laserConfig.Tolerance != _alignmentTolerance.Value) { ManualLogSource log6 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] AlignmentTolerance "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_alignmentTolerance.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.Tolerance); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log6.LogInfo(val); } if (laserConfig.Thickness != _laserVisualThickness.Value) { ManualLogSource log7 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(45, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] LaserVisualThickness "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_laserVisualThickness.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.Thickness); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log7.LogInfo(val); } if (laserConfig.GlowIntensity != _laserGlowIntensity.Value) { ManualLogSource log8 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] LaserGlowIntensity "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_laserGlowIntensity.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.GlowIntensity); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log8.LogInfo(val); } if (laserConfig.SnapIndicatorSize != _snapIndicatorSize.Value) { ManualLogSource log9 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] SnapIndicatorSize "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_snapIndicatorSize.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.SnapIndicatorSize); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log9.LogInfo(val); } if (laserConfig.HeightLimit != _laserHeightLimit.Value) { ManualLogSource log10 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(41, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] LaserHeightLimit "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_laserHeightLimit.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.HeightLimit); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log10.LogInfo(val); } if (laserConfig.SnapIndicatorRadius != _snapIndicatorRadius.Value) { ManualLogSource log11 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] SnapIndicatorRadius "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_snapIndicatorRadius.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.SnapIndicatorRadius); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log11.LogInfo(val); } if (laserConfig.MinFootprintHalfExtent != _minFootprintHalfExtent.Value) { ManualLogSource log12 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(47, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] MinFootprintHalfExtent "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_minFootprintHalfExtent.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.MinFootprintHalfExtent); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log12.LogInfo(val); } if (laserConfig.SnapCapture != _alignmentSnapCapture.Value) { ManualLogSource log13 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(45, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] AlignmentSnapCapture "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_alignmentSnapCapture.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.SnapCapture); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log13.LogInfo(val); } if (laserConfig.HaloScale != _laserHaloScale.Value) { ManualLogSource log14 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] LaserHaloScale "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_laserHaloScale.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.HaloScale); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log14.LogInfo(val); } if (laserConfig.SnapIndicatorThickness != _snapIndicatorThickness.Value) { ManualLogSource log15 = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(47, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock] SnapIndicatorThickness "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(_snapIndicatorThickness.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" clamped to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(laserConfig.SnapIndicatorThickness); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } log15.LogInfo(val); } } } public class GridLockTool : MonoBehaviour { private void Update() { SnapPatches.TickFreeMode(); } } internal static class AlignmentSnapState { private static readonly List<LaserLine[]> Lines = new List<LaserLine[]>(); private static bool _hasMoving; private static double _offsetX; private static double _offsetZ; private static double _halfX; private static double _halfZ; internal static IReadOnlyList<LaserLine[]> StationaryLines => Lines; internal static void Publish(in WorldFootprint moving, List<LaserLine[]> stationaryLines) { Lines.Clear(); if (stationaryLines != null) { for (int i = 0; i < stationaryLines.Count; i++) { Lines.Add(stationaryLines[i]); } } Footprint2D footprint = moving.Footprint; if (!footprint.IsValid) { _hasMoving = false; return; } double num = footprint.CenterX - (double)moving.PivotX; double num2 = footprint.CenterZ - (double)moving.PivotZ; (double, double) tuple = Footprint2D.Right(footprint.YawDegrees); (double, double) tuple2 = Footprint2D.Forward(footprint.YawDegrees); _offsetX = num * tuple.Item1 + num2 * tuple.Item2; _offsetZ = num * tuple2.Item1 + num2 * tuple2.Item2; _halfX = footprint.HalfX; _halfZ = footprint.HalfZ; _hasMoving = true; } internal static void Clear() { Lines.Clear(); _hasMoving = false; _offsetX = 0.0; _offsetZ = 0.0; _halfX = 0.0; _halfZ = 0.0; } internal static bool TryGetMovingLocal(out double offX, out double offZ, out double halfX, out double halfZ) { offX = (_hasMoving ? _offsetX : 0.0); offZ = (_hasMoving ? _offsetZ : 0.0); halfX = (_hasMoving ? _halfX : 0.0); halfZ = (_hasMoving ? _halfZ : 0.0); return _hasMoving; } } internal static class FootprintReader { private static bool _failureLogged; private static bool _footprintComponentFailureLogged; internal static bool TryRead(GameObject root, out WorldFootprint result) { //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0312: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_0282: 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_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0179: 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_0184: Unknown result type (might be due to invalid IL or missing references) result = default(WorldFootprint); try { if ((Object)(object)root == (Object)null) { return false; } Transform transform = root.transform; Vector3 position = transform.position; double num = transform.eulerAngles.y; double num2 = (0.0 - num) * Math.PI / 180.0; double cos = Math.Cos(num2); double sin = Math.Sin(num2); double minX = double.MaxValue; double maxX = double.MinValue; double minZ = double.MaxValue; double maxZ = double.MinValue; float minY = float.MaxValue; float maxY = float.MinValue; bool flag = false; BoxCollider val = TryFindFootprintCollider(root); if ((Object)(object)val != (Object)null) { BoxLocalBounds(val, out var lo, out var hi); Accumulate(lo, hi, ((Component)val).transform, position, cos, sin, ref minX, ref maxX, ref minZ, ref maxZ, ref minY, ref maxY); flag = true; } if (!flag) { List<BoxCollider> list = CollectLogicFootprintBoxes(root); for (int i = 0; i < list.Count; i++) { BoxCollider val2 = list[i]; BoxLocalBounds(val2, out var lo2, out var hi2); Accumulate(lo2, hi2, ((Component)val2).transform, position, cos, sin, ref minX, ref maxX, ref minZ, ref maxZ, ref minY, ref maxY); flag = true; } } string reason; if (!flag) { Il2CppArrayBase<Collider> componentsInChildren = root.GetComponentsInChildren<Collider>(true); int num3 = componentsInChildren?.Length ?? 0; for (int j = 0; j < num3; j++) { Collider val3 = componentsInChildren[j]; if (!((Object)(object)val3 == (Object)null) && !ShouldSkipCollider(val3, out reason) && TryLocalBox(val3, out var lo3, out var hi3)) { Accumulate(lo3, hi3, ((Component)val3).transform, position, cos, sin, ref minX, ref maxX, ref minZ, ref maxZ, ref minY, ref maxY); flag = true; } } } if (!flag) { Il2CppArrayBase<Renderer> componentsInChildren2 = root.GetComponentsInChildren<Renderer>(true); int num4 = componentsInChildren2?.Length ?? 0; for (int k = 0; k < num4; k++) { Renderer val4 = componentsInChildren2[k]; if (!((Object)(object)val4 == (Object)null) && TryRendererLocalBox(val4, out Vector3 lo4, out Vector3 hi4, out reason)) { Accumulate(lo4, hi4, ((Component)val4).transform, position, cos, sin, ref minX, ref maxX, ref minZ, ref maxZ, ref minY, ref maxY); flag = true; } } } if (!flag) { return false; } double num5 = (minX + maxX) * 0.5; double num6 = (minZ + maxZ) * 0.5; double num7 = num * Math.PI / 180.0; double num8 = Math.Cos(num7); double num9 = Math.Sin(num7); double centerX = (double)position.x + (num5 * num8 + num6 * num9); double centerZ = (double)position.z + ((0.0 - num5) * num9 + num6 * num8); Footprint2D footprint = new Footprint2D(centerX, centerZ, num, (maxX - minX) * 0.5, (maxZ - minZ) * 0.5); if (!footprint.IsValid) { return false; } result = new WorldFootprint(footprint, minY, maxY, position.x, position.z); return true; } catch (Exception ex) { if (!_failureLogged) { _failureLogged = true; ManualLogSource log = Plugin.Log; bool flag2 = default(bool); BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(74, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[GridLock][laser] FootprintReader.TryRead threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Exception>(ex); } log.LogError(val5); } return false; } } private static BoxCollider TryFindFootprintCollider(GameObject root) { try { StructureFootprint componentInChildren = root.GetComponentInChildren<StructureFootprint>(true); if ((Object)(object)componentInChildren == (Object)null) { return null; } BoxCollider footprintCollider = componentInChildren.FootprintCollider; if ((Object)(object)footprintCollider != (Object)null) { return footprintCollider; } GameObject footprint = componentInChildren.footprint; return ((Object)(object)footprint != (Object)null) ? footprint.GetComponent<BoxCollider>() : null; } catch (Exception value) { if (!_footprintComponentFailureLogged) { _footprintComponentFailureLogged = true; Plugin.Log.LogWarning((object)("[GridLock][laser] StructureFootprint lookup threw (logged once, fail-open " + $"to the collider scan): {value}")); } return null; } } private static List<BoxCollider> CollectLogicFootprintBoxes(GameObject root) { List<BoxCollider> list = new List<BoxCollider>(); Il2CppArrayBase<Collider> componentsInChildren = root.GetComponentsInChildren<Collider>(true); int num = componentsInChildren?.Length ?? 0; for (int i = 0; i < num; i++) { Collider val = componentsInChildren[i]; if (!((Object)(object)val == (Object)null)) { BoxCollider val2 = ((Il2CppObjectBase)val).TryCast<BoxCollider>(); if (!((Object)(object)val2 == (Object)null) && IsLogicFootprintBox(val2)) { list.Add(val2); } } } return list; } private static bool IsLogicFootprintBox(BoxCollider box) { Transform transform = ((Component)box).transform; if (!string.Equals(((Object)((Component)transform).gameObject).name, "Footprint", StringComparison.OrdinalIgnoreCase)) { return false; } Transform parent = transform.parent; if ((Object)(object)parent != (Object)null) { return string.Equals(((Object)((Component)parent).gameObject).name, "Logic", StringComparison.OrdinalIgnoreCase); } return false; } private static void BoxLocalBounds(BoxCollider box, out Vector3 lo, out Vector3 hi) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_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_002b: 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) Vector3 val = box.size * 0.5f; lo = box.center - val; hi = box.center + val; } private static bool TryLocalBox(Collider c, out Vector3 lo, out Vector3 hi) { //IL_0001: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) lo = default(Vector3); hi = default(Vector3); BoxCollider val = ((Il2CppObjectBase)c).TryCast<BoxCollider>(); if ((Object)(object)val != (Object)null) { BoxLocalBounds(val, out lo, out hi); return true; } MeshCollider val2 = ((Il2CppObjectBase)c).TryCast<MeshCollider>(); if ((Object)(object)val2 != (Object)null) { Mesh sharedMesh = val2.sharedMesh; if ((Object)(object)sharedMesh == (Object)null) { return false; } Bounds bounds = sharedMesh.bounds; lo = ((Bounds)(ref bounds)).min; hi = ((Bounds)(ref bounds)).max; return true; } SphereCollider val3 = ((Il2CppObjectBase)c).TryCast<SphereCollider>(); if ((Object)(object)val3 != (Object)null) { float radius = val3.radius; Vector3 val4 = default(Vector3); ((Vector3)(ref val4))..ctor(radius, radius, radius); lo = val3.center - val4; hi = val3.center + val4; return true; } CapsuleCollider val5 = ((Il2CppObjectBase)c).TryCast<CapsuleCollider>(); if ((Object)(object)val5 != (Object)null) { float radius2 = val5.radius; float num = Mathf.Max(val5.height * 0.5f, radius2); Vector3 val6 = default(Vector3); ((Vector3)(ref val6))..ctor((val5.direction == 0) ? num : radius2, (val5.direction == 1) ? num : radius2, (val5.direction == 2) ? num : radius2); lo = val5.center - val6; hi = val5.center + val6; return true; } return false; } private static bool ShouldSkipCollider(Collider c, out string reason) { if (!c.enabled) { reason = "disabled"; return true; } if (c.isTrigger && !IsFootprintNamed(((Object)c).name)) { reason = "trigger not footprint-named"; return true; } reason = null; return false; } private static bool TryRendererLocalBox(Renderer r, out Vector3 lo, out Vector3 hi, out string skipReason) { //IL_0001: 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_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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) lo = default(Vector3); hi = default(Vector3); if (!r.enabled) { skipReason = "disabled"; return false; } MeshFilter component = ((Component)r).GetComponent<MeshFilter>(); if ((Object)(object)component == (Object)null) { skipReason = "no MeshFilter"; return false; } Mesh sharedMesh = component.sharedMesh; if ((Object)(object)sharedMesh == (Object)null) { skipReason = "no sharedMesh"; return false; } Bounds bounds = sharedMesh.bounds; lo = ((Bounds)(ref bounds)).min; hi = ((Bounds)(ref bounds)).max; skipReason = null; return true; } private static void Accumulate(Vector3 lo, Vector3 hi, Transform contributor, Vector3 origin, double cos, double sin, ref double minX, ref double maxX, ref double minZ, ref double maxZ, ref float minY, ref float maxY) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: 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_00bf: 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) Vector3 val = default(Vector3); for (int i = 0; i < 8; i++) { ((Vector3)(ref val))..ctor(((i & 1) == 0) ? lo.x : hi.x, ((i & 2) == 0) ? lo.y : hi.y, ((i & 4) == 0) ? lo.z : hi.z); Vector3 val2 = contributor.TransformPoint(val); double num = val2.x - origin.x; double num2 = val2.z - origin.z; double num3 = num * cos + num2 * sin; double num4 = (0.0 - num) * sin + num2 * cos; if (num3 < minX) { minX = num3; } if (num3 > maxX) { maxX = num3; } if (num4 < minZ) { minZ = num4; } if (num4 > maxZ) { maxZ = num4; } if (val2.y < minY) { minY = val2.y; } if (val2.y > maxY) { maxY = val2.y; } } } private static bool IsFootprintNamed(string name) { if (name != null) { return name.IndexOf("footprint", StringComparison.OrdinalIgnoreCase) >= 0; } return false; } } internal sealed class LaserLinePool { private const float MinSqrLength = 1E-08f; private const float MinWidth = 0.001f; private const float MinAlpha = 0.001f; private readonly List<LineRenderer> _pool = new List<LineRenderer>(64); private readonly Transform _root; private readonly int _sortingOrder; private readonly LineTextureMode _textureMode; private readonly Material _material; private int _used; private bool _failureLogged; internal int LineCount => _used; internal LaserLinePool(Transform parent, string name, int sortingOrder) : this(parent, name, sortingOrder, null, (LineTextureMode)0) { } internal LaserLinePool(Transform parent, string name, int sortingOrder, Material material, LineTextureMode textureMode) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown _sortingOrder = sortingOrder; _material = material; _textureMode = textureMode; GameObject val = new GameObject(name); val.transform.SetParent(parent, false); _root = val.transform; } internal void BeginFrame() { try { int num = Math.Min(_used, _pool.Count); for (int i = 0; i < num; i++) { LineRenderer val = _pool[i]; if ((Object)(object)val != (Object)null) { ((Renderer)val).enabled = false; } } } catch (Exception ex) { LogOnce("BeginFrame", ex); } _used = 0; } internal void AddLine(Vector3 a, Vector3 b, Color color, float width) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) if (width < 0.001f || color.a < 0.001f) { return; } Vector3 val = a - b; if (((Vector3)(ref val)).sqrMagnitude < 1E-08f) { return; } try { LineRenderer val2 = Rent(_used); if (!((Object)(object)val2 == (Object)null)) { _used++; ((Renderer)val2).enabled = true; val2.positionCount = 2; val2.SetPosition(0, a); val2.SetPosition(1, b); Style(val2, color, width); } } catch (Exception ex) { LogOnce("AddLine", ex); } } internal void AddLine(List<Vector3> points, Color color, float width) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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) //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_00ac: 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) if (points == null || points.Count < 2 || width < 0.001f || color.a < 0.001f) { return; } Vector3 val = points[0]; bool flag = false; for (int i = 1; i < points.Count; i++) { Vector3 val2 = points[i] - val; if (((Vector3)(ref val2)).sqrMagnitude >= 1E-08f) { flag = true; break; } } if (!flag) { return; } try { LineRenderer val3 = Rent(_used); if (!((Object)(object)val3 == (Object)null)) { _used++; ((Renderer)val3).enabled = true; val3.positionCount = points.Count; for (int j = 0; j < points.Count; j++) { val3.SetPosition(j, points[j]); } Style(val3, color, width); } } catch (Exception ex) { LogOnce("AddLine", ex); } } private static void Style(LineRenderer line, Color color, float width) { //IL_000f: 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) line.startWidth = width; line.endWidth = width; line.startColor = color; line.endColor = color; } internal void SetColor(Color color) { //IL_0032: 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) try { int num = Math.Min(_used, _pool.Count); for (int i = 0; i < num; i++) { LineRenderer val = _pool[i]; if (!((Object)(object)val == (Object)null)) { val.startColor = color; val.endColor = color; } } } catch (Exception ex) { LogOnce("SetColor", ex); } } private LineRenderer Rent(int index) { //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) //IL_0059: Unknown result type (might be due to invalid IL or missing references) while (_pool.Count <= index) { GameObject val = new GameObject($"Line_{_pool.Count}"); val.transform.SetParent(_root, false); LineRenderer val2 = val.AddComponent<LineRenderer>(); val2.useWorldSpace = true; val2.textureMode = _textureMode; val2.alignment = (LineAlignment)0; val2.numCapVertices = 4; val2.numCornerVertices = 2; ((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)val2).receiveShadows = false; ((Renderer)val2).lightProbeUsage = (LightProbeUsage)0; ((Renderer)val2).reflectionProbeUsage = (ReflectionProbeUsage)0; ((Renderer)val2).motionVectorGenerationMode = (MotionVectorGenerationMode)2; ((Renderer)val2).sortingOrder = _sortingOrder; val2.loop = false; val2.widthMultiplier = 1f; Material val3 = (((Object)(object)_material != (Object)null) ? _material : LaserMaterial.Get()); if ((Object)(object)val3 != (Object)null) { ((Renderer)val2).sharedMaterial = val3; } ((Renderer)val2).enabled = false; _pool.Add(val2); } return _pool[index]; } private void LogOnce(string where, Exception ex) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown if (!_failureLogged) { _failureLogged = true; ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(65, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock][laser] LaserLinePool."); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } } internal static class LaserMaterial { private const int HaloTextureHeight = 16; private const float HaloCentreAlpha = 1f; private static Material _material; private static bool _resolved; private static Material _halo; private static bool _haloResolved; private static Texture2D _haloTexture; internal static Material Get() { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (_resolved) { return _material; } _resolved = true; bool flag = default(bool); try { Shader val = Shader.Find("Sprites/Default"); if ((Object)(object)val == (Object)null) { val = Shader.Find("Unlit/Color"); } if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"[GridLock][laser] no line shader found (Sprites/Default and Unlit/Color both missing); lasers draw with Unity's default material."); return null; } Material val2 = new Material(val); ((Object)val2).hideFlags = (HideFlags)32; if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Color.white); } _material = val2; ManualLogSource log = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(40, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[GridLock][laser] line material shader: "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)val).name); } log.LogInfo(val3); } catch (Exception ex) { _material = null; ManualLogSource log2 = Plugin.Log; BepInExErrorLogInterpolatedStringHandler val4 = new BepInExErrorLogInterpolatedStringHandler(69, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[GridLock][laser] line shader lookup threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<Exception>(ex); } log2.LogError(val4); } return _material; } internal static Material GetHalo() { //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown if (_haloResolved) { return _halo; } _haloResolved = true; bool flag = default(bool); try { Shader val = Shader.Find("Legacy Shaders/Particles/Additive"); if ((Object)(object)val == (Object)null) { val = Shader.Find("Particles/Additive"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Mobile/Particles/Additive"); } if ((Object)(object)val == (Object)null) { val = Shader.Find("Sprites/Default"); } if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)"[GridLock][laser] no halo shader found (the three additive shaders and Sprites/Default are all missing); lasers draw their core only."); return null; } Material val2 = new Material(val); ((Object)val2).hideFlags = (HideFlags)32; if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Color.white); } Texture2D val3 = BuildFalloff(); if ((Object)(object)val3 != (Object)null) { _haloTexture = val3; val2.mainTexture = (Texture)(object)val3; } _halo = val2; ManualLogSource log = Plugin.Log; BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(40, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[GridLock][laser] halo material shader: "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((Object)val).name); } log.LogInfo(val4); } catch (Exception ex) { _halo = null; _haloTexture = null; ManualLogSource log2 = Plugin.Log; BepInExErrorLogInterpolatedStringHandler val5 = new BepInExErrorLogInterpolatedStringHandler(70, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("[GridLock][laser] halo material build threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Exception>(ex); } log2.LogError(val5); } return _halo; } private static Texture2D BuildFalloff() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_0069: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(1, 16, (TextureFormat)4, false); ((Object)val).hideFlags = (HideFlags)32; ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)1; for (int i = 0; i < 16; i++) { float t = Mathf.Abs((((float)i + 0.5f) / 16f - 0.5f) * 2f); val.SetPixel(0, i, new Color(1f, 1f, 1f, 1f * (1f - Smoothstep(t)))); } val.Apply(); return val; } private static float Smoothstep(float t) { if (t <= 0f) { return 0f; } if (t >= 1f) { return 1f; } return t * t * (3f - 2f * t); } } public class LaserOverlay : MonoBehaviour { private const int MaxSnapPoints = 1024; private const double PulseAmplitude = 0.08; private const float AlignedWidening = 1.3f; private const int StationaryHaloSortingOrder = 5000; private const int StationarySortingOrder = 5001; private const int SnapSortingOrder = 5002; private const int MovingHaloSortingOrder = 5003; private const int MovingSortingOrder = 5004; private const int AlignedHaloSortingOrder = 5005; private const int AlignedSortingOrder = 5006; private const float RebuildInterval = 1f; private const float GhostHeightTolerance = 0.1f; private bool _failureLogged; private bool _drawFailureLogged; private bool _poolFailureLogged; private LaserLinePool _stationaryHaloPool; private LaserLinePool _stationaryPool; private SnapCrossMesh _snapMesh; private LaserLinePool _movingHaloPool; private LaserLinePool _movingPool; private LaserLinePool _alignedHaloPool; private LaserLinePool _alignedPool; private readonly List<Vector3> _drapeBuffer = new List<Vector3>(64); private IReadOnlyList<List<Vector3>[]> _stationaryDraped; internal WorldFootprint Moving; internal LaserLine[] MovingLines; internal IReadOnlyList<WorldFootprint> Stationary; internal List<LaserLine[]> StationaryLines; internal List<AlignmentMatch> Matches; internal bool FreeMove; private bool _shown; private IntPtr _builtPreview; private Vector3 _builtPosition; private Quaternion _builtRotation; private bool _builtFreeMove; private bool _builtRoad; private int _builtRoadVersion; private int _builtConfigVersion; private int _builtStationaryVersion; private float _builtAt; private void Awake() { //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown MovingLines = Array.Empty<LaserLine>(); StationaryLines = new List<LaserLine[]>(); try { Material halo = LaserMaterial.GetHalo(); _stationaryHaloPool = new LaserLinePool(((Component)this).transform, "StationaryHalo", 5000, halo, (LineTextureMode)0); _stationaryPool = new LaserLinePool(((Component)this).transform, "Stationary", 5001); _snapMesh = new SnapCrossMesh(5002); _movingHaloPool = new LaserLinePool(((Component)this).transform, "MovingHalo", 5003, halo, (LineTextureMode)0); _movingPool = new LaserLinePool(((Component)this).transform, "Moving", 5004); _alignedHaloPool = new LaserLinePool(((Component)this).transform, "AlignedHalo", 5005, halo, (LineTextureMode)0); _alignedPool = new LaserLinePool(((Component)this).transform, "Aligned", 5006); } catch (Exception ex) { _stationaryHaloPool = null; _stationaryPool = null; _snapMesh?.Destroy(); _snapMesh = null; _movingHaloPool = null; _movingPool = null; _alignedHaloPool = null; _alignedPool = null; if (!_poolFailureLogged) { _poolFailureLogged = true; ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(116, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock][laser] line pools could not be created (logged once, fail-open); "); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("the overlay draws nothing this session: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } } private void OnDisable() { Hide(); } private void OnDestroy() { _snapMesh?.Destroy(); _snapMesh = null; } private void LateUpdate() { RunFrame(); } private void RunFrame() { //IL_03c9: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0167: 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_0365: Unknown result type (might be due to invalid IL or missing references) //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_036e: Unknown result type (might be due to invalid IL or missing references) try { if (!GridLockConfig.LaserEnabled) { Hide(); return; } GameObject val = SnapPatches.CurrentPreviewInstance(); if ((Object)(object)val == (Object)null || !val.activeInHierarchy) { Hide(); return; } LaserConfig laser = GridLockConfig.Laser; double cell = GridLockConfig.Grid.Cell; Transform transform = val.transform; Vector3 position = transform.position; Quaternion rotation = transform.rotation; bool flag = RoadLaserSource.IsRoadToolActive(); IReadOnlyList<(double, double)> points = null; double halfWidth = 0.0; double floorY = 0.0; double topY = 0.0; Vector3 val2 = position; if (flag) { if (!RoadLaserSource.TryGet(out points, out halfWidth, out floorY, out topY, out double movingX, out double movingZ)) { Hide(); return; } ((Vector3)(ref val2))..ctor((float)movingX, position.y, (float)movingZ); } IReadOnlyList<WorldFootprint> readOnlyList = StationaryScan.Near(val, val2, laser.DetectionDistance, laser.ExtensionLength, laser.HeightLimit, laser.MinFootprintHalfExtent, cell); float unscaledTime = Time.unscaledTime; bool isFreeMove = SnapPatches.IsFreeMove; IntPtr pointer = ((Il2CppObjectBase)val).Pointer; if (_shown && pointer == _builtPreview && position.x == _builtPosition.x && position.z == _builtPosition.z && Math.Abs(position.y - _builtPosition.y) < 0.1f && rotation == _builtRotation && isFreeMove == _builtFreeMove && flag == _builtRoad && (!flag || RoadLaserSource.Version == _builtRoadVersion) && GridLockConfig.Version == _builtConfigVersion && StationaryScan.ResultVersion == _builtStationaryVersion && unscaledTime - _builtAt < 1f) { if (GridLockConfig.LaserPulseEnabled) { Recolor(); } _snapMesh?.UpdateView(); return; } Hide(); LaserLine[] array; WorldFootprint result; if (flag) { array = RoadLasers.LinesFor(points, halfWidth, laser.ExtensionLength); if (array.Length == 0) { return; } double extensionLength = laser.ExtensionLength; result = new WorldFootprint(new Footprint2D(val2.x, val2.z, 0.0, halfWidth, halfWidth), (float)(floorY - extensionLength), (float)(topY + extensionLength), val2.x, val2.z); } else { if (!FootprintReader.TryRead(val, out result)) { return; } array = GridReference.LinesFor(result.Footprint, result.PivotX, result.PivotZ, cell, laser.ExtensionLength); } _stationaryDraped = StationaryScan.LastDraped; StationaryLines.Clear(); for (int i = 0; i < readOnlyList.Count; i++) { WorldFootprint worldFootprint = readOnlyList[i]; StationaryLines.Add(GridReference.LinesFor(worldFootprint.Footprint, worldFootprint.PivotX, worldFootprint.PivotZ, cell, laser.ExtensionLength)); } Moving = result; MovingLines = array; Stationary = readOnlyList; Matches = LaserAlignment.Find(array, StationaryLines, laser.Tolerance); FreeMove = isFreeMove; if (!flag) { AlignmentSnapState.Publish(in Moving, StationaryLines); } Draw(laser); _shown = true; _builtPreview = pointer; _builtPosition = position; _builtRotation = rotation; _builtFreeMove = isFreeMove; _builtRoad = flag; _builtRoadVersion = RoadLaserSource.Version; _builtConfigVersion = GridLockConfig.Version; _builtStationaryVersion = StationaryScan.ResultVersion; _builtAt = unscaledTime; } catch (Exception ex) { if (!_failureLogged) { _failureLogged = true; ManualLogSource log = Plugin.Log; bool flag2 = default(bool); BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(74, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[GridLock][laser] LaserOverlay.LateUpdate threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex); } log.LogError(val3); } } } private void Hide() { AlignmentSnapState.Clear(); if (_shown) { _shown = false; _stationaryHaloPool?.BeginFrame(); _stationaryPool?.BeginFrame(); _snapMesh?.Hide(); _movingHaloPool?.BeginFrame(); _movingPool?.BeginFrame(); _alignedHaloPool?.BeginFrame(); _alignedPool?.BeginFrame(); } } private void Recolor() { //IL_0012: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) double pulse = PulseFactor(); _stationaryPool?.SetColor(LaserPalette.Core(LaserPalette.StationaryRole, pulse)); _movingPool?.SetColor(LaserPalette.Core(LaserPalette.MovingRole, pulse)); _alignedPool?.SetColor(LaserPalette.Core(LaserPalette.AlignedRole, pulse)); } private void Draw(LaserConfig cfg) { //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d8: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: 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_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_033d: Unknown result type (might be due to invalid IL or missing references) //IL_0342: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) try { double glowIntensity = cfg.GlowIntensity; float num = (float)cfg.Thickness; float heightLimit = (float)cfg.HeightLimit; float floorY = Moving.FloorY; float topY = Moving.TopY; double pulse = PulseFactor(); bool flag = cfg.HaloScale > 0.0 && (Object)(object)LaserMaterial.GetHalo() != (Object)null; float haloWidth = (float)(cfg.Thickness * cfg.HaloScale); Color stationaryRole = LaserPalette.StationaryRole; Color coreColor = LaserPalette.Core(stationaryRole, pulse); Color haloColor = LaserPalette.Halo(stationaryRole, glowIntensity); LaserLinePool haloPool = (flag ? _stationaryHaloPool : null); for (int i = 0; i < Stationary.Count && i < StationaryLines.Count; i++) { LaserLine[] array = StationaryLines[i]; if (array == null) { continue; } List<Vector3>[] array2 = ((_stationaryDraped != null && i < _stationaryDraped.Count) ? _stationaryDraped[i] : null); WorldFootprint worldFootprint = Stationary[i]; for (int j = 0; j < array.Length; j++) { if (LaserAlignment.IsRelevant(MovingLines, in array[j], cfg.ExtensionLength)) { if (array2 != null && j < array2.Length && array2[j] != null) { AddCached(haloPool, _stationaryPool, array2[j], haloColor, haloWidth, coreColor, num); } else { AddDraped(haloPool, _stationaryPool, array[j].Laser, worldFootprint.FloorY, worldFootprint.TopY, heightLimit, haloColor, haloWidth, coreColor, num, _drapeBuffer); } } } } Color movingRole = LaserPalette.MovingRole; Color coreColor2 = LaserPalette.Core(movingRole, pulse); Color haloColor2 = LaserPalette.Halo(movingRole, glowIntensity); LaserLinePool haloPool2 = (flag ? _movingHaloPool : null); for (int k = 0; k < MovingLines.Length; k++) { AddDraped(haloPool2, _movingPool, MovingLines[k].Laser, floorY, topY, heightLimit, haloColor2, haloWidth, coreColor2, num, _drapeBuffer); } Color alignedRole = LaserPalette.AlignedRole; Color coreColor3 = LaserPalette.Core(alignedRole, pulse); Color haloColor3 = LaserPalette.Halo(alignedRole, glowIntensity); LaserLinePool haloPool3 = (flag ? _alignedHaloPool : null); float coreWidth = num * 1.3f; float haloWidth2 = (float)(cfg.Thickness * 1.2999999523162842 * cfg.HaloScale); int num2 = ((Matches != null) ? Matches.Count : 0); for (int l = 0; l < num2; l++) { AddDraped(haloPool3, _alignedPool, Matches[l].Green, floorY, topY, heightLimit, haloColor3, haloWidth2, coreColor3, coreWidth, _drapeBuffer); } if (!FreeMove && _snapMesh != null) { Footprint2D footprint = Moving.Footprint; List<(double, double)> list = SnapPoints.Around(footprint.CenterX, footprint.CenterZ, GridLockConfig.Grid.Cell, cfg.SnapIndicatorRadius, 1024); float halfLength = (float)(cfg.SnapIndicatorSize * 0.5); float width = (float)cfg.SnapIndicatorThickness; Color snapRole = LaserPalette.SnapRole; _snapMesh.Clear(); for (int m = 0; m < list.Count; m++) { float x = (float)list[m].Item1; float z = (float)list[m].Item2; _snapMesh.Add(x, LineDraper.HeightAt(x, z, floorY, topY, heightLimit), z); } _snapMesh.Commit(halfLength, width, snapRole); } } catch (Exception ex) { if (!_drawFailureLogged) { _drawFailureLogged = true; ManualLogSource log = Plugin.Log; bool flag2 = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(68, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock][laser] LaserOverlay.Draw threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } } private static void AddDraped(LaserLinePool haloPool, LaserLinePool corePool, in Segment2D segment, float floorY, float topY, float heightLimit, Color haloColor, float haloWidth, Color coreColor, float coreWidth, List<Vector3> buffer) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) if (buffer != null && (haloPool != null || corePool != null)) { LineDraper.Drape(in segment, floorY, topY, heightLimit, buffer); AddCached(haloPool, corePool, buffer, haloColor, haloWidth, coreColor, coreWidth); } } private static void AddCached(LaserLinePool haloPool, LaserLinePool corePool, List<Vector3> points, Color haloColor, float haloWidth, Color coreColor, float coreWidth) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) haloPool?.AddLine(points, haloColor, haloWidth); corePool?.AddLine(points, coreColor, coreWidth); } private static double PulseFactor() { if (!GridLockConfig.LaserPulseEnabled) { return 1.0; } return 1.0 + 0.08 * Math.Sin(Math.PI * 2.0 * (double)Time.unscaledTime); } } internal static class LaserPalette { private const double CoreWhitening = 0.15; private const double HaloAlphaScale = 0.25; private const float HaloAlphaMin = 0.05f; private const float HaloAlphaMax = 1f; internal static Color MovingRole => Role(0.2, 0.5, 1.0); internal static Color StationaryRole => Role(1.0, 0.85, 0.1); internal static Color AlignedRole => Role(0.2, 1.0, 0.3); internal static Color SnapRole => Role(1.0, 0.15, 0.15); internal static Color Core(Color role, double pulse) { //IL_0000: 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_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) return new Color((float)(Whiten(role.r) * pulse), (float)(Whiten(role.g) * pulse), (float)(Whiten(role.b) * pulse), 1f); } internal static Color Halo(Color role, double glow) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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) float num = Mathf.Clamp((float)(0.25 * glow), 0.05f, 1f); return new Color(role.r, role.g, role.b, num); } private static Color Role(double r, double g, double b) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return new Color((float)r, (float)g, (float)b, 1f); } private static double Whiten(double channel) { return channel + 0.15 * (1.0 - channel); } } internal static class LineDraper { internal const float Spacing = 0.5f; internal const float Lift = 0.25f; private const int MaxSamples = 256; internal static int Drape(in Segment2D seg, float floorY, float topY, float heightLimit, List<Vector3> into) { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) if (into == null) { return 0; } into.Clear(); double aX = seg.AX; double aZ = seg.AZ; double num = seg.BX - aX; double num2 = seg.BZ - aZ; double num3 = Math.Sqrt(num * num + num2 * num2); int num4 = 1; if (!double.IsNaN(num3) && !double.IsInfinity(num3) && num3 > 0.5) { num4 = (int)Math.Ceiling(num3 / 0.5); if (num4 > 256) { num4 = 256; } } for (int i = 0; i <= num4; i++) { double num5 = (double)i / (double)num4; float num6 = (float)(aX + num * num5); float num7 = (float)(aZ + num2 * num5); into.Add(new Vector3(num6, HeightAt(num6, num7, floorY, topY, heightLimit), num7)); } return into.Count; } internal static float HeightAt(float x, float z, float floorY, float topY, float heightLimit) { float num = floorY; if (TerrainHeight.TrySample(x, z, out var y) && !float.IsNaN(y) && !float.IsInfinity(y)) { num = y; } float num2 = Math.Min(topY, num + heightLimit); float num3 = num + 0.25f; if (num3 < floorY) { num3 = floorY; } if (num3 > num2) { num3 = num2; } return num3; } } internal static class RoadLaserSource { private static readonly List<(double X, double Z)> _points = new List<(double, double)>(8); private static double _halfWidth = double.NaN; private static double _floorY; private static double _topY; private static double _movingX; private static double _movingZ; internal static int Version { get; private set; } internal static void Begin() { _halfWidth = double.NaN; _points.Clear(); Version++; } internal static bool IsRoadToolActive() { try { PlayerBuilder val = SessionState.ResolveBuilder(); StructurePreviewData val2 = (((Object)(object)val != (Object)null) ? val.previewData : null); return val2 != null && ((Il2CppObjectBase)val2).TryCast<SplineStructurePreviewData>() != null; } catch { return false; } } internal static void Publish(PolyLinePlacement placement, int move, double width) { //IL_005a: 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_0063: 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_00de: 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) int count = placement.points.Count; double num = width * 0.5; bool flag = count != _points.Count || num != _halfWidth; _halfWidth = num; double num2 = double.MaxValue; double num3 = double.MinValue; for (int i = 0; i < count; i++) { Vector3 position = placement.GetPosition(i); (double, double) tuple = (position.x, position.z); if (i < _points.Count) { bool num4 = flag; (double, double) tuple2 = _points[i]; (double, double) tuple3 = tuple; flag = num4 | (tuple2.Item1 != tuple3.Item1 || tuple2.Item2 != tuple3.Item2); _points[i] = tuple; } else { _points.Add(tuple); } num2 = Math.Min(num2, position.y); num3 = Math.Max(num3, position.y); } if (_points.Count > count) { _points.RemoveRange(count, _points.Count - count); } if (flag) { if (count > 0) { (_movingX, _movingZ) = _points[(move >= 0 && move < count) ? move : (count - 1)]; } _floorY = num2; _topY = num3; Version++; } } internal static void Clear() { if (_points.Count != 0) { _points.Clear(); Version++; } } internal static void Reset() { _halfWidth = double.NaN; Clear(); } internal static bool TryGet(out IReadOnlyList<(double X, double Z)> points, out double halfWidth, out double floorY, out double topY, out double movingX, out double movingZ) { points = _points; halfWidth = _halfWidth; floorY = _floorY; topY = _topY; movingX = _movingX; movingZ = _movingZ; if (_points.Count > 0) { return !double.IsNaN(_halfWidth); } return false; } } internal sealed class SnapCrossMesh { private const int VerticesPerCross = 8; private const int IndicesPerCross = 12; private readonly int _sortingOrder; private GameObject _holder; private MeshRenderer _renderer; private Mesh _mesh; private readonly List<Vector3> _centers = new List<Vector3>(1024); private readonly Point3[] _corners = new Point3[4]; private Il2CppStructArray<Vector3> _vertices; private Il2CppStructArray<Color> _colors; private int _meshCrosses = -1; private float _halfLength; private float _width; private Camera _camera; private Transform _view; private Vector3 _cameraPosition; private Quaternion _cameraRotation; private bool _dirty; private bool _failureLogged; internal int Count { get { if (!((Object)(object)_renderer != (Object)null) || !((Renderer)_renderer).enabled) { return 0; } return _centers.Count; } } internal SnapCrossMesh(int sortingOrder) { _sortingOrder = sortingOrder; Create(); } private void Create() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown _holder = new GameObject("GridLockSnapCrosses"); _mesh = new Mesh(); _mesh.MarkDynamic(); _holder.AddComponent<MeshFilter>().sharedMesh = _mesh; _renderer = _holder.AddComponent<MeshRenderer>(); ((Renderer)_renderer).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)_renderer).receiveShadows = false; ((Renderer)_renderer).lightProbeUsage = (LightProbeUsage)0; ((Renderer)_renderer).reflectionProbeUsage = (ReflectionProbeUsage)0; ((Renderer)_renderer).motionVectorGenerationMode = (MotionVectorGenerationMode)2; ((Renderer)_renderer).sortingOrder = _sortingOrder; Material val = LaserMaterial.Get(); if ((Object)(object)val != (Object)null) { ((Renderer)_renderer).sharedMaterial = val; } ((Renderer)_renderer).enabled = false; _meshCrosses = -1; } internal void Clear() { _centers.Clear(); } internal void Add(float x, float y, float z) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) _centers.Add(new Vector3(x, y, z)); } internal void Commit(float halfLength, float width, Color color) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) try { _halfLength = halfLength; _width = width; if (_centers.Count == 0) { Hide(); return; } if ((Object)(object)_holder == (Object)null || (Object)(object)_renderer == (Object)null || (Object)(object)_mesh == (Object)null) { Destroy(); Create(); } if (_meshCrosses < _centers.Count) { Resize(_centers.Count); } for (int i = 0; i < ((Il2CppArrayBase<Color>)(object)_colors).Length; i++) { ((Il2CppArrayBase<Color>)(object)_colors)[i] = color; } _dirty = true; ((Renderer)_renderer).enabled = true; UpdateView(); _mesh.colors = _colors; } catch (Exception ex) { Fail("Commit", ex); } } internal void Hide() { if ((Object)(object)_renderer != (Object)null) { ((Renderer)_renderer).enabled = false; } } internal void UpdateView() { //IL_0082: 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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: 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_00d4: 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: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)_renderer == (Object)null || !((Renderer)_renderer).enabled) { return; } if ((Object)(object)_camera == (Object)null || (Object)(object)_view == (Object)null) { _camera = Camera.main; _view = (((Object)(object)_camera != (Object)null) ? ((Component)_camera).transform : null); } if ((Object)(object)_view == (Object)null) { return; } Vector3 position = _view.position; Quaternion rotation = _view.rotation; if (!_dirty && position == _cameraPosition && rotation == _cameraRotation) { return; } _cameraPosition = position; _cameraRotation = rotation; _dirty = false; Point3 camera = new Point3(position.x, position.y, position.z); Span<Point3> span = _corners; int i = 0; for (int j = 0; j < _centers.Count; j++) { Vector3 val = _centers[j]; Point3 center = new Point3(val.x, val.y, val.z); CrossQuad.Corners(center, alongX: true, _halfLength, _width, camera, span); for (int k = 0; k < 4; k++) { ((Il2CppArrayBase<Vector3>)(object)_vertices)[i++] = new Vector3((float)span[k].X, (float)span[k].Y, (float)span[k].Z); } CrossQuad.Corners(center, alongX: false, _halfLength, _width, camera, span); for (int l = 0; l < 4; l++) { ((Il2CppArrayBase<Vector3>)(object)_vertices)[i++] = new Vector3((float)span[l].X, (float)span[l].Y, (float)span[l].Z); } } Vector3 val2 = _centers[0]; for (; i < ((Il2CppArrayBase<Vector3>)(object)_vertices).Length; i++) { ((Il2CppArrayBase<Vector3>)(object)_vertices)[i] = val2; } _mesh.vertices = _vertices; _mesh.RecalculateBounds(); } catch (Exception ex) { Fail("UpdateView", ex); } } internal void Destroy() { if ((Object)(object)_holder != (Object)null) { Object.Destroy((Object)(object)_holder); } if ((Object)(object)_mesh != (Object)null) { Object.Destroy((Object)(object)_mesh); } } private void Resize(int crosses) { _mesh.Clear(); _vertices = new Il2CppStructArray<Vector3>((long)(crosses * 8)); _colors = new Il2CppStructArray<Color>((long)(crosses * 8)); Il2CppStructArray<int> val = new Il2CppStructArray<int>((long)(crosses * 12)); int num = 0; for (int i = 0; i < crosses * 2; i++) { int num2 = i * 4; ((Il2CppArrayBase<int>)(object)val)[num++] = num2; ((Il2CppArrayBase<int>)(object)val)[num++] = num2 + 1; ((Il2CppArrayBase<int>)(object)val)[num++] = num2 + 2; ((Il2CppArrayBase<int>)(object)val)[num++] = num2; ((Il2CppArrayBase<int>)(object)val)[num++] = num2 + 2; ((Il2CppArrayBase<int>)(object)val)[num++] = num2 + 3; } _mesh.vertices = _vertices; _mesh.triangles = val; _meshCrosses = crosses; } private void Fail(string where, Exception ex) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown Hide(); if (!_failureLogged) { _failureLogged = true; ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(65, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock][laser] SnapCrossMesh."); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } } internal static class StationaryScan { private sealed class Entry { internal WorldFootprint Footprint; internal List<Vector3>[] Draped; internal bool Valid; internal bool Excluded; internal bool ExtentTested; internal float ReadAt; internal float SeenAt; internal long ScanId; } private const float RetryReadInterval = 2f; private const float EvictInterval = 10f; private const float RedrapeSweepInterval = 2f; private const int RedrapePerFrame = 4; private static Settlement[] _settlements; private static bool _failureLogged; private static long _scanId; private static double _drapeExtension = double.NaN; private static double _drapeHeightLimit = double.NaN; private static double _drapeCell = double.NaN; private static double _minHalfExtent = double.NaN; private static bool _scanned; private static (int X, int Z) _scanCell; private static int _scanVersion; private static float _lastScanAt; private static double _scanRadius = double.NaN; private static IntPtr _scanPreview; private static int _redrapeNext; private static float _redrapeSweepAt = -999f; private static readonly Dictionary<IntPtr, Entry> _cache = new Dictionary<IntPtr, Entry>(); private static readonly List<WorldFootprint> _result = new List<WorldFootprint>(); private static readonly List<List<Vector3>[]> _drapedResult = new List<List<Vector3>[]>(); private static readonly List<Entry> _resultEntries = new List<Entry>(); private static readonly List<Entry> _previousEntries = new List<Entry>(); private static readonly List<IntPtr> _evict = new List<IntPtr>(); private static List<Structure> _found; private static int _structureVersion; internal static IReadOnlyList<List<Vector3>[]> LastDraped => _drapedResult; internal static int ResultVersion { get; private set; } internal static void OnStructureRemoved(IntPtr structure) { _cache.Remove(structure); _structureVersion++; } internal static IReadOnlyList<WorldFootprint> Near(GameObject preview, Vector3 world, double radius, double extensionLength, double heightLimit, double minFootprintHalfExtent, double cell) { //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Expected O, but got Unknown //IL_006b: 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_00f7: Unknown result type (might be due to invalid IL or missing references) try { if (extensionLength != _drapeExtension || heightLimit != _drapeHeightLimit || cell != _drapeCell || minFootprintHalfExtent != _minHalfExtent) { _drapeExtension = extensionLength; _drapeHeightLimit = heightLimit; _drapeCell = cell; _minHalfExtent = minFootprintHalfExtent; _cache.Clear(); _scanned = false; } float unscaledTime = Time.unscaledTime; IntPtr intPtr = (((Object)(object)preview != (Object)null) ? ((Il2CppObjectBase)preview).Pointer : IntPtr.Zero); (int, int) tuple = ((int)Math.Floor((double)world.x / cell), (int)Math.Floor((double)world.z / cell)); if (!_scanned || radius != _scanRadius || intPtr != _scanPreview || StationaryRescan.Due(_scanCell, tuple, _scanVersion, _structureVersion, _lastScanAt, unscaledTime)) { _scanned = true; _scanCell = tuple; _scanVersion = _structureVersion; _lastScanAt = unscaledTime; _scanRadius = radius; _scanPreview = intPtr; Search(world, radius, extensionLength, heightLimit, minFootprintHalfExtent, cell, intPtr, unscaledTime); } else { Redrape(cell, extensionLength, heightLimit, unscaledTime); } } catch (Exception ex) { _result.Clear(); _drapedResult.Clear(); _resultEntries.Clear(); ResultVersion++; if (!_failureLogged) { _failureLogged = true; ManualLogSource log = Plugin.Log; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(70, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[GridLock][laser] StationaryScan.Near threw (logged once, fail-open): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } log.LogError(val); } } return _result; } private static void Search(Vector3 world, double radius, double extensionLength, double heightLimit, double minFootprintHalfExtent, double cell, IntPtr previewPtr, float now) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) _previousEntries.Clear(); _previousEntries.AddRange(_resultEntries); _result.Clear(); _drapedResult.Clear(); _resultEntries.Clear(); long num = ++_scanId; if (radius > 0.0 && AcquireSettlements()) { if (_found == null) { _found = new List<Structure>(); } for (int i = 0; i < _settlements.Length; i++) { Settlement val = _settlements[i]; if ((Object)(object)val == (Object)null) { continue; } _found.Clear(); Vector3 val2 = world; float num2 = (float)radius; val.FindStructuresInRange(ref val2, ref num2, _found, (Predicate<Structure>)null); int count = _found.Count; for (int j = 0; j < count; j++) { Structure val3 = _found[j]; if ((Object)(object)val3 == (Object)null) { continue; } if (previewPtr != IntPtr.Zero) { GameObject gameObject = ((Component)val3).gameObject; if ((Object)(object)gameObject != (Object)null && ((Il2CppObjectBase)gameObject).Pointer == previewPtr) { continue; } } IntPtr pointer = ((Il2CppObjectBase)val3).Pointer; if (!_cache.TryGetValue(pointer, out Entry value)) { value = new Entry { ReadAt = float.MinValue }; _cache[pointer] = value; string text = ExclusionReason(val3); value.Excluded = text != null; } value.SeenAt = now; if (value.Excluded) { continue; } if (!value.Valid && now - value.ReadAt > 2f) { value.Valid = FootprintReader.TryRead(((Component)val3).gameObject, out var result); value.Footprint = result; value.ReadAt = now; value.Draped = (value.Valid ? Drape(result, cell, extensionLength, heightLimit, value.Draped) : null); } if (!value.ExtentTested && value.Valid) { value.ExtentTested = true; if (IsBelowMinExtent(value.Footprint.Footprint, minFootprintHalfExtent)) { value.Excluded = true; value.Draped = null; continue; } } if (value.Valid && value.ScanId != num) { value.ScanId = num; _result.Add(value.Footprint); _drapedResult.Add(value.Draped); _resultEntries.Add(value); } } } } EvictStale(now); if (!SameEntries(_previousEntries, _resultEntries)) { ResultVersion++; _redrapeNext = 0; } _previousEntries.Clear(); } private static bool AcquireSettlements() { bool flag = _settlements == null; int num = 0; while (!flag && num < _settlements.Length) { flag = (Object)(object)_settlements[num] == (Object)null; num++; } if (flag) { _settlements = Il2CppArrayBase<Settlement>.op_Implicit(Object.FindObjectsOfType<Settlement>()); } return _settlements != null; } private static void Redrape(double cell, double extensionLength, double heightLimit, float now) { if (_redrapeNext >= _resultEntries.Count) { if (now - _redrapeSweepAt < 2f) { return; } _redrapeSweepAt = now; _redrapeNext = 0; } int num = Math.Min(_redrapeNext + 4, _resultEntries.Count); while (_redrapeNext < num) { Entry entry = _resultEntries[_redrapeNext]; if (entry.Valid && !entry.Excluded) { entry.Draped = Drape(entry.Footprint, cell, extensionLength, heightLimit, entry.Draped); _drapedResult[_redrapeNext] = entry.Draped; } _redrapeNext++; } } private static bool SameEntries(List<Entry> a, List<Entry> b) { if (a.Count != b.Count) { return false; } for (int i = 0; i < a.Count; i++) { if (a[i] != b[i]) { return false; } } return true; } internal static void Reset() { _settlements = null; _minHalfExtent = double.NaN; _scanned = false; _cache.Clear(); _result.Clear(); _drapedResult.Clear(); _resultEntries.Clear(); _redrapeNext = 0; ResultVersion++; } private static List<Vector3>[] Drape(WorldFootprint footprint, double cell, double extensionLength, double heightLimit, List<Vector3>[] reuse) { LaserLine[] array = GridReference.LinesFor(footprint.Footprint, footprint.PivotX, footprint.PivotZ, cell, extensionLength); if (array.Length == 0) { return null; } List<Vector3>[] array2 = ((reuse != null && reuse.Length == array.Length) ? reuse : new List<Vector3>[array.Length]); for (int i = 0; i < array.Length; i++) { List<Vector3>[] array3 = array2; int num = i; if (array3[num] == null) { array3[num] = new List<Vector3>(32); } LineDraper.Drape(array[i].Laser, footprint.FloorY, footprint.TopY, (float)heightLimit, array2[i]); } return array2; } private static string ExclusionReason(Structure str) { try { if ((Object)(object)str.Parent != (Object)null) { return "built into a parent structure"; } } catch { } try { GameObject gameObject = ((Component)str).gameObject; string text = (((Object)(object)gameObject != (Object)null) ? ((Object)gameObject).name : null); if (!string.IsNullOrEmpty(text) && text.IndexOf("flag", StringComparison.OrdinalIgnoreCase) >= 0) { return "name contains \"flag\""; } } catch { } return null; } private static bool IsBelowMinExtent(Footprint2D footprint, double minHalfExtent) { if (footprint.HalfX < minHalfExtent) { return footprint.HalfZ < minHalfExtent; } return false; } private static void EvictStale(float now) { _evict.Clear(); foreach (KeyValuePair<IntPtr, Entry> item in _cache) { if (now - item.Value.SeenAt > 10f) { _evict.Add(item.Key); } } for (int i = 0; i < _evict.Count; i++) { _cache.Remove(_evict[i]); } _evict.Clear(); } } internal static class TerrainHeight { private struct Tile { internal Terrain Terrain; internal float X; internal float Y; internal float Z; internal float SizeX; internal float SizeZ; } private const float ReacquireInterval = 1f; private const float RaycastStartY = 200f; private const float RaycastMaxDistance = 400f; private static Tile[] _tiles = Array.Empty<Tile>(); private static int _tileCount; private static bool _acquired; private static float _lastAcquire = -999f; private static bool _failureLogged; internal static bool TrySample(float x, float z, out float y) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) y = 0f; try { float unscaledTime = Time.unscaledTime; if (!_acquired || unscaledTime - _lastAcquire > 1f) { Acquire(); _lastAcquire = unscaledTime; } for (int i = 0; i < _tileCount; i++) { ref Tile reference = ref _tiles[i]; if (!(x < reference.X) && !(x > reference.X + reference.SizeX) && !(z < reference.Z) && !(z > reference.Z + reference.SizeZ) && !((Object)(object)reference.Terrain == (Object)null)) { y = reference.Terrain.SampleHeight(new Vector3(x, reference.Y, z)) + reference.Y; return true; } } return TryRaycast(x, z, out y); } catch (Exception ex) { LogOnce("TrySample", ex); return false; } } private static void Acquire() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_009