Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of WaterAndTarPools v1.0.1
WaterAndTarPools/WaterAndTarPools.dll
Decompiled 2 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; 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.Security.Cryptography; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using DrainTarPit; using DrainTarPit.Building; using DrainTarPit.Debug; using DrainTarPit.Drain; using DrainTarPit.TextLocal; using DrainTarPit.Ui; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using UnityEngine.UIElements; using WaterAndTarPools.Debug; using WaterAndTarPools.Drain; using WaterAndTarPools.Logging; using WaterAndTarPools.Signs; using WaterAndTarPools.Ui; using WaterAndTarPools.Visuals; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("KydlTools")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.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 WaterAndTarPools { internal static class OldFiles { internal static int Carry() { int num = 0; num += Move("DrainTarPit.WaterLook.txt", "WaterAndTarPools.WaterLook.txt", folder: false); num += Move("DrainTarPit.SignStyle.txt", "WaterAndTarPools.SignStyle.txt", folder: false); num += Move("DrainTarPit.PoolStyles", "WaterAndTarPools.PoolStyles", folder: true); ModLog.Verbose("OldFiles: " + num + " file(s) / folder(s) carried over from the DrainTarPit names"); return num; } private static int Move(string oldName, string newName, bool folder) { string text = Path.Combine(Paths.ConfigPath, oldName); string text2 = Path.Combine(Paths.ConfigPath, newName); try { bool num; if (!folder) { if (File.Exists(text)) { num = File.Exists(text2); goto IL_003f; } } else if (Directory.Exists(text)) { num = Directory.Exists(text2); goto IL_003f; } goto IL_0041; IL_003f: if (!num) { if (folder) { Directory.Move(text, text2); } else { File.Move(text, text2); } ModLog.Info("OldFiles: " + oldName + " renamed to " + newName); return 1; } goto IL_0041; IL_0041: return 0; } catch (IOException ex) { ModLog.Warn("OldFiles: " + oldName + " could not be renamed to " + newName + ": " + ex.Message); return 0; } catch (UnauthorizedAccessException ex2) { ModLog.Warn("OldFiles: no permission to rename " + oldName + ": " + ex2.Message); return 0; } } } [BepInPlugin("com.kydldev.WaterAndTarPools", "WaterAndTarPools", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { public const string ModGuid = "com.kydldev.WaterAndTarPools"; public const string ModName = "WaterAndTarPools"; public const string ModVersion = "1.0.1"; public const string BundleName = "waterandtarpools"; internal static Plugin Instance; internal static AssetBundle Bundle { get; private set; } private void Awake() { //IL_01d1: Unknown result type (might be due to invalid IL or missing references) Instance = this; ModLog.Init(((BaseUnityPlugin)this).Logger); ModLog.Info("WaterAndTarPools 1.0.1 loaded (dll built " + File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location).ToString("yyyy-MM-dd HH:mm:ss") + ")"); PoolSettings.Bind(((BaseUnityPlugin)this).Config); OldFiles.Carry(); Bundle = LoadBundle(); AudioClip val = (((Object)(object)Bundle != (Object)null) ? Bundle.LoadAsset<AudioClip>("assets/audio/water_splash.ogg") : null); if ((Object)(object)val != (Object)null) { PoolHooks.Clips["water_splash"] = val; } ModLog.Verbose("Water splash sound " + (((Object)(object)val != (Object)null) ? ("handed to DrainTarPit (" + val.length.ToString("0.00") + " s)") : "not in the water bundle - water pours silently")); PoolHooks.PoolsMod = "WaterAndTarPools 1.0.1"; PoolHooks.Deposit = Deposit; PoolHooks.WaterColourFor = WaterTint.ColourFor; PoolVolumeHooks.Install(); PoolHooks.Commands["ptest"] = delegate(string[] args) { PoolTests.Run(args); }; PoolHooks.Commands["meshdump"] = delegate(string[] args) { DtpCommands.Print(MeshDump.Run((args.Length != 0 && int.TryParse(args[0], out var result)) ? result : 6)); }; PoolHooks.Commands["cleanpools"] = CleanPools; PrefabManager.OnVanillaPrefabsAvailable += RegisterSign; new Harmony("com.kydldev.WaterAndTarPools").PatchAll(Assembly.GetExecutingAssembly()); ModLog.Info("Hooked into DrainTarPit 1.0.0 (deposits, water colour, pool volume hooks, dtp ptest / meshdump / cleanpools)"); } private unsafe static void Deposit(Vector3 at, Vector3 dir, float volume, PumpLiquid liquid) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Invalid comparison between Unknown and I4 //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) if (!PoolSettings.On) { ModLog.Verbose("Deposit: " + ((object)(*(PumpLiquid*)(&liquid))/*cast due to .constrained prefix*/).ToString() + " not deposited, [General] EnableAll is off"); return; } bool value; if ((int)liquid != 1) { if ((int)liquid != 2) { goto IL_004c; } value = PoolSettings.DepositWater.Value; } else { value = PoolSettings.DepositTar.Value; } if (value) { TarPool.DepositAtNozzle(at, dir, volume, liquid); return; } goto IL_004c; IL_004c: ModLog.Verbose("Deposit: " + ((object)(*(PumpLiquid*)(&liquid))/*cast due to .constrained prefix*/).ToString() + " not deposited ([General] Deposit" + ((object)(*(PumpLiquid*)(&liquid))/*cast due to .constrained prefix*/).ToString() + " off), it only pours out visually"); } private static void CleanPools(string[] args) { float result = 1f; int num; if (args.Length != 0) { num = ((args[0].ToLowerInvariant() == "small") ? 1 : 0); if (num != 0 && args.Length > 1 && !float.TryParse(args[1].Replace(',', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { result = 1f; } } else { num = 0; } foreach (string item in (num != 0) ? PoolDebug.RemoveSmallPumpPools(Mathf.Max(0.01f, result)) : PoolDebug.RemoveJunkPools()) { DtpCommands.Print(item); } } private static void RegisterSign() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterSign; PoolSignPiece.Register(); PoolSignPlacement.LogTargets(); } private static AssetBundle LoadBundle() { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); foreach (string text in manifestResourceNames) { if (text != "waterandtarpools" && !text.EndsWith(".waterandtarpools")) { continue; } using Stream stream = executingAssembly.GetManifestResourceStream(text); using MemoryStream memoryStream = new MemoryStream(); stream?.CopyTo(memoryStream); AssetBundle val = AssetBundle.LoadFromMemory(memoryStream.ToArray()); if ((Object)(object)val != (Object)null) { ModLog.Info("Water bundle loaded from the DLL (" + val.GetAllAssetNames().Length + " assets)"); return val; } } string text2 = Path.Combine(Path.GetDirectoryName(executingAssembly.Location) ?? "", "waterandtarpools"); if (File.Exists(text2)) { AssetBundle val2 = AssetBundle.LoadFromFile(text2); if ((Object)(object)val2 != (Object)null) { ModLog.Info("Water bundle loaded from " + text2); return val2; } } ModLog.Error("Water bundle 'waterandtarpools' not found: only the Game water style works (Tropical / Lake / Ashlands need it)"); return null; } private void Update() { PoolRegistry.Tick(); PoolStyles.Tick(); if (!PoolSettings.On) { PoolSignMenu.Shut("mod switched off"); PoolMenu.Shut("mod switched off"); } else { PoolSignMenu.Tick(); PoolMenu.Tick(); } } internal void RunCoroutine(IEnumerator routine) { ((MonoBehaviour)this).StartCoroutine(routine); } } internal static class PoolSettings { public static ConfigEntry<bool> EnableAll; public static ConfigEntry<bool> DepositTar; public static ConfigEntry<bool> DepositWater; public static ConfigEntry<bool> DebugLog; public static ConfigEntry<float> EffectsVolume; public static ConfigEntry<bool> WaterSplashSound; public static ConfigEntry<bool> WaterSlugFlow; public static ConfigEntry<float> MinWaterDepth; public static ConfigEntry<bool> PoolWalls; public static ConfigEntry<bool> PoolOverflow; public static ConfigEntry<bool> PoolRimDisappear; public static ConfigEntry<bool> PoolRunoff; public static ConfigEntry<bool> PoolShedFilm; public static ConfigEntry<bool> PoolFilmEvaporates; public static ConfigEntry<bool> PoolFishStayIn; public static ConfigEntry<bool> PoolJumpBoost; public static ConfigEntry<int> PoolJumpPresses; public static ConfigEntry<float> PoolJumpHeight; public static ConfigEntry<float> LiquidCellSize; public static ConfigEntry<float> WaterFlow; public static ConfigEntry<float> WaterPoolSize; public static ConfigEntry<float> WaterDepthLook; public static ConfigEntry<KeyCode> PoolMenuKey; public static readonly Tunable<WaterStyleOption> WaterStyle = new Tunable<WaterStyleOption>("Visuals", "WaterStyle", (WaterStyleOption)0, "Water style of pools when no admin world style and no personal style is set."); public static readonly Tunable<bool> PoolMeshFix = new Tunable<bool>("Visuals", "PoolMeshFix", true, "Dry grid points near the water are put at the water level (no water sheet hanging on the walls)."); public static readonly Tunable<int> PoolMeshReach = new Tunable<int>("Visuals", "PoolMeshReach", 6, "PoolMeshFix: how many grid cells away from a wet point a dry point is still put at the water level."); public static readonly Tunable<float> SignBoardBrightness = new Tunable<float>("Visuals", "SignBoardBrightness", 1.5f, "Pool sign: brightness of the wooden board."); public static readonly Tunable<float> SignTextBrightness = new Tunable<float>("Visuals", "SignTextBrightness", 1.2f, "Pool sign: brightness of the name's colours."); public static readonly Tunable<float> PoolFilmDepth = new Tunable<float>("Pools", "PoolFilmDepth", 0.05f, "Depth (m) below which liquid counts as a thin film for PoolShedFilm."); public static bool On { get { if (EnableAll == null || EnableAll.Value) { return ModSettings.On; } return false; } } public static void Bind(ConfigFile c) { //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Expected O, but got Unknown //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Expected O, but got Unknown //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Expected O, but got Unknown //IL_02af: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Expected O, but got Unknown //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Expected O, but got Unknown //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Expected O, but got Unknown EnableAll = c.Bind<bool>("General", "EnableAll", true, "Switches the whole mod on / off while playing. Off: pumped liquid only pours out visually, no water pumping, no pool menus or sign editing, fish and the jump boost are left to the game. Pools already in the world stay."); DepositTar = c.Bind<bool>("General", "DepositTar", true, "Pumped tar is poured into a real tar pool where the stream from the nozzle lands: it fills the lowest basin around that point (a hole dug with the pickaxe, a dip enclosed by walls) up to its rim. The pool slows players, is saved in the world and can be pumped again. Off = the tar only pours out visually."); DepositWater = c.Bind<bool>("General", "DepositWater", true, "Pumped water is poured into a real water pool where the stream from the nozzle lands (a hole, a moat, a dip enclosed by walls), saved in the world and pumpable again. Water that lands in the sea or a lake just joins it. Off = the water only pours out visually."); DebugLog = c.Bind<bool>("DebugLog", "Enable", false, "Writes detailed lines about everything this mod does to the BepInEx log (for bug reports). Leave off while playing normally."); EffectsVolume = c.Bind<float>("Effects", "EffectsVolume", 0.6f, new ConfigDescription("Volume of the water splash (0 = silent). The pump sounds have their own volume in DrainTarPit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); WaterSplashSound = c.Bind<bool>("Effects", "WaterSplashSound", true, "Play a water splash where the pumped water comes down. Off = water pours silently."); WaterSlugFlow = c.Bind<bool>("Effects", "WaterSlugFlow", true, "Show a slug of water travelling through see-through hoses on every pump stroke (its speed is DrainTarPit's LiquidFlowSpeed)."); MinWaterDepth = c.Bind<float>("Pools", "MinWaterDepth", 0.3f, new ConfigDescription("Minimum water depth (m) at the strainer tip for it to count as 'in water'.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 3f), Array.Empty<object>())); PoolWalls = c.Bind<bool>("Pools", "PoolWalls", true, "Built pieces (stone / wood walls, floors, ...) hold the liquid of the pools the pump makes, like terrain does: a ring of walls fills up to the lowest point of its rim. Pieces of DrainTarPit, players and items are ignored; a roof floating over the pool does not count."); PoolRimDisappear = c.Bind<bool>("Pools", "PoolRimDisappear", true, "The rim is the lowest point of the walls / ground around a pool. On: the liquid rises to the rim and never higher; whatever would run over it disappears right there. Off: the liquid runs over the rim (see PoolOverflow)."); PoolOverflow = c.Bind<bool>("Pools", "PoolOverflow", true, "Only with PoolRimDisappear off: liquid running over the rim fills whatever basin lies behind it (up to 3 more); what finds no basin runs off. Off = it just runs off."); PoolRunoff = c.Bind<bool>("Pools", "PoolRunoff", true, "When the liquid reaches the edge of a pool's grid and the ground goes on downhill (a long moat, a ditch) it continues into the next pool beyond the edge (at most 6 in a row), so a moat longer than one pool fills end to end. On flat ground it runs off."); PoolShedFilm = c.Bind<bool>("Pools", "PoolShedFilm", true, "Liquid thinner than 5 cm (a film) on the outside of walls or on a slope slides off quickly instead of lingering. Off = the game's own slow spreading."); PoolFilmEvaporates = c.Bind<bool>("Pools", "PoolFilmEvaporates", true, "With PoolShedFilm: a film lying flat with nothing deeper next to it evaporates in a second or two. Off = such films stay."); PoolFishStayIn = c.Bind<bool>("Pools", "PoolFishStayIn", true, "Fish in a water pool stay in its water: they turn back at the walls and cannot jump out. Fish in the sea / lakes are never touched."); PoolJumpBoost = c.Bind<bool>("Pools", "PoolJumpBoost", true, "Getting out of a pool (water or tar): close to its edge (within 2 m), pressing Jump PoolJumpPresses times within 3 seconds lifts you PoolJumpHeight m up and towards the edge."); PoolJumpPresses = c.Bind<int>("Pools", "PoolJumpPresses", 3, new ConfigDescription("Jump presses within 3 seconds at the edge of a pool that give the lift (PoolJumpBoost).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 6), Array.Empty<object>())); PoolJumpHeight = c.Bind<float>("Pools", "PoolJumpHeight", 2f, new ConfigDescription("How high (m) the lift out of a pool takes your feet (PoolJumpBoost).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 5f), Array.Empty<object>())); WaterPoolSize = c.Bind<float>("Pools", "WaterPoolSize", 24f, new ConfigDescription("Side length (m) of one pool grid. Bigger pools hold longer moats in one piece but cost more simulation time. Read when the world loads; pools that already exist keep their size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(8f, 48f), Array.Empty<object>())); LiquidCellSize = c.Bind<float>("Pools", "LiquidCellSize", 0.25f, new ConfigDescription("Size (m) of one grid cell of a pool (tar and water). The liquid surface ends at a grid point, so smaller = it reaches the walls more closely, at more simulation time. Read when the world loads; pools that already exist keep their size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.15f, 0.5f), Array.Empty<object>())); WaterFlow = c.Bind<float>("Pools", "WaterFlow", 4f, new ConfigDescription("How freely water runs compared with tar: 1 = as thick as tar, 4 = about twice as fast, 16 = about four times.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 64f), Array.Empty<object>())); WaterDepthLook = c.Bind<float>("Visuals", "WaterDepthLook", 0.15f, new ConfigDescription("Game water style only: how deep the water looks (0 = shallow, calm and clear like the shore, 1 = open sea). Applies live.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); PoolMenuKey = c.Bind<KeyCode>("Visuals", "PoolMenuKey", (KeyCode)290, "Opens / closes the pool menu: the world water style (server admins), and every pool with a named pool sign (position, closest portal) with your own water style for it (only on your screen). None = no menu."); Sync(); EnableAll.SettingChanged += delegate { Sync(); ModLog.Info("Config: EnableAll = " + EnableAll.Value); }; MinWaterDepth.SettingChanged += delegate { Sync(); }; WaterSplashSound.SettingChanged += delegate { Sync(); }; EffectsVolume.SettingChanged += delegate { Sync(); }; WaterSlugFlow.SettingChanged += delegate { Sync(); }; WaterDepthLook.SettingChanged += delegate { PoolWater.RequestRefresh(); }; WaterStyle.SettingChanged += delegate { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) ModLog.Verbose("Config: WaterStyle = " + ((object)WaterStyle.Value/*cast due to .constrained prefix*/).ToString() + ", water pools redraw"); PoolWater.RequestRefresh(); }; PoolMeshFix.SettingChanged += delegate { PoolMesh.Refresh(); }; PoolMeshReach.SettingChanged += delegate { PoolMesh.Refresh(); }; SignBoardBrightness.SettingChanged += delegate { ModLog.Verbose("Config: SignBoardBrightness = " + SignBoardBrightness.Value + ", " + PoolSign.BrightnessChanged() + " sign(s) redrawn"); }; SignTextBrightness.SettingChanged += delegate { ModLog.Verbose("Config: SignTextBrightness = " + SignTextBrightness.Value + ", " + PoolSign.BrightnessChanged() + " sign(s) redrawn"); }; WaterFlow.SettingChanged += delegate { TarPool.ApplyWaterFlow(); }; PoolMesh.Refresh(); ModLog.Verbose("PoolSettings: bound (EnableAll " + EnableAll.Value + ", debug log " + DebugLog.Value + ")"); } internal static int Sync() { ModSettings.AllowWater.Value = On; ModSettings.MinWaterDepth.Value = MinWaterDepth.Value; ModSettings.WaterSplashSound.Value = WaterSplashSound.Value; ModSettings.WaterSplashVolume.Value = EffectsVolume.Value; ModSettings.WaterSlugFlow.Value = WaterSlugFlow.Value; ModLog.Verbose("PoolSettings: DrainTarPit water values set (water pumping " + (On ? "on" : "off") + ", min depth " + MinWaterDepth.Value.ToString("0.00") + " m, splash " + WaterSplashSound.Value + " at " + EffectsVolume.Value.ToString("0.00") + ", water slug " + WaterSlugFlow.Value + ")"); return ModSettings.AllowWater.Value ? 1 : 0; } } } namespace WaterAndTarPools.Visuals { internal static class PoolMesh { [HarmonyPatch(typeof(LiquidVolume), "PrebuildMesh")] private static class Patch_PrebuildMesh { private static void Prefix(LiquidVolume __instance, List<float> ___m_depths, List<float> ___m_heights) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) _fixFor = null; if (!_enabled || ((int)__instance.m_liquidType != 0 && !PumpPools.ContainsKey(__instance))) { return; } try { _fixFor = __instance; Build(__instance, ___m_depths, ___m_heights); } catch (Exception) { _fixFor = null; } } private static void Postfix(LiquidVolume __instance, List<float> ___m_depths, List<Color32> ___m_tempColors) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: 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_0100: Unknown result type (might be due to invalid IL or missing references) if (_fixFor != __instance || ___m_depths == null || ___m_tempColors == null) { return; } try { int width = __instance.m_width; int num = width + 1; int num2 = num * num; if (___m_depths.Count < num2 || ___m_tempColors.Count < num2) { return; } for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { int index = i * num + j; if (___m_depths[index] >= 0.05f || ___m_tempColors[index].a == byte.MaxValue) { continue; } bool flag = false; for (int k = -1; k <= 1; k++) { if (flag) { break; } for (int l = -1; l <= 1; l++) { int num3 = j + l; int num4 = i + k; if (num3 >= 0 && num4 >= 0 && num3 <= width && num4 <= width && ___m_depths[num4 * num + num3] >= 0.05f) { flag = true; break; } } } if (flag) { Color32 value = ___m_tempColors[index]; value.a = byte.MaxValue; ___m_tempColors[index] = value; } } } } catch (Exception) { } } private static void Finalizer() { _fixFor = null; } } [HarmonyPatch(typeof(LiquidVolume), "CalcVertex")] private static class Patch_CalcVertex { private static void Postfix(LiquidVolume __instance, int __0, int __1, bool __2, ref Vector3 __result) { if (__2 || _fixFor != __instance) { return; } float[] fix = _fix; int num = __1 * (__instance.m_width + 1) + __0; if (fix != null && num >= 0 && num < fix.Length) { float num2 = fix[num]; if (!float.IsNaN(num2)) { __result.y = num2; } } } } private static volatile bool _enabled = true; private static readonly ConcurrentDictionary<LiquidVolume, byte> PumpPools = new ConcurrentDictionary<LiquidVolume, byte>(); private const float DrawDepth = 0.05f; private const float UnderTop = 0.05f; private const float DeepDraw = 0.1f; private const int EdgeReach = 3; private static volatile int _reach = 6; [ThreadStatic] private static float[] _fix; [ThreadStatic] private static LiquidVolume _fixFor; [ThreadStatic] private static float[] _bufA; [ThreadStatic] private static float[] _bufB; internal static void MarkPumpPool(LiquidVolume v) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if ((Object)(object)v != (Object)null && (int)v.m_liquidType == 1) { PumpPools.TryAdd(v, 0); } } internal static void Forget(LiquidVolume v) { if ((Object)(object)v != (Object)null) { PumpPools.TryRemove(v, out var _); } } public static void Refresh() { if (PoolSettings.PoolMeshFix != null) { _enabled = PoolSettings.PoolMeshFix.Value; } if (PoolSettings.PoolMeshReach != null) { _reach = Mathf.Clamp(PoolSettings.PoolMeshReach.Value, 1, 24); } PoolDebug.MarkMeshDirty((LiquidType)0); } internal static float[] Explain(LiquidVolume v, List<float> d, List<float> h) { Build(v, d, h); int num = (v.m_width + 1) * (v.m_width + 1); if (_fix == null || _fix.Length < num) { return null; } float[] array = new float[num]; Array.Copy(_fix, array, num); return array; } private static void Build(LiquidVolume v, List<float> d, List<float> h) { int width = v.m_width; int num = width + 1; int num2 = num * num; if (d == null || h == null || d.Count < num2 || h.Count < num2) { _fixFor = null; return; } if (_fix == null || _fix.Length < num2) { _fix = new float[num2]; _bufA = new float[num2]; _bufB = new float[num2]; } int reach = _reach; float[] bufA = _bufA; float[] bufB = _bufB; for (int i = 0; i < num2; i++) { bufA[i] = ((d[i] >= 0.05f) ? (h[i] + ((d[i] > 0.1f) ? d[i] : 0.1f)) : float.PositiveInfinity); } for (int j = 0; j < num; j++) { int num3 = j * num; for (int k = 0; k < num; k++) { int num4 = ((k - reach >= 0) ? (k - reach) : 0); int num5 = ((k + reach > width) ? width : (k + reach)); float num6 = float.PositiveInfinity; for (int l = num4; l <= num5; l++) { float num7 = bufA[num3 + l]; if (num7 < num6) { num6 = num7; } } bufB[num3 + k] = num6; } } for (int m = 0; m < num; m++) { int num8 = ((m - reach >= 0) ? (m - reach) : 0); int num9 = ((m + reach > width) ? width : (m + reach)); for (int n = 0; n < num; n++) { float num10 = float.PositiveInfinity; for (int num11 = num8; num11 <= num9; num11++) { float num12 = bufB[num11 * num + n]; if (num12 < num10) { num10 = num12; } } bufA[m * num + n] = num10; } } float num13 = float.PositiveInfinity; for (int num14 = 0; num14 < num2; num14++) { if (h[num14] < num13) { num13 = h[num14]; } } num13 -= 1f; for (int num15 = 0; num15 < num2; num15++) { if (d[num15] >= 0.05f) { _fix[num15] = float.NaN; continue; } float num16 = bufA[num15]; _fix[num15] = ((num16 < float.PositiveInfinity && h[num15] >= num16) ? Mathf.Min(num16, h[num15] - 0.05f) : num13); bufB[num15] = ((num16 < float.PositiveInfinity && h[num15] < num16) ? 1f : 0f); } for (int num17 = 0; num17 < num; num17++) { for (int num18 = 0; num18 < num; num18++) { int num19 = num17 * num + num18; if (d[num19] >= 0.05f || bufB[num19] > 0f || float.IsNaN(_fix[num19])) { continue; } float num20 = float.PositiveInfinity; for (int num21 = -1; num21 <= 1; num21++) { for (int num22 = -1; num22 <= 1; num22++) { int num23 = num18 + num22; int num24 = num17 + num21; if (num23 >= 0 && num24 >= 0 && num23 <= width && num24 <= width) { int num25 = num24 * num + num23; if (bufB[num25] > 0f && _fix[num25] < num20) { num20 = _fix[num25]; } } } } if (num20 < _fix[num19]) { _fix[num19] = num20; } } } for (int num26 = 0; num26 < num; num26++) { for (int num27 = 0; num27 < num; num27++) { int num28 = num26 * num + num27; if (d[num28] >= 0.1f) { continue; } float num29 = float.NegativeInfinity; for (int num30 = -3; num30 <= 3; num30++) { for (int num31 = -3; num31 <= 3; num31++) { int num32 = num27 + num31; int num33 = num26 + num30; if (num32 < 0 || num33 < 0 || num32 > width || num33 > width) { continue; } int index = num33 * num + num32; if (!(d[index] < 0.1f)) { float num34 = h[index] + d[index]; if (num34 > num29) { num29 = num34; } } } } if (num29 == float.NegativeInfinity) { continue; } if (h[num28] < num29 - 0.05f) { if (d[num28] >= 0.001f) { _fix[num28] = num29; } continue; } bool flag = false; for (int num35 = -1; num35 <= 1; num35++) { if (flag) { break; } for (int num36 = -1; num36 <= 1; num36++) { int num37 = num27 + num36; int num38 = num26 + num35; if (num37 >= 0 && num38 >= 0 && num37 <= width && num38 <= width) { int index2 = num38 * num + num37; if (d[index2] < 0.001f && h[index2] < num29 - 0.05f) { flag = true; break; } } } } if (!flag) { _fix[num28] = Mathf.Min(num29, h[num28] - 0.05f); } } } } } internal static class PoolWater { [HarmonyPatch(typeof(LiquidVolume), "Update")] private static class Patch_Update { private static void Postfix(LiquidVolume __instance) { try { Tick(__instance); } catch (Exception ex) { ModLog.VerboseWarn("PoolWater.Tick: " + ex.Message); } } } [HarmonyPatch(typeof(LiquidVolume), "OnDestroy")] private static class Patch_OnDestroy { private static void Prefix(LiquidVolume __instance) { Done.Remove(__instance); } } private static readonly FieldInfo FSurface = AccessTools.Field(typeof(WaterVolume), "m_waterSurface"); private static readonly FieldInfo FWaterTime = AccessTools.Field(typeof(WaterVolume), "s_waterTime"); private static readonly PropertyInfo PInstances = AccessTools.Property(typeof(WaterVolume), "Instances"); private static Material _vanilla; private static Material _clear; private static int _gen = 1; private static int _configuredGen; private static float _nextSearch; private static int _timeFrame = -1; private static readonly Dictionary<LiquidVolume, int> Done = new Dictionary<LiquidVolume, int>(); private static bool _skipPreset; private const string WaterShader = "Custom/Water"; private static readonly Dictionary<WaterStyleOption, Material> StyleMats = new Dictionary<WaterStyleOption, Material>(); private static readonly HashSet<WaterStyleOption> StyleMissing = new HashSet<WaterStyleOption>(); internal static Material Active { get { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) WaterStyleOption val = (WaterStyleOption)((PoolSettings.WaterStyle != null) ? ((int)PoolSettings.WaterStyle.Value) : 0); if ((int)val != 0 && StyleMats.TryGetValue(val, out var value) && (Object)(object)value != (Object)null) { return value; } if (!((Object)(object)_vanilla != (Object)null)) { return _clear; } return _vanilla; } } internal static bool IsOceanCopy => (Object)(object)_vanilla != (Object)null; internal static WaterStyleOption StyleInUse => PoolStyles.Default; public static void RequestRefresh() { _gen++; } internal static void ResetLook(bool withPreset) { if ((Object)(object)_vanilla != (Object)null) { Object.Destroy((Object)(object)_vanilla); } _vanilla = null; _nextSearch = 0f; _skipPreset = !withPreset; _gen++; } internal static Material StyleLook() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return StyleLook(StyleInUse); } internal static Material StyleLook(WaterStyleOption s) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) if ((int)s != 0) { return StyleMaterial(s); } return null; } internal unsafe static int ResetStyle(WaterStyleOption style) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) int num = 0; if (StyleMats.TryGetValue(style, out var value)) { StyleMats.Remove(style); if ((Object)(object)value != (Object)null) { Object.Destroy((Object)(object)value); num++; } } StyleMissing.Remove(style); _gen++; ModLog.Verbose("PoolWater: water style " + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString() + " reset to its shipped values (" + num + " tuned copy thrown away, look generation " + _gen + ")"); return num; } public static Material ClearLook(Material tar) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_clear != (Object)null) { return _clear; } Color color = default(Color); ((Color)(ref color))..ctor(0.2f, 0.5f, 0.62f, 0.38f); Material val = null; Shader val2 = Shader.Find("Standard"); if ((Object)(object)val2 != (Object)null) { val = new Material(val2); val.SetFloat("_Mode", 3f); val.SetInt("_SrcBlend", 5); val.SetInt("_DstBlend", 10); val.SetInt("_ZWrite", 0); val.DisableKeyword("_ALPHATEST_ON"); val.EnableKeyword("_ALPHABLEND_ON"); val.DisableKeyword("_ALPHAPREMULTIPLY_ON"); if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.98f); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } } else if ((Object)(object)tar != (Object)null) { val = new Material(tar); if (val.HasProperty("_BumpScale")) { val.SetFloat("_BumpScale", 0.15f); } if (val.HasProperty("_Glossiness")) { val.SetFloat("_Glossiness", 0.98f); } if (val.HasProperty("_Smoothness")) { val.SetFloat("_Smoothness", 0.98f); } if (val.HasProperty("_Metallic")) { val.SetFloat("_Metallic", 0f); } } if ((Object)(object)val == (Object)null) { return null; } val.renderQueue = 3000; ((Object)val).name = "DTP_WaterClear"; val.color = color; Object.DontDestroyOnLoad((Object)(object)val); return _clear = val; } private static Material BuildVanilla() { //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown try { IEnumerable enumerable = ((PInstances != null) ? (PInstances.GetValue(null, null) as IEnumerable) : null); if (enumerable == null) { return FromLoadedMaterials(); } foreach (object item in enumerable) { WaterVolume val = (WaterVolume)((item is WaterVolume) ? item : null); MeshRenderer val2 = (MeshRenderer)(((Object)(object)val != (Object)null && FSurface != null) ? /*isinst with value type is only supported in some contexts*/: null); Material val3 = (((Object)(object)val2 != (Object)null) ? ((Renderer)val2).sharedMaterial : null); if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.shader == (Object)null)) { Material val4 = new Material(val3) { name = "DTP_WaterVanilla" }; Object.DontDestroyOnLoad((Object)(object)val4); ModLog.Info("PoolWater: using a copy of the game's ocean material '" + ((Object)val3).name + "' (shader '" + ((Object)val3.shader).name + "') for water pools."); return val4; } } } catch (Exception ex) { ModLog.Warn("PoolWater: could not copy the ocean material: " + ex.Message); } return FromLoadedMaterials(); } private static Material FromLoadedMaterials() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown //IL_00e4: Expected O, but got Unknown try { Material val = null; Material[] array = Resources.FindObjectsOfTypeAll<Material>(); foreach (Material val2 in array) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null) && !(((Object)val2.shader).name != "Custom/Water") && !((Object)val2).name.StartsWith("DTP_") && ((Object)(object)val == (Object)null || (((Object)val2).name.ToLowerInvariant().StartsWith("water") && !((Object)val).name.ToLowerInvariant().StartsWith("water")))) { val = val2; } } if ((Object)(object)val == (Object)null) { ModLog.Verbose("PoolWater: no ocean surface and no loaded 'Custom/Water' material yet, the plain tint is used for now"); return null; } Material val3 = new Material(val) { name = "DTP_WaterVanilla" }; Object.DontDestroyOnLoad((Object)val3); ModLog.Info("PoolWater: no ocean surface loaded, using a copy of the loaded game material '" + ((Object)val).name + "' (shader 'Custom/Water') for water pools."); return val3; } catch (Exception ex) { ModLog.Warn("PoolWater: could not search the loaded materials: " + ex.Message); return null; } } private static void Configure(Material m) { float num = Mathf.Clamp01(PoolSettings.WaterDepthLook.Value); m.SetFloatArray("_depth", new float[4] { num, num, num, num }); m.SetFloat("_UseGlobalWind", 0f); } private unsafe static Material StyleMaterial(WaterStyleOption style) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Expected O, but got Unknown //IL_015a: Unknown result type (might be due to invalid IL or missing references) if (StyleMats.TryGetValue(style, out var value) && (Object)(object)value != (Object)null) { return value; } if (StyleMissing.Contains(style)) { return null; } string text = "assets/materials/water/dtp_water_" + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString().ToLowerInvariant() + ".mat"; try { Material val = (((Object)(object)Plugin.Bundle != (Object)null) ? Plugin.Bundle.LoadAsset<Material>(text) : null); if ((Object)(object)val == (Object)null || (Object)(object)val.shader == (Object)null || !val.shader.isSupported) { StyleMissing.Add(style); ModLog.Warn("PoolWater: water style " + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString() + " is not usable (" + (((Object)(object)val == (Object)null) ? ("'" + text + "' not in the bundle") : ("shader " + (((Object)(object)val.shader == (Object)null) ? "missing" : (((Object)val.shader).name + " not supported on this graphics card")))) + ") - the Game water is used"); return null; } value = new Material(val) { name = "DTP_Water_" + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString() }; Object.DontDestroyOnLoad((Object)(object)value); StyleMats[style] = value; ModLog.Info("PoolWater: water style " + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString() + " loaded (material '" + ((Object)val).name + "', shader '" + ((Object)val.shader).name + "')"); return value; } catch (Exception ex) { StyleMissing.Add(style); ModLog.Warn("PoolWater: water style " + ((object)(*(WaterStyleOption*)(&style))/*cast due to .constrained prefix*/).ToString() + " could not be loaded: " + ex.Message + " - the Game water is used"); return null; } } private static Material Current(LiquidVolume v) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) WaterStyleOption val = (((Object)(object)v != (Object)null) ? PoolStyles.For(v) : StyleInUse); if ((int)val != 0) { Material val2 = StyleMaterial(val); if ((Object)(object)val2 != (Object)null) { return val2; } } return GameWater(); } private static Material GameWater() { if ((Object)(object)_vanilla == (Object)null && Time.unscaledTime >= _nextSearch) { _nextSearch = Time.unscaledTime + 2f; _vanilla = BuildVanilla(); if ((Object)(object)_vanilla != (Object)null) { _gen++; if (!_skipPreset) { WaterLook.Apply(_vanilla); } _skipPreset = false; } } if ((Object)(object)_vanilla != (Object)null) { if (_configuredGen != _gen) { Configure(_vanilla); _configuredGen = _gen; } return _vanilla; } return _clear; } private static void FeedTime() { if ((Object)(object)_vanilla == (Object)null || Time.frameCount == _timeFrame) { return; } _timeFrame = Time.frameCount; float num = Time.time; try { if (FWaterTime != null) { num = (float)FWaterTime.GetValue(null); } } catch { } _vanilla.SetFloat("_WaterTime", num); } private static void Tick(LiquidVolume v) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)v == (Object)null || (int)v.m_liquidType != 0 || (int)SystemInfo.graphicsDeviceType == 4) { return; } if ((Object)(object)_vanilla == (Object)null) { GameWater(); } if (Done.TryGetValue(v, out var value) && value == _gen) { FeedTime(); return; } Material val = Current(v); if ((Object)(object)val == (Object)null) { return; } if ((Object)(object)val == (Object)(object)_vanilla) { FeedTime(); } Done[v] = _gen; string[] obj = new string[9] { "PoolWater: pool ", ((Object)v).name, " at ", null, null, null, null, null, null }; Vector3 position = ((Component)v).transform.position; obj[3] = ((Vector3)(ref position)).ToString("0"); obj[4] = " drawn with '"; obj[5] = ((Object)val).name; obj[6] = "' (look generation "; obj[7] = _gen.ToString(); obj[8] = ")"; ModLog.Verbose(string.Concat(obj)); Renderer[] componentsInChildren = ((Component)v).GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if (!(val2 is ParticleSystemRenderer)) { Material[] array = (Material[])(object)new Material[Mathf.Max(1, val2.sharedMaterials.Length)]; for (int j = 0; j < array.Length; j++) { array[j] = val; } val2.sharedMaterials = array; val2.shadowCastingMode = (ShadowCastingMode)0; } } } } internal static class WaterLook { private static readonly CultureInfo Inv = CultureInfo.InvariantCulture; internal const string BuiltInResource = "WaterAndTarPools.WaterLook.txt"; public static string Path => System.IO.Path.Combine(Paths.ConfigPath, "WaterAndTarPools.WaterLook.txt"); private static string F(float v) { return v.ToString("R", Inv); } public static string Dump(Material m) { //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Expected I4, but got Unknown //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_011f: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0220: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0287: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); if ((Object)(object)m == (Object)null) { return ""; } Shader shader = m.shader; stringBuilder.AppendLine("# DrainTarPit water look - material '" + ((Object)m).name + "', shader '" + (((Object)(object)shader != (Object)null) ? ((Object)shader).name : "?") + "'"); stringBuilder.AppendLine("depth " + F(PoolSettings.WaterDepthLook.Value)); stringBuilder.AppendLine("queue " + m.renderQueue); if ((Object)(object)shader != (Object)null) { int propertyCount = shader.GetPropertyCount(); for (int i = 0; i < propertyCount; i++) { string propertyName = shader.GetPropertyName(i); ShaderPropertyType propertyType = shader.GetPropertyType(i); switch ((int)propertyType) { case 0: { Color color = m.GetColor(propertyName); stringBuilder.AppendLine("color " + propertyName + " " + F(color.r) + " " + F(color.g) + " " + F(color.b) + " " + F(color.a)); break; } case 1: { Vector4 vector = m.GetVector(propertyName); stringBuilder.AppendLine("vector " + propertyName + " " + F(vector.x) + " " + F(vector.y) + " " + F(vector.z) + " " + F(vector.w)); break; } case 4: { Vector2 textureScale = m.GetTextureScale(propertyName); Vector2 textureOffset = m.GetTextureOffset(propertyName); stringBuilder.AppendLine("tiling " + propertyName + " " + F(textureScale.x) + " " + F(textureScale.y) + " " + F(textureOffset.x) + " " + F(textureOffset.y)); break; } default: stringBuilder.AppendLine("float " + propertyName + " " + F(m.GetFloat(propertyName))); break; } } } string[] shaderKeywords = m.shaderKeywords; foreach (string text in shaderKeywords) { stringBuilder.AppendLine("keyword " + text); } return stringBuilder.ToString(); } public static bool Save(Material m) { try { File.WriteAllText(Path, Dump(m)); ModLog.Info("WaterLook: preset saved to " + Path); return true; } catch (Exception ex) { ModLog.Warn("WaterLook: could not save the preset: " + ex.Message); return false; } } private static string[] BuiltInLines() { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("WaterAndTarPools.WaterLook.txt"); if (stream == null) { ModLog.Warn("WaterLook: the built-in look (WaterAndTarPools.WaterLook.txt) is missing from the DLL - the pools keep the game's ocean look"); return null; } using StreamReader streamReader = new StreamReader(stream); return streamReader.ReadToEnd().Split(new char[1] { '\n' }, StringSplitOptions.None); } public static int Apply(Material m) { if ((Object)(object)m == (Object)null) { ModLog.Verbose("WaterLook: no material to apply the look to"); return 0; } bool flag = File.Exists(Path); string[] array; try { array = (flag ? File.ReadAllLines(Path) : BuiltInLines()); } catch (IOException ex) { ModLog.Warn("WaterLook: the preset file could not be read (" + ex.Message + "), the built-in look is used"); flag = false; array = BuiltInLines(); } if (array == null) { return 0; } ModLog.Verbose("WaterLook: applying the " + (flag ? ("saved look from " + Path) : "built-in look") + " (" + array.Length + " lines)"); return ApplyLines(m, array, flag ? Path : "the built-in look", flag); } private static int ApplyLines(Material m, string[] lines, string source, bool allowDepth) { //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) int num = 0; try { for (int i = 0; i < lines.Length; i++) { string text = lines[i].Trim(); if (text.Length == 0 || text[0] == '#') { continue; } string[] array = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (array.Length < 2) { continue; } try { string text2 = array[0]; if (text2 == null) { continue; } switch (text2.Length) { case 5: switch (text2[0]) { case 'f': if (text2 == "float" && array.Length >= 3 && m.HasProperty(array[1])) { m.SetFloat(array[1], Parse(array[2])); num++; } break; case 'c': if (text2 == "color" && array.Length >= 6 && m.HasProperty(array[1])) { m.SetColor(array[1], new Color(Parse(array[2]), Parse(array[3]), Parse(array[4]), Parse(array[5]))); num++; } break; case 'q': if (text2 == "queue") { m.renderQueue = (int)Parse(array[1]); num++; } break; case 'd': if (text2 == "depth") { if (!allowDepth) { ModLog.Verbose("WaterLook: depth " + array[1] + " of the built-in look skipped ([Drain] WaterDepthLook keeps " + ((PoolSettings.WaterDepthLook != null) ? PoolSettings.WaterDepthLook.Value.ToString("0.00") : "?") + ")"); } else if (PoolSettings.WaterDepthLook != null) { PoolSettings.WaterDepthLook.Value = Mathf.Clamp01(Parse(array[1])); num++; } } break; } break; case 6: switch (text2[0]) { case 'v': if (text2 == "vector" && array.Length >= 6 && m.HasProperty(array[1])) { m.SetVector(array[1], new Vector4(Parse(array[2]), Parse(array[3]), Parse(array[4]), Parse(array[5]))); num++; } break; case 't': if (text2 == "tiling" && array.Length >= 6 && m.HasProperty(array[1])) { m.SetTextureScale(array[1], new Vector2(Parse(array[2]), Parse(array[3]))); m.SetTextureOffset(array[1], new Vector2(Parse(array[4]), Parse(array[5]))); num++; } break; } break; case 7: if (text2 == "keyword") { m.EnableKeyword(array[1]); num++; } break; } } catch (FormatException ex) { ModLog.VerboseWarn("WaterLook: line skipped, a number could not be read '" + text + "': " + ex.Message); } catch (Exception ex2) { ModLog.VerboseWarn("WaterLook: line skipped '" + text + "': " + ex2.Message); } } ModLog.Info("WaterLook: " + num + " values from " + source + " applied to the pool water."); } catch (Exception ex3) { ModLog.Warn("WaterLook: could not apply the look from " + source + ": " + ex3.Message); } return num; } private static float Parse(string s) { return float.Parse(s, NumberStyles.Float, Inv); } } internal static class WaterTint { internal static readonly Color GameBody = new Color(0.3f, 0.55f, 0.72f, 1f); private static string _lastKey = ""; internal static WaterStyleOption Current(out Color body, out Color glow) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) return Current(PoolWater.StyleInUse, out body, out glow); } internal unsafe static WaterStyleOption Current(WaterStyleOption wanted, out Color body, out Color glow) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) body = GameBody; glow = Color.black; Material val = PoolWater.StyleLook(wanted); if ((Object)(object)val == (Object)null) { Note("Game", body, glow, "fixed blue (" + ((object)(*(WaterStyleOption*)(&wanted))/*cast due to .constrained prefix*/).ToString() + " style" + (((int)wanted == 0) ? "" : ", its material is not usable") + ")"); return (WaterStyleOption)0; } Derive(val, out body, out glow); return wanted; } internal unsafe static WaterStyleOption StyleFor(Vector3? source, Vector3? dest) { //IL_000e: 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_0053: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) LiquidVolume val = (source.HasValue ? WaterPoolAt(source.Value) : null); LiquidVolume val2 = (((Object)(object)val == (Object)null && dest.HasValue) ? WaterPoolAt(dest.Value) : null); LiquidVolume val3 = val ?? val2; WaterStyleOption result = (((Object)(object)val3 != (Object)null) ? PoolStyles.For(val3) : PoolWater.StyleInUse); ModLog.Verbose("WaterTint: pump water style " + ((object)(*(WaterStyleOption*)(&result))/*cast due to .constrained prefix*/).ToString() + " (" + (((Object)(object)val != (Object)null) ? ("from the pool the strainer is in, " + ((Object)val).name) : (((Object)(object)val2 != (Object)null) ? ("from the pool under the nozzle, " + ((Object)val2).name) : "no pump water pool at either end: default")) + ")"); return result; } internal unsafe static WaterColour ColourFor(DtpPiece pump, Vector3? source, Vector3? dest) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) Color body; Color glow; WaterStyleOption val = Current((!source.HasValue && (Object)(object)pump != (Object)null && dest.HasValue) ? ForPump(pump, dest.Value) : StyleFor(source, dest), out body, out glow); return new WaterColour { Key = ((object)(*(WaterStyleOption*)(&val))/*cast due to .constrained prefix*/).ToString(), Body = body, Glow = glow }; } internal static WaterStyleOption ForPump(DtpPiece pump, Vector3 nozzle) { //IL_0083: Expected O, but got Unknown //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) Vector3? source = null; try { HoseWalk val = (((Object)(object)pump != (Object)null) ? HoseNetwork.Walk(pump, "intake", (DtpKind)2) : null); if (val != null && val.Ok && (Object)(object)val.Terminal != (Object)null) { source = val.Terminal.StrainerTip; } else { ModLog.Verbose("WaterTint: pump intake chain " + ((val == null) ? "unknown (no pump)" : ("not complete (" + val.Reason + ")")) + ", only the nozzle end is used"); } } catch (MissingReferenceException ex) { MissingReferenceException ex2 = ex; ModLog.VerboseWarn("WaterTint: a hose was removed while its chain was followed (" + ((Exception)(object)ex2).Message + "), only the nozzle end is used"); } return StyleFor(source, nozzle); } private static LiquidVolume WaterPoolAt(Vector3 p) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) LiquidVolume val = default(LiquidVolume); float num = default(float); float num2 = default(float); if (!TarPits.TrySample(p, ref val, ref num, ref num2, (LiquidType)0) || !TarPits.IsPumpPool(val)) { return null; } return val; } private unsafe static void Derive(Material style, out Color body, out Color glow) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: 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_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_012a: 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_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0160: 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_017b: 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) Color val = (Color)(style.HasProperty("_Absorption") ? style.GetColor("_Absorption") : new Color(0.3f, 0.1f, 0.05f)); Color val2 = (Color)(style.HasProperty("_ScatterColor") ? style.GetColor("_ScatterColor") : new Color(0.05f, 0.3f, 0.33f)); Color val3 = default(Color); ((Color)(ref val3))..ctor(Mathf.Exp((0f - val.r) * 4f), Mathf.Exp((0f - val.g) * 4f), Mathf.Exp((0f - val.b) * 4f)); Color val4 = val3 * 0.6f + val2 * 0.6f; float num = Mathf.Max(((Color)(ref val4)).maxColorComponent, 0.001f); body = val4 * (0.6f / num); body.a = 1f; glow = (style.HasProperty("_Emission") ? (style.GetColor("_Emission") * 2f) : Color.black); glow.a = 1f; string name = ((Object)style).name; Color body2 = body; Color glow2 = glow; string[] obj = new string[6] { "absorption ", null, null, null, null, null }; Color val5 = val; obj[1] = ((object)(*(Color*)(&val5))/*cast due to .constrained prefix*/).ToString(); obj[2] = ", scatter "; val5 = val2; obj[3] = ((object)(*(Color*)(&val5))/*cast due to .constrained prefix*/).ToString(); obj[4] = ", through 1 m "; val5 = val3; obj[5] = ((object)(*(Color*)(&val5))/*cast due to .constrained prefix*/).ToString(); Note(name, body2, glow2, string.Concat(obj)); } private unsafe static void Note(string from, Color body, Color glow, string how) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) Color val = body; string? text = ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString(); val = glow; string text2 = from + text + ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString(); if (!(text2 == _lastKey)) { _lastKey = text2; string[] obj = new string[9] { "WaterTint: water effects colour from '", from, "': body ", null, null, null, null, null, null }; val = body; obj[3] = ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString(); obj[4] = ", glow "; val = glow; obj[5] = ((object)(*(Color*)(&val))/*cast due to .constrained prefix*/).ToString(); obj[6] = " ("; obj[7] = how; obj[8] = ")"; ModLog.Verbose(string.Concat(obj)); } } } } namespace WaterAndTarPools.Ui { public sealed class PoolMenuEntry { public string Id = ""; public string Name = ""; public string Style = ""; public string Portal = ""; public Vector3 Pos; public float PortalDistance = -1f; public string MyStyle = ""; public bool Tar; } public interface IPoolMenuHost { string MenuKey { get; } bool IsAdmin { get; } string WorldStyle { get; } string DefaultStyle { get; } IList<string> Styles { get; } IList<PoolMenuEntry> Pools { get; } bool Waiting { get; } string T(string key, params string[] args); void SetWorldStyle(string style); void SetPoolStyle(string id, string style); void Refresh(); void Close(string why); } public sealed class PoolMenuView { private readonly IPoolMenuHost _host; public readonly VisualElement Window; private readonly VisualElement _content; public PoolMenuView(IPoolMenuHost host) { _host = host; UiScroll val = default(UiScroll); Window = UiKit.Window(_host.T("dtp_ui_pools_title"), _host.T("dtp_ui_pools_close", _host.MenuKey), (Action)delegate { _host.Close("X"); }, ref val); _content = val.Content; Rebuild(); } public void Rebuild() { _content.Clear(); BuildWorld(); BuildList(); UiLog.Verbose("PoolMenuView: built (" + _host.Pools.Count + " pool(s), admin " + _host.IsAdmin + ", world style '" + _host.WorldStyle + "', waiting " + _host.Waiting + ")"); } private string StyleName(string s) { if (s.Length != 0) { return _host.T("dtp_ui_style_" + s.ToLowerInvariant()); } return _host.T("dtp_ui_style_notset"); } private void BuildWorld() { //IL_00fc: Unknown result type (might be due to invalid IL or missing references) _content.Add(UiControls.Heading(_host.T("dtp_ui_world_style"))); if (_host.IsAdmin) { List<string> list = new List<string> { "" }; list.AddRange(_host.Styles); _content.Add(UiControls.Row(_host.T("dtp_ui_world_style_all"), (VisualElement)(object)UiControls.Dropdown((IList<string>)list, _host.WorldStyle, (Func<string, string>)StyleName, (Action<string>)delegate(string s) { _host.SetWorldStyle(s); }))); _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_world_style_note"))); } else { _content.Add(UiControls.Row(_host.T("dtp_ui_world_style_all"), (VisualElement)(object)UiKit.Label(StyleName(_host.WorldStyle), 22f, UiKit.Gold, false))); _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_world_style_admin_only"))); } } private void BuildList() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) _content.Add(UiControls.Heading(_host.T("dtp_ui_pools"))); VisualElement val = UiControls.Line((VisualElement[])(object)new VisualElement[2] { (VisualElement)UiKit.Label(_host.T("dtp_ui_pools_count", _host.Pools.Count.ToString()), 22f, UiKit.Text, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_refresh"), (Action)_host.Refresh, false) }); val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)3); _content.Add(val); _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_pools_note"))); if (_host.Waiting && _host.Pools.Count == 0) { _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_pools_loading"))); return; } if (_host.Pools.Count == 0) { _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_pools_none"))); return; } foreach (PoolMenuEntry pool in _host.Pools) { _content.Add(Card(pool)); } } private VisualElement Card(PoolMenuEntry p) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) VisualElement val = new VisualElement(); val.style.flexShrink = StyleFloat.op_Implicit(0f); val.style.backgroundColor = StyleColor.op_Implicit(UiKit.PanelLight); UiKit.Borders(val, 1f, UiKit.Border); UiKit.Radius(val, 6f); UiKit.Pad(val, 10f, 14f); val.style.marginTop = StyleLength.op_Implicit(8f); Label val2 = new Label(SignStyle.Parse(p.Style).RenderForUi(p.Name)); ((TextElement)val2).enableRichText = true; ((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(28f); ((VisualElement)val2).style.flexShrink = StyleFloat.op_Implicit(0f); ((VisualElement)val2).style.whiteSpace = StyleEnum<WhiteSpace>.op_Implicit((WhiteSpace)0); val.Add((VisualElement)(object)val2); val.Add((VisualElement)(object)Info(_host.T("dtp_ui_pool_pos", p.Pos.x.ToString("0"), p.Pos.z.ToString("0"), p.Pos.y.ToString("0")))); val.Add((VisualElement)(object)Info((p.PortalDistance < 0f) ? _host.T("dtp_ui_pool_noportal") : _host.T("dtp_ui_pool_portal", (p.Portal.Length > 0) ? p.Portal : _host.T("dtp_ui_pool_portal_unnamed"), p.PortalDistance.ToString("0")))); List<string> list = new List<string> { "" }; list.AddRange(_host.Styles); string def = _host.T("dtp_ui_style_default", StyleName(_host.DefaultStyle)); string id = p.Id; Button val3 = UiControls.Dropdown((IList<string>)list, p.MyStyle, (Func<string, string>)((string s) => (!p.Tar) ? ((s.Length != 0) ? StyleName(s) : def) : _host.T("dtp_ui_tar_pool")), (Action<string>)delegate(string s) { _host.SetPoolStyle(id, s); }); if (p.Tar) { ((VisualElement)val3).SetEnabled(false); ((VisualElement)val3).style.opacity = StyleFloat.op_Implicit(0.5f); } val.Add(UiControls.Row(_host.T("dtp_ui_my_style"), (VisualElement)(object)val3)); UiLog.Verbose("PoolMenuView: card '" + p.Name + "' (" + (p.Tar ? "tar, style drop-down disabled" : ("water, my style '" + p.MyStyle + "'")) + ")"); return val; } private static Label Info(string text) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) Label obj = UiKit.Label(text, 18f, UiKit.TextDim, false); ((VisualElement)obj).style.flexShrink = StyleFloat.op_Implicit(0f); ((VisualElement)obj).style.marginTop = StyleLength.op_Implicit(2f); return obj; } } public interface ISignMenuHost { IList<string> Fonts { get; } int MaxLetters { get; } string T(string key, params string[] args); void Preview(string name, SignStyle style); void Save(string name, SignStyle style); void Close(string why); int SavePreferred(SignStyle style); SignStyle LoadPreferred(); } public sealed class SignMenuView { private static readonly string[] Emoji = new string[12] { "\ud83d\udc1f", "\ud83d\udca7", "\ud83c\udf0a", "\ud83d\udd25", "⚓", "⭐", "❤", "☠", "\ud83c\udf7a", "\ud83c\udf3f", "❄", "⚔" }; private readonly ISignMenuHost _host; private readonly HashSet<int> _selected = new HashSet<int>(); public readonly VisualElement Window; private readonly VisualElement _content; private VisualElement _letters; private Label _status; private string _name; private string _letterColour = "#FF0000"; private SignStyle _style; public string Name => _name; public SignStyle Style => _style; public SignMenuView(ISignMenuHost host, string name, SignStyle style) { _host = host; _name = name ?? ""; _style = ((style != null) ? style.Clone() : new SignStyle()); UiScroll val = default(UiScroll); Window = UiKit.Window(_host.T("dtp_ui_sign_title"), _host.T("dtp_ui_esc_close"), (Action)delegate { _host.Close("X"); }, ref val); _content = val.Content; Build(); UiLog.Verbose("SignMenuView: built for '" + _name + "' (" + _host.Fonts.Count + " font(s), style " + _style?.ToString() + ")"); } private void Changed(string what) { _style.Clamp(); _host.Preview(_name, _style); UiLog.Verbose("SignMenuView: " + what + " -> '" + _name + "' " + _style); } private void Status(string text) { if (_status != null) { ((TextElement)_status).text = text; } UiLog.Verbose("SignMenuView: " + text); } private void Build() { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown //IL_006c: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0526: Unknown result type (might be due to invalid IL or missing references) //IL_0530: Expected O, but got Unknown //IL_053c: Unknown result type (might be due to invalid IL or missing references) //IL_0552: Unknown result type (might be due to invalid IL or missing references) //IL_056c: Unknown result type (might be due to invalid IL or missing references) //IL_0806: Unknown result type (might be due to invalid IL or missing references) //IL_081c: Unknown result type (might be due to invalid IL or missing references) _content.Clear(); _content.Add(UiControls.Heading(_host.T("dtp_ui_name"))); _content.Add((VisualElement)(object)UiControls.TextField(_name, _host.MaxLetters * 2, (Action<string>)delegate(string v) { _name = v; RebuildLetters(); Changed("name"); })); VisualElement val = new VisualElement(); val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2); val.style.flexWrap = StyleEnum<Wrap>.op_Implicit((Wrap)1); val.style.flexShrink = StyleFloat.op_Implicit(0f); string[] emoji = Emoji; foreach (string text in emoji) { string em = text; val.Add((VisualElement)(object)UiControls.Button(em, (Action)delegate { AddEmoji(em); }, false)); } _content.Add(UiControls.Row(_host.T("dtp_ui_emoji"), val)); _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_emoji_note"))); _content.Add(UiControls.Heading(_host.T("dtp_ui_text"))); List<string> list = new List<string> { "" }; list.AddRange(_host.Fonts); _content.Add(UiControls.Row(_host.T("dtp_ui_font"), (VisualElement)(object)UiControls.Dropdown((IList<string>)list, _style.Font, (Func<string, string>)((string f) => (f.Length != 0) ? f : _host.T("dtp_ui_font_default")), (Action<string>)delegate(string f) { _style.Font = f; Changed("font"); }))); _content.Add(UiControls.Row(_host.T("dtp_ui_size"), UiControls.Line((VisualElement[])(object)new VisualElement[2] { UiControls.Toggle(_host.T("dtp_ui_auto"), _style.Size <= 0f, (Action<bool>)delegate(bool on) { _style.Size = (on ? 0f : 4f); Changed("auto size " + on); }), Grow(UiControls.Slider(0.5f, 12f, (_style.Size <= 0f) ? 4f : _style.Size, "0.0", (Action<float>)delegate(float v) { _style.Size = v; Changed("size"); })) }))); _content.Add(UiControls.Row(_host.T("dtp_ui_style"), UiControls.Line((VisualElement[])(object)new VisualElement[5] { UiControls.Toggle(_host.T("dtp_ui_bold"), _style.Bold, (Action<bool>)delegate(bool on) { _style.Bold = on; Changed("bold"); }), UiControls.Toggle(_host.T("dtp_ui_italic"), _style.Italic, (Action<bool>)delegate(bool on) { _style.Italic = on; Changed("italic"); }), UiControls.Toggle(_host.T("dtp_ui_underline"), _style.Underline, (Action<bool>)delegate(bool on) { _style.Underline = on; Changed("underline"); }), UiControls.Toggle(_host.T("dtp_ui_strike"), _style.Strike, (Action<bool>)delegate(bool on) { _style.Strike = on; Changed("strike"); }), UiControls.Toggle(_host.T("dtp_ui_upper"), _style.Upper, (Action<bool>)delegate(bool on) { _style.Upper = on; Changed("upper case"); }) }))); List<string> list2 = new List<string> { "l", "c", "r" }; _content.Add(UiControls.Row(_host.T("dtp_ui_align"), (VisualElement)(object)UiControls.Dropdown((IList<string>)list2, _style.Align.ToString(), (Func<string, string>)AlignName, (Action<string>)delegate(string a) { _style.Align = a[0]; Changed("align"); }))); _content.Add(UiControls.Row(_host.T("dtp_ui_spacing"), UiControls.Slider(-20f, 50f, _style.Spacing, "0", (Action<float>)delegate(float v) { _style.Spacing = v; Changed("spacing"); }))); _content.Add(UiControls.Heading(_host.T("dtp_ui_colour"))); Action<string> action = default(Action<string>); _content.Add(UiControls.ColorPicker(_style.Color, (Action<string>)BaseColour, ref action)); _content.Add(UiControls.Heading(_host.T("dtp_ui_letters"))); _content.Add((VisualElement)(object)UiControls.Note(_host.T("dtp_ui_letters_note"))); _letters = new VisualElement(); _letters.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2); _letters.style.flexWrap = StyleEnum<Wrap>.op_Implicit((Wrap)1); _letters.style.flexShrink = StyleFloat.op_Implicit(0f); _content.Add(_letters); RebuildLetters(); _content.Add(UiControls.Line((VisualElement[])(object)new VisualElement[6] { (VisualElement)UiControls.Button(_host.T("dtp_ui_all"), (Action)SelectAll, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_none"), (Action)delegate { _selected.Clear(); RebuildLetters(); }, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_paint"), (Action)Paint, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_rainbow"), (Action)Rainbow, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_gradient"), (Action)Gradient, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_clear"), (Action)ClearLetters, false) })); Action<string> action2 = default(Action<string>); _content.Add(UiControls.ColorPicker(_letterColour, (Action<string>)LetterColour, ref action2)); _content.Add(UiControls.Heading(_host.T("dtp_ui_pref"))); _content.Add(UiControls.Line((VisualElement[])(object)new VisualElement[3] { (VisualElement)UiControls.Button(_host.T("dtp_ui_pref_save"), (Action)delegate { int num2 = _host.SavePreferred(_style); Status(_host.T((num2 > 0) ? "dtp_ui_pref_saved" : "dtp_ui_pref_failed")); }, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_pref_use"), (Action)UsePreferred, false), (VisualElement)UiControls.Button(_host.T("dtp_ui_reset"), (Action)ResetStyle, false) })); _status = UiControls.Note(""); _content.Add((VisualElement)(object)_status); VisualElement val2 = UiControls.Line((VisualElement[])(object)new VisualElement[2] { (VisualElement)UiControls.Button(_host.T("dtp_ui_save"), (Action)delegate { _host.Save(_name, _style); }, true), (VisualElement)UiControls.Button(_host.T("dtp_ui_cancel"), (Action)delegate { _host.Close("Cancel"); }, false) }); val2.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)2); val2.style.marginTop = StyleLength.op_Implicit(12f); _content.Add(val2); } private static VisualElement Grow(VisualElement e) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) e.style.flexGrow = StyleFloat.op_Implicit(1f); e.style.minWidth = StyleLength.op_Implicit(200f); return e; } private string AlignName(string a) { return _host.T((a == "l") ? "dtp_ui_left" : ((a == "r") ? "dtp_ui_right" : "dtp_ui_center")); } private void RebuildLetters() { //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00b3: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0196: 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) if (_letters == null) { return; } _letters.Clear(); List<string> letters = SignStyle.SplitLetters(_name); _selected.RemoveWhere((int i) => i >= letters.Count); Color val = default(Color); for (int num = 0; num < letters.Count; num++) { int idx = num; if (!_style.Letters.TryGetValue(num, out var value)) { value = _style.Color; } ColorUtility.TryParseHtmlString(value, ref val); Label val2 = new Label(letters[num]); ((VisualElement)val2).style.minWidth = StyleLength.op_Implicit(36f); ((VisualElement)val2).style.height = StyleLength.op_Implicit(40f); ((VisualElement)val2).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4); ((VisualElement)val2).style.fontSize = StyleLength.op_Implicit(24f); ((VisualElement)val2).style.color = StyleColor.op_Implicit(val); ((VisualElement)val2).style.marginRight = StyleLength.op_Implicit(4f); ((VisualElement)val2).style.marginTop = StyleLength.op_Implicit(4f); ((VisualElement)val2).style.flexShrink = StyleFloat.op_Implicit(0f); bool flag = _selected.Contains(num); ((VisualElement)val2).style.backgroundColor = StyleColor.op_Implicit(UiKit.Track); UiKit.Radius((VisualElement)(object)val2, 4f); UiKit.Borders((VisualElement)(object)val2, (float)((!flag) ? 1 : 2), flag ? UiKit.Gold : UiKit.Border); ((CallbackEventHandler)val2).RegisterCallback<PointerDownEvent>((EventCallback<PointerDownEvent>)delegate { if (!_selected.Remove(idx)) { _selected.Add(idx); } UiLog.Verbose("SignMenuView: letter " + idx + " " + (_selected.Contains(idx) ? "selected" : "unselected")); RebuildLetters(); }, (TrickleDown)0); _letters.Add((VisualElement)(object)val2); } } private void SelectAll() { _selected.Clear(); int count = SignStyle.SplitLetters(_name).Count; for (int i = 0; i < count; i++) { _selected.Add(i); } RebuildLetters(); } private List<int> Sel() { List<int> list = new List<int>(_selected); list.Sort(); return list; } private void BaseColour(string h) { _style.Color = h; int count = SignStyle.SplitLetters(_name).Count; int num = 0; for (int i = 0; i < count; i++) { if (_style.Letters.ContainsKey(i)) { num++; } } if (count > 0 && num == count) { _style.Letters.Clear(); Status(_host.T("dtp_ui_letters_reset")); UiLog.Verbose("SignMenuView: all " + count + " letters had their own colour, cleared for the text colour " + h); } RebuildLetters(); Changed("colour " + h); } private void LetterColour(string h) { _letterColour = h; List<int> list = Sel(); if (list.Count == 0) { UiLog.Verbose("SignMenuView: letter colour " + h + " picked, no letter selected (Paint / Gradient use it)"); return; } foreach (int item in list) { _style.Letters[item] = h; } RebuildLetters(); Changed("letter colour " + h + " on " + list.Count + " selected letter(s)"); } private void Paint() { List<int> list = Sel(); if (list.Count == 0) { Status(_host.T("dtp_ui_select_first")); return; } foreach (int item in list) { _style.Letters[item] = _letterColour; } RebuildLetters(); Changed("painted " + list.Count + " letter(s) " + _letterColour); } private void Rainbow() { //IL_006a: Unknown result type (might be due to invalid IL or missing references) List<int> list = Sel(); if (list.Count == 0) { Status(_host.T("dtp_ui_select_first")); return; } for (int i = 0; i < list.Count; i++) { _style.Letters[list[i]] = "#" + ColorUtility.ToHtmlStringRGB(Color.HSVToRGB((list.Count == 1) ? 0f : ((float)i / (float)list.Count), 0.85f, 1f)); } RebuildLetters(); Changed("rainbow over " + list.Count + " letter(s)"); } private void Gradient() { List<int> list = Sel(); if (list.Count == 0) { Status(_host.T("dtp_ui_select_first")); return; } int num = _style.Gradient(list[0], list[list.Count - 1], _style.Color, _letterColour); RebuildLetters(); Changed("gradient over " + num + " letter(s) " + _style.Color + " -> " + _letterColour); } private void ClearLetters() { List<int> list = Sel(); if (list.Count == 0) { int count = _style.Letters.Count; _style.Letters.Clear(); RebuildLetters(); Changed("cleared all " + count + " letter colour(s)"); return; } foreach (int item in list) { _style.Letters.Remove(item); } RebuildLetters(); Changed("cleared " + list.Count + " letter colour(s)"); } private void AddEmoji(string em) { if (SignStyle.SplitLetters(_name).Count >= _host.MaxLetters) { Status(_host.T("dtp_ui_name_full")); return; } _name += em; Build(); Changed("emoji added"); } private void UsePreferred() { SignStyle signStyle = _host.LoadPreferred(); if (signStyle == null) { Status(_host.T("dtp_ui_pref_none")); return; } _style = signStyle; Build(); Changed("preferred style used"); Status(_host.T("dtp_ui_pref_used")); } private void ResetStyle() { _style = new SignStyle(); Build(); Changed("reset to the default style"); Status(_host.T("dtp_ui_reset_done")); } } } namespace WaterAndTarPools.Signs { internal static class PoolFinder { internal const float Reach = 5f; private const float Step = 0.5f; private const int Dirs = 16; private const float Wet = 0.02f; internal static bool Accepts(LiquidVolume v) { if ((Object)(object)v != (Object)null) { if (!TarPits.IsTar(v)) { return TarPits.IsPumpPool(v); } return true; } return false; } internal static LiquidVolume Find(Vector3 p, float reach, out float dist) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) dist = -1f; LiquidVolume val = null; float num = float.MaxValue; float num2 = 0f; foreach (LiquidVolume item in TarPits.All) { if (Accepts(item)) { float depth; float num3 = Distance(item, p, reach, out depth); if (!(num3 < 0f) && (num3 < num - 0.01f || (Mathf.Abs(num3 - num) <= 0.01f && depth > num2))) { val = item; num = num3; num2 = depth; } } } if ((Object)(object)val != (Object)null) { dist = num; } ModLog.Verbose("PoolFinder: at " + ((Vector3)(ref p)).ToString("0.0") + (((Object)(object)val != (Object)null) ? (" pool " + ((Object)val).name + " (" + LiquidName(val) + ") " + ((num <= 0f) ? "under it" : (num.ToString("0.0") + " m away"))) : (" no pool within " + reach + " m"))); return val; } private static float Distance(LiquidVolume v, Vector3 p, float reach, out float depth) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) depth = 0f; Vector2 val = TarPits.ToGrid(v, p); float num = reach / Mathf.Max(0.01f, v.m_scale); if (val.x < 0f - num || val.y < 0f - num || val.x > (float)v.m_width + num || val.y > (float)v.m_width + num) { return -1f; } Held val2 = TarPits.Hold(v); try { List<float> list = TarPits.Depths(v); if (list == null || list.Count < (v.m_width + 1) * (v.m_width + 1)) { return -1f; } depth = DepthAt(v, list, p); if (depth > 0.02f) { return 0f; } for (float num2 = 0.5f; num2 <= reach + 0.001f; num2 += 0.5f) { for (int i = 0; i < 16; i++) { float num3 = (float)i * (float)Math.PI * 2f / 16f; float num4 = DepthAt(v, list, p + new Vector3(Mathf.Cos(num3) * num2, 0f, Mathf.Sin(num3) * num2)); if (num4 > 0.02f) { depth = num4; return num2; } } } } finally { ((IDisposable)val2)?.Dispose(); } return -1f; } private static float DepthAt(LiquidVolume v, List<float> d, Vector3 w) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Vector2 val = TarPits.ToGrid(v, w); if (!TarPits.InGrid(v, val)) { return 0f; } return TarPits.DepthAt(v, d, val.x, val.y); } internal static string LiquidName(LiquidVolume v) { if (!((Object)(object)v == (Object)null)) { if (!TarPits.IsTar(v)) { return "water"; } return "tar"; } return ""; } } internal sealed class PoolMenu : IPoolMenuHost { private const string LockName = "PoolMenu"; private static PoolMenu _open; private PoolMenuView _view; private int _shownVersion = -1; private readonly List<PoolMenuEntry> _pools = new List<PoolMenuEntry>(); internal static bool IsOpen => _open != null; public string MenuKey { get { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (PoolSettings.PoolMenuKey == null) { return "F9"; } return ((object)PoolSettings.PoolMenuKey.Value/*cast due to .constrained prefix*/).ToString(); } } public bool IsAdmin { get { if ((Object)(object)ZNet.instance != (Object)null) { return ZNet.instance.LocalPlayerIsAdminOrHost(); } return false; } } public string WorldStyle { get { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) WaterStyleOption? val = PoolStyles.World(); if (!val.HasValue) { return ""; } return ((object)val.Value/*cast due to .constrained prefix*/).ToString(); } } public string DefaultStyle => ((object)PoolStyles.Default/*cast due to .constrained prefix*/).ToString(); public IList<string> Styles => Enum.GetNames(typeof(WaterStyleOption)); public IList<PoolMenuEntry> Pools => _pools; public bool Waiting { get { if (PoolRegistry.Version == 0) { return Time.unscaledTime - PoolRegistry.RequestedAt < 10f; } return false; } } internal static int Shut(string why) { if (_open == null) { return 0; } _open.Close(why); return 1; } internal static void Tick() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) KeyCode val = (KeyCode)((PoolSettings.PoolMenuKey != null) ? ((int)PoolSettings.PoolMenuKey.Value) : 0); if (_open == null) { if ((int)val != 0 && ZInput.GetKeyDown(val, true) && !((Object)(object)Player.m_localPlayer == (Object)null) && (!((Object)(object)Chat.instance != (Object)null) || !Chat.instance.HasFocus()) && !Console.IsVisible() && !Menu.IsVisible() && !InventoryGui.IsVisible()) { Open(); } } else if (ZInput.GetKeyDown(val, true) || ZInput.GetKeyDown((KeyCode)27, true) || (Object)(object)Player.m_localPlayer == (Object)null) { _open.Close(((Object)(object)Player.m_localPlayer == (Object)null) ? "no player" : "key"); } else if (PoolRegistry.Version != _open._shownVersion) { _open.Redraw(); } } private static void Open() { VisualElement root = UiKit.Root; if (root == null) { ModLog.Warn("PoolMenu: UI Toolkit is not available, the pool menu cannot open"); return; } PoolMenu poolMenu = new PoolMenu(); int num = PoolRegistry.Request(); poolMenu.Fill(); poolMenu._view = new PoolMenuView(poolMenu); root.Add(poolMenu._view.Window); _open = poolMenu; UiInputLock.Hold("PoolMenu"); ModLog.Verbose("PoolMenu: opened (list request sent: " + num + ", world style '" + poolMenu.WorldStyle + "', admin " + poolMenu.IsAdmin + ")"); } private void Fill() { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) _pools.Clear(); foreach (PoolRegistry.Entry item in PoolRegistry.Received) { WaterStyleOption? val = PoolStyles.MineFor(item.Id); _pools.Add(new PoolMenuEntry { Id = item.Id, Name = item.Name, Style = item.Style, Pos = item.Pos, Portal = item.Portal, PortalDistance = item.PortalDistance, Tar = (item.Liquid == "tar"), MyStyle = (val.HasValue ? ((object)val.Value/*cast due to .constrained prefix*/).ToString() : "") }); } _shownVersion = PoolRegistry.Version; } private void Redraw() { Fill(); if (_view != null) { _view.Rebuild(); } ModLog.Verbose("PoolMenu: redrawn with " + _pools.Count + " pool(s)"); } public string T(string key, params string[] args) { return Loc.T(key, args); } public void SetWorldStyle(string style) { int num = PoolRegistry.SetWorldStyle(style); ModLog.Verbose("PoolMenu: world style '" + style + "' asked for (sent " + num + ")"); Plugin.Instance.RunCoroutine(RedrawSoon()); } private IEnumerator RedrawSoon() { yield return (object)new WaitForSecondsRealtime(0.6f); if (_open == this && _view != null) { _view.Rebuild(); ModLog.Verbose("PoolMenu: redrawn after the world style change (now '" + WorldStyle + "')"); } } public void SetPoolStyle(string id, string style) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) WaterStyleOption result; WaterStyleOption? style2 = ((style.Length > 0 && Enum.TryParse<WaterStyleOption>(style, ignoreCase: true, out result)) ? new WaterStyleOption?(result) : ((WaterStyleOption?)null)); int num = PoolStyles.SetMine(id, style2); foreach (PoolMenuEntry pool in _pools) { if (pool.Id == id) { pool.MyStyle = (style2.HasValue ? ((object)style2.Value/*cast due to .constrained prefix*/).ToString() : ""); } } ModLog.Verbose("PoolMenu: my style for pool " + id + " -> '" + style + "' (" + num + " personal choice(s) in this world)"); } public void Refresh() { ModLog.Verbose("PoolMenu: refresh asked (" + PoolRegistry.Request() + ")"); } public void Close(string why) { if (_view != null) { _view.Window.RemoveFromHierarchy(); } _view = null; if (_open == this) { _open = null; } UiInputLock.Release("PoolMenu"); ModLog.Verbose("PoolMenu: closed (" + why + ")"); } } internal static class PoolRegistry { internal sealed class Entry { public string Id = ""; public string Name = ""; public string Style = ""; public string Portal = ""; public string Liquid = ""; public Vector3 Pos; public float PortalDistance = -1f; } internal const string RpcListReq = "DTP_PoolListReq"; internal const string RpcList = "DTP_PoolList"; internal const string RpcSetWorldStyle = "DTP_SetWorldStyle"; internal const string WorldKey = "dtp_waterstyle"; private const float CacheSeconds = 5f; private static ZRoutedRpc _registeredOn; private static readonly List<Entry> Cache = new List<Entry>(); private static float _cacheAt = -100f; private static List<string> _portalPrefabs; internal static readonly List<Entry> Received = new List<Entry>(); internal static int Version; internal static float RequestedAt = -100f; private static readonly MethodInfo MListContains = AccessTools.Method(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); private static readonly FieldInfo FAdminList = AccessTools.Field(typeof(ZNet), "m_adminList"); internal static void Tick() { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null && instance != _registeredOn) { _registeredOn = instance; instance.Register<ZPackage>("DTP_PoolListReq", (Action<long, ZPackage>)OnList