Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Footpath v1.0.0
Footpath.dll
Decompiled 21 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using Footpath.Core; using Footpath.Game; using Footpath.Integration; using HarmonyLib; using JetBrains.Annotations; using M2Core.Assets; using M2Core.Config; using M2Core.Content; using M2Core.Patching; using Microsoft.CodeAnalysis; using ServerSync; using SoftReferenceableAssets; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.U2D; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: <df624971-15bb-4610-90d8-8156aa9d7db1>IgnoresAccessChecksTo("assembly_utils")] [assembly: <df624971-15bb-4610-90d8-8156aa9d7db1>IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Footpath")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+059c5fc6ba562ec3b765d4bb5641a829e075953d")] [assembly: AssemblyProduct("Footpath")] [assembly: AssemblyTitle("Footpath")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Footpath { [BepInPlugin("M2Valheim.Footpath", "Footpath", "1.0.0")] [BepInIncompatibility("chistix.trails")] [BepInIncompatibility("com.ragemedia.anttrails")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "M2Valheim.Footpath"; public const string PluginName = "Footpath"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private static Harmony _harmony; internal static readonly ConfigSync Sync = new ConfigSync("M2Valheim.Footpath") { DisplayName = "Footpath", CurrentVersion = "1.0.0", MinimumRequiredVersion = ModVersion.SameMinorMinimum("1.0.0"), ModRequired = true, IsLocked = true }; private void Awake() { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Invalid comparison between Unknown and I4 Log = ((BaseUnityPlugin)this).Logger; TrailConfig.Bind(((BaseUnityPlugin)this).Config, new ServerSyncSink(Sync)); _harmony = new Harmony("M2Valheim.Footpath"); _harmony.PatchAll(); GameObject val = new GameObject("Footpath"); Object.DontDestroyOnLoad((Object)(object)val); val.AddComponent<StepCollector>(); if ((int)SystemInfo.graphicsDeviceType != 4) { val.AddComponent<GrassLayer>(); val.AddComponent<TrailMarks>(); } Log.LogInfo((object)"Footpath 1.0.0 loaded."); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace Footpath.Patches { [HarmonyPatch(typeof(FootStep), "RPC_Step")] internal static class FootStepPatch { private static bool Prepare() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 return (int)SystemInfo.graphicsDeviceType != 4; } private static void Postfix(FootStep __instance, int effectIndex, Vector3 point) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) TrailPrints.OnStep(__instance, effectIndex, point); } } [HarmonyPatch(typeof(TerrainComp), "DoOperation")] internal static class OperationPatch { private static void Postfix(TerrainComp __instance, Vector3 pos, Settings modifier) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) if (modifier != null && modifier.m_paintCleared && (int)modifier.m_paintType == 3) { TrailZone.Of(__instance)?.MaintainAround(pos, modifier); } } } [HarmonyPatch(typeof(TerrainComp), "Awake")] internal static class TerrainCompAwakePatch { private static void Postfix(TerrainComp __instance) { if (!((Object)(object)__instance.m_hmap == (Object)null) && !((Object)(object)__instance.m_nview == (Object)null) && __instance.m_nview.IsValid() && (Object)(object)((Component)__instance).GetComponent<TrailZone>() == (Object)null) { ((Component)__instance).gameObject.AddComponent<TrailZone>(); } } } [HarmonyPatch(typeof(TerrainComp), "CheckLoad")] internal static class TerrainCompCheckLoadPatch { private static void Finalizer() { ResetGrassPatch.SkipNext = false; } private static bool Prefix(TerrainComp __instance) { ZNetView nview = __instance.m_nview; ZDO val = (((Object)(object)nview != (Object)null && nview.IsValid()) ? nview.GetZDO() : null); if (val == null || val.DataRevision == __instance.m_lastDataRevision) { return true; } TrailZone trailZone = TrailZone.Of(__instance); if ((Object)(object)trailZone == (Object)null) { return true; } byte[] byteArray = val.GetByteArray(ZDOVars.s_TCData, (byte[])null); if (byteArray != null && SameBytes(byteArray, trailZone.LastTcData)) { __instance.m_lastDataRevision = val.DataRevision; return false; } trailZone.LastTcData = byteArray; return true; } private static bool SameBytes(byte[] a, byte[] b) { if (a == b) { return true; } if (a == null || b == null || a.Length != b.Length) { return false; } for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return false; } } return true; } } [HarmonyPatch(typeof(TerrainComp), "Load")] internal static class TerrainCompLoadPatch { private static bool[] _modified = new bool[0]; private static float[] _level = new float[0]; private static float[] _smooth = new float[0]; private static bool[] _paintModified = new bool[0]; private static Color[] _paint = (Color[])(object)new Color[0]; private static readonly List<int> Changed = new List<int>(); internal static Heightmap PaintOnlyNext; private static void Prefix(TerrainComp __instance) { PaintOnlyNext = null; Copy(__instance.m_modifiedHeight, ref _modified); Copy(__instance.m_levelDelta, ref _level); Copy(__instance.m_smoothDelta, ref _smooth); if (!((Object)(object)TrailZone.Of(__instance) == (Object)null)) { Copy(__instance.m_modifiedPaint, ref _paintModified); Copy(__instance.m_paintMask, ref _paint); } } private static void Postfix(TerrainComp __instance, bool __result) { if (!__result || !Same(__instance.m_modifiedHeight, _modified) || !Same(__instance.m_levelDelta, _level) || !Same(__instance.m_smoothDelta, _smooth)) { return; } PaintOnlyNext = __instance.m_hmap; TrailZone trailZone = TrailZone.Of(__instance); if ((Object)(object)trailZone == (Object)null || _paint.Length != __instance.m_paintMask.Length) { return; } trailZone.ReloadCells(); if (OnlyModPaint(__instance, trailZone)) { ResetGrassPatch.SkipNext = true; if (Changed.Count > 0) { GrassLayer.OnPaintChanged(trailZone, Changed); } } } private static bool OnlyModPaint(TerrainComp tc, TrailZone zone) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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_00c0: 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_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) Changed.Clear(); int num = tc.m_width + 1; Color[] paintMask = tc.m_paintMask; bool[] modifiedPaint = tc.m_modifiedPaint; for (int i = 0; i < paintMask.Length; i++) { bool flag = _paintModified[i]; if (!modifiedPaint[i]) { if (flag) { return false; } continue; } Color val = (flag ? _paint[i] : tc.m_hmap.GetPaintMask(i % num, i / num)); Color val2 = paintMask[i]; if (flag && val2 == val) { continue; } if (Mathf.Abs(val2.g - val.g) > 1f / 170f || Mathf.Abs(val2.b - val.b) > 1f / 170f || Mathf.Abs(val2.a - val.a) > 1f / 170f) { return false; } if (!(Mathf.Abs(val2.r - val.r) <= 0.0019607844f)) { if (Mathf.Abs(val2.r - (float)(int)zone.Grid.Painted[i] / 255f) > 1f / 170f) { return false; } Changed.Add(i); } } return true; } private static void Copy<T>(T[] source, ref T[] target) { if (source == null) { target = new T[0]; return; } if (target.Length != source.Length) { target = new T[source.Length]; } Array.Copy(source, target, source.Length); } private static bool Same(bool[] a, bool[] b) { if (a == null || a.Length != b.Length) { return false; } for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return false; } } return true; } private static bool Same(float[] a, float[] b) { if (a == null || a.Length != b.Length) { return false; } for (int i = 0; i < a.Length; i++) { if (a[i] != b[i]) { return false; } } return true; } } [HarmonyPatch(typeof(Heightmap), "Poke")] internal static class HeightmapPokePatch { private static void Prefix(Heightmap __instance, ref bool paintOnly) { if (!((Object)(object)TerrainCompLoadPatch.PaintOnlyNext == (Object)null) && !((Object)(object)TerrainCompLoadPatch.PaintOnlyNext != (Object)(object)__instance)) { paintOnly = true; TerrainCompLoadPatch.PaintOnlyNext = null; } } } [HarmonyPatch(typeof(ClutterSystem), "ResetGrass")] internal static class ResetGrassPatch { internal static bool SkipNext; private static bool Prefix() { if (!SkipNext) { return true; } SkipNext = false; return false; } } [HarmonyPatch(typeof(ClutterSystem), "GenerateVegPatch")] internal static class VegPatchPatch { private static bool Prepare() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 return (int)SystemInfo.graphicsDeviceType != 4; } private static void Postfix(Vector2Int patchID, PatchData __result) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) GrassLayer.OnPatchBuilt(patchID, __result); } } } namespace Footpath.Integration { internal sealed class ServerSyncSink : IConfigSyncSink { private readonly ConfigSync _sync; public ServerSyncSink(ConfigSync sync) { _sync = sync; } public void Add<T>(ConfigEntry<T> entry) { _sync.AddConfigEntry<T>(entry); } } internal static class TrailConfig { public static ConfigEntry<bool> Active { get; private set; } public static void Bind(ConfigFile config, IConfigSyncSink sync) { OrderedConfig orderedConfig = new OrderedConfig(config, sync); Active = orderedConfig.Bind("General", "Enabled", defaultValue: true, "Trails form, fade and are painted. Off: everything pauses, existing trails stay as they are."); } } } namespace Footpath.Game { internal sealed class BladeSet { public readonly InstanceRenderer Renderer; public readonly int Count; public readonly Matrix4x4[] Original; public readonly bool Flat; public readonly float[] Angle; public readonly float[] Heading; public readonly float[] Scale; public readonly float[] PressedAt; public readonly float[] WalkHeading; public readonly bool[] Cleared; public readonly float[] Due; public readonly float[] HashHeading; public readonly float[] AngleJitter; public readonly int[] FallSlot; public bool Retired; private readonly bool[] _active; public readonly List<int> Active = new List<int>(); private readonly int _minX; private readonly int _minZ; private readonly int _sizeX; private readonly int _sizeZ; private readonly int[] _cellStart; private readonly int[] _cellBlades; public bool Alive => !Retired && (Object)(object)Renderer != (Object)null && Renderer.m_instanceCount == Count; public BladeSet(InstanceRenderer ir) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) Renderer = ir; Count = ir.m_instanceCount; Original = (Matrix4x4[])(object)new Matrix4x4[Count]; Array.Copy(ir.m_instances, Original, Count); Vector3 val; if (!((Object)(object)ir.m_mesh != (Object)null)) { val = Vector3.one; } else { Bounds bounds = ir.m_mesh.bounds; val = Vector3.Scale(((Bounds)(ref bounds)).size, ir.m_scale); } Vector3 val2 = val; Flat = val2.y < Mathf.Max(val2.x, val2.z); Angle = new float[Count]; Heading = new float[Count]; Scale = new float[Count]; PressedAt = new float[Count]; WalkHeading = new float[Count]; Cleared = new bool[Count]; Due = new float[Count]; HashHeading = new float[Count]; AngleJitter = new float[Count]; _active = new bool[Count]; FallSlot = new int[Count]; Cell[] array = new Cell[Count]; int num = int.MaxValue; int num2 = int.MaxValue; int num3 = int.MinValue; int num4 = int.MinValue; for (int i = 0; i < Count; i++) { Scale[i] = 1f; PressedAt[i] = float.NegativeInfinity; HashHeading[i] = GrassMath.HashHeading(Original[i].m03, Original[i].m23); AngleJitter[i] = GrassMath.AngleJitter(Original[i].m03, Original[i].m23); array[i] = Cell.FromWorld(Original[i].m03, Original[i].m23); num = Math.Min(num, array[i].X); num2 = Math.Min(num2, array[i].Z); num3 = Math.Max(num3, array[i].X); num4 = Math.Max(num4, array[i].Z); } if (Count == 0) { num = (num2 = (num3 = (num4 = 0))); } _minX = num; _minZ = num2; _sizeX = num3 - num + 1; _sizeZ = num4 - num2 + 1; _cellStart = new int[_sizeX * _sizeZ + 1]; _cellBlades = new int[Count]; for (int j = 0; j < Count; j++) { _cellStart[LocalCell(array[j]) + 1]++; } for (int k = 0; k < _sizeX * _sizeZ; k++) { _cellStart[k + 1] += _cellStart[k]; } int[] array2 = new int[_sizeX * _sizeZ]; for (int l = 0; l < Count; l++) { int num5 = LocalCell(array[l]); _cellBlades[_cellStart[num5] + array2[num5]++] = l; } } private int LocalCell(Cell c) { return (c.Z - _minZ) * _sizeX + (c.X - _minX); } public bool BladesAt(Cell c, out int start, out int end, out int[] blades) { blades = _cellBlades; start = (end = 0); int num = c.X - _minX; int num2 = c.Z - _minZ; if (num < 0 || num2 < 0 || num >= _sizeX || num2 >= _sizeZ) { return false; } int num3 = num2 * _sizeX + num; start = _cellStart[num3]; end = _cellStart[num3 + 1]; return end > start; } public float HeadingOf(int i) { return float.IsNegativeInfinity(PressedAt[i]) ? PersistentHeading(i) : WalkHeading[i]; } public Cell ClearCell(int i) { return new Cell((int)Math.Floor(Original[i].m03), (int)Math.Floor(Original[i].m23)); } public float WearOf(int i) { float m = Original[i].m03; float m2 = Original[i].m23; int num = (int)Math.Floor(m); int num2 = (int)Math.Floor(m2); return GrassMath.Bilinear(TrailZone.WearAt(new Cell(num, num2)), TrailZone.WearAt(new Cell(num + 1, num2)), TrailZone.WearAt(new Cell(num, num2 + 1)), TrailZone.WearAt(new Cell(num + 1, num2 + 1)), m - (float)num, m2 - (float)num2); } public void Activate(int i) { Due[i] = 0f; if (!_active[i]) { _active[i] = true; Active.Add(i); } } public void DeactivateAt(int k) { int num = Active[k]; _active[num] = false; Active[k] = Active[Active.Count - 1]; Active.RemoveAt(Active.Count - 1); } public void Write(int i, float angle, float heading, float scale) { //IL_0024: 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_008e: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: 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_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_008f: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) Angle[i] = angle; Heading[i] = heading; Scale[i] = scale; Matrix4x4 val = Original[i]; Matrix4x4 val2; if (Flat) { val2 = ((angle < 0.01f && scale >= 0.999f) ? val : (val * Matrix4x4.Scale(new Vector3(scale, scale * GrassMath.SquashScale(angle), scale)))); } else { val2 = ((scale >= 0.999f) ? val : (val * Matrix4x4.Scale(new Vector3(scale, scale, scale)))); if (angle >= 0.01f) { float num = heading * ((float)Math.PI / 180f); float num2 = angle * AngleJitter[i] * ((float)Math.PI / 180f); float num3 = Mathf.Sin(num2); float m = Mathf.Cos(num2); Matrix4x4 identity = Matrix4x4.identity; identity.m01 = num3 * Mathf.Sin(num); identity.m11 = m; identity.m21 = num3 * Mathf.Cos(num); val2 = identity * val2; ((Matrix4x4)(ref val2)).SetColumn(3, ((Matrix4x4)(ref val)).GetColumn(3)); } } Renderer.m_instances[i] = val2; } public void ApplyPersistent(int i) { float num = WearModel.TiltDeg(WearOf(i)); if (!(num < 1f)) { Write(i, num, PersistentHeading(i), 1f); } } public float PersistentHeading(int i) { float m = Original[i].m03; float m2 = Original[i].m23; Cell cell = Cell.FromWorld(m, m2); float gx = TrailZone.WearAt(new Cell(cell.X + 1, cell.Z)) - TrailZone.WearAt(new Cell(cell.X - 1, cell.Z)); float gz = TrailZone.WearAt(new Cell(cell.X, cell.Z + 1)) - TrailZone.WearAt(new Cell(cell.X, cell.Z - 1)); float num = GrassMath.PersistentHeading(HashHeading[i], gx, gz) + GrassMath.HeadingJitter(m, m2); return (num % 360f + 360f) % 360f; } } internal readonly struct Emitter { public readonly int Id; public readonly Vector3 Pos; public readonly Vector3 Dir; public readonly int HalfWidth; public readonly bool Valid; public readonly bool Wheel; public Emitter(int id, Vector3 pos, Vector3 dir, int halfWidth, bool valid, bool wheel = false) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0011: Unknown result type (might be due to invalid IL or missing references) Id = id; Pos = pos; Dir = dir; HalfWidth = halfWidth; Valid = valid; Wheel = wheel; } } internal static class Emitters { private const float WheelRayUp = 0.3f; private const float WheelRayLength = 1.8f; public static void Collect(Player local, List<Emitter> output) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: 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_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Unknown result type (might be due to invalid IL or missing references) output.Clear(); bool valid = !((Character)local).IsDead() && !((Character)local).IsAttached() && !((Character)local).IsDebugFlying() && !((Character)local).IsTeleporting() && !((Character)local).IsSwimming() && ((Character)local).IsOnHeightmap(); output.Add(new Emitter(((Object)local).GetInstanceID(), ((Component)local).transform.position, Direction((Character)(object)local), 1, valid)); IDoodadController doodadController = local.GetDoodadController(); Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); Character val2 = ((val != null) ? val.GetCharacter() : null); if ((Object)(object)val2 != (Object)null) { bool valid2 = !val2.IsDead() && !val2.IsSwimming() && val2.IsOnHeightmap() && !((Character)local).IsTeleporting(); output.Add(new Emitter(((Object)val2).GetInstanceID(), ((Component)val2).transform.position, Direction(val2), Bundling.MountHalfWidth(val2.GetRadius()), valid2)); } foreach (Vagon instance in Vagon.m_instances) { if ((Object)(object)instance == (Object)null || (!instance.IsAttached((Character)(object)local) && (!((Object)(object)val2 != (Object)null) || !instance.IsAttached(val2)))) { continue; } bool flag = (Object)(object)instance.m_nview != (Object)null && instance.m_nview.IsValid() && instance.m_nview.IsOwner() && !((Character)local).IsTeleporting(); Vector3 forward = ((Component)instance).transform.forward; if (instance.m_wheels == null || instance.m_wheels.Length == 0) { output.Add(new Emitter(((Object)instance).GetInstanceID(), ((Component)instance).transform.position, forward, 0, flag && OnTerrain(((Component)instance).transform.position), wheel: true)); continue; } Rigidbody[] wheels = instance.m_wheels; foreach (Rigidbody val3 in wheels) { if ((Object)(object)val3 != (Object)null) { output.Add(new Emitter(((Object)val3).GetInstanceID(), val3.position, forward, 0, flag && OnTerrain(val3.position), wheel: true)); } } } } internal static bool OnTerrain(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) RaycastHit hit; return TerrainHit(pos, out hit); } internal static bool TerrainHit(Vector3 pos, out RaycastHit hit) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_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) hit = default(RaycastHit); if ((Object)(object)ZoneSystem.instance == (Object)null) { return false; } return Physics.Raycast(pos + Vector3.up * 0.3f, Vector3.down, ref hit, 1.8f, ZoneSystem.instance.m_solidRayMask) && (Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent<Heightmap>() != (Object)null; } private static Vector3 Direction(Character c) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_005f: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) Vector3 velocity = c.GetVelocity(); velocity.y = 0f; if (((Vector3)(ref velocity)).sqrMagnitude > 0.01f) { return ((Vector3)(ref velocity)).normalized; } Vector3 forward = ((Component)c).transform.forward; forward.y = 0f; return (((Vector3)(ref forward)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref forward)).normalized : Vector3.forward; } } internal sealed class GrassLayer : MonoBehaviour { private sealed class PatchEntry { public PatchData Data; public readonly List<BladeSet> Sets = new List<BladeSet>(); public int LookupVersion; } private struct Fall { public BladeSet Set; public int Blade; public float X; public float Z; public float Vx; public float Vz; public float Tx; public float Tz; public float Omega; } private const float LiveInterval = 0.1f; private const float RelaxInterval = 0.25f; private const float RewriteHeadingDeg = 30f; private const int MaxFalling = 6000; private static GrassLayer _instance; private static readonly Dictionary<Vector2Int, PatchEntry> Patches = new Dictionary<Vector2Int, PatchEntry>(); private static readonly HashSet<long> PendingWear = new HashSet<long>(); private static readonly HashSet<long> PendingPaint = new HashSet<long>(); private static readonly List<long> Drain = new List<long>(); private static Dictionary<string, Clutter> _clutterByPrefab; private static int _clutterCount = -1; private static int _lookupVersion; private static readonly List<Fall> Falls = new List<Fall>(); private readonly List<LivePress> _presses = new List<LivePress>(); private readonly List<Vector2Int> _dead = new List<Vector2Int>(); private float _nextLive; private float _nextRelax; private const int MaxPendingPerPass = 400; private void Awake() { _instance = this; } private void OnDestroy() { if ((Object)(object)_instance == (Object)(object)this) { _instance = null; } } public static void OnWearChanged(TrailZone zone, int index) { if ((Object)(object)_instance != (Object)null) { PendingWear.Add(Key(zone, index)); } } public static void OnPaintChanged(TrailZone zone, IEnumerable<int> indices) { if ((Object)(object)_instance == (Object)null) { return; } foreach (int index in indices) { PendingPaint.Add(Key(zone, index)); } } private static long Key(TrailZone zone, int index) { //IL_0001: 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) return ((long)(zone.Zone.x & 0xFFFF) << 32) | ((long)(zone.Zone.y & 0xFFFF) << 16) | (uint)index; } public static void OnPatchBuilt(Vector2Int id, PatchData data) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_instance == (Object)null || data == null) { return; } if (!WearUnder(data.center)) { Retire(id); return; } PatchEntry patchEntry = Build(id, data); foreach (BladeSet set in patchEntry.Sets) { for (int i = 0; i < set.Count; i++) { set.ApplyPersistent(i); } } } private static bool WearUnder(Vector3 center) { //IL_001a: 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_0030: 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) ClutterSystem instance = ClutterSystem.instance; float num = instance.m_grassPatchSize / 2f + 1f; Cell cell = Cell.FromWorld(center.x - num, center.z - num); Cell cell2 = Cell.FromWorld(center.x + num, center.z + num); TrailZone trailZone = null; int num2 = int.MinValue; int num3 = int.MinValue; for (int i = cell.Z; i <= cell2.Z; i++) { for (int j = cell.X; j <= cell2.X; j++) { ZoneCells.Primary(new Cell(j, i), out var zoneX, out var zoneZ, out var index); if (zoneX != num2 || zoneZ != num3) { num2 = zoneX; num3 = zoneZ; trailZone = TrailZone.Find(zoneX, zoneZ); } if ((Object)(object)trailZone != (Object)null && trailZone.Grid.Wear[index] > 0f) { return true; } } } return false; } private static PatchEntry Get(Vector2Int id) { //IL_0016: 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_007e: Unknown result type (might be due to invalid IL or missing references) ClutterSystem instance = ClutterSystem.instance; if ((Object)(object)instance == (Object)null || !instance.m_patches.TryGetValue(id, out var value)) { return null; } EnsureLookup(instance); if (Patches.TryGetValue(id, out var value2) && value2.Data == value && AllAlive(value2)) { if (value2.LookupVersion != _lookupVersion) { AddMissingSets(value2); } return value2; } return Build(id, value); } private static void AddMissingSets(PatchEntry entry) { entry.LookupVersion = _lookupVersion; foreach (GameObject @object in entry.Data.m_objects) { if ((Object)(object)@object == (Object)null) { continue; } InstanceRenderer component = @object.GetComponent<InstanceRenderer>(); if ((Object)(object)component == (Object)null || component.m_instanceCount == 0 || !Eligible(((Object)@object).name)) { continue; } bool flag = false; foreach (BladeSet set in entry.Sets) { if ((Object)(object)set.Renderer == (Object)(object)component) { flag = true; } } if (!flag) { BladeSet bladeSet = new BladeSet(component); entry.Sets.Add(bladeSet); for (int i = 0; i < bladeSet.Count; i++) { bladeSet.ApplyPersistent(i); } } } } private static bool AllAlive(PatchEntry entry) { foreach (BladeSet set in entry.Sets) { if (!set.Alive) { return false; } } return true; } private static PatchEntry Build(Vector2Int id, PatchData data) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) Retire(id); EnsureLookup(ClutterSystem.instance); PatchEntry patchEntry = new PatchEntry { Data = data, LookupVersion = _lookupVersion }; foreach (GameObject @object in data.m_objects) { if (!((Object)(object)@object == (Object)null)) { InstanceRenderer component = @object.GetComponent<InstanceRenderer>(); if (!((Object)(object)component == (Object)null) && component.m_instanceCount != 0 && Eligible(((Object)@object).name)) { patchEntry.Sets.Add(new BladeSet(component)); } } } Patches[id] = patchEntry; return patchEntry; } internal static string DebugBlades(Vector3 pos, float radius) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: 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) StringBuilder stringBuilder = new StringBuilder(); float num = radius * radius; foreach (KeyValuePair<Vector2Int, PatchEntry> patch in Patches) { foreach (BladeSet set in patch.Value.Sets) { if (!set.Alive) { continue; } int num2 = 0; int num3 = 0; float num4 = 0f; float num5 = 0f; for (int i = 0; i < set.Count; i++) { float num6 = set.Original[i].m03 - pos.x; float num7 = set.Original[i].m23 - pos.z; if (!(num6 * num6 + num7 * num7 > num)) { num2++; num4 += set.Angle[i]; Vector3 val = Vector4.op_Implicit(((Matrix4x4)(ref set.Original[i])).GetColumn(1)); float magnitude = ((Vector3)(ref val)).magnitude; Vector4 column = ((Matrix4x4)(ref set.Renderer.m_instances[i])).GetColumn(1); num5 += ((magnitude > 0.0001f) ? (column.y / magnitude) : 1f); if (set.Angle[i] > 0.5f || set.Scale[i] < 0.999f) { num3++; } } } if (num2 != 0) { stringBuilder.Append(string.Format("{0} {1}: {2} Halme, angefasst {3}, ", ((Object)set.Renderer).name, set.Flat ? "flach" : "hoch", num2, num3) + $"Neigung {num4 / (float)num2:0}°, Höhe {num5 / (float)num2:0.00}; "); } } } return (stringBuilder.Length > 0) ? stringBuilder.ToString() : "Keine erfassten Halme im Umkreis (Feld ohne Abnutzung und ohne Tritt)."; } private static void Retire(Vector2Int id) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) if (!Patches.TryGetValue(id, out var value)) { return; } foreach (BladeSet set in value.Sets) { set.Retired = true; } Patches.Remove(id); } private static void EnsureLookup(ClutterSystem cs) { if ((Object)(object)cs == (Object)null || (_clutterByPrefab != null && _clutterCount == cs.m_clutter.Count)) { return; } _clutterByPrefab = new Dictionary<string, Clutter>(); foreach (Clutter item in cs.m_clutter) { if ((Object)(object)item.m_prefab != (Object)null) { _clutterByPrefab[((Object)item.m_prefab).name + "(Clone)"] = item; } } _clutterCount = cs.m_clutter.Count; _lookupVersion++; } private static bool Eligible(string objectName) { Clutter value; return _clutterByPrefab != null && _clutterByPrefab.TryGetValue(objectName, out value) && value.m_instanced && value.m_onUncleared && !value.m_onCleared; } private void Update() { ClutterSystem instance = ClutterSystem.instance; if ((Object)(object)instance == (Object)null) { return; } float time = Time.time; if (Falls.Count > 0) { StepFalls(Time.deltaTime); } if (time >= _nextLive) { _nextLive = time + 0.1f; if (TrailConfig.Active != null && TrailConfig.Active.Value) { Live(instance, time); } } if (time >= _nextRelax) { _nextRelax = time + 0.25f; ApplyPending(instance); Relax(time, 0.25f); } } private void Live(ClutterSystem cs, float now) { LiveEmitters.Collect(Player.m_localPlayer, cs.m_distance, _presses); foreach (LivePress press in _presses) { Press(cs, press, now); } } private static void Press(ClutterSystem cs, LivePress press, float now) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_01ab: Unknown result type (might be due to invalid IL or missing references) float radius = press.Radius; Vector2Int vegPatch = cs.GetVegPatch(press.Pos - new Vector3(radius, 0f, radius)); Vector2Int vegPatch2 = cs.GetVegPatch(press.Pos + new Vector3(radius, 0f, radius)); Cell cell = Cell.FromWorld(press.Pos.x - radius, press.Pos.z - radius); Cell cell2 = Cell.FromWorld(press.Pos.x + radius, press.Pos.z + radius); float num = radius * radius; float num2 = (press.Heading % 360f + 360f) % 360f; float num3 = Mathf.Cos(num2 * ((float)Math.PI / 180f)); float num4 = 0f - Mathf.Sin(num2 * ((float)Math.PI / 180f)); float num5 = 0f - num4; float num6 = num3; for (int i = ((Vector2Int)(ref vegPatch)).y; i <= ((Vector2Int)(ref vegPatch2)).y; i++) { for (int j = ((Vector2Int)(ref vegPatch)).x; j <= ((Vector2Int)(ref vegPatch2)).x; j++) { PatchEntry patchEntry = Get(new Vector2Int(j, i)); if (patchEntry == null) { continue; } foreach (BladeSet set in patchEntry.Sets) { for (int k = cell.Z; k <= cell2.Z; k++) { for (int l = cell.X; l <= cell2.X; l++) { if (!set.BladesAt(new Cell(l, k), out var start, out var end, out var blades)) { continue; } for (int m = start; m < end; m++) { int num7 = blades[m]; float num8 = set.Original[num7].m03 - press.Pos.x; float num9 = set.Original[num7].m23 - press.Pos.z; if (num8 * num8 + num9 * num9 > num || set.Cleared[num7]) { continue; } float num10 = GrassMath.OutwardHeading(num2, num8 * num3 + num9 * num4, radius) + GrassMath.HeadingJitter(set.Original[num7].m03, set.Original[num7].m23); num10 = (num10 % 360f + 360f) % 360f; float num11 = GrassMath.FallShare(num8 * num5 + num9 * num6, radius) * GrassMath.LateralShare(num8 * num3 + num9 * num4, radius); float num12 = 70f * num11; bool flag = Mathf.Abs(Mathf.DeltaAngle(set.Heading[num7], num10)) > 30f; if (!flag && set.Angle[num7] >= num12 - 1f && set.FallSlot[num7] == 0) { if (num11 >= 1f) { set.PressedAt[num7] = now; set.Activate(num7); } continue; } float num13 = now - GrassMath.AgeForShare(num11); if (float.IsNegativeInfinity(set.PressedAt[num7]) || num13 > set.PressedAt[num7]) { set.PressedAt[num7] = num13; } set.WalkHeading[num7] = num10; set.Activate(num7); StartFall(set, num7, num12, num10, flag); } } } } } } } private static void ApplyPending(ClutterSystem cs) { if (PendingWear.Count == 0 && PendingPaint.Count == 0) { return; } int num = 400; num -= Take(PendingPaint, num); foreach (long item in Drain) { TouchPaint(cs, item); } Take(PendingWear, num); foreach (long item2 in Drain) { TouchWear(cs, item2); } } private static int Take(HashSet<long> pending, int max) { Drain.Clear(); if (max <= 0) { return 0; } foreach (long item in pending) { if (Drain.Count >= max) { break; } Drain.Add(item); } if (Drain.Count == pending.Count) { pending.Clear(); } else { foreach (long item2 in Drain) { pending.Remove(item2); } } return Drain.Count; } private static TrailZone Unpack(long key, out int index) { int zoneX = (short)((key >> 32) & 0xFFFF); int zoneZ = (short)((key >> 16) & 0xFFFF); index = (int)(key & 0xFFFF); return TrailZone.Find(zoneX, zoneZ); } private static void TouchWear(ClutterSystem cs, long key) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_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_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) int index; TrailZone trailZone = Unpack(key, out index); if ((Object)(object)trailZone == (Object)null) { return; } Vector3 val = trailZone.CellWorld(index); int num = (int)val.x; int num2 = (int)val.z; Vector2Int vegPatch = cs.GetVegPatch(val - new Vector3(1f, 0f, 1f)); Vector2Int vegPatch2 = cs.GetVegPatch(val + new Vector3(0.99f, 0f, 0.99f)); for (int i = ((Vector2Int)(ref vegPatch)).y; i <= ((Vector2Int)(ref vegPatch2)).y; i++) { for (int j = ((Vector2Int)(ref vegPatch)).x; j <= ((Vector2Int)(ref vegPatch2)).x; j++) { PatchEntry patchEntry = Get(new Vector2Int(j, i)); if (patchEntry == null) { continue; } foreach (BladeSet set in patchEntry.Sets) { for (int k = num2 - 1; k <= num2 + 1; k++) { for (int l = num - 1; l <= num + 1; l++) { if (!set.BladesAt(new Cell(l, k), out var start, out var end, out var blades)) { continue; } for (int m = start; m < end; m++) { int num3 = blades[m]; if (Mathf.Abs(set.Original[num3].m03 - val.x) < 1f && Mathf.Abs(set.Original[num3].m23 - val.z) < 1f) { set.Activate(num3); } } } } } } } } private static void TouchPaint(ClutterSystem cs, long key) { //IL_0026: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_008d: Unknown result type (might be due to invalid IL or missing references) int index; TrailZone trailZone = Unpack(key, out index); if ((Object)(object)trailZone == (Object)null) { return; } bool flag = trailZone.IsClearedAt(index); Vector3 val = trailZone.CellWorld(index); Cell other = new Cell((int)val.x, (int)val.z); Vector2Int vegPatch = cs.GetVegPatch(val); Vector2Int vegPatch2 = cs.GetVegPatch(val + new Vector3(0.99f, 0f, 0.99f)); for (int i = ((Vector2Int)(ref vegPatch)).y; i <= ((Vector2Int)(ref vegPatch2)).y; i++) { for (int j = ((Vector2Int)(ref vegPatch)).x; j <= ((Vector2Int)(ref vegPatch2)).x; j++) { PatchEntry patchEntry = Get(new Vector2Int(j, i)); if (patchEntry == null) { continue; } foreach (BladeSet set in patchEntry.Sets) { for (int k = other.Z; k <= other.Z + 1; k++) { for (int l = other.X; l <= other.X + 1; l++) { if (!set.BladesAt(new Cell(l, k), out var start, out var end, out var blades)) { continue; } for (int m = start; m < end; m++) { int num = blades[m]; if (set.ClearCell(num).Equals(other)) { set.Cleared[num] = flag; set.Activate(num); } } } } } } } } private static void StartFall(BladeSet set, int i, float angle, float heading, bool turned) { float num = heading * ((float)Math.PI / 180f); float tx = angle * Mathf.Sin(num); float tz = angle * Mathf.Cos(num); int num2 = set.FallSlot[i] - 1; if (num2 >= 0) { Fall value = Falls[num2]; if (turned || angle * angle > value.Tx * value.Tx + value.Tz * value.Tz) { value.Tx = tx; value.Tz = tz; Falls[num2] = value; } return; } if (Falls.Count >= 6000) { set.Write(i, angle, heading, set.Scale[i]); return; } float num3 = set.Angle[i]; float num4 = set.Heading[i] * ((float)Math.PI / 180f); float m = set.Original[i].m03; float m2 = set.Original[i].m23; Falls.Add(new Fall { Set = set, Blade = i, X = num3 * Mathf.Sin(num4), Z = num3 * Mathf.Cos(num4), Tx = tx, Tz = tz, Omega = GrassMath.FallOmegaAt(m, m2) }); set.FallSlot[i] = Falls.Count; } private static void StepFalls(float dt) { if (dt <= 0f) { return; } int num = Mathf.Min(8, Mathf.CeilToInt(dt / (1f / 60f))); float dt2 = dt / (float)num; float num2 = 0.25f; float num3 = 9f; for (int num4 = Falls.Count - 1; num4 >= 0; num4--) { Fall value = Falls[num4]; BladeSet set = value.Set; if (!set.Alive) { RemoveFall(num4); } else { for (int i = 0; i < num; i++) { GrassMath.SpringStep(ref value.X, ref value.Vx, value.Tx, value.Omega, dt2); GrassMath.SpringStep(ref value.Z, ref value.Vz, value.Tz, value.Omega, dt2); } float num5 = value.X - value.Tx; float num6 = value.Z - value.Tz; bool flag = num5 * num5 + num6 * num6 < num2 && value.Vx * value.Vx + value.Vz * value.Vz < num3; float num7 = (flag ? value.Tx : value.X); float num8 = (flag ? value.Tz : value.Z); float num9 = Mathf.Min(80f, Mathf.Sqrt(num7 * num7 + num8 * num8)); float num10 = ((num9 > 0.01f) ? (Mathf.Atan2(num7, num8) * 57.29578f) : set.WalkHeading[value.Blade]); if (num10 < 0f) { num10 += 360f; } set.Write(value.Blade, num9, num10, set.Scale[value.Blade]); if (flag) { RemoveFall(num4); set.Activate(value.Blade); } else { Falls[num4] = value; } } } } private static void RemoveFall(int k) { Fall fall = Falls[k]; fall.Set.FallSlot[fall.Blade] = 0; int num = Falls.Count - 1; if (k != num) { Fall value = Falls[num]; Falls[k] = value; value.Set.FallSlot[value.Blade] = k + 1; } Falls.RemoveAt(num); } private void Relax(float now, float dt) { //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02b6: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_0276: Unknown result type (might be due to invalid IL or missing references) _dead.Clear(); float maxStep = 14f * dt; float maxStep2 = dt / 1.5f; foreach (KeyValuePair<Vector2Int, PatchEntry> patch in Patches) { PatchEntry value = patch.Value; bool flag = true; foreach (BladeSet set in value.Sets) { if (!set.Alive) { flag = false; break; } if (set.Active.Count == 0) { continue; } for (int num = set.Active.Count - 1; num >= 0; num--) { int num2 = set.Active[num]; if (!(now < set.Due[num2]) && set.FallSlot[num2] == 0) { float num3 = WearModel.TiltDeg(set.WearOf(num2)); float ageSec = now - set.PressedAt[num2]; float fresh = GrassMath.FreshShare(ageSec); float num4 = GrassMath.DisplayAngle(num3, fresh); float num5 = (set.Cleared[num2] ? 0f : 1f); float num6 = GrassMath.Approach(set.Angle[num2], num4, maxStep); float num7 = GrassMath.Approach(set.Scale[num2], num5, maxStep2); bool flag2 = num6 != num4 || num7 != num5; float num8 = (flag2 ? 0f : GrassMath.NextWriteAge(num3, fresh)); bool flag3 = !flag2 && float.IsPositiveInfinity(num8); if (flag3) { num6 = num3; } if (Mathf.Abs(num6 - set.Angle[num2]) >= 1f || num7 != set.Scale[num2] || (flag3 && num6 != set.Angle[num2])) { set.Write(num2, num6, set.HeadingOf(num2), num7); } if (flag3) { set.DeactivateAt(num); } else { set.Due[num2] = (flag2 ? now : (set.PressedAt[num2] + num8)); } } } } if (!flag) { _dead.Add(patch.Key); } } foreach (Vector2Int item in _dead) { Retire(item); } } } internal readonly struct LivePress { public readonly Vector3 Pos; public readonly float Heading; public readonly float Radius; public LivePress(Vector3 pos, float heading, float radius) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) Pos = pos; Heading = heading; Radius = radius; } } internal static class LiveEmitters { private const float PlayerRadius = 1.5f; private const float MountExtra = 0.5f; private const float WheelRadius = 0.4f; private const float MaxAboveGround = 0.3f; private const float MinWheelSpin = 1f; private static readonly List<Emitter> Own = new List<Emitter>(); private static readonly Dictionary<int, Vector3> LastPos = new Dictionary<int, Vector3>(); private static readonly Dictionary<Character, Sadle> Saddles = new Dictionary<Character, Sadle>(); public static void Collect(Player local, float maxDistance, List<LivePress> output) { //IL_0026: 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_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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0183: 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: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: 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_0234: 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_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_035e: Unknown result type (might be due to invalid IL or missing references) //IL_0363: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_039f: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03d9: Unknown result type (might be due to invalid IL or missing references) //IL_03e5: Unknown result type (might be due to invalid IL or missing references) output.Clear(); Camera mainCamera = Utils.GetMainCamera(); if ((Object)(object)mainCamera == (Object)null) { return; } Vector3 position = ((Component)mainCamera).transform.position; float num = maxDistance * maxDistance; Character val = null; if ((Object)(object)local != (Object)null) { Emitters.Collect(local, Own); int instanceID = ((Object)local).GetInstanceID(); foreach (Emitter item in Own) { if (item.Valid && !(Flat2(item.Pos - position) > num)) { float radius = (item.Wheel ? 0.4f : ((item.Id == instanceID) ? 1.5f : ((float)item.HalfWidth + 0.5f))); output.Add(new LivePress(item.Pos, HeadingOf(item.Dir), radius)); } } IDoodadController doodadController = local.GetDoodadController(); Sadle val2 = (Sadle)(object)((doodadController is Sadle) ? doodadController : null); val = ((val2 != null) ? val2.GetCharacter() : null); } foreach (Player allPlayer in Player.GetAllPlayers()) { if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)allPlayer == (Object)(object)local)) { Vector3 position2 = ((Component)allPlayer).transform.position; if (!(Flat2(position2 - position) > num) && OnGround((Character)(object)allPlayer, position2)) { output.Add(new LivePress(position2, Moved(((Object)allPlayer).GetInstanceID(), position2, ((Component)allPlayer).transform.forward), 1.5f)); } } } foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)null || allCharacter is Player || (Object)(object)allCharacter == (Object)(object)val) { continue; } Vector3 position3 = ((Component)allCharacter).transform.position; if (!(Flat2(position3 - position) > num)) { Sadle val3 = SaddleOf(allCharacter); if (!((Object)(object)val3 == (Object)null) && ((Behaviour)val3).isActiveAndEnabled && val3.HaveValidUser() && OnGround(allCharacter, position3)) { float radius2 = (float)Bundling.MountHalfWidth(allCharacter.GetRadius()) + 0.5f; output.Add(new LivePress(position3, Moved(((Object)allCharacter).GetInstanceID(), position3, ((Component)allCharacter).transform.forward), radius2)); } } } foreach (Vagon instance in Vagon.m_instances) { if ((Object)(object)instance == (Object)null || instance.m_wheels == null || ((Object)(object)local != (Object)null && instance.IsAttached((Character)(object)local)) || ((Object)(object)val != (Object)null && instance.IsAttached(val)) || Flat2(((Component)instance).transform.position - position) > num) { continue; } Rigidbody[] wheels = instance.m_wheels; foreach (Rigidbody val4 in wheels) { if (!((Object)(object)val4 == (Object)null)) { Vector3 angularVelocity = val4.angularVelocity; if (!(((Vector3)(ref angularVelocity)).sqrMagnitude < 1f) && Emitters.OnTerrain(val4.position)) { output.Add(new LivePress(val4.position, HeadingOf(((Component)instance).transform.forward), 0.4f)); } } } } } private static bool OnGround(Character c, Vector3 pos) { //IL_0008: 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) float num = default(float); return !c.IsSwimming() && Heightmap.GetHeight(pos, ref num) && pos.y - num <= 0.3f; } private static Sadle SaddleOf(Character c) { if (!Saddles.TryGetValue(c, out var value)) { if (Saddles.Count > 512) { Saddles.Clear(); } value = (Saddles[c] = ((Component)c).GetComponentInChildren<Sadle>(true)); } return value; } private static float Moved(int id, Vector3 pos, Vector3 forward) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) Vector3 dir = forward; if (LastPos.TryGetValue(id, out var value)) { Vector3 val = pos - value; val.y = 0f; if (((Vector3)(ref val)).sqrMagnitude > 0.0004f) { dir = val; } } if (LastPos.Count > 512) { LastPos.Clear(); } LastPos[id] = pos; return HeadingOf(dir); } private static float HeadingOf(Vector3 dir) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) return Mathf.Atan2(dir.x, dir.z) * 57.29578f; } private static float Flat2(Vector3 d) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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) return d.x * d.x + d.z * d.z; } } internal sealed class StepCollector : MonoBehaviour { private const float SampleInterval = 0.25f; private const float SendInterval = 2f; private const int MaxBufferedPerZone = 512; private readonly Dictionary<int, StepTrace> _traces = new Dictionary<int, StepTrace>(); private readonly Dictionary<(int, int), List<(int index, float weight)>> _buffer = new Dictionary<(int, int), List<(int, float)>>(); private readonly Dictionary<(int, int), float> _readySince = new Dictionary<(int, int), float>(); private readonly List<Emitter> _emitters = new List<Emitter>(); private readonly List<Cell> _cells = new List<Cell>(); private readonly List<(Cell cell, float weight)> _wide = new List<(Cell, float)>(); private float _nextSample; private float _nextSend; private readonly Dictionary<int, int> _mergeIndex = new Dictionary<int, int>(); private readonly List<(int, float)> _merged = new List<(int, float)>(); private void Update() { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)ZNet.instance == (Object)null) && !((Object)(object)ZNetScene.instance == (Object)null) && TrailConfig.Active != null && TrailConfig.Active.Value) { if (Time.time >= _nextSample) { _nextSample = Time.time + 0.25f; Sample(localPlayer); } if (Time.time >= _nextSend) { _nextSend = Time.time + 2f; Send(localPlayer); } } } private void Sample(Player local) { //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) Emitters.Collect(local, _emitters); foreach (Emitter emitter in _emitters) { if (!_traces.TryGetValue(emitter.Id, out var value)) { value = (_traces[emitter.Id] = new StepTrace()); } if (!emitter.Valid || !AllowedAt(emitter.Pos)) { value.Reset(); continue; } _cells.Clear(); value.Add(emitter.Pos.x, emitter.Pos.z, _cells); foreach (Cell cell in _cells) { Cell center = Bundling.Attract(cell, emitter.Dir.x, emitter.Dir.z, TrailZone.WearAt); _wide.Clear(); Bundling.Widen(center, emitter.Dir.x, emitter.Dir.z, emitter.HalfWidth, _wide); foreach (var (c, item) in _wide) { foreach (var (item2, item3, item4) in ZoneCells.Map(c)) { Buffer((item2, item3)).Add((item4, item)); } } } } } private static bool AllowedAt(Vector3 pos) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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) return TrailGround.Allows(pos, checkPaint: false) && PrivateArea.CheckAccess(pos, 0f, false, true) && !Location.IsInsideNoBuildLocation(pos); } private List<(int, float)> Buffer((int, int) zone) { if (!_buffer.TryGetValue(zone, out List<(int, float)> value)) { value = (_buffer[zone] = new List<(int, float)>()); } return value; } private void Send(Player local) { if (((Character)local).IsTeleporting()) { _readySince.Clear(); } foreach (KeyValuePair<(int, int), List<(int, float)>> item3 in _buffer.ToList()) { (int, int) key = item3.Key; int item = key.Item1; int item2 = key.Item2; List<(int, float)> value = item3.Value; if (value.Count == 0) { continue; } TrailZone trailZone = TrailZone.Find(item, item2); if ((Object)(object)trailZone != (Object)null) { Merge(value); trailZone.SendSteps(value); trailZone.Predict(value); value.Clear(); _readySince.Remove(item3.Key); } else { Merge(value); if (value.Count > 512) { value.RemoveRange(0, value.Count - 512); } TryCreate(item3.Key, local); } } } private void Merge(List<(int index, float weight)> cells) { _mergeIndex.Clear(); _merged.Clear(); foreach (var (num, num2) in cells) { if (!_mergeIndex.TryGetValue(num, out var value)) { _mergeIndex[num] = _merged.Count; _merged.Add((num, num2)); } else { _merged[value] = (num, Mathf.Max(_merged[value].Item2, num2)); } } cells.Clear(); cells.AddRange(_merged); } private void TryCreate((int x, int z) zone, Player local) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor((float)(zone.x * 64), 0f, (float)(zone.z * 64)); Heightmap val2 = Heightmap.FindHeightmap(val); if (((Character)local).IsTeleporting() || !ZNetScene.instance.IsAreaReady(val) || (Object)(object)val2 == (Object)null || (Object)(object)TerrainComp.FindTerrainCompiler(val) != (Object)null) { _readySince.Remove(zone); return; } if (!_readySince.TryGetValue(zone, out var value)) { value = (_readySince[zone] = Time.time); } long sessionID = ZDOMan.GetSessionID(); List<long> list = new List<long>(); foreach (Player allPlayer in Player.GetAllPlayers()) { if (!((Object)(object)allPlayer == (Object)null) && !((Object)(object)((Character)allPlayer).m_nview == (Object)null) && ((Character)allPlayer).m_nview.IsValid()) { Vector3 position = ((Component)allPlayer).transform.position; if (CreatorRank.InZone(position.x, position.z, zone.x, zone.z)) { list.Add(((Character)allPlayer).m_nview.GetZDO().GetOwner()); } } } int rank = CreatorRank.Rank(sessionID, list); if (CreatorRank.ShouldCreate(rank, Time.time - value)) { _readySince.Remove(zone); val2.GetAndCreateTerrainCompiler(); } } } internal static class TerrainPainter { public static void Apply(TerrainComp tc, IReadOnlyList<(int index, float r)> cells, Vector3 center, float radius) { //IL_004c: 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_0097: 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_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) int num = tc.m_width + 1; foreach (var cell in cells) { int item = cell.index; float item2 = cell.r; Color val = (tc.m_modifiedPaint[item] ? tc.m_paintMask[item] : tc.m_hmap.GetPaintMask(item % num, item / num)); val.r = item2; tc.m_paintMask[item] = val; tc.m_modifiedPaint[item] = true; } tc.m_operations++; tc.m_lastOpPoint = center; tc.m_lastOpRadius = radius; tc.Save(false); tc.m_hmap.Poke(1, true); } } internal static class TrailGround { public static bool Allows(Vector3 pos, bool checkPaint) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_0088: Unknown result type (might be due to invalid IL or missing references) if (WorldGenerator.IsDeepnorth(pos.x, pos.z)) { return false; } Heightmap val = Heightmap.FindHeightmap(pos); if ((Object)(object)val == (Object)null) { return false; } if ((int)val.GetBiome(pos, 0.02f, false) == 4) { return false; } if (val.IsLava(pos, 0.6f)) { return false; } if (!checkPaint) { return true; } Color paintMask = val.GetPaintMask(pos); return paintMask.g <= 0.5f && paintMask.b <= 0.5f; } } internal static class TrailKeys { public static readonly int Cells = StringExtensionMethods.GetStableHashCode("Footpath_cells"); public static readonly int Time = StringExtensionMethods.GetStableHashCode("Footpath_time"); public static readonly int Ver = StringExtensionMethods.GetStableHashCode("Footpath_ver"); public const int FormatVersion = 2; public const string StepsRpc = "Footpath_Steps"; } internal sealed class TrailMarks : MonoBehaviour { private sealed class ZoneMarks { public int Version = int.MinValue; public float BuiltAt = float.MinValue; public float GroundAt = float.MinValue; public int LiveVersion = int.MinValue; public float Distance; public byte[] TcData; public readonly List<Particle> Marks = new List<Particle>(); public readonly Dictionary<int, (bool ok, Vector3 point, Vector3 normal)> Ground = new Dictionary<int, (bool, Vector3, Vector3)>(); } public const float SideOffset = 0.15f; public const float AlongJitter = 0.2f; public const float AreaJitter = 0.35f; public const float Range = 100f; public const int MaxMarks = 12000; public const float RebuildSec = 5f; public const float GroundRefreshSec = 60f; private const float CheckSec = 1f; private const float Lifetime = 10000000f; private static TrailMarks _instance; private readonly Dictionary<TrailZone, ZoneMarks> _zones = new Dictionary<TrailZone, ZoneMarks>(); private readonly List<TrailZone> _gone = new List<TrailZone>(); private readonly List<ZoneMarks> _byDistance = new List<ZoneMarks>(); private ParticleSystem _system; private Particle[] _buffer = (Particle[])(object)new Particle[256]; private bool _dirty; private bool _force; private float _nextCheck; private static readonly float[] Plus = new float[4]; private static readonly float[] Minus = new float[4]; private static readonly TrailPrints.Part[] Parts = new TrailPrints.Part[2]; private void Awake() { _instance = this; } internal static void Refresh() { if (!((Object)(object)_instance == (Object)null)) { _instance._force = true; _instance._nextCheck = 0f; } } private void Update() { //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0227: 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_0235: Unknown result type (might be due to invalid IL or missing references) if (Time.time < _nextCheck) { return; } _nextCheck = Time.time + 1f; Camera mainCamera = Utils.GetMainCamera(); if (TrailConfig.Active == null || !TrailConfig.Active.Value || !((Object)(object)Player.m_localPlayer != (Object)null) || !((Object)(object)mainCamera != (Object)null)) { if (_zones.Count > 0) { _zones.Clear(); _dirty = true; } Upload(); return; } Vector3 position = ((Component)mainCamera).transform.position; TrailPrints.Tick(position); _gone.Clear(); foreach (TrailZone key in _zones.Keys) { if ((Object)(object)key == (Object)null || !InRange(key, position)) { _gone.Add(key); } } foreach (TrailZone item in _gone) { _zones.Remove(item); } if (_gone.Count > 0) { _dirty = true; } TrailZone trailZone = null; ZoneMarks marks = null; float num = float.MaxValue; foreach (TrailZone item2 in TrailZone.Loaded) { if ((Object)(object)item2 == (Object)null || !InRange(item2, position)) { continue; } if (!_zones.TryGetValue(item2, out var value)) { value = (_zones[item2] = new ZoneMarks()); } Vector3 position2 = ((Component)item2).transform.position; value.Distance = (position2.x - position.x) * (position2.x - position.x) + (position2.z - position.z) * (position2.z - position.z); bool flag = value.Version != item2.WearVersion || value.LiveVersion != TrailPrints.LiveVersion || Time.time - value.GroundAt >= 60f; if (_force || (flag && !(Time.time - value.BuiltAt < 5f))) { if (!EnsureSystem()) { return; } if (_force) { Build(item2, value); _dirty = true; } else if (value.Distance < num) { trailZone = item2; marks = value; num = value.Distance; } } } if ((Object)(object)trailZone != (Object)null) { Build(trailZone, marks); _dirty = true; } _force = false; Upload(); } private static bool InRange(TrailZone zone, Vector3 camPos) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_001b: 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) Vector3 position = ((Component)zone).transform.position; float num = position.x - camPos.x; float num2 = position.z - camPos.z; return num * num + num2 * num2 <= 10000f; } private static void Build(TrailZone zone, ZoneMarks marks) { //IL_0084: 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_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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_01a8: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_025f: Unknown result type (might be due to invalid IL or missing references) //IL_0304: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_035b: 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_0372: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03cb: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_03f2: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_044e: Unknown result type (might be due to invalid IL or missing references) //IL_0452: Unknown result type (might be due to invalid IL or missing references) //IL_0457: Unknown result type (might be due to invalid IL or missing references) //IL_0469: Unknown result type (might be due to invalid IL or missing references) //IL_047d: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Unknown result type (might be due to invalid IL or missing references) //IL_0494: Unknown result type (might be due to invalid IL or missing references) //IL_0496: Unknown result type (might be due to invalid IL or missing references) //IL_04a0: Unknown result type (might be due to invalid IL or missing references) //IL_04b9: Unknown result type (might be due to invalid IL or missing references) //IL_04c6: Unknown result type (might be due to invalid IL or missing references) //IL_04c8: Unknown result type (might be due to invalid IL or missing references) //IL_0505: Unknown result type (might be due to invalid IL or missing references) marks.Version = zone.WearVersion; marks.LiveVersion = TrailPrints.LiveVersion; marks.BuiltAt = Time.time; marks.Marks.Clear(); if (marks.TcData != zone.LastTcData || Time.time - marks.GroundAt >= 60f) { marks.TcData = zone.LastTcData; marks.Ground.Clear(); marks.GroundAt = Time.time; } int num = 64; Color currentTint = TrailPrints.CurrentTint; float sizeMin = TrailPrints.SizeMin; float sizeMax = TrailPrints.SizeMax; float[] wear = zone.Grid.Wear; for (int i = 0; i < wear.Length; i++) { float num2 = wear[i]; if (num2 < 0.18f) { continue; } Vector3 val = zone.CellWorld(i); if (!MarkLayout.Present(num2, val.x, val.z)) { continue; } int num3 = i % 65; int num4 = i / 65; if ((num3 == num || num4 == num) && TrailZone.HasPrimaryElsewhere(zone, val)) { continue; } for (int j = 0; j < 4; j++) { Plus[j] = WearNear(zone, num3, num4, MarkLayout.DirX[j], MarkLayout.DirZ[j]); Minus[j] = WearNear(zone, num3, num4, -MarkLayout.DirX[j], -MarkLayout.DirZ[j]); } int num5 = MarkLayout.Classify(num2, Plus, Minus); if (num5 == -1 || (num5 == 4 && WearModel.Hash01(val.x, val.z) >= 0.35f)) { continue; } Cell c = Cell.FromWorld(val.x, val.z); if (TrailPrints.HasLivePrintNear(c)) { continue; } if (!marks.Ground.TryGetValue(i, out (bool, Vector3, Vector3) value)) { value = (marks.Ground[i] = FindGround(val)); } if (value.Item1 && !zone.IsFieldOrPavedAt(i)) { float num6 = WearModel.Hash01(val.x + 0.11f, val.z + 0.73f) * 2f - 1f; float num7; float num8; float num9; if (num5 == 4) { num7 = num6 * 0.35f; num8 = (WearModel.Hash01(val.x - 0.47f, val.z - 0.29f) * 2f - 1f) * 0.35f; num9 = WearModel.Hash01(val.x + 0.31f, val.z - 0.57f) * 360f; } else { MarkLayout.Along(num5, out var ax, out var az); int num10 = MarkLayout.StepIndex(num5, val.x, val.z); float num11 = (((num10 & 1) == 0) ? 0.15f : (-0.15f)); float num12 = num6 * 0.2f; num7 = az * num11 + ax * num12; num8 = (0f - ax) * num11 + az * num12; num9 = TrailPrints.SpinAlong(new Vector3(ax, 0f, az)) + (WearModel.Hash01(val.x + 0.31f, val.z - 0.57f) * 2f - 1f) * 10f; } Vector3 item = value.Item3; Vector3 point = value.Item2 + new Vector3(num7, (item.y > 0.1f) ? ((0f - (item.x * num7 + item.z * num8)) / item.y) : 0f, num8); Color val2 = currentTint; float size = Mathf.Lerp(sizeMin, sizeMax, WearModel.Hash01(val.x - 0.83f, val.z + 0.19f)); float num13 = num9 * ((float)Math.PI / 180f); int num14 = TrailPrints.StepParts(point, item, new Vector3(0f - Mathf.Sin(num13), 0f, 0f - Mathf.Cos(num13)), size, Parts); Vector3 rotation3D = TrailPrints.DecalEuler(item, num9); for (int k = 0; k < num14; k++) { List<Particle> marks2 = marks.Marks; Particle item2 = default(Particle); ((Particle)(ref item2)).position = Parts[k].position; ((Particle)(ref item2)).rotation3D = rotation3D; ((Particle)(ref item2)).velocity = -item * 0.001f; ((Particle)(ref item2)).startSize3D = Parts[k].size; ((Particle)(ref item2)).startColor = Color32.op_Implicit(val2); ((Particle)(ref item2)).startLifetime = 10000000f; ((Particle)(ref item2)).remainingLifetime = 10000000f; ((Particle)(ref item2)).randomSeed = (uint)((i * 2 + k) * 2654435761u); marks2.Add(item2); } } } } private static float WearNear(TrailZone zone, int x, int z, int dx, int dz) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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) int num = x + dx; int num2 = z + dz; if (num >= 0 && num < 65 && num2 >= 0 && num2 < 65) { return zone.Grid.Wear[num2 * 65 + num]; } Vector3 val = zone.CellWorld(z * 65 + x); return TrailZone.WearAt(Cell.FromWorld(val.x + (float)dx, val.z + (float)dz)); } private static (bool, Vector3, Vector3) FindGround(Vector3 cell) { //IL_0003: 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_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_0065: 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_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: 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_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Invalid comparison between Unknown and I4 //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); ((Vector3)(ref val))..ctor(cell.x, 0f, cell.z); float y = default(float); if (!Heightmap.GetHeight(val, ref y)) { return (false, default(Vector3), default(Vector3)); } val.y = y; if (!Emitters.TerrainHit(val, out var hit)) { return (false, default(Vector3), default(Vector3)); } if (Floating.GetLiquidLevel(((RaycastHit)(ref hit)).point, 1f, (LiquidType)10) > ((RaycastHit)(ref hit)).point.y) { return (false, default(Vector3), default(Vector3)); } if (!TrailGround.Allows(((RaycastHit)(ref hit)).point, checkPaint: false)) { return (false, default(Vector3), default(Vector3)); } if ((int)Heightmap.FindBiome(((RaycastHit)(ref hit)).point) == 32) { return (false, default(Vector3), default(Vector3)); } return (true, ((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal); } private void Upload() { //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) if (!_dirty) { return; } _dirty = false; int num = 0; foreach (ZoneMarks value in _zones.Values) { num += value.Marks.Count; } num = Mathf.Min(num, 12000); if ((Object)(object)_system == (Object)null) { return; } if (_buffer.Length < num) { _buffer = (Particle[])(object)new Particle[Mathf.NextPowerOfTwo(num)]; } _byDistance.Clear(); _byDistance.AddRange(_zones.Values); _byDistance.Sort((ZoneMarks a, ZoneMarks b) => a.Distance.CompareTo(b.Distance)); int num2 = 0; foreach (ZoneMarks item in _byDistance) { foreach (Particle mark in item.Marks) { if (num2 >= num) { break; } _buffer[num2++] = mark; } } _system.SetParticles(_buffer, num2); TrailPrints.Settle(_system); } private bool EnsureSystem() { if ((Object)(object)_system != (Object)null) { return true; } _system = TrailPrints.CreateSystem("Footpath_Marks", 12000, out var _); if ((Object)(object)_system == (Object)null) { return false; } TrailPrints.DisableOverLifetime(_system); return true; } internal static string DebugState() { if ((Object)(object)_instance == (Object)null) { return "Bleibende Abdrücke: aus."; } int count = _instance._zones.Count; int num = (((Object)(object)_instance._system != (Object)null) ? _instance._system.particleCount : 0); return $"Bleibende Abdrücke: {num} in {count} Zonen."; } } internal static class TrailPrints { internal struct Part { public Vector3 position; public Vector3 size; } public const int MaxPrints = 4000; private const float Lifetime = 10000000f; private const float CullSec = 2f; private const float CullMoveM = 10f; public const float MaxCameraDistance = 60f; private const float SettleStep = 0.0001f; public const float Glossiness = 0f; public const float Opacity = 0.75f; public static readonly Color Tint = new Color(0.05f, 0.03f, 0.015f); public const float SizeFactor = 0.75f; public const float BumpScale = 0f; public const float FootWidth = 1.2f; public const float FootLength = 0.8f; public const float HeelBallGap = 0.3f; public const float PartSize = 0.6f; public const float HeelScale = 0.8f; public const float Density = 3f; public const float Metallic = 0f; public const float CellSize = 0.5f; private const MotionType GroundMotion = (MotionType)103; private static ParticleSystem _system; private static bool _noTemplate; private static float _vanillaSizeMin; private static float _vanillaSizeMax; private static Color _tint = new Color(Tint.r, Tint.g, Tint.b, 0.75f); private static float _sizeFactor = 0.75f; private static float _gloss = 0f; private static float _bump = 0f; private static float _footWidth = 1.2f; private static float _footLength = 0.8f; private static float _gap = 0.3f; private static float _part = 0.6f; private static float _density = 3f; private static float _metallic = 0f; private static Texture _vanillaMainTex; private static Texture2D _denseTex; private static float _denseFor = float.NaN; private static Texture2D _debugTex; private static readonly List<ParticleSystem> Systems = new List<ParticleSystem>(); private static readonly Dictionary<Character, Sadle> Saddles = new Dictionary<Character, Sadle>(); private static readonly Dictionary<uint, long> StepSpot = new Dictionary<uint, long>(); private static readonly Dictionary<long, uint> Newest = new Dictionary<long, uint>(); private static readonly HashSet<Cell> Cells = new HashSet<Cell>(); private static readonly HashSet<uint> KeptSteps = new HashSet<uint>(); private static readonly List<uint> GoneSteps = new List<uint>(); private static bool _replaced; private static uint _stepId; private static Particle[] _cullBuffer = (Particle[])(object)new Particle[256]; private static float _nextCull; private static Vector3 _culledAt = new Vector3(float.MaxValue, 0f, 0f); private static readonly Dictionary<StepEffect, bool> VanillaDecal = new Dictionary<StepEffect, bool>(); private static readonly Part[] Parts = new Part[2]; internal static int LiveVersion { get; private set; } internal static float CurrentFootWidth => _footWidth; internal static float CurrentFootLength => _footLength; internal static Color CurrentTint => _tint; internal static float SizeMin => _vanillaSizeMin * _sizeFactor; internal static float SizeMax => _vanillaSizeMax * _sizeFactor; public static void OnStep(FootStep step, int effectIndex, Vector3 point) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Invalid comparison between Unknown and I4 //IL_00a7: 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_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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) if (TrailConfig.Active == null || !TrailConfig.Active.Value || !LeavesPrints(step.m_character) || effectIndex < 0 || effectIndex >= step.m_effects.Count) { return; } StepEffect val = step.m_effects[effectIndex]; if ((val.m_motionType & 0x67) == 0 || HasVanillaDecal(val)) { return; } Camera mainCamera = Utils.GetMainCamera(); if (!((Object)(object)mainCamera == (Object)null)) { Vector3 val2 = ((Component)mainCamera).transform.position - point; if (!(((Vector3)(ref val2)).sqrMagnitude > 3600f) && Emitters.TerrainHit(point, out var hit) && !(Floating.GetLiquidLevel(((RaycastHit)(ref hit)).point, 1f, (LiquidType)10) > ((RaycastHit)(ref hit)).point.y) && TrailGround.Allows(((RaycastHit)(ref hit)).point, checkPaint: true)) { Place(((RaycastHit)(ref hit)).point, ((RaycastHit)(ref hit)).normal, ((Component)step.m_character).transform.forward); } } } private static long SpotKey(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) return ((long)Mathf.FloorToInt(p.x / 0.5f) << 32) ^ (uint)Mathf.FloorToInt(p.z / 0.5f); } internal static bool HasLivePrintNear(Cell c) { if (Cells.Count == 0) { return false; } for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (Cells.Contains(new Cell(c.X + j, c.Z + i))) { return true; } } } return false; } internal static void Tick(Vector3 camPos) { //IL_0022: 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_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_system == (Object)null) { return; } int particleCount = _system.particleCount; float num = camPos.x - _culledAt.x; float num2 = camPos.z - _culledAt.z; bool flag = Time.time >= _nextCull && (particleCount >= 3998 || num * num + num2 * num2 >= 100f); if (!flag && !_replaced) { return; } if (flag) { _nextCull = Time.time + 2f; _c