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 Church Glass v1.0.0
plugins/ChurchGlass.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.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ChurchGlass.Core; using ChurchGlass.Dev; using ChurchGlass.Gameplay; using ChurchGlass.UI; using ChurchGlass.Visual; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; 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 ChurchGlass { public static class Cfg { public static ConfigEntry<string> StationGlass; public static ConfigEntry<string> StationPanes; public static ConfigEntry<string> StationPictures; public static ConfigEntry<string> MeltBase; public static ConfigEntry<int> MeltYield; public static readonly Dictionary<int, ConfigEntry<string>> Dyes = new Dictionary<int, ConfigEntry<string>>(); public static readonly Dictionary<string, ConfigEntry<string>> PictureRecipes = new Dictionary<string, ConfigEntry<string>>(); public static ConfigEntry<float> PaneHealth; public static ConfigEntry<float> PictureHealth; public static ConfigEntry<bool> SunLight; public static ConfigEntry<bool> ShowPalette; public static ConfigEntry<bool> WheelColor; public static ConfigEntry<float> LightStrength; public static ConfigEntry<float> GlowStrength; public static ConfigEntry<int> LitWindows; public static ConfigEntry<KeyCode> KeyColor; public static ConfigEntry<KeyCode> KeyTurn; public static ConfigEntry<KeyCode> KeyTilt; public static ConfigEntry<KeyCode> KeyRecolor; private static ConfigurationManagerAttributes _admin; 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_0011: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Expected O, but got Unknown //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0275: Expected O, but got Unknown //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_02d2: Expected O, but got Unknown //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Expected O, but got Unknown //IL_032d: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Expected O, but got Unknown _admin = new ConfigurationManagerAttributes { IsAdminOnly = true }; StationGlass = c.Bind<string>("1 - Building", "StationGlass", "forge", new ConfigDescription("Crafting station where coloured glass is melted (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { _admin })); StationPanes = c.Bind<string>("1 - Building", "StationPanes", "piece_stonecutter", new ConfigDescription("Crafting station that has to be near to set glass panes (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { _admin })); StationPictures = c.Bind<string>("1 - Building", "StationPictures", "piece_stonecutter", new ConfigDescription("Crafting station that has to be near to build the picture windows (prefab name, empty for none).", (AcceptableValueBase)null, new object[1] { _admin })); MeltBase = c.Bind<string>("1 - Building", "MeltBase", "Crystal:1,Tin:1", new ConfigDescription("What every melt of coloured glass takes besides its dye, \"Item:amount,Item:amount\".", (AcceptableValueBase)null, new object[1] { _admin })); MeltYield = c.Bind<int>("1 - Building", "MeltYield", 20, new ConfigDescription("Pieces of glass one melt yields. A 1 m square pane takes 4, a 50 cm or 25 cm pane takes 1.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), new object[1] { _admin })); PaneHealth = c.Bind<float>("1 - Building", "PaneHealth", 20f, new ConfigDescription("Health of a glass pane (the vanilla crystal wall has 10).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 1000f), new object[1] { _admin })); PictureHealth = c.Bind<float>("1 - Building", "PictureHealth", 300f, new ConfigDescription("Health of a picture window in its stone frame.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 5000f), new object[1] { _admin })); GlassColor[] all = Palette.All; foreach (GlassColor glassColor in all) { Dyes[glassColor.Id] = c.Bind<string>("2 - Dyes", "Dye_" + glassColor.Key, glassColor.Dye, new ConfigDescription("Dye of one melt of " + glassColor.EnItem.ToLowerInvariant() + ", added to MeltBase (empty for none).", (AcceptableValueBase)null, new object[1] { _admin })); } PictureSpec[] all2 = PictureSpec.All; foreach (PictureSpec pictureSpec in all2) { PictureRecipes[pictureSpec.Key] = c.Bind<string>("3 - Pictures", "Recipe_" + pictureSpec.Key, pictureSpec.DefaultRecipe, new ConfigDescription("Build cost of the picture window \"" + pictureSpec.En + "\", \"Item:amount,Item:amount\".", (AcceptableValueBase)null, new object[1] { _admin })); } SunLight = c.Bind<bool>("4 - Client", "SunLight", true, "The sun and moon shine coloured light through windows onto floors and walls."); LightStrength = c.Bind<float>("4 - Client", "LightStrength", 1f, new ConfigDescription("Brightness of the coloured light that falls through windows.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>())); GlowStrength = c.Bind<float>("4 - Client", "GlowStrength", 1f, new ConfigDescription("How brightly glass glows when daylight is behind it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>())); LitWindows = c.Bind<int>("4 - Client", "LitWindows", 8, new ConfigDescription("At most this many windows near you cast coloured light at the same time (three lights each).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 24), Array.Empty<object>())); ShowPalette = c.Bind<bool>("4 - Client", "ShowPalette", true, "Show the colour palette and the keys while a glass pane is selected in the hammer."); WheelColor = c.Bind<bool>("4 - Client", "WheelColor", true, "Left Alt + mouse wheel chooses the glass colour while placing."); KeyColor = c.Bind<KeyCode>("4 - Client", "KeyColor", (KeyCode)110, "Next glass colour (with Shift: previous)."); KeyTurn = c.Bind<KeyCode>("4 - Client", "KeyTurn", (KeyCode)104, "Turn the pane a quarter within its own plane (with Shift: back)."); KeyTilt = c.Bind<KeyCode>("4 - Client", "KeyTilt", (KeyCode)106, "Tilt the pane: upright, 26°, 45°, flat (with Shift: back)."); KeyRecolor = c.Bind<KeyCode>("4 - Client", "KeyRecolor", (KeyCode)107, "Recolour the pane you look at with the chosen colour (swaps the glass in your inventory)."); } } public static class Items { private const string BasePrefab = "BronzeNails"; private static readonly Dictionary<int, CustomItem> Registered = new Dictionary<int, CustomItem>(); private static readonly Dictionary<int, ItemDrop> Drops = new Dictionary<int, ItemDrop>(); public static void Init() { PrefabManager.OnVanillaPrefabsAvailable += Add; } public static ItemDrop Drop(int colorId) { if (Drops.TryGetValue(colorId, out var value) && (Object)(object)value != (Object)null) { return value; } GameObject val = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.GetItemPrefab(Palette.Get(colorId).ItemPrefab) : null); value = (((Object)(object)val != (Object)null) ? val.GetComponent<ItemDrop>() : null); if ((Object)(object)value != (Object)null) { Drops[colorId] = value; } return value; } private static void Add() { try { Mats.Init(); GlassColor[] all = Palette.All; for (int i = 0; i < all.Length; i++) { AddOne(all[i]); } } catch (Exception ex) { ChurchGlassPlugin.Log.LogError((object)("Could not register the glass items: " + ex)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= Add; } } private static void AddOne(GlassColor c) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0096: 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_00a6: Expected O, but got Unknown //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Expected O, but got Unknown //IL_0161: Unknown result type (might be due to invalid IL or missing references) GameObject val = GlassStack(c); Sprite val2 = (GUIManager.IsHeadless() ? null : IconPainter.Glass(new Color((float)c.R, (float)c.G, (float)c.B))); ItemConfig val3 = new ItemConfig { Name = "$" + c.ItemPrefab, Description = "$sg_glass_desc", CraftingStation = (Cfg.StationGlass.Value ?? "").Trim(), Amount = Math.Max(1, Cfg.MeltYield.Value), Weight = 0.1f, StackSize = 100, Icon = val2 }; foreach (var (text, num) in MeltRecipe(c.Id)) { val3.AddRequirement(new RequirementConfig(text, num, 0, true)); } CustomItem val4 = new CustomItem(c.ItemPrefab, "BronzeNails", val3); if ((Object)(object)val4.ItemPrefab == (Object)null) { Object.Destroy((Object)(object)val); ChurchGlassPlugin.Log.LogError((object)("Cloning BronzeNails for " + c.ItemPrefab + " failed.")); return; } Reskin(val4.ItemPrefab, val); SharedData shared = val4.ItemDrop.m_itemData.m_shared; shared.m_itemType = (ItemType)1; shared.m_maxQuality = 1; shared.m_teleportable = true; shared.m_value = 0; if ((Object)(object)val2 != (Object)null) { shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 }; } ItemManager.Instance.AddItem(val4); Registered[c.Id] = val4; } public static List<(string item, int amount)> MeltRecipe(int colorId) { ConfigEntry<string> value; string text = (Cfg.Dyes.TryGetValue(colorId, out value) ? value.Value : Palette.Get(colorId).Dye); return Palette.Merge(Cfg.MeltBase.Value, text); } public static void ApplyConfig() { //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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_011d: Expected O, but got Unknown if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0) { return; } CraftingStation craftingStation = Pieces.Station(Cfg.StationGlass.Value, "coloured glass"); foreach (KeyValuePair<int, CustomItem> item3 in Registered) { try { CustomRecipe recipe = item3.Value.Recipe; Recipe val = ((recipe != null) ? recipe.Recipe : null); if ((Object)(object)val == (Object)null) { continue; } List<Requirement> list = new List<Requirement>(); foreach (var item4 in MeltRecipe(item3.Key)) { string item = item4.item; int item2 = item4.amount; GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item); ItemDrop val2 = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 == (Object)null) { ChurchGlassPlugin.Log.LogWarning((object)(((Object)item3.Value.ItemPrefab).name + " melt: unknown item '" + item + "'.")); continue; } list.Add(new Requirement { m_resItem = val2, m_amount = item2, m_recover = true }); } if (list.Count > 0) { val.m_resources = list.ToArray(); } val.m_amount = Math.Max(1, Cfg.MeltYield.Value); val.m_craftingStation = craftingStation; } catch (Exception ex) { ChurchGlassPlugin.Log.LogWarning((object)("Could not apply a melt recipe: " + ex.Message)); } } } internal static GameObject GlassStack(GlassColor c) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0066: 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_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("sg_glass_model"); val.SetActive(false); for (int i = 0; i < 3; i++) { GameObject val2 = new GameObject("pane" + i); val2.transform.SetParent(val.transform, false); val2.transform.localPosition = new Vector3(0.012f * (float)i, 0.012f + 0.022f * (float)i, -0.01f * (float)i); val2.transform.localRotation = Quaternion.Euler(90f, 12f * (float)i - 10f, 0f); val2.transform.localScale = Vector3.one * 0.9f; ((Renderer)Pieces.AddMesh(val2, "glass", PaneMesh.Glass(ShapeKind.Square, PaneSize.Small, c.Id), Mats.Shine, Mats.Glow, Mats.Multiply).GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0; Pieces.AddMesh(val2, "lead", PaneMesh.Lead(ShapeKind.Square, PaneSize.Small), Mats.Lead); } return val; } private static void Reskin(GameObject prefab, GameObject visual) { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: 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) 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]); } MeshRenderer component = prefab.GetComponent<MeshRenderer>(); if ((Object)(object)component != (Object)null) { Object.DestroyImmediate((Object)(object)component); } MeshFilter component2 = prefab.GetComponent<MeshFilter>(); if ((Object)(object)component2 != (Object)null) { Object.DestroyImmediate((Object)(object)component2); } ((Object)visual).name = "model"; visual.transform.SetParent(transform, false); visual.transform.localPosition = Vector3.zero; visual.transform.localRotation = Quaternion.identity; visual.SetActive(true); BoxCollider obj = prefab.AddComponent<BoxCollider>(); obj.center = new Vector3(0.012f, 0.04f, -0.01f); obj.size = new Vector3(0.3f, 0.09f, 0.3f); Pieces.SetLayer(visual, prefab.layer); } } public static class Lang { private static readonly (string key, string en, string de)[] Texts = new(string, string, string)[43] { ("jotunn_cat_churchglass", "Church glass", "Kirchenglas"), ("jotunn_cat_churchglasspictures", "Glass pictures", "Glasbilder"), ("sg_size_100", "1 m", "1 m"), ("sg_size_50", "50 cm", "50 cm"), ("sg_size_25", "25 cm", "25 cm"), ("sg_shape_square", "Square", "Quadrat"), ("sg_shape_square_desc", "A square pane in its lead. Choose the glass colour while placing; it costs glass of that colour.", "Eine quadratische Scheibe in ihrer Bleifassung. Die Glasfarbe wählst du beim Setzen; sie kostet Glas dieser Farbe."), ("sg_shape_strip", "Strip", "Streifen"), ("sg_shape_strip_desc", "Half a square, long and narrow. Turn it a quarter for an upright strip.", "Ein halbes Quadrat, lang und schmal. Eine Vierteldrehung macht einen stehenden Streifen daraus."), ("sg_shape_lath", "Border", "Leiste"), ("sg_shape_lath_desc", "A quarter of a square: for borders and bands around a picture.", "Ein Viertel Quadrat: für Ränder und Bänder um ein Bild."), ("sg_shape_triangle", "Triangle", "Dreieck"), ("sg_shape_triangle_desc", "Half a square, cut corner to corner. Two of them, one turned half round, fill the square.", "Ein halbes Quadrat, von Ecke zu Ecke geteilt. Zwei davon, eines halb gedreht, füllen das Quadrat."), ("sg_shape_gable", "Gable", "Spitze"), ("sg_shape_gable_desc", "A tall triangle on the full width. The two wedges fill its square.", "Ein hohes Dreieck über die volle Breite. Die beiden Keile füllen sein Quadrat."), ("sg_shape_lowgable", "Low gable", "Flache Spitze"), ("sg_shape_lowgable_desc", "A low triangle, half as high as wide. Two small triangles fill its strip.", "Ein flaches Dreieck, halb so hoch wie breit. Zwei kleine Dreiecke füllen seinen Streifen."), ("sg_shape_wedge", "Wedge", "Keil"), ("sg_shape_wedge_desc", "What a gable leaves of its square on one side. Turn it round (mouse wheel) for the other side.", "Was eine Spitze auf einer Seite von ihrem Quadrat übrig lässt. Umgedreht (Mausrad) passt er auf die andere Seite."), ("sg_shape_diamond", "Diamond", "Raute"), ("sg_shape_diamond_desc", "A square on its tip. Four small triangles fill its corners.", "Ein Quadrat auf der Spitze. Vier kleine Dreiecke füllen seine Ecken."), ("sg_shape_circle", "Circle", "Kreis"), ("sg_shape_circle_desc", "A round pane. Four spandrels of the next smaller size fill its corners.", "Eine runde Scheibe. Vier Zwickel der nächstkleineren Größe füllen ihre Ecken."), ("sg_shape_halfcircle", "Half circle", "Halbkreis"), ("sg_shape_halfcircle_desc", "Half a round pane, for the tops of arched lights.", "Eine halbe runde Scheibe, für die Bögen von Rundfenstern."), ("sg_shape_quarter", "Quarter circle", "Viertelkreis"), ("sg_shape_quarter_desc", "A quarter disc. With a spandrel of the same size it fills a square.", "Eine Viertelscheibe. Mit einem gleich großen Zwickel füllt sie ein Quadrat."), ("sg_shape_spandrel", "Spandrel", "Zwickel"), ("sg_shape_spandrel_desc", "The corner a round pane leaves free.", "Die Ecke, die eine runde Scheibe frei lässt."), ("sg_shape_roundarch", "Round arch", "Rundbogen"), ("sg_shape_roundarch_desc", "A square with a round top, the head of a round-arched light.", "Ein Quadrat mit rundem Abschluss, der Kopf eines Rundbogenfensters."), ("sg_shape_lancet", "Pointed arch", "Spitzbogen"), ("sg_shape_lancet_desc", "The pointed head of a gothic light, as high as wide. Two arch spandrels fill its square.", "Der spitze Kopf eines gotischen Fensters, so hoch wie breit. Zwei Bogenzwickel füllen sein Quadrat."), ("sg_shape_archspandrel", "Arch spandrel", "Bogenzwickel"), ("sg_shape_archspandrel_desc", "What a pointed arch leaves of its square on one side. Turn it round for the other side.", "Was ein Spitzbogen auf einer Seite von seinem Quadrat übrig lässt. Umgedreht passt er auf die andere Seite."), ("sg_glass_desc", "Coloured glass, melted from crystal with a dye and cast thin. Cut into panes with the hammer.", "Farbiges Glas, aus Kristall mit einem Farbstoff geschmolzen und dünn gegossen. Mit dem Hammer zu Scheiben geschnitten."), ("sg_msg_samecolor", "This pane already has that colour.", "Diese Scheibe hat schon diese Farbe."), ("sg_msg_noglass", "You need {0}.", "Dir fehlt {0}."), ("sg_msg_recolored", "New glass: {0}", "Neues Glas: {0}"), ("sg_hud_turned", "turned {0}°", "gedreht {0}°"), ("sg_hud_tilted", "tilted {0}°", "geneigt {0}°"), ("sg_hud_key_wheel", "Alt + wheel", "Alt + Mausrad"), ("sg_hud_keys", "[{0}] colour [{1}] turn [{2}] tilt [{3}] recolour [Shift] back", "[{0}] Farbe [{1}] drehen [{2}] neigen [{3}] umfärben [Umschalt] zurück") }; 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; } GlassColor[] all = Palette.All; foreach (GlassColor glassColor in all) { dictionary["sg_color_" + glassColor.Key] = glassColor.En; dictionary2["sg_color_" + glassColor.Key] = glassColor.De; dictionary[glassColor.ItemPrefab] = glassColor.EnItem; dictionary2[glassColor.ItemPrefab] = glassColor.DeItem; } PictureSpec[] all2 = PictureSpec.All; foreach (PictureSpec pictureSpec in all2) { dictionary[pictureSpec.Prefab] = pictureSpec.En; dictionary2[pictureSpec.Prefab] = pictureSpec.De; dictionary[pictureSpec.Prefab + "_desc"] = pictureSpec.DescEn; dictionary2[pictureSpec.Prefab + "_desc"] = pictureSpec.DescDe; } 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 string L(string token) { if (Localization.instance == null) { return token; } return Localization.instance.Localize(token); } } public static class Pictures { private sealed class Data { public PictureSpec Spec; public Texture2D Texture; public Material Multiply; public Material Glow; public List<List<V2>> Lead; public PlaneGrid Grid; } private const string BasePrefab = "crystal_wall_1x1"; private const float LeadHalf = 0.011f; private static readonly Dictionary<string, Data> ByKey = new Dictionary<string, Data>(); public static PictureSpec SpecOf(string key) { if (!ByKey.TryGetValue(key ?? "", out var value)) { return PictureSpec.All[0]; } return value.Spec; } public static PlaneGrid GridOf(string key) { if (!ByKey.TryGetValue(key ?? "", out var value)) { return null; } if (value.Grid == null) { value.Grid = BuildGrid(value); } return value.Grid; } public static Material BaseGlow(string key) { if (!ByKey.TryGetValue(key ?? "", out var value)) { return Mats.Glow; } return value.Glow; } public static Material NewGlow(string key) { //IL_0030: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown Data value; Material val = (ByKey.TryGetValue(key ?? "", out value) ? value.Glow : Mats.Glow); if (!((Object)(object)val == (Object)null)) { return new Material(val) { name = "SG_PictureGlow_" + key, hideFlags = (HideFlags)32 }; } return null; } public static GameObject Register(PictureSpec spec) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Expected O, but got Unknown //IL_0119: 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_0134: 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_0148: Expected O, but got Unknown //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Expected O, but got Unknown //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: 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_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Expected O, but got Unknown //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Expected O, but got Unknown //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Expected O, but got Unknown //IL_037b: Unknown result type (might be due to invalid IL or missing references) string path = ChurchGlassPlugin.AssetPath(spec.Texture); string path2 = ChurchGlassPlugin.AssetPath(spec.LeadFile); if (!File.Exists(path) || !File.Exists(path2)) { ChurchGlassPlugin.Log.LogWarning((object)("Picture '" + spec.Key + "' left out: " + spec.Texture + " or " + spec.LeadFile + " missing.")); return null; } Data data = new Data { Spec = spec, Lead = PictureSpec.ReadLead(path2) }; Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true) { name = "SG_Picture_" + spec.Key }; if (!AssetUtils.LoadImage(val, File.ReadAllBytes(path))) { ChurchGlassPlugin.Log.LogWarning((object)("Picture '" + spec.Key + "': texture could not be read.")); return null; } ((Texture)val).wrapMode = (TextureWrapMode)1; ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).anisoLevel = 4; ((Object)val).hideFlags = (HideFlags)32; data.Texture = val; if ((Object)(object)Mats.Multiply != (Object)null) { data.Multiply = new Material(Mats.Multiply) { name = "SG_PictureMultiply_" + spec.Key, mainTexture = (Texture)(object)val, hideFlags = (HideFlags)32 }; } if ((Object)(object)Mats.Glow != (Object)null) { data.Glow = new Material(Mats.Glow) { name = "SG_PictureGlow_" + spec.Key, mainTexture = (Texture)(object)val, hideFlags = (HideFlags)32 }; } ByKey[spec.Key] = data; GameObject val2 = Model(data); Sprite icon = (GUIManager.IsHeadless() ? null : IconPainter.Picture(spec, val)); PieceConfig val3 = new PieceConfig { Name = "$" + spec.Prefab, Description = "$" + spec.Prefab + "_desc", PieceTable = "Hammer", Category = "ChurchGlassPictures", CraftingStation = (Cfg.StationPictures.Value ?? "").Trim(), Icon = icon }; foreach (var (text, num) in Palette.Merge(Recipe(spec))) { val3.AddRequirement(new RequirementConfig(text, num, 0, true)); } CustomPiece val4 = new CustomPiece(spec.Prefab, "crystal_wall_1x1", val3); if ((Object)(object)val4.PiecePrefab == (Object)null) { ChurchGlassPlugin.Log.LogError((object)("Cloning crystal_wall_1x1 failed; no " + spec.Prefab + ".")); Object.Destroy((Object)(object)val2); return null; } GameObject piecePrefab = val4.PiecePrefab; Pieces.Strip(piecePrefab); val2.transform.SetParent(piecePrefab.transform, false); val2.SetActive(true); Pieces.SetLayer(val2, piecePrefab.layer); MeshCollider obj = piecePrefab.AddComponent<MeshCollider>(); obj.sharedMesh = PaneMesh.Prism(spec.FrameOutline(), 0.1f, "SG_PictureCol_" + spec.Key); obj.convex = true; Pieces.AddSnapPoints(piecePrefab, SnapPoints(spec)); Pieces.SetupWear(piecePrefab, val2, Cfg.PictureHealth.Value); WearNTear component = piecePrefab.GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_materialType = (MaterialType)1; } Piece component2 = piecePrefab.GetComponent<Piece>(); component2.m_canRotate = true; component2.m_allowRotatedOverlap = false; component2.m_groundOnly = false; component2.m_allowedInDungeons = false; if (string.IsNullOrWhiteSpace(Cfg.StationPictures.Value)) { component2.m_craftingStation = null; } piecePrefab.AddComponent<GlassPicture>().Key = spec.Key; PieceManager.Instance.AddPiece(val4); return piecePrefab; } private static string Recipe(PictureSpec spec) { if (!Cfg.PictureRecipes.TryGetValue(spec.Key, out var value) || string.IsNullOrWhiteSpace(value.Value)) { return spec.DefaultRecipe; } return value.Value; } public static void ApplyConfig(Dictionary<string, GameObject> prefabs) { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_010a: 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_011e: Expected O, but got Unknown CraftingStation craftingStation = Pieces.Station(Cfg.StationPictures.Value, "picture windows"); foreach (KeyValuePair<string, GameObject> prefab in prefabs) { Piece component = prefab.Value.GetComponent<Piece>(); component.m_craftingStation = craftingStation; WearNTear component2 = prefab.Value.GetComponent<WearNTear>(); if ((Object)(object)component2 != (Object)null) { component2.m_health = Cfg.PictureHealth.Value; } List<Requirement> list = new List<Requirement>(); foreach (var item3 in Palette.Merge(Recipe(SpecOf(prefab.Key)))) { string item = item3.item; int item2 = item3.amount; GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item); ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { ChurchGlassPlugin.Log.LogWarning((object)(((Object)prefab.Value).name + " recipe: unknown item '" + item + "'.")); continue; } list.Add(new Requirement { m_resItem = val, m_amount = item2, m_recover = true }); } if (list.Count > 0) { component.m_resources = list.ToArray(); } } } private static IEnumerable<V2> SnapPoints(PictureSpec s) { double num = s.Width / 2.0; double num2 = s.Height / 2.0; List<V2> list = new List<V2>(); for (double num3 = 0.0 - num; num3 <= num + 1E-06; num3 += 0.5) { list.Add(new V2(num3, 0.0 - num2)); } for (double num4 = 0.0 - num2 + 0.5; num4 <= num2 + 1E-06; num4 += 0.5) { list.Add(new V2(0.0 - num, num4)); list.Add(new V2(num, num4)); } list.Add(new V2(0.0, num2)); return list; } private static GameObject Model(Data d) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown PictureSpec s = d.Spec; GameObject val = new GameObject("visual"); val.SetActive(false); List<V2> list = s.GlassOutline(); List<int> tris = Poly.Triangulate(list); Func<V2, Vector2> uv = (V2 p) => new Vector2((float)(p.X / s.GlassWidth + 0.5), (float)(p.Y / s.GlassHeight + 0.5)); Mesh mesh = PaneMesh.BuildGlass(list, tris, (V2 _) => Color.white, "SG_PictureGlass_" + s.Key, uv); MeshRenderer component = Pieces.AddMesh(val, "glass", mesh, Mats.Shine, d.Glow, d.Multiply).GetComponent<MeshRenderer>(); ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component).receiveShadows = false; ((Renderer)Pieces.AddMesh(val, "shadow", PaneMesh.BuildShadow(list, tris, "SG_PictureShadow_" + s.Key), Mats.Lead).GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)3; Pieces.AddMesh(val, "lead", LeadLines(d.Lead, list, "SG_PictureLead_" + s.Key), Mats.Lead); Pieces.AddMesh(val, "frame", Ring(s.FrameOutline(), list, 0.1f, "SG_PictureFrame_" + s.Key), Mats.Frame); return val; } private static Mesh LeadLines(List<List<V2>> lines, List<V2> outline, string name) { //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Expected O, but got Unknown //IL_00e4: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = new MeshBuilder(); float num = 0.008f; foreach (List<V2> line in lines) { for (int i = 0; i + 1 < line.Count; i++) { V2 v = line[i]; V2 v2 = line[i + 1]; V2 normalized = (v2 - v).Normalized; if (!(normalized.Length < 0.5)) { v -= normalized * 0.010999999940395355; v2 += normalized * 0.010999999940395355; V2 v3 = normalized.Left * 0.010999999940395355; V2 p = v - v3; V2 p2 = v + v3; V2 p3 = v2 - v3; V2 p4 = v2 + v3; meshBuilder.Quad(PaneMesh.V(p, num), PaneMesh.V(p3, num), PaneMesh.V(p4, num), PaneMesh.V(p2, num), Vector3.forward); meshBuilder.Quad(PaneMesh.V(p, 0f - num), PaneMesh.V(p3, 0f - num), PaneMesh.V(p4, 0f - num), PaneMesh.V(p2, 0f - num), Vector3.back); Vector3 val = PaneMesh.V(normalized.Left); meshBuilder.Quad(PaneMesh.V(p2, num), PaneMesh.V(p4, num), PaneMesh.V(p4, 0f - num), PaneMesh.V(p2, 0f - num), val); meshBuilder.Quad(PaneMesh.V(p, num), PaneMesh.V(p3, num), PaneMesh.V(p3, 0f - num), PaneMesh.V(p, 0f - num), -val); } } } Mesh val2 = meshBuilder.ToMesh(name); Mesh val3 = PaneMesh.BuildLead(outline, 0.022f, num, name + "_rim"); CombineInstance[] array = new CombineInstance[2]; CombineInstance val4 = default(CombineInstance); ((CombineInstance)(ref val4)).mesh = val2; ((CombineInstance)(ref val4)).transform = Matrix4x4.identity; array[0] = val4; val4 = default(CombineInstance); ((CombineInstance)(ref val4)).mesh = val3; ((CombineInstance)(ref val4)).transform = Matrix4x4.identity; array[1] = val4; CombineInstance[] array2 = (CombineInstance[])(object)array; Mesh val5 = new Mesh { name = name, indexFormat = (IndexFormat)1 }; val5.CombineMeshes(array2, true, true); Object.Destroy((Object)(object)val2); Object.Destroy((Object)(object)val3); return val5; } private static Mesh Ring(List<V2> outer, List<V2> inner, float depth, string name) { //IL_0031: 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_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_0071: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0083: 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_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_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_009c: 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 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: 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_00cb: 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_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011c: 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_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0130: 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_0139: 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_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = new MeshBuilder(); int num = Math.Min(outer.Count, inner.Count); for (int i = 0; i < num; i++) { int index = (i + 1) % num; Vector3 val = PaneMesh.V(outer[i]); Vector3 val2 = PaneMesh.V(outer[index]); Vector3 val3 = PaneMesh.V(inner[i]); Vector3 val4 = PaneMesh.V(inner[index]); Vector3 val5 = Vector3.forward * depth; meshBuilder.Quad(val + val5, val2 + val5, val4 + val5, val3 + val5, Vector3.forward); meshBuilder.Quad(val - val5, val2 - val5, val4 - val5, val3 - val5, Vector3.back); Vector3 normal = PaneMesh.V((outer[index] - outer[i]).Normalized.Left * -1.0); meshBuilder.Quad(val + val5, val2 + val5, val2 - val5, val - val5, normal); Vector3 normal2 = PaneMesh.V((inner[index] - inner[i]).Normalized.Left); meshBuilder.Quad(val3 + val5, val4 + val5, val4 - val5, val3 - val5, normal2); } return meshBuilder.ToMesh(name); } private static PlaneGrid BuildGrid(Data d) { //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_037a: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) PictureSpec spec = d.Spec; List<V2> p = spec.GlassOutline(); double num = Math.Max(spec.GlassWidth, spec.GlassHeight) / 200.0; PlaneGrid planeGrid = new PlaneGrid { Cell = num, MinU = (0.0 - spec.GlassWidth) / 2.0, MinV = (0.0 - spec.GlassHeight) / 2.0, W = (int)Math.Ceiling(spec.GlassWidth / num), H = (int)Math.Ceiling(spec.GlassHeight / num) }; planeGrid.R = new float[planeGrid.W * planeGrid.H]; planeGrid.G = new float[planeGrid.W * planeGrid.H]; planeGrid.B = new float[planeGrid.W * planeGrid.H]; Color[] array = null; try { array = d.Texture.GetPixels(); } catch (Exception ex) { ChurchGlassPlugin.Log.LogWarning((object)("Picture '" + spec.Key + "': texture not readable for light (" + ex.Message + ").")); } int width = ((Texture)d.Texture).width; int height = ((Texture)d.Texture).height; bool[] array2 = new bool[planeGrid.W * planeGrid.H]; foreach (List<V2> item in d.Lead) { for (int i = 0; i + 1 < item.Count; i++) { V2 v = item[i]; V2 v2 = item[i + 1]; double length = (v2 - v).Length; int num2 = Math.Max(1, (int)Math.Ceiling(length / (num * 0.5))); for (int j = 0; j <= num2; j++) { V2 v3 = v + (v2 - v) * ((double)j / (double)num2); int num3 = (int)((v3.X - planeGrid.MinU) / num); int num4 = (int)((v3.Y - planeGrid.MinV) / num); if (num3 >= 0 && num4 >= 0 && num3 < planeGrid.W && num4 < planeGrid.H) { array2[num4 * planeGrid.W + num3] = true; } } } } for (int k = 0; k < planeGrid.H; k++) { for (int l = 0; l < planeGrid.W; l++) { V2 q = new V2(planeGrid.MinU + ((double)l + 0.5) * num, planeGrid.MinV + ((double)k + 0.5) * num); int num5 = k * planeGrid.W + l; if (!array2[num5] && Poly.Contains(p, q)) { if (array == null) { planeGrid.R[num5] = (planeGrid.G[num5] = (planeGrid.B[num5] = 0.5f)); continue; } int num6 = Mathf.Clamp((int)((q.X / spec.GlassWidth + 0.5) * (double)width), 0, width - 1); int num7 = Mathf.Clamp((int)((q.Y / spec.GlassHeight + 0.5) * (double)height), 0, height - 1); Color val = array[num7 * width + num6]; planeGrid.R[num5] = (float)Palette.ToLinear(val.r); planeGrid.G[num5] = (float)Palette.ToLinear(val.g); planeGrid.B[num5] = (float)Palette.ToLinear(val.b); } } } return planeGrid; } } public static class Pieces { [HarmonyPatch(typeof(Game), "Start")] private static class ApplyOnWorldStart { private static void Postfix() { ApplyConfig(); } } private const string BasePrefab = "crystal_wall_1x1"; public const string PaneCategory = "ChurchGlass"; public const string PictureCategory = "ChurchGlassPictures"; private static readonly Dictionary<(ShapeKind, PaneSize), GameObject> PanePrefabs = new Dictionary<(ShapeKind, PaneSize), GameObject>(); private static readonly Dictionary<string, GameObject> PicturePrefabs = new Dictionary<string, GameObject>(); private static readonly Dictionary<(ShapeKind, PaneSize, int), Requirement[]> CostCache = new Dictionary<(ShapeKind, PaneSize, int), Requirement[]>(); private static readonly int[] IconColors = new int[15] { 16, 4, 9, 12, 18, 8, 14, 6, 15, 7, 19, 13, 17, 5, 10 }; public static IEnumerable<GameObject> AllPanes => PanePrefabs.Values; public static void Init() { PrefabManager.OnVanillaPrefabsAvailable += Add; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplyConfig(); }; Cfg.StationGlass.SettingChanged += delegate { ApplyConfig(); }; Cfg.StationPanes.SettingChanged += delegate { ApplyConfig(); }; Cfg.StationPictures.SettingChanged += delegate { ApplyConfig(); }; Cfg.MeltBase.SettingChanged += delegate { ApplyConfig(); }; Cfg.MeltYield.SettingChanged += delegate { ApplyConfig(); }; Cfg.PaneHealth.SettingChanged += delegate { ApplyConfig(); }; Cfg.PictureHealth.SettingChanged += delegate { ApplyConfig(); }; foreach (ConfigEntry<string> value in Cfg.Dyes.Values) { value.SettingChanged += delegate { ApplyConfig(); }; } foreach (ConfigEntry<string> value2 in Cfg.PictureRecipes.Values) { value2.SettingChanged += delegate { ApplyConfig(); }; } } public static void ApplyConfig() { if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0) { return; } try { Items.ApplyConfig(); CraftingStation craftingStation = Station(Cfg.StationPanes.Value, "glass panes"); foreach (GameObject value in PanePrefabs.Values) { value.GetComponent<Piece>().m_craftingStation = craftingStation; WearNTear component = value.GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { component.m_health = Cfg.PaneHealth.Value; } } ApplyPaneCosts(); Pictures.ApplyConfig(PicturePrefabs); } catch (Exception ex) { ChurchGlassPlugin.Log.LogWarning((object)("Could not apply the building config: " + ex.Message)); } if ((Object)(object)Player.m_localPlayer != (Object)null) { Player.m_localPlayer.UpdateAvailablePiecesList(); } } public static void ApplyPaneCosts() { foreach (KeyValuePair<(ShapeKind, PaneSize), GameObject> panePrefab in PanePrefabs) { Requirement[] array = PaneCost(panePrefab.Key.Item1, panePrefab.Key.Item2, Selection.Color); if (array != null) { panePrefab.Value.GetComponent<Piece>().m_resources = array; } } } public static Requirement[] PaneCost(ShapeKind k, PaneSize s, int colorId) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_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_0053: Expected O, but got Unknown if (CostCache.TryGetValue((k, s, colorId), out var value)) { return value; } ItemDrop val = Items.Drop(colorId); if ((Object)(object)val == (Object)null) { return null; } value = (Requirement[])(object)new Requirement[1] { new Requirement { m_resItem = val, m_amount = Shapes.Cost(k, s), m_recover = true } }; CostCache[(k, s, colorId)] = value; return value; } public static CraftingStation Station(string name, string what) { name = (name ?? "").Trim(); if (name.Length == 0) { return null; } object obj; if (!((Object)(object)ZNetScene.instance != (Object)null)) { obj = null; } else { GameObject prefab = ZNetScene.instance.GetPrefab(name); obj = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null); } CraftingStation val = (CraftingStation)obj; if ((Object)(object)val == (Object)null && PrefabManager.Instance != null) { GameObject prefab2 = PrefabManager.Instance.GetPrefab(name); val = ((prefab2 != null) ? prefab2.GetComponent<CraftingStation>() : null); } if ((Object)(object)val == (Object)null) { ChurchGlassPlugin.Log.LogWarning((object)("Unknown crafting station '" + name + "' for " + what + ".")); } return val; } private static void Add() { try { Mats.Init(); PaneSize[] sizes = Shapes.Sizes; foreach (PaneSize s in sizes) { ShapeKind[] all = Shapes.All; for (int j = 0; j < all.Length; j++) { AddPane(all[j], s); } } PictureSpec[] all2 = PictureSpec.All; for (int i = 0; i < all2.Length; i++) { AddPicture(all2[i]); } } catch (Exception ex) { ChurchGlassPlugin.Log.LogError((object)("Could not register the glass pieces: " + ex)); } finally { PrefabManager.OnVanillaPrefabsAvailable -= Add; } } private static void AddPane(ShapeKind k, PaneSize s) { //IL_0048: 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_005b: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown string text = Shapes.PrefabName(k, s); GameObject val = PaneModel(k, s); GlassColor glassColor = Palette.Get(IconColors[(int)k % IconColors.Length]); Sprite icon = (GUIManager.IsHeadless() ? null : IconPainter.Pane(Shapes.Get(k, s), new Color((float)glassColor.R, (float)glassColor.G, (float)glassColor.B))); PieceConfig val2 = new PieceConfig(); string text2 = k.ToString().ToLowerInvariant(); int num = (int)s; val2.Name = "$sg_shape_" + text2 + " $sg_size_" + num; val2.Description = "$sg_shape_" + k.ToString().ToLowerInvariant() + "_desc"; val2.PieceTable = "Hammer"; val2.Category = "ChurchGlass"; val2.CraftingStation = (Cfg.StationPanes.Value ?? "").Trim(); val2.Icon = icon; PieceConfig val3 = val2; val3.AddRequirement(new RequirementConfig(Palette.Get(0).ItemPrefab, Shapes.Cost(k, s), 0, true)); CustomPiece val4 = new CustomPiece(text, "crystal_wall_1x1", val3); if ((Object)(object)val4.PiecePrefab == (Object)null) { ChurchGlassPlugin.Log.LogError((object)("Cloning crystal_wall_1x1 failed; no " + text + ".")); Object.Destroy((Object)(object)val); return; } GameObject piecePrefab = val4.PiecePrefab; Strip(piecePrefab); val.transform.SetParent(piecePrefab.transform, false); val.SetActive(true); SetLayer(val, piecePrefab.layer); Mesh[] array = PaneMesh.Colliders(k, s); foreach (Mesh sharedMesh in array) { MeshCollider obj = piecePrefab.AddComponent<MeshCollider>(); obj.sharedMesh = sharedMesh; obj.convex = true; } AddSnapPoints(piecePrefab, Shapes.Get(k, s).SnapPoints); SetupWear(piecePrefab, val, Cfg.PaneHealth.Value); Piece component = piecePrefab.GetComponent<Piece>(); component.m_canRotate = true; component.m_allowRotatedOverlap = true; component.m_groundOnly = false; component.m_groundPiece = false; component.m_allowedInDungeons = false; component.m_noClipping = false; if (string.IsNullOrWhiteSpace(Cfg.StationPanes.Value)) { component.m_craftingStation = null; } GlassPane glassPane = piecePrefab.AddComponent<GlassPane>(); glassPane.Kind = k; glassPane.Size = s; PieceManager.Instance.AddPiece(val4); PanePrefabs[(k, s)] = piecePrefab; } private static GameObject PaneModel(ShapeKind k, PaneSize s) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected O, but got Unknown GameObject val = new GameObject("visual"); val.SetActive(false); GameObject obj = AddMesh(val, "glass", PaneMesh.Glass(k, s, 0), Mats.Shine, Mats.Glow, Mats.Multiply); ((Renderer)obj.GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)obj.GetComponent<MeshRenderer>()).receiveShadows = false; AddMesh(val, "lead", PaneMesh.Lead(k, s), Mats.Lead); ((Renderer)AddMesh(val, "shadow", PaneMesh.Shadow(k, s), Mats.Lead).GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)3; return val; } internal static GameObject AddMesh(GameObject parent, string name, Mesh mesh, params Material[] mats) { //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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown GameObject val = new GameObject(name); val.transform.SetParent(parent.transform, false); val.AddComponent<MeshFilter>().sharedMesh = mesh; ((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterials = mats; return val; } internal static void Strip(GameObject prefab) { 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]); } } internal static void AddSnapPoints(GameObject prefab, IEnumerable<V2> points, float z = 0f) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) foreach (V2 point in points) { GameObject val = new GameObject("$hud_snappoint_edge") { tag = "snappoint" }; val.transform.SetParent(prefab.transform, false); val.transform.localPosition = PaneMesh.V(point, z); val.SetActive(false); } } internal static void SetupWear(GameObject prefab, GameObject visual, float health) { 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 = health; component.m_noRoofWear = true; component.m_noSupportWear = false; component.m_supports = false; component.m_fragmentRoots = null; } } internal 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); } } private static void AddPicture(PictureSpec spec) { GameObject val = Pictures.Register(spec); if ((Object)(object)val != (Object)null) { PicturePrefabs[spec.Key] = val; } } } [BepInPlugin("zap.churchglass", "ChurchGlass", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class ChurchGlassPlugin : BaseUnityPlugin { public const string PluginGuid = "zap.churchglass"; public const string PluginName = "ChurchGlass"; public const string PluginVersion = "1.0.0"; private Harmony _harmony; public static ChurchGlassPlugin 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(); Items.Init(); Pieces.Init(); _harmony = new Harmony("zap.churchglass"); _harmony.PatchAll(typeof(ChurchGlassPlugin).Assembly); SunGlass.Ensure(); PaletteHud.Ensure(); SelfTest.TryStart(((Component)this).gameObject); } private void Update() { Selection.Update(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } } namespace ChurchGlass.Visual { internal static class IconPainter { private struct Shape { public List<V2> Outline; public Color Color; } private const int Size = 64; private static readonly Color LeadColor = new Color(0.13f, 0.13f, 0.14f, 1f); private static readonly Color FrameColor = new Color(0.62f, 0.56f, 0.46f, 0.55f); public static Sprite Pane(ShapeGeom g, Color c) { //IL_002d: 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) List<V2> outline = Shapes.Get(ShapeKind.Square, PaneSize.Large).Outline; return Paint(new Shape[1] { new Shape { Outline = g.Outline, Color = c } }, 1.12, 0.035, outline, "SG_IconPane"); } public static Sprite Glass(Color c) { //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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_0123: Unknown result type (might be due to invalid IL or missing references) List<Shape> list = new List<Shape>(); List<V2> outline = Shapes.Get(ShapeKind.Square, PaneSize.Medium).Outline; for (int i = 0; i < 3; i++) { double num = (double)(-18 + 16 * i) * Math.PI / 180.0; double num2 = Math.Cos(num); double num3 = Math.Sin(num); List<V2> list2 = new List<V2>(); foreach (V2 item in outline) { list2.Add(new V2(item.X * num2 - item.Y * num3 - 0.16 + 0.15 * (double)i, item.X * num3 + item.Y * num2 + 0.12 - 0.12 * (double)i)); } float num4 = 0.82f + 0.09f * (float)i; list.Add(new Shape { Outline = list2, Color = new Color(c.r * num4, c.g * num4, c.b * num4, 1f) }); } return Paint(list, 1.05, 0.04, null, "SG_IconGlass"); } private static Sprite Paint(IList<Shape> shapes, double span, double lead, List<V2> frame, string name) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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_0093: 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 result type (might be due to invalid IL or missing references) Color[] array = (Color[])(object)new Color[4096]; for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { Color val = Color.clear; for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { V2 p = new V2((((double)j + ((double)l + 0.5) / 2.0) / 64.0 - 0.5) * span, (((double)i + ((double)k + 0.5) / 2.0) / 64.0 - 0.5) * span); val += Sample(shapes, p, lead, frame); } } array[i * 64 + j] = val / 4f; } } return ToSprite(array, name); } private static Color Sample(IList<Shape> shapes, V2 p, double lead, List<V2> frame) { //IL_00e4: 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_0090: 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_00b8: 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_00de: Unknown result type (might be due to invalid IL or missing references) for (int num = shapes.Count - 1; num >= 0; num--) { Shape shape = shapes[num]; if (Poly.Contains(shape.Outline, p)) { if (Poly.EdgeDistance(shape.Outline, p) < lead) { return LeadColor; } float num2 = 0.88f + 0.22f * (float)Math.Max(-0.5, Math.Min(0.5, (p.Y - p.X) * 0.6)); return new Color(Mathf.Clamp01(shape.Color.r * num2), Mathf.Clamp01(shape.Color.g * num2), Mathf.Clamp01(shape.Color.b * num2), 1f); } } if (frame != null && Poly.EdgeDistance(frame, p) < 0.012) { return FrameColor; } return Color.clear; } public static Sprite Picture(PictureSpec spec, Texture2D tex) { //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_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) List<V2> p = spec.GlassOutline(); List<V2> p2 = spec.FrameOutline(); double num = Math.Max(spec.Width, spec.Height) * 1.04; Color[] array = (Color[])(object)new Color[4096]; Color val = default(Color); ((Color)(ref val))..ctor(0.6f, 0.6f, 0.62f, 1f); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { V2 q = new V2((((double)j + 0.5) / 64.0 - 0.5) * num, (((double)i + 0.5) / 64.0 - 0.5) * num); if (Poly.Contains(p, q)) { float num2 = (float)(q.X / spec.GlassWidth + 0.5); float num3 = (float)(q.Y / spec.GlassHeight + 0.5); Color pixelBilinear = tex.GetPixelBilinear(num2, num3); array[i * 64 + j] = new Color(Mathf.Clamp01(pixelBilinear.r * 1.25f), Mathf.Clamp01(pixelBilinear.g * 1.25f), Mathf.Clamp01(pixelBilinear.b * 1.25f), 1f); } else if (Poly.Contains(p2, q)) { array[i * 64 + j] = val; } else { array[i * 64 + j] = Color.clear; } } } return ToSprite(array, "SG_IconPicture_" + spec.Key); } private static Sprite ToSprite(Color[] px, string name) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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_0049: 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_0067: Expected O, but got Unknown Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false) { name = name, filterMode = (FilterMode)1, wrapMode = (TextureWrapMode)1, hideFlags = (HideFlags)32 }; val.SetPixels(px); val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 100f); } } internal static class Mats { public static Material Multiply; public static Material Glow; public static Material Shine; public static Material Lead; public static Material Frame; public static Texture2D GlassTex; private static readonly int TintColor = Shader.PropertyToID("_TintColor"); private static readonly int InvFade = Shader.PropertyToID("_InvFade"); private static readonly int Glossiness = Shader.PropertyToID("_Glossiness"); private static readonly int Metallic = Shader.PropertyToID("_Metallic"); private static readonly int MainTex = Shader.PropertyToID("_MainTex"); private static readonly int BumpScale = Shader.PropertyToID("_BumpScale"); private static readonly int ValueNoise = Shader.PropertyToID("_ValueNoise"); private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); public static readonly Color DefaultGlow = new Color(0.22f, 0.22f, 0.22f, 1f); public static bool Ready { get; private set; } public static void Init() { //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Expected O, but got Unknown //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_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Expected O, but got Unknown //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Expected O, but got Unknown //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_029b: Unknown result type (might be due to invalid IL or missing references) //IL_02a0: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Expected O, but got Unknown //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_0290: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) if (Ready) { return; } try { if ((Object)(object)GlassTex == (Object)null) { GlassTex = MakeGlassTexture(); } Shader[] source = Resources.FindObjectsOfTypeAll<Shader>(); Shader val = ((IEnumerable<Shader>)source).FirstOrDefault((Func<Shader, bool>)((Shader s) => ((Object)s).name == "Legacy Shaders/Particles/Multiply")); Shader val2 = ((IEnumerable<Shader>)source).FirstOrDefault((Func<Shader, bool>)((Shader s) => ((Object)s).name == "Legacy Shaders/Particles/Additive")); Material val3 = FindMat("crystal_wall_1x1", "crystal_window"); Material val4 = FindMat("iron_grate", "metalwall") ?? FindMat("IronNails", "ironnails"); Material val5 = FindMat("stone_wall_1x1", "stone_mat"); if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null) { ChurchGlassPlugin.Log.LogWarning((object)$"Glass materials not found yet (multiply {(Object)(object)val != (Object)null}, additive {(Object)(object)val2 != (Object)null}, crystal {(Object)(object)val3 != (Object)null}, iron {(Object)(object)val4 != (Object)null})."); Fallbacks(); return; } Multiply = new Material(val) { name = "SG_GlassMultiply", hideFlags = (HideFlags)32, mainTexture = (Texture)(object)GlassTex }; if (Multiply.HasProperty(InvFade)) { Multiply.SetFloat(InvFade, 3f); } Glow = new Material(val2) { name = "SG_GlassGlow", hideFlags = (HideFlags)32, mainTexture = (Texture)(object)GlassTex }; Glow.SetColor(TintColor, DefaultGlow); if (Glow.HasProperty(InvFade)) { Glow.SetFloat(InvFade, 3f); } Shine = new Material(val3) { name = "SG_GlassShine", hideFlags = (HideFlags)32 }; Shine.SetTexture(MainTex, (Texture)null); Shine.color = new Color(0.92f, 0.95f, 1f, 0.06f); SetF(Shine, Glossiness, 0.92f); SetF(Shine, Metallic, 0f); SetF(Shine, BumpScale, 0.25f); if (Shine.HasProperty(EmissionColor)) { Shine.SetColor(EmissionColor, Color.black); } Lead = new Material(val4) { name = "SG_Lead", hideFlags = (HideFlags)32 }; Lead.color = new Color(0.3f, 0.3f, 0.32f); SetF(Lead, Metallic, 0.6f); SetF(Lead, Glossiness, 0.35f); if (Lead.HasProperty(ValueNoise)) { Lead.SetFloat(ValueNoise, 0f); } Frame = (Material)((!((Object)(object)val5 != (Object)null)) ? ((object)Lead) : ((object)new Material(val5) { name = "SG_Frame", hideFlags = (HideFlags)32 })); Ready = true; } catch (Exception ex) { ChurchGlassPlugin.Log.LogWarning((object)("Building glass materials failed: " + ex.Message)); Fallbacks(); } } public static Material NewGlow() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown if (!((Object)(object)Glow == (Object)null)) { return new Material(Glow) { name = "SG_GlassGlow_Window", hideFlags = (HideFlags)32 }; } return null; } public static void SetGlow(Material m, Color c) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)m != (Object)null && m.HasProperty(TintColor)) { m.SetColor(TintColor, c); } } private static void Fallbacks() { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown Shader val = Shader.Find("Sprites/Default") ?? Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse"); if (!((Object)(object)val == (Object)null)) { if ((Object)(object)Multiply == (Object)null) { Multiply = new Material(val) { name = "SG_Fallback", color = new Color(1f, 1f, 1f, 0.4f) }; } if ((Object)(object)Glow == (Object)null) { Glow = Multiply; } if ((Object)(object)Shine == (Object)null) { Shine = Multiply; } if ((Object)(object)Lead == (Object)null) { Lead = new Material(val) { color = new Color(0.2f, 0.2f, 0.22f) }; } if ((Object)(object)Frame == (Object)null) { Frame = Lead; } } } 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 void SetF(Material m, int id, float v) { if ((Object)(object)m != (Object)null && m.HasProperty(id)) { m.SetFloat(id, v); } } private static Texture2D MakeGlassTexture() { //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_02d3: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02f1: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Expected O, but got Unknown //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) Random random = new Random(1271); Color32[] array = (Color32[])(object)new Color32[16384]; double[] array2 = new double[8]; for (int i = 0; i < array2.Length; i++) { array2[i] = random.NextDouble() * Math.PI * 2.0; } for (int j = 0; j < 128; j++) { for (int k = 0; k < 128; k++) { double num = (double)(k * 2) * Math.PI / 128.0; double num2 = (double)(j * 2) * Math.PI / 128.0; double num3 = 0.5 * Math.Sin(num + 2.0 * num2 + array2[0]) + 0.35 * Math.Sin(3.0 * num - num2 + array2[1]) + 0.25 * Math.Sin(2.0 * num + 5.0 * num2 + array2[2]); double num4 = 0.18 * Math.Sin(7.0 * num + 0.5 * Math.Sin(num2 + array2[3]) * 3.0 + array2[4]) + 0.1 * Math.Sin(13.0 * num + array2[5]); double v = 0.93 + 0.035 * num3 + 0.025 * num4; array[j * 128 + k] = Gray(v); } } for (int l = 0; l < 26; l++) { int num5 = random.Next(128); int num6 = random.Next(128); double num7 = 0.8 + random.NextDouble() * 1.6; for (int m = -3; m <= 3; m++) { for (int n = -3; n <= 3; n++) { double num8 = Math.Sqrt(n * n + m * m); if (!(num8 > num7 + 0.6)) { int num9 = (num6 + m + 128) % 128 * 128 + (num5 + n + 128) % 128; double v2 = ((Math.Abs(num8 - num7) < 0.6) ? 0.82 : 1.0); array[num9] = Gray(v2); } } } } Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true) { name = "SG_AntiqueGlass", wrapMode = (TextureWrapMode)0, filterMode = (FilterMode)2, anisoLevel = 4, hideFlags = (HideFlags)32 }; val.SetPixels32(array); val.Apply(true, false); return val; } private static Color32 Gray(double v) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) byte num = (byte)Math.Max(0.0, Math.Min(255.0, v * 255.0)); return new Color32(num, num, num, byte.MaxValue); } } internal static class PaneMesh { public const float LeadHalf = 0.009f; public const float LeadDepth = 0.008f; public const float GlassHalf = 0.0025f; public const float ColliderHalf = 0.02f; private static readonly Dictionary<(ShapeKind, PaneSize, int), Mesh> GlassCache = new Dictionary<(ShapeKind, PaneSize, int), Mesh>(); private static readonly Dictionary<(ShapeKind, PaneSize), Mesh> LeadCache = new Dictionary<(ShapeKind, PaneSize), Mesh>(); private static readonly Dictionary<(ShapeKind, PaneSize), Mesh> ShadowCache = new Dictionary<(ShapeKind, PaneSize), Mesh>(); private static readonly Dictionary<(ShapeKind, PaneSize), Mesh[]> ColliderCache = new Dictionary<(ShapeKind, PaneSize), Mesh[]>(); public static Vector3 V(V2 p, float z = 0f) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) return new Vector3((float)p.X, (float)p.Y, z); } public static Mesh Glass(ShapeKind k, PaneSize s, int colorId) { if (GlassCache.TryGetValue((k, s, colorId), out var value) && (Object)(object)value != (Object)null) { return value; } List<V2> outline = Shapes.Get(k, s).Outline; List<int> triangles = Shapes.Get(k, s).Triangles; GlassColor c = Palette.Get(colorId); string[] obj = new string[6] { "SG_Glass_", k.ToString(), "_", null, null, null }; int num = (int)s; obj[3] = num.ToString(); obj[4] = "_"; obj[5] = colorId.ToString(); value = BuildGlass(outline, triangles, c, string.Concat(obj)); GlassCache[(k, s, colorId)] = value; return value; } public static Mesh BuildGlass(IList<V2> outline, IList<int> tris, GlassColor c, string name) { //IL_0021: 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) Color lin = new Color((float)c.LinR, (float)c.LinG, (float)c.LinB, 1f); return BuildGlass(outline, tris, (V2 _) => lin, name); } public static Mesh BuildGlass(IList<V2> outline, IList<int> tris, Func<V2, Color> color, string name, Func<V2, Vector2> uv = null) { //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_017a: 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_0184: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0218: 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_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) int count = outline.Count; List<Vector3> list = new List<Vector3>(count * 3); List<Color> list2 = new List<Color>(count * 3); List<Vector2> list3 = new List<Vector2>(count * 3); List<Vector3> list4 = new List<Vector3>(count * 3); uv = uv ?? ((Func<V2, Vector2>)((V2 p) => new Vector2((float)p.X * 1.6f, (float)p.Y * 1.6f))); float[] array = new float[3] { 0f, 0.0025f, -0.0025f }; foreach (float num2 in array) { foreach (V2 item in outline) { list.Add(V(item, num2)); list2.Add(color(item)); list3.Add(uv(item)); list4.Add((num2 < 0f) ? Vector3.back : Vector3.forward); } } List<int> list5 = new List<int>(); List<int> list6 = new List<int>(); for (int num3 = 0; num3 < tris.Count; num3 += 3) { int num4 = tris[num3]; int num5 = tris[num3 + 1]; int num6 = tris[num3 + 2]; if (Vector3.Dot(Vector3.Cross(V(outline[num5]) - V(outline[num4]), V(outline[num6]) - V(outline[num4])), Vector3.forward) < 0f) { int num7 = num5; num5 = num6; num6 = num7; } list6.Add(num4); list6.Add(num5); list6.Add(num6); list5.Add(count + num4); list5.Add(count + num5); list5.Add(count + num6); list5.Add(2 * count + num4); list5.Add(2 * count + num6); list5.Add(2 * count + num5); } Mesh val = new Mesh { name = name }; val.SetVertices(list); val.SetColors(list2); val.SetUVs(0, list3); val.SetNormals(list4); val.subMeshCount = 2; val.SetTriangles(list5, 0); val.SetTriangles(list6, 1); val.RecalculateBounds(); return val; } public static Mesh Lead(ShapeKind k, PaneSize s) { if (LeadCache.TryGetValue((k, s), out var value) && (Object)(object)value != (Object)null) { return value; } List<V2> outline = Shapes.Get(k, s).Outline; string text = k.ToString(); int num = (int)s; value = BuildLead(outline, 0.009f, 0.008f, "SG_Lead_" + text + "_" + num); LeadCache[(k, s)] = value; return value; } public static Mesh BuildLead(IList<V2> o, float width, float depth, string name) { //IL_0080: 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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: 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_010e: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = new MeshBuilder(); int count = o.Count; for (int i = 0; i < count; i++) { V2 v = o[i]; V2 v2 = o[(i + 1) % count]; V2 normalized = (v2 - v).Normalized; if (!(normalized.Length < 0.5)) { V2 left = normalized.Left; V2 p = v + left * width; V2 p2 = v2 + left * width; meshBuilder.Quad(V(v, depth), V(v2, depth), V(p2, depth), V(p, depth), Vector3.forward); meshBuilder.Quad(V(v, 0f - depth), V(v2, 0f - depth), V(p2, 0f - depth), V(p, 0f - depth), Vector3.back); Vector3 val = V(left * -1.0); Vector3 normalized2 = ((Vector3)(ref val)).normalized; meshBuilder.Quad(V(v, depth), V(v2, depth), V(v2, 0f - depth), V(v, 0f - depth), normalized2); meshBuilder.Quad(V(p, depth), V(p2, depth), V(p2, 0f - depth), V(p, 0f - depth), -normalized2); V2 normalized3 = (o[(i + 2) % count] - v2).Normalized; if (normalized3.Length > 0.5) { V2 p3 = v2 + normalized3.Left * width; meshBuilder.Tri(V(v2, depth), V(p2, depth), V(p3, depth), Vector3.forward); meshBuilder.Tri(V(v2, 0f - depth), V(p2, 0f - depth), V(p3, 0f - depth), Vector3.back); } } } return meshBuilder.ToMesh(name); } public static Mesh Shadow(ShapeKind k, PaneSize s) { if (ShadowCache.TryGetValue((k, s), out var value) && (Object)(object)value != (Object)null) { return value; } ShapeGeom shapeGeom = Shapes.Get(k, s); List<V2> outline = shapeGeom.Outline; List<int> triangles = shapeGeom.Triangles; string text = k.ToString(); int num = (int)s; value = BuildShadow(outline, triangles, "SG_Shadow_" + text + "_" + num); ShadowCache[(k, s)] = value; return value; } public static Mesh BuildShadow(IList<V2> o, IList<int> tris, string name) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: 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) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: 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_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = new MeshBuilder(); for (int i = 0; i < tris.Count; i += 3) { Vector3 a = V(o[tris[i]]); Vector3 b = V(o[tris[i + 1]]); Vector3 c = V(o[tris[i + 2]]); meshBuilder.Tri(a, b, c, Vector3.forward); meshBuilder.Tri(a, b, c, Vector3.back); } return meshBuilder.ToMesh(name); } public static Mesh[] Colliders(ShapeKind k, PaneSize s) { if (ColliderCache.TryGetValue((k, s), out var value) && value != null) { return value; } ShapeGeom shapeGeom = Shapes.Get(k, s); value = (Mesh[])(object)new Mesh[shapeGeom.ConvexParts.Count]; for (int i = 0; i < value.Length; i++) { Mesh[] array = value; int num = i; List<V2> poly = shapeGeom.ConvexParts[i]; string[] obj = new string[6] { "SG_Col_", k.ToString(), "_", null, null, null }; int num2 = (int)s; obj[3] = num2.ToString(); obj[4] = "_"; obj[5] = i.ToString(); array[num] = Prism(poly, 0.02f, string.Concat(obj)); } ColliderCache[(k, s)] = value; return value; } public static Mesh Prism(IList<V2> poly, float half, string name) { //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_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: 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_00d9: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) MeshBuilder meshBuilder = new MeshBuilder(); int count = poly.Count; for (int i = 1; i < count - 1; i++) { meshBuilder.Tri(V(poly[0], half), V(poly[i], half), V(poly[i + 1], half), Vector3.forward); meshBuilder.Tri(V(poly[0], 0f - half), V(poly[i], 0f - half), V(poly[i + 1], 0f - half), Vector3.back); } for (int j = 0; j < count; j++) { V2 v = poly[j]; V2 v2 = poly[(j + 1) % count]; Vector3 normal = V((v2 - v).Normalized.Left * -1.0); meshBuilder.Quad(V(v, half), V(v2, half), V(v2, 0f - half), V(v, 0f - half), normal); } return meshBuilder.ToMesh(name); } } internal sealed class MeshBuilder { private readonly List<Vector3> _v = new List<Vector3>(); private readonly List<Vector3> _n = new List<Vector3>(); private readonly List<Vector2> _uv = new List<Vector2>(); private readonly List<int> _t = new List<int>(); public void Tri(Vector3 a, Vector3 b, Vector3 c, Vector3 normal) { //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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_003c: 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_0044: 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_004c: 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_0022: 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_0025: 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_0064: 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_007d: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009d: 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) if (Vector3.Dot(Vector3.Cross(b - a, c - a), normal) < 0f) { Vector3 val = b; b = c; c = val; } int count = _v.Count; Vector3[] array = (Vector3[])(object)new Vector3[3] { a, b, c }; foreach (Vector3 val2 in array) { _v.Add(val2); _n.Add(normal); _uv.Add((Mathf.Abs(normal.z) > 0.5f) ? ne