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 Sundial v1.0.0
plugins/Sundial.dll
Decompiled 5 days ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Sundial.Audio; using Sundial.Core; using Sundial.Dev; using Sundial.Gameplay; using Sundial.Visual; using UnityEngine; using UnityEngine.Audio; using UnityEngine.Rendering; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Sundial { public static class Cfg { public static ConfigEntry<string> Recipe; public static ConfigEntry<string> Station; public static ConfigEntry<bool> AutoAlign; public static ConfigEntry<bool> AllowTurning; public static ConfigEntry<float> MarkTolerance; public static ConfigEntry<string> CircleRecipe; public static ConfigEntry<string> CircleStation; public static ConfigEntry<bool> LevelGround; public static ConfigEntry<string> MarbleRecipe; public static ConfigEntry<string> MarbleCircleRecipe; public static ConfigEntry<string> MarbleStation; public static ConfigEntry<string> GraustenRecipe; public static ConfigEntry<string> GraustenCircleRecipe; public static ConfigEntry<string> GraustenStation; public static ConfigEntry<string> RingRecipe; public static ConfigEntry<string> RingStation; public static ConfigEntry<bool> ShowExactTime; public static ConfigEntry<bool> ShowEykt; public static ConfigEntry<bool> SpeakReading; public static void Bind(ConfigFile c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Expected O, but got Unknown //IL_017c: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Expected O, but got Unknown //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Expected O, but got Unknown //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Expected O, but got Unknown //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Expected O, but got Unknown //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_0271: Expected O, but got Unknown //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Expected O, but got Unknown //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Expected O, but got Unknown //IL_02f0: Unknown result type (might be due to invalid IL or missing references) //IL_02fa: Expected O, but got Unknown ConfigurationManagerAttributes val = new ConfigurationManagerAttributes { IsAdminOnly = true }; Recipe = c.Bind<string>("1 - Building", "Recipe", "Stone:12,Bronze:2", new ConfigDescription("Build cost of the sundial, \"Item:amount,Item:amount\" (item prefab names).", (AcceptableValueBase)null, new object[1] { val })); Station = c.Bind<string>("1 - Building", "Station", "piece_workbench", new ConfigDescription("Crafting station that has to be near (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { val })); AutoAlign = c.Bind<bool>("1 - Building", "AutoAlign", false, new ConfigDescription("A new sundial or sun circle points its XII to true north by itself. Off: like a real one, it has to be aligned once (mark the shadow tip before and after noon).", (AcceptableValueBase)null, new object[1] { val })); AllowTurning = c.Bind<bool>("1 - Building", "AllowTurning", true, new ConfigDescription("The quick way: players can turn a sundial or sun circle by hand (Shift + mouse wheel while looking at it) and align it by eye. It reads only as true as they aimed.", (AcceptableValueBase)null, new object[1] { val })); MarkTolerance = c.Bind<float>("1 - Building", "MarkTolerance", 0.06f, new ConfigDescription("How exactly the second shadow mark has to match the first one's length (fraction). Lower is stricter and more exact.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.25f), new object[1] { val })); CircleRecipe = c.Bind<string>("1 - Building", "CircleRecipe", "Stone:80,Bronze:4", new ConfigDescription("Build cost of the sun circle, \"Item:amount,Item:amount\" (item prefab names).", (AcceptableValueBase)null, new object[1] { val })); CircleStation = c.Bind<string>("1 - Building", "CircleStation", "piece_workbench", new ConfigDescription("Crafting station that has to be near the sun circle (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { val })); MarbleRecipe = c.Bind<string>("1 - Building", "MarbleRecipe", "BlackMarble:12,Bronze:2", new ConfigDescription("Build cost of the black marble sundial.", (AcceptableValueBase)null, new object[1] { val })); MarbleCircleRecipe = c.Bind<string>("1 - Building", "MarbleCircleRecipe", "BlackMarble:80,Bronze:4", new ConfigDescription("Build cost of the black marble sun circle.", (AcceptableValueBase)null, new object[1] { val })); MarbleStation = c.Bind<string>("1 - Building", "MarbleStation", "piece_stonecutter", new ConfigDescription("Crafting station near which the black marble ones are built (like the game's own marble pieces).", (AcceptableValueBase)null, new object[1] { val })); GraustenRecipe = c.Bind<string>("1 - Building", "GraustenRecipe", "Grausten:12,Bronze:2", new ConfigDescription("Build cost of the grausten sundial.", (AcceptableValueBase)null, new object[1] { val })); GraustenCircleRecipe = c.Bind<string>("1 - Building", "GraustenCircleRecipe", "Grausten:80,Bronze:4", new ConfigDescription("Build cost of the grausten sun circle.", (AcceptableValueBase)null, new object[1] { val })); GraustenStation = c.Bind<string>("1 - Building", "GraustenStation", "piece_stonecutter", new ConfigDescription("Crafting station near which the grausten ones are built.", (AcceptableValueBase)null, new object[1] { val })); RingRecipe = c.Bind<string>("1 - Building", "RingRecipe", "Bronze:1", new ConfigDescription("Cost of the ring dial (Bauernring), \"Item:amount,Item:amount\".", (AcceptableValueBase)null, new object[1] { val })); RingStation = c.Bind<string>("1 - Building", "RingStation", "forge", new ConfigDescription("Crafting station of the ring dial (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { val })); LevelGround = c.Bind<bool>("1 - Building", "LevelGround", true, new ConfigDescription("Building a sun circle levels the ground beneath it and clears the grass, like a hoe would (this stays when the circle is removed).", (AcceptableValueBase)null, new object[1] { val })); ShowExactTime = c.Bind<bool>("2 - Client", "ShowExactTime", false, "Also show the reading as hh:mm (what the shadow says, not the game's clock)."); ShowEykt = c.Bind<bool>("2 - Client", "ShowEykt", true, "Name the Old Norse day mark (eykt) near a reading: Dagmál, Hádegi, Nón, …"); SpeakReading = c.Bind<bool>("2 - Client", "SpeakReading", true, "Your Viking says the time out loud (speech bubble) when you read the dial closely."); } } public static class Lang { private static readonly (string key, string en, string de)[] Texts = new(string, string, string)[65] { ("piece_sundial", "Sundial", "Sonnenuhr"), ("piece_sundial_desc", "A stone pedestal with an engraved bronze dial. The gnomon's edge is set for the sky it is built under. Align it to north and the shadow tells the hour; by moonlight it is twelve hours off.", "Ein Steinsockel mit gravierter Bronzescheibe. Die Kante des Schattenstabs ist auf den Himmel eingestellt, unter dem die Uhr gebaut wird. Nach Norden ausgerichtet zeigt der Schatten die Stunde; im Mondlicht geht sie zwölf Stunden versetzt."), ("piece_sundial_blackmarble", "Sundial (black marble)", "Sonnenuhr (schwarzer Marmor)"), ("piece_sundial_grausten", "Sundial (grausten)", "Sonnenuhr (Grausten)"), ("piece_suncircle", "Sun circle", "Sonnenkreis"), ("piece_suncircle_blackmarble", "Sun circle (black marble)", "Sonnenkreis (schwarzer Marmor)"), ("piece_suncircle_grausten", "Sun circle (grausten)", "Sonnenkreis (Grausten)"), ("piece_suncircle_desc", "A paved stone circle round a standing stone with a bronze ball on top: a great sundial for the heart of a hall. Lay it out, find north with two equal shadows, and the hour stones are raised where the shadow points at each hour.", "Ein gepflasterter Steinkreis um einen Menhir mit Bronzekugel: eine große Sonnenuhr für die Mitte deines Hofs. Anlegen, mit zwei gleich langen Schatten Norden finden, dann werden die Stundensteine dort aufgerichtet, wohin der Schatten zu jeder Stunde zeigt."), ("suncircle_find_north", "The hour stones lie ready. First find north: mark the tip of the stone's shadow in the morning ($KEY_AltPlace + $KEY_Use), then again when it touches the chalk circle in the afternoon.", "Die Stundensteine liegen bereit. Finde zuerst Norden: markiere vormittags die Spitze des Schattens ($KEY_AltPlace + $KEY_Use) und noch einmal, wenn sie nachmittags den Kreidekreis berührt."), ("suncircle_find_north_eye", "Or quickly, by eye: the chalk line shows where XII will stand – turn it north with $KEY_AltPlace + mouse wheel (north is up on the map).", "Oder schnell nach Augenmaß: die Kreidelinie zeigt, wo XII stehen wird – dreh sie mit $KEY_AltPlace + Mausrad nach Norden (auf der Karte ist Norden oben)."), ("sundial_msg_turning", "The plate is still turning – mark when it stands still.", "Die Scheibe dreht sich noch – markiere, wenn sie stillsteht."), ("suncircle_raising", "The hour stones are being raised …", "Die Stundensteine werden aufgerichtet …"), ("suncircle_msg_nostones", "No hour stones stand yet – find north first.", "Noch stehen keine Stundensteine – finde zuerst Norden."), ("suncircle_msg_offpaving", "The shadow tip falls beyond the paving – mark it nearer to noon.", "Die Schattenspitze fällt über das Pflaster hinaus – markiere näher am Mittag."), ("suncircle_msg_aligned", "Halfway between the marks lies north – the hour stones are raised by it ({0}).", "Genau zwischen den Marken liegt Norden – danach werden die Stundensteine aufgerichtet ({0})."), ("item_sundial_ring", "Ring dial", "Bauernring"), ("item_sundial_ring_desc", "A bronze ring on a cord, as farmers carried them. Hold it up against the sun: through a small hole a spot of light falls on the hours engraved inside. It needs no north, wherever you are. But one mark serves morning and afternoon alike, and around noon, when the sun hardly climbs, it is vague. Engraved for the sky of most lands (45° north).", "Ein Bronzering an einer Schnur, wie ihn die Bauern trugen. Halte ihn gegen die Sonne: durch ein kleines Loch fällt ein Lichtpunkt auf die Stunden, die innen eingraviert sind. Norden braucht er nicht, wo du auch bist. Doch dieselbe Marke gilt für Vormittag und Nachmittag, und um Mittag, wenn die Sonne kaum noch steigt, ist er ungenau. Graviert für den Himmel der meisten Länder (45° Nord)."), ("ring_swinging", "The ring swings on its cord …", "Der Ring pendelt an seiner Schnur aus …"), ("ring_spot_at", "The spot of light stands at {0}", "Der Lichtpunkt steht bei {0}"), ("ring_spot_between", "The spot of light stands between {0} and {1}", "Der Lichtpunkt steht zwischen {0} und {1}"), ("ring_beyond", "The spot of light stands beyond XII", "Der Lichtpunkt steht jenseits von XII"), ("ring_noon", "around noon – near noon the ring tells no more", "um die Mittagszeit – genauer sagt es der Ring um Mittag nicht"), ("ring_sun_east", "the sun is in the east", "die Sonne steht im Osten"), ("ring_sun_west", "the sun is in the west", "die Sonne steht im Westen"), ("ring_nolight_cloud", "The sun is hidden – no light falls through the hole.", "Die Sonne ist verdeckt – kein Licht fällt durch das Loch."), ("ring_nolight_low", "The sun is too low for the ring.", "Die Sonne steht zu tief für den Ring."), ("ring_nolight_dark", "Too dark – the moon's light is too weak for the ring.", "Zu dunkel – für den Ring ist das Mondlicht zu schwach."), ("ring_nolight_dim", "Too dark here – no sunbeam reaches the ring.", "Hier ist es zu dunkel – kein Sonnenstrahl erreicht den Ring."), ("ring_nolight_shade", "No sunlight here – step out into the sun.", "Hier fällt kein Sonnenlicht hin – geh hinaus in die Sonne."), ("ring_wrong_sky", "Engraved for {0}° north – under this sky it reads wrong.", "Für {0}° Nord graviert – unter diesem Himmel geht er falsch."), ("ring_put_away", "use it again to put it away", "erneut benutzen zum Wegstecken"), ("sundial_shadow", "Shadow on {0}", "Schatten auf {0}"), ("sundial_moonshadow", "Moon shadow on {0}", "Mondschatten auf {0}"), ("sundial_moonnote", "by the moon, twelve hours on", "beim Mond zwölf Stunden weiter"), ("sundial_noshadow_cloud", "No shadow – the sun is hidden.", "Kein Schatten – die Sonne ist verdeckt."), ("sundial_noshadow_low", "The sun is too low to cast a shadow.", "Die Sonne steht zu tief für einen Schatten."), ("sundial_noshadow_dark", "No shadow – it is too dark.", "Kein Schatten – es ist zu dunkel."), ("sundial_shaded", "The dial lies in the shade.", "Die Uhr liegt im Schatten."), ("sundial_built_for", "made for {0}° north", "gebaut für {0}° Nord"), ("sundial_aligned", "aligned to north", "eingenordet"), ("sundial_by_eye", "aligned by eye", "nach Augenmaß ausgerichtet"), ("sundial_wheel", "Mouse wheel", "Mausrad"), ("sundial_turn", "Turn by eye", "Nach Augenmaß drehen"), ("sundial_read", "Read closely", "Genau ablesen"), ("sundial_mark", "Mark the shadow tip", "Schattenspitze markieren"), ("sundial_mark2", "Set the second mark", "Zweite Marke setzen"), ("sundial_wipe", "hold: wipe the chalk", "halten: Kreide wegwischen"), ("sundial_wait_circle", "Mark again when the shadow tip touches the chalk circle after noon.", "Berührt die Schattenspitze nach Mittag den Kreidekreis, markiere erneut."), ("sundial_tip_near", "The shadow tip touches the chalk circle.", "Die Schattenspitze berührt den Kreidekreis."), ("sundial_tip_spot", "The shadow tip lies right on the chalk circle – mark it now!", "Die Schattenspitze liegt genau auf dem Kreidekreis – jetzt markieren!"), ("sundial_tip_coming", "The shadow tip is nearing the chalk circle.", "Die Schattenspitze nähert sich dem Kreidekreis."), ("sundial_msg_chime", "{0}: the shadow tip is reaching the chalk circle.", "{0}: Die Schattenspitze erreicht den Kreidekreis."), ("sundial_prec_exact", "spot on", "aufs Haar genau"), ("sundial_prec_fine", "very precisely", "sehr genau"), ("sundial_prec_good", "fairly well", "recht genau"), ("sundial_prec_rough", "only roughly – measure again for a finer setting", "nur grob – miss noch einmal für mehr Genauigkeit"), ("sundial_msg_mark1", "Chalk mark set. Mark the tip again when its shadow touches the circle after noon.", "Kreidemarke gesetzt. Markiere die Spitze erneut, wenn ihr Schatten nach Mittag den Kreis berührt."), ("sundial_msg_notequal", "The shadow is not as long as the first one yet – its tip has to touch the chalk circle.", "Der Schatten ist noch nicht so lang wie der erste – seine Spitze muss den Kreidekreis berühren."), ("sundial_msg_tooclose", "Too soon – wait until the shadow has swung past noon.", "Zu früh – warte, bis der Schatten über Mittag gewandert ist."), ("sundial_msg_aligned", "Halfway between the marks lies north – you turn the dial plate to it ({0}).", "Genau zwischen den Marken liegt Norden – du drehst die Scheibe danach ({0})."), ("sundial_msg_toolong", "The shadow is already longer than the first – its tip has passed the chalk circle. It comes round again tomorrow at this time.", "Der Schatten ist schon länger als der erste – seine Spitze ist über den Kreidekreis hinaus. Morgen um diese Zeit kommt sie wieder."), ("sundial_msg_wiped", "You wipe the chalk off.", "Du wischst die Kreide weg."), ("sundial_msg_noshadow", "There is no shadow to mark.", "Es gibt keinen Schatten zum Markieren."), ("sundial_msg_offplate", "The shadow tip falls beside the plate – mark it nearer to noon.", "Die Schattenspitze fällt neben die Scheibe – markiere näher am Mittag."), ("sundial_say", "It is {0}.", "Es ist {0}.") }; public static Language Current { get { if (Localization.instance == null || !(Localization.instance.GetSelectedLanguage() == "German")) { return Language.English; } return Language.German; } } public static void Register() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); Dictionary<string, string> dictionary = new Dictionary<string, string>(); Dictionary<string, string> dictionary2 = new Dictionary<string, string>(); (string, string, string)[] texts = Texts; for (int i = 0; i < texts.Length; i++) { (string, string, string) tuple = texts[i]; string item = tuple.Item1; string item2 = tuple.Item2; string item3 = tuple.Item3; dictionary[item] = item2; dictionary2[item] = item3; } string text = "English"; localization.AddTranslation(ref text, dictionary); text = "German"; localization.AddTranslation(ref text, dictionary2); } public static string T(string token, params object[] args) { string text = ((Localization.instance != null) ? Localization.instance.Localize("$" + token) : token); if (args == null || args.Length == 0) { return text; } try { return string.Format(text, args); } catch (FormatException) { return text; } } } public static class Pieces { [HarmonyPatch(typeof(Game), "Start")] private static class ApplyOnWorldStart { private static void Postfix() { ApplyConfig(); RingDial.ApplyConfig(); } } [HarmonyPatch(typeof(ObjectDB), "UpdateRegisters")] private static class RegisterLevelOp { private static void Postfix(ObjectDB __instance) { if (_levelOps != null && !((Object)(object)_smoothOp == (Object)null) && !((Object)(object)__instance == (Object)null)) { TerrainOp[] levelOps = _levelOps; foreach (TerrainOp val in levelOps) { __instance.m_terrainOpsByHash[StringExtensionMethods.GetStableHashCode(((Object)((Component)val).gameObject).name)] = val; } __instance.m_terrainOpsByHash[StringExtensionMethods.GetStableHashCode("sundial_smooth_ground")] = _smoothOp; } } } public const string SundialPrefab = "piece_sundial"; public const string CirclePrefab = "piece_suncircle"; private const string BasePrefab = "stone_pillar"; private const string LevelOpName = "sundial_level_ground"; private const string SmoothOpName = "sundial_smooth_ground"; private static readonly float[] LevelReach = new float[4] { 1f, 0.7f, 0.35f, 0f }; private static readonly Dictionary<StoneStyle, GameObject> Dials = new Dictionary<StoneStyle, GameObject>(); private static readonly Dictionary<StoneStyle, GameObject> Circles = new Dictionary<StoneStyle, GameObject>(); private static TerrainOp[] _levelOps; private static TerrainOp _smoothOp; public static Sprite Icon { get; private set; } public static Sprite CircleIcon { get; private set; } public static void Init() { PrefabManager.OnVanillaPrefabsAvailable += Add; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplyConfig(); }; ConfigEntry<string>[] array = new ConfigEntry<string>[10] { Cfg.Recipe, Cfg.Station, Cfg.CircleRecipe, Cfg.CircleStation, Cfg.MarbleRecipe, Cfg.MarbleCircleRecipe, Cfg.MarbleStation, Cfg.GraustenRecipe, Cfg.GraustenCircleRecipe, Cfg.GraustenStation }; for (int num = 0; num < array.Length; num++) { array[num].SettingChanged += delegate { ApplyConfig(); }; } CreateTerrainOps(); } public static void ApplyConfig() { StoneStyle[] all = StoneStyle.All; foreach (StoneStyle stoneStyle in all) { if (Dials.TryGetValue(stoneStyle, out var value)) { Apply(value, RecipeFor(stoneStyle, circle: false), StationFor(stoneStyle, circle: false)); } if (Circles.TryGetValue(stoneStyle, out var value2)) { Apply(value2, RecipeFor(stoneStyle, circle: true), StationFor(stoneStyle, circle: true)); } } } internal static GameObject FindPrefab(string name) { if (string.IsNullOrEmpty(name)) { return null; } GameObject val = null; if ((Object)(object)ObjectDB.instance != (Object)null) { val = ObjectDB.instance.GetItemPrefab(name); } if ((Object)(object)val == (Object)null && (Object)(object)ZNetScene.instance != (Object)null) { val = ZNetScene.instance.GetPrefab(name); } if ((Object)(object)val == (Object)null) { try { val = PrefabManager.Instance.GetPrefab(name); } catch (Exception) { } } return val; } private static string RecipeFor(StoneStyle s, bool circle) { if (s == StoneStyle.BlackMarble) { return (circle ? Cfg.MarbleCircleRecipe : Cfg.MarbleRecipe).Value; } if (s == StoneStyle.Grausten) { return (circle ? Cfg.GraustenCircleRecipe : Cfg.GraustenRecipe).Value; } return (circle ? Cfg.CircleRecipe : Cfg.Recipe).Value; } private static string StationFor(StoneStyle s, bool circle) { if (s == StoneStyle.BlackMarble) { return Cfg.MarbleStation.Value; } if (s == StoneStyle.Grausten) { return Cfg.GraustenStation.Value; } return (circle ? Cfg.CircleStation : Cfg.Station).Value; } internal static void Apply(GameObject prefab, string recipe, string station) { //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown try { if ((Object)(object)prefab == (Object)null) { return; } Piece component = prefab.GetComponent<Piece>(); if ((Object)(object)component == (Object)null) { return; } List<Requirement> list = new List<Requirement>(); foreach (RequirementConfig item in ParseRecipe(recipe)) { GameObject obj = FindPrefab(item.Item); ItemDrop val = ((obj != null) ? obj.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { SundialPlugin.Log.LogWarning((object)(((Object)prefab).name + " recipe: unknown item '" + item.Item + "'.")); continue; } list.Add(new Requirement { m_resItem = val, m_amount = item.Amount, m_recover = true }); } if (list.Count > 0) { component.m_resources = list.ToArray(); } if (string.IsNullOrWhiteSpace(station)) { component.m_craftingStation = null; return; } GameObject obj2 = FindPrefab(station.Trim()); CraftingStation val2 = ((obj2 != null) ? obj2.GetComponent<CraftingStation>() : null); if ((Object)(object)val2 != (Object)null) { component.m_craftingStation = val2; } else { SundialPlugin.Log.LogWarning((object)(((Object)prefab).name + " station: unknown crafting station '" + station + "'.")); } } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Could not apply the recipe of " + ((prefab != null) ? ((Object)prefab).name : null) + ": " + ex.Message)); } } private static void Add() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) try { Mats.Init(); StoneStyle[] all = StoneStyle.All; for (int i = 0; i < all.Length; i++) { StoneStyle stoneStyle = (Mats.Style = all[i]); SundialModel sundialModel = SundialModel.Create(45.0); Sprite icon = RenderIcon(((Component)sundialModel).gameObject, Quaternion.Euler(-38f, 155f, 0f)); if (stoneStyle == StoneStyle.Granite) { Icon = icon; } Dials[stoneStyle] = Register(stoneStyle.Suffixed("piece_sundial"), "$" + stoneStyle.Suffixed("piece_sundial"), "$piece_sundial_desc", RecipeFor(stoneStyle, circle: false), StationFor(stoneStyle, circle: false), icon, ((Component)sundialModel).gameObject, circle: false); SunCircleModel sunCircleModel = SunCircleModel.Create(45.0); icon = RenderIcon(((Component)sunCircleModel).gameObject, Quaternion.Euler(-24f, 160f, 0f)); if (stoneStyle == StoneStyle.Granite) { CircleIcon = icon; } Circles[stoneStyle] = Register(stoneStyle.Suffixed("piece_suncircle"), "$" + stoneStyle.Suffixed("piece_suncircle"), "$piece_suncircle_desc", RecipeFor(stoneStyle, circle: true), StationFor(stoneStyle, circle: true), icon, ((Component)sunCircleModel).gameObject, circle: true); } } catch (Exception ex) { SundialPlugin.Log.LogError((object)("Could not register the sundial pieces: " + ex)); } finally { Mats.Style = StoneStyle.Granite; PrefabManager.OnVanillaPrefabsAvailable -= Add; } } private static GameObject Register(string prefabName, string name, string desc, string recipe, string station, Sprite icon, GameObject visual, bool circle) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0029: 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_0043: Expected O, but got Unknown //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Expected O, but got Unknown PieceConfig val = new PieceConfig { Name = name, Description = desc, PieceTable = "Hammer", Category = "Misc", CraftingStation = (station ?? ""), Icon = icon }; foreach (RequirementConfig item in ParseRecipe(recipe)) { val.AddRequirement(item); } CustomPiece val2 = new CustomPiece(prefabName, "stone_pillar", val); if ((Object)(object)val2.PiecePrefab == (Object)null) { SundialPlugin.Log.LogError((object)("Cloning stone_pillar failed; no " + prefabName + ".")); Object.Destroy((Object)(object)visual); return null; } if (string.IsNullOrWhiteSpace(station)) { Piece component = val2.PiecePrefab.GetComponent<Piece>(); if ((Object)(object)component != (Object)null) { component.m_craftingStation = null; } } Reskin(val2.PiecePrefab, visual, circle); PieceManager.Instance.AddPiece(val2); return val2.PiecePrefab; } private static void Reskin(GameObject prefab, GameObject visual, bool circle) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00db: 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) Transform transform = prefab.transform; for (int num = transform.childCount - 1; num >= 0; num--) { Object.DestroyImmediate((Object)(object)((Component)transform.GetChild(num)).gameObject); } Collider[] components = prefab.GetComponents<Collider>(); for (int i = 0; i < components.Length; i++) { Object.DestroyImmediate((Object)(object)components[i]); } visual.transform.SetParent(transform, false); visual.transform.localPosition = Vector3.zero; visual.transform.localRotation = Quaternion.identity; SetLayer(visual, prefab.layer); if (!circle) { BoxCollider obj = prefab.AddComponent<BoxCollider>(); obj.center = new Vector3(0f, 0.5405f, 0f); obj.size = new Vector3(0.529f, 1.081f, 0.529f); BoxCollider obj2 = prefab.AddComponent<BoxCollider>(); obj2.center = new Vector3(0f, 1.09825f, 0f); obj2.size = new Vector3(0.759f, 0.069f, 0.759f); } WearNTear component = prefab.GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_new = visual; component.m_worn = visual; component.m_broken = visual; component.m_health = (circle ? 6000f : 1000f); component.m_fragmentRoots = null; } Piece component2 = prefab.GetComponent<Piece>(); if ((Object)(object)component2 != (Object)null) { component2.m_groundOnly = false; component2.m_noInWater = true; if (circle) { component2.m_noClipping = false; component2.m_clipEverything = false; } } prefab.AddComponent<SundialPiece>(); } private static void SetLayer(GameObject go, int layer) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) go.layer = layer; foreach (Transform item in go.transform) { SetLayer(((Component)item).gameObject, layer); } } internal static Sprite RenderIcon(GameObject visual, Quaternion rotation) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown if (GUIManager.IsHeadless()) { return null; } GameObject val = null; try { val = Object.Instantiate<GameObject>(visual); val.transform.position = Vector3.zero; val.transform.rotation = Quaternion.identity; return RenderManager.Instance.Render(new RenderRequest(val) { Rotation = rotation, Width = 128, Height = 128, ParticleSimulationTime = -1f, UseCache = false }); } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Icon rendering failed: " + ex.Message)); return null; } finally { if ((Object)(object)val != (Object)null) { Object.DestroyImmediate((Object)(object)val); } } } public static List<RequirementConfig> ParseRecipe(string recipe) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); if (string.IsNullOrWhiteSpace(recipe)) { return list; } string[] array = recipe.Split(new char[2] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { string[] array2 = text.Split(new char[1] { ':' }); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0 && array2[0].Trim().Length > 0) { list.Add(new RequirementConfig(array2[0].Trim(), result, 0, true)); } else { SundialPlugin.Log.LogWarning((object)("Ignoring invalid recipe entry '" + text + "'.")); } } return list; } private static void CreateTerrainOps() { //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) _levelOps = (TerrainOp[])(object)new TerrainOp[LevelReach.Length]; for (int i = 0; i < LevelReach.Length; i++) { _levelOps[i] = NewOp((i == 0) ? "sundial_level_ground" : ("sundial_level_ground_" + Mathf.RoundToInt(LevelReach[i] * 100f))); Settings settings = _levelOps[i].m_settings; settings.m_level = true; settings.m_levelRadius = 4.74f + LevelReach[i]; settings.m_paintCleared = true; settings.m_paintType = (PaintType)2; settings.m_paintRadius = 5.4399996f; settings.m_paintStrength = 1f; settings.m_paintExp = 0.25f; } _smoothOp = NewOp("sundial_smooth_ground"); Settings settings2 = _smoothOp.m_settings; settings2.m_smooth = true; settings2.m_smoothRadius = 7.74f; settings2.m_smoothPower = 2.2f; settings2.m_paintCleared = true; settings2.m_paintType = (PaintType)2; settings2.m_paintRadius = 5.4399996f; settings2.m_paintStrength = 1f; settings2.m_paintExp = 0.25f; } private static TerrainOp NewOp(string name) { //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_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown GameObject val = new GameObject(name); val.SetActive(false); Object.DontDestroyOnLoad((Object)val); TerrainOp obj = val.AddComponent<TerrainOp>(); Settings settings = obj.m_settings; settings.m_levelOffset = 0f; settings.m_level = false; settings.m_square = false; settings.m_raise = false; settings.m_smooth = false; settings.m_paintCleared = false; settings.m_paintHeightCheck = false; return obj; } private static void Apply(TerrainOp template, Vector3 at) { //IL_0006: 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) GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, at, Quaternion.identity); ((Object)obj).name = ((Object)((Component)template).gameObject).name; obj.SetActive(true); } public static void LevelGround(Vector3 at) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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) try { if (_levelOps != null && !((Object)(object)ZoneSystem.instance == (Object)null)) { float num = default(float); if (!ZoneSystem.instance.GetGroundHeight(at, ref num) || Mathf.Abs(num - at.y) > 1f) { SundialPlugin.Log.LogInfo((object)$"Sun circle at {at}: not on the ground (terrain at {num:0.00}), leaving the ground as it is."); } else { ((MonoBehaviour)SundialPlugin.Instance).StartCoroutine(LevelSoon(at)); } } } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Could not level the ground: " + ex.Message)); } } private static float NearestCircle(Vector3 at) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) float num = float.PositiveInfinity; foreach (SundialPiece item in SundialPiece.All) { if (!((Object)(object)item == (Object)null) && item.IsCircle) { float num2 = Vector3.Distance(((Component)item).transform.position, at); if (num2 > 0.5f && num2 < num) { num = num2; } } } return num; } private static TerrainOp LevelOpFor(float nearest) { float num = nearest - 4.42f - 0.3f; TerrainOp[] levelOps = _levelOps; foreach (TerrainOp val in levelOps) { if (val.m_settings.m_levelRadius <= num) { return val; } } return _levelOps[_levelOps.Length - 1]; } private static IEnumerator LevelSoon(Vector3 at) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) List<Heightmap> maps = new List<Heightmap>(); List<TerrainComp> comps = new List<TerrainComp>(); try { Heightmap.FindHeightmap(at, _smoothOp.GetRadius(), maps); foreach (Heightmap item in maps) { comps.Add(item.GetAndCreateTerrainCompiler()); } } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Could not prepare the ground: " + ex.Message)); yield break; } float until = Time.time + 10f; while (Time.time < until && comps.Exists((TerrainComp c) => (Object)(object)c != (Object)null && (Object)(object)c.m_nview != (Object)null && c.m_nview.IsValid() && c.m_nview.IsOwner() && !c.m_initialized)) { yield return null; } yield return null; float nearest = NearestCircle(at); try { Apply(LevelOpFor(nearest), at); } catch (Exception ex2) { SundialPlugin.Log.LogWarning((object)("Could not level the ground: " + ex2.Message)); yield break; } yield return (object)new WaitForSeconds(1.5f); try { if (nearest < _smoothOp.m_settings.m_smoothRadius + 4.42f + 0.5f) { SundialPlugin.Log.LogInfo((object)$"Sun circle at {at}: levelled the ground; another circle is close, so the edge is left unsmoothed."); yield break; } Apply(_smoothOp, at); SundialPlugin.Log.LogInfo((object)$"Sun circle at {at}: levelled the ground ({maps.Count} heightmaps)."); } catch (Exception ex3) { SundialPlugin.Log.LogWarning((object)("Could not smooth the ground: " + ex3.Message)); } } } [BepInPlugin("jan.sundial", "Sundial", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class SundialPlugin : BaseUnityPlugin { public const string PluginGuid = "jan.sundial"; public const string PluginName = "Sundial"; public const string PluginVersion = "1.0.0"; private Harmony _harmony; public static SundialPlugin Instance { get; private set; } public static string PluginDir { get; private set; } public static ManualLogSource Log { get; private set; } public static string AssetPath(string fileName) { return Path.Combine(PluginDir ?? "", "Assets", fileName); } private void Awake() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown Instance = this; Log = ((BaseUnityPlugin)this).Logger; PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); Cfg.Bind(((BaseUnityPlugin)this).Config); Lang.Register(); Pieces.Init(); RingDial.Init(); _harmony = new Harmony("jan.sundial"); _harmony.PatchAll(typeof(SundialPlugin).Assembly); SelfTest.TryStart(((Component)this).gameObject); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace Sundial.Visual { internal static class DialFace { public const float PlateRadius = 0.3f; public const float FootZ = -0.112500004f; private const float BandIn = 0.79f; private const float BandOut = 0.925f; private const float Inner = 0.77f; private static readonly string[] Numerals = new string[12] { "XII", "I", "II", "III", "IIII", "V", "VI", "VII", "VIII", "IX", "X", "XI" }; private static readonly Dictionary<int, Texture2D[]> Cache = new Dictionary<int, Texture2D[]>(); private static bool _loaded; private static bool _loadFailed; private static int _n; private static Color32[] _albedo; private static float[] _height; private static Color32[] _atlas; private static int _atlasW; private static int _atlasH; private static readonly Dictionary<string, RectInt> Glyphs = new Dictionary<string, RectInt>(); public static Texture2D[] Get(double latitudeDeg) { int key = (int)Math.Round(latitudeDeg * 10.0); if (Cache.TryGetValue(key, out var value) && (Object)(object)value[0] != (Object)null) { return value; } if (!Load()) { return null; } try { value = Build(latitudeDeg); Cache[key] = value; return value; } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Engraving the dial failed: " + ex)); return null; } } public static string NumeralFor(int hour12) { return Numerals[(hour12 % 12 + 12) % 12]; } private static bool Load() { //IL_015e: Unknown result type (might be due to invalid IL or missing references) if (_loaded) { return true; } if (_loadFailed) { return false; } try { Texture2D val = Read("plate_albedo.png", linear: false); Texture2D val2 = Read("plate_height.png", linear: true); Texture2D val3 = Read("numerals.png", linear: true); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || ((Texture)val).width != ((Texture)val2).width) { throw new IOException("plate art missing or mismatched"); } _n = ((Texture)val).width; _albedo = val.GetPixels32(); Color32[] pixels = val2.GetPixels32(); _height = new float[pixels.Length]; for (int i = 0; i < pixels.Length; i++) { _height[i] = (float)(int)pixels[i].r / 255f; } _atlas = val3.GetPixels32(); _atlasW = ((Texture)val3).width; _atlasH = ((Texture)val3).height; string[] array = File.ReadAllLines(SundialPlugin.AssetPath("numerals.txt")); for (int j = 0; j < array.Length; j++) { string[] array2 = array[j].Split(new char[1] { ' ' }); if (array2.Length == 5) { int num = int.Parse(array2[1]); int num2 = int.Parse(array2[2]); int num3 = int.Parse(array2[3]); int num4 = int.Parse(array2[4]); Glyphs[array2[0]] = new RectInt(num, _atlasH - num2 - num4, num3, num4); } } Object.Destroy((Object)(object)val); Object.Destroy((Object)(object)val2); Object.Destroy((Object)(object)val3); _loaded = true; return true; } catch (Exception ex) { _loadFailed = true; SundialPlugin.Log.LogWarning((object)("Sundial plate art could not be loaded: " + ex.Message)); return false; } } private static Texture2D Read(string file, bool linear) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown string path = SundialPlugin.AssetPath(file); if (!File.Exists(path)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false, linear); if (!AssetUtils.LoadImage(val, File.ReadAllBytes(path))) { return null; } return val; } private static Texture2D[] Build(double lat) { //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0118: 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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_01da: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_037b: Unknown result type (might be due to invalid IL or missing references) //IL_0382: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Expected O, but got Unknown //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03c3: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03d3: Expected O, but got Unknown //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_02ce: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Unknown result type (might be due to invalid IL or missing references) //IL_0334: Unknown result type (might be due to invalid IL or missing references) int n = _n; float num = (float)n / 0.6f; float[] array = (float[])_height.Clone(); float[] array2 = new float[array.Length]; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0f, -0.112500004f); float r = 0.23700002f; float r2 = 0.25725f; float num2 = 0.231f; Vector2 val2 = default(Vector2); for (int i = 24; i <= 72; i++) { double num3 = (double)i / 4.0; float num4 = (float)(DialMath.HourLineAngle(num3, lat) * 0.01745329238474369); ((Vector2)(ref val2))..ctor(Mathf.Sin(num4), Mathf.Cos(num4)); bool num5 = i % 4 == 0; bool flag = i % 2 == 0; if (num5) { Vector2 b = RayToCircle(val, val2, r); Engrave(array, array2, val + val2 * 0.022f, b, 0.0021f * num, 0.42f, num); int num6 = (int)Math.Round(num3) % 12; Vector2 at = RayToCircle(val, val2, r2); Stamp(array, array2, Numerals[num6], at, 0.02511f, num); } else { Vector2 b2 = RayToCircle(val, val2, r); Vector2 a = RayToCircle(val, val2, flag ? (num2 - 0.02f) : (num2 - 0.008f)); Engrave(array, array2, a, b2, (flag ? 0.0016f : 0.0011f) * num, 0.34f, num); } } Color32[] array3 = (Color32[])(object)new Color32[_albedo.Length]; Color val3 = default(Color); ((Color)(ref val3))..ctor(0.16f, 0.11f, 0.07f); Color val4 = default(Color); ((Color)(ref val4))..ctor(0.25f, 0.47f, 0.4f); for (int j = 0; j < array3.Length; j++) { float num7 = array2[j]; if (num7 <= 0f) { array3[j] = _albedo[j]; continue; } Color val5 = Color32.op_Implicit(_albedo[j]); float num8 = Mathf.Clamp01(num7 * 2.4f); Color val6 = Color.Lerp(val5, val4, num8 * 0.25f); val6 = Color.Lerp(val6, val3, num8 * 0.62f); array3[j] = Color32.op_Implicit(val6); } Color32[] array4 = (Color32[])(object)new Color32[array.Length]; for (int k = 0; k < n; k++) { int num9 = Math.Max(0, k - 1) * n; int num10 = Math.Min(n - 1, k + 1) * n; int num11 = k * n; for (int l = 0; l < n; l++) { int num12 = Math.Max(0, l - 1); int num13 = Math.Min(n - 1, l + 1); float num14 = (array[num11 + num13] - array[num11 + num12]) * 3.2f; float num15 = (array[num10 + l] - array[num9 + l]) * 3.2f; Vector3 val7 = new Vector3(0f - num14, 0f - num15, 1f); Vector3 normalized = ((Vector3)(ref val7)).normalized; array4[num11 + l] = new Color32((byte)((normalized.x * 0.5f + 0.5f) * 255f), (byte)((normalized.y * 0.5f + 0.5f) * 255f), (byte)((normalized.z * 0.5f + 0.5f) * 255f), byte.MaxValue); } } Texture2D val8 = new Texture2D(n, n, (TextureFormat)4, true, false) { name = "Sundial_PlateAlbedo_" + lat.ToString("0.0"), wrapMode = (TextureWrapMode)1, anisoLevel = 4 }; val8.SetPixels32(array3); val8.Apply(true, true); Texture2D val9 = new Texture2D(n, n, (TextureFormat)4, true, true) { name = "Sundial_PlateNormal_" + lat.ToString("0.0"), wrapMode = (TextureWrapMode)1, anisoLevel = 4 }; val9.SetPixels32(array4); val9.Apply(true, true); return (Texture2D[])(object)new Texture2D[2] { val8, val9 }; } private static Vector2 RayToCircle(Vector2 from, Vector2 dir, float r) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) float num = Vector2.Dot(from, dir); float num2 = ((Vector2)(ref from)).sqrMagnitude - r * r; float num3 = 0f - num + Mathf.Sqrt(Mathf.Max(0f, num * num - num2)); return from + dir * num3; } private static Vector2 ToPx(Vector2 plate, float pxPerM) { //IL_0000: 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_0028: Unknown result type (might be due to invalid IL or missing references) return new Vector2((plate.x + 0.3f) * pxPerM - 0.5f, (plate.y + 0.3f) * pxPerM - 0.5f); } private static void Engrave(float[] height, float[] cut, Vector2 a, Vector2 b, float widthPx, float depth, float pxPerM) { //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) //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_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_0021: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) Vector2 val = ToPx(a, pxPerM); Vector2 val2 = ToPx(b, pxPerM); float num = widthPx * 0.5f + 1f; int val3 = Mathf.FloorToInt(Mathf.Min(val.x, val2.x) - num); int val4 = Mathf.CeilToInt(Mathf.Max(val.x, val2.x) + num); int val5 = Mathf.FloorToInt(Mathf.Min(val.y, val2.y) - num); int val6 = Mathf.CeilToInt(Mathf.Max(val.y, val2.y) + num); Vector2 val7 = val2 - val; float num2 = Mathf.Max(1E-06f, ((Vector2)(ref val7)).sqrMagnitude); for (int i = Math.Max(0, val5); i <= Math.Min(_n - 1, val6); i++) { for (int j = Math.Max(0, val3); j <= Math.Min(_n - 1, val4); j++) { Vector2 val8 = new Vector2((float)j, (float)i); float num3 = Mathf.Clamp01(Vector2.Dot(val8 - val, val7) / num2); float num4 = Vector2.Distance(val8, val + val7 * num3) / (widthPx * 0.5f); if (!(num4 >= 1f)) { float depth2 = (1f - num4) * depth; Cut(height, cut, i * _n + j, depth2); } } } } private static void Stamp(float[] height, float[] cut, string glyph, Vector2 at, float heightM, float pxPerM) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) if (!Glyphs.TryGetValue(glyph, out var value)) { return; } float num = heightM * pxPerM / (float)((RectInt)(ref value)).height; Vector2 val = ((((Vector2)(ref at)).sqrMagnitude > 1E-08f) ? ((Vector2)(ref at)).normalized : Vector2.up); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(val.y, 0f - val.x); Vector2 val3 = ToPx(at, pxPerM); float num2 = (float)((RectInt)(ref value)).width * 0.5f * num; float num3 = (float)((RectInt)(ref value)).height * 0.5f * num; float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3) + 2f; for (int i = Mathf.Max(0, Mathf.FloorToInt(val3.y - num4)); i <= Mathf.Min(_n - 1, Mathf.CeilToInt(val3.y + num4)); i++) { for (int j = Mathf.Max(0, Mathf.FloorToInt(val3.x - num4)); j <= Mathf.Min(_n - 1, Mathf.CeilToInt(val3.x + num4)); j++) { Vector2 val4 = new Vector2((float)j, (float)i) - val3; float num5 = Vector2.Dot(val4, val2) / num + (float)((RectInt)(ref value)).width * 0.5f; float num6 = Vector2.Dot(val4, val) / num + (float)((RectInt)(ref value)).height * 0.5f; if (!(num5 < 0f) && !(num6 < 0f) && !(num5 >= (float)(((RectInt)(ref value)).width - 1)) && !(num6 >= (float)(((RectInt)(ref value)).height - 1))) { float num7 = SampleAtlas((float)((RectInt)(ref value)).x + num5, (float)((RectInt)(ref value)).y + num6); if (!(num7 <= 0.01f)) { Cut(height, cut, i * _n + j, num7 * 0.4f); } } } } } private static float SampleAtlas(float x, float y) { int num = (int)x; int num2 = (int)y; float num3 = x - (float)num; float num4 = y - (float)num2; float num5 = (int)_atlas[num2 * _atlasW + num].r; float num6 = (int)_atlas[num2 * _atlasW + num + 1].r; float num7 = (int)_atlas[(num2 + 1) * _atlasW + num].r; float num8 = (int)_atlas[(num2 + 1) * _atlasW + num + 1].r; return Mathf.Lerp(Mathf.Lerp(num5, num6, num3), Mathf.Lerp(num7, num8, num3), num4) / 255f; } private static void Cut(float[] height, float[] cut, int i, float depth) { if (!(depth <= cut[i])) { height[i] -= depth - cut[i]; cut[i] = depth; } } } internal interface IDialModel { float ShownYaw { get; } bool ScaleReady { get; } double NodusDistance { get; } Vector3 NodusWorld { get; } Vec3 TipFoot { get; } void Bind(); void SetLatitude(double latitudeDeg); void DriveYaw(float targetYaw, bool aligned, bool mayRise, bool instant); bool LineHours(Vec3 towardLightLocal, out double hours); bool TipShadow(Vec3 towardLightLocal, out Vec3 tip); bool OnSurface(Vec3 p); Vector3 SurfaceToWorld(Vec3 p); void SetChalk(IList<Vec3> marks, bool circle, float frameYaw); void UpdateShadow(Vector3 towardLightWorld, float alpha); } internal static class Mats { public static Material Bronze; public static Material Plate; public static Material Chalk; public static Material Shadow; public static StoneStyle Style = StoneStyle.Granite; private static readonly Dictionary<int, Material> PlateByLat = new Dictionary<int, Material>(); private static bool _vanilla; private static readonly int Metallic = Shader.PropertyToID("_Metallic"); private static readonly int Glossiness = Shader.PropertyToID("_Glossiness"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int BumpMap = Shader.PropertyToID("_BumpMap"); private static readonly int BumpScale = Shader.PropertyToID("_BumpScale"); private static Texture2D _stoneNormal; private static Texture2D _pavingNormal; public static Material Stone => Style.Stone; public static Material Paving => Style.Paving; public static Material Carve => Style.Carve; public static void Init() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Expected O, but got Unknown //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) if (_vanilla) { return; } Material val = FindMat("BronzeNails", "bronzenails") ?? FindMat("Bronze", "bronze"); StoneStyle[] all = StoneStyle.All; for (int i = 0; i < all.Length; i++) { MakeStone(all[i]); } if ((Object)(object)Shadow == (Object)null) { Shadow = Std("Shadow", new Color(0.02f, 0.015f, 0.01f, 0.6f), 0f, 0f); if ((Object)(object)Shadow != (Object)null) { MakeFade(Shadow); } } if ((Object)(object)val != (Object)null && ((Object)(object)Bronze == (Object)null || !((Object)Bronze).name.EndsWith("_v"))) { Bronze = new Material(val) { name = "Sundial_Bronze_v", hideFlags = (HideFlags)32 }; Bronze.color *= new Color(0.75f, 0.72f, 0.68f, 1f); SetF(Bronze, Metallic, 0.75f); SetF(Bronze, Glossiness, 0.32f); } else if ((Object)(object)Bronze == (Object)null) { Bronze = Std("Bronze", new Color(0.64f, 0.46f, 0.24f), 0.85f, 0.55f); } if ((Object)(object)Plate == (Object)null) { Plate = Std("Plate", new Color(0.64f, 0.46f, 0.24f), 0.55f, 0.3f); } if ((Object)(object)Chalk == (Object)null) { Chalk = Std("Chalk", new Color(0.93f, 0.92f, 0.86f), 0f, 0.02f); } _vanilla = (Object)(object)val != (Object)null; } private static void MakeStone(StoneStyle s) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) string text = ((s.Id.Length == 0) ? "" : ("_" + s.Id)); if ((Object)(object)_stoneNormal == (Object)null) { _stoneNormal = LoadTex("stone_normal.png", linear: true, (TextureWrapMode)0); } if ((Object)(object)_pavingNormal == (Object)null) { _pavingNormal = LoadTex("paving_normal.png", linear: true, (TextureWrapMode)0); } if ((Object)(object)s.Stone == (Object)null) { s.Stone = Std("Stone" + text, s.StoneTint, 0f, s.Gloss); Texture2D val = LoadTex(s.Suffixed("stone_albedo.png"), linear: false, (TextureWrapMode)0) ?? LoadTex("stone_albedo.png", linear: false, (TextureWrapMode)0); if ((Object)(object)val != (Object)null && (Object)(object)s.Stone != (Object)null) { s.Stone.SetTexture(MainTex, (Texture)(object)val); } SetNormal(s.Stone, _stoneNormal, 0.9f * s.Bump); } if ((Object)(object)s.Paving == (Object)null) { s.Paving = Std("Paving" + text, s.PavingTint, 0f, s.PavingGloss); Texture2D val2 = LoadTex(s.Suffixed("paving_albedo.png"), linear: false, (TextureWrapMode)0) ?? LoadTex("paving_albedo.png", linear: false, (TextureWrapMode)0); if ((Object)(object)val2 != (Object)null && (Object)(object)s.Paving != (Object)null) { s.Paving.SetTexture(MainTex, (Texture)(object)val2); } SetNormal(s.Paving, _pavingNormal, 1.1f * s.Bump); } if ((Object)(object)s.Carve == (Object)null) { s.Carve = Std("Carve" + text, s.CarveColor, s.CarveMetal, s.CarveGloss); } } private static void SetNormal(Material m, Texture2D n, float scale) { if (!((Object)(object)m == (Object)null) && !((Object)(object)n == (Object)null) && m.HasProperty(BumpMap)) { m.SetTexture(BumpMap, (Texture)(object)n); SetF(m, BumpScale, scale); m.EnableKeyword("_NORMALMAP"); } } public static Texture2D LoadTex(string file, bool linear, TextureWrapMode wrap) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) try { string path = SundialPlugin.AssetPath(file); if (!File.Exists(path)) { return null; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, linear) { name = "Sundial_" + file, wrapMode = wrap, anisoLevel = 4 }; if (!AssetUtils.LoadImage(val, File.ReadAllBytes(path))) { return null; } ((Texture)val).wrapMode = wrap; return val; } catch (Exception ex) { SundialPlugin.Log.LogWarning((object)("Could not load " + file + ": " + ex.Message)); return null; } } private static void MakeFade(Material m) { m.SetFloat("_Mode", 2f); m.SetInt("_SrcBlend", 5); m.SetInt("_DstBlend", 10); m.SetInt("_ZWrite", 0); m.DisableKeyword("_ALPHATEST_ON"); m.EnableKeyword("_ALPHABLEND_ON"); m.DisableKeyword("_ALPHAPREMULTIPLY_ON"); m.renderQueue = 3000; } public static Material PlateFor(double latitudeDeg) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) Init(); int key = (int)Math.Round(latitudeDeg * 10.0); if (PlateByLat.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } Texture2D[] array = DialFace.Get(latitudeDeg); if (array == null || (Object)(object)Plate == (Object)null) { return Plate; } value = new Material(Plate) { name = "Sundial_Plate_" + latitudeDeg.ToString("0.0"), hideFlags = (HideFlags)32 }; value.color = new Color(0.66f, 0.63f, 0.6f); value.SetTexture(MainTex, (Texture)(object)array[0]); if (value.HasProperty(BumpMap)) { value.SetTexture(BumpMap, (Texture)(object)array[1]); SetF(value, BumpScale, 1f); value.EnableKeyword("_NORMALMAP"); } PlateByLat[key] = value; return value; } private static Material FindMat(string prefabName, string matName) { GameObject val = null; try { val = PrefabManager.Instance.GetPrefab(prefabName); } catch (Exception) { } if ((Object)(object)val == (Object)null) { return null; } Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true); foreach (Renderer val2 in componentsInChildren) { if ((Object)(object)val2 == (Object)null) { continue; } Material[] sharedMaterials = val2.sharedMaterials; foreach (Material val3 in sharedMaterials) { if (!((Object)(object)val3 == (Object)null) && (((Object)val3).name == matName || ((Object)val3).name.StartsWith(matName + " ", StringComparison.Ordinal))) { return val3; } } } return null; } private static Material Std(string name, Color c, float metallic, float gloss) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_007f: Expected O, but got Unknown Shader val = Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse") ?? Shader.Find("Sprites/Default") ?? Shader.Find("Hidden/Internal-Colored"); if ((Object)(object)val == (Object)null) { return null; } Material val2 = new Material(val) { name = "Sundial_" + name, hideFlags = (HideFlags)32, color = c }; SetF(val2, Metallic, metallic); SetF(val2, Glossiness, gloss); return val2; } private static void SetF(Material m, int id, float v) { if ((Object)(object)m != (Object)null && m.HasProperty(id)) { m.SetFloat(id, v); } } } internal sealed class MeshBuilder { public readonly List<Vector3> Vertices = new List<Vector3>(256); public readonly List<Vector3> Normals = new List<Vector3>(256); public readonly List<Vector2> UVs = new List<Vector2>(256); public readonly List<int> Triangles = new List<int>(512); private readonly Stack<Matrix4x4> _stack = new Stack<Matrix4x4>(); private Matrix4x4 _base = Matrix4x4.identity; private Matrix4x4 _local = Matrix4x4.identity; private Matrix4x4 _m = Matrix4x4.identity; private Matrix4x4 _n = Matrix4x4.identity; private bool _flip; public bool IsEmpty => Triangles.Count == 0; public void SetBase(Matrix4x4 m) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_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) if (!(m == _base)) { _base = m; Recalc(); } } public void Push(Matrix4x4 m) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _stack.Push(_local); _local *= m; Recalc(); } public void Push(Vector3 pos, Quaternion rot) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) Push(Matrix4x4.TRS(pos, rot, Vector3.one)); } public void Pop() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) _local = ((_stack.Count > 0) ? _stack.Pop() : Matrix4x4.identity); Recalc(); } private void Recalc() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) _m = _base * _local; Matrix4x4 inverse = ((Matrix4x4)(ref _m)).inverse; _n = ((Matrix4x4)(ref inverse)).transpose; _flip = ((Matrix4x4)(ref _m)).determinant < 0f; } public int Add(Vector3 p, Vector3 n, Vector2 uv) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_003a: 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) Vertices.Add(((Matrix4x4)(ref _m)).MultiplyPoint3x4(p)); Vector3 val = ((Matrix4x4)(ref _n)).MultiplyVector(n); float magnitude = ((Vector3)(ref val)).magnitude; Normals.Add((magnitude > 1E-08f) ? (val / magnitude) : Vector3.up); UVs.Add(uv); return Vertices.Count - 1; } public void Tri(int a, int b, int c) { Triangles.Add(a); if (_flip) { Triangles.Add(c); Triangles.Add(b); } else { Triangles.Add(b); Triangles.Add(c); } } public void Quad(int a, int b, int c, int d) { Tri(a, b, c); Tri(a, c, d); } public Mesh ToMesh(string name) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown Mesh val = new Mesh { name = name }; if (Vertices.Count > 65000) { val.indexFormat = (IndexFormat)1; } val.SetVertices(Vertices); val.SetNormals(Normals); val.SetUVs(0, UVs); val.SetTriangles(Triangles, 0, true); val.RecalculateTangents(); return val; } public void Clear() { Vertices.Clear(); Normals.Clear(); UVs.Clear(); Triangles.Clear(); } } internal sealed class PartSet { private readonly List<Material> _mats = new List<Material>(); private readonly List<MeshBuilder> _builders = new List<MeshBuilder>(); private readonly Stack<Matrix4x4> _stack = new Stack<Matrix4x4>(); private Matrix4x4 _current = Matrix4x4.identity; public MeshBuilder this[Material mat] { get { //IL_0059: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = null; for (int i = 0; i < _mats.Count; i++) { if (_mats[i] == mat) { meshBuilder = _builders[i]; break; } } if (meshBuilder == null) { meshBuilder = new MeshBuilder(); _mats.Add(mat); _builders.Add(meshBuilder); } meshBuilder.SetBase(_current); return meshBuilder; } } public void Push(Matrix4x4 m) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) _stack.Push(_current); _current *= m; } public void Push(Vector3 pos, Quaternion rot) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) Push(Matrix4x4.TRS(pos, rot, Vector3.one)); } public void Push(Vector3 pos, Quaternion rot, Vector3 scale) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) Push(Matrix4x4.TRS(pos, rot, scale)); } public void Pop() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) _current = ((_stack.Count > 0) ? _stack.Pop() : Matrix4x4.identity); } public void Emit(Transform parent, string name) { //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown for (int i = 0; i < _builders.Count; i++) { MeshBuilder meshBuilder = _builders[i]; Material val = _mats[i]; if (!meshBuilder.IsEmpty) { string text = (((Object)(object)val != (Object)null) ? ((Object)val).name.Replace("Sundial_", "") : "Mat"); GameObject val2 = new GameObject(name + "_" + text); val2.transform.SetParent(parent, false); val2.AddComponent<MeshFilter>().sharedMesh = meshBuilder.ToMesh(((Object)val2).name); MeshRenderer obj = val2.AddComponent<MeshRenderer>(); ((Renderer)obj).sharedMaterial = val; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)1; ((Renderer)obj).receiveShadows = true; } } _mats.Clear(); _builders.Clear(); _stack.Clear(); _current = Matrix4x4.identity; } } internal static class MeshKit { private const float Tau = (float)Math.PI * 2f; public static Quaternion AlongX => Quaternion.Euler(0f, 0f, -90f); public static Quaternion AlongZ => Quaternion.Euler(90f, 0f, 0f); public static void ProfileNormals(IList<Vector2> p, Vector2[] result) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) int count = p.Count; for (int i = 0; i < count; i++) { Vector2 val = Vector2.zero; Vector2 val4; if (i > 0) { Vector2 val2 = p[i] - p[i - 1]; if (((Vector2)(ref val2)).sqrMagnitude > 1E-12f) { Vector2 val3 = val; val4 = new Vector2(val2.y, 0f - val2.x); val = val3 + ((Vector2)(ref val4)).normalized; } } if (i < count - 1) { Vector2 val5 = p[i + 1] - p[i]; if (((Vector2)(ref val5)).sqrMagnitude > 1E-12f) { Vector2 val6 = val; val4 = new Vector2(val5.y, 0f - val5.x); val = val6 + ((Vector2)(ref val4)).normalized; } } result[i] = (Vector2)((((Vector2)(ref val)).sqrMagnitude > 1E-12f) ? ((Vector2)(ref val)).normalized : new Vector2(1f, 0f)); } } public static void Lathe(MeshBuilder mb, IList<Vector2> prof, int seg, float uTiles = 1f, float vPerMeter = 1f, IList<Vector2> normals = null, bool swapUV = false) { //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) //IL_005d: 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_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ba: Unknown result type (might be due to invalid IL or missing references) int count = prof.Count; if (count < 2 || seg < 3) { return; } Vector2[] array = (Vector2[])(object)new Vector2[count]; if (normals != null) { for (int i = 0; i < count; i++) { array[i] = normals[i]; } } else { ProfileNormals(prof, array); } float[] array2 = new float[count]; for (int j = 1; j < count; j++) { array2[j] = array2[j - 1] + Vector2.Distance(prof[j], prof[j - 1]); } int num = seg + 1; int num2 = -1; Vector2 val = default(Vector2); for (int k = 0; k < count; k++) { for (int l = 0; l <= seg; l++) { float num3 = (float)l * ((float)Math.PI * 2f / (float)seg); float num4 = Mathf.Cos(num3); float num5 = Mathf.Sin(num3); ((Vector2)(ref val))..ctor((float)l / (float)seg * uTiles, array2[k] * vPerMeter); if (swapUV) { ((Vector2)(ref val))..ctor(val.y, val.x); } int num6 = mb.Add(new Vector3(prof[k].x * num4, prof[k].y, prof[k].x * num5), new Vector3(array[k].x * num4, array[k].y, array[k].x * num5), val); if (num2 < 0) { num2 = num6; } } } for (int m = 0; m < count - 1; m++) { Vector2 val2 = prof[m + 1] - prof[m]; if (!(((Vector2)(ref val2)).sqrMagnitude < 1E-12f) && (!(prof[m].x <= 0f) || !(prof[m + 1].x <= 0f))) { for (int n = 0; n < seg; n++) { int num7 = num2 + m * num + n; int d = num7 + 1; int num8 = num7 + num; int c = num8 + 1; mb.Quad(num7, num8, c, d); } } } } public static void LatheX(MeshBuilder mb, Vector3 origin, IList<Vector2> prof, int seg, float uTiles = 1f, float vPerMeter = 1f, bool swapUV = false) { //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) mb.Push(origin, AlongX); Lathe(mb, prof, seg, uTiles, vPerMeter, null, swapUV); mb.Pop(); } public static void LatheZ(MeshBuilder mb, Vector3 origin, IList<Vector2> prof, int seg, float uTiles = 1f, float vPerMeter = 1f, bool swapUV = false) { //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) mb.Push(origin, AlongZ); Lathe(mb, prof, seg, uTiles, vPerMeter, null, swapUV); mb.Pop(); } public static float Tiles(float radius, float perMeter) { return Mathf.Max(1f, Mathf.Round((float)Math.PI * 2f * radius * perMeter)); } public static void Arc(List<Vector2> list, Vector2 center, float radius, float fromDeg, float toDeg, int steps) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) for (int i = 0; i <= steps; i++) { float num = Mathf.Lerp(fromDeg, toDeg, (float)i / (float)steps) * ((float)Math.PI / 180f); list.Add(center + new Vector2(Mathf.Cos(num), Mathf.Sin(num)) * radius); } } public static void Cylinder(MeshBuilder mb, Vector3 a, Vector3 b, float ra, float rb, int seg, bool capA = true, bool capB = true, float uTiles = 1f, float vPerMeter = 1f, bool swapUV = false) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) Vector3 val = b - a; float magnitude = ((Vector3)(ref val)).magnitude; if (!(magnitude < 1E-06f)) { List<Vector2> list = new List<Vector2>(6); if (capA) { list.Add(new Vector2(0f, 0f)); list.Add(new Vector2(ra, 0f)); } list.Add(new Vector2(ra, 0f)); list.Add(new Vector2(rb, magnitude)); if (capB) { list.Add(new Vector2(rb, magnitude)); list.Add(new Vector2(0f, magnitude)); } mb.Push(a, Quaternion.FromToRotation(Vector3.up, val / magnitude)); Lathe(mb, list, seg, uTiles, vPerMeter, null, swapUV); mb.Pop(); } } public static void Cylinder(MeshBuilder mb, Vector3 a, Vector3 b, float r, int seg, bool caps = true, float uTiles = 1f, float vPerMeter = 1f) { //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) Cylinder(mb, a, b, r, r, seg, caps, caps, uTiles, vPerMeter); } public static void Sphere(MeshBuilder mb, Vector3 c, float r, int seg = 12, int rings = 8) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) Ellipsoid(mb, c, new Vector3(r, r, r), Quaternion.identity, seg, rings); } public static void Ellipsoid(MeshBuilder mb, Vector3 c, Vector3 radii, Quaternion rot, int seg = 12, int rings = 8) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_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_0058: 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) Vector2[] array = (Vector2[])(object)new Vector2[rings + 1]; Vector2[] array2 = (Vector2[])(object)new Vector2[rings + 1]; for (int i = 0; i <= rings; i++) { float num = (float)i / (float)rings * (float)Math.PI; array2[i] = new Vector2(Mathf.Sin(num), 0f - Mathf.Cos(num)); array[i] = array2[i]; } mb.Push(Matrix4x4.TRS(c, rot, radii)); Lathe(mb, array, seg, 1f, 0.5f, array2); mb.Pop(); } public static void Torus(MeshBuilder mb, Vector3 c, Quaternion rot, float majorR, float minorR, int seg, int tubeSeg, float uTiles = 1f, float vPerMeter = 1f) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) Vector2[] array = (Vector2[])(object)new Vector2[tubeSeg + 1]; Vector2[] array2 = (Vector2[])(object)new Vector2[tubeSeg + 1]; for (int i = 0; i <= tubeSeg; i++) { float num = -(float)Math.PI + (float)i * ((float)Math.PI * 2f) / (float)tubeSeg; array2[i] = new Vector2(Mathf.Cos(num), Mathf.Sin(num)); array[i] = new Vector2(majorR, 0f) + array2[i] * minorR; } mb.Push(c, rot); Lathe(mb, array, seg, uTiles, vPerMeter, array2); mb.Pop(); } public static void Box(MeshBuilder mb, Vector3 center, Vector3 size, Quaternion rot, float uvPerMeter = 2f) { //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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: 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_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: 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_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_010c: 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_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) mb.Push(center, rot); Vector3 val = size * 0.5f; int num = ((!(size.x >= size.y) || !(size.x >= size.z)) ? ((size.y >= size.z) ? 1 : 2) : 0); for (int i = 0; i < 3; i++) { for (int j = -1; j <= 1; j += 2) { int num2 = (i + 1) % 3; int num3 = (i + 2) % 3; if (num3 == num) { int num4 = num2; num2 = num3; num3 = num4; } Vector3 val2 = Axis(i) * (float)j; Vector3 val3 = val2 * ((Vector3)(ref val))[i]; Vector3 val4 = Axis(num2) * ((Vector3)(ref val))[num2]; Vector3 val5 = Axis(num3) * ((Vector3)(ref val))[num3]; float num5 = ((Vector3)(ref val))[num2] * uvPerMeter; float num6 = ((Vector3)(ref val))[num3] * uvPerMeter; FlatQuad(mb, val3 - val4 - val5, val3 - val4 + val5, val3 + val4 + val5, val3 + val4 - val5, val2, new Vector2(0f - num5, 0f - num6), new Vector2(0f - num5, num6), new Vector2(num5, num6), new Vector2(num5, 0f - num6)); } } mb.Pop(); } private static Vector3 Axis(int k) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) return (Vector3)(k switch { 1 => Vector3.up, 0 => Vector3.right, _ => Vector3.forward, }); } public static void Disc(MeshBuilder mb, Vector3 c, float r, int seg, float uvRadius = 0.5f, float uvRotDeg = 0f) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown r