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 EyeOfSauron v1.7.2
BepInEx\plugins\EyeOfSauron\SauronEyePortal.dll
Decompiled 13 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("SauronEyePortal")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("SauronEyePortal")] [assembly: AssemblyTitle("SauronEyePortal")] [assembly: AssemblyVersion("1.0.0.0")] [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 SauronEyePortal { [BepInPlugin("promotor.valheim.sauroneyeportal", "Sauron Eye Portal", "1.7.1")] public sealed class SauronEyePortalPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")] private static class UpdatePortalPatch { [HarmonyPostfix] private static void Postfix(TeleportWorld __instance) { Apply(__instance); } } public const string Guid = "promotor.valheim.sauroneyeportal"; public const string Name = "Sauron Eye Portal"; public const string Version = "1.7.1"; internal static ConfigEntry<bool> Enabled; internal static ConfigEntry<string> PortalTag; internal static ConfigEntry<bool> DebugLogging; internal static ConfigEntry<bool> EyeEnabled; internal static ConfigEntry<float> EyeVerticalOffset; internal static ConfigEntry<float> EyeWidth; internal static ConfigEntry<float> EyeHeight; internal static ConfigEntry<float> EyeScale; internal static ConfigEntry<float> EyeDepth; internal static ConfigEntry<bool> HidePortalGeometry; internal static ConfigEntry<bool> HidePortalParticles; internal static ConfigEntry<float> BlinkIntervalMin; internal static ConfigEntry<float> BlinkIntervalMax; internal static ConfigEntry<float> BlinkDuration; internal static ConfigEntry<bool> ScanEnabled; internal static ConfigEntry<float> ScanSpeed; internal static ConfigEntry<float> ScanAmplitude; internal static ConfigEntry<float> ScanTiltDegrees; internal static ConfigEntry<float> EmberIntensity; internal static ConfigEntry<bool> EmberLightEnabled; internal static ConfigEntry<float> EmberLightRange; internal static ConfigEntry<bool> EyeFlames; internal static ConfigEntry<float> FlameDensity; internal static ConfigEntry<float> FlameLength; internal static ConfigEntry<float> ScleraFlicker; internal static ConfigEntry<float> PupilHeightFraction; internal static ConfigEntry<float> PupilWidthFraction; internal static ConfigEntry<float> PupilInset; internal static ConfigEntry<float> PupilVisualWidth; internal static ConfigEntry<bool> UseNativePortalFlames; internal static SauronEyePortalPlugin Instance; internal static bool HeadlessServer; private Harmony harmony; private float nextLogTime; private void Awake() { //IL_042a: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Expected O, but got Unknown Instance = this; HeadlessServer = Application.isBatchMode; Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the Sauron portal effect logic."); PortalTag = ((BaseUnityPlugin)this).Config.Bind<string>("General", "PortalTag", "SAURON", "Exact portal name (case-sensitive) that should become the Eye of Sauron."); DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "DebugLogging", true, "Write occasional diagnostics to BepInEx log."); EyeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Eye", "EyeEnabled", true, "Create a custom eye visual in the middle of the tagged portal."); EyeVerticalOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "EyeVerticalOffset", 1.35f, "Local Y offset for the eye visual inside the portal ring."); EyeWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "EyeWidth", 1.1f, "Base eye width in local units."); EyeHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "EyeHeight", 0.52f, "Base eye height in local units."); EyeScale = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "EyeScale", 2f, "Scale the whole eye visual. 1=original size, 2=200%, up to 30."); EyeDepth = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "EyeDepth", 0.12f, "Convex depth of the eye surface. 0 = flat, 0.3 = pronounced."); PupilHeightFraction = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "PupilHeightFraction", 0.68f, "Black slit height as fraction of eye height."); PupilWidthFraction = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "PupilWidthFraction", 0.12f, "Black slit width as fraction of eye width."); PupilInset = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "PupilInset", 0.04f, "How far in front of the sclera the pupil sits, to create depth."); PupilVisualWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Eye", "PupilVisualWidth", 0.29f, "Width of the pupil visual relative to eye width; 0.29 is the recommended larger slit."); HidePortalGeometry = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal", "HidePortalGeometry", true, "Hide portal frame and portal-surface mesh while keeping colliders and interaction."); HidePortalParticles = ((BaseUnityPlugin)this).Config.Bind<bool>("Portal", "HidePortalParticles", true, "Hide original portal fire/smoke particles so only the custom eye flames remain."); BlinkIntervalMin = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "BlinkIntervalMin", 4f, "Minimum seconds between blinks."); BlinkIntervalMax = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "BlinkIntervalMax", 8f, "Maximum seconds between blinks."); BlinkDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "BlinkDuration", 0.18f, "Duration of a full blink in seconds."); ScanEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Animation", "ScanEnabled", true, "Slowly move the pupil and tilt the eye as if scanning the landscape."); ScanSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "ScanSpeed", 0.24f, "Scanning rate in radians per second."); ScanAmplitude = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "PupilTravel", 0.16f, "How far the pupil travels, as a fraction of eye width."); ScanTiltDegrees = ((BaseUnityPlugin)this).Config.Bind<float>("Animation", "EyeTiltDegrees", 4.5f, "Maximum left/right eye tilt in degrees."); EmberIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("Embers", "EmberIntensity", 1.6f, "Brightness multiplier for eye and flames."); EmberLightEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Embers", "PointLight", true, "Attach a small local point light to the eye on clients."); EmberLightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Embers", "LightRange", 3.5f, "Eye point-light range in world units."); ScleraFlicker = ((BaseUnityPlugin)this).Config.Bind<float>("Embers", "ScleraFlicker", 0.6f, "Animated fiery sclera pulsing. 0 disables flicker, 1 strong flicker."); EyeFlames = ((BaseUnityPlugin)this).Config.Bind<bool>("Fire", "EyeFlames", true, "Spawn fire directly from the eye outline and sclera."); UseNativePortalFlames = ((BaseUnityPlugin)this).Config.Bind<bool>("Fire", "UseNativePortalFlames", true, "Reuse the native portal particle material and particle renderer instead of the simple generated flame texture."); FlameDensity = ((BaseUnityPlugin)this).Config.Bind<float>("Fire", "FlameDensity", 52f, "Flame particles per second. Range 0-240."); FlameLength = ((BaseUnityPlugin)this).Config.Bind<float>("Fire", "FlameLength", 0.36f, "How far fire tongues rise relative to eye height. Range 0.05-2."); harmony = new Harmony("promotor.valheim.sauroneyeportal"); harmony.PatchAll(typeof(SauronEyePortalPlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Sauron Eye Portal v1.7.1 loaded. Target tag: " + PortalTag.Value + ". Mode: " + (HeadlessServer ? "dedicated server" : "client visual renderer"))); } internal void LogFlameInfo(string message) { ((BaseUnityPlugin)this).Logger.LogInfo((object)message); } internal void LogFlameWarning(string message) { ((BaseUnityPlugin)this).Logger.LogWarning((object)message); } private void OnDestroy() { if (harmony != null) { harmony.UnpatchSelf(); } Instance = null; } internal static bool IsTargetPortal(TeleportWorld portal) { if ((Object)(object)portal == (Object)null || Enabled == null || !Enabled.Value || PortalTag == null) { return false; } return string.Equals(portal.GetText(), PortalTag.Value, StringComparison.Ordinal); } private static void Apply(TeleportWorld portal) { if (!IsTargetPortal(portal) || HeadlessServer) { return; } if ((Object)(object)portal.m_target_found != (Object)null) { portal.m_target_found.SetActive(true); } if (EyeEnabled != null && EyeEnabled.Value) { SauronEyeVisual component = ((Component)portal).GetComponent<SauronEyeVisual>(); if ((Object)(object)component == (Object)null) { component = ((Component)portal).gameObject.AddComponent<SauronEyeVisual>(); component.Initialize(portal); } else { component.MarkSeen(); } } if ((Object)(object)Instance != (Object)null && DebugLogging != null && DebugLogging.Value && Time.unscaledTime >= Instance.nextLogTime) { Instance.nextLogTime = Time.unscaledTime + 15f; ((BaseUnityPlugin)Instance).Logger.LogInfo((object)"SAURON portal detected; billboard eye ensured."); } } } public sealed class SauronEyeVisual : MonoBehaviour { private TeleportWorld portal; private GameObject visualRoot; private Transform billboardRoot; private Transform eyeRoot; private Transform iris; private Transform pupil; private Transform halo; private Material irisMaterial; private Material pupilMaterial; private Material haloMaterial; private Material flameMaterial; private ParticleSystem flames; private bool usingNativeFlames; private string nativeFlameSource; private Light emberLight; private readonly Dictionary<Renderer, bool> hiddenMeshRenderers = new Dictionary<Renderer, bool>(); private readonly Dictionary<ParticleSystemRenderer, bool> hiddenParticleRenderers = new Dictionary<ParticleSystemRenderer, bool>(); private readonly List<Material> ownedMaterials = new List<Material>(); private readonly List<Texture2D> ownedTextures = new List<Texture2D>(); private readonly List<Mesh> ownedMeshes = new List<Mesh>(); private float nextBlink; private float blinkStart = -1f; private float blinkAmount; private float scanSeed; private float nextHideRefresh; private float flameRemainder; private bool initialized; public void Initialize(TeleportWorld owningPortal) { portal = owningPortal; scanSeed = Random.Range(0f, 100f); MakeVisual(); ScheduleBlink(initial: true); initialized = true; } public void MarkSeen() { if (!initialized && (Object)(object)portal != (Object)null) { MakeVisual(); initialized = true; } } private void OnDestroy() { RestoreOriginalMesh(); RestorePortalParticleRenderers(); if ((Object)(object)visualRoot != (Object)null) { Object.Destroy((Object)(object)visualRoot); } foreach (Material ownedMaterial in ownedMaterials) { if ((Object)(object)ownedMaterial != (Object)null) { Object.Destroy((Object)(object)ownedMaterial); } } foreach (Texture2D ownedTexture in ownedTextures) { if ((Object)(object)ownedTexture != (Object)null) { Object.Destroy((Object)(object)ownedTexture); } } foreach (Mesh ownedMesh in ownedMeshes) { if ((Object)(object)ownedMesh != (Object)null) { Object.Destroy((Object)(object)ownedMesh); } } } private void Update() { if ((Object)(object)portal == (Object)null || !SauronEyePortalPlugin.IsTargetPortal(portal)) { RestoreOriginalMesh(); RestorePortalParticleRenderers(); if ((Object)(object)visualRoot != (Object)null) { visualRoot.SetActive(false); } return; } if ((Object)(object)visualRoot == (Object)null) { MakeVisual(); } if ((Object)(object)visualRoot != (Object)null) { visualRoot.SetActive(SauronEyePortalPlugin.EyeEnabled.Value); } if (!SauronEyePortalPlugin.EyeEnabled.Value) { return; } if (Time.time >= nextHideRefresh) { nextHideRefresh = Time.time + 1f; if (SauronEyePortalPlugin.HidePortalGeometry.Value) { HideOriginalMesh(); } else { RestoreOriginalMesh(); } if (SauronEyePortalPlugin.HidePortalParticles.Value) { HidePortalParticleRenderers(); } else { RestorePortalParticleRenderers(); } } UpdateBillboard(); UpdateBlink(); AnimateEye(); EmitEyeFlames(); } private void MakeVisual() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0046: 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_0098: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Expected O, but got Unknown //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Expected O, but got Unknown //IL_034d: Unknown result type (might be due to invalid IL or missing references) //IL_0385: Unknown result type (might be due to invalid IL or missing references) visualRoot = new GameObject("SauronEye_BillboardRoot"); visualRoot.transform.SetParent(((Component)this).transform, false); visualRoot.transform.localPosition = new Vector3(0f, SauronEyePortalPlugin.EyeVerticalOffset.Value, 0f); visualRoot.layer = ((Component)this).gameObject.layer; billboardRoot = new GameObject("Billboard").transform; billboardRoot.SetParent(visualRoot.transform, false); eyeRoot = new GameObject("EyeRoot").transform; eyeRoot.SetParent(billboardRoot, false); Texture2D val = CreateScleraTexture(512, 256); Texture2D val2 = CreateSlitTexture(128, 256); Texture2D val3 = CreateHaloTexture(256, 128); Texture2D val4 = CreateFlameTexture(48, 96); ownedTextures.Add(val); ownedTextures.Add(val2); ownedTextures.Add(val3); ownedTextures.Add(val4); Shader val5 = Shader.Find("Unlit/Transparent"); if ((Object)(object)val5 == (Object)null) { val5 = Shader.Find("Sprites/Default"); } if ((Object)(object)val5 == (Object)null) { val5 = Shader.Find("Legacy Shaders/Transparent/Diffuse"); } if ((Object)(object)val5 == (Object)null) { val5 = Shader.Find("Standard"); } Shader val6 = Shader.Find("Particles/Standard Unlit"); if ((Object)(object)val6 == (Object)null) { val6 = Shader.Find("Legacy Shaders/Particles/Additive"); } if ((Object)(object)val6 == (Object)null) { val6 = Shader.Find("Sprites/Default"); } if ((Object)(object)val6 == (Object)null) { val6 = val5; } halo = MakeQuad("EmberHalo", eyeRoot, val5, (Texture)(object)val3, new Color(1f, 0.23f, 0.03f, 0.35f), 3000, -0.04f, out haloMaterial); iris = MakeCurvedIris("FlameSclera", eyeRoot, val5, (Texture)(object)val, Color.white, 3010, 0f, out irisMaterial); pupil = MakeQuad("SinglePupil", eyeRoot, val5, (Texture)(object)val2, Color.white, 3020, SauronEyePortalPlugin.PupilInset.Value, out pupilMaterial); flameMaterial = new Material(val6); flameMaterial.mainTexture = (Texture)(object)val4; flameMaterial.renderQueue = 3015; ownedMaterials.Add(flameMaterial); if (SauronEyePortalPlugin.UseNativePortalFlames.Value) { flames = TryCreateNativePortalFlames(eyeRoot); } if ((Object)(object)flames == (Object)null) { flames = CreateEyeFlameSystem(eyeRoot, flameMaterial); usingNativeFlames = false; nativeFlameSource = "procedural fallback"; } if ((Object)(object)SauronEyePortalPlugin.Instance != (Object)null) { SauronEyePortalPlugin.Instance.LogFlameInfo("SAURON flame system: " + nativeFlameSource); } GameObject val7 = new GameObject("SauronEmberLight"); val7.transform.SetParent(eyeRoot, false); val7.transform.localPosition = new Vector3(0f, 0f, 0.09f); emberLight = val7.AddComponent<Light>(); emberLight.type = (LightType)2; emberLight.color = new Color(1f, 0.17f, 0.018f); emberLight.shadows = (LightShadows)0; } private Transform MakeQuad(string name, Transform parent, Shader shader, Texture texture, Color color, int queue, float z, out Material material) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown //IL_005d: Unknown result type (might be due to invalid IL or missing references) GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5); ((Object)obj).name = name; obj.layer = ((Component)this).gameObject.layer; obj.transform.SetParent(parent, false); obj.transform.localPosition = new Vector3(0f, 0f, z); material = new Material(shader); material.mainTexture = texture; material.color = color; material.renderQueue = queue; ownedMaterials.Add(material); ((Renderer)obj.GetComponent<MeshRenderer>()).material = material; Collider component = obj.GetComponent<Collider>(); if ((Object)(object)component != (Object)null) { Object.Destroy((Object)(object)component); } return obj.transform; } private Transform MakeCurvedIris(string name, Transform parent, Shader shader, Texture texture, Color color, int queue, float z, out Material material) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Expected O, but got Unknown GameObject val = new GameObject(name); val.layer = ((Component)this).gameObject.layer; val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, 0f, z); MeshFilter val2 = val.AddComponent<MeshFilter>(); MeshRenderer obj = val.AddComponent<MeshRenderer>(); material = new Material(shader); material.mainTexture = texture; material.color = color; material.renderQueue = queue; ownedMaterials.Add(material); ((Renderer)obj).material = material; int num = 24; int num2 = 12; Vector3[] array = (Vector3[])(object)new Vector3[(num + 1) * (num2 + 1)]; Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length]; int[] array3 = new int[num * num2 * 6]; for (int i = 0; i <= num2; i++) { for (int j = 0; j <= num; j++) { float num3 = (float)j / (float)num; float num4 = (float)i / (float)num2; float num5 = num3 - 0.5f; float num6 = num4 - 0.5f; float num7 = (1f - Mathf.Pow(Mathf.Abs(num5 * 2f), 1.7f)) * (1f - Mathf.Pow(Mathf.Abs(num6 * 2f), 1.7f)); num7 = Mathf.Max(0f, num7); float num8 = Mathf.Clamp(SauronEyePortalPlugin.EyeDepth.Value, 0f, 0.3f); array[i * (num + 1) + j] = new Vector3(num5, num6, (0f - num7) * num8); array2[i * (num + 1) + j] = new Vector2(num3, num4); } } int num9 = 0; for (int k = 0; k < num2; k++) { for (int l = 0; l < num; l++) { int num10 = k * (num + 1) + l; int num11 = num10 + 1; int num12 = num10 + num + 1; int num13 = num12 + 1; array3[num9++] = num10; array3[num9++] = num12; array3[num9++] = num11; array3[num9++] = num11; array3[num9++] = num12; array3[num9++] = num13; } } Mesh val3 = new Mesh(); ((Object)val3).name = "SauronEyeCurvedSclera"; val3.vertices = array; val3.uv = array2; val3.triangles = array3; val3.RecalculateNormals(); val2.sharedMesh = val3; ownedMeshes.Add(val3); return val.transform; } private void UpdateBillboard() { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (!((Object)(object)visualRoot == (Object)null) && !((Object)(object)billboardRoot == (Object)null)) { visualRoot.transform.localPosition = new Vector3(0f, SauronEyePortalPlugin.EyeVerticalOffset.Value, 0f); Camera main = Camera.main; if (!((Object)(object)main == (Object)null)) { billboardRoot.rotation = Quaternion.LookRotation(((Component)main).transform.forward, ((Component)main).transform.up); } } } private void HideOriginalMesh() { if ((Object)(object)portal == (Object)null) { return; } Renderer[] componentsInChildren = ((Component)portal).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && (!((Object)(object)visualRoot != (Object)null) || !((Component)val).transform.IsChildOf(visualRoot.transform)) && !(val is ParticleSystemRenderer) && (val is MeshRenderer || val is SkinnedMeshRenderer)) { if (!hiddenMeshRenderers.ContainsKey(val)) { hiddenMeshRenderers[val] = val.enabled; } val.enabled = false; } } } private void RestoreOriginalMesh() { foreach (KeyValuePair<Renderer, bool> hiddenMeshRenderer in hiddenMeshRenderers) { if ((Object)(object)hiddenMeshRenderer.Key != (Object)null) { hiddenMeshRenderer.Key.enabled = hiddenMeshRenderer.Value; } } hiddenMeshRenderers.Clear(); } private void HidePortalParticleRenderers() { if ((Object)(object)portal == (Object)null) { return; } ParticleSystemRenderer[] componentsInChildren = ((Component)portal).GetComponentsInChildren<ParticleSystemRenderer>(true); foreach (ParticleSystemRenderer val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && (!((Object)(object)visualRoot != (Object)null) || !((Component)val).transform.IsChildOf(visualRoot.transform))) { if (!hiddenParticleRenderers.ContainsKey(val)) { hiddenParticleRenderers[val] = ((Renderer)val).enabled; } ((Renderer)val).enabled = false; } } } private void RestorePortalParticleRenderers() { foreach (KeyValuePair<ParticleSystemRenderer, bool> hiddenParticleRenderer in hiddenParticleRenderers) { if ((Object)(object)hiddenParticleRenderer.Key != (Object)null) { ((Renderer)hiddenParticleRenderer.Key).enabled = hiddenParticleRenderer.Value; } } hiddenParticleRenderers.Clear(); } private ParticleSystem TryCreateNativePortalFlames(Transform parent) { //IL_01a7: 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_01c9: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: 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_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02eb: Unknown result type (might be due to invalid IL or missing references) //IL_02f0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)portal == (Object)null) { return null; } ParticleSystem[] componentsInChildren = ((Component)portal).GetComponentsInChildren<ParticleSystem>(true); ParticleSystem val = null; int num = int.MinValue; ParticleSystem[] array = componentsInChildren; foreach (ParticleSystem val2 in array) { if ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).GetComponent<ParticleSystemRenderer>() == (Object)null || ((Object)(object)visualRoot != (Object)null && ((Component)val2).transform.IsChildOf(visualRoot.transform))) { continue; } ParticleSystemRenderer component = ((Component)val2).GetComponent<ParticleSystemRenderer>(); if (!((Object)(object)((Renderer)component).sharedMaterial == (Object)null)) { string text = ((Object)val2).name.ToLowerInvariant(); string text2 = ((Object)((Renderer)component).sharedMaterial).name.ToLowerInvariant(); string text3 = text + " " + text2; int num2 = 0; if (text3.Contains("flame")) { num2 += 100; } if (text3.Contains("fire")) { num2 += 90; } if (text3.Contains("burn")) { num2 += 50; } if (text3.Contains("portal")) { num2 += 15; } if (text3.Contains("smoke")) { num2 -= 100; } if (text3.Contains("spark")) { num2 -= 50; } if (text3.Contains("ember")) { num2 -= 20; } if (num2 > num) { num = num2; val = val2; } } } if ((Object)(object)val == (Object)null || num <= 0) { return null; } try { GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, parent, false); ((Object)val3).name = "SauronNativePortalFlameTemplate"; val3.transform.localPosition = new Vector3(0f, 0f, 0.015f); val3.transform.localRotation = Quaternion.identity; val3.transform.localScale = Vector3.one; foreach (Transform item in val3.transform) { Object.Destroy((Object)(object)((Component)item).gameObject); } MonoBehaviour[] components = val3.GetComponents<MonoBehaviour>(); for (int i = 0; i < components.Length; i++) { ((Behaviour)components[i]).enabled = false; } Collider[] components2 = val3.GetComponents<Collider>(); for (int i = 0; i < components2.Length; i++) { Object.Destroy((Object)(object)components2[i]); } ParticleSystem component2 = val3.GetComponent<ParticleSystem>(); ParticleSystemRenderer component3 = val3.GetComponent<ParticleSystemRenderer>(); if ((Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null) { Object.Destroy((Object)(object)val3); return null; } component2.Stop(true, (ParticleSystemStopBehavior)0); MainModule main = component2.main; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).playOnAwake = false; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0; ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f); ((MainModule)(ref main)).maxParticles = 800; EmissionModule emission = component2.emission; ((EmissionModule)(ref emission)).enabled = false; ShapeModule shape = component2.shape; ((ShapeModule)(ref shape)).enabled = false; ((Renderer)component3).enabled = true; component2.Play(); usingNativeFlames = true; nativeFlameSource = ((Object)val).name + " / " + ((Object)((Renderer)((Component)val).GetComponent<ParticleSystemRenderer>()).sharedMaterial).name; return component2; } catch (Exception ex) { if ((Object)(object)SauronEyePortalPlugin.Instance != (Object)null) { SauronEyePortalPlugin.Instance.LogFlameWarning("Could not clone native portal flames: " + ex.Message); } return null; } } private ParticleSystem CreateEyeFlameSystem(Transform parent, Material material) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("EyeScleraFlames"); val.transform.SetParent(parent, false); val.transform.localPosition = new Vector3(0f, 0f, 0.01f); ParticleSystem obj = val.AddComponent<ParticleSystem>(); MainModule main = obj.main; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).playOnAwake = false; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0; ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f); ((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.55f); ((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(0.1f); ((MainModule)(ref main)).maxParticles = 900; EmissionModule emission = obj.emission; ((EmissionModule)(ref emission)).enabled = false; ShapeModule shape = obj.shape; ((ShapeModule)(ref shape)).enabled = false; ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>(); component.renderMode = (ParticleSystemRenderMode)0; ((Renderer)component).material = material; obj.Play(); return obj; } private void EmitEyeFlames() { //IL_01bf: 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_0211: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)flames == (Object)null || !SauronEyePortalPlugin.EyeFlames.Value) { return; } float num = Mathf.Clamp(SauronEyePortalPlugin.EyeScale.Value, 0.1f, 30f); float num2 = Mathf.Max(0.05f, SauronEyePortalPlugin.EyeWidth.Value) * num; float num3 = Mathf.Max(0.05f, SauronEyePortalPlugin.EyeHeight.Value) * num; float num4 = Mathf.Clamp(SauronEyePortalPlugin.FlameDensity.Value, 0f, 240f); float num5 = Mathf.Clamp(SauronEyePortalPlugin.FlameLength.Value, 0.05f, 2f) * num3; float num6 = Mathf.Lerp(1f, 0.05f, blinkAmount); flameRemainder += num4 * Mathf.Min(Time.deltaTime, 0.1f); int num7 = Mathf.Min(32, Mathf.FloorToInt(flameRemainder)); flameRemainder -= num7; for (int i = 0; i < num7; i++) { float num8 = Random.Range(-0.96f, 0.96f); float num9 = AlmondRim(num8); bool num10 = Random.value < 0.72f; float num11 = 0.9f + 0.1f * Random.value; float num12 = (num10 ? 1f : (-1f)) * num9 * num11; if (Random.value < 0.16f) { num8 = Mathf.Sign(Random.Range(-1f, 1f)) * Random.Range(0.72f, 0.98f); num9 = AlmondRim(num8); num12 = Random.Range(-0.3f, 0.42f) * num9; } if (!(Mathf.Abs(num8) < 0.28f) || !(Mathf.Abs(num12) < num9 * 0.74f)) { EmitParams val = default(EmitParams); ((EmitParams)(ref val)).position = new Vector3(num8 * num2 * 0.48f, num12 * num3 * 0.46f * num6, 0f); ((EmitParams)(ref val)).velocity = new Vector3(num8 * num5 * 0.05f, num5 * Random.Range(0.75f, 1.35f), 0f); ((EmitParams)(ref val)).startLifetime = Random.Range(0.45f, 0.95f); ((EmitParams)(ref val)).startSize = Mathf.Max(0.025f, num3 * Random.Range(0.13f, 0.25f)); ((EmitParams)(ref val)).startColor = Color32.op_Implicit(usingNativeFlames ? Color.white : Color.Lerp(new Color(1f, 0.1f, 0.01f, 0.88f), new Color(1f, 0.82f, 0.16f, 0.95f), Random.value)); flames.Emit(val, 1); } } } private void UpdateBlink() { if (blinkStart < 0f) { if (Time.time >= nextBlink) { blinkStart = Time.time; } blinkAmount = 0f; return; } float num = Mathf.Max(0.05f, SauronEyePortalPlugin.BlinkDuration.Value); float num2 = (Time.time - blinkStart) / num; if (num2 >= 1f) { blinkStart = -1f; blinkAmount = 0f; ScheduleBlink(initial: false); } else { blinkAmount = ((num2 < 0.5f) ? (num2 * 2f) : ((1f - num2) * 2f)); } } private void ScheduleBlink(bool initial) { float num = Mathf.Max(0.5f, SauronEyePortalPlugin.BlinkIntervalMin.Value); float num2 = Mathf.Max(num, SauronEyePortalPlugin.BlinkIntervalMax.Value); nextBlink = Time.time + (initial ? Random.Range(0.7f, 1.5f) : Random.Range(num, num2)); } private void AnimateEye() { //IL_0119: 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_0157: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0348: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)iris == (Object)null) && !((Object)(object)pupil == (Object)null) && !((Object)(object)halo == (Object)null)) { float num = Mathf.Clamp(SauronEyePortalPlugin.EyeScale.Value, 0.1f, 30f); float num2 = Mathf.Max(0.05f, SauronEyePortalPlugin.EyeWidth.Value) * num; float num3 = Mathf.Max(0.05f, SauronEyePortalPlugin.EyeHeight.Value) * num; float num4 = Mathf.Lerp(1f, 0.05f, blinkAmount); float num5 = Time.time * Mathf.Max(0.01f, SauronEyePortalPlugin.ScanSpeed.Value) + scanSeed; float num6 = (SauronEyePortalPlugin.ScanEnabled.Value ? (0.77f * Mathf.Sin(num5) + 0.23f * Mathf.Sin(num5 * 0.39f + 1.3f)) : 0f); float num7 = Mathf.Clamp(SauronEyePortalPlugin.ScanTiltDegrees.Value, 0f, 20f); eyeRoot.localRotation = Quaternion.Euler(0f, 0f, (0f - num7) * num6); iris.localScale = new Vector3(num2, num3 * num4, 1f); halo.localScale = new Vector3(num2 * 1.18f, num3 * 1.22f * num4, 1f); float num8 = Mathf.Clamp(SauronEyePortalPlugin.PupilVisualWidth.Value, 0.08f, 0.4f); float num9 = Mathf.Clamp(SauronEyePortalPlugin.PupilHeightFraction.Value, 0.18f, 0.86f); pupil.localScale = new Vector3(num2 * num8, num3 * num9 * num4, 1f); float num10 = num2 * 0.5f; float num11 = num2 * num8 * 0.5f; float num12 = Mathf.Min(num2 * Mathf.Clamp(SauronEyePortalPlugin.ScanAmplitude.Value, 0f, 0.3f), Mathf.Max(0f, num10 - num11 - num2 * 0.08f)); pupil.localPosition = new Vector3(num6 * num12, 0f, SauronEyePortalPlugin.PupilInset.Value); float num13 = Mathf.Clamp(SauronEyePortalPlugin.EmberIntensity.Value, 0.2f, 4f); float num14 = 0.83f + 0.17f * Mathf.Sin(Time.time * 2.1f); float num15 = Mathf.Clamp01(SauronEyePortalPlugin.ScleraFlicker.Value); float num16 = 0.65f + 0.16f * Mathf.Sin(Time.time * 10.7f + scanSeed) + 0.11f * Mathf.Sin(Time.time * 15.4f + scanSeed * 1.8f); if ((Object)(object)irisMaterial != (Object)null) { irisMaterial.color = new Color(1f, Mathf.Clamp01(0.72f + num16 * 0.18f * num15), Mathf.Clamp01(0.14f + num16 * 0.1f), 1f); } if ((Object)(object)haloMaterial != (Object)null) { haloMaterial.color = new Color(1f, 0.2f + 0.05f * num14, 0.02f, Mathf.Clamp01(0.26f * num13 * num14)); } if ((Object)(object)pupilMaterial != (Object)null) { pupilMaterial.color = new Color(1f, 1f, 1f, 1f); } if ((Object)(object)emberLight != (Object)null) { ((Behaviour)emberLight).enabled = SauronEyePortalPlugin.EmberLightEnabled.Value; emberLight.intensity = Mathf.Clamp(num13 * (0.65f + 0.14f * Mathf.Sin(Time.time * 2f)), 0f, 6f); emberLight.range = Mathf.Max(0f, SauronEyePortalPlugin.EmberLightRange.Value); } } } private float AlmondRim(float x) { return Mathf.Pow(Mathf.Max(0f, 1f - Mathf.Abs(x)), 0.72f); } private Texture2D CreateScleraTexture(int width, int height) { //IL_0071: 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_01bb: 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) //IL_01d6: 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_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0175: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) Texture2D val = NewTexture(width, height); Color val2 = default(Color); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float num = ((float)j - (float)(width - 1) * 0.5f) / ((float)width * 0.5f); float num2 = ((float)i - (float)(height - 1) * 0.5f) / ((float)height * 0.5f); float num3 = AlmondRim(num); float num4 = Mathf.Abs(num2) / Mathf.Max(0.001f, num3); if (num4 > 1f) { val.SetPixel(j, i, Color.clear); continue; } float num5 = Smooth01(0.7f, 0.98f, num4); float num6 = Mathf.Clamp01(1f - Mathf.Abs(num) * 1.25f - num4 * 0.55f); float num7 = 0.5f + 0.5f * Mathf.Sin(num * 14f + num2 * 5f + Mathf.Sin(num * 23f) * 0.7f); float num8 = 0.5f + 0.5f * Mathf.Sin(num * 9f + 0.8f * num7); if (num4 > 0.9f) { ((Color)(ref val2))..ctor(0.1f, 0.01f, 0.005f, 0.96f); } else if (num4 > 0.72f) { val2 = Color.Lerp(new Color(0.78f, 0.07f, 0.01f, 1f), new Color(1f, 0.35f, 0.04f, 1f), num8); } else { float num9 = 0.25f + 0.75f * num6; val2 = Color.Lerp(new Color(0.92f, 0.22f, 0.03f, 1f), new Color(1f, 0.72f, 0.1f, 1f), num9 * (0.65f + 0.35f * num7)); } float num10 = 1f - 0.22f * Mathf.Exp((0f - num * num) * 11f); val2.r *= num10; val2.g *= num10; val2.b *= num10; val2.a *= Mathf.Clamp01((1f - num5) * 4f); val.SetPixel(j, i, val2); } } val.Apply(); return val; } private Texture2D CreateSlitTexture(int width, int height) { //IL_00a0: 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_00ca: Unknown result type (might be due to invalid IL or missing references) Texture2D val = NewTexture(width, height); float num = (float)(width - 1) * 0.5f; float num2 = (float)(height - 1) * 0.5f; for (int i = 0; i < height; i++) { float num3 = Mathf.Abs(((float)i - num2) / ((float)height * 0.5f)); float num4 = Mathf.Pow(Mathf.Max(0f, 1f - num3), 0.62f); float num5 = Mathf.Max(0.4f, (float)width * 0.33f * num4); float num6 = num5 + 2f; for (int j = 0; j < width; j++) { float num7 = Mathf.Abs((float)j - num); if (num3 >= 1f || num7 > num6) { val.SetPixel(j, i, Color.clear); continue; } if (num7 <= num5) { val.SetPixel(j, i, new Color(0.01f, 0f, 0.004f, 0.99f)); continue; } float num8 = 1f - (num7 - num5) / Mathf.Max(0.001f, num6 - num5); val.SetPixel(j, i, new Color(1f, 0.2f, 0.02f, 0.55f * num8)); } } val.Apply(); return val; } private Texture2D CreateHaloTexture(int width, int height) { //IL_0081: Unknown result type (might be due to invalid IL or missing references) Texture2D val = NewTexture(width, height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float num = ((float)j - (float)(width - 1) * 0.5f) / ((float)width * 0.5f); float num2 = ((float)i - (float)(height - 1) * 0.5f) / ((float)height * 0.5f); float num3 = Mathf.Sqrt(num * num + num2 * num2); float num4 = Mathf.Pow(Mathf.Clamp01(1f - num3), 2f) * 0.34f; val.SetPixel(j, i, new Color(1f, 0.2f, 0.015f, num4)); } } val.Apply(); return val; } private Texture2D CreateFlameTexture(int width, int height) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) Texture2D val = NewTexture(width, height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { float num = ((float)j - (float)(width - 1) * 0.5f) / ((float)width * 0.5f); float num2 = (float)i / (float)(height - 1); float num3 = Mathf.Clamp01((0.7f * Mathf.Pow(Mathf.Max(0f, 1f - num2), 0.82f) + 0.04f - Mathf.Abs(num)) * 7f) * Mathf.Pow(1f - num2, 0.66f); Color val2 = Color.Lerp(new Color(1f, 0.11f, 0.01f, 0f), new Color(1f, 0.85f, 0.22f, 1f), 1f - num2); val2.a = num3 * 0.78f; val.SetPixel(j, i, val2); } } val.Apply(); return val; } private Texture2D NewTexture(int width, int height) { //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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return new Texture2D(width, height, (TextureFormat)4, false) { wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)1 }; } private float Smooth01(float edge0, float edge1, float x) { x = Mathf.Clamp01((x - edge0) / Mathf.Max(0.0001f, edge1 - edge0)); return x * x * (3f - 2f * x); } } }