using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("HTFWater")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("HTFWater")] [assembly: AssemblyTitle("HTFWater")] [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 HTFWater { [BepInPlugin("yoxi.htf.water", "Better Oceans", "2.1.0")] public class WaterPlugin : BaseUnityPlugin { public const string Guid = "yoxi.htf.water"; internal static ManualLogSource Log; internal static Material Tuned; internal static Shader Sea; internal static Shader SeaLit; internal static Shader SeaClassic; internal static Material TunedLit; internal static Material TunedClassic; internal static ConfigEntry Quality; internal static ConfigEntry Enabled; internal static ConfigEntry FollowSky; internal static ConfigEntry Brightness; internal static ConfigEntry Whitecaps; internal static ConfigEntry SkyReflection; internal static ConfigEntry SkyResolution; internal static ConfigEntry SkyRefresh; internal static ConfigEntry Shoreline; internal static ConfigEntry AdoptStray; internal static ConfigEntry Tuner; internal static ConfigEntry TintClouds; internal static ConfigEntry AutoHaze; internal static ConfigEntry SeeInto; internal static ConfigEntry Clarity; internal static ConfigEntry ShowWorking; internal static ConfigEntry SwellHeight; internal static ConfigEntry WavesOn; internal static ConfigEntry SwellLength; internal static ConfigEntry SwellWaves; internal static ConfigEntry SwellSpread; internal static ConfigEntry SwellSeed; internal static ConfigEntry MeshStep; internal static ConfigEntry SwellSteep; internal static ConfigEntry SwellSpeed; internal static ConfigEntry Breakers; internal static ConfigEntry SurfReach; internal static ConfigEntry Refract; internal static ConfigEntry BreakType; internal static ConfigEntry SwashRun; internal static ConfigEntry LightsOnWater; internal static ConfigEntry LitShader; internal static ConfigEntry Wake; internal static ConfigEntry WakeLife; internal static ConfigEntry WakeWidth; internal static ConfigEntry ShoreDetail; private static readonly string[] Floats = new string[22] { "_Fresnel", "_Mottle", "_Chop", "_ChopScale", "_Drift", "_Churn", "_Ride", "_SwellNormal", "_Gloss", "_GlitterStrength", "_Sparkle", "_Foam", "_Haze", "_HazeRange", "_Streaks", "_SubStrength", "_Whitecaps", "_Exposure", "_ShoreFoam", "_ShoreWidth", "_ShoreWash", "_ShallowDepth" }; private static readonly string[] Colours = new string[7] { "_Shallow", "_Deep", "_SkyTint", "_Horizon", "_SunColour", "_FoamColour", "_Sub" }; internal static bool IsUltra { get { if (Quality != null) { return Quality.Value == "Ultra"; } return false; } } internal static bool IsLit { get { if (Quality != null) { return Quality.Value != "Classic"; } return true; } } internal static float MeshStepWanted() { float num = ((MeshStep != null) ? MeshStep.Value : 1f); if (!IsUltra) { return num; } return Mathf.Min(num, 0.5f); } private void Awake() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Expected O, but got Unknown //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Expected O, but got Unknown //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Expected O, but got Unknown //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Expected O, but got Unknown //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Expected O, but got Unknown //IL_02b3: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Expected O, but got Unknown //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Expected O, but got Unknown //IL_0321: Unknown result type (might be due to invalid IL or missing references) //IL_032b: Expected O, but got Unknown //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Expected O, but got Unknown //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Expected O, but got Unknown //IL_03ee: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Expected O, but got Unknown //IL_042b: Unknown result type (might be due to invalid IL or missing references) //IL_0435: Expected O, but got Unknown //IL_0468: Unknown result type (might be due to invalid IL or missing references) //IL_0472: Expected O, but got Unknown //IL_04c5: Unknown result type (might be due to invalid IL or missing references) //IL_04cf: Expected O, but got Unknown //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_050c: Expected O, but got Unknown //IL_053f: Unknown result type (might be due to invalid IL or missing references) //IL_0549: Expected O, but got Unknown //IL_057c: Unknown result type (might be due to invalid IL or missing references) //IL_0586: Expected O, but got Unknown //IL_05b9: Unknown result type (might be due to invalid IL or missing references) //IL_05c3: Expected O, but got Unknown //IL_05f6: Unknown result type (might be due to invalid IL or missing references) //IL_0600: Expected O, but got Unknown //IL_0633: Unknown result type (might be due to invalid IL or missing references) //IL_063d: Expected O, but got Unknown //IL_0717: Unknown result type (might be due to invalid IL or missing references) //IL_0721: Expected O, but got Unknown //IL_0750: Unknown result type (might be due to invalid IL or missing references) //IL_0755: Unknown result type (might be due to invalid IL or missing references) //IL_0765: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind("Water", "Enabled", true, "Replace the game's flat sea with the detailed one. Turn this off to get the shipped water back."); FollowSky = ((BaseUnityPlugin)this).Config.Bind("Water", "FollowTheSky", true, "Let the sea answer to the real light: it darkens at night, warms at sunset and greys under storms. Needs nothing else installed, but this is what makes it sit right with a day-night mod."); Brightness = ((BaseUnityPlugin)this).Config.Bind("Water", "Brightness", 1f, new ConfigDescription("Overall light level of the sea. Below 1 is a darker, deeper ocean; above 1 is a brighter tropical one.", (AcceptableValueBase)(object)new AcceptableValueRange(0.3f, 2f), Array.Empty())); Whitecaps = ((BaseUnityPlugin)this).Config.Bind("Water", "Whitecaps", -1f, new ConfigDescription("How much of the sea is allowed to break white. -1 keeps the value the look was tuned with.", (AcceptableValueBase)(object)new AcceptableValueRange(-1f, 1f), Array.Empty())); SkyReflection = ((BaseUnityPlugin)this).Config.Bind("Reflection", "ReflectTheSky", true, "Reflect the sky that is actually above you - sunset, stars, moon, storm clouds - instead of a fixed blue. This is what makes the sea part of the scene rather than a blue floor. Costs a little performance; turn it off on a weak machine and the water falls back to a sky-coloured gradient that still follows the light."); SkyResolution = ((BaseUnityPlugin)this).Config.Bind("Reflection", "Resolution", 128, new ConfigDescription("Size of the sky reflection. 64 is cheap, 128 is the sweet spot, 256 is sharp and costs more.", (AcceptableValueBase)(object)new AcceptableValueList(new int[4] { 32, 64, 128, 256 }), Array.Empty())); SkyRefresh = ((BaseUnityPlugin)this).Config.Bind("Reflection", "RefreshSeconds", 0.5f, new ConfigDescription("How often the sky reflection is re-rendered. The sky changes slowly, so this can be lazy - raise it if the framerate suffers.", (AcceptableValueBase)(object)new AcceptableValueRange(0.1f, 5f), Array.Empty())); Wake = ((BaseUnityPlugin)this).Config.Bind("Water", "BoatWake", true, "Boats churn the water behind them and it fades away. The game has none of this: it fires splash particles at the hull and leaves nothing on the sea. Works for every boat on the water, not only yours."); WakeLife = ((BaseUnityPlugin)this).Config.Bind("Water", "WakeSeconds", 3.2f, new ConfigDescription("How long a boat's wake takes to fade away.", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 20f), Array.Empty())); WakeWidth = ((BaseUnityPlugin)this).Config.Bind("Water", "WakeWidth", 1f, new ConfigDescription("How wide the churned lane behind a boat is.", (AcceptableValueBase)(object)new AcceptableValueRange(0.2f, 3f), Array.Empty())); Quality = ((BaseUnityPlugin)this).Config.Bind("Water", "Quality", "Realistic", new ConfigDescription("Classic is the original Better Oceans look. Realistic is the spectrum sea, trimmed to run well - the default. Ultra is the same sea with nothing skipped, for PCs that can take it. The Shaders screen in the pause menu flips this.", (AcceptableValueBase)(object)new AcceptableValueList(new string[3] { "Classic", "Realistic", "Ultra" }), Array.Empty())); LitShader = ((BaseUnityPlugin)this).Config.Bind("Water", "UseTheLitSea", true, "The sea is lit by the game's own render pipeline, so torches, fog, shadows, reflections and the weather all reach it the same way they reach everything else. Turn this off for the older version that works its own lighting out - dimmer, and blind to nearby lights."); LightsOnWater = ((BaseUnityPlugin)this).Config.Bind("Water", "TorchesLightTheWater", true, "Let torches, lamps and other nearby lights fall on the sea. The game's own water is a lit surface and gets this automatically; ours is unlit and has to be handed the four nearest lights."); SeeInto = ((BaseUnityPlugin)this).Config.Bind("Seeing into it", "SeeIntoTheWater", 1, new ConfigDescription("Whether you can see the seabed through the shallows. The sea used to be genuinely opaque - the depth you could see was a painted colour, not the bottom showing through - which is what made it read as plastic. Set to 0 for exactly the old look.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 1), Array.Empty())); Clarity = ((BaseUnityPlugin)this).Config.Bind("Seeing into it", "SeeThisFarDown", 6f, new ConfigDescription("Roughly how many metres down you can still make the bottom out. Lower is murkier. Red light dies about three times faster than blue whatever this is set to, so the sand goes green before it goes dark - that is the thing that reads as water rather than as glass.", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 12f), Array.Empty())); ShowWorking = ((BaseUnityPlugin)this).Config.Bind("Seeing into it", "ShowTheWorking", 0, new ConfigDescription("Diagnostics. 0 normal, 1 how deep the water is (black 0m to white 10m), 2 what survives the water, 3 what is behind it, 4 fresnel, 5 green where there is real geometry behind the water and red where there is only open sea.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 5), Array.Empty())); WavesOn = ((BaseUnityPlugin)this).Config.Bind("Swell", "WavesOn", true, "Waves on or off. The Shaders screen in the pause menu flips this; WaveHeight below is remembered while they are off."); SwellHeight = ((BaseUnityPlugin)this).Config.Bind("Swell", "WaveHeight", 0.28f, new ConfigDescription("How big the real waves are, in metres, on top of the game's own three centimetres. Everything that floats rides these properly - the boat, the bobber, dropped items - because the buoyancy the game asks for is answered with the same maths the surface is drawn from. 0 is the game's flat sea. Try 0.3 first.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 3f), Array.Empty())); SwellLength = ((BaseUnityPlugin)this).Config.Bind("Swell", "LongestWave", 34f, new ConfigDescription("The length of the biggest train, in metres. Shorter is choppier, longer is a slow ocean roll.", (AcceptableValueBase)(object)new AcceptableValueRange(4f, 120f), Array.Empty())); SwellWaves = ((BaseUnityPlugin)this).Config.Bind("Swell", "HowManyWaves", 24, new ConfigDescription("How many wave components make up the sea. They are not chosen by hand: their lengths, heights and directions are drawn from the JONSWAP ocean spectrum, so the mix of long slow swell, chop and ripple is a real sea's mix. More is more convincing and costs a little GPU time.", (AcceptableValueBase)(object)new AcceptableValueRange(8, 64), Array.Empty())); SwellSpread = ((BaseUnityPlugin)this).Config.Bind("Swell", "WaveSpreadDegrees", 35f, new ConfigDescription("How widely the waves fan out either side of the wind. Crossing crests are what make a sea look chaotic rather than corrugated. Narrow at the peak, wider away from it, as real spreading is.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 80f), Array.Empty())); MeshStep = ((BaseUnityPlugin)this).Config.Bind("Swell", "MeshMetresPerVertex", 1f, new ConfigDescription("How finely the sea surface is rebuilt, in metres between vertices. The game ships one every 3.1m, which turns every wave into flat triangles. 1.0 is smooth and cheap (about 40,000 vertices). 0 leaves the game's mesh alone.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 4f), Array.Empty())); SwellSeed = ((BaseUnityPlugin)this).Config.Bind("Swell", "Seed", 1, "Which particular sea you get. The same seed and settings build the identical wave table on every machine, so a crew shares one ocean. Change it for a different arrangement of the same weather."); SwellSpeed = ((BaseUnityPlugin)this).Config.Bind("Swell", "HowFastItRolls", 0.6f, new ConfigDescription("How quickly the swell travels. The speed of each train relative to the others is real physics and is not touched by this - long waves always outrun short ones. This only slows the whole set, because a correct ocean swell reads as hurrying in a world this small.", (AcceptableValueBase)(object)new AcceptableValueRange(0.2f, 1.5f), Array.Empty())); Breakers = ((BaseUnityPlugin)this).Config.Bind("Swell", "WavesBreakOnTheShore", 1f, new ConfigDescription("Whitewater where the seabed rises enough to trip the waves over. Where they break is decided by the depth under them, not by distance from the sand - so a shelf breaks them far out and a steep drop lets them run right in. Needs waves: it does nothing at WaveHeight 0.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 2f), Array.Empty())); SurfReach = ((BaseUnityPlugin)this).Config.Bind("Swell", "HowFarOutTheyBreak", 2f, new ConfigDescription("How wide the surf zone is. Applied honestly, a 35cm swell breaks in under a metre and a half of water - a strip a metre wide that you cannot see. This gives the BREAKING TEST a bigger wave than the sea actually has, so the white forms further out. It changes nothing that floats: no height, no buoyancy, only where the foam is.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 8f), Array.Empty())); Refract = ((BaseUnityPlugin)this).Config.Bind("Swell", "WavesTurnToFaceTheShore", 1f, new ConfigDescription("Waves arrive parallel to a beach whatever direction they came from, because the part of a crest in shallow water slows down and the crest pivots. With this on they wrap around headlands, bunch up on points and open out into bays - all of it read off the shape of the coast, none of it authored. 0 leaves them as flat plane waves.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); BreakType = ((BaseUnityPlugin)this).Config.Bind("Swell", "BreakByBeachSlope", 1f, new ConfigDescription("Waves do not break one way. A flat sandy beach makes them SPILL - foam crumbles down the face over a wide band and lingers. A steeper one makes them PLUNGE - the crest throws forward and curls over in a hard narrow line. Steeper still and they SURGE, barely breaking at all and running straight up the beach. Which one you get is read off the slope under the wave, so one island does all three on different sides. 0 makes every break the same everywhere.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); SwashRun = ((BaseUnityPlugin)this).Config.Bind("Swell", "WaterRunsUpTheBeach", 1f, new ConfigDescription("What happens after a wave finishes breaking. It becomes a thin sheet that rushes up the beach face and then drains back more slowly than it came. The two look nothing alike - the uprush is a hard bright lacy edge, the backwash is stranded foam thinning on the sand - and the shader tells them apart by asking what the wave is about to do a quarter second from now.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 2f), Array.Empty())); SwellSteep = ((BaseUnityPlugin)this).Config.Bind("Swell", "CrestsPeak", 0.55f, new ConfigDescription("How peaked the crests are. 0 is a plain sine and looks like a swimming pool; higher gives sharp tops over broad flat troughs, which is what real swell does.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 1f), Array.Empty())); AutoHaze = ((BaseUnityPlugin)this).Config.Bind("Horizon", "HazeFollowsTheWeather", true, "A real horizon is not a line - it is where the air gets too thick to see through, close in a storm and far on a clear day. This lets the sea's distance fade follow the game's own fog instead of sitting at a fixed setting. Turn it off to control the haze yourself with F9."); TintClouds = ((BaseUnityPlugin)this).Config.Bind("Horizon", "TintTheBackgroundClouds", true, "The game's background cloud spheres are plain white at three times full brightness, and no sky mod repaints them - so they glare through at the horizon as a pale band under a sunset. This tints them to whatever colour the sky actually is. Nothing to do with the water, but it is the band you can see over it."); Tuner = ((BaseUnityPlugin)this).Config.Bind("Water", "TuningMenu", false, "Press F9 in game to open a panel of sliders for every look value, and watch the sea change as you drag. Save writes them beside the mod and they are used from then on. Meant for deciding how the water should look - leave it off for normal play."); AdoptStray = ((BaseUnityPlugin)this).Config.Bind("Water", "AdoptStrayWaterPlanes", true, "Some island scenes ship with a second water plane of their own, still wearing the game's original flat blue. Give it the same sea as everything else so it does not draw a mismatched band at the horizon."); Shoreline = ((BaseUnityPlugin)this).Config.Bind("Shore", "ShorelineFoam", true, "Foam washing up and back at the water's edge, and pale shallows over the sand. Measured by firing a grid of rays at the seabed when an island loads - it costs a moment on load and nothing afterwards."); ShoreDetail = ((BaseUnityPlugin)this).Config.Bind("Shore", "Detail", 256, new ConfigDescription("Resolution of that seabed measurement. 256 across the island is about a metre per sample. Lower it if the load pause is noticeable.", (AcceptableValueBase)(object)new AcceptableValueList(new int[4] { 64, 128, 256, 384 }), Array.Empty())); if (!Enabled.Value) { ((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Oceans starts switched off. The Shaders screen in the pause menu turns it on."); } if (LoadBundle()) { Harmony val = new Harmony("yoxi.htf.water"); val.PatchAll(typeof(Hooks)); val.PatchAll(typeof(TheSeaHasWavesNow)); val.PatchAll(typeof(ShaderMenu.PauseHooks)); Log.LogInfo((object)"Patched WaterManager.GetWaterHeight, so everything that floats rides the swell."); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Better Water is in. Waiting for the sea."); } } private bool LoadBundle() { //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Expected O, but got Unknown //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string[] array = new string[2] { Path.Combine(directoryName, "htfwater.bundle"), Path.Combine(Paths.PluginPath, "htfwater.bundle") }; foreach (string text in array) { if (!File.Exists(text)) { continue; } AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)this).Logger.LogError((object)("Found " + text + " but it would not load - is it built for this Unity?")); return false; } LitShader.Value = IsLit; Material[] array2 = val.LoadAllAssets(); foreach (Material val2 in array2) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null)) { if (((Object)val2.shader).name == "HTF/WaterLit") { SeaLit = val2.shader; TunedLit = new Material(val2.shader); } else if (((Object)val2.shader).name == "HTF/Water") { SeaClassic = val2.shader; TunedClassic = new Material(val2.shader); } } } Sea = (IsLit ? (SeaLit ?? SeaClassic) : (SeaClassic ?? SeaLit)); Tuned = (((Object)(object)Sea == (Object)(object)SeaLit) ? TunedLit : TunedClassic); if ((Object)(object)Sea != (Object)null && ((Object)(object)SeaLit == (Object)null || (Object)(object)SeaClassic == (Object)null)) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Only " + ((Object)Sea).name + " is in the bundle, so the quality switch cannot change shader. Re-export from Unity to get both.")); } else if ((Object)(object)Sea != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Using " + ((Object)Sea).name + " (" + Quality.Value + ")" + (IsLit ? " - the pipeline lights this one." : " - this one lights itself."))); } if ((Object)(object)Tuned != (Object)null) { ((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded the sea from " + text + ".")); return true; } ((BaseUnityPlugin)this).Logger.LogError((object)"htfwater.bundle carries no HTF/Water material."); return false; } ((BaseUnityPlugin)this).Logger.LogError((object)"htfwater.bundle is missing. It must sit beside HTFWater.dll."); return false; } internal static void Dress(Material live) { //IL_006c: Unknown result type (might be due to invalid IL or missing references) string[] floats = Floats; foreach (string text in floats) { if (Tuned.HasProperty(text) && live.HasProperty(text)) { live.SetFloat(text, Tuned.GetFloat(text)); } } floats = Colours; foreach (string text2 in floats) { if (Tuned.HasProperty(text2) && live.HasProperty(text2)) { live.SetColor(text2, Tuned.GetColor(text2)); } } if (Whitecaps.Value >= 0f) { live.SetFloat("_Whitecaps", Whitecaps.Value); } } } internal static class Hooks { [HarmonyPatch(typeof(WaterManager), "Awake")] [HarmonyPostfix] private static void OnWaterAwake(WaterManager __instance) { if ((Object)(object)WaterPlugin.Sea == (Object)null) { return; } try { ((Component)__instance).gameObject.AddComponent().Bind(__instance); } catch (Exception ex) { WaterPlugin.Log.LogError((object)("Could not take over the water: " + ex)); } } } public class SeaKeeper : MonoBehaviour { private const BindingFlags Priv = BindingFlags.Instance | BindingFlags.NonPublic; private Material _mat; private Renderer[] _tiles; private Light _sun; private float _nextLook; private Color _tunedHorizon; private Color _tunedSky; private Color _tunedSun; private Texture2D _shoreMap; private float[] _shoreDist; private Vector2[] _shoreToSea; private int _shoreCells; private float _shoreStep; private Vector3 _shoreCentre; private float _shoreExtent; private float _nextShore; private float _checkAt = -1f; private float _strayUntil; private float _nextStray; private int _strayCount; private readonly List _clouds = new List(); private readonly List _cloudWas = new List(); private float _nextCloud; private float dayLitLast = 1f; private float _sunPeak; private float _ambPeak; private float _fogBase = -1f; private float sceneLast = 1f; private float overcastLast; private ReflectionProbe _probe; private Transform _probeT; private Camera _skyCam; private RenderTexture _skyRT; private float _nextSky; private float _nextMask; private float _nextSay; private float _nextRead; private bool _skyFound; private bool _usingShared; private Texture2D _read; private Color _skyAtHorizon = Color.clear; private readonly Color[] _faces = (Color[])(object)new Color[4]; private float _waterY; public static SeaKeeper Instance; private Material _vanilla; private static Material VanillaKept; private Material _ours; private bool _live = true; private bool _startChecked; private Transform _main; private float _modelScale = 1f; private Action _fogAtRender; private readonly Dictionary _seaLayers = new Dictionary(); private float _nextMaskLook = 5f; private bool _maskSaid; private float _mirrorWanted = -1f; private static bool _askedAboutTextures; public static bool SceneTexturesOK; private float _nextAskSay; private float _lastAskSay; private string found = ""; private Color _wAmb; private Color _wFog; private float _wFogD; private float _wRefl; private float _wAmbI; private int _wSky = -1; private int _wCube = -1; private float _wSunI; private Color _wSunC; private int _wSuns; private int _wSunN; private int _wSunCN; private Color _rAmb; private Color _rFog; private float _rRefl; private int _rAmbN; private int _rFogN; private int _rReflN; private int _wAmbN; private int _wFogN; private int _wFogDN; private int _wReflN; private int _wAmbIN; private int _wSkyN; private int _wCubeN; private float _wSayAt; private bool _wHooked; private readonly Dictionary _wCams = new Dictionary(); private readonly List _cloudNow = new List(); private float _cloudSayAt; private readonly List _lamps = new List(); private float _nextLampScan; private readonly Vector4[] _lampPos = (Vector4[])(object)new Vector4[4]; private readonly Vector4[] _lampCol = (Vector4[])(object)new Vector4[4]; public static float Clock { get; private set; } private void PutColor(string name, Color v) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_mat != (Object)null && _mat.HasProperty(name)) { _mat.SetColor(name, v); } } private void PutFloat(string name, float v) { if ((Object)(object)_mat != (Object)null && _mat.HasProperty(name)) { _mat.SetFloat(name, v); } } private void PutVector(string name, Vector4 v) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_mat != (Object)null && _mat.HasProperty(name)) { _mat.SetVector(name, v); } } private void PutTexture(string name, Texture v) { if ((Object)(object)_mat != (Object)null && _mat.HasProperty(name)) { _mat.SetTexture(name, v); } } private Color TakeColor(string name, Color fallback) { //IL_001c: 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) if (!((Object)(object)_mat != (Object)null) || !_mat.HasProperty(name)) { return fallback; } return _mat.GetColor(name); } private float TakeFloat(string name, float fallback) { if (!((Object)(object)_mat != (Object)null) || !_mat.HasProperty(name)) { return fallback; } return _mat.GetFloat(name); } public void SetLive(bool on) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown if ((Object)(object)_mat == (Object)null || on == _live) { return; } _live = on; if (!on) { _ours = new Material(_mat); if ((Object)(object)_vanilla != (Object)null) { _mat.shader = _vanilla.shader; _mat.CopyPropertiesFromMaterial(_vanilla); _mat.renderQueue = _vanilla.renderQueue; } TheSeaHasWavesNow.Muted = true; WakeMaker component = ((Component)this).GetComponent(); if ((Object)(object)component != (Object)null) { ((Behaviour)component).enabled = false; } if ((Object)(object)_probeT != (Object)null) { ((Component)_probeT).gameObject.SetActive(false); } WaterPlugin.Log.LogInfo((object)("Better Oceans off - the game's own water is back (" + (((Object)(object)_vanilla != (Object)null && (Object)(object)_vanilla.shader != (Object)null) ? ((Object)_vanilla.shader).name : "?") + ").")); return; } if ((Object)(object)_ours != (Object)null) { _mat.shader = _ours.shader; _mat.CopyPropertiesFromMaterial(_ours); } else { _mat.shader = WaterPlugin.Sea; WaterPlugin.Dress(_mat); } try { _mat.SetVectorArray("_WaveA", Swell.A); _mat.SetVectorArray("_WaveB", Swell.B); } catch { } TheSeaHasWavesNow.Muted = false; WakeOn(WaterPlugin.Wake.Value); SkyOn(WaterPlugin.SkyReflection.Value); LightsOn(WaterPlugin.LightsOnWater.Value); ShoreOn(WaterPlugin.Shoreline.Value); if ((Object)(object)_mat.shader != (Object)(object)WaterPlugin.Sea) { ApplyQuality(WaterPlugin.Quality.Value); } WaterPlugin.Log.LogInfo((object)"Better Oceans on."); } public void ApplyQuality(string q) { //IL_016b: 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) bool flag = q != "Classic"; WaterPlugin.LitShader.Value = flag; Shader val = (flag ? (WaterPlugin.SeaLit ?? WaterPlugin.SeaClassic) : (WaterPlugin.SeaClassic ?? WaterPlugin.SeaLit)); if ((Object)(object)val == (Object)null) { return; } WaterPlugin.Sea = val; WaterPlugin.Tuned = (((Object)(object)val == (Object)(object)WaterPlugin.SeaLit) ? WaterPlugin.TunedLit : WaterPlugin.TunedClassic); if ((Object)(object)_mat != (Object)null && _live) { _mat.shader = val; WaterPlugin.Dress(_mat); WaterTuner.Load(_mat); PutFloat("_Model_Scale", _modelScale); try { _mat.SetVectorArray("_WaveA", Swell.A); _mat.SetVectorArray("_WaveB", Swell.B); } catch { } ShoreOn(WaterPlugin.Shoreline.Value); WakeOn(WaterPlugin.Wake.Value); LightsOn(WaterPlugin.LightsOnWater.Value); if (!WaterPlugin.SkyReflection.Value) { SkyOn(on: false); } } try { Subdivide(_main, WaterPlugin.MeshStepWanted(), force: true); } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Mesh: " + ex.Message)); } _shoreCentre = new Vector3(100000000f, 0f, 100000000f); WaterPlugin.Log.LogInfo((object)("Quality: " + q + " - " + ((Object)val).name + ", mesh every " + WaterPlugin.MeshStepWanted().ToString("0.0") + "m, " + (WaterPlugin.IsUltra ? "nothing skipped." : "trimmed to run well."))); } private void PushFog() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Invalid comparison between Unknown and I4 //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Invalid comparison between Unknown and I4 //IL_005b: 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) if (!((Object)(object)_mat == (Object)null)) { bool fog = RenderSettings.fog; PutFloat("_FogOn", fog ? 1f : 0f); if (fog) { FogMode fogMode = RenderSettings.fogMode; float num = (((int)fogMode == 1) ? 0f : (((int)fogMode == 2) ? 1f : 2f)); PutColor("_FogColour", RenderSettings.fogColor); PutVector("_FogInfo", new Vector4(num, RenderSettings.fogDensity, RenderSettings.fogStartDistance, RenderSettings.fogEndDistance)); } } } private void HookFogAtRender() { if (_fogAtRender != null) { return; } _fogAtRender = delegate(ScriptableRenderContext ctx, Camera cam) { if (!((Object)(object)cam == (Object)null) && _live) { bool flag = (Object)(object)cam.targetTexture != (Object)null; try { PutFloat("_SceneOK", (!flag && SceneTexturesOK) ? 1f : 0f); } catch { } if (!flag) { try { PushFog(); } catch { } } } }; RenderPipelineManager.beginCameraRendering += _fogAtRender; } private void LookAtTheBoatMask() { //IL_029e: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) if (_maskSaid || Time.time < _nextMaskLook) { return; } _nextMaskLook = Time.time + 5f; Renderer[] array = Object.FindObjectsByType((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Renderer val in array) { if ((Object)(object)val == (Object)null || ((Object)val).name.IndexOf("Mask", StringComparison.OrdinalIgnoreCase) < 0 || ((Object)val).name.IndexOf("Boat", StringComparison.OrdinalIgnoreCase) < 0) { continue; } Material sharedMaterial = val.sharedMaterial; string text = ""; if ((Object)(object)sharedMaterial != (Object)null) { string[] array2 = new string[11] { "_Stencil", "_StencilComp", "_StencilOp", "_StencilRef", "_ColorMask", "_ZWrite", "_ZTest", "_Cull", "_Surface", "_Blend", "_QueueOffset" }; foreach (string text2 in array2) { if (sharedMaterial.HasProperty(text2)) { text = text + " " + text2 + "=" + sharedMaterial.GetFloat(text2); } } } ManualLogSource log = WaterPlugin.Log; string[] obj = new string[19] { "Boat mask '", ((Object)val).name, "' active=", ((Component)val).gameObject.activeInHierarchy.ToString(), " enabled=", val.enabled.ToString(), " layer=", ((Component)val).gameObject.layer.ToString(), " shader=", ((Object)(object)sharedMaterial != (Object)null && (Object)(object)sharedMaterial.shader != (Object)null) ? ((Object)sharedMaterial.shader).name : "?", " queue=", (((Object)(object)sharedMaterial != (Object)null) ? sharedMaterial.renderQueue : (-1)).ToString(), " (shader default ", (((Object)(object)sharedMaterial != (Object)null && (Object)(object)sharedMaterial.shader != (Object)null) ? sharedMaterial.shader.renderQueue : (-1)).ToString(), ") type=", ((Object)(object)sharedMaterial != (Object)null) ? sharedMaterial.GetTag("RenderType", false, "?") : "?", text, " bounds=", null }; Bounds bounds = val.bounds; Vector3 size = ((Bounds)(ref bounds)).size; obj[18] = ((Vector3)(ref size)).ToString("0.0"); log.LogInfo((object)string.Concat(obj)); _maskSaid = true; } if (_maskSaid && (Object)(object)_mat != (Object)null) { WaterPlugin.Log.LogInfo((object)("Our sea: shader queue default " + _mat.shader.renderQueue + ", material queue " + _mat.renderQueue + ", type " + _mat.GetTag("RenderType", false, "?"))); } } private List SeaRenderers(Transform main) { List list = new List(); if (_tiles != null) { Renderer[] tiles = _tiles; foreach (Renderer val in tiles) { if ((Object)(object)val != (Object)null && !list.Contains(val)) { list.Add(val); } } } if ((Object)(object)main != (Object)null) { Renderer[] tiles = ((Component)main).GetComponentsInChildren(true); foreach (Renderer val2 in tiles) { if ((Object)(object)val2 != (Object)null && !list.Contains(val2)) { list.Add(val2); } } } return list; } private void SeaLayers(bool ours) { foreach (KeyValuePair seaLayer in _seaLayers) { if ((Object)(object)seaLayer.Key != (Object)null) { ((Component)seaLayer.Key).gameObject.layer = ((!ours) ? seaLayer.Value : 0); } } } public void ShoreOn(bool on) { PutFloat("_UseShore", (on && (Object)(object)_shoreMap != (Object)null) ? 1f : 0f); } public void LightsOn(bool on) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) PutFloat("_Lamps", on ? 1f : 0f); if (on || (Object)(object)_mat == (Object)null) { return; } for (int i = 0; i < _lampPos.Length; i++) { _lampPos[i] = Vector4.zero; _lampCol[i] = Vector4.zero; } try { _mat.SetVectorArray("_PointPos", _lampPos); _mat.SetVectorArray("_PointCol", _lampCol); } catch { } } public void WakeOn(bool on) { WakeMaker component = ((Component)this).GetComponent(); if (on && (Object)(object)component == (Object)null && (Object)(object)_mat != (Object)null) { component = ((Component)this).gameObject.AddComponent(); component.Mat = _mat; component.WaterY = _waterY; WakeField.Life = WaterPlugin.WakeLife.Value; WakeField.Width = WaterPlugin.WakeWidth.Value; } else if ((Object)(object)component != (Object)null) { ((Behaviour)component).enabled = on; } if (!on) { PutFloat("_UseWake", 0f); } } public void SkyOn(bool on) { if (on && (Object)(object)_probeT == (Object)null) { try { BuildProbe(); } catch { } } else if ((Object)(object)_probeT != (Object)null) { ((Component)_probeT).gameObject.SetActive(on); } if (!on) { float num = TakeFloat("_SkyMirror", -1f); if (num > 0f) { _mirrorWanted = num; } PutFloat("_SkyMirror", 0f); PutFloat("_SkyReflect", 0f); } else { PutFloat("_SkyMirror", (_mirrorWanted > 0f) ? _mirrorWanted : 0.75f); PutFloat("_SkyReflect", 1f); } } public void Bind(WaterManager wm) { //IL_0394: 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_007c: Expected O, but got Unknown //IL_03cc: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03d6: Unknown result type (might be due to invalid IL or missing references) //IL_03e2: Unknown result type (might be due to invalid IL or missing references) //IL_03e7: Unknown result type (might be due to invalid IL or missing references) //IL_03ec: Unknown result type (might be due to invalid IL or missing references) //IL_03f8: Unknown result type (might be due to invalid IL or missing references) //IL_03fd: Unknown result type (might be due to invalid IL or missing references) //IL_0402: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: 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_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) Instance = this; Type typeFromHandle = typeof(WaterManager); ref Material mat = ref _mat; object? value = typeFromHandle.GetField("_waterMat", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(wm); mat = (Material)((value is Material) ? value : null); if ((Object)(object)_mat != (Object)null && (Object)(object)_mat.shader != (Object)null && !((Object)_mat.shader).name.StartsWith("HTF/")) { VanillaKept = new Material(_mat); } _vanilla = VanillaKept; _tiles = typeFromHandle.GetField("_waterTiles", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(wm) as Renderer[]; object? value2 = typeFromHandle.GetField("_mainWater", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(wm); Transform val = (Transform)((value2 is Transform) ? value2 : null); if ((Object)(object)_mat == (Object)null) { WaterPlugin.Log.LogError((object)"The water manager has no material - leaving the sea alone."); ((Behaviour)this).enabled = false; return; } _mat.shader = WaterPlugin.Sea; WaterPlugin.Dress(_mat); WaterPlugin.Log.LogInfo((object)("Sea render queue " + _mat.renderQueue + ", layer " + (((Object)(object)val != (Object)null) ? ((Component)val).gameObject.layer : (-1)) + " - the game's own, drawn by the game's own water step.")); _main = val; _modelScale = (((Object)(object)val != (Object)null) ? val.localScale.x : 1f); if ((Object)(object)val != (Object)null) { PutFloat("_Model_Scale", _modelScale); } try { MeshFilter val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInChildren() : null); Mesh val3 = (((Object)(object)val2 != (Object)null) ? val2.sharedMesh : null); if ((Object)(object)val3 == (Object)null) { WaterPlugin.Log.LogWarning((object)"The sea has no mesh to read, so how finely it can be waved is unknown."); } else { Bounds bounds = val3.bounds; Vector3 size = ((Bounds)(ref bounds)).size; float num = Mathf.Max(size.x, size.z) * (((Object)(object)val != (Object)null) ? val.localScale.x : 1f); int vertexCount = val3.vertexCount; float num2 = Mathf.Sqrt((float)Mathf.Max(vertexCount, 1)); float num3 = num / Mathf.Max(num2 - 1f, 1f); WaterPlugin.Log.LogInfo((object)("Sea mesh: " + vertexCount + " vertices over " + num.ToString("0") + "m, about one every " + num3.ToString("0.0") + "m.")); float num4 = ((WaterPlugin.SwellLength != null) ? (WaterPlugin.SwellLength.Value / 12.25f) : 3f); if (num3 > num4 / 4f) { WaterPlugin.Log.LogWarning((object)("The sea mesh is too coarse for these waves. Its shortest train is " + num4.ToString("0.0") + "m long and there is only a vertex every " + num3.ToString("0.0") + "m, so the waves will come out as flat facets with straight edges. Either the swell needs longer waves or the mesh needs subdividing.")); } } } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Could not measure the sea mesh: " + ex.Message)); } try { Subdivide(val, WaterPlugin.MeshStepWanted(), force: false); } catch (Exception ex2) { WaterPlugin.Log.LogWarning((object)("Could not rebuild the sea mesh: " + ex2.Message)); } _waterY = (((Object)(object)val != (Object)null) ? val.position.y : 0f); if (WaterPlugin.SkyReflection.Value) { BuildProbe(); } PutFloat("_UseShore", 0f); _tunedHorizon = TakeColor("_Horizon", Color.white); _tunedSky = TakeColor("_SkyTint", Color.white); _tunedSun = TakeColor("_SunColour", Color.white); WaterPlugin.Log.LogInfo((object)("The sea is ours (" + ((_tiles != null) ? _tiles.Length : 0) + " tiles).")); WaterTuner.Load(_mat); if (WaterPlugin.Wake.Value) { WakeMaker wakeMaker = ((Component)this).gameObject.AddComponent(); wakeMaker.Mat = _mat; wakeMaker.WaterY = _waterY; WakeField.Life = WaterPlugin.WakeLife.Value; WakeField.Width = WaterPlugin.WakeWidth.Value; WaterPlugin.Log.LogInfo((object)"Boat wake is on."); } if (WaterPlugin.Tuner.Value) { ((Component)this).gameObject.AddComponent().Mat = _mat; WaterPlugin.Log.LogInfo((object)"Tuning menu is on - press F9."); } _checkAt = Time.time + 6f; _strayUntil = Time.time + 60f; HookFogAtRender(); LightsOn(WaterPlugin.LightsOnWater.Value); if (!WaterPlugin.SkyReflection.Value) { SkyOn(on: false); } } private void FindOtherWater() { //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_0170: 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_0192: 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) HashSet hashSet = new HashSet((IEnumerable)(((object)_tiles) ?? ((object)new Renderer[0]))); int num = 0; Renderer[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Renderer val in array) { if ((Object)(object)val == (Object)null || hashSet.Contains(val)) { continue; } Material sharedMaterial = val.sharedMaterial; if ((Object)(object)sharedMaterial == (Object)null) { continue; } string text = (((Object)sharedMaterial).name + " " + (((Object)(object)sharedMaterial.shader != (Object)null) ? ((Object)sharedMaterial.shader).name : "")).ToLowerInvariant(); if (text.Contains("water") && !text.Contains("particle") && !text.Contains("splash") && !text.Contains("explosion") && !text.Contains("underwater")) { Bounds bounds = val.bounds; _strayCount++; WaterPlugin.Log.LogInfo((object)("Other water surface: " + ((Object)((Component)val).gameObject).name + " [" + ((Object)sharedMaterial).name + " / " + (((Object)(object)sharedMaterial.shader != (Object)null) ? ((Object)sharedMaterial.shader).name : "?") + "] at " + ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString() + " size " + ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString())); if (WaterPlugin.AdoptStray.Value && (Object)(object)sharedMaterial != (Object)(object)_mat) { val.sharedMaterial = _mat; num++; } } } if (num > 0) { WaterPlugin.Log.LogInfo((object)("Put our sea onto " + num + " stray water surface(s).")); } } private void CheckPhysics() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) try { float num = 0f; Vector3[] array = (Vector3[])(object)new Vector3[5] { new Vector3(0f, 0f, 0f), new Vector3(37.5f, 0f, -12.25f), new Vector3(-140f, 0f, 88f), new Vector3(613f, 0f, 421f), new Vector3(-7.3f, 0f, 999.1f) }; foreach (Vector3 val in array) { float num2 = ShaderHeight(val); float waterHeight = WaterManager.GetWaterHeight(val); num = Mathf.Max(num, Mathf.Abs(num2 - waterHeight)); } if (num > 0.005f) { WaterPlugin.Log.LogWarning((object)("THE SURFACE DOES NOT MATCH THE PHYSICS - out by " + num.ToString("0.####") + "m. Things will float wrong. Report this.")); } else { WaterPlugin.Log.LogInfo((object)("Surface matches the physics (worst " + num.ToString("0.#####") + "m across five spots).")); } } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Could not check the physics: " + ex.Message)); } } private void Subdivide(Transform main, float step, bool force) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_0136: 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_0152: 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_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0178: 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_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0198: 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_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown //IL_029b: 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_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02bd: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_030f: Unknown result type (might be due to invalid IL or missing references) if (step <= 0.01f || (Object)(object)main == (Object)null) { return; } MeshFilter componentInChildren = ((Component)main).GetComponentInChildren(); if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.sharedMesh == (Object)null) { return; } Mesh sharedMesh = componentInChildren.sharedMesh; if (!force && ((Object)sharedMesh).name.StartsWith("HTFSeaGrid")) { return; } Bounds bounds = sharedMesh.bounds; float num = Mathf.Max(main.lossyScale.x, 0.0001f); float num2 = step / num; int num3 = Mathf.Clamp(Mathf.CeilToInt(((Bounds)(ref bounds)).size.x / num2), 2, 512); int num4 = Mathf.Clamp(Mathf.CeilToInt(((Bounds)(ref bounds)).size.z / num2), 2, 512); while ((num3 + 1) * (num4 + 1) > 260000) { num3 = num3 * 3 / 4; num4 = num4 * 3 / 4; } int num5 = num3 + 1; int num6 = num4 + 1; Vector3[] array = (Vector3[])(object)new Vector3[num5 * num6]; Vector2[] array2 = (Vector2[])(object)new Vector2[num5 * num6]; Vector3[] array3 = (Vector3[])(object)new Vector3[num5 * num6]; for (int i = 0; i < num6; i++) { float num7 = (float)i / (float)num4; for (int j = 0; j < num5; j++) { float num8 = (float)j / (float)num3; int num9 = i * num5 + j; array[num9] = new Vector3(((Bounds)(ref bounds)).min.x + ((Bounds)(ref bounds)).size.x * num8, ((Bounds)(ref bounds)).center.y, ((Bounds)(ref bounds)).min.z + ((Bounds)(ref bounds)).size.z * num7); array2[num9] = new Vector2(num8, num7); array3[num9] = Vector3.up; } } int[] array4 = new int[num3 * num4 * 6]; int num10 = 0; for (int k = 0; k < num4; k++) { for (int l = 0; l < num3; l++) { int num11 = k * num5 + l; int num12 = num11 + num5; array4[num10++] = num11; array4[num10++] = num12; array4[num10++] = num11 + 1; array4[num10++] = num11 + 1; array4[num10++] = num12; array4[num10++] = num12 + 1; } } Mesh val = new Mesh { name = "HTFSeaGrid" }; if (array.Length > 65000) { val.indexFormat = (IndexFormat)1; } val.vertices = array; val.uv = array2; val.normals = array3; val.triangles = array4; Bounds bounds2 = bounds; ((Bounds)(ref bounds2)).Expand(new Vector3(0f, 20f / num, 0f)); val.bounds = bounds2; componentInChildren.sharedMesh = val; float num13 = ((Bounds)(ref bounds)).size.x * num / (float)num3; WaterPlugin.Log.LogInfo((object)("Sea mesh rebuilt: " + array.Length + " vertices over " + (((Bounds)(ref bounds)).size.x * num).ToString("0") + "m, one every " + num13.ToString("0.0") + "m (was one every 3.1m).")); } private float ShaderHeight(Vector3 p) { //IL_0042: 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_0080: Unknown result type (might be due to invalid IL or missing references) float num = _mat.GetFloat("_Fake_Time"); if (num <= 0.0001f) { num = Time.time; } float num2 = _mat.GetFloat("_Wave_Offset"); float num3 = _mat.GetFloat("_Model_Scale"); float num4 = Train(p, num + num2, "_Wave_Frequency_1", "_Gradient_Speed_1", "_Wave_Direction_1", "_Wave_Height_1") + Train(p, num + num2, "_Wave_Frequency_2", "_Gradient_Speed_2", "_Wave_Direction_2", "_Wave_Height_2"); num4 += Swell.At(p, num); return _waterY + num4 * num3; } private float Train(Vector3 p, float t, string freq, string speed, string dir, string height) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: 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) Vector3 val = Vector4.op_Implicit(_mat.GetVector(dir)); ((Vector3)(ref val)).Normalize(); return Mathf.Sin(Vector3.Dot(val, p) * _mat.GetFloat(freq) + t * _mat.GetFloat(speed)) * _mat.GetFloat(height); } private void BuildProbe() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_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_0037: 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_004a: Expected O, but got Unknown //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown int num = Mathf.Clamp(WaterPlugin.SkyResolution.Value, 32, 256); _skyRT = new RenderTexture(num, num, 16, (RenderTextureFormat)0) { dimension = (TextureDimension)4, useMipMap = true, autoGenerateMips = false, wrapMode = (TextureWrapMode)1, filterMode = (FilterMode)2 }; _skyRT.Create(); GameObject val = new GameObject("SeaSkyCam"); ((Object)val).hideFlags = (HideFlags)61; _probeT = val.transform; _skyCam = val.AddComponent(); ((Behaviour)_skyCam).enabled = false; _skyCam.clearFlags = (CameraClearFlags)1; _skyCam.nearClipPlane = 0.3f; _skyCam.farClipPlane = 4000f; _skyCam.cullingMask = -1; ShootSky(announce: true); } private void ShootSky(bool announce) { Texture customReflectionTexture = RenderSettings.customReflectionTexture; Cubemap val = (Cubemap)(object)((customReflectionTexture is Cubemap) ? customReflectionTexture : null); if ((Object)(object)val != (Object)null) { PutTexture("_SeaSky", (Texture)(object)val); PutFloat("_SkyReflect", WaterPlugin.SkyReflection.Value ? 1f : 0f); _usingShared = true; if (announce) { WaterPlugin.Log.LogInfo((object)("Using the sky mod's own reflection cubemap (" + ((Texture)val).width + "px) - the sea mirrors exactly what the sky is doing.")); } return; } _usingShared = false; if ((Object)(object)_skyCam == (Object)null || (Object)(object)_skyRT == (Object)null) { return; } if (!_skyCam.RenderToCubemap(_skyRT)) { PutFloat("_SkyReflect", 0f); if (announce) { WaterPlugin.Log.LogWarning((object)"RenderToCubemap refused - the sea will use the sky-coloured gradient instead."); } return; } _skyRT.GenerateMips(); PutTexture("_SeaSky", (Texture)(object)_skyRT); PutFloat("_SkyReflect", WaterPlugin.SkyReflection.Value ? 1f : 0f); if (announce) { WaterPlugin.Log.LogInfo((object)("The sea is reflecting the real sky (" + ((Texture)_skyRT).width + "px cubemap).")); } } private static void DrawWaterAfterThePhoto(object feat, object rendererData) { //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) Type type = feat.GetType(); if (type.Name != "RenderObjects") { return; } FieldInfo field = type.GetField("settings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj = ((field != null) ? field.GetValue(feat) : null); if (obj == null) { return; } Type type2 = obj.GetType(); FieldInfo field2 = type2.GetField("filterSettings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj2 = ((field2 != null) ? field2.GetValue(obj) : null); if (obj2 == null) { return; } FieldInfo field3 = obj2.GetType().GetField("LayerMask", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num; if (!(field3 != null)) { num = 0; } else { LayerMask val = (LayerMask)field3.GetValue(obj2); num = ((LayerMask)(ref val)).value; } if ((num & 0x10) == 0) { return; } FieldInfo field4 = type2.GetField("Event", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field4 == null) { return; } int num2 = Convert.ToInt32(field4.GetValue(obj)); int num3 = 400 + 1; if (num2 >= num3) { WaterPlugin.Log.LogInfo((object)("Water step already after the photo (" + num2 + ").")); return; } field4.SetValue(obj, Enum.ToObject(field4.FieldType, num3)); MethodInfo method = rendererData.GetType().GetMethod("SetDirty", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (method != null) { method.Invoke(rendererData, null); } WaterPlugin.Log.LogInfo((object)("Water step moved from event " + num2 + " to " + num3 + " (just after the pipeline photographs the opaques), so the sea can see through itself.")); } private static void MakeSureWeCanSeeThroughWater() { //IL_04c4: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03aa: Unknown result type (might be due to invalid IL or missing references) //IL_05d6: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Unknown result type (might be due to invalid IL or missing references) if (_askedAboutTextures) { return; } _askedAboutTextures = true; try { RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline; if ((Object)(object)currentRenderPipeline == (Object)null) { WaterPlugin.Log.LogWarning((object)"No render pipeline asset, so the sea cannot be made see-through."); return; } Type type = ((object)currentRenderPipeline).GetType(); WaterPlugin.Log.LogInfo((object)("Pipeline asset is " + type.Name + ".")); string[] array = new string[2] { "supportsCameraOpaqueTexture", "supportsCameraDepthTexture" }; foreach (string text in array) { PropertyInfo property = type.GetProperty(text, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (property == null) { WaterPlugin.Log.LogWarning((object)(" " + text + ": this URP version has no such setting.")); continue; } if ((bool)property.GetValue(currentRenderPipeline, null)) { WaterPlugin.Log.LogInfo((object)(" " + text + ": already on.")); continue; } if (!property.CanWrite) { WaterPlugin.Log.LogWarning((object)(" " + text + ": OFF and read-only, so it cannot be turned on here.")); continue; } property.SetValue(currentRenderPipeline, true, null); bool flag = (bool)property.GetValue(currentRenderPipeline, null); WaterPlugin.Log.LogInfo((object)(" " + text + ": was off, set on, reads back " + flag + ".")); } try { RenderPipelineAsset currentRenderPipeline2 = GraphicsSettings.currentRenderPipeline; Type type2 = (((Object)(object)currentRenderPipeline2 != (Object)null) ? ((object)currentRenderPipeline2).GetType() : null); PropertyInfo propertyInfo = ((type2 != null) ? type2.GetProperty("supportsCameraOpaqueTexture") : null); PropertyInfo propertyInfo2 = ((type2 != null) ? type2.GetProperty("supportsCameraDepthTexture") : null); SceneTexturesOK = propertyInfo != null && propertyInfo2 != null && (bool)propertyInfo.GetValue(currentRenderPipeline2, null) && (bool)propertyInfo2.GetValue(currentRenderPipeline2, null); WaterPlugin.Log.LogInfo((object)(SceneTexturesOK ? "The sea can see through itself: the pipeline keeps colour and depth of everything under it." : "No scene colour or depth from the pipeline, so the bottom is painted rather than seen.")); } catch { SceneTexturesOK = false; } try { RenderPipelineAsset currentRenderPipeline3 = GraphicsSettings.currentRenderPipeline; Type type3 = ((object)currentRenderPipeline3).GetType(); PropertyInfo property2 = type3.GetProperty("opaqueDownsampling"); string text2 = "Renderer: opaqueDownsampling=" + ((property2 != null) ? property2.GetValue(currentRenderPipeline3, null) : "?"); FieldInfo field = type3.GetField("m_RendererDataList", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Array array2 = ((field != null) ? (field.GetValue(currentRenderPipeline3) as Array) : null); LayerMask val; if (array2 != null && array2.Length > 0 && array2.GetValue(0) != null) { object value = array2.GetValue(0); Type type4 = value.GetType(); text2 = text2 + ", " + type4.Name; array = new string[6] { "renderingMode", "copyDepthMode", "depthPrimingMode", "opaqueLayerMask", "transparentLayerMask", "intermediateTextureMode" }; foreach (string text3 in array) { PropertyInfo property3 = type4.GetProperty(text3, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo field2 = type4.GetField("m_" + char.ToUpper(text3[0]) + text3.Substring(1), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj2 = ((property3 != null) ? property3.GetValue(value, null) : ((field2 != null) ? field2.GetValue(value) : null)); if (obj2 is LayerMask) { val = (LayerMask)obj2; obj2 = ((LayerMask)(ref val)).value; } text2 = text2 + ", " + text3 + "=" + (obj2 ?? "?"); } } WaterPlugin.Log.LogInfo((object)text2); if (array2 == null || array2.Length <= 0 || array2.GetValue(0) == null) { return; } object value2 = array2.GetValue(0); PropertyInfo property4 = value2.GetType().GetProperty("rendererFeatures", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); IEnumerable enumerable = ((property4 != null) ? (property4.GetValue(value2, null) as IEnumerable) : null); if (enumerable == null) { return; } foreach (object item in enumerable) { if (item == null) { continue; } Type type5 = item.GetType(); string text4 = "Renderer feature " + type5.Name + " '" + ((Object)item).name + "'"; FieldInfo field3 = type5.GetField("settings", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj3 = ((field3 != null) ? field3.GetValue(item) : null); if (obj3 != null) { Type type6 = obj3.GetType(); array = new string[2] { "Event", "filterSettings" }; foreach (string text5 in array) { FieldInfo field4 = type6.GetField(text5, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj4 = ((field4 != null) ? field4.GetValue(obj3) : null); if (obj4 == null) { continue; } if (text5 == "filterSettings") { Type type7 = obj4.GetType(); string[] array3 = new string[2] { "RenderQueueType", "LayerMask" }; foreach (string text6 in array3) { FieldInfo field5 = type7.GetField(text6, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); object obj5 = ((field5 != null) ? field5.GetValue(obj4) : null); if (obj5 is LayerMask) { val = (LayerMask)obj5; obj5 = ((LayerMask)(ref val)).value; } text4 = text4 + ", " + text6 + "=" + (obj5 ?? "?"); } } else { text4 = text4 + ", " + text5 + "=" + obj4; } } } WaterPlugin.Log.LogInfo((object)text4); try { DrawWaterAfterThePhoto(item, value2); } catch (Exception ex) { WaterPlugin.Log.LogInfo((object)("Could not move the water step: " + ex.Message)); } } } catch (Exception ex2) { WaterPlugin.Log.LogInfo((object)("Renderer probe: " + ex2.Message)); } } catch (Exception ex3) { WaterPlugin.Log.LogWarning((object)("Could not ask the pipeline about its opaque and depth textures: " + ex3.Message)); } } private unsafe void LateUpdate() { //IL_0bd9: Unknown result type (might be due to invalid IL or missing references) //IL_0bea: Unknown result type (might be due to invalid IL or missing references) //IL_0bf1: Unknown result type (might be due to invalid IL or missing references) //IL_0bf6: Unknown result type (might be due to invalid IL or missing references) //IL_0bf8: Unknown result type (might be due to invalid IL or missing references) //IL_0c0b: Unknown result type (might be due to invalid IL or missing references) //IL_0c10: Unknown result type (might be due to invalid IL or missing references) //IL_1062: Unknown result type (might be due to invalid IL or missing references) //IL_1064: Unknown result type (might be due to invalid IL or missing references) //IL_106b: Unknown result type (might be due to invalid IL or missing references) //IL_0c86: Unknown result type (might be due to invalid IL or missing references) //IL_0c8b: Unknown result type (might be due to invalid IL or missing references) //IL_0c9c: Unknown result type (might be due to invalid IL or missing references) //IL_0ca1: Unknown result type (might be due to invalid IL or missing references) //IL_0cb2: Unknown result type (might be due to invalid IL or missing references) //IL_0cb7: Unknown result type (might be due to invalid IL or missing references) //IL_0cc8: Unknown result type (might be due to invalid IL or missing references) //IL_0ccd: Unknown result type (might be due to invalid IL or missing references) //IL_0c3c: Unknown result type (might be due to invalid IL or missing references) //IL_0c41: Unknown result type (might be due to invalid IL or missing references) //IL_0c46: Unknown result type (might be due to invalid IL or missing references) //IL_0c4a: Unknown result type (might be due to invalid IL or missing references) //IL_0c51: Unknown result type (might be due to invalid IL or missing references) //IL_0c6d: Unknown result type (might be due to invalid IL or missing references) //IL_0c72: Unknown result type (might be due to invalid IL or missing references) //IL_0e2a: Unknown result type (might be due to invalid IL or missing references) //IL_0e2f: Unknown result type (might be due to invalid IL or missing references) //IL_0e4f: Unknown result type (might be due to invalid IL or missing references) //IL_0e54: Unknown result type (might be due to invalid IL or missing references) //IL_0e87: Unknown result type (might be due to invalid IL or missing references) //IL_0f03: Unknown result type (might be due to invalid IL or missing references) //IL_0f1f: Unknown result type (might be due to invalid IL or missing references) //IL_0f3b: Unknown result type (might be due to invalid IL or missing references) //IL_0f57: Unknown result type (might be due to invalid IL or missing references) //IL_0cdd: Unknown result type (might be due to invalid IL or missing references) //IL_0ce2: Unknown result type (might be due to invalid IL or missing references) //IL_0d06: Unknown result type (might be due to invalid IL or missing references) //IL_0d08: Unknown result type (might be due to invalid IL or missing references) //IL_0d0c: Unknown result type (might be due to invalid IL or missing references) //IL_0d11: Unknown result type (might be due to invalid IL or missing references) //IL_0d25: Unknown result type (might be due to invalid IL or missing references) //IL_0d34: Unknown result type (might be due to invalid IL or missing references) //IL_0d36: Unknown result type (might be due to invalid IL or missing references) //IL_0ff1: Unknown result type (might be due to invalid IL or missing references) //IL_0ff6: Unknown result type (might be due to invalid IL or missing references) //IL_049a: Unknown result type (might be due to invalid IL or missing references) //IL_04d5: Unknown result type (might be due to invalid IL or missing references) //IL_04da: Unknown result type (might be due to invalid IL or missing references) //IL_050e: Unknown result type (might be due to invalid IL or missing references) //IL_05db: Unknown result type (might be due to invalid IL or missing references) //IL_05f3: Unknown result type (might be due to invalid IL or missing references) //IL_05fd: Unknown result type (might be due to invalid IL or missing references) //IL_06e1: Unknown result type (might be due to invalid IL or missing references) //IL_06e6: Unknown result type (might be due to invalid IL or missing references) //IL_0798: Unknown result type (might be due to invalid IL or missing references) //IL_079d: Unknown result type (might be due to invalid IL or missing references) //IL_07a2: Unknown result type (might be due to invalid IL or missing references) //IL_07b3: Unknown result type (might be due to invalid IL or missing references) //IL_07b9: Unknown result type (might be due to invalid IL or missing references) //IL_08d1: Unknown result type (might be due to invalid IL or missing references) //IL_08d6: Unknown result type (might be due to invalid IL or missing references) //IL_08e6: Unknown result type (might be due to invalid IL or missing references) //IL_08eb: Unknown result type (might be due to invalid IL or missing references) //IL_08fb: Unknown result type (might be due to invalid IL or missing references) //IL_0903: Unknown result type (might be due to invalid IL or missing references) //IL_090d: Unknown result type (might be due to invalid IL or missing references) //IL_0912: Unknown result type (might be due to invalid IL or missing references) //IL_0917: Unknown result type (might be due to invalid IL or missing references) //IL_094b: Unknown result type (might be due to invalid IL or missing references) //IL_094f: Unknown result type (might be due to invalid IL or missing references) //IL_0954: Unknown result type (might be due to invalid IL or missing references) //IL_0956: Unknown result type (might be due to invalid IL or missing references) //IL_095b: Unknown result type (might be due to invalid IL or missing references) //IL_0962: Unknown result type (might be due to invalid IL or missing references) //IL_0967: Unknown result type (might be due to invalid IL or missing references) //IL_096f: Unknown result type (might be due to invalid IL or missing references) //IL_0920: Unknown result type (might be due to invalid IL or missing references) //IL_0922: Unknown result type (might be due to invalid IL or missing references) //IL_092c: Unknown result type (might be due to invalid IL or missing references) //IL_0931: Unknown result type (might be due to invalid IL or missing references) //IL_0936: Unknown result type (might be due to invalid IL or missing references) //IL_09a0: Unknown result type (might be due to invalid IL or missing references) //IL_09a5: Unknown result type (might be due to invalid IL or missing references) //IL_09b5: Unknown result type (might be due to invalid IL or missing references) //IL_09ba: Unknown result type (might be due to invalid IL or missing references) //IL_09e8: Unknown result type (might be due to invalid IL or missing references) //IL_09ea: Unknown result type (might be due to invalid IL or missing references) //IL_09cb: Unknown result type (might be due to invalid IL or missing references) //IL_09d0: Unknown result type (might be due to invalid IL or missing references) //IL_0aeb: Unknown result type (might be due to invalid IL or missing references) //IL_0afe: Unknown result type (might be due to invalid IL or missing references) //IL_0b03: Unknown result type (might be due to invalid IL or missing references) //IL_0a37: Unknown result type (might be due to invalid IL or missing references) //IL_0a67: Unknown result type (might be due to invalid IL or missing references) //IL_0a6c: Unknown result type (might be due to invalid IL or missing references) //IL_0a6e: Unknown result type (might be due to invalid IL or missing references) //IL_0a75: Unknown result type (might be due to invalid IL or missing references) //IL_0a7c: Unknown result type (might be due to invalid IL or missing references) //IL_0a93: Unknown result type (might be due to invalid IL or missing references) //IL_0aab: Unknown result type (might be due to invalid IL or missing references) //IL_0ac3: Unknown result type (might be due to invalid IL or missing references) //IL_0ade: Unknown result type (might be due to invalid IL or missing references) //IL_0ae0: Unknown result type (might be due to invalid IL or missing references) //IL_0ae4: Unknown result type (might be due to invalid IL or missing references) //IL_0ae9: Unknown result type (might be due to invalid IL or missing references) //IL_0b8d: Unknown result type (might be due to invalid IL or missing references) //IL_0b92: Unknown result type (might be due to invalid IL or missing references) //IL_0ba6: Unknown result type (might be due to invalid IL or missing references) //IL_0bb5: Unknown result type (might be due to invalid IL or missing references) //IL_0bb7: Unknown result type (might be due to invalid IL or missing references) if (!_startChecked) { _startChecked = true; if (!WaterPlugin.Enabled.Value) { SetLive(on: false); return; } } if (WaterPlugin.ShowWorking.Value > 0) { WatchTheLighting(); } if (!_live) { return; } try { LookAtTheBoatMask(); } catch { } MakeSureWeCanSeeThroughWater(); float num = (((Object)(object)_mat != (Object)null) ? _mat.GetFloat("_Fake_Time") : 0f); Clock = ((num > 0.0001f) ? num : Time.time); Swell.Height = ((WaterPlugin.WavesOn.Value && WaterPlugin.IsLit) ? WaterPlugin.SwellHeight.Value : 0f); Swell.Length = WaterPlugin.SwellLength.Value; Swell.Count = (WaterPlugin.IsUltra ? Mathf.Max(WaterPlugin.SwellWaves.Value, 40) : WaterPlugin.SwellWaves.Value); Swell.SpreadDeg = WaterPlugin.SwellSpread.Value; Swell.Seed = WaterPlugin.SwellSeed.Value; Swell.Steep = WaterPlugin.SwellSteep.Value; Swell.Speed = WaterPlugin.SwellSpeed.Value; Swell.Refract = WaterPlugin.Refract.Value; Swell.SurfReach = WaterPlugin.SurfReach.Value; if (Swell.Regenerate() && (Object)(object)_mat != (Object)null) { try { _mat.SetVectorArray("_WaveA", Swell.A); _mat.SetVectorArray("_WaveB", Swell.B); } catch { } try { Swell.WriteTable(Path.Combine(Path.GetDirectoryName(typeof(WaterPlugin).Assembly.Location), "htfwater_waves.txt")); } catch { } float num2 = 2f * Swell.Height; WaterPlugin.Log.LogInfo((object)("Sea rebuilt: " + Swell.Active + " wave components from the JONSWAP spectrum, peak " + Swell.Length.ToString("0") + "m, significant height " + num2.ToString("0.00") + "m, spread " + Swell.SpreadDeg.ToString("0") + " degrees.")); } if (Time.time >= _nextAskSay) { float num3 = (float)TheSeaHasWavesNow.Asked / Mathf.Max(Time.time - _lastAskSay, 0.01f); WaterPlugin.Log.LogInfo((object)("Buoyancy: the game asked for the water height " + num3.ToString("0") + " times a second, " + Swell.Active + " waves each.")); TheSeaHasWavesNow.Asked = 0; _lastAskSay = Time.time; _nextAskSay = Time.time + 5f; } PutFloat("_Ultra", WaterPlugin.IsUltra ? 1f : 0f); PutFloat("_SceneOK", SceneTexturesOK ? 1f : 0f); PutFloat("_SwellHeight", Swell.Height); PutFloat("_SwellLength", Swell.Length); PutFloat("_SwellCount", Swell.Active); PutFloat("_SwellSteep", Swell.Steep); PutFloat("_SwellSpread", Swell.SpreadDeg * ((float)Math.PI / 180f)); PutFloat("_SwellDir", Swell.Direction); PutFloat("_SwellSpeed", Swell.Speed); PutFloat("_Breakers", WaterPlugin.Breakers.Value); PutFloat("_SurfReach", WaterPlugin.SurfReach.Value); PutFloat("_Refract2", WaterPlugin.Refract.Value); PutFloat("_BreakType", WaterPlugin.BreakType.Value); PutFloat("_Swash", WaterPlugin.SwashRun.Value); PutFloat("_Transmit", WaterPlugin.SeeInto.Value); PutFloat("_Clarity", WaterPlugin.Clarity.Value); PutFloat("_Debug", WaterPlugin.ShowWorking.Value); if ((Object)(object)_mat == (Object)null) { return; } if (_checkAt > 0f && Time.time >= _checkAt) { _checkAt = -1f; CheckPhysics(); } if (WaterPlugin.LightsOnWater.Value) { Transform val = Eye(); if ((Object)(object)val != (Object)null) { FeedLights(val.position); } } if (WaterPlugin.TintClouds.Value && Time.time >= _nextCloud) { _nextCloud = Time.time + 0.3f; Color sky = _faces[0]; if (!(((Color)(ref sky)).maxColorComponent < 0.01f) && (!(dayLitLast > 0.5f) || !(((Color)(ref sky)).maxColorComponent < 0.08f))) { TintClouds(sky, Mathf.Lerp(0.25f, 1f, dayLitLast)); } } if (Time.time < _strayUntil && Time.time >= _nextStray) { _nextStray = Time.time + 3f; FindOtherWater(); } if (WaterPlugin.Shoreline.Value && Time.time >= _nextShore) { _nextShore = Time.time + 4f; MaybeMapSeabed(); } if ((Object)(object)_skyCam != (Object)null && Time.time >= _nextSky) { _nextSky = Time.time + WaterPlugin.SkyRefresh.Value; Transform val2 = Eye(); if ((Object)(object)val2 != (Object)null) { _probeT.position = new Vector3(val2.position.x, _waterY + 1.5f, val2.position.z); } if (!_skyFound && Time.time >= _nextMask) { _nextMask = Time.time + 3f; int num4 = SkyLayers(); if (num4 != 0) { _skyFound = true; _skyCam.cullingMask = num4; WaterPlugin.Log.LogInfo((object)("Sky found on layers " + num4 + " - " + found)); } } ShootSky(announce: false); } if (!WaterPlugin.FollowSky.Value) { return; } if (Time.time >= _nextLook) { _nextLook = Time.time + 2f; _sun = BrightestSun(); } _sunPeak = Mathf.Max(_sunPeak, ((Object)(object)_sun != (Object)null) ? _sun.intensity : 0f); Color val3 = RenderSettings.ambientLight; float grayscale = ((Color)(ref val3)).grayscale; _ambPeak = Mathf.Max(_ambPeak, grayscale); float num5 = (((Object)(object)_sun != (Object)null && _sunPeak > 0.01f) ? Mathf.Clamp01(_sun.intensity / _sunPeak) : 1f); float num6 = ((_ambPeak > 0.001f) ? Mathf.Clamp01(grayscale / _ambPeak) : 1f); float num7 = Mathf.Max(num5, num6 * 0.9f); float value = WaterPlugin.Brightness.Value; if ((Object)(object)_sun != (Object)null) { PutVector("_SunDir", Vector4.op_Implicit(-((Component)_sun).transform.forward)); PutColor("_SunColour", _tunedSun * num5); } value *= Mathf.Lerp(0.22f, 1f, num7); float num8 = (RenderSettings.fog ? RenderSettings.fogDensity : 0f); if (num8 > 0f) { _fogBase = ((_fogBase <= 0f) ? num8 : Mathf.Min(_fogBase, num8)); } float num9 = ((_fogBase > 1E-05f && num8 > 0f) ? Mathf.Clamp01((num8 / _fogBase - 1f) / 2.2f) : 0f); PutFloat("_Overcast", num9); overcastLast = num9; sceneLast = num7; if (WaterPlugin.AutoHaze.Value) { PutFloat("_Haze", Mathf.Lerp(0.55f, 1f, num9)); PutFloat("_HazeRange", Mathf.Lerp(340f, 90f, num9)); } PutFloat("_Exposure", Mathf.Clamp(value, 0.06f, 2.5f)); Color val4 = RenderSettings.ambientLight; if (((Color)(ref val4)).maxColorComponent < 0.02f) { val4 = RenderSettings.ambientSkyColor; } if ((Object)(object)_sun != (Object)null) { val4 += _sun.color * 0.6f; } if (RenderSettings.fog) { val4 += RenderSettings.fogColor * 0.5f; } float num10 = Mathf.Max(((Color)(ref val4)).maxColorComponent, 0.001f); val4 /= num10; val4 = Color.Lerp(Color.white, val4, 0.45f); PutColor("_Ambient", val4); PushFog(); if (_tiles != null && _tiles.Length != 0 && !_tiles[0].enabled) { return; } Color val5 = RenderSettings.ambientSkyColor; if (((Color)(ref val5)).maxColorComponent < 0.02f) { val5 = RenderSettings.ambientLight; } if (((Color)(ref val5)).maxColorComponent < 0.02f) { val5 = _tunedSky; } Color val6 = default(Color); ((Color)(ref val6))..ctor(0.55f, 0.7f, 0.9f); Color val7 = val6; float num11 = 1f; float num12 = 0f; float num13 = 0f; if ((Object)(object)_sun != (Object)null) { num11 = (dayLitLast = Mathf.Clamp01(_sun.intensity)); float num14 = Mathf.Abs(((Component)_sun).transform.forward.y); num13 = Mathf.Clamp01(1.15f - num14 * 1.3f); num12 = num13; Color color = _sun.color; float num15 = Mathf.Max(color.r, Mathf.Max(color.g, color.b)); Color val8 = default(Color); ((Color)(ref val8))..ctor(Mathf.Clamp01(num15 + (color.r - num15) * 1.9f), Mathf.Clamp01(num15 + (color.g - num15) * 1.9f), Mathf.Clamp01(num15 + (color.b - num15) * 1.9f)); val7 = Color.Lerp(val6, val8, num13); } val7 *= Mathf.Lerp(0.18f, 1f, num11); val7.a = 1f; Texture customReflectionTexture = RenderSettings.customReflectionTexture; Cubemap val9 = (Cubemap)(object)((customReflectionTexture is Cubemap) ? customReflectionTexture : null); string[] array = new string[4] { "_HorizonPX", "_HorizonNX", "_HorizonPZ", "_HorizonNZ" }; CubemapFace[] array2 = new CubemapFace[4]; RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); CubemapFace[] array3 = (CubemapFace[])(object)array2; bool flag = false; if ((Object)(object)val9 != (Object)null && ((Texture)val9).width >= 4) { try { for (int i = 0; i < 4; i++) { Color pixel = val9.GetPixel(array3[i], ((Texture)val9).width / 2, ((Texture)val9).height - 1); pixel.a = 1f; PutColor(array[i], pixel); _faces[i] = pixel; } flag = true; } catch { flag = false; } } if (!flag) { Color val10 = Color.Lerp(val6, new Color(0.42f, 0.34f, 0.56f), num12); val10 *= Mathf.Lerp(0.18f, 1f, num11); Vector2 normalized = default(Vector2); ((Vector2)(ref normalized))..ctor(0f, 1f); if ((Object)(object)_sun != (Object)null) { Vector3 val11 = -((Component)_sun).transform.forward; Vector2 val12 = default(Vector2); ((Vector2)(ref val12))..ctor(val11.x, val11.z); if (((Vector2)(ref val12)).sqrMagnitude > 0.0001f) { normalized = ((Vector2)(ref val12)).normalized; } } Vector2[] array4 = (Vector2[])(object)new Vector2[4] { new Vector2(1f, 0f), new Vector2(-1f, 0f), new Vector2(0f, 1f), new Vector2(0f, -1f) }; for (int j = 0; j < 4; j++) { float num16 = Mathf.Pow(Mathf.Clamp01(Vector2.Dot(array4[j], normalized) * 0.5f + 0.5f), 1.4f); Color val13 = Color.Lerp(val10, val7, num16); val13.a = 1f; PutColor(array[j], val13); _faces[j] = val13; } } if (Time.time >= _nextSay) { _nextSay = Time.time + 20f; Texture customReflectionTexture2 = RenderSettings.customReflectionTexture; Cubemap val14 = (Cubemap)(object)((customReflectionTexture2 is Cubemap) ? customReflectionTexture2 : null); WaterPlugin.Log.LogInfo((object)("Sky cubemap now " + (((Object)(object)val14 == (Object)null) ? "none" : (((Texture)val14).width + "px (16 = the sky mod's own)")) + ", haze reaches " + TakeFloat("_HazeRange", 0f) + "m")); ManualLogSource log = WaterPlugin.Log; string[] obj5 = new string[14] { "Sea fog: on=", TakeFloat("_FogOn", -1f).ToString(), " colour ", Show(TakeColor("_FogColour", Color.black)), " info ", null, null, null, null, null, null, null, null, null }; Vector4 vector = _mat.GetVector("_FogInfo"); obj5[5] = ((Vector4)(ref vector)).ToString("0.0000"); obj5[6] = " | RenderSettings fog="; obj5[7] = RenderSettings.fog.ToString(); obj5[8] = " "; obj5[9] = Show(RenderSettings.fogColor); obj5[10] = " density "; obj5[11] = RenderSettings.fogDensity.ToString("0.0000"); obj5[12] = " | exposure "; obj5[13] = TakeFloat("_Exposure", -1f).ToString("0.00"); log.LogInfo((object)string.Concat(obj5)); WaterPlugin.Log.LogInfo((object)("Faces E/W/N/S " + Show(_faces[0]) + " " + Show(_faces[1]) + " " + Show(_faces[2]) + " " + Show(_faces[3]))); ManualLogSource log2 = WaterPlugin.Log; string[] obj6 = new string[13] { "Horizon colour ", val7.r.ToString("0.00"), ", ", val7.g.ToString("0.00"), ", ", val7.b.ToString("0.00"), " (sun ", null, null, null, null, null, null }; object obj7; if (!((Object)(object)_sun != (Object)null)) { obj7 = "none"; } else { val3 = _sun.color; obj7 = ((object)(*(Color*)(&val3))/*cast due to .constrained prefix*/).ToString(); } obj6[7] = (string)obj7; obj6[8] = ", exposure "; obj6[9] = TakeFloat("_Exposure", 1f).ToString("0.00"); obj6[10] = ", horizonLit "; obj6[11] = num11.ToString("0.00"); obj6[12] = ")"; log2.LogInfo((object)string.Concat(obj6)); } PutColor("_SkyTint", Color.Lerp(val5, val7, 0.4f)); } private void OnDestroy() { //IL_00b1: Unknown result type (might be due to invalid IL or missing references) if (_fogAtRender != null) { RenderPipelineManager.beginCameraRendering -= _fogAtRender; } if ((Object)(object)_probeT != (Object)null) { Object.Destroy((Object)(object)((Component)_probeT).gameObject); } if ((Object)(object)_skyRT != (Object)null) { _skyRT.Release(); } if ((Object)(object)_shoreMap != (Object)null) { Object.Destroy((Object)(object)_shoreMap); } for (int i = 0; i < _clouds.Count; i++) { if ((Object)(object)_clouds[i] != (Object)null && (Object)(object)_clouds[i].sharedMaterial != (Object)null) { _clouds[i].sharedMaterial.SetColor("_Color", _cloudWas[i]); } } } private static bool IsSomethingFloating(RaycastHit hit) { Collider collider = ((RaycastHit)(ref hit)).collider; if ((Object)(object)collider == (Object)null) { return false; } if ((Object)(object)((RaycastHit)(ref hit)).rigidbody != (Object)null) { return true; } if (((Component)collider).gameObject.layer == 3) { return true; } MonoBehaviour[] componentsInParent = ((Component)collider).GetComponentsInParent(true); foreach (MonoBehaviour val in componentsInParent) { if (!((Object)(object)val == (Object)null)) { string name = ((object)val).GetType().Name; if (name == "Player" || name == "Boat") { return true; } } } return false; } private void MaybeMapSeabed() { //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_0038: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0661: Unknown result type (might be due to invalid IL or missing references) //IL_0662: Unknown result type (might be due to invalid IL or missing references) //IL_0685: Unknown result type (might be due to invalid IL or missing references) //IL_068b: Unknown result type (might be due to invalid IL or missing references) //IL_069f: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0789: Unknown result type (might be due to invalid IL or missing references) //IL_078e: 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_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0572: Unknown result type (might be due to invalid IL or missing references) //IL_0578: Unknown result type (might be due to invalid IL or missing references) //IL_057e: Unknown result type (might be due to invalid IL or missing references) //IL_0583: Unknown result type (might be due to invalid IL or missing references) Transform val = Eye(); if ((Object)(object)val == (Object)null) { return; } Vector3 position = val.position; position.y = _waterY; float num = 300f; Vector3 val2; if ((Object)(object)_shoreMap != (Object)null) { val2 = position - _shoreCentre; if (((Vector3)(ref val2)).sqrMagnitude < 14400f) { return; } } int num2 = Mathf.Clamp(WaterPlugin.IsUltra ? Mathf.Max(WaterPlugin.ShoreDetail.Value, 384) : WaterPlugin.ShoreDetail.Value, 64, 512); int num3 = -1; Texture2D val3 = new Texture2D(num2, num2, (TextureFormat)17, false, true); ((Texture)val3).wrapMode = (TextureWrapMode)1; ((Texture)val3).filterMode = (FilterMode)1; Color[] array = (Color[])(object)new Color[num2 * num2]; float num4 = num * 2f / (float)(num2 - 1); float num5 = _waterY + 60f; float num6 = _waterY - 14f; int num7 = 0; int num8 = 0; float num9 = -9999f; Dictionary dictionary = new Dictionary(); Dictionary dictionary2 = new Dictionary(); RaycastHit hit = default(RaycastHit); for (int i = 0; i < num2; i++) { float num10 = position.z - num + (float)i * num4; for (int j = 0; j < num2; j++) { float num11 = position.x - num + (float)j * num4; float num12 = num6; if (Physics.Raycast(new Vector3(num11, num5, num10), Vector3.down, ref hit, 400f, num3, (QueryTriggerInteraction)1) && !IsSomethingFloating(hit)) { num12 = ((RaycastHit)(ref hit)).point.y; num7++; if (num12 > num9) { num9 = num12; } num8 |= 1 << ((Component)((RaycastHit)(ref hit)).collider).gameObject.layer; if (num12 > _waterY - 3f) { string key = ((Object)((Component)((RaycastHit)(ref hit)).collider).transform.root).name + " > " + ((Object)((RaycastHit)(ref hit)).collider).name + " [" + ((object)((RaycastHit)(ref hit)).collider).GetType().Name + ", layer " + ((Component)((RaycastHit)(ref hit)).collider).gameObject.layer + (((Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent() != (Object)null) ? ", rendered" : ", no renderer") + "]"; dictionary.TryGetValue(key, out var value); dictionary[key] = value + 1; if (value == 0) { dictionary2[key] = ((RaycastHit)(ref hit)).point; } } } array[i * num2 + j].r = num12; } } int num13 = Mathf.Clamp(Mathf.RoundToInt(45f / num4), 1, 64); bool[] array2 = new bool[num2 * num2]; List list = new List(); for (int k = 0; k < array.Length; k++) { if (!(array[k].r <= _waterY + 0.05f)) { array2[k] = true; list.Add(k); } } if (list.Count > 0) { List list2 = new List(); for (int l = 0; l < num13; l++) { list2.Clear(); for (int m = 0; m < list.Count; m++) { int num14 = list[m]; int num15 = num14 % num2; int num16 = num14 / num2; if (num15 > 0 && !array2[num14 - 1]) { array2[num14 - 1] = true; list2.Add(num14 - 1); } if (num15 < num2 - 1 && !array2[num14 + 1]) { array2[num14 + 1] = true; list2.Add(num14 + 1); } if (num16 > 0 && !array2[num14 - num2]) { array2[num14 - num2] = true; list2.Add(num14 - num2); } if (num16 < num2 - 1 && !array2[num14 + num2]) { array2[num14 + num2] = true; list2.Add(num14 + num2); } } if (list2.Count == 0) { break; } List list3 = list; list = list2; list2 = list3; } int num17 = 0; for (int n = 0; n < array.Length; n++) { if (!array2[n] && !(array[n].r <= _waterY - 6f)) { array[n].r = Mathf.Min(array[n].r, _waterY - 8f); num17++; } } if (num17 > 0) { WaterPlugin.Log.LogInfo((object)("Shore survey: " + num17 + " shallow cell(s) had no land to reach, so they are open water rather than beach. That is what drew a square of foam around a submerged plateau.")); } } try { float[] array3 = new float[array.Length]; for (int num18 = 0; num18 < array.Length; num18++) { array3[num18] = array[num18].r; } float peakLength = ((WaterPlugin.SwellLength != null) ? WaterPlugin.SwellLength.Value : 34f); ShoreField.Build(array3, num2, num4, _waterY, peakLength, out var dist, out var toSea); for (int num19 = 0; num19 < array.Length; num19++) { array[num19].g = dist[num19]; array[num19].b = toSea[num19].x; array[num19].a = toSea[num19].y; } Swell.Bed = array3; Swell.Dist = dist; Swell.Cells = num2; Swell.Centre = new Vector2(position.x, position.z); Swell.Extent = num; Swell.WaterY = _waterY; _shoreDist = dist; _shoreToSea = toSea; _shoreCells = num2; _shoreStep = num4; int num20 = 0; for (int num21 = 0; num21 < dist.Length; num21++) { if (dist[num21] > 0.01f && dist[num21] < 40f) { num20++; } } WaterPlugin.Log.LogInfo((object)("Shore field built: " + num20 + " cell(s) within 40m of the water's edge. Waves will turn to face it as they come in.")); } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Could not build the shore field, so the waves will not bend towards the coast: " + ex.Message)); } val3.SetPixels(array); val3.Apply(false, false); if ((Object)(object)_shoreMap != (Object)null) { Object.Destroy((Object)(object)_shoreMap); } _shoreMap = val3; _shoreCentre = position; _shoreExtent = num; PutTexture("_ShoreMap", (Texture)(object)_shoreMap); PutVector("_ShoreArea", new Vector4(position.x, position.z, num, 1f / (num * 2f))); PutFloat("_UseShore", 1f); if ((Object)(object)_skyCam != (Object)null && num8 != 0 && !_skyFound) { _skyCam.cullingMask = ~num8; } int num22 = 0; for (int num23 = 0; num23 < array.Length; num23++) { float num24 = _waterY - array[num23].r; if (num24 > 0f && num24 < 8f) { num22++; } } foreach (KeyValuePair item in dictionary) { ManualLogSource log = WaterPlugin.Log; string[] obj = new string[9] { "Shallow or dry under the ray: ", item.Key, " - ", item.Value.ToString(), " cell(s), first at ", null, null, null, null }; val2 = dictionary2[item.Key]; obj[5] = ((Vector3)(ref val2)).ToString("0.0"); obj[6] = " (player at "; obj[7] = ((Vector3)(ref position)).ToString("0.0"); obj[8] = ")"; log.LogInfo((object)string.Concat(obj)); } WaterPlugin.Log.LogInfo((object)("Seabed mapped: " + num2 + "x" + num2 + " over " + (num * 2f).ToString("0") + "m, " + num7 + "/" + num2 * num2 + " rays landed, waterline y=" + _waterY.ToString("0.00") + ", seabed highest y=" + num9.ToString("0.00") + "; " + num22 + " samples in 0-8m of water (" + (100f * (float)num22 / (float)array.Length).ToString("0.0") + "%).")); if (num7 == 0) { WaterPlugin.Log.LogWarning((object)"No rays hit anything - the shoreline will stay off."); } } private void ReadSkyColours() { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_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_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_0150: 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_016d: 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_015e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_skyRT == (Object)null || !_skyRT.IsCreated()) { return; } if ((Object)(object)_read == (Object)null) { _read = new Texture2D(8, 8, (TextureFormat)4, false, false); } RenderTexture active = RenderTexture.active; int width = ((Texture)_skyRT).width; Rect val = default(Rect); ((Rect)(ref val))..ctor((float)width * 0.5f - 4f, (float)width * 0.52f, 8f, 8f); CubemapFace[] array = new CubemapFace[4]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); CubemapFace[] array2 = (CubemapFace[])(object)array; string[] array3 = new string[4] { "_HorizonPX", "_HorizonNX", "_HorizonPZ", "_HorizonNZ" }; for (int i = 0; i < 4; i++) { Graphics.SetRenderTarget(_skyRT, 0, array2[i]); _read.ReadPixels(val, 0, 0, false); _read.Apply(false, false); Color val2 = Color.clear; Color[] pixels = _read.GetPixels(); Color[] array4 = pixels; foreach (Color val3 in array4) { val2 += val3; } val2 /= (float)pixels.Length; val2.a = 1f; if (((Color)(ref val2)).maxColorComponent > 0.01f) { PutColor(array3[i], val2); if (i == 0) { _skyAtHorizon = val2; } _faces[i] = val2; } } RenderTexture.active = active; } private int SkyLayers() { int num = 0; found = ""; Transform[] array = Object.FindObjectsByType((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Transform val in array) { if (((Object)val).name.IndexOf("nightsky", StringComparison.OrdinalIgnoreCase) >= 0) { Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren(true); foreach (Transform val2 in componentsInChildren) { num |= 1 << ((Component)val2).gameObject.layer; } found = found + ((found.Length > 0) ? " + " : "") + ((Object)val).name + " hierarchy"; } } Renderer[] array2 = Object.FindObjectsByType((FindObjectsInactive)1, (FindObjectsSortMode)0); foreach (Renderer val3 in array2) { Material sharedMaterial = val3.sharedMaterial; if ((Object)(object)sharedMaterial == (Object)null) { continue; } string text = (((Object)sharedMaterial).name + " " + (((Object)(object)sharedMaterial.shader != (Object)null) ? ((Object)sharedMaterial.shader).name : "")).ToLowerInvariant(); if (text.Contains("cloud") || text.Contains("sky") || text.Contains("star") || text.Contains("moon") || text.Contains("galaxy") || text.Contains("dusk") || text.Contains("shade") || text.Contains("glow") || text.Contains("halo") || text.Contains("sundisc") || text.Contains("meteor")) { int num2 = 1 << ((Component)val3).gameObject.layer; if ((num & num2) == 0) { found = found + ((found.Length > 0) ? ", " : "") + ((Object)sharedMaterial).name + " (layer " + ((Component)val3).gameObject.layer + ")"; } num |= num2; } } return num; } private void TintClouds(Color sky, float level) { //IL_00fb: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_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_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0176: 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_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_0192: 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) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: 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_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: 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_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0279: 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) //IL_029d: Unknown result type (might be due to invalid IL or missing references) if (_clouds.Count == 0) { Renderer[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Renderer val in array) { Material val2 = (((Object)(object)val != (Object)null) ? val.sharedMaterial : null); if (!((Object)(object)val2 == (Object)null) && val2.HasProperty("_Color") && ((Object)val2).name.IndexOf("cloudsbackground", StringComparison.OrdinalIgnoreCase) >= 0) { _clouds.Add(val); _cloudWas.Add(val2.GetColor("_Color")); WaterPlugin.Log.LogInfo((object)("Backdrop sphere " + ((Object)((Component)val).gameObject).name + " was " + ((object)val2.GetColor("_Color")/*cast due to .constrained prefix*/).ToString())); } } if (_clouds.Count == 0) { return; } } float num = Mathf.Max(((Color)(ref sky)).maxColorComponent, 0.001f); Color val3 = sky / num; for (int j = 0; j < _clouds.Count; j++) { Renderer val4 = _clouds[j]; if ((Object)(object)val4 == (Object)null) { continue; } Material sharedMaterial = val4.sharedMaterial; if (!((Object)(object)sharedMaterial == (Object)null)) { Color val5 = _cloudWas[j]; Color val6 = new Color(val5.r * val3.r, val5.g * val3.g, val5.b * val3.b, val5.a) * level; while (_cloudNow.Count <= j) { _cloudNow.Add(Color.clear); } Color val7 = _cloudNow[j]; if (val7.a <= 0f) { val7 = val6; } Color val8 = Color.Lerp(val7, val6, 0.3f); _cloudNow[j] = val8; if (_cloudSayAt <= Time.time && Mathf.Abs(val6.r - val7.r) + Mathf.Abs(val6.g - val7.g) + Mathf.Abs(val6.b - val7.b) > 0.25f * Mathf.Max(((Color)(ref val7)).maxColorComponent, 0.1f)) { _cloudSayAt = Time.time + 10f; WaterPlugin.Log.LogInfo((object)("Backdrop tint asked to jump from " + Show(val7) + " to " + Show(val6) + " (sky sample " + Show(sky) + ", level " + level.ToString("0.00") + ") - smoothed rather than snapped.")); } sharedMaterial.SetColor("_Color", val8); } } } private void WatchTheLighting() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: 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_005e: Invalid comparison between Unknown and I4 //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: 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_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0156: 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_0173: 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_0228: 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_0230: Unknown result type (might be due to invalid IL or missing references) if (!_wHooked) { _wHooked = true; RenderPipelineManager.beginCameraRendering += delegate(ScriptableRenderContext ctx, Camera cam) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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_00c4: 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_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)cam == (Object)null)) { string key = ((Object)cam).name + (((Object)(object)cam.targetTexture != (Object)null) ? " (to texture)" : ""); _wCams.TryGetValue(key, out var value); _wCams[key] = value + 1; if (!((Object)(object)cam.targetTexture != (Object)null)) { if (Diff(RenderSettings.ambientLight, _rAmb)) { _rAmbN++; } if (Diff(RenderSettings.fogColor, _rFog)) { _rFogN++; } if (Mathf.Abs(RenderSettings.reflectionIntensity - _rRefl) > 0.02f) { _rReflN++; } _rAmb = RenderSettings.ambientLight; _rFog = RenderSettings.fogColor; _rRefl = RenderSettings.reflectionIntensity; } } }; } float num = 0f; Color val = Color.black; int num2 = 0; Light[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Light val2 in array) { if (!((Object)(object)val2 == (Object)null) && ((Behaviour)val2).isActiveAndEnabled && (int)val2.type == 1) { num2++; num += val2.intensity; val += val2.color * val2.intensity; } } if (Mathf.Abs(num - _wSunI) > 0.03f * Mathf.Max(_wSunI, 0.05f)) { _wSunN++; } if (Diff(val, _wSunC)) { _wSunCN++; } _wSunI = num; _wSunC = val; _wSuns = num2; Color ambientLight = RenderSettings.ambientLight; Color fogColor = RenderSettings.fogColor; float fogDensity = RenderSettings.fogDensity; float reflectionIntensity = RenderSettings.reflectionIntensity; float ambientIntensity = RenderSettings.ambientIntensity; int num4 = (((Object)(object)RenderSettings.skybox != (Object)null) ? ((Object)RenderSettings.skybox).GetInstanceID() : 0); int num5 = (((Object)(object)RenderSettings.customReflectionTexture != (Object)null) ? ((Object)RenderSettings.customReflectionTexture).GetInstanceID() : 0); if (Diff(ambientLight, _wAmb)) { _wAmbN++; } if (Diff(fogColor, _wFog)) { _wFogN++; } if (Mathf.Abs(fogDensity - _wFogD) > 0.0005f) { _wFogDN++; } if (Mathf.Abs(reflectionIntensity - _wRefl) > 0.02f) { _wReflN++; } if (Mathf.Abs(ambientIntensity - _wAmbI) > 0.02f) { _wAmbIN++; } if (num4 != _wSky) { _wSkyN++; } if (num5 != _wCube) { _wCubeN++; } _wAmb = ambientLight; _wFog = fogColor; _wFogD = fogDensity; _wRefl = reflectionIntensity; _wAmbI = ambientIntensity; _wSky = num4; _wCube = num5; if (!(Time.time >= _wSayAt)) { return; } _wSayAt = Time.time + 5f; string text = ""; foreach (KeyValuePair wCam in _wCams) { text = text + " " + wCam.Key + " x" + wCam.Value; } _wCams.Clear(); WaterPlugin.Log.LogInfo((object)("Lighting watch (5s): ambient changed " + _wAmbN + "x, fog colour " + _wFogN + "x, fog density " + _wFogDN + "x, reflection strength " + _wReflN + "x, ambient strength " + _wAmbIN + "x, skybox swapped " + _wSkyN + "x, reflection cubemap swapped " + _wCubeN + "x. At render time: ambient " + _rAmbN + "x, fog " + _rFogN + "x, reflection " + _rReflN + "x. Suns: " + _wSuns + ", intensity changed " + _wSunN + "x, colour " + _wSunCN + "x. Mod " + (_live ? "on" : "off") + ". Cameras:" + text)); _wAmbN = (_wFogN = (_wFogDN = (_wReflN = (_wAmbIN = (_wSkyN = (_wCubeN = 0)))))); _rAmbN = (_rFogN = (_rReflN = (_wSunN = (_wSunCN = 0)))); } private static bool Diff(Color a, Color b) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) return Mathf.Abs(a.r - b.r) + Mathf.Abs(a.g - b.g) + Mathf.Abs(a.b - b.b) > 0.03f; } private void FeedLights(Vector3 near) { //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) //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_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Invalid comparison between Unknown and I4 //IL_0149: 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_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019b: 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_01a9: 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_01ba: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (Time.time >= _nextLampScan) { _nextLampScan = Time.time + 0.4f; _lamps.Clear(); Light[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Light val in array) { if (!((Object)(object)val == (Object)null) && ((Behaviour)val).isActiveAndEnabled && (int)val.type != 1 && !(val.intensity <= 0.01f) && !(val.range <= 0.1f)) { Vector3 val2 = ((Component)val).transform.position - near; if (!(((Vector3)(ref val2)).sqrMagnitude > (val.range + 40f) * (val.range + 40f))) { _lamps.Add(val); } } } _lamps.Sort(delegate(Light a, Light b) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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) float value = a.intensity / Mathf.Max(0.5f, Vector3.Distance(((Component)a).transform.position, near)); return (b.intensity / Mathf.Max(0.5f, Vector3.Distance(((Component)b).transform.position, near))).CompareTo(value); }); } for (int num = 0; num < 4; num++) { if (num < _lamps.Count && (Object)(object)_lamps[num] != (Object)null && ((Behaviour)_lamps[num]).isActiveAndEnabled) { Light val3 = _lamps[num]; Vector3 position = ((Component)val3).transform.position; _lampPos[num] = new Vector4(position.x, position.y, position.z, val3.range); Color val4 = val3.color * val3.intensity; _lampCol[num] = new Vector4(val4.r, val4.g, val4.b, 1f); } else { _lampPos[num] = Vector4.zero; _lampCol[num] = Vector4.zero; } } _mat.SetVectorArray("_PointPos", _lampPos); _mat.SetVectorArray("_PointCol", _lampCol); } private static string Show(Color c) { return "(" + c.r.ToString("0.00") + "," + c.g.ToString("0.00") + "," + c.b.ToString("0.00") + ")"; } private static Transform Eye() { Camera main = Camera.main; if ((Object)(object)main != (Object)null) { return ((Component)main).transform; } Camera[] allCameras = Camera.allCameras; foreach (Camera val in allCameras) { if ((Object)(object)val != (Object)null && ((Behaviour)val).isActiveAndEnabled) { return ((Component)val).transform; } } return null; } private void BindSky(bool announce) { Texture val = (Texture)(((Object)(object)_probe.realtimeTexture != (Object)null) ? ((object)_probe.realtimeTexture) : ((object)_probe.texture)); if ((Object)(object)val == (Object)null) { PutFloat("_SkyReflect", 0f); if (announce) { WaterPlugin.Log.LogWarning((object)"The sky probe produced no cubemap - falling back to the plain sky gradient."); } return; } PutTexture("_SeaSky", val); PutFloat("_SkyReflect", 1f); if (announce) { WaterPlugin.Log.LogInfo((object)("Sky cubemap bound: " + val.width + "px, " + ((object)val).GetType().Name + ".")); } } private static Light BrightestSun() { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 Light val = null; Light[] array = Object.FindObjectsByType((FindObjectsInactive)0, (FindObjectsSortMode)0); foreach (Light val2 in array) { if ((int)val2.type == 1 && ((Behaviour)val2).isActiveAndEnabled && ((Object)(object)val == (Object)null || val2.intensity > val.intensity)) { val = val2; } } return val; } } public static class ShaderMenu { private class Row { public GameObject Go; public string Label; public Func Get; public Action Set; public Func Show; } public static class PauseHooks { [HarmonyPatch(typeof(PauseManager), "OnPause")] [HarmonyPostfix] private static void AfterPause() { try { OnPauseChanged(); } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Shaders menu: " + ex)); } } [HarmonyPatch(typeof(PauseManager), "MainPauseScreenOrClose")] [HarmonyPostfix] private static void AfterBack() { try { Hide(); } catch (Exception ex) { WaterPlugin.Log.LogWarning((object)("Shaders menu: " + ex)); } } } private static GameObject _button; private static GameObject _screen; private static GameObject _mainScreen; private static bool _dumped; private static readonly List _rows = new List(); private static void OnPauseChanged() { if (!PauseManager.IsPaused) { Hide(); return; } if ((Object)(object)_button == (Object)null || (Object)(object)_screen == (Object)null) { Build(); } Hide(); } private static T Field(object on, string name) where T : class { try { FieldInfo fieldInfo = AccessTools.Field(on.GetType(), name); return (fieldInfo != null) ? (fieldInfo.GetValue(on) as T) : null; } catch { return null; } } private static void Build() { //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_030b: Unknown result type (might be due to invalid IL or missing references) //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_0301: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0616: Unknown result type (might be due to invalid IL or missing references) //IL_05f2: Unknown result type (might be due to invalid IL or missing references) //IL_05f7: Unknown result type (might be due to invalid IL or missing references) //IL_0606: Unknown result type (might be due to invalid IL or missing references) //IL_060b: Unknown result type (might be due to invalid IL or missing references) object? value = AccessTools.Field(typeof(PauseManager), "_instance").GetValue(null); PauseManager val = (PauseManager)((value is PauseManager) ? value : null); if ((Object)(object)val == (Object)null) { return; } _mainScreen = Field(val, "_mainScreen"); GameObject val2 = Field(val, "_mainMenuButton"); if ((Object)(object)_mainScreen == (Object)null || (Object)(object)val2 == (Object)null) { WaterPlugin.Log.LogWarning((object)"Shaders menu: the pause screen does not look the way this was written for, so there is no Shaders button. The config still works."); return; } if (!_dumped) { _dumped = true; WaterPlugin.Log.LogInfo((object)"Pause screen layout, for the record:"); Dump(_mainScreen.transform, 0, 5); } _button = Object.Instantiate(val2, val2.transform.parent); ((Object)_button).name = "ShadersButton"; _button.transform.SetSiblingIndex(val2.transform.GetSiblingIndex()); _button.SetActive(true); Unlocalise(_button); SetLabel(_button, "Shaders"); Rewire(_button, Open); _screen = Object.Instantiate(_mainScreen, _mainScreen.transform.parent); ((Object)_screen).name = "ShadersScreen"; _screen.transform.SetSiblingIndex(_mainScreen.transform.GetSiblingIndex() + 1); Transform val3 = _screen.transform.Find(PathUnder(_mainScreen.transform, val2.transform)); Button[] componentsInChildren; if ((Object)(object)val3 == (Object)null) { componentsInChildren = _screen.GetComponentsInChildren