Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ValheimRiftRelics v1.0.1
ValheimRiftRelics.dll
Decompiled 5 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using RiftMagic.Config; using RiftMagic.Items; using RiftMagic.Storage; using RiftMagic.Visuals; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: AssemblyCompany("ValheimRiftRelics")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+444f1d340408b7b4d3c57d59320601bd57220ea3")] [assembly: AssemblyProduct("ValheimRiftRelics")] [assembly: AssemblyTitle("ValheimRiftRelics")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace RiftMagic.Visuals { internal class BlinkTrail : MonoBehaviour { private struct Streak { internal LineRenderer Line; internal Vector3 Tail; internal Vector3 Head; internal float Alpha; internal float Width; } private const int StreakCount = 9; private const float Lifetime = 0.45f; private const float MinRadius = 0.08f; private const float MaxRadius = 0.55f; private const float MinWidth = 0.018f; private const float MaxWidth = 0.045f; private static readonly Color StreakColor = new Color(0.78f, 0.52f, 1f); private static readonly AnimationCurve StreakShape = new AnimationCurve((Keyframe[])(object)new Keyframe[3] { new Keyframe(0f, 0.15f), new Keyframe(0.6f, 1f), new Keyframe(1f, 0.35f) }); private Streak[] _streaks; private Light _light; private float _lightIntensity; private float _age; internal static void Spawn(Vector3 from, Vector3 to) { //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) //IL_0010: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_0047: 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_0060: 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) if ((Object)(object)Player.m_localPlayer == (Object)null) { return; } Vector3 val = to - from; if (!(((Vector3)(ref val)).sqrMagnitude < 0.25f)) { Material material = GetMaterial(); if (!((Object)(object)material == (Object)null)) { GameObject val2 = new GameObject("RM_BlinkTrail"); val2.transform.position = (from + to) * 0.5f; val2.AddComponent<BlinkTrail>().Build(from, to, material); } } } private void Build(Vector3 from, Vector3 to, Material material) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_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_0010: 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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: 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_0047: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0140: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) Vector3 val = to - from; float magnitude = ((Vector3)(ref val)).magnitude; Vector3 val2 = val / magnitude; Vector3 val3 = Vector3.Cross(val2, Vector3.up); if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f) { val3 = Vector3.Cross(val2, Vector3.right); } ((Vector3)(ref val3)).Normalize(); Vector3 val4 = Vector3.Cross(val3, val2); _streaks = new Streak[9]; for (int i = 0; i < 9; i++) { float num = Random.value * (float)Math.PI * 2f; float num2 = Random.Range(0.08f, 0.55f); Vector3 val5 = (val3 * Mathf.Cos(num) + val4 * Mathf.Sin(num)) * num2; float num3 = Random.Range(0f, 0.25f); float num4 = Random.Range(0.75f, 1f); float num5 = Random.Range(0.55f, 1f); Vector3 tail = from + val * num3 + val5; Vector3 head = from + val * num4 + val5 * num5; _streaks[i] = new Streak { Line = MakeLine(i, material, tail, head), Tail = tail, Head = head, Alpha = Random.Range(0.55f, 1f), Width = Random.Range(0.018f, 0.045f) }; } _light = ((Component)this).gameObject.AddComponent<Light>(); _light.type = (LightType)2; _light.color = StreakColor; _light.range = Mathf.Clamp(magnitude * 0.6f, 2f, 8f); _light.shadows = (LightShadows)0; _lightIntensity = 1.4f; _light.intensity = _lightIntensity; Apply(0f); } private LineRenderer MakeLine(int index, Material material, Vector3 tail, Vector3 head) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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) GameObject val = new GameObject("streak" + index); val.transform.SetParent(((Component)this).transform, false); LineRenderer obj = val.AddComponent<LineRenderer>(); obj.useWorldSpace = true; obj.positionCount = 2; obj.SetPosition(0, tail); obj.SetPosition(1, head); ((Renderer)obj).sharedMaterial = material; obj.textureMode = (LineTextureMode)0; obj.numCapVertices = 2; obj.widthCurve = StreakShape; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)obj).receiveShadows = false; return obj; } private void Update() { _age += Time.deltaTime; float num = _age / 0.45f; if (num >= 1f) { Object.Destroy((Object)(object)((Component)this).gameObject); } else { Apply(num); } } private void Apply(float t) { //IL_0046: 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_0058: 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_00e7: Unknown result type (might be due to invalid IL or missing references) float num = 1f - Mathf.SmoothStep(0f, 1f, t); Streak[] streaks = _streaks; for (int i = 0; i < streaks.Length; i++) { Streak streak = streaks[i]; if (!((Object)(object)streak.Line == (Object)null)) { streak.Line.SetPosition(0, Vector3.Lerp(streak.Tail, streak.Head, t * 0.85f)); streak.Line.widthMultiplier = streak.Width * (1f - 0.5f * t); float num2 = streak.Alpha * num; streak.Line.startColor = new Color(StreakColor.r, StreakColor.g, StreakColor.b, num2 * 0.1f); streak.Line.endColor = new Color(StreakColor.r, StreakColor.g, StreakColor.b, num2); } } if ((Object)(object)_light != (Object)null) { _light.intensity = _lightIntensity * num; } } private static Material GetMaterial() { return GlowMaterials.Additive("Blink trail", (Texture)(object)GlowMaterials.SoftEdge()); } } internal static class EyeGlow { internal static readonly Color Colour = new Color(0.72f, 0.4f, 1f); private static Texture2D _texture; internal static void Place(Transform eye, Vector3 position, float size, float inherited, Transform cam) { //IL_007d: 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_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_001c: 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_0065: 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_0046: 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_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)eye == (Object)null) { return; } if ((Object)(object)cam != (Object)null) { Vector3 val = cam.position - position; float magnitude = ((Vector3)(ref val)).magnitude; if (magnitude > 0.05f) { float num = Mathf.Min(size * 0.5f, magnitude * 0.5f); position += val / magnitude * num; size *= (magnitude - num) / magnitude; } eye.rotation = Quaternion.LookRotation(position - cam.position); } eye.position = position; float num2 = size / inherited; eye.localScale = new Vector3(num2, num2, num2); } internal static Texture2D Texture() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0086: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_texture != (Object)null) { return _texture; } _texture = new Texture2D(32, 32, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, hideFlags = (HideFlags)61 }; for (int i = 0; i < 32; i++) { for (int j = 0; j < 32; j++) { float num = ((float)j + 0.5f) / 32f * 2f - 1f; float num2 = ((float)i + 0.5f) / 32f * 2f - 1f; float num3 = Mathf.Clamp01(Mathf.Sqrt(num * num + num2 * num2)); Color val = Color.Lerp(Colour, Color.white, Mathf.Pow(1f - num3, 4f)); val.a = (1f - num3) * (1f - num3); _texture.SetPixel(j, i, val); } } _texture.Apply(); return _texture; } } internal static class GlowMaterials { private static readonly string[] AdditiveShaders = new string[7] { "Legacy Shaders/Particles/Additive", "Particles/Additive", "Mobile/Particles/Additive", "Sprites/Default", "Particles/Standard Unlit", "Unlit/Transparent", "Legacy Shaders/Particles/Alpha Blended" }; private static readonly string[] TransparentShaders = new string[4] { "Sprites/Default", "Particles/Standard Unlit", "Unlit/Transparent", "Legacy Shaders/Particles/Alpha Blended" }; private static readonly Dictionary<string, Material> Cache = new Dictionary<string, Material>(); private static Texture2D _white; private static Texture2D _softEdge; internal static Material Additive(string purpose, Texture texture) { return Build(purpose, texture, 3100, AdditiveShaders); } internal static Material Transparent(string purpose, Texture texture) { return Build(purpose, texture, 3000, TransparentShaders); } private static Material Build(string purpose, Texture texture, int queue, string[] shaders) { //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_003b: Expected O, but got Unknown //IL_007b: 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) if (Cache.TryGetValue(purpose, out var value) && (Object)(object)value != (Object)null) { return value; } Shader val = ShaderLookup.Find(purpose, shaders); if ((Object)(object)val == (Object)null) { return null; } Material val2 = new Material(val) { renderQueue = queue }; if (val2.HasProperty("_MainTex")) { val2.SetTexture("_MainTex", texture); } if (val2.HasProperty("_TintColor")) { val2.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f)); } if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Color.white); } Cache[purpose] = val2; return val2; } internal static void SetAlpha(Material material, float alpha) { //IL_003b: 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) if (!((Object)(object)material == (Object)null)) { alpha = Mathf.Clamp01(alpha); if (material.HasProperty("_TintColor")) { material.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f * alpha)); } if (material.HasProperty("_Color")) { material.SetColor("_Color", new Color(1f, 1f, 1f, alpha)); } } } internal static Texture2D White() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //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_0042: 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_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_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) if ((Object)(object)_white != (Object)null) { return _white; } _white = new Texture2D(2, 2, (TextureFormat)4, false) { hideFlags = (HideFlags)61 }; _white.SetPixels((Color[])(object)new Color[4] { Color.white, Color.white, Color.white, Color.white }); _white.Apply(); return _white; } internal static Texture2D SoftEdge() { //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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_0081: 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) if ((Object)(object)_softEdge != (Object)null) { return _softEdge; } _softEdge = new Texture2D(2, 32, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, hideFlags = (HideFlags)61 }; Color val = default(Color); for (int i = 0; i < 32; i++) { float num = ((float)i + 0.5f) / 32f * 2f - 1f; float num2 = Mathf.Clamp01(1f - num * num); num2 *= num2; ((Color)(ref val))..ctor(1f, 1f, 1f, num2); _softEdge.SetPixel(0, i, val); _softEdge.SetPixel(1, i, val); } _softEdge.Apply(); return _softEdge; } } internal static class RiftMotes { internal sealed class Palette { internal readonly string Name; internal readonly Color Deep; internal readonly Color Bright; internal readonly Color SparkEmission; internal Palette(string name, Color deep, Color bright, Color sparkEmission) { //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) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) Name = name; Deep = deep; Bright = bright; SparkEmission = sparkEmission; } } private struct Tuning { internal float PerSecond; internal float PerMetre; internal float Lifetime; internal float Size; internal float Gravity; } private const string SourceItem = "Demister"; private const string SourceBall = "demister_ball"; internal static readonly Palette Rift = new Palette("rift", new Color(0.55f, 0.2f, 1f), new Color(0.85f, 0.6f, 1f), new Color(0.6f, 0.18f, 1f) * 3.2f); private static readonly Dictionary<string, Tuning> Tunings = new Dictionary<string, Tuning> { ["embers"] = new Tuning { PerSecond = 2f, PerMetre = 0f, Lifetime = 2f, Size = 0.03f, Gravity = -0.03f }, ["sparcs_front"] = new Tuning { PerSecond = 0.5f, PerMetre = 1.2f, Lifetime = 0.6f, Size = 0.045f, Gravity = 0f } }; private static GameObject _holder; private static readonly Dictionary<Palette, List<GameObject>> Templates = new Dictionary<Palette, List<GameObject>>(); private static readonly Dictionary<Palette, Dictionary<Material, Material>> Recoloured = new Dictionary<Palette, Dictionary<Material, Material>>(); internal static void Attach(Transform parent, Bounds area, float rate, Palette palette = null) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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) if ((Object)(object)parent == (Object)null || rate <= 0f) { return; } foreach (GameObject item in Prepare(palette ?? Rift)) { GameObject obj = Object.Instantiate<GameObject>(item, parent, false); ((Object)obj).name = ((Object)item).name; obj.transform.localPosition = ((Bounds)(ref area)).center; obj.transform.localRotation = Quaternion.identity; obj.transform.localScale = Vector3.one; ParticleSystem component = obj.GetComponent<ParticleSystem>(); ShapeModule shape = component.shape; ((ShapeModule)(ref shape)).scale = Vector3.Max(((Bounds)(ref area)).size, Vector3.one * 0.01f); EmissionModule emission = component.emission; ((EmissionModule)(ref emission)).rateOverTimeMultiplier = ((EmissionModule)(ref emission)).rateOverTimeMultiplier * rate; ((EmissionModule)(ref emission)).rateOverDistanceMultiplier = ((EmissionModule)(ref emission)).rateOverDistanceMultiplier * rate; } } private static List<GameObject> Prepare(Palette palette) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) if (Templates.TryGetValue(palette, out var value)) { return value; } value = new List<GameObject>(); Templates[palette] = value; Transform val = FindBall(); if ((Object)(object)val == (Object)null) { Logger.LogWarning((object)("Could not find the Wisplight's glow to copy; nothing will give off " + palette.Name + " motes.")); return value; } if ((Object)(object)_holder == (Object)null) { _holder = new GameObject("RM_RiftMotes"); _holder.SetActive(false); Object.DontDestroyOnLoad((Object)(object)_holder); } ParticleSystem[] componentsInChildren = ((Component)val).GetComponentsInChildren<ParticleSystem>(true); foreach (ParticleSystem val2 in componentsInChildren) { if (!Tunings.TryGetValue(((Object)val2).name, out var value2)) { continue; } GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, _holder.transform, false); ((Object)val3).name = "RM_mote_" + palette.Name + "_" + ((Object)val2).name; foreach (Transform item in val3.transform) { Object.Destroy((Object)(object)((Component)item).gameObject); } val3.SetActive(true); Retune(val3.GetComponent<ParticleSystem>(), value2, palette); ParticleSystemRenderer component = val3.GetComponent<ParticleSystemRenderer>(); if ((Object)(object)component != (Object)null) { ((Renderer)component).sharedMaterials = ((Renderer)component).sharedMaterials.Select((Material m) => Recolour(m, palette)).ToArray(); } value.Add(val3); } Logger.LogInfo((object)((value.Count > 0) ? ("Motes copied from the Wisplight: " + string.Join(", ", value.Select((GameObject t) => ((Object)t).name).ToArray()) + ".") : ("The Wisplight's glow has no ember or spark systems to copy; nothing will give off " + palette.Name + " motes."))); return value; } private static Transform FindBall() { GameObject prefab = PrefabManager.Instance.GetPrefab("Demister"); ItemDrop val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<ItemDrop>() : null); SE_Demister val2 = (SE_Demister)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val2 != (Object)null && (Object)(object)val2.m_ballPrefab != (Object)null) { return val2.m_ballPrefab.transform; } GameObject prefab2 = PrefabManager.Instance.GetPrefab("demister_ball"); if (!((Object)(object)prefab2 != (Object)null)) { return null; } return prefab2.transform; } private static void Retune(ParticleSystem ps, Tuning tuning, Palette palette) { //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_0037: 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_005b: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_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_0094: 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_00b1: 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_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Invalid comparison between Unknown and I4 //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014d: 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_015c: 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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01ad: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) MainModule main = ps.main; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1; ((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).prewarm = false; ((MainModule)(ref main)).playOnAwake = true; ((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(tuning.Lifetime); ((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(tuning.Size); ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(tuning.Gravity); ((MainModule)(ref main)).startColor = new MinMaxGradient(palette.Deep, palette.Bright); EmissionModule emission = ps.emission; ((EmissionModule)(ref emission)).enabled = true; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(tuning.PerSecond); ((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(tuning.PerMetre); ShapeModule shape = ps.shape; ((ShapeModule)(ref shape)).enabled = true; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5; ((ShapeModule)(ref shape)).position = Vector3.zero; ((ShapeModule)(ref shape)).rotation = Vector3.zero; ((ShapeModule)(ref shape)).sphericalDirectionAmount = 1f; ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime; if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled) { MinMaxGradient color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color; object obj; if ((int)((MinMaxGradient)(ref color)).mode != 1) { obj = null; } else { color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color; obj = ((MinMaxGradient)(ref color)).gradient; } Gradient val = (Gradient)obj; Gradient val2 = new Gradient(); val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) }, (GradientAlphaKey[])((val != null && val.alphaKeys.Length != 0) ? ((Array)val.alphaKeys) : ((Array)new GradientAlphaKey[3] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 0.6f), new GradientAlphaKey(0f, 1f) }))); ((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val2); } } private static Material Recolour(Material source, Palette palette) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)source == (Object)null) { return null; } if (!Recoloured.TryGetValue(palette, out var value)) { value = (Recoloured[palette] = new Dictionary<Material, Material>()); } if (value.TryGetValue(source, out var value2)) { return value2; } value2 = new Material(source) { name = ((Object)source).name + " (" + palette.Name + ")" }; if (value2.HasProperty("_EmissionColor")) { value2.SetColor("_EmissionColor", palette.SparkEmission); } value[source] = value2; return value2; } } internal static class ShaderLookup { private static readonly HashSet<string> Logged = new HashSet<string>(); internal static Shader Find(string purpose, params string[] candidates) { foreach (string text in candidates) { Shader val = Shader.Find(text); if (!((Object)(object)val == (Object)null)) { if (Logged.Add(purpose)) { Logger.LogInfo((object)(purpose + ": using shader '" + text + "'.")); } return val; } } if (Logged.Add(purpose)) { Logger.LogWarning((object)(purpose + ": none of [" + string.Join(", ", candidates) + "] survived the build.")); } return null; } } internal static class TrailFx { private const string TrailRpc = "RM_RiftTrail"; private const float SightRange = 150f; internal static void Register() { if (ZRoutedRpc.instance == null) { return; } try { ZRoutedRpc.instance.Register<Vector3, Vector3>("RM_RiftTrail", (Action<long, Vector3, Vector3>)OnTrail); } catch (ArgumentException) { } } internal static void Trail(Vector3 from, Vector3 to) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (ZRoutedRpc.instance == null) { BlinkTrail.Spawn(from, to); return; } ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RM_RiftTrail", new object[2] { from, to }); } private static void OnTrail(long sender, Vector3 from, Vector3 to) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) if (InSight(from) || InSight(to)) { BlinkTrail.Spawn(from, to); } } private static bool InSight(Vector3 at) { //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) //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) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { Vector3 val = ((Component)localPlayer).transform.position - at; return ((Vector3)(ref val)).sqrMagnitude <= 22500f; } return false; } } } namespace RiftMagic.Config { internal static class RiftConfig { internal static ConfigEntry<float> SorterRange; internal static ConfigEntry<int> SorterMoltenCores; internal static ConfigEntry<float> SorterEyeForward; internal static ConfigEntry<float> SorterEyeUp; internal static ConfigEntry<float> SorterEyeSpacing; internal static ConfigEntry<float> SorterEyeSize; internal static ConfigEntry<float> SorterSeamGlow; internal static ConfigEntry<float> AegisArmor; internal static ConfigEntry<float> AegisCooldownMinutes; internal static void BindRelics(ConfigFile cfg, bool inGameHints) { SorterRange = Admin(cfg, "Rift Sorting Chest", "Range", 50f, "How far, in metres, a Rift Sorting Chest reaches for chests to sort into."); SorterMoltenCores = Admin(cfg, "Rift Sorting Chest", "MoltenCoreCost", 2, "Molten Cores it takes to build a Rift Sorting Chest, on top of a Grausten chest's own cost. Takes effect on restart."); SorterEyeForward = Local(cfg, "Rift Sorting Chest", "EyeForward", 0.4f, "Where the chest's glowing eyes sit, in metres from its base: toward its front (negative: its back)." + Hint("rift_eyes chest forward <value>")); SorterEyeUp = Local(cfg, "Rift Sorting Chest", "EyeUp", 1.02f, "Height of the chest's glowing eyes above its base, in metres." + Hint("rift_eyes chest up <value>")); SorterEyeSpacing = Local(cfg, "Rift Sorting Chest", "EyeSpacing", 0.11f, "Distance between the chest's two glowing eyes, in metres." + Hint("rift_eyes chest spacing <value>")); SorterEyeSize = Local(cfg, "Rift Sorting Chest", "EyeSize", 0.06f, "Size of the chest's glowing eyes, in metres; 0 hides them." + Hint("rift_eyes chest size <value>")); SorterSeamGlow = Local(cfg, "Rift Sorting Chest", "SeamGlow", 1f, "Brightness of the golden light leaking from under the chest's lid, brighter while it is open; 0 turns it off." + Hint("rift_eyes chest glow <value>")); AegisArmor = Admin(cfg, "Rift Aegis", "Armor", 50f, "Armor the Rift Aegis trinket adds while worn."); AegisCooldownMinutes = Admin(cfg, "Rift Aegis", "CooldownMinutes", 5f, "Minutes after the Rift Aegis turns aside a killing blow before it can do so again."); string Hint(string command) { if (!inGameHints) { return ""; } return " In game: " + command + "."; } } private static ConfigEntry<T> Local<T>(ConfigFile cfg, string section, string key, T def, string desc) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown return cfg.Bind<T>(section, key, def, new ConfigDescription(desc, (AcceptableValueBase)null, Array.Empty<object>())); } private static ConfigEntry<T> Admin<T>(ConfigFile cfg, string section, string key, T def, string desc) { //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_001c: Expected O, but got Unknown //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown return cfg.Bind<T>(section, key, def, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes { IsAdminOnly = true } })); } } } namespace RiftMagic.Items { internal static class RiftAegis { [HarmonyPatch(typeof(Character), "ApplyDamage")] private static class CharacterApplyDamage { private static void Prefix(Character __instance, out float __state) { __state = (((Object)(object)__instance == (Object)(object)Player.m_localPlayer && (Object)(object)__instance != (Object)null) ? __instance.GetHealth() : (-1f)); } private static void Postfix(Character __instance, float __state) { if (!(__state <= 0f)) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (!((Object)(object)val == (Object)null) && !((Character)val).IsDead() && !(((Character)val).GetHealth() > 0f) && ((Character)val).GetSEMan().HaveStatusEffect(EffectHash) && !(CooldownLeft(val) > TimeSpan.Zero)) { Save(val, __state); } } } } internal const string PrefabName = "RM_RiftAegis"; internal const string NameToken = "$riftmagic_item_aegis"; private const string CloneSource = "TrinketSilverDamage"; private const string FallbackSource = "TrinketBronzeHealth"; private const string ReadyKey = "RM_aegis_ready"; private static readonly Color Metal = new Color(1f, 0.78f, 0.35f); private static readonly Color Glow = new Color(0.6f, 0.25f, 1f); private static EffectList _saveEffects; internal static readonly Dictionary<string, string> English = new Dictionary<string, string> { { "riftmagic_item_aegis", "Rift Aegis" }, { "riftmagic_item_aegis_desc", "A silver charm gone gold where the rift touched it. It hardens whoever wears it, and once in a while it catches a blow that would have been their last." }, { "riftmagic_se_aegis", "Rift Aegis" }, { "riftmagic_aegis_guard", "Turns aside a killing blow, once every" }, { "riftmagic_aegis_minutes", "minutes" }, { "riftmagic_aegis_saved", "The Rift Aegis turns aside a killing blow!" }, { "riftmagic_aegis_readyin", "Ready in" }, { "riftmagic_aegis_ready", "Ready" } }; internal static int EffectHash => StringExtensionMethods.GetStableHashCode("RM_SE_RiftAegis"); internal static TimeSpan Cooldown => TimeSpan.FromMinutes(Mathf.Max(0f, RiftConfig.AegisCooldownMinutes.Value)); internal static void Register() { //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab("RM_RiftAegis", "TrinketSilverDamage") ?? PrefabManager.Instance.CreateClonedPrefab("RM_RiftAegis", "TrinketBronzeHealth"); if ((Object)(object)val == (Object)null) { Logger.LogError((object)"Could not clone 'TrinketSilverDamage' or 'TrinketBronzeHealth'; the Rift Aegis is unavailable."); return; } Tint(val); SharedData shared = val.GetComponent<ItemDrop>().m_itemData.m_shared; if ((Object)(object)shared.m_fullAdrenalineSE != (Object)null) { _saveEffects = shared.m_fullAdrenalineSE.m_startEffects; } SE_RiftAegis effect = ScriptableObject.CreateInstance<SE_RiftAegis>(); ((Object)effect).name = "RM_SE_RiftAegis"; ((StatusEffect)effect).m_name = "$riftmagic_se_aegis"; ((StatusEffect)effect).m_category = string.Empty; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect((StatusEffect)(object)effect, false)); shared.m_name = "$riftmagic_item_aegis"; shared.m_description = "$riftmagic_item_aegis_desc"; shared.m_equipStatusEffect = (StatusEffect)(object)effect; shared.m_fullAdrenalineSE = null; shared.m_maxAdrenaline = 0f; ClearModifiers(shared); IconMaker.RenderIcon(val, (Action<Sprite>)delegate(Sprite sprite) { shared.m_icons = (Sprite[])(object)new Sprite[1] { sprite }; ((StatusEffect)effect).m_icon = sprite; }, withParticles: true); ItemManager.Instance.AddItem(new CustomItem(val, false)); Logger.LogInfo((object)"Rift Aegis registered (spawn RM_RiftAegis)."); } private static void Tint(GameObject item) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (val is ParticleSystemRenderer) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length == 0) { continue; } Material[] array = (Material[])(object)new Material[sharedMaterials.Length]; for (int j = 0; j < sharedMaterials.Length; j++) { if (!((Object)(object)sharedMaterials[j] == (Object)null)) { Material val2 = new Material(sharedMaterials[j]); if (val2.HasProperty("_Color")) { val2.SetColor("_Color", Metal); } if (val2.HasProperty("_EmissionColor")) { val2.EnableKeyword("_EMISSION"); val2.SetColor("_EmissionColor", Glow * 0.4f); } array[j] = val2; } } val.sharedMaterials = array; } } private static void ClearModifiers(SharedData shared) { string[] array = new string[10] { "m_movementModifier", "m_homeItemsStaminaModifier", "m_heatResistanceModifier", "m_jumpStaminaModifier", "m_attackStaminaModifier", "m_blockStaminaModifier", "m_dodgeStaminaModifier", "m_swimStaminaModifier", "m_sneakStaminaModifier", "m_runStaminaModifier" }; foreach (string text in array) { FieldInfo fieldInfo = AccessTools.Field(typeof(SharedData), text); if (fieldInfo != null && fieldInfo.FieldType == typeof(float)) { fieldInfo.SetValue(shared, 0f); } } } internal static TimeSpan CooldownLeft(Player player) { if ((Object)(object)player == (Object)null || !player.m_customData.TryGetValue("RM_aegis_ready", out var value) || !long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result)) { return TimeSpan.Zero; } TimeSpan timeSpan = new DateTime(result, DateTimeKind.Utc) - DateTime.UtcNow; if (!(timeSpan > Cooldown)) { return timeSpan; } return Cooldown; } internal static string Format(TimeSpan span) { return (int)span.TotalMinutes + ":" + span.Seconds.ToString("00", CultureInfo.InvariantCulture); } private static void Save(Player player, float healthBefore) { //IL_0054: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) ((Character)player).SetHealth(Mathf.Max(1f, healthBefore)); player.m_customData["RM_aegis_ready"] = DateTime.UtcNow.Add(Cooldown).Ticks.ToString(CultureInfo.InvariantCulture); EffectList saveEffects = _saveEffects; if (saveEffects != null) { saveEffects.Create(((Character)player).GetCenterPoint(), ((Component)player).transform.rotation, ((Component)player).transform, 1f, -1, default(ZDOID)); } ((Character)player).Message((MessageType)2, "$riftmagic_aegis_saved", 0, (Sprite)null, false); Logger.LogInfo((object)$"Rift Aegis saved {player.GetPlayerName()} at {healthBefore:0.#} health."); } } internal class SE_RiftAegis : StatusEffect { internal const string EffectName = "RM_SE_RiftAegis"; public override void ModifyArmorMods(ref float armor) { armor += RiftConfig.AegisArmor.Value; } public override string GetIconText() { Character character = base.m_character; TimeSpan timeSpan = RiftAegis.CooldownLeft((Player)(object)((character is Player) ? character : null)); if (!(timeSpan > TimeSpan.Zero)) { return ""; } return RiftAegis.Format(timeSpan); } public override string GetTooltipString() { float num = Mathf.Max(0f, RiftConfig.AegisCooldownMinutes.Value); CultureInfo invariantCulture = CultureInfo.InvariantCulture; string text = "$item_armor: <color=orange>+" + RiftConfig.AegisArmor.Value.ToString("0.#", invariantCulture) + "</color>\n$riftmagic_aegis_guard " + num.ToString("0.#", invariantCulture) + " $riftmagic_aegis_minutes."; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return text; } TimeSpan timeSpan = RiftAegis.CooldownLeft(localPlayer); return text + "\n" + ((timeSpan > TimeSpan.Zero) ? ("$riftmagic_aegis_readyin " + RiftAegis.Format(timeSpan)) : "<color=#9be38f>$riftmagic_aegis_ready</color>"); } } internal static class IconMaker { private const int IconSize = 128; internal static void RenderIcon(GameObject prefab, SharedData shared, bool withParticles = true) { if (shared != null) { RenderIcon(prefab, (Action<Sprite>)delegate(Sprite sprite) { shared.m_icons = (Sprite[])(object)new Sprite[1] { sprite }; }, withParticles); } } internal static void RenderIcon(GameObject prefab, Action<Sprite> apply, bool withParticles = true) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: 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_0060: Expected O, but got Unknown if ((Object)(object)prefab == (Object)null || apply == null) { return; } try { RenderRequest val = new RenderRequest(prefab) { Rotation = RenderManager.IsometricRotation, Width = 128, Height = 128, UseCache = true }; if (!withParticles) { val.ParticleSimulationTime = -1f; } RenderManager.Instance.EnqueueRender(val, (Action<Sprite>)delegate(Sprite sprite) { if ((Object)(object)sprite == (Object)null) { Logger.LogWarning((object)("Icon render for '" + ((Object)prefab).name + "' came back empty; keeping the inherited icon.")); } else { apply(sprite); } }); } catch (Exception ex) { Logger.LogWarning((object)("Could not render icon for '" + ((Object)prefab).name + "': " + ex.Message)); } } } } namespace RiftMagic.Storage { internal class RiftSorter : MonoBehaviour { [HarmonyPatch(typeof(Container), "Interact")] private static class ContainerInteract { private static void Prefix(Container __instance, bool hold) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) if (!hold) { RiftSorter component = ((Component)__instance).GetComponent<RiftSorter>(); if (!((Object)(object)component == (Object)null) && !((Object)(object)component._nview == (Object)null) && component._nview.IsValid() && !component._nview.IsOwner() && component.OwnerIsSilent() && (!__instance.m_checkGuardStone || PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false)) && __instance.CheckAccess(Game.instance.GetPlayerProfile().GetPlayerID())) { component.TakeOver(); } } } } private const float TickSeconds = 0.5f; private const float RetrySeconds = 5f; private const float BeatSeconds = 2f; private const double SilentSeconds = 6.0; private const double TakeOverSpread = 6.0; private static readonly int BeatKey = StringExtensionMethods.GetStableHashCode("RM_sorter_beat"); private static int _pieceMask; private ZNetView _nview; private Container _container; private Inventory _watched; private bool _changed = true; private float _nextRetry; private float _nextBeat; private void Awake() { _nview = ((Component)this).GetComponent<ZNetView>(); _container = ((Component)this).GetComponent<Container>(); if (_pieceMask == 0) { _pieceMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" }); } ((MonoBehaviour)this).InvokeRepeating("Tick", Random.Range(0.5f, 1f), 0.5f); } private void Tick() { if ((Object)(object)_container == (Object)null || (Object)(object)_nview == (Object)null || !_nview.IsValid()) { return; } Inventory inventory = _container.GetInventory(); if (inventory == null) { return; } Watch(inventory); if (!_nview.IsOwner()) { if (inventory.NrOfItems() > 0 && (Object)(object)Player.m_localPlayer != (Object)null && OwnerIsSilent(6.0 + ClientSpread())) { TakeOver(); } return; } Beat(); if (!((Object)(object)Player.m_localPlayer == (Object)null) && inventory.NrOfItems() != 0 && (_changed || !(Time.time < _nextRetry))) { Sort(inventory); _changed = false; _nextRetry = Time.time + 5f; } } private void Watch(Inventory source) { if (_watched != source) { _watched = source; source.m_onChanged = (Action)Delegate.Combine(source.m_onChanged, (Action)delegate { _changed = true; }); } } private void Beat() { if (!(Time.time < _nextBeat) && !((Object)(object)ZNet.instance == (Object)null)) { _nextBeat = Time.time + 2f; ZDO zDO = _nview.GetZDO(); bool num = _container.m_lastRevision == zDO.DataRevision; zDO.Set(BeatKey, ZNet.instance.GetTime().Ticks); if (num) { _container.m_lastRevision = zDO.DataRevision; } } } private bool OwnerIsSilent(double seconds = 6.0) { if ((Object)(object)ZNet.instance == (Object)null) { return false; } long ticks = _nview.GetZDO().GetLong(BeatKey, 0L); return (ZNet.instance.GetTime() - new DateTime(ticks)).TotalSeconds > seconds; } private static double ClientSpread() { return (double)(ZDOMan.GetSessionID() & 0xFFFF) / 65535.0 * 6.0; } private void TakeOver() { Logger.LogInfo((object)"Rift Sorting Chest: its owner does not answer; taking it over."); _nview.ClaimOwnership(); _nextBeat = 0f; Beat(); } private void Sort(Inventory source) { //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_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) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) List<Container> list = FindTargets(); if (list.Count == 0) { return; } int num = 0; HashSet<Container> hashSet = new HashSet<Container>(); foreach (ItemData item in new List<ItemData>(source.GetAllItems())) { foreach (Container item2 in list) { Inventory inventory = item2.GetInventory(); if (inventory.ContainsItemByName(item.m_shared.m_name) && HasRoomFor(inventory, item)) { if (!item2.IsOwner()) { item2.m_nview.ClaimOwnership(); } int stack = item.m_stack; if (inventory.AddItem(item)) { source.RemoveItem(item); num += stack; hashSet.Add(item2); break; } if (item.m_stack < stack) { num += stack - item.m_stack; hashSet.Add(item2); } } } } if (num == 0) { return; } source.Changed(false, false); Vector3 val = ((Component)this).transform.position + Vector3.up; foreach (Container item3 in hashSet) { TrailFx.Trail(val, ((Component)item3).transform.position + Vector3.up * 0.5f); } InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_currentContainer == (Object)(object)_container) { instance.m_moveItemEffects.Create(((Component)this).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID)); ((Character)Player.m_localPlayer).Message((MessageType)2, $"$riftmagic_sorter_sorted {num}", 0, (Sprite)null, false); } } private List<Container> FindTargets() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) List<Container> list = new List<Container>(); HashSet<Container> hashSet = new HashSet<Container>(); Vector3 here = ((Component)this).transform.position; long playerID = Game.instance.GetPlayerProfile().GetPlayerID(); Collider[] array = Physics.OverlapSphere(here, RiftConfig.SorterRange.Value, _pieceMask); for (int i = 0; i < array.Length; i++) { Container componentInParent = ((Component)array[i]).GetComponentInParent<Container>(); if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)_container) && hashSet.Add(componentInParent) && !((Object)(object)((Component)componentInParent).GetComponent<RiftSorter>() != (Object)null) && !((Object)(object)componentInParent.m_rootObjectOverride != (Object)null) && !((Object)(object)componentInParent.m_wagon != (Object)null) && !componentInParent.m_autoDestroyEmpty && !((Object)(object)((Component)componentInParent).GetComponent<Piece>() == (Object)null) && componentInParent.GetInventory() != null) { ZNetView nview = componentInParent.m_nview; if (!((Object)(object)nview == (Object)null) && nview.IsValid() && !(componentInParent.IsOwner() ? componentInParent.IsInUse() : (nview.GetZDO().GetInt(ZDOVars.s_inUse, 0) == 1)) && componentInParent.CheckAccess(playerID) && PrivateArea.CheckAccess(((Component)componentInParent).transform.position, 0f, false, false)) { componentInParent.Load(); list.Add(componentInParent); } } } list.Sort(delegate(Container a, Container b) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) Vector3 val = ((Component)a).transform.position - here; float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude; val = ((Component)b).transform.position - here; return sqrMagnitude.CompareTo(((Vector3)(ref val)).sqrMagnitude); }); return list; } private static bool HasRoomFor(Inventory dest, ItemData item) { if (dest.HaveEmptySlot()) { return true; } if (item.m_shared.m_maxStackSize <= 1) { return false; } foreach (ItemData allItem in dest.GetAllItems()) { if (allItem.m_shared.m_name == item.m_shared.m_name && allItem.m_quality == item.m_quality && allItem.m_worldLevel == item.m_worldLevel && allItem.m_stack < allItem.m_shared.m_maxStackSize) { return true; } } return false; } } internal class RiftSorterEyes : MonoBehaviour { private Transform _left; private Transform _right; private Light _light; private float _seed; private RiftSorterLid _lid; private bool _lidSought; private void Awake() { //IL_0072: Unknown result type (might be due to invalid IL or missing references) _seed = Random.value * 10f; Material val = GlowMaterials.Additive("Companion eyes", (Texture)(object)EyeGlow.Texture()); if (!((Object)(object)val == (Object)null)) { _left = MakeGlow("eyeL", val); _right = MakeGlow("eyeR", val); _light = ((Component)this).gameObject.AddComponent<Light>(); _light.type = (LightType)2; _light.color = EyeGlow.Colour; _light.shadows = (LightShadows)0; } } private Transform MakeGlow(string name, Material material) { GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5); ((Object)obj).name = name; obj.transform.SetParent(((Component)this).transform, false); Collider component = obj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } MeshRenderer component2 = obj.GetComponent<MeshRenderer>(); ((Renderer)component2).sharedMaterial = material; ((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component2).receiveShadows = false; return obj.transform; } private void LateUpdate() { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014a: 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_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0155: 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_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0162: 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_0225: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_left == (Object)null || RiftConfig.SorterEyeSize == null) { return; } float value = RiftConfig.SorterEyeSize.Value; bool flag = value > 0f; ((Component)_left).gameObject.SetActive(flag); ((Component)_right).gameObject.SetActive(flag); bool flag2 = (Object)(object)_light != (Object)null; if (flag2) { ((Behaviour)_light).enabled = flag; } if (flag) { Transform val = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent : ((Component)this).transform); Vector3 val2 = val.position + val.forward * RiftConfig.SorterEyeForward.Value + val.up * RiftConfig.SorterEyeUp.Value; Vector3 val3 = val.right * (RiftConfig.SorterEyeSpacing.Value * 0.5f); Vector3 val4 = val.forward; if (!_lidSought) { _lid = RiftSorterLid.Find(val); _lidSought = true; } if (_lid != null && _lid.IsOpen && RiftConfig.SorterEyeUp.Value > _lid.SeamHeight) { Matrix4x4 closedToOpen = _lid.ClosedToOpen; val2 = ((Matrix4x4)(ref closedToOpen)).MultiplyPoint3x4(val2); val3 = ((Matrix4x4)(ref closedToOpen)).MultiplyVector(val3); val4 = ((Matrix4x4)(ref closedToOpen)).MultiplyVector(val4); } float num = 0.85f + 0.15f * Mathf.PerlinNoise(Time.time * 3f, _seed); Transform cam = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform : null)); float inherited = Mathf.Max(0.001f, ((Component)this).transform.lossyScale.x); EyeGlow.Place(_left, val2 - val3, value * num, inherited, cam); EyeGlow.Place(_right, val2 + val3, value * num, inherited, cam); if (flag2) { ((Component)_light).transform.position = val2 + val4 * 0.05f; _light.range = Mathf.Max(0.5f, value * 11f); _light.intensity = 1.4f * num; } } } } internal class RiftSorterLid { private readonly GameObject _openRoot; private readonly Transform _open; private readonly Transform _closed; internal Bounds Local { get; } internal float SeamHeight { get { //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_0009: Unknown result type (might be due to invalid IL or missing references) Bounds local = Local; return ((Bounds)(ref local)).min.y; } } internal bool IsOpen { get { if ((Object)(object)_openRoot != (Object)null) { return _openRoot.activeSelf; } return false; } } internal Matrix4x4 ClosedToOpen => _open.localToWorldMatrix * _closed.worldToLocalMatrix; private RiftSorterLid(GameObject openRoot, Transform open, Transform closed, Bounds local) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _openRoot = openRoot; _open = open; _closed = closed; Local = local; } internal static RiftSorterLid Find(Transform chest) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) Container componentInParent = ((Component)chest).GetComponentInParent<Container>(); if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent.m_open == (Object)null || (Object)(object)componentInParent.m_closed == (Object)null) { return null; } MeshFilter val = LidMesh(componentInParent.m_open); MeshFilter val2 = LidMesh(componentInParent.m_closed); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null) { return null; } Bounds bounds = val2.sharedMesh.bounds; Matrix4x4 val3 = ((Component)componentInParent).transform.worldToLocalMatrix * ((Component)val2).transform.localToWorldMatrix; Bounds local = default(Bounds); ((Bounds)(ref local))..ctor(((Matrix4x4)(ref val3)).MultiplyPoint3x4(((Bounds)(ref bounds)).min), Vector3.zero); for (int i = 0; i < 8; i++) { ((Bounds)(ref local)).Encapsulate(((Matrix4x4)(ref val3)).MultiplyPoint3x4(new Vector3(((i & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((i & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((i & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z))); } return new RiftSorterLid(componentInParent.m_open, ((Component)val).transform, ((Component)val2).transform, local); } private static MeshFilter LidMesh(GameObject model) { MeshFilter val = null; MeshFilter[] componentsInChildren = model.GetComponentsInChildren<MeshFilter>(true); foreach (MeshFilter val2 in componentsInChildren) { if (!((Object)(object)val2.sharedMesh == (Object)null)) { if (!((Object)val2).name.ToLowerInvariant().Contains("lod")) { return val2; } if ((Object)(object)val == (Object)null) { val = val2; } } } return val; } } internal static class RiftSorterPiece { internal const string PrefabName = "RM_RiftSortingChest"; private const string CloneSource = "piece_chest_grausten"; private const string MoltenCore = "MoltenCore"; private static readonly Color Body = new Color(0.78f, 0.62f, 1f); private static readonly Color SpotGlow = new Color(0.45f, 0.15f, 0.85f) * 0.35f; private static readonly Color Gold = new Color(1f, 0.76f, 0.3f); private const float GoldShine = 0.12f; private static readonly Color Glow = new Color(0.6f, 0.25f, 1f); private const float LightRange = 3.5f; private const float LightIntensity = 0.8f; private const float MoteRate = 0.6f; internal static readonly Dictionary<string, string> English = new Dictionary<string, string> { { "riftmagic_piece_riftsorter", "Rift Sorting Chest" }, { "riftmagic_piece_riftsorter_desc", "A Grausten chest with a Molten Core's heat let into it through the rift. Whatever goes in is carried off to the chests nearby that already hold the same thing and have room for it. What finds no such chest waits here." }, { "riftmagic_sorter_sorted", "Sorted into nearby chests:" } }; internal static void Register() { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Expected O, but got Unknown //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Expected O, but got Unknown //IL_02cd: Unknown result type (might be due to invalid IL or missing references) GameObject val = PrefabManager.Instance.CreateClonedPrefab("RM_RiftSortingChest", "piece_chest_grausten"); if ((Object)(object)val == (Object)null) { Logger.LogError((object)"Could not clone 'piece_chest_grausten'; the Rift Sorting Chest is unavailable."); return; } Piece piece = val.GetComponent<Piece>(); Container component = val.GetComponent<Container>(); if ((Object)(object)piece == (Object)null || (Object)(object)component == (Object)null) { Logger.LogError((object)"'piece_chest_grausten' is no longer a chest piece; the Rift Sorting Chest is unavailable."); return; } component.m_name = "$riftmagic_piece_riftsorter"; val.AddComponent<RiftSorter>(); GameObject val2 = new GameObject("rift_eyes"); val2.transform.SetParent(val.transform, false); val2.AddComponent<RiftSorterEyes>(); GameObject val3 = new GameObject("rift_seam"); val3.transform.SetParent(val.transform, false); val3.AddComponent<RiftSorterSeam>(); Bounds bounds = LocalBounds(val); Tint(val); AddGlow(val, bounds); RiftMotes.Attach(val.transform, new Bounds(((Bounds)(ref bounds)).center + Vector3.up * ((Bounds)(ref bounds)).extents.y, new Vector3(((Bounds)(ref bounds)).size.x, 0.1f, ((Bounds)(ref bounds)).size.z)), 0.6f); List<RequirementConfig> list = new List<RequirementConfig>(); Requirement[] resources = piece.m_resources; foreach (Requirement val4 in resources) { if (!((Object)(object)val4.m_resItem == (Object)null)) { list.Add(new RequirementConfig { Item = ((Object)val4.m_resItem).name, Amount = val4.m_amount, Recover = val4.m_recover }); } } list.Add(new RequirementConfig { Item = "MoltenCore", Amount = Mathf.Max(1, RiftConfig.SorterMoltenCores.Value), Recover = true }); CustomPiece val5 = new CustomPiece(val, false, new PieceConfig { Name = "$riftmagic_piece_riftsorter", Description = "$riftmagic_piece_riftsorter_desc", PieceTable = "Hammer", Category = ((object)Unsafe.As<PieceCategory, PieceCategory>(ref piece.m_category)/*cast due to .constrained prefix*/).ToString(), CraftingStation = (((Object)(object)piece.m_craftingStation != (Object)null) ? ((Object)piece.m_craftingStation).name : null), Requirements = list.ToArray() }); PieceManager.Instance.AddPiece(val5); List<string> list2 = new List<string>(); foreach (RequirementConfig item in list) { list2.Add($"{item.Item} x{item.Amount}"); } Logger.LogInfo((object)($"Rift Sorting Chest registered: Hammer > {piece.m_category}, " + "station " + (((Object)(object)piece.m_craftingStation != (Object)null) ? ((Object)piece.m_craftingStation).name : "none") + ", costs " + string.Join(", ", list2) + ".")); IconMaker.RenderIcon(val, (Action<Sprite>)delegate(Sprite sprite) { piece.m_icon = sprite; }, withParticles: false); } private static void Tint(GameObject chest) { Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>(); Renderer[] componentsInChildren = chest.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (val is ParticleSystemRenderer) { continue; } Material[] sharedMaterials = val.sharedMaterials; if (sharedMaterials == null || sharedMaterials.Length == 0) { continue; } Material[] array = (Material[])(object)new Material[sharedMaterials.Length]; for (int j = 0; j < sharedMaterials.Length; j++) { if (!((Object)(object)sharedMaterials[j] == (Object)null)) { if (!dictionary.TryGetValue(sharedMaterials[j], out var value)) { value = Repaint(sharedMaterials[j]); dictionary[sharedMaterials[j]] = value; } array[j] = value; } } val.sharedMaterials = array; } } private static Material Repaint(Material source) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0132: 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_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_022a: 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_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_028b: Unknown result type (might be due to invalid IL or missing references) Material val = new Material(source); Texture val2 = (val.HasProperty("_MainTex") ? val.GetTexture("_MainTex") : null); Texture val3 = (val.HasProperty("_MetallicTex") ? val.GetTexture("_MetallicTex") : null); Texture val4 = (val.HasProperty("_EmissionMap") ? val.GetTexture("_EmissionMap") : null); if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null) { if (val.HasProperty("_Color")) { val.SetColor("_Color", Body); } SetEmission(val, SpotGlow); return val; } int width = val2.width; int height = val2.height; Color[] array = ReadPixels(val2, width, height, linear: false); Color[] array2 = ReadPixels(val3, width, height, linear: true); Color[] array3 = (((Object)(object)val4 != (Object)null) ? ReadPixels(val4, width, height, linear: true) : null); Color[] array4 = (Color[])(object)new Color[array.Length]; Color[] array5 = (Color[])(object)new Color[array.Length]; for (int i = 0; i < array.Length; i++) { Color val5 = array[i]; float num = Mathf.Clamp01(array2[i].r); float num2 = Mathf.Clamp01(0.45f + 0.9f * ((Color)(ref val5)).grayscale); Color val6 = Gold * num2; Color val7 = val5 * Body; array4[i] = Color.Lerp(val7, val6, num); array4[i].a = val5.a; float num3 = ((array3 != null) ? ((Color)(ref array3[i])).grayscale : 0f); array5[i] = SpotGlow * num3 + Gold * (0.12f * num * (1f - num3)); array5[i].a = 1f; } val.SetTexture("_MainTex", (Texture)(object)MakeTexture(((Object)val2).name + "_rift", width, height, array4, val2.wrapMode)); if (val.HasProperty("_Color")) { val.SetColor("_Color", Color.white); } if (val.HasProperty("_MetalColor")) { val.SetColor("_MetalColor", Color.white); } if (val.HasProperty("_EmissionMap")) { val.SetTexture("_EmissionMap", (Texture)(object)MakeTexture(((Object)val2).name + "_rift_e", width, height, array5, val2.wrapMode)); SetEmission(val, Color.white); } else { SetEmission(val, SpotGlow); } return val; } private static void SetEmission(Material mat, Color colour) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) if (mat.HasProperty("_EmissionColor")) { mat.EnableKeyword("_EMISSION"); mat.SetColor("_EmissionColor", colour); } } private static Color[] ReadPixels(Texture texture, int w, int h, bool linear) { //IL_0029: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown RenderTexture temporary = RenderTexture.GetTemporary(w, h, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)(linear ? 1 : 2)); RenderTexture active = RenderTexture.active; try { Graphics.Blit(texture, temporary); RenderTexture.active = temporary; Texture2D val = new Texture2D(w, h, (TextureFormat)4, false, linear); val.ReadPixels(new Rect(0f, 0f, (float)w, (float)h), 0, 0); val.Apply(); Color[] pixels = val.GetPixels(); Object.Destroy((Object)val); return pixels; } finally { RenderTexture.active = active; RenderTexture.ReleaseTemporary(temporary); } } private static Texture2D MakeTexture(string name, int w, int h, Color[] pixels, TextureWrapMode wrap) { //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_0011: 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_0019: 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_0027: 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_0037: Expected O, but got Unknown Texture2D val = new Texture2D(w, h, (TextureFormat)4, true, false) { name = name, wrapMode = wrap, filterMode = (FilterMode)1, anisoLevel = 4 }; val.SetPixels(pixels); val.Apply(true, true); return val; } private static void AddGlow(GameObject chest, Bounds bounds) { //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_001c: 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_0030: 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_005c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("rift_glow"); val.transform.SetParent(chest.transform, false); val.transform.localPosition = ((Bounds)(ref bounds)).center + Vector3.up * (((Bounds)(ref bounds)).extents.y + 0.3f); Light obj = val.AddComponent<Light>(); obj.type = (LightType)2; obj.color = Glow; obj.range = 3.5f; obj.intensity = 0.8f; obj.shadows = (LightShadows)0; } private static Bounds LocalBounds(GameObject chest) { //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_017d: 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_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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008a: 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_0094: 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_00a8: 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_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0115: 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) bool flag = false; Bounds result = default(Bounds); ((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero); Transform transform = chest.transform; MeshFilter[] componentsInChildren = chest.GetComponentsInChildren<MeshFilter>(true); Vector3 val3 = default(Vector3); foreach (MeshFilter val in componentsInChildren) { if ((Object)(object)val.sharedMesh == (Object)null || (Object)(object)((Component)val).GetComponent<LODGroup>() != (Object)null || ((Object)val).name.ToLowerInvariant().Contains("lod")) { continue; } Bounds bounds = val.sharedMesh.bounds; Matrix4x4 val2 = transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; for (int j = 0; j < 8; j++) { ((Vector3)(ref val3))..ctor(((j & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((j & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((j & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z); Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val3); if (!flag) { ((Bounds)(ref result))..ctor(val4, Vector3.zero); flag = true; } else { ((Bounds)(ref result)).Encapsulate(val4); } } } if (!flag) { return new Bounds(new Vector3(0f, 0.5f, 0f), new Vector3(1.6f, 1f, 1f)); } return result; } } internal class RiftSorterSeam : MonoBehaviour { private static readonly Color Gold = new Color(1f, 0.78f, 0.32f); private const float Outset = 0.012f; private const float BandHalfHeight = 0.04f; private const float SpillWidth = 0.08f; private const float MouthLift = 0.01f; private const float ClosedLevel = 0.55f; private const float OpenLevel = 1f; private const float OpenSpeed = 5f; private RiftSorterLid _lid; private Mesh _mesh; private MeshRenderer _renderer; private Light _light; private float[] _alpha; private bool[] _mouth; private Color[] _colours; private float _open; private float _seed; private void Start() { //IL_0075: 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_00da: Expected O, but got Unknown //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) Transform chest = (((Object)(object)((Component)this).transform.parent != (Object)null) ? ((Component)this).transform.parent : ((Component)this).transform); _lid = RiftSorterLid.Find(chest); Material val = GlowMaterials.Additive("Sorter seam", (Texture)(object)GlowMaterials.White()); if (_lid == null || (Object)(object)val == (Object)null) { ((Behaviour)this).enabled = false; return; } _seed = Random.value * 10f; _mesh = Build(_lid.Local); ((Component)this).gameObject.AddComponent<MeshFilter>().sharedMesh = _mesh; _renderer = ((Component)this).gameObject.AddComponent<MeshRenderer>(); ((Renderer)_renderer).sharedMaterial = val; ((Renderer)_renderer).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)_renderer).receiveShadows = false; GameObject val2 = new GameObject("rift_seam_light"); val2.transform.SetParent(((Component)this).transform, false); Transform transform = val2.transform; Bounds local = _lid.Local; float x = ((Bounds)(ref local)).center.x; float seamHeight = _lid.SeamHeight; local = _lid.Local; transform.localPosition = new Vector3(x, seamHeight, ((Bounds)(ref local)).center.z); _light = val2.AddComponent<Light>(); _light.type = (LightType)2; _light.color = Gold; _light.shadows = (LightShadows)0; } private void OnDestroy() { if ((Object)(object)_mesh != (Object)null) { Object.Destroy((Object)(object)_mesh); } } private void LateUpdate() { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_012f: 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_0142: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_mesh == (Object)null || RiftConfig.SorterSeamGlow == null) { return; } float value = RiftConfig.SorterSeamGlow.Value; bool flag = value > 0f; ((Renderer)_renderer).enabled = flag; bool flag2 = (Object)(object)_light != (Object)null; if (flag2) { ((Behaviour)_light).enabled = flag; } if (flag) { _open = Mathf.MoveTowards(_open, _lid.IsOpen ? 1f : 0f, Time.deltaTime * 5f); float num = 0.88f + 0.12f * Mathf.PerlinNoise(Time.time * 2.2f, _seed); float num2 = value * num * Mathf.Lerp(0.55f, 1f, _open); Color val = Color.Lerp(Gold, Color.white, Mathf.Clamp01(num2 - 1f) * 0.6f); for (int i = 0; i < _colours.Length; i++) { float num3 = _alpha[i] * num2 * (_mouth[i] ? _open : 1f); _colours[i] = new Color(val.r, val.g, val.b, Mathf.Clamp01(num3)); } _mesh.colors = _colours; if (flag2) { _light.intensity = value * num * Mathf.Lerp(0.5f, 1.5f, _open); _light.range = Mathf.Lerp(1.6f, 3f, _open); } } } private Mesh Build(Bounds lid) { //IL_0002: 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_0022: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0115: 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_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Unknown result type (might be due to invalid IL or missing references) //IL_027f: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a1: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02a9: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references)