Decompiled source of WinterLab v1.3.0
Mods/WinterLab.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Buffers.Binary; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BoneLib; using BoneLib.BoneMenu; using BoneWinter; using HarmonyLib; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppInterop.Runtime.InteropTypes.Fields; using Il2CppSLZ.Marrow; using Il2CppSLZ.Marrow.Interaction; using Il2CppSLZ.Marrow.Pool; using Il2CppSystem; using MelonLoader; using MelonLoader.Preferences; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: MelonInfo(typeof(BoneWinterMod), "WinterLab", "1.3.0", "nighthippo", null)] [assembly: MelonGame("Stress Level Zero", "BONELAB")] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("WinterLab")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.0.0")] [assembly: AssemblyInformationalVersion("1.3.0")] [assembly: AssemblyProduct("WinterLab")] [assembly: AssemblyTitle("WinterLab")] [assembly: AssemblyVersion("1.3.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace BoneWinter { public sealed class BoneWinterMod : MelonMod { private WinterSettings settings; private WinterLook look; private SnowCoverage coverage; private Snowfall snowfall; private FrozenWater frozenWater; private readonly SnowSteps steps = new SnowSteps(); private readonly SnowContacts contacts = new SnowContacts(); private bool levelReady; private bool clearSnow; private float rebuildAt = float.PositiveInfinity; private float saveAt = float.PositiveInfinity; private Vector3 coverageOrigin; public override void OnInitializeMelon() { settings = new WinterSettings(); look = new WinterLook(((MelonBase)this).LoggerInstance); coverage = new SnowCoverage(((MelonBase)this).LoggerInstance); snowfall = new Snowfall(((MelonBase)this).LoggerInstance); frozenWater = new FrozenWater(((MelonBase)this).LoggerInstance, ((MelonBase)this).HarmonyInstance); new WinterMenu(settings, ApplySettings, RegenerateSnow, ClearSnow); Hooking.OnLevelLoading += OnLevelLoading; Hooking.OnLevelLoaded += OnLevelLoaded; Hooking.OnLevelUnloaded += EndLevel; ((MelonBase)this).LoggerInstance.Msg("Initialized. Waiting for a playable level."); } public override void OnLateInitializeMelon() { frozenWater.Connect(); } private void OnLevelLoading(LevelInfo _) { EndLevel(); } public override void OnSceneWasLoaded(int buildIndex, string sceneName) { if (levelReady && !clearSnow && settings.Enabled.Value && settings.Coverage.Value) { rebuildAt = Time.unscaledTime + 1.2f; } } private void OnLevelLoaded(LevelInfo _) { if (!levelReady) { levelReady = true; clearSnow = false; ApplySettings(WinterChange.All, save: false); } } private void ApplySettings(WinterChange change) { ApplySettings(change, save: true); } private void ApplySettings(WinterChange change, bool save) { if (save) { saveAt = Time.unscaledTime + 0.4f; } if (!levelReady) { return; } if (change.HasFlag(WinterChange.Coverage)) { clearSnow = false; if (settings.Enabled.Value && settings.Coverage.Value) { rebuildAt = Time.unscaledTime + 0.75f; } else { ClearSnow(); } } if (change.HasFlag(WinterChange.Weather)) { if (settings.Enabled.Value && settings.Snowfall.Value) { snowfall.Configure(look.Flakes, settings); } else { snowfall.Clear(); } } if (change.HasFlag(WinterChange.Ice)) { if (settings.Enabled.Value && settings.Ice.Value && frozenWater.Connected) { Material ice = look.Ice; if (Object.op_Implicit((Object)(object)ice)) { ice.SetFloat("_IceOpacity", settings.IceOpacity.Value); } frozenWater.Enable(ice, settings.Slipperiness.Value, settings.IceThickness.Value); } else { frozenWater.Clear(); } } if (change.HasFlag(WinterChange.Steps) && !settings.Compression.Value) { coverage.ClearImpressions(); } if (!settings.Enabled.Value) { look.Clear(); } } private void RegenerateSnow() { if (levelReady && settings.Enabled.Value && settings.Coverage.Value) { clearSnow = false; rebuildAt = Time.unscaledTime; } } private void ClearSnow() { clearSnow = true; rebuildAt = float.PositiveInfinity; coverage.Clear(); } public override void OnUpdate() { //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) float unscaledTime = Time.unscaledTime; if (unscaledTime >= saveAt) { Save(); } if (!levelReady) { return; } RigManager rigManager = Player.RigManager; if (Object.op_Implicit((Object)(object)rigManager) && !clearSnow && float.IsPositiveInfinity(rebuildAt) && coverage.NeedsNewFallbackRegion) { Vector3 val = ((Component)rigManager).transform.position - coverageOrigin; if (((Vector3)(ref val)).sqrMagnitude > 4225f) { rebuildAt = unscaledTime + 0.4f; } } if (!clearSnow && unscaledTime >= rebuildAt) { rebuildAt = float.PositiveInfinity; if (Object.op_Implicit((Object)(object)rigManager)) { coverageOrigin = ((Component)rigManager).transform.position; } contacts.Reset(); coverage.Generate(look.Snow, settings.GetCoverageOptions(), Object.op_Implicit((Object)(object)rigManager) ? new Vector3?(coverageOrigin) : ((Vector3?)null)); } coverage.Update(); if (Object.op_Implicit((Object)(object)rigManager) && settings.Snowfall.Value) { snowfall.Update(((Component)rigManager).transform.position); } steps.Update(coverage, snowfall, look, settings); if (Object.op_Implicit((Object)(object)rigManager)) { PhysicsRig physicsRig = Player.PhysicsRig; contacts.Update(((Component)rigManager).transform.position, (Collider)(object)(Object.op_Implicit((Object)(object)physicsRig) ? physicsRig._football : null), coverage, settings); } frozenWater.Update(); } private void Save() { saveAt = float.PositiveInfinity; try { settings.Save(); } catch (Exception ex) { ((MelonBase)this).LoggerInstance.Warning("Could not save preferences: " + ex.Message); } } private void EndLevel() { levelReady = false; steps.Reset(); contacts.Reset(); ClearSnow(); snowfall?.Clear(); frozenWater?.Clear(); look?.Clear(); } public override void OnDeinitializeMelon() { Hooking.OnLevelLoading -= OnLevelLoading; Hooking.OnLevelLoaded -= OnLevelLoaded; Hooking.OnLevelUnloaded -= EndLevel; if (!float.IsPositiveInfinity(saveAt)) { Save(); } EndLevel(); frozenWater?.Disconnect(); look?.Dispose(); } } internal sealed class CollisionSnowSurface { private readonly record struct Hit(bool Valid, Vector3 Point, Vector3 Normal); internal readonly record struct Triangle(bool Valid, Vector3 A, Vector3 B, Vector3 C); private const float Spacing = 0.5f; private const float HorizontalPadding = 0.12f; private const float VerticalPadding = 0.18f; private const int SamplesPerCollider = 16384; private readonly Dictionary<(int X, int Z), List<Bounds>> regions = new Dictionary<(int, int), List<Bounds>>(); private readonly List<Bounds> large = new List<Bounds>(); private const float CellSize = 12f; internal bool HasMissingMeshes { get { if (regions.Count == 0) { return large.Count != 0; } return true; } } internal void AddMissing(Bounds bounds) { //IL_0011: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) ((Bounds)(ref bounds)).Expand(new Vector3(0.24f, 0.36f, 0.24f)); var (num, num2, num3, num4) = Cells(bounds); if ((long)(num2 - num + 1) * (long)(num4 - num3 + 1) > 64) { large.Add(bounds); return; } for (int i = num; i <= num2; i++) { for (int j = num3; j <= num4; j++) { if (!regions.TryGetValue((i, j), out var value)) { regions.Add((i, j), value = new List<Bounds>()); } value.Add(bounds); } } } internal IEnumerable<Triangle> Reconstruct(Collider collider, float minUp, Vector3? focus, bool colliderOnly = false) { Bounds bounds = collider.bounds; List<Bounds> matches = (colliderOnly ? new List<Bounds> { bounds } : OverlappingRegions(bounds)); if (matches.Count == 0) { yield break; } Bounds val = matches[0]; for (int i = 1; i < matches.Count; i++) { ((Bounds)(ref val)).Encapsulate(matches[i]); } Vector3 lo = Vector3.Max(((Bounds)(ref val)).min, ((Bounds)(ref bounds)).min); Vector3 hi = Vector3.Min(((Bounds)(ref val)).max, ((Bounds)(ref bounds)).max); if (focus.HasValue) { Vector3 valueOrDefault = focus.GetValueOrDefault(); lo.x = Math.Max(lo.x, valueOrDefault.x - 105f); lo.z = Math.Max(lo.z, valueOrDefault.z - 105f); hi.x = Math.Min(hi.x, valueOrDefault.x + 105f); hi.z = Math.Min(hi.z, valueOrDefault.z + 105f); } float num = hi.x - lo.x; float num2 = hi.z - lo.z; if (num < 0.08f || num2 < 0.08f || hi.y < lo.y) { yield break; } float num3 = Math.Max(0.5f, MathF.Sqrt(num * num2 / 16384f)); int nx = Math.Clamp((int)MathF.Ceiling(num / num3), 1, 192); int nz = Math.Clamp((int)MathF.Ceiling(num2 / num3), 1, 192); Hit[] previous = new Hit[nx + 1]; Hit[] current = new Hit[nx + 1]; float rayTop = ((Bounds)(ref bounds)).max.y + 0.15f; float rayLength = rayTop - lo.y + 0.1f; for (int z = 0; z <= nz; z++) { float wz = Mathf.Lerp(lo.z + 0.004f, hi.z - 0.004f, (float)z / (float)nz); for (int x = 0; x <= nx; x++) { float x2 = Mathf.Lerp(lo.x + 0.004f, hi.x - 0.004f, (float)x / (float)nx); current[x] = Check(collider, x2, wz, rayTop, rayLength, minUp); if (x > 0 && z > 0) { yield return MakeTriangle(previous[x - 1], current[x - 1], previous[x], matches); yield return MakeTriangle(previous[x], current[x - 1], current[x], matches); } else { yield return default(Triangle); } } Hit[] array = current; current = previous; previous = array; } } private List<Bounds> OverlappingRegions(Bounds bounds) { //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) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) List<Bounds> result = new List<Bounds>(); foreach (Bounds item in large) { Bounds current = item; if (((Bounds)(ref current)).Intersects(bounds)) { result.Add(current); } } HashSet<Bounds> seen = new HashSet<Bounds>(); var (num, num2, num3, num4) = Cells(bounds); if ((long)(num2 - num + 1) * (long)(num4 - num3 + 1) > (long)regions.Count * 2L) { foreach (var (tuple3, cell) in regions) { if (tuple3.Item1 >= num && tuple3.Item1 <= num2 && tuple3.Item2 >= num3 && tuple3.Item2 <= num4) { AddIntersecting(cell); } } } else { for (int i = num; i <= num2; i++) { for (int j = num3; j <= num4; j++) { if (regions.TryGetValue((i, j), out var value)) { AddIntersecting(value); } } } } return result; void AddIntersecting(List<Bounds> list2) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_0034: Unknown result type (might be due to invalid IL or missing references) foreach (Bounds item2 in list2) { Bounds current2 = item2; if (((Bounds)(ref current2)).Intersects(bounds) && seen.Add(current2)) { result.Add(current2); } } } } private static Hit Check(Collider collider, float x, float z, float top, float length, float minUp) { //IL_0005: 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_001d: 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_0046: 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) Ray val = default(Ray); ((Ray)(ref val))..ctor(new Vector3(x, top, z), Vector3.down); RaycastHit val2 = default(RaycastHit); if (!Object.op_Implicit((Object)(object)collider) || !collider.Raycast(val, ref val2, length) || ((RaycastHit)(ref val2)).normal.y <= minUp) { return default(Hit); } return new Hit(Valid: true, ((RaycastHit)(ref val2)).point, ((RaycastHit)(ref val2)).normal); } private static Triangle MakeTriangle(Hit a, Hit b, Hit c, List<Bounds> regions) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_005a: 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_0069: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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) if (!a.Valid || !b.Valid || !c.Valid || !SameSurface(a, b) || !SameSurface(b, c) || !SameSurface(c, a)) { return default(Triangle); } Vector3 val = (a.Point + b.Point + c.Point) / 3f; foreach (Bounds region in regions) { Bounds current = region; if (((Bounds)(ref current)).Contains(val)) { return new Triangle(Valid: true, a.Point, b.Point, c.Point); } } return default(Triangle); } private static bool SameSurface(Hit a, Hit b) { //IL_0002: 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_000e: 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_0016: 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_0030: 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_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = b.Point - a.Point; if (Vector3.Dot(a.Normal, b.Normal) > 0.8f && Math.Abs(Vector3.Dot(a.Normal, val)) < 0.085f) { return Math.Abs(Vector3.Dot(b.Normal, val)) < 0.085f; } return false; } private static (int X0, int X1, int Z0, int Z1) Cells(Bounds bounds) { //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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) Vector3 min = ((Bounds)(ref bounds)).min; Vector3 max = ((Bounds)(ref bounds)).max; return (X0: Mathf.FloorToInt(min.x / 12f), X1: Mathf.FloorToInt(max.x / 12f), Z0: Mathf.FloorToInt(min.z / 12f), Z1: Mathf.FloorToInt(max.z / 12f)); } } internal sealed class FrozenWater { private readonly record struct IcePose(Vector3 Center, Quaternion Rotation, Vector3 Scale); private sealed class IceSheet { internal readonly MonoBehaviour Volume; internal readonly Collider Trigger; internal readonly GameObject GameObject; internal IcePose Pose { get; private set; } internal IceSheet(MonoBehaviour volume, Collider trigger, Material surface, PhysicMaterial grip) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) Volume = volume; Trigger = trigger; GameObject = GameObject.CreatePrimitive((PrimitiveType)3); ((Object)GameObject).name = "BoneWinter ice sheet"; GameObject.SetActive(false); try { SceneManager.MoveGameObjectToScene(GameObject, ((Component)volume).gameObject.scene); ((Renderer)GameObject.GetComponent<MeshRenderer>()).sharedMaterial = surface; ((Collider)GameObject.GetComponent<BoxCollider>()).sharedMaterial = grip; } catch { Object.Destroy((Object)(object)GameObject); throw; } } internal void SetPose(IcePose pose) { //IL_000e: 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_0021: Unknown result type (might be due to invalid IL or missing references) Transform transform = GameObject.transform; transform.SetPositionAndRotation(pose.Center, pose.Rotation); transform.localScale = pose.Scale; Pose = pose; } } private static FrozenWater bridge; private readonly Instance log; private readonly Harmony harmony; private readonly Dictionary<int, MonoBehaviour> pending = new Dictionary<int, MonoBehaviour>(); private readonly Dictionary<int, IceSheet> frozen = new Dictionary<int, IceSheet>(); private readonly List<int> removed = new List<int>(); private MethodInfo enableHook; private Action<FrozenWater> scan; private PropertyInfo density; private PropertyInfo ambience; private PropertyInfo splashVisual; private PropertyInfo splashSound; private FieldInfo center; private FieldInfo size; private Material surface; private PhysicMaterial grip; private bool active; private bool needsScan; private float refreshAt; private float depth; internal bool Connected => scan != null; internal FrozenWater(Instance log, Harmony harmony) { this.log = log; this.harmony = harmony; } internal void Connect() { //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Expected O, but got Unknown Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly item) => !item.IsDynamic && item.GetName().Name == "FluidLab"); if (assembly == null) { log.Msg("FluidLab is absent. Frozen water is unavailable."); return; } try { Type type = assembly.GetType("FluidLab.LiquidVolume", throwOnError: true); density = AccessTools.Property(type, "Density"); ambience = AccessTools.Property(type, "AmbienceBarcode"); splashVisual = AccessTools.Property(type, "SplashVFXBarcode"); splashSound = AccessTools.Property(type, "SplashSFXBarcode"); center = AccessTools.Field(type, "center"); size = AccessTools.Field(type, "size"); enableHook = AccessTools.DeclaredMethod(type, "OnEnable", Type.EmptyTypes, (Type[])null); if (density?.PropertyType != typeof(float) || ambience?.PropertyType != typeof(string) || splashVisual?.PropertyType != typeof(string) || splashSound?.PropertyType != typeof(string) || center?.FieldType != typeof(Il2CppValueField<Vector3>) || size?.FieldType != typeof(Il2CppValueField<Vector3>) || enableHook == null) { throw new NotSupportedException("LiquidVolume does not match the inspected FluidLab 1.0.3 API."); } Action<FrozenWater> action = (Action<FrozenWater>)AccessTools.DeclaredMethod(typeof(FrozenWater), "Discover", (Type[])null, (Type[])null).MakeGenericMethod(type).CreateDelegate(typeof(Action<FrozenWater>)); harmony.Patch((MethodBase)enableHook, (HarmonyMethod)null, new HarmonyMethod(typeof(FrozenWater), "OnVolumeEnabled", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); bridge = this; scan = action; log.Msg($"Connected to FluidLab {assembly.GetName().Version}."); } catch (Exception ex) { log.Warning("Frozen water unavailable: " + ex.GetBaseException().Message); } } internal void Disconnect() { if (Connected) { harmony.Unpatch((MethodBase)enableHook, (HarmonyPatchType)2, harmony.Id); } if (bridge == this) { bridge = null; } scan = null; } private static void Discover<T>(FrozenWater instance) where T : MonoBehaviour { foreach (T item in Object.FindObjectsOfType<T>()) { instance.Queue((MonoBehaviour)(object)item); } } private static void OnVolumeEnabled(MonoBehaviour __instance) { bridge?.Queue(__instance); } private void Queue(MonoBehaviour volume) { if (active && Object.op_Implicit((Object)(object)volume)) { int instanceID = ((Object)volume).GetInstanceID(); if (!frozen.ContainsKey(instanceID)) { pending[instanceID] = volume; } } } internal void Enable(Material material, float slipperiness, float thickness) { //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_004a: 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_0061: Expected O, but got Unknown if (!Connected || !Object.op_Implicit((Object)(object)material)) { Clear(); return; } surface = material; depth = thickness; refreshAt = 0f; if (!active) { grip = new PhysicMaterial("BoneWinter slippery ice") { frictionCombine = (PhysicMaterialCombine)2, bounceCombine = (PhysicMaterialCombine)2, bounciness = 0f }; active = true; needsScan = true; } grip.dynamicFriction = Mathf.Lerp(0.72f, 0.014f, slipperiness); grip.staticFriction = Mathf.Lerp(0.8f, 0.022f, slipperiness); } internal void Update() { if (!active) { return; } if (needsScan) { needsScan = false; try { scan(this); } catch (Exception ex) { log.Warning("Could not enumerate FluidLab volumes: " + ex.GetBaseException().Message); } } int num = 0; int key; foreach (KeyValuePair<int, MonoBehaviour> item2 in pending) { item2.Deconstruct(out key, out var value); int num2 = key; MonoBehaviour val = value; if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).isActiveAndEnabled || frozen.ContainsKey(num2)) { continue; } try { if (TryFreeze(num2, val)) { num++; } } catch (Exception ex2) { log.Warning("Could not freeze FluidLab volume '" + ((Object)val).name + "': " + ex2.GetBaseException().Message); } } pending.Clear(); if (num != 0) { log.Msg($"Froze {num} FluidLab water volume(s)."); } if (Time.unscaledTime < refreshAt) { return; } refreshAt = Time.unscaledTime + 0.2f; foreach (KeyValuePair<int, IceSheet> item3 in frozen) { item3.Deconstruct(out key, out var value2); int item = key; IceSheet iceSheet = value2; try { if (Object.op_Implicit((Object)(object)iceSheet.Volume) && ((Component)iceSheet.Volume).gameObject.activeInHierarchy && Object.op_Implicit((Object)(object)iceSheet.Trigger) && Object.op_Implicit((Object)(object)iceSheet.GameObject) && TryGetPose(iceSheet.Volume, out var pose)) { if (iceSheet.Pose != pose) { iceSheet.SetPose(pose); } continue; } } catch (Exception ex3) { log.Warning("Removing a stale ice sheet: " + ex3.GetBaseException().Message); } removed.Add(item); } foreach (int item4 in removed) { IceSheet sheet = frozen[item4]; frozen.Remove(item4); Release(sheet); } removed.Clear(); } private bool TryFreeze(int id, MonoBehaviour volume) { if (!(Mathf.Abs((float)density.GetValue(volume) - 1000f) <= 0.001f) || NonWater(ambience.GetValue(volume) as string) || NonWater(splashVisual.GetValue(volume) as string) || NonWater(splashSound.GetValue(volume) as string) || NonWater(((Object)((Component)volume).gameObject).name) || !TryGetPose(volume, out var pose)) { return false; } Collider[] array = ((IEnumerable<Collider>)((Component)volume).GetComponents<Collider>()).Where((Collider collider) => Object.op_Implicit((Object)(object)collider) && collider.enabled && collider.isTrigger).ToArray(); if (array.Length != 1 || !Object.op_Implicit((Object)(object)((Il2CppObjectBase)array[0]).TryCast<BoxCollider>()) || Object.op_Implicit((Object)(object)((Component)volume).GetComponent("FlowVolume"))) { return false; } IceSheet iceSheet = null; try { iceSheet = new IceSheet(volume, array[0], surface, grip); iceSheet.SetPose(pose); frozen.Add(id, iceSheet); ((Behaviour)volume).enabled = false; iceSheet.Trigger.enabled = false; iceSheet.GameObject.SetActive(true); return true; } catch { frozen.Remove(id); if (iceSheet != null) { Release(iceSheet); } throw; } } private static bool NonWater(string name) { if (name != null) { if (!name.Contains("lava", StringComparison.OrdinalIgnoreCase) && !name.Contains("acid", StringComparison.OrdinalIgnoreCase) && !name.Contains("magma", StringComparison.OrdinalIgnoreCase)) { return name.Contains("oil", StringComparison.OrdinalIgnoreCase); } return true; } return false; } private bool TryGetPose(MonoBehaviour volume, out IcePose pose) { //IL_000e: 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_0016: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) pose = default(IcePose); Transform transform = ((Component)volume).transform; Matrix4x4 localToWorldMatrix = transform.localToWorldMatrix; Vector3 lossyScale = ((Matrix4x4)(ref localToWorldMatrix)).lossyScale; Vector3 val = ((Matrix4x4)(ref localToWorldMatrix)).MultiplyPoint3x4(((Il2CppValueField<Vector3>)center.GetValue(volume)).Get()); Vector3 val2 = Vector3.Scale(lossyScale, ((Il2CppValueField<Vector3>)size.GetValue(volume)).Get()); Vector3 forward = transform.forward; Vector3 up = transform.up; if (!(val2.x > 0.05f) || !(val2.y > 0f) || !(val2.z > 0.05f) || !float.IsFinite(((Vector3)(ref val2)).sqrMagnitude) || !float.IsFinite(((Vector3)(ref val)).sqrMagnitude) || Vector3.Dot(up, Vector3.up) < 0.999f) { return false; } val.y += val2.y * 0.5f + 0.012f - depth * 0.5f; forward.y = 0f; pose = new IcePose(val, Quaternion.LookRotation(forward, Vector3.up), new Vector3(val2.x, depth, val2.z)); return true; } internal void Clear() { active = false; needsScan = false; pending.Clear(); foreach (IceSheet value in frozen.Values) { Release(value); } frozen.Clear(); if (Object.op_Implicit((Object)(object)grip)) { Object.Destroy((Object)(object)grip); } grip = null; surface = null; } private void Release(IceSheet sheet) { if (Object.op_Implicit((Object)(object)sheet.GameObject)) { sheet.GameObject.SetActive(false); Object.Destroy((Object)(object)sheet.GameObject); } try { if (Object.op_Implicit((Object)(object)sheet.Volume)) { ((Behaviour)sheet.Volume).enabled = true; } if (Object.op_Implicit((Object)(object)sheet.Trigger)) { sheet.Trigger.enabled = true; } } catch (Exception ex) { log.Warning("Could not restore a FluidLab trigger: " + ex.GetBaseException().Message); } } } internal sealed class MeshSource { internal readonly Vector3[] Vertices; internal readonly int[][] Indices; internal long Bytes { get; } internal MeshSource(Mesh mesh) : this(((IEnumerable<Vector3>)mesh.vertices).ToArray(), ReadIndices(mesh)) { } internal MeshSource(Vector3[] vertices, int[][] indices) { Vertices = vertices; Indices = indices; Bytes = vertices.LongLength * 12 + indices.Sum((int[] part) => ((part != null) ? part.LongLength : 0) * 4); } private static int[][] ReadIndices(Mesh mesh) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) int[][] array = new int[mesh.subMeshCount][]; for (int i = 0; i < array.Length; i++) { if ((int)mesh.GetTopology(i) == 0) { array[i] = ((IEnumerable<int>)mesh.GetIndices(i, true)).ToArray(); } } return array; } } internal sealed class GpuMeshReadback { private const int MaxBufferBytes = 25165824; private readonly int vertexCount; private readonly int stride; private readonly int positionOffset; private readonly int componentSize; private readonly int indexSize; private readonly VertexAttributeFormat format; private readonly SubMeshDescriptor[] submeshes; private byte[] vertexBytes; private byte[] indexBytes; private bool failed; private bool canceled; internal bool Done { get { if (!failed) { if (vertexBytes != null) { return indexBytes != null; } return false; } return true; } } internal GpuMeshReadback(Mesh mesh) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_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_0064: Expected I4, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Invalid comparison between Unknown and I4 //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) vertexCount = mesh.vertexCount; stride = mesh.GetVertexBufferStride(mesh.GetVertexAttributeStream((VertexAttribute)0)); positionOffset = mesh.GetVertexAttributeOffset((VertexAttribute)0); format = mesh.GetVertexAttributeFormat((VertexAttribute)0); VertexAttributeFormat val = format; int num; switch ((int)val) { case 0: num = 4; break; case 1: case 4: case 5: num = 2; break; default: throw new NotSupportedException($"Position format '{format}' is unsupported."); } componentSize = num; if (mesh.GetVertexAttributeDimension((VertexAttribute)0) < 3 || positionOffset < 0 || stride < positionOffset + componentSize * 3 || (long)stride * (long)vertexCount > 25165824) { throw new NotSupportedException("The mesh has an unsupported position stream."); } indexSize = (((int)mesh.indexFormat == 1) ? 4 : 2); submeshes = (SubMeshDescriptor[])(object)new SubMeshDescriptor[mesh.subMeshCount]; for (int i = 0; i < submeshes.Length; i++) { submeshes[i] = mesh.GetSubMesh(i); } try { Read(mesh.GetVertexBuffer(mesh.GetVertexAttributeStream((VertexAttribute)0)), delegate(byte[] data) { vertexBytes = data; }); Read(mesh.GetIndexBuffer(), delegate(byte[] data) { indexBytes = data; }); } catch { Cancel(); throw; } } internal void Cancel() { canceled = true; vertexBytes = (indexBytes = null); } private void Read(GraphicsBuffer buffer, Action<byte[]> store) { //IL_00be: Unknown result type (might be due to invalid IL or missing references) if (buffer == null) { throw new InvalidOperationException("Unity did not expose the mesh graphics buffer."); } try { long byteCount = (long)buffer.count * (long)buffer.stride; if (byteCount <= 0 || byteCount > 25165824) { throw new InvalidOperationException($"The graphics buffer is outside the {24} MiB readback limit."); } Action<AsyncGPUReadbackRequest> action = delegate(AsyncGPUReadbackRequest request) { try { if (!canceled) { if (((AsyncGPUReadbackRequest)(ref request)).hasError || ((AsyncGPUReadbackRequest)(ref request)).layerDataSize != byteCount) { failed = true; } else { IntPtr dataRaw = ((AsyncGPUReadbackRequest)(ref request)).GetDataRaw(0); if (dataRaw == IntPtr.Zero) { failed = true; } else { byte[] array = new byte[(int)byteCount]; Marshal.Copy(dataRaw, array, 0, array.Length); store(array); } } } } catch { failed = true; } finally { buffer.Dispose(); } }; AsyncGPUReadback.Request(buffer, (int)byteCount, 0, Action<AsyncGPUReadbackRequest>.op_Implicit(action)); } catch { buffer.Dispose(); throw; } } internal MeshSource Decode() { //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_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_00b6: Unknown result type (might be due to invalid IL or missing references) if (failed || vertexBytes == null || indexBytes == null || (long)vertexCount * (long)stride > vertexBytes.Length) { return null; } Vector3[] array = (Vector3[])(object)new Vector3[vertexCount]; int num = 0; int num2 = positionOffset; while (num < array.Length) { array[num] = new Vector3(ReadComponent(num2), ReadComponent(num2 + componentSize), ReadComponent(num2 + 2 * componentSize)); num++; num2 += stride; } int[][] array2 = new int[submeshes.Length][]; for (int i = 0; i < submeshes.Length; i++) { SubMeshDescriptor val = submeshes[i]; if ((int)((SubMeshDescriptor)(ref val)).topology != 0) { continue; } if (((SubMeshDescriptor)(ref val)).indexStart < 0 || ((SubMeshDescriptor)(ref val)).indexCount < 0 || ((long)((SubMeshDescriptor)(ref val)).indexStart + (long)((SubMeshDescriptor)(ref val)).indexCount) * indexSize > indexBytes.Length) { return null; } int[] array3 = new int[((SubMeshDescriptor)(ref val)).indexCount]; int num3 = ((SubMeshDescriptor)(ref val)).indexStart * indexSize; int baseVertex = ((SubMeshDescriptor)(ref val)).baseVertex; int num4 = 0; while (num4 < array3.Length) { int num5 = ((indexSize == 4) ? BinaryPrimitives.ReadInt32LittleEndian(indexBytes.AsSpan(num3, 4)) : BinaryPrimitives.ReadUInt16LittleEndian(indexBytes.AsSpan(num3, 2))); num5 += baseVertex; if ((uint)num5 >= (uint)vertexCount) { return null; } array3[num4] = num5; num4++; num3 += indexSize; } array2[i] = array3; } return new MeshSource(array, array2); } private float ReadComponent(int offset) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected I4, but got Unknown Span<byte> span = vertexBytes.AsSpan(offset, componentSize); VertexAttributeFormat val = format; return (int)val switch { 0 => BinaryPrimitives.ReadSingleLittleEndian(span), 1 => (float)BitConverter.UInt16BitsToHalf(BinaryPrimitives.ReadUInt16LittleEndian(span)), 5 => Math.Max(-1f, (float)BinaryPrimitives.ReadInt16LittleEndian(span) / 32767f), 4 => (float)(int)BinaryPrimitives.ReadUInt16LittleEndian(span) / 65535f, _ => throw new InvalidOperationException("Unexpected vertex position format."), }; } } internal sealed class SnowContacts { private readonly Il2CppReferenceArray<Collider> nearby = new Il2CppReferenceArray<Collider>(1024L); private readonly Il2CppStructArray<RaycastHit> hits = new Il2CppStructArray<RaycastHit>(16L); private readonly Dictionary<int, Vector3> lastContact = new Dictionary<int, Vector3>(); private readonly HashSet<int> seen = new HashSet<int>(); private int count; private int cursor; private float refreshAt; internal void Reset() { ArrayClear(); lastContact.Clear(); seen.Clear(); count = (cursor = 0); refreshAt = 0f; } private void ArrayClear() { for (int i = 0; i < count; i++) { ((Il2CppArrayBase<Collider>)(object)nearby)[i] = null; } } internal void Update(Vector3 player, Collider steppingBall, SnowCoverage coverage, WinterSettings settings) { //IL_0049: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_018d: 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_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: 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_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: 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_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) if (!settings.Enabled.Value || !settings.Compression.Value || !coverage.ReadyForContacts) { return; } float unscaledTime = Time.unscaledTime; if (cursor >= count && unscaledTime >= refreshAt) { ArrayClear(); count = Physics.OverlapSphereNonAlloc(player, 18f, nearby, -1, (QueryTriggerInteraction)1); cursor = 0; refreshAt = unscaledTime + 0.22f; if (lastContact.Count > 2048) { lastContact.Clear(); } seen.Clear(); } Vector3 val2 = default(Vector3); for (int num = Math.Min(count, cursor + 28); cursor < num; cursor++) { Collider val = ((Il2CppArrayBase<Collider>)(object)nearby)[cursor]; if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val == (Object)(object)steppingBall || !val.enabled || val is TerrainCollider || ((Object)((Component)val).gameObject).name == "BoneWinter ice sheet") { continue; } int instanceID = ((Object)val).GetInstanceID(); if (!seen.Add(instanceID)) { continue; } Bounds bounds = val.bounds; Vector3 extents = ((Bounds)(ref bounds)).extents; if (extents.y < 0.005f || extents.x > 3f || extents.z > 3f || extents.y > 3f) { continue; } ((Vector3)(ref val2))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).min.y, ((Bounds)(ref bounds)).center.z); if (lastContact.TryGetValue(instanceID, out var value)) { Vector3 val3 = value - val2; if (((Vector3)(ref val3)).sqrMagnitude < 0.0144f) { continue; } } Rigidbody attachedRigidbody = val.attachedRigidbody; if (TryFindSupport(val, val2, out var contact)) { Vector3 forward = ((extents.x > extents.z) ? Vector3.right : Vector3.forward); float num2 = settings.CompressionDepth.Value; if (Object.op_Implicit((Object)(object)attachedRigidbody)) { num2 *= Mathf.Clamp(0.8f + Mathf.Log10(Mathf.Max(1f, attachedRigidbody.mass)) * 0.3f, 0.8f, 1.35f); } if (coverage.StampContact(contact, forward, num2, Mathf.Clamp(Mathf.Max(extents.x, extents.z), 0.045f, 1.25f), Mathf.Clamp(Mathf.Min(extents.x, extents.z), 0.04f, 1.25f))) { lastContact[instanceID] = val2; } } } } internal bool TryFindSupport(Collider collider, Vector3 bottom, out Vector3 contact) { //IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_007a: 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_00bd: Unknown result type (might be due to invalid IL or missing references) contact = default(Vector3); float num = float.PositiveInfinity; int num2 = Physics.RaycastNonAlloc(bottom + Vector3.up * 0.025f, Vector3.down, hits, 0.14f, -1, (QueryTriggerInteraction)1); for (int i = 0; i < num2; i++) { RaycastHit val = ((Il2CppArrayBase<RaycastHit>)(object)hits)[i]; Collider collider2 = ((RaycastHit)(ref val)).collider; if (Object.op_Implicit((Object)(object)collider2) && !((Object)(object)collider2 == (Object)(object)collider) && !Object.op_Implicit((Object)(object)collider2.attachedRigidbody) && !(((RaycastHit)(ref val)).normal.y < 0.2f) && !(((Object)((Component)collider2).gameObject).name == "BoneWinter ice sheet") && !(((RaycastHit)(ref val)).distance >= num)) { num = ((RaycastHit)(ref val)).distance; contact = ((RaycastHit)(ref val)).point; } } return float.IsFinite(num); } } internal sealed class SnowCoverage { private readonly record struct BatchKey(int Mesh, int Root, int Scene); private sealed class StaticBatch { private sealed class Member { internal readonly Bounds Bounds; internal readonly bool Eligible; internal readonly bool[] Excluded; internal int NextMaterial; internal Member(Bounds bounds, bool eligible, bool[] excluded) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) Bounds = bounds; Eligible = eligible; Excluded = excluded; } } private readonly List<Member> members = new List<Member>(); private bool allEligible = true; internal bool Processed; internal Matrix4x4 WorldMatrix { get; } internal StaticBatch(Transform root) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) WorldMatrix = (Object.op_Implicit((Object)(object)root) ? root.localToWorldMatrix : Matrix4x4.identity); } internal void Add(MeshRenderer renderer, bool eligible) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) Il2CppReferenceArray<Material> sharedMaterials = ((Renderer)renderer).sharedMaterials; bool[] array = new bool[((Il2CppArrayBase<Material>)(object)sharedMaterials)?.Length ?? 0]; for (int i = 0; i < array.Length; i++) { array[i] = IsLiquidOrEffect(sharedMaterials, i); } allEligible &= eligible && !array.Contains(value: true); members.Add(new Member(((Renderer)renderer).bounds, eligible, array)); } internal void AddMissingBounds(CollisionSnowSurface fallback) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) foreach (Member member in members) { if (member.Eligible && (member.Excluded.Length == 0 || member.Excluded.Contains(value: false))) { fallback.AddMissing(member.Bounds); } } } internal bool ShouldCover(Bounds localBounds) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_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_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_0074: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0116: 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_0119: 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_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) if (allEligible) { return true; } Matrix4x4 worldMatrix = WorldMatrix; Vector3 val = ((Matrix4x4)(ref worldMatrix)).MultiplyPoint3x4(((Bounds)(ref localBounds)).center); Vector3 extents = ((Bounds)(ref localBounds)).extents; worldMatrix = WorldMatrix; Vector3 val2 = ((Matrix4x4)(ref worldMatrix)).MultiplyVector(new Vector3(extents.x, 0f, 0f)); worldMatrix = WorldMatrix; Vector3 val3 = ((Matrix4x4)(ref worldMatrix)).MultiplyVector(new Vector3(0f, extents.y, 0f)); worldMatrix = WorldMatrix; Vector3 val4 = ((Matrix4x4)(ref worldMatrix)).MultiplyVector(new Vector3(0f, 0f, extents.z)); Vector3 val5 = default(Vector3); ((Vector3)(ref val5))..ctor(Mathf.Abs(val2.x) + Mathf.Abs(val3.x) + Mathf.Abs(val4.x), Mathf.Abs(val2.y) + Mathf.Abs(val3.y) + Mathf.Abs(val4.y), Mathf.Abs(val2.z) + Mathf.Abs(val3.z) + Mathf.Abs(val4.z)); Vector3 val6 = val - val5; Vector3 val7 = val + val5; Member member = null; float num = float.PositiveInfinity; foreach (Member member2 in members) { Bounds bounds = member2.Bounds; ((Bounds)(ref bounds)).Expand(0.04f); if (((Bounds)(ref bounds)).Contains(val6) && ((Bounds)(ref bounds)).Contains(val7)) { Bounds bounds2 = member2.Bounds; Vector3 val8 = ((Bounds)(ref bounds2)).center - val; float sqrMagnitude = ((Vector3)(ref val8)).sqrMagnitude; bounds2 = member2.Bounds; val8 = ((Bounds)(ref bounds2)).extents - val5; float num2 = sqrMagnitude + ((Vector3)(ref val8)).sqrMagnitude; if (num2 < num) { member = member2; num = num2; } } } if (member == null || !member.Eligible) { return false; } int val9 = member.NextMaterial++; if (member.Excluded.Length != 0) { return !member.Excluded[Math.Min(val9, member.Excluded.Length - 1)]; } return true; } } private readonly record struct TaperVertex(Vector3 Point, float Depth); private readonly record struct TaperSide(Vector3 Start, Vector3 Normal) { internal float Distance(Vector3 point) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) return Vector3.Dot(point - Start, Normal); } } private sealed class SnowChunk { internal readonly Vector3 Origin; internal readonly List<Vector3> Vertices = new List<Vector3>(); internal readonly List<Vector3> Normals = new List<Vector3>(); internal readonly List<Color32> Colors = new List<Color32>(); internal SnowChunk(Vector3 origin) { //IL_0028: 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) Origin = origin; } internal void Triangle(Vector3 a, Vector3 b, Vector3 c, Vector3 normal, float alphaA, float alphaB, float alphaC) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0034: 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_004b: 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_0065: 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_0086: 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) Vertices.Add(a - Origin); Vertices.Add(b - Origin); Vertices.Add(c - Origin); Normals.Add(normal); Normals.Add(normal); Normals.Add(normal); Colors.Add(CoverageColor(alphaA)); Colors.Add(CoverageColor(alphaB)); Colors.Add(CoverageColor(alphaC)); } private static Color32 CoverageColor(float alpha) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) return new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)MathF.Round(alpha * 255f)); } internal void Clear() { Vertices.Clear(); Normals.Clear(); Colors.Clear(); } } private readonly record struct Edge(Vector3 A, Vector3 B, Vector3 Normal); private readonly record struct Surface(Vector3 A, Vector3 B, Vector3 C, Vector3 Normal, int RoofId); private readonly record struct SnowSample(Vector3 Point, bool Covered, float Depth); private readonly struct EdgeKey : IEquatable<EdgeKey> { private readonly Vector3Int a; private readonly Vector3Int b; internal EdgeKey(Vector3 first, Vector3 second) { //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_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) a = Vector3Int.RoundToInt(first * 1000f); b = Vector3Int.RoundToInt(second * 1000f); } public bool Equals(EdgeKey other) { //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_0027: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) if (!(a == other.a) || !(b == other.b)) { if (a == other.b) { return b == other.a; } return false; } return true; } public override bool Equals(object obj) { if (obj is EdgeKey other) { return Equals(other); } return false; } public override int GetHashCode() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) return ((object)a/*cast due to .constrained prefix*/).GetHashCode() ^ ((object)b/*cast due to .constrained prefix*/).GetHashCode(); } } private const int MaxChunkVertices = 12000; private const float ChunkSize = 24f; private readonly Instance log; private readonly Stopwatch frame = new Stopwatch(); private const int MaxCollisionTriangles = 100000; private readonly List<SnowImpressionPatch> meshes = new List<SnowImpressionPatch>(); private readonly Queue<SnowImpressionPatch> dirty = new Queue<SnowImpressionPatch>(); private readonly HashSet<SnowImpressionPatch> queued = new HashSet<SnowImpressionPatch>(); private readonly HashSet<SnowImpressionPatch> pressed = new HashSet<SnowImpressionPatch>(); private readonly Dictionary<int, GpuMeshReadback> readbacks = new Dictionary<int, GpuMeshReadback>(); private GameObject root; private IEnumerator generation; private CoverageOptions options; private float minUp; private Material material; private int triangleCount; private int skippedMeshes; private int failedMeshes; private bool usedFallback; private readonly List<TaperSide> taper = new List<TaperSide>(3); private const float EdgeWidth = 0.16f; internal bool ReadyForContacts { get { if (generation == null && Object.op_Implicit((Object)(object)root)) { return meshes.Count > 0; } return false; } } internal bool NeedsNewFallbackRegion { get { if (generation == null && Object.op_Implicit((Object)(object)root)) { if (skippedMeshes <= 0) { return usedFallback; } return true; } return false; } } private bool OutOfTime => frame.Elapsed.TotalMilliseconds >= (double)options.FrameBudget; internal SnowCoverage(Instance log) { this.log = log; } internal void Generate(Material snow, CoverageOptions settings, Vector3? playerPosition) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_0061: 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) Clear(); if (Object.op_Implicit((Object)(object)snow)) { material = snow; options = settings; minUp = Mathf.Cos(settings.Angle * ((float)Math.PI / 180f)) + 1E-06f; root = new GameObject("BoneWinter snow coverage"); generation = Build((Vector3)(((??)playerPosition) ?? Vector3.zero), playerPosition); } } internal void Update() { if (generation == null) { if (dirty.TryDequeue(out var result)) { queued.Remove(result); result.Rebuild(); } return; } frame.Restart(); try { if (!generation.MoveNext()) { generation = null; } } catch (Exception value) { log.Error($"Snow generation stopped: {value}"); Clear(); } } internal void Clear() { (generation as IDisposable)?.Dispose(); generation = null; CancelReadbacks(); if (Object.op_Implicit((Object)(object)root)) { root.SetActive(false); Object.Destroy((Object)(object)root); } foreach (SnowImpressionPatch mesh in meshes) { mesh.Destroy(); } root = null; meshes.Clear(); dirty.Clear(); queued.Clear(); pressed.Clear(); } internal bool Stamp(Vector3 contact, Vector3 forward, float depth) { //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) return StampContact(contact, forward, depth, 0.158f, 0.092f); } internal bool StampContact(Vector3 contact, Vector3 forward, float depth, float length, float width) { //IL_003a: 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) if (!ReadyForContacts || depth <= 0f || dirty.Count > 12) { return false; } bool result = false; foreach (SnowImpressionPatch mesh in meshes) { if (mesh.Stamp(contact, forward, depth, options.Thickness, length, width)) { result = true; pressed.Add(mesh); Queue(mesh); } } return result; } internal void ClearImpressions() { foreach (SnowImpressionPatch item in pressed) { if (item.Reset()) { Queue(item); } } pressed.Clear(); } private void Queue(SnowImpressionPatch patch) { if (queued.Add(patch)) { dirty.Enqueue(patch); } } private void CancelReadbacks() { foreach (GpuMeshReadback value in readbacks.Values) { value.Cancel(); } readbacks.Clear(); } private IEnumerator Build(Vector3 origin, Vector3? collisionFocus) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SnowCoverage snowCoverage = this; SnowCoverage snowCoverage2 = this; SnowCoverage snowCoverage3 = this; int num = 0; snowCoverage3.failedMeshes = 0; snowCoverage.triangleCount = (snowCoverage2.skippedMeshes = num); usedFallback = false; taper.Clear(); Dictionary<Vector3Int, SnowChunk> chunks = new Dictionary<Vector3Int, SnowChunk>(); SnowShelter shelter = (options.PreventShelteredSnow ? new SnowShelter(options.Clearance, options.RoofRange, options.Feather) : null); List<Surface> surfaces = new List<Surface>(); Dictionary<EdgeKey, Edge> edges = new Dictionary<EdgeKey, Edge>(); List<Edge> borders = (options.EdgeSkirts ? new List<Edge>() : null); CollisionSnowSurface collisionFallback = new CollisionSnowSurface(); HashSet<int> noSnow = new HashSet<int>(); foreach (LODGroup item4 in Object.FindObjectsOfType<LODGroup>()) { if (!Object.op_Implicit((Object)(object)item4)) { continue; } Il2CppReferenceArray<LOD> lODs = item4.GetLODs(); HashSet<int> hashSet = new HashSet<int>(); for (int i = 0; i < ((Il2CppArrayBase<LOD>)(object)lODs).Length; i++) { foreach (Renderer item5 in (Il2CppArrayBase<Renderer>)(object)((Il2CppArrayBase<LOD>)(object)lODs)[i].renderers) { if (Object.op_Implicit((Object)(object)item5)) { int instanceID = ((Object)item5).GetInstanceID(); if (i == 0) { hashSet.Add(instanceID); } else if (!hashSet.Contains(instanceID)) { noSnow.Add(instanceID); } } } } if (OutOfTime) { yield return null; } } Dictionary<BatchKey, StaticBatch> batches = new Dictionary<BatchKey, StaticBatch>(); List<(MeshFilter Filter, MeshRenderer Renderer, StaticBatch Batch, float Distance)> candidates = new List<(MeshFilter, MeshRenderer, StaticBatch, float)>(); GameObject heldLeft = Player.GetObjectInHand(Player.LeftHand); GameObject heldRight = Player.GetObjectInHand(Player.RightHand); foreach (MeshFilter item6 in Object.FindObjectsOfType<MeshFilter>(true)) { if (Object.op_Implicit((Object)(object)item6)) { MeshRenderer component = ((Component)item6).GetComponent<MeshRenderer>(); if (Object.op_Implicit((Object)(object)component)) { bool flag = ((Component)item6).gameObject.activeInHierarchy && ((Renderer)component).enabled && !((Renderer)component).forceRenderingOff && !noSnow.Contains(((Object)component).GetInstanceID()) && IsEnvironment((Component)(object)item6, heldLeft, heldRight); StaticBatch value = null; Mesh val = (((Renderer)component).isPartOfStaticBatch ? item6.sharedMesh : null); if (Object.op_Implicit((Object)(object)val)) { Transform staticBatchRootTransform = ((Renderer)component).staticBatchRootTransform; int instanceID2 = ((Object)val).GetInstanceID(); int num2 = (Object.op_Implicit((Object)(object)staticBatchRootTransform) ? ((Object)staticBatchRootTransform).GetInstanceID() : 0); Scene scene = ((Component)item6).gameObject.scene; BatchKey key = new BatchKey(instanceID2, num2, ((Scene)(ref scene)).handle); if (!batches.TryGetValue(key, out value)) { batches.Add(key, value = new StaticBatch(staticBatchRootTransform)); } value.Add(component, flag); } if (flag) { StaticBatch item = value; Bounds bounds = ((Renderer)component).bounds; candidates.Add((item6, component, item, ((Bounds)(ref bounds)).SqrDistance(origin))); } } } if (OutOfTime) { yield return null; } } candidates.Sort(((MeshFilter Filter, MeshRenderer Renderer, StaticBatch Batch, float Distance) left, (MeshFilter Filter, MeshRenderer Renderer, StaticBatch Batch, float Distance) right) => left.Distance.CompareTo(right.Distance)); Dictionary<int, MeshSource> readCache = new Dictionary<int, MeshSource>(); HashSet<int> rejected = new HashSet<int>(); bool gpuSupported = SystemInfo.supportsAsyncGPUReadback; int recovered = 0; long cachedBytes = 0L; for (int candidate = 0; candidate < candidates.Count; candidate++) { var (filter, renderer, batch, _) = candidates[candidate]; if (!Object.op_Implicit((Object)(object)filter) || !((Component)filter).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)renderer) || !((Renderer)renderer).enabled) { continue; } if (batch != null) { if (batch.Processed) { continue; } batch.Processed = true; } Mesh mesh = filter.sharedMesh; if (!Object.op_Implicit((Object)(object)mesh)) { continue; } int id = ((Object)mesh).GetInstanceID(); if (rejected.Contains(id)) { skippedMeshes++; AddMissingBounds(collisionFallback, renderer, batch); continue; } if (!readCache.TryGetValue(id, out var source)) { if (mesh.isReadable) { try { source = new MeshSource(mesh); } catch (Exception error) { FailMesh(mesh, error); rejected.Add(id); } } else if (gpuSupported) { for (int num3 = candidate; num3 < Math.Min(candidates.Count, candidate + 48) && (num3 <= candidate || readbacks.Count < 6); num3++) { MeshFilter item2 = candidates[num3].Filter; Mesh val2 = (Object.op_Implicit((Object)(object)item2) ? item2.sharedMesh : null); if (!Object.op_Implicit((Object)(object)val2) || val2.isReadable) { continue; } int instanceID3 = ((Object)val2).GetInstanceID(); if (!readbacks.ContainsKey(instanceID3) && !rejected.Contains(instanceID3) && !readCache.ContainsKey(instanceID3)) { try { readbacks.Add(instanceID3, new GpuMeshReadback(val2)); } catch (Exception error2) { rejected.Add(instanceID3); FailMesh(val2, error2); } } } if (readbacks.Remove(id, out var readback)) { float deadline = Time.realtimeSinceStartup + 2f; while (!readback.Done && Time.realtimeSinceStartup < deadline) { readbacks[id] = readback; yield return null; } readbacks.Remove(id); try { source = readback.Decode(); } catch (Exception error3) { FailMesh(mesh, error3); } readback.Cancel(); } if (source != null) { recovered++; } readback = null; } if (source == null) { skippedMeshes++; AddMissingBounds(collisionFallback, renderer, batch); rejected.Add(id); if (OutOfTime) { yield return null; } continue; } if (cachedBytes + source.Bytes <= 50331648) { readCache.Add(id, source); cachedBytes += source.Bytes; } } Matrix4x4 transform = batch?.WorldMatrix ?? ((Component)filter).transform.localToWorldMatrix; bool mirrored = ((Matrix4x4)(ref transform)).determinant < 0f; Vector3 translation = ((Matrix4x4)(ref transform)).MultiplyPoint3x4(Vector3.zero); Vector3[] world = (Vector3[])(object)new Vector3[source.Vertices.Length]; for (int i2 = 0; i2 < world.Length; i2++) { world[i2] = ((Matrix4x4)(ref transform)).MultiplyVector(source.Vertices[i2]); if ((i2 & 0x1FF) == 0 && OutOfTime) { yield return null; } } Il2CppReferenceArray<Material> materials = ((batch == null) ? ((Renderer)renderer).sharedMaterials : null); for (int i2 = 0; i2 < source.Indices.Length; i2++) { int[] indices = source.Indices[i2]; if (indices == null) { continue; } bool num4; if (batch != null) { SubMeshDescriptor subMesh = mesh.GetSubMesh(i2); num4 = !batch.ShouldCover(((SubMeshDescriptor)(ref subMesh)).bounds); } else { num4 = IsLiquidOrEffect(materials, i2); } if (num4) { continue; } for (int i3 = 0; i3 + 2 < indices.Length; i3 += 3) { Vector3 a = world[indices[i3]]; Vector3 b = world[indices[i3 + ((!mirrored) ? 1 : 2)]]; Vector3 c = world[indices[i3 + (mirrored ? 1 : 2)]]; CollectSurface(chunks, shelter, surfaces, a, b, c, edges, translation); if ((i3 & 0x7F) == 0 && OutOfTime) { yield return null; } } } if (OutOfTime) { yield return null; } source = null; } CancelReadbacks(); foreach (Terrain item7 in Object.FindObjectsOfType<Terrain>()) { if (!Object.op_Implicit((Object)(object)item7) || !((Behaviour)item7).enabled || !item7.drawHeightmap) { continue; } TerrainData data = item7.terrainData; if (!Object.op_Implicit((Object)(object)data)) { continue; } Vector3 translation = item7.GetPosition(); int candidate = data.heightmapResolution - 1; if (candidate < 1) { continue; } int id = Mathf.Max(1, Mathf.CeilToInt((float)candidate / 512f)); Vector3 scale = data.heightmapScale; for (int i2 = 0; i2 < candidate; i2 += id) { int i3 = Mathf.Min(i2 + id, candidate); for (int x = 0; x < candidate; x += id) { int num5 = Mathf.Min(x + id, candidate); if (!data.IsHole(Mathf.Min(candidate - 1, (x + num5) / 2), Mathf.Min(candidate - 1, (i2 + i3) / 2))) { Vector3 a2 = translation + new Vector3((float)x * scale.x, data.GetHeight(x, i2), (float)i2 * scale.z); Vector3 b2 = translation + new Vector3((float)x * scale.x, data.GetHeight(x, i3), (float)i3 * scale.z); Vector3 val3 = translation + new Vector3((float)num5 * scale.x, data.GetHeight(num5, i2), (float)i2 * scale.z); Vector3 c2 = translation + new Vector3((float)num5 * scale.x, data.GetHeight(num5, i3), (float)i3 * scale.z); CollectSurface(chunks, shelter, surfaces, a2, b2, val3, edges, Vector3.zero); CollectSurface(chunks, shelter, surfaces, val3, b2, c2, edges, Vector3.zero); } if ((x & 0xF) == 0 && OutOfTime) { yield return null; } } } } int fallbackSurfaces = 0; bool colliderOnly = surfaces.Count == 0 || (collisionFocus.HasValue && !surfaces.Any((Surface face) => face.Normal.y > 0.35f && DistanceToFaceBounds(face, origin) < 100f)); if (colliderOnly || collisionFallback.HasMissingMeshes || (shelter != null && options.UseColliders)) { Il2CppArrayBase<Collider> val4 = Object.FindObjectsOfType<Collider>(); IEnumerable<Collider> enumerable2; if ((!colliderOnly && !collisionFallback.HasMissingMeshes) || !collisionFocus.HasValue) { IEnumerable<Collider> enumerable = (IEnumerable<Collider>)val4; enumerable2 = enumerable; } else { IEnumerable<Collider> enumerable = ((IEnumerable<Collider>)val4).OrderBy(delegate(Collider val5) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)val5)) { return float.PositiveInfinity; } Bounds bounds2 = val5.bounds; return ((Bounds)(ref bounds2)).SqrDistance(origin); }); enumerable2 = enumerable; } IEnumerable<Collider> enumerable3 = enumerable2; foreach (Collider item8 in enumerable3) { if (Object.op_Implicit((Object)(object)item8) && item8.enabled && !item8.isTrigger && !Object.op_Implicit((Object)(object)item8.attachedRigidbody) && ((Object)((Component)item8).gameObject).name != "BoneWinter ice sheet" && IsEnvironment((Component)(object)item8, heldLeft, heldRight)) { if (shelter != null && options.UseColliders) { shelter.AddCollider(item8); } if ((colliderOnly || collisionFallback.HasMissingMeshes) && fallbackSurfaces < 100000 && ((Object)(object)((Il2CppObjectBase)item8).TryCast<TerrainCollider>() == (Object)null || !Object.op_Implicit((Object)(object)((Component)item8).GetComponent<Terrain>()))) { foreach (CollisionSnowSurface.Triangle item9 in collisionFallback.Reconstruct(item8, minUp, collisionFocus, colliderOnly)) { if (item9.Valid) { CollectSurface(chunks, shelter, surfaces, item9.A, item9.B, item9.C, edges, Vector3.zero); fallbackSurfaces++; if (fallbackSurfaces == 100000) { break; } } if (OutOfTime) { yield return null; } } } } if (OutOfTime) { yield return null; } } } usedFallback = fallbackSurfaces > 0 || colliderOnly; if (shelter != null) { foreach (int item10 in shelter.SortColumns()) { _ = item10; if (OutOfTime) { yield return null; } } } HashSet<EdgeKey> drops = new HashSet<EdgeKey>(); foreach (var (item3, edge2) in edges) { if (IsDrop(edge2)) { drops.Add(item3); } else { borders?.Add(edge2); } if (OutOfTime) { yield return null; } } foreach (int item11 in BuildSheltered(chunks, shelter, surfaces, borders, drops, origin)) { _ = item11; yield return null; } foreach (SnowChunk value2 in chunks.Values) { Publish(value2); if (OutOfTime) { yield return null; } } log.Msg($"Snow coverage generated: {triangleCount:N0} surface triangles in {meshes.Count:N0} chunks. Recovered {recovered:N0} GPU meshes and sampled {fallbackSurfaces:N0} collision triangles. {skippedMeshes:N0} visual mesh instances were unavailable ({failedMeshes:N0} read errors)."); } private static void AddMissingBounds(CollisionSnowSurface fallback, MeshRenderer renderer, StaticBatch batch) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) if (batch == null) { fallback.AddMissing(((Renderer)renderer).bounds); } else { batch.AddMissingBounds(fallback); } } private void FailMesh(Mesh mesh, Exception error) { if (++failedMeshes <= 3) { log.Warning("Could not read mesh '" + ((Object)mesh).name + "': " + error.GetBaseException().Message); } } private static bool IsEnvironment(Component component, GameObject heldLeft, GameObject heldRight) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) GameObject gameObject = component.gameObject; Scene scene = gameObject.scene; if (!((Scene)(ref scene)).IsValid() || !((Scene)(ref scene)).isLoaded || ((Scene)(ref scene)).name == "DontDestroyOnLoad") { return false; } if (Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<Rigidbody>()) || Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<RigManager>())) { return false; } if (!gameObject.isStatic && (Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<Animator>()) || Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<MarrowEntity>()) || Object.op_Implicit((Object)(object)gameObject.GetComponentInParent<Poolee>()))) { return false; } Transform transform = component.transform; if (!Object.op_Implicit((Object)(object)heldLeft) || !transform.IsChildOf(heldLeft.transform)) { if (Object.op_Implicit((Object)(object)heldRight)) { return !transform.IsChildOf(heldRight.transform); } return true; } return false; } private static bool IsLiquidOrEffect(Il2CppReferenceArray<Material> materials, int index) { if (materials == null || ((Il2CppArrayBase<Material>)(object)materials).Length == 0) { return false; } Material val = ((Il2CppArrayBase<Material>)(object)materials)[Math.Min(index, ((Il2CppArrayBase<Material>)(object)materials).Length - 1)]; if (!Object.op_Implicit((Object)(object)val)) { return false; } Shader shader = val.shader; string text = (Object.op_Implicit((Object)(object)shader) ? ((Object)shader).name : string.Empty); if (!text.Contains("Water", StringComparison.OrdinalIgnoreCase) && !text.Contains("Liquid", StringComparison.OrdinalIgnoreCase) && !text.Contains("Lava", StringComparison.OrdinalIgnoreCase) && !text.Contains("Particle", StringComparison.OrdinalIgnoreCase)) { return text.Contains("Decal", StringComparison.OrdinalIgnoreCase); } return true; } private void CollectSurface(Dictionary<Vector3Int, SnowChunk> chunks, SnowShelter shelter, List<Surface> surfaces, Vector3 a, Vector3 b, Vector3 c, Dictionary<EdgeKey, Edge> edges, Vector3 translation) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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_000b: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_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_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_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_0059: 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_005d: 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_006b: 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_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_0085: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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_00b9: Unknown result type (might be due to invalid IL or missing references) Vector3 val = Vector3.Cross(b - a, c - a); float magnitude = ((Vector3)(ref val)).magnitude; if (!float.IsFinite(magnitude) || magnitude < 1E-06f) { return; } a += translation; b += translation; c += translation; int roofId = shelter?.AddTriangle(a, b, c, val.y) ?? (-1); if (val.y > magnitude * minUp) { val /= magnitude; surfaces.Add(new Surface(a, b, c, val, roofId)); if (edges != null) { ToggleEdge(edges, a, b, val); ToggleEdge(edges, b, c, val); ToggleEdge(edges, c, a, val); } } } private static float DistanceToFaceBounds(Surface face, Vector3 point) { //IL_0004: 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_0017: 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_0031: Unknown result type (might be due to invalid IL or missing references) Bounds val = default(Bounds); ((Bounds)(ref val))..ctor(face.A, Vector3.zero); ((Bounds)(ref val)).Encapsulate(face.B); ((Bounds)(ref val)).Encapsulate(face.C); return ((Bounds)(ref val)).SqrDistance(point); } private IEnumerable<int> BuildSheltered(Dictionary<Vector3Int, SnowChunk> chunks, SnowShelter shelter, List<Surface> surfaces, List<Edge> borders, HashSet<EdgeKey> drops, Vector3 origin) { //IL_0034: 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) Stack<(Vector3 A, Vector3 B, Vector3 C, int Level)> faces = new Stack<(Vector3, Vector3, Vector3, int)>(); float spacingSquared = options.Resolution * options.Resolution; bool nearbyPublished = false; foreach (Surface surface in surfaces.OrderBy((Surface face) => DistanceToFaceBounds(face, origin))) { if (!nearbyPublished && DistanceToFaceBounds(surface, origin) > 576f) { nearbyPublished = true; foreach (SnowChunk value in chunks.Values) { Publish(value); if (OutOfTime) { yield return 0; } } } taper.Clear(); SetTaper(surface.A, surface.B, surface.C, drops); SetTaper(surface.B, surface.C, surface.A, drops); SetTaper(surface.C, surface.A, surface.B, drops); Vector2 slope = SurfaceSlope(surface.Normal); faces.Push((surface.A, surface.B, surface.C, 0)); (Vector3, Vector3, Vector3, int) result; while (faces.TryPop(out result)) { var (val, val2, val3, num) = result; switch (shelter?.Classify(val, val2, val3, surface.RoofId) ?? ShelterRegion.Open) { case ShelterRegion.Open: AddTop(chunks, val, val2, val3, surface.Normal, 1f, 1f, 1f); break; case ShelterRegion.Boundary: if (num < 8 && Math.Max(HorizontalDistanceSquared(val, val2), Math.Max(HorizontalDistanceSquared(val2, val3), HorizontalDistanceSquared(val3, val))) > spacingSquared) { Vector3 val4 = (val + val2) * 0.5f; Vector3 val5 = (val2 + val3) * 0.5f; Vector3 val6 = (val3 + val) * 0.5f; int item = num + 1; faces.Push((val, val4, val6, item)); faces.Push((val4, val2, val5, item)); faces.Push((val6, val5, val3, item)); faces.Push((val4, val5, val6, item)); } else { AddShelterLeaf(chunks, shelter, val, val2, val3, surface.Normal, slope); } break; } if (OutOfTime) { yield return 0; } } } taper.Clear(); if (borders == null) { yield break; } Stack<(Vector3 A, Vector3 B, int Level)> segments = new Stack<(Vector3, Vector3, int)>(); foreach (Edge border in borders) { Vector2 slope = SurfaceSlope(border.Normal); segments.Push((border.A, border.B, 0)); (Vector3, Vector3, int) result2; while (segments.TryPop(out result2)) { (Vector3, Vector3, int) tuple2 = result2; Vector3 item2 = tuple2.Item1; Vector3 item3 = tuple2.Item2; int item4 = tuple2.Item3; Vector3 val7 = (item2 + item3) * 0.5f; switch (shelter?.Classify(item2, item3, val7, -1) ?? ShelterRegion.Open) { case ShelterRegion.Open: AddSkirt(chunks, item2, item3, 1f, 1f); break; case ShelterRegion.Boundary: if (item4 < 8 && HorizontalDistanceSquared(item2, item3) > spacingSquared) { segments.Push((item2, val7, item4 + 1)); segments.Push((val7, item3, item4 + 1)); } else { SnowSample snowSample = Sample(shelter, val7, slope); AddShelteredSkirt(chunks, shelter, Sample(shelter, item2, slope), snowSample, slope); AddShelteredSkirt(chunks, shelter, snowSample, Sample(shelter, item3, slope), slope); } break; } if (OutOfTime) { yield return 0; } } } } private void AddShelterLeaf(Dictionary<Vector3Int, SnowChunk> chunks, SnowShelter shelter, Vector3 a, Vector3 b, Vector3 c, Vector3 normal, Vector2 slope) { //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_000b: 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_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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_00d6: Unknown result type (might be due to invalid IL or missing references) SnowSample snowSample = Sample(shelter, a, slope); SnowSample snowSample2 = Sample(shelter, b, slope); SnowSample snowSample3 = Sample(shelter, c, slope); SnowSample c2 = Sample(shelter, (a + b + c) / 3f, slope); float num = (snowSample.Depth + snowSample2.Depth + snowSample3.Depth) / 3f; if ((snowSample.Covered == snowSample2.Covered && snowSample2.Covered == snowSample3.Covered && snowSample3.Covered != c2.Covered) || (!c2.Covered && Math.Abs(c2.Depth - num) > 0.12f)) { ClipTop(chunks, shelter, snowSample, snowSample2, c2, normal, slope); ClipTop(chunks, shelter, snowSample2, snowSample3, c2, normal, slope); ClipTop(chunks, shelter, snowSample3, snowSample, c2, normal, slope); } else { ClipTop(chunks, shelter, snowSample, snowSample2, snowSample3, normal, slope); } } private void ClipTop(Dictionary<Vector3Int, SnowChunk> chunks, SnowShelter shelter, SnowSample a, SnowSample b, SnowSample c, Vector3 normal, Vector2 slope) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //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_008e: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: 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_013d: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0165: 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) switch ((a.Covered ? 1 : 0) + (b.Covered ? 1 : 0) + (c.Covered ? 1 : 0)) { case 0: AddTop(chunks, a.Point, b.Point, c.Point, normal, a.Depth, b.Depth, c.Depth); break; case 1: { if (b.Covered) { SnowSample snowSample7 = b; SnowSample snowSample8 = c; c = a; b = snowSample8; a = snowSample7; } else if (c.Covered) { SnowSample snowSample9 = c; SnowSample snowSample10 = a; c = b; b = snowSample10; a = snowSample9; } SnowSample snowSample11 = FindLip(shelter, b, a, slope); SnowSample snowSample12 = FindLip(shelter, c, a, slope); AddTop(chunks, snowSample11.Point, b.Point, c.Point, normal, snowSample11.Depth, b.Depth, c.Depth); AddTop(chunks, snowSample11.Point, c.Point, snowSample12.Point, normal, snowSample11.Depth, c.Depth, snowSample12.Depth); break; } case 2: { if (!b.Covered) { SnowSample snowSample = b; SnowSample snowSample2 = c; c = a; b = snowSample2; a = snowSample; } else if (!c.Covered) { SnowSample snowSample3 = c; SnowSample snowSample4 = a; c = b; b = snowSample4; a = snowSample3; } SnowSample snowSample5 = FindLip(shelter, a, b, slope); SnowSample snowSample6 = FindLip(shelter, a, c, slope); AddTop(chunks, a.Point, snowSample5.Point, snowSample6.Point, normal, a.Depth, snowSample5.Depth, snowSample6.Depth); break; } } } private void AddShelteredSkirt(Dictionary<Vector3Int, SnowChunk> chunks, SnowShelter shelter, SnowSample a, SnowSample b, Vector2 slope) { //IL_0021: 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_004c: 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) if (!a.Covered || !b.Covered) { if (a.Covered) { a = FindLip(shelter, b, a, slope); } if (b.Covered) { b = FindLip(shelter, a, b, slope); } AddSkirt(chunks, a.Point, b.Point, a.Depth, b.Depth); } } private SnowSample FindLip(SnowShelter shelter, SnowSample open, SnowSample covered, Vector2 slope) { //IL_0007: 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_0013: 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_0022: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i < 7; i++) { SnowSample snowSample = Sample(shelter, (open.Poi