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 TreeRibbons v1.0.4
plugins/TreeRibbons.dll
Decompiled 2 hours ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyVersion("0.0.0.0")] namespace TreeRibbons; public enum WhoCanUntie { WardAccess, WhoTiedIt } [BepInPlugin("anwo.TreeRibbons", "TreeRibbons", "1.0.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class TreeRibbonsPlugin : BaseUnityPlugin { public const string Guid = "anwo.TreeRibbons"; public const string ModName = "TreeRibbons"; public const string Version = "1.0.4"; internal const string ItemPrefabName = "anwo_TreeRibbon"; internal const string DefaultRecipe = "LeatherScraps:1,Raspberry:2"; internal const string RulesSection = "1 - Ribbons"; internal const string DisplaySection = "2 - Display"; internal const string TyingSection = "3 - Tying"; internal static ManualLogSource Log; internal static ConfigEntry<string> Recipe; internal static ConfigEntry<bool> Protect; internal static ConfigEntry<bool> AlsoSmall; internal static ConfigEntry<WhoCanUntie> WhoUnties; internal static ConfigEntry<bool> ShowRibbons; internal static ConfigEntry<bool> HitMessage; internal static ConfigEntry<bool> AimHeight; internal static ConfigEntry<bool> SwayWithTree; internal static GameObject Item; internal static string ItemName; private Harmony m_harmony; internal const string HostNote = "Set by the host."; internal const string OwnNote = "Each player's own setting."; internal static readonly string[] BaseItems = new string[3] { "JuteRed", "LinenThread", "LeatherScraps" }; private static string s_appliedRecipe; private static readonly HashSet<string> s_warned = new HashSet<string>(); private void Awake() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; BindConfig(((BaseUnityPlugin)this).Config); ((BaseUnityPlugin)this).Config.Save(); ShowRibbons.SettingChanged += delegate { Ribbons.LookChanged(); }; SwayWithTree.SettingChanged += delegate { Ribbons.LookChanged(); }; m_harmony = new Harmony("anwo.TreeRibbons"); m_harmony.PatchAll(typeof(Protection)); m_harmony.PatchAll(typeof(SaplingRibbons)); m_harmony.PatchAll(typeof(RibbonAim)); PrefabManager.OnVanillaPrefabsAvailable += AddItem; SynchronizationManager.OnConfigurationSynchronized += delegate { ApplyRecipe(); }; Recipe.SettingChanged += delegate { ApplyRecipe(); }; ItemManager.OnItemsRegistered += ApplyRecipe; Log.LogInfo((object)("TreeRibbons 1.0.4 loaded. Ribboned trees " + (Protect.Value ? "cannot be harmed" : "are only marked") + ".")); } private void Update() { Ribbons.Tick(); RibbonAim.Tick(); } private void OnDestroy() { if (m_harmony != null) { m_harmony.UnpatchSelf(); } } internal static string WithNote(string description, string note) { description = (description ?? "").TrimEnd(); if (description.EndsWith(note)) { return description; } if (description.Length == 0) { return note; } return description + ((description.EndsWith(".") || description.EndsWith(")")) ? " " : ". ") + note; } private static ConfigEntry<T> Synced<T>(ConfigFile cfg, string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown ConfigurationManagerAttributes val = new ConfigurationManagerAttributes(); val.IsAdminOnly = true; return cfg.Bind<T>(section, key, value, new ConfigDescription(WithNote(description, "Set by the host."), range, new object[1] { val })); } private static ConfigEntry<T> Own<T>(ConfigFile cfg, string section, string key, T value, string description, AcceptableValueBase range = null) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown return cfg.Bind<T>(section, key, value, new ConfigDescription(WithNote(description, "Each player's own setting."), range, Array.Empty<object>())); } internal static void BindConfig(ConfigFile cfg) { Recipe = Synced(cfg, "1 - Ribbons", "Tree ribbon recipe", "LeatherScraps:1,Raspberry:2", "Cost of one Tree ribbon, made at a workbench, as Item:Amount pairs separated by commas (item names are prefab names, like LeatherScraps, Raspberry, LinenThread). A change counts at once, also for players already in the game."); Protect = Synced(cfg, "1 - Ribbons", "Ribboned trees cannot be harmed", value: true, "A tree with a ribbon tied round it takes no damage from anything: axes and other weapons, arrows, creatures, other trees falling on it, fire, explosions and other mods. A swing at it stops there without a mark, and fire doesn't catch on it. Off: a ribbon only marks a tree; it can be cut down like any other, and its ribbon drops where it stood."); AlsoSmall = Synced(cfg, "1 - Ribbons", "Small trees, stumps and saplings", value: true, "Ribbons can also be tied to small trees, tree stumps and old fallen logs, and to tree saplings (the ribbon stays on the tree a sapling grows into). Off: ribbons only go on standing trees; ribbons already tied keep working."); WhoUnties = Synced(cfg, "1 - Ribbons", "Who can take ribbons off", WhoCanUntie.WardAccess, "WardAccess: anyone a ward there lets in (anyone, where there is no ward). WhoTiedIt: only the player who tied the ribbon, or an admin, and only where a ward lets them in. Tying a ribbon always needs a ward's permission."); ShowRibbons = Own(cfg, "2 - Display", "Show ribbons", value: true, "Draws a red ribbon round the trunk of every ribboned tree, with a knot and two hanging ends. Off: no ribbons are drawn on your screen; the trees stay protected, and looking at one still tells you it has a ribbon."); SwayWithTree = Own(cfg, "2 - Display", "Ribbons sway with the tree", value: true, "A ribbon moves with its trunk as the wind sways the tree, drawn the way the tree itself is drawn. Off: ribbons stay still while the tree sways."); AimHeight = Own(cfg, "3 - Tying", "Aim the ribbon", value: true, "Using a ribbon from the hotbar on a tree shows the ribbon on the trunk where you look, at that height, and it follows as you aim: left click ties it there, right click puts it away. Off: it is tied straight away, at chest height, round the tree you look at."); HitMessage = Own(cfg, "2 - Display", "Message when you hit one", value: true, "When you hit a ribboned tree, a short message says it can't be cut (at most every " + 3f.ToString("0") + " seconds). Off: no message."); } private void AddItem() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Expected O, but got Unknown PrefabManager.OnVanillaPrefabsAvailable -= AddItem; try { string text = null; string[] baseItems = BaseItems; foreach (string text2 in baseItems) { if ((Object)(object)PrefabManager.Instance.GetPrefab(text2) != (Object)null) { text = text2; break; } } if (text == null) { Log.LogError((object)"No vanilla cloth item found to make the Tree ribbon from. The ribbon is not added."); return; } ItemConfig val = new ItemConfig(); val.Name = "Tree ribbon"; val.Description = "A strip of red cloth. Use it from your hotbar while looking at a tree, aim at the trunk and left click to tie it round there; that tree is then safe from axes, creatures, falling trees and fire. Shift+E on the tree takes the ribbon off again."; val.CraftingStation = CraftingStations.Workbench; val.MinStationLevel = 1; val.Requirements = ParseRecipe(Recipe.Value); val.Weight = 0.1f; val.StackSize = 20; Sprite val2 = LoadIcon(); if ((Object)(object)val2 != (Object)null) { val.Icons = (Sprite[])(object)new Sprite[1] { val2 }; } CustomItem val3 = new CustomItem("anwo_TreeRibbon", text, val); if ((Object)(object)val3.ItemPrefab == (Object)null || (Object)(object)val3.ItemDrop == (Object)null) { Log.LogError((object)("Could not make the Tree ribbon item (copying " + text + " failed).")); return; } ItemManager.Instance.AddItem(val3); Item = val3.ItemPrefab; SharedData shared = val3.ItemDrop.m_itemData.m_shared; ItemName = shared.m_name; shared.m_teleportable = true; shared.m_maxStackSize = 20; shared.m_weight = 0.1f; Log.LogInfo((object)("Tree ribbon item added (" + Recipe.Value + "; looks like " + text + " on the ground).")); } catch (Exception ex) { Log.LogError((object)("Adding the Tree ribbon item failed: " + ex)); } } internal static bool IsRibbon(ItemData item) { if (item == null || item.m_shared == null) { return false; } if ((Object)(object)item.m_dropPrefab != (Object)null && ((Object)item.m_dropPrefab).name == "anwo_TreeRibbon") { return true; } if (ItemName != null) { return item.m_shared.m_name == ItemName; } return false; } internal static RequirementConfig[] ParseRecipe(string recipe) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //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_007a: 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_008d: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); foreach (KeyValuePair<string, int> item in Parse(recipe)) { list.Add(new RequirementConfig { Item = item.Key, Amount = item.Value, Recover = true }); } if (list.Count == 0) { list.Add(new RequirementConfig { Item = "LeatherScraps", Amount = 1, Recover = true }); } return list.ToArray(); } internal static List<KeyValuePair<string, int>> Parse(string recipe) { List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(); string[] array = (recipe ?? "").Split(','); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(':'); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0 && array2[0].Trim().Length != 0) { list.Add(new KeyValuePair<string, int>(array2[0].Trim(), result)); } } return list; } internal static void ApplyRecipe() { try { if (Recipe == null || (Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_recipes == null || (Object)(object)ObjectDB.instance.GetItemPrefab("LeatherScraps") == (Object)null) { return; } Requirement[] array = null; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if (!((Object)(object)recipe == (Object)null) && !((Object)(object)recipe.m_item == (Object)null) && !(((Object)((Component)recipe.m_item).gameObject).name != "anwo_TreeRibbon")) { if (array == null) { array = Build(Recipe.Value); } recipe.m_resources = array; } } if (array != null) { List<string> list = new List<string>(); Requirement[] array2 = array; foreach (Requirement val in array2) { list.Add(((Object)val.m_resItem).name + " " + val.m_amount); } string text = string.Join(", ", list.ToArray()); if (text != s_appliedRecipe) { s_appliedRecipe = text; Log.LogInfo((object)("Tree ribbon cost: " + text)); } } } catch (Exception ex) { Log.LogWarning((object)("Setting the Tree ribbon's cost failed: " + ex.Message)); } } private static Requirement[] Build(string recipe) { //IL_0085: 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_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0106: 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_0115: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Expected O, but got Unknown List<Requirement> list = new List<Requirement>(); foreach (KeyValuePair<string, int> item in Parse(recipe)) { GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(item.Key); ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null); if ((Object)(object)val == (Object)null) { if (s_warned.Add(item.Key)) { Log.LogWarning((object)("Tree ribbon recipe: there is no item called \"" + item.Key + "\", so it is left out.")); } } else { list.Add(new Requirement { m_resItem = val, m_amount = item.Value, m_recover = true }); } } if (list.Count == 0) { GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab("LeatherScraps"); ItemDrop val2 = (((Object)(object)itemPrefab2 != (Object)null) ? itemPrefab2.GetComponent<ItemDrop>() : null); if ((Object)(object)val2 != (Object)null) { list.Add(new Requirement { m_resItem = val2, m_amount = 1, m_recover = true }); } } return list.ToArray(); } private static Sprite LoadIcon() { //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Expected O, but got Unknown //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Expected O, but got Unknown Texture2D val = null; try { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TreeRibbons.ribbon.png"); if (stream != null) { byte[] array = new byte[stream.Length]; int num; for (int i = 0; i < array.Length; i += num) { num = stream.Read(array, i, array.Length - i); if (num <= 0) { break; } } val = new Texture2D(2, 2, (TextureFormat)4, false); if (!ImageConversion.LoadImage(val, array)) { val = null; } } } catch (Exception ex) { Log.LogWarning((object)("Could not load the Tree ribbon icon: " + ex.Message)); val = null; } try { if ((Object)(object)val == (Object)null) { val = new Texture2D(64, 64, (TextureFormat)4, false); val.SetPixels32(RibbonDesign.IconPixels(64)); val.Apply(false); } ((Object)val).name = "anwo_treeribbon_icon"; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } catch (Exception ex2) { Log.LogWarning((object)("Could not make the Tree ribbon icon: " + ex2.Message)); return null; } } } [HarmonyPatch] internal static class Protection { [HarmonyPostfix] [HarmonyPatch(typeof(TreeBase), "Awake")] private static void TreeAwake(TreeBase __instance) { if ((Object)(object)__instance != (Object)null) { Ribbons.Attach(((Component)__instance).gameObject, RibbonKind.Tree); } } [HarmonyPostfix] [HarmonyPatch(typeof(Destructible), "Awake")] private static void DestructibleAwake(Destructible __instance) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Invalid comparison between Unknown and I4 try { if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).GetComponent<TreeBase>() != (Object)null) { return; } Plant component = ((Component)__instance).GetComponent<Plant>(); if ((Object)(object)component != (Object)null) { if (Ribbons.GrowsIntoTree(component)) { Ribbons.Attach(((Component)__instance).gameObject, RibbonKind.Sapling); } } else if ((int)__instance.GetDestructibleType() == 2) { Ribbons.Attach(((Component)__instance).gameObject, RibbonKind.Small); } } catch { } } [HarmonyPrefix] [HarmonyPatch(typeof(Attack), "AddHitPoint")] private static bool SwingHit(GameObject go, Humanoid ___m_character) { TreeRibbon treeRibbon = Ribbons.Guarding(go); if ((Object)(object)treeRibbon == (Object)null) { return true; } Ribbons.Blocked(treeRibbon, (Character)(object)___m_character, "a swing"); return false; } [HarmonyPrefix] [HarmonyPatch(typeof(TreeBase), "Damage")] private static bool TreeHit(TreeBase __instance, HitData hit) { return Pass((Component)(object)__instance, hit); } [HarmonyPrefix] [HarmonyPatch(typeof(Destructible), "Damage")] private static bool SmallTreeHit(Destructible __instance, HitData hit) { return Pass((Component)(object)__instance, hit); } private static bool Pass(Component tree, HitData hit) { TreeRibbon treeRibbon = (((Object)(object)tree != (Object)null) ? Ribbons.Guarding(tree.gameObject) : null); if ((Object)(object)treeRibbon == (Object)null) { return true; } Character attacker = null; try { attacker = ((hit != null) ? hit.GetAttacker() : null); } catch { } Ribbons.Blocked(treeRibbon, attacker, How(hit)); return false; } internal static string How(HitData hit) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: 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_002c: Expected I4, but got Unknown //IL_002c: 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_005d: Expected I4, but got Unknown if (hit == null) { return "a hit"; } HitType hitType = hit.m_hitType; switch (hitType - 1) { default: switch (hitType - 11) { case 2: return "a falling tree"; case 0: return "something falling on it"; case 9: return "fire"; case 4: return "a falling building"; case 8: return "a catapult"; case 5: return "a turret"; } break; case 1: return "a player's hit"; case 0: return "a creature's hit"; case 4: return "fire"; case 2: case 3: break; } return "a hit"; } [HarmonyPrefix] [HarmonyPatch(typeof(TreeBase), "RPC_Damage")] private static bool TreeDamage(TreeBase __instance, HitData hit, out bool __state) { __state = false; if ((Object)(object)__instance == (Object)null) { return true; } if (!Ribbons.ProtectOn) { TreeRibbon component = ((Component)__instance).GetComponent<TreeRibbon>(); __state = (Object)(object)component != (Object)null && component.Ribboned; return true; } return Pass((Component)(object)__instance, hit); } [HarmonyPostfix] [HarmonyPatch(typeof(TreeBase), "RPC_Damage")] private static void TreeDamaged(TreeBase __instance, bool __state) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (__state && (Object)(object)__instance != (Object)null) { Ribbons.DropIfGone(((Component)__instance).gameObject, ((Component)__instance).transform.position); } } [HarmonyPrefix] [HarmonyPatch(typeof(Destructible), "RPC_Damage")] private static bool SmallTreeDamage(Destructible __instance, HitData hit) { return Pass((Component)(object)__instance, hit); } [HarmonyPrefix] [HarmonyPatch(typeof(Destructible), "Destroy")] private static bool SmallTreeDestroy(Destructible __instance, HitData hit, out bool __state) { __state = false; if ((Object)(object)__instance == (Object)null) { return true; } if (!Ribbons.ProtectOn) { TreeRibbon component = ((Component)__instance).GetComponent<TreeRibbon>(); __state = (Object)(object)component != (Object)null && component.Ribboned; return true; } return Pass((Component)(object)__instance, hit); } [HarmonyPostfix] [HarmonyPatch(typeof(Destructible), "Destroy")] private static void SmallTreeDestroyed(Destructible __instance, bool __state) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) if (__state && (Object)(object)__instance != (Object)null) { Ribbons.DropIfGone(((Component)__instance).gameObject, ((Component)__instance).transform.position); } } [HarmonyPrefix] [HarmonyPatch(typeof(Fire), "DoDamage")] private static bool FireHit(IDestructible toHit) { Component val = (Component)(object)((toHit is Component) ? toHit : null); TreeRibbon treeRibbon = (((Object)(object)val != (Object)null) ? Ribbons.Guarding(val.gameObject) : null); if ((Object)(object)treeRibbon == (Object)null) { return true; } Ribbons.Blocked(treeRibbon, null, "fire"); return false; } [HarmonyPostfix] [HarmonyPatch(typeof(Cinder), "CanBurn")] private static void NoFireOnRibbons(Collider collider, ref bool __result) { if (!__result || (Object)(object)collider == (Object)null || !Ribbons.ProtectOn) { return; } try { TreeRibbon componentInParent = ((Component)collider).GetComponentInParent<TreeRibbon>(); if (!((Object)(object)componentInParent == (Object)null) && componentInParent.Ribboned) { __result = false; Ribbons.Blocked(componentInParent, null, "a spark"); } } catch { } } [HarmonyPostfix] [HarmonyPatch(typeof(HoverText), "GetHoverText")] private static void HoverTextLines(HoverText __instance, ref string __result) { AddLines((Component)(object)__instance, ref __result); } [HarmonyPostfix] [HarmonyPatch(typeof(Plant), "GetHoverText")] private static void PlantLines(Plant __instance, ref string __result) { AddLines((Component)(object)__instance, ref __result); } private static void AddLines(Component c, ref string text) { try { if (!((Object)(object)c == (Object)null)) { TreeRibbon componentInParent = c.GetComponentInParent<TreeRibbon>(); if (!((Object)(object)componentInParent == (Object)null) && componentInParent.Ribboned) { text += Ribbons.Localize(componentInParent.Lines()); } } } catch { } } } [HarmonyPatch] internal static class SaplingRibbons { [HarmonyPrefix] [HarmonyPatch(typeof(Plant), "Grow")] private static void Growing(Plant __instance, out RibbonData __state) { __state = null; try { TreeRibbon treeRibbon = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<TreeRibbon>() : null); if ((Object)(object)treeRibbon != (Object)null) { __state = treeRibbon.Data(); } if (__state != null) { __state.Height = -1f; } } catch { } } [HarmonyPostfix] [HarmonyPatch(typeof(Plant), "Grow")] private static void Grown(Plant __instance, GameObject __result, RibbonData __state) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (__state == null || (Object)(object)__result == (Object)null) { return; } try { ZNetView component = __result.GetComponent<ZNetView>(); if (!((Object)(object)component == (Object)null) && component.IsValid()) { TreeRibbon.Write(component, __state); TreeRibbon component2 = __result.GetComponent<TreeRibbon>(); if ((Object)(object)component2 != (Object)null) { component2.Check(now: true); } Ribbons.Note("A ribboned sapling grew into a tree at " + Ribbons.Where(__result.transform.position) + "; the ribbon stays on it."); } } catch (Exception ex) { TreeRibbonsPlugin.Log.LogWarning((object)("Keeping a sapling's ribbon on its tree failed: " + ex.Message)); } } } [HarmonyPatch] internal static class RibbonAim { internal const float Reach = 5f; private static GameObject s_preview; private static TreeRibbon s_tree; private static float s_height = float.NaN; private static float s_dir = float.NaN; private static float s_nextBuild; private static int s_mask; internal static bool Active { get; private set; } internal static void Toggle(Player p) { if (Active) { Stop("Ribbon put away"); } else { Start(p); } } private static void Start(Player p) { Active = true; s_tree = null; s_height = float.NaN; ((Character)p).Message((MessageType)2, "Aim at a trunk: left click ties the ribbon there, right click puts it away", 0, (Sprite)null, false); } internal static void Stop(string why) { Active = false; Hide(); s_tree = null; if (why != null) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)1, why, 0, (Sprite)null, false); } } } private static void Hide() { if ((Object)(object)s_preview != (Object)null) { Object.Destroy((Object)(object)s_preview); } s_preview = null; } internal static void Tick() { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) if (!Active) { return; } try { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || (TreeRibbonsPlugin.AimHeight != null && !TreeRibbonsPlugin.AimHeight.Value)) { Stop(null); return; } if (((Character)localPlayer).InPlaceMode()) { Stop(null); return; } if (Ribbon(localPlayer) == null) { Stop("You have no ribbons left"); return; } if (InventoryGui.IsVisible() || Menu.IsVisible() || Minimap.IsOpen()) { Hide(); s_tree = null; return; } if (!Aim(localPlayer, out var tree, out var height) || tree.Ribboned) { Hide(); s_tree = null; return; } float num = Ribbons.KnotAngle(((Component)tree).transform.position, ((Component)localPlayer).transform.position); if ((!((Object)(object)s_preview != (Object)null) || !((Object)(object)tree == (Object)(object)s_tree) || !(Math.Abs(height - s_height) < 0.015f) || !(Math.Abs(Mathf.DeltaAngle(num, s_dir)) < 8f)) && !(Time.time < s_nextBuild)) { s_nextBuild = Time.time + 0.05f; Hide(); s_tree = tree; s_height = height; s_dir = num; s_preview = RibbonLook.Make(((Component)tree).gameObject, num, height, anyway: true, preview: true, out var _); } } catch (Exception ex) { TreeRibbonsPlugin.Log.LogWarning((object)("Showing where the ribbon goes failed: " + ex.Message)); Stop(null); } } internal static bool Aim(Player p, out TreeRibbon tree, out float height) { //IL_006a: 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_00bb: 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_00db: 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) tree = null; height = -1f; GameCamera instance = GameCamera.instance; if ((Object)(object)instance == (Object)null) { return false; } if (s_mask == 0) { s_mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "terrain", "vehicle" }); } Transform transform = ((Component)instance).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.position, transform.forward, ref val, 60f, s_mask, (QueryTriggerInteraction)1)) { return false; } tree = (((Object)(object)((RaycastHit)(ref val)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<TreeRibbon>() : null); if ((Object)(object)tree == (Object)null || Vector3.Distance(((Component)p).transform.position, ((RaycastHit)(ref val)).point) > 5f) { tree = null; return false; } height = ((RaycastHit)(ref val)).point.y - ((Component)tree).transform.position.y; return true; } internal static ItemData Ribbon(Player p) { Inventory val = (((Object)(object)p != (Object)null) ? ((Humanoid)p).GetInventory() : null); if (val == null) { return null; } foreach (ItemData allItem in val.GetAllItems()) { if (TreeRibbonsPlugin.IsRibbon(allItem)) { return allItem; } } return null; } private static void Place(Player p) { if (!Aim(p, out var tree, out var height)) { ((Character)p).Message((MessageType)2, "Aim at a tree's trunk", 0, (Sprite)null, false); return; } ItemData val = Ribbon(p); if (val == null) { Stop("You have no ribbons left"); return; } tree.Tie(p, val, Math.Max(0.03f, height)); if (tree.Ribboned) { Hide(); Active = false; s_tree = null; } } [HarmonyPrefix] [HarmonyPatch(typeof(Player), "SetControls")] private static void Controls(Player __instance, ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold) { if (!Active || (Object)(object)__instance != (Object)(object)Player.m_localPlayer) { return; } try { if (attack) { Place(__instance); } else if (block | secondaryAttack) { Stop("Ribbon put away"); } } catch (Exception ex) { TreeRibbonsPlugin.Log.LogWarning((object)("Tying the aimed ribbon failed: " + ex.Message)); Stop(null); } attack = (attackHold = (secondaryAttack = (secondaryAttackHold = (block = (blockHold = false))))); } } internal sealed class RibbonShape { internal readonly List<Vector3> V = new List<Vector3>(); internal readonly List<Vector3> N = new List<Vector3>(); internal readonly List<Vector2> UV = new List<Vector2>(); internal readonly List<int> T = new List<int>(); internal int Add(Vector3 p, Vector3 n, Vector2 uv) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) V.Add(p); N.Add(n); UV.Add(uv); return V.Count - 1; } internal void Tri(int a, int b, int c) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) if (Vector3.Dot(Vector3.Cross(V[b] - V[a], V[c] - V[a]), N[a] + N[b] + N[c]) >= 0f) { T.Add(a); T.Add(b); T.Add(c); } else { T.Add(a); T.Add(c); T.Add(b); } } internal void Quad(int a, int b, int c, int d) { Tri(a, b, c); Tri(a, c, d); } } internal static class RibbonDesign { internal const float ChestHeight = 1.3f; internal const float BandWidth = 0.05f; internal const float ClothThickness = 0.003f; internal const float EndLength = 0.2f; internal const float MinRadius = 0.015f; internal const float MaxRadius = 15f; internal const int Bins = 64; internal static float TieHeight(float height) { if (!(height > 0f)) { return 1.3f; } return Mathf.Clamp(Mathf.Min(1.3f, height * 0.55f), 0.03f, 1.3f); } internal static float Width(float radius) { return 0.05f; } internal static float Thickness(float radius) { return 0.003f; } internal static float TailLength(float radius) { return 0.2f; } internal static int PickTrunk(IList<int> hits, IList<float> radii) { int num = 0; for (int i = 0; i < hits.Count; i++) { num = Math.Max(num, hits[i]); } if (num == 0) { return -1; } int num2 = ((num >= 6) ? 6 : num); int num3 = -1; for (int j = 0; j < hits.Count; j++) { if (hits[j] >= num2 && (num3 < 0 || radii[j] > radii[num3])) { num3 = j; } } return num3; } private static Vector3 Out(float rad) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) return new Vector3((float)Math.Sin(rad), 0f, (float)Math.Cos(rad)); } internal static float[] Round(float radius) { float[] array = new float[64]; for (int i = 0; i < 64; i++) { array[i] = radius; } return array; } internal static int BinOf(float dx, float dz) { float num = (float)Math.Atan2(dx, dz); if (num < 0f) { num += (float)Math.PI * 2f; } return (int)Math.Round(num / ((float)Math.PI * 2f) * 64f) % 64; } internal static float RadiusAt(float[] outline, float ang) { float num = ang / ((float)Math.PI * 2f) * 64f; float num2 = num - (float)Math.Floor(num / 64f) * 64f; int num3 = (int)Math.Floor(num2) % 64; int num4 = (num3 + 1) % 64; float num5 = num2 - (float)Math.Floor(num2); return outline[num3] * (1f - num5) + outline[num4] * num5; } internal static float[] Smooth(float[] outline) { int num = outline.Length; float[] array = new float[num]; for (int i = 0; i < num; i++) { array[i] = Math.Max(outline[i], Math.Max(outline[(i + num - 1) % num], outline[(i + 1) % num])); } float[] array2 = new float[num]; for (int j = 0; j < num; j++) { float val = (array[(j + num - 1) % num] + 2f * array[j] + array[(j + 1) % num]) * 0.25f; array2[j] = Math.Max(outline[j], val); } return array2; } internal static RibbonShape Build(float radius, float knotDegrees) { return Build(Round(radius), knotDegrees); } internal static RibbonShape Build(float[] outline, float knotDegrees) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_0072: 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_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_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_00cf: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0100: 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_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) RibbonShape ribbonShape = new RibbonShape(); float[] array = new float[outline.Length]; for (int i = 0; i < array.Length; i++) { array[i] = Mathf.Clamp(outline[i], 0.015f, 15f) + 0.003f; } float num = 0.05f; float num2 = 0.003f; float num3 = knotDegrees * ((float)Math.PI / 180f); Band(ribbonShape, array, num, num2, num3); Vector3 val = Out(num3); Vector3 up = Vector3.up; Vector3 side = Vector3.Cross(up, val); float a = num * 0.62f; float num4 = num * 0.56f; float num5 = Mathf.Max(num2 * 2.5f, num * 0.3f); Vector3 val2 = val * (RadiusAt(array, num3) + num5); Knot(ribbonShape, val2, side, up, val, a, num4, num5); float num6 = 0.2f; Vector3 start = val2 - up * (num4 * 0.3f) + val * (num5 * 0.2f); Tail(ribbonShape, start, side, up, val, -1f, num6, num * 0.75f, num2, num5); Tail(ribbonShape, start, side, up, val, 1f, num6 * 0.85f, num * 0.75f, num2, num5); return ribbonShape; } private static void Band(RibbonShape s, float[] outline, float w, float t, float knot) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: 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_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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011d: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_015d: 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_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_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_0181: 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_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) //IL_019e: 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_01ae: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f2: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: 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) float num = 0f; foreach (float val in outline) { num = Math.Max(num, val); } int num2 = Mathf.Clamp((int)Math.Round(num * 80f), 64, 256); int[] array = null; float num3 = 0f; Vector3 val2 = Vector3.zero; for (int j = 0; j <= num2; j++) { float num4 = (float)j / (float)num2 * (float)Math.PI * 2f; Vector3 val3 = Out(num4); float num5 = RadiusAt(outline, num4); float num6 = w * 0.08f * (float)Math.Sin(2f * num4 + knot); Vector3 val4 = val3 * num5; Vector3 val5 = val3 * (num5 + t); if (j > 0) { float num7 = num3; Vector3 val6 = val5 - val2; num3 = num7 + ((Vector3)(ref val6)).magnitude / (w * 2f); } val2 = val5; Vector3 val7 = Vector3.up * (num6 - w * 0.5f); Vector3 val8 = Vector3.up * (num6 + w * 0.5f); int[] array2 = new int[8] { s.Add(val5 + val7, val3, new Vector2(num3, 0f)), s.Add(val5 + val8, val3, new Vector2(num3, 1f)), s.Add(val4 + val7, -val3, new Vector2(num3, 0f)), s.Add(val4 + val8, -val3, new Vector2(num3, 1f)), s.Add(val4 + val8, Vector3.up, new Vector2(num3, 1f)), s.Add(val5 + val8, Vector3.up, new Vector2(num3, 1f)), s.Add(val4 + val7, Vector3.down, new Vector2(num3, 0f)), s.Add(val5 + val7, Vector3.down, new Vector2(num3, 0f)) }; if (array != null) { for (int k = 0; k < 4; k++) { s.Quad(array[k * 2], array[k * 2 + 1], array2[k * 2 + 1], array2[k * 2]); } } array = array2; } } private static void Knot(RibbonShape s, Vector3 center, Vector3 side, Vector3 up, Vector3 o, float a, float b, float c) { //IL_0071: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_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_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_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0111: 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_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) int count = s.V.Count; for (int i = 0; i <= 7; i++) { float num = -(float)Math.PI / 2f + (float)i / 7f * (float)Math.PI; float num2 = (float)Math.Cos(num); float num3 = (float)Math.Sin(num); for (int j = 0; j <= 12; j++) { float num4 = (float)j / 12f * (float)Math.PI * 2f; float num5 = num2 * (float)Math.Cos(num4); float num6 = num2 * (float)Math.Sin(num4); Vector3 p = center + side * (a * num5) + up * (b * num3) + o * (c * num6); Vector3 val = side * (num5 / a) + up * (num3 / b) + o * (num6 / c); Vector3 n = ((Vector3)(ref val)).normalized; if (((Vector3)(ref n)).sqrMagnitude < 0.5f) { n = ((num3 >= 0f) ? up : (-up)); } s.Add(p, n, new Vector2((float)j / 12f, (float)i / 7f)); } } for (int k = 0; k < 7; k++) { for (int l = 0; l < 12; l++) { int num7 = count + k * 13 + l; s.Quad(num7, num7 + 1, num7 + 12 + 2, num7 + 12 + 1); } } } private static void Tail(RibbonShape s, Vector3 start, Vector3 side, Vector3 up, Vector3 o, float dir, float length, float width, float t, float knot) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //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) //IL_002b: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0085: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_03d3: Unknown result type (might be due to invalid IL or missing references) //IL_03d8: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03eb: Unknown result type (might be due to invalid IL or missing references) //IL_03ff: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_0408: Unknown result type (might be due to invalid IL or missing references) //IL_040d: Unknown result type (might be due to invalid IL or missing references) //IL_0412: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0424: Unknown result type (might be due to invalid IL or missing references) //IL_0429: Unknown result type (might be due to invalid IL or missing references) //IL_042c: Unknown result type (might be due to invalid IL or missing references) //IL_042e: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0434: Unknown result type (might be due to invalid IL or missing references) //IL_043b: Unknown result type (might be due to invalid IL or missing references) //IL_043d: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0443: 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_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0109: 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_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0138: 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_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_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_0201: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020d: 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_0217: 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_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0238: 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_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_025a: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02a6: 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_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0141: 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_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_03bb: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_0327: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0358: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Unknown result type (might be due to invalid IL or missing references) //IL_0360: Unknown result type (might be due to invalid IL or missing references) //IL_0362: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_0399: Unknown result type (might be due to invalid IL or missing references) //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03a5: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ab: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[6]; for (int i = 0; i <= 5; i++) { float num = (float)i / 5f; array[i] = start - up * (length * num) + side * (dir * (length * 0.24f * num + width * 0.2f)) + o * (knot * 0.25f + length * 0.12f * num * num); } int[] array2 = null; int[] array3 = null; Vector3 val = -up; Vector3 val2 = o; Vector3 val3 = side; for (int j = 0; j <= 5; j++) { Vector3 val4 = ((j < 5) ? (array[j + 1] - array[j]) : (array[j] - array[j - 1])); Vector3 normalized = ((Vector3)(ref val4)).normalized; val4 = o - normalized * Vector3.Dot(o, normalized); Vector3 normalized2 = ((Vector3)(ref val4)).normalized; val4 = Vector3.Cross(normalized, normalized2); Vector3 normalized3 = ((Vector3)(ref val4)).normalized; float num2 = width * (1f - 0.1f * (float)j / 5f) * 0.5f; Vector3 val5 = array[j]; if (j == 5) { val5 -= normalized * (width * 0.45f); } float num3 = (float)j / 5f * length / (width * 2f); Vector3 val6 = array[j] - normalized3 * num2; Vector3 val7 = array[j] + normalized3 * num2; int[] array4 = new int[3] { s.Add(val6 + normalized2 * (t * 0.5f), normalized2, new Vector2(num3, 0f)), s.Add(val5 + normalized2 * (t * 0.5f), normalized2, new Vector2(num3, 0.5f)), s.Add(val7 + normalized2 * (t * 0.5f), normalized2, new Vector2(num3, 1f)) }; int[] array5 = new int[3] { s.Add(val6 - normalized2 * (t * 0.5f), -normalized2, new Vector2(num3, 0f)), s.Add(val5 - normalized2 * (t * 0.5f), -normalized2, new Vector2(num3, 0.5f)), s.Add(val7 - normalized2 * (t * 0.5f), -normalized2, new Vector2(num3, 1f)) }; if (array2 != null) { s.Quad(array2[0], array2[1], array4[1], array4[0]); s.Quad(array2[1], array2[2], array4[2], array4[1]); s.Quad(array3[0], array3[1], array5[1], array5[0]); s.Quad(array3[1], array3[2], array5[2], array5[1]); Edge(s, array[j - 1] - val3 * (width * (1f - 0.1f * (float)(j - 1) / 5f) * 0.5f), val6, val2, normalized2, t, -normalized3); Edge(s, array[j - 1] + val3 * (width * (1f - 0.1f * (float)(j - 1) / 5f) * 0.5f), val7, val2, normalized2, t, normalized3); } array2 = array4; array3 = array5; val = normalized; val2 = normalized2; val3 = normalized3; } Vector3 val8 = array[5] - val * (width * 0.45f); float num4 = width * 0.9f * 0.5f; Vector3 a = array[5] - val3 * num4; Vector3 b = array[5] + val3 * num4; CutEdge(s, a, val8, val2, t, val); CutEdge(s, val8, b, val2, t, val); } private static void Edge(RibbonShape s, Vector3 a, Vector3 b, Vector3 na, Vector3 nb, float t, Vector3 outward) { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: 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_0023: 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_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_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_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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: 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_007f: Unknown result type (might be due to invalid IL or missing references) int a2 = s.Add(a + na * (t * 0.5f), outward, Vector2.zero); int b2 = s.Add(a - na * (t * 0.5f), outward, Vector2.zero); int c = s.Add(b - nb * (t * 0.5f), outward, Vector2.zero); int d = s.Add(b + nb * (t * 0.5f), outward, Vector2.zero); s.Quad(a2, b2, c, d); } private static void CutEdge(RibbonShape s, Vector3 a, Vector3 b, Vector3 n, float t, Vector3 along) { //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_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: 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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007c: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_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_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) Vector3 val = b - a; Vector3 val2 = Vector3.Cross(n, val); Vector3 val3 = ((Vector3)(ref val2)).normalized; if (Vector3.Dot(val3, along) < 0f) { val3 = -val3; } int a2 = s.Add(a + n * (t * 0.5f), val3, Vector2.zero); int b2 = s.Add(a - n * (t * 0.5f), val3, Vector2.zero); int c = s.Add(b - n * (t * 0.5f), val3, Vector2.zero); int d = s.Add(b + n * (t * 0.5f), val3, Vector2.zero); s.Quad(a2, b2, c, d); } internal static bool Circle(IList<Vector3> points, out Vector3 center, out float radius) { //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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004e: 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_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: 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) center = Vector3.zero; radius = 0f; if (points == null || points.Count < 3) { return false; } float num = 0f; float num2 = 0f; float num3 = 0f; foreach (Vector3 point in points) { num += point.x; num2 += point.y; num3 += point.z; } center = new Vector3(num / (float)points.Count, num2 / (float)points.Count, num3 / (float)points.Count); foreach (Vector3 point2 in points) { float num4 = point2.x - center.x; float num5 = point2.z - center.z; radius = Mathf.Max(radius, (float)Math.Sqrt(num4 * num4 + num5 * num5)); } return radius > 0.001f; } internal static bool Cut(Vector3 a, Vector3 b, Vector3 c, float y, out Vector2 p, out Vector2 q) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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_0034: 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_0048: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) Vector2 val = (p = (q = Vector2.zero)); int n = 0; Edge(a, b, y, ref n, ref p, ref q); Edge(b, c, y, ref n, ref p, ref q); Edge(c, a, y, ref n, ref p, ref q); if (n == 2) { val = p - q; return ((Vector2)(ref val)).sqrMagnitude > 1E-12f; } return false; } private static void Edge(Vector3 u, Vector3 v, float y, ref int n, ref Vector2 p, ref Vector2 q) { //IL_0000: 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_001d: 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_002a: 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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0076: 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_006c: 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) bool num = u.y > y; bool flag = v.y > y; if (num != flag && n < 2) { float num2 = (y - u.y) / (v.y - u.y); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(u.x + (v.x - u.x) * num2, u.z + (v.z - u.z) * num2); if (n == 0) { p = val; } else { q = val; } n++; } } internal static int Nearest(IList<Vector2> lines, Vector2 mid, float limit, float[] floor, float[] dist) { //IL_0046: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) int num = 0; for (int i = 0; i < dist.Length; i++) { double num2 = (double)i * Math.PI * 2.0 / (double)dist.Length; float num3 = (float)Math.Sin(num2); float num4 = (float)Math.Cos(num2); float num5 = float.MaxValue; for (int j = 0; j + 1 < lines.Count; j += 2) { float num6 = lines[j].x - mid.x; float num7 = lines[j].y - mid.y; float num8 = lines[j + 1].x - lines[j].x; float num9 = lines[j + 1].y - lines[j].y; float num10 = num3 * num9 - num4 * num8; if (!(Math.Abs(num10) < 1E-09f)) { float num11 = (num6 * num9 - num7 * num8) / num10; float num12 = (num6 * num4 - num7 * num3) / num10; if (!(num12 < 0f) && !(num12 > 1f) && !(num11 <= 0.001f) && !(num11 > limit) && (floor == null || !(num11 <= floor[i])) && num11 < num5) { num5 = num11; } } } dist[i] = ((num5 < float.MaxValue) ? num5 : 0f); if (dist[i] > 0f) { num++; } } return num; } internal static Vector2 Centroid(Vector2 mid, float[] dist) { //IL_004f: 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_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_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0157: 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) List<Vector2> list = new List<Vector2>(); for (int i = 0; i < dist.Length; i++) { if (!(dist[i] <= 0f)) { double num = (double)i * Math.PI * 2.0 / (double)dist.Length; list.Add(new Vector2((float)Math.Sin(num) * dist[i], (float)Math.Cos(num) * dist[i])); } } if (list.Count < 3) { return mid; } double num2 = 0.0; double num3 = 0.0; double num4 = 0.0; for (int j = 0; j < list.Count; j++) { Vector2 val = list[j]; Vector2 val2 = list[(j + 1) % list.Count]; double num5 = (double)val.x * (double)val2.y - (double)val2.x * (double)val.y; num2 += num5; num3 += (double)(val.x + val2.x) * num5; num4 += (double)(val.y + val2.y) * num5; } if (Math.Abs(num2) < 1E-09) { return mid; } return new Vector2(mid.x + (float)(num3 / (3.0 * num2)), mid.y + (float)(num4 / (3.0 * num2))); } internal static bool TrunkRing(IList<Vector2> lines, Vector2 near, out Vector2 middle, out float radius) { //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_0060: 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_0074: 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_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_00a2: 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_00c3: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_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_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02c2: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Unknown result type (might be due to invalid IL or missing references) //IL_02f5: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0322: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) //IL_033e: Unknown result type (might be due to invalid IL or missing references) //IL_0340: Unknown result type (might be due to invalid IL or missing references) //IL_0345: Unknown result type (might be due to invalid IL or missing references) middle = near; radius = 0f; int num = ((lines != null) ? (lines.Count / 2) : 0); if (num < 6 || num > 800) { return false; } int[] array = new int[num]; for (int i = 0; i < num; i++) { array[i] = i; } Vector2 val; for (int j = 0; j < num; j++) { for (int k = j + 1; k < num; k++) { val = lines[2 * j] - lines[2 * k]; if (((Vector2)(ref val)).sqrMagnitude > 0.0004f) { val = lines[2 * j] - lines[2 * k + 1]; if (((Vector2)(ref val)).sqrMagnitude > 0.0004f) { val = lines[2 * j + 1] - lines[2 * k]; if (((Vector2)(ref val)).sqrMagnitude > 0.0004f) { val = lines[2 * j + 1] - lines[2 * k + 1]; if (((Vector2)(ref val)).sqrMagnitude > 0.0004f) { continue; } } } } int num2 = Root(array, j); int num3 = Root(array, k); if (num2 != num3) { array[num2] = num3; } } } Dictionary<int, List<int>> dictionary = new Dictionary<int, List<int>>(); for (int l = 0; l < num; l++) { int key = Root(array, l); if (!dictionary.TryGetValue(key, out var value)) { value = (dictionary[key] = new List<int>()); } value.Add(l); } float num4 = float.MaxValue; Vector2 val4 = default(Vector2); foreach (List<int> value2 in dictionary.Values) { if (value2.Count < 6) { continue; } double num5 = 0.0; double num6 = 0.0; double num7 = 0.0; foreach (int item in value2) { Vector2 val2 = lines[2 * item]; Vector2 val3 = lines[2 * item + 1]; val = val3 - val2; double num8 = ((Vector2)(ref val)).magnitude; num5 += num8; num6 += (double)(val2.x - near.x + val3.x - near.x) * 0.5 * num8; num7 += (double)(val2.y - near.y + val3.y - near.y) * 0.5 * num8; } if (num5 <= 0.0) { continue; } ((Vector2)(ref val4))..ctor(near.x + (float)(num6 / num5), near.y + (float)(num7 / num5)); val = val4 - near; float magnitude = ((Vector2)(ref val)).magnitude; if (magnitude >= num4) { continue; } num4 = magnitude; middle = val4; radius = 0f; foreach (int item2 in value2) { float val5 = radius; val = lines[2 * item2] - val4; float magnitude2 = ((Vector2)(ref val)).magnitude; val = lines[2 * item2 + 1] - val4; radius = Math.Max(val5, Math.Max(magnitude2, ((Vector2)(ref val)).magnitude)); } } return num4 < float.MaxValue; } private static int Root(int[] parent, int i) { while (parent[i] != i) { parent[i] = parent[parent[i]]; i = parent[i]; } return i; } internal static Color32[] ClothPixels(int n) { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[n * n]; Random random = new Random(7); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { float num = (((j + i) % 4 < 2) ? 1.06f : 0.93f); num *= 0.96f + (float)random.NextDouble() * 0.08f; int num2 = Math.Min(i, n - 1 - i); if (num2 < 3) { num *= 0.72f; } else if (num2 == 5) { num *= 1.22f; } float v = 0.7f * num; float v2 = 0.075f * num; float v3 = 0.06f * num; array[i * n + j] = new Color32(To(v), To(v2), To(v3), byte.MaxValue); } } return array; } private static byte To(float v) { return (byte)Mathf.Clamp(Mathf.RoundToInt(v * 255f), 0, 255); } internal static Color32[] IconPixels(int n) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: 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) Color32[] array = (Color32[])(object)new Color32[n * n]; Color32 val = default(Color32); ((Color32)(ref val))..ctor((byte)0, (byte)0, (byte)0, (byte)0); Color32 val2 = default(Color32); ((Color32)(ref val2))..ctor((byte)60, (byte)14, (byte)12, byte.MaxValue); Color32 val3 = default(Color32); ((Color32)(ref val3))..ctor((byte)196, (byte)36, (byte)30, byte.MaxValue); Color32 val4 = default(Color32); ((Color32)(ref val4))..ctor((byte)232, (byte)86, (byte)70, byte.MaxValue); float num = (float)n * 0.5f; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { float num2 = ((float)j + 0.5f - num) / (float)n; float num3 = ((float)i + 0.5f - num) / (float)n; Color32 val5 = val; float num4 = num2 / 0.34f; float num5 = (num3 - 0.12f) / 0.24f; float num6 = (float)Math.Sqrt(num4 * num4 + num5 * num5); if (num6 > 0.62f && num6 < 1f) { val5 = ((num6 > 0.92f || num6 < 0.7f) ? val2 : ((num3 > 0.18f) ? val4 : val3)); } float[] array2 = new float[2] { -1f, 1f }; foreach (float num7 in array2) { float num8 = 0f - num3 + 0.02f; if (num8 < 0f || num8 > 0.44f) { continue; } float num9 = num7 * (0.03f + num8 * 0.42f); float num10 = 0.065f; float num11 = ((Math.Abs(num2 - num9) < num10 * 0.6f) ? (0.44f - (num10 * 0.6f - Math.Abs(num2 - num9)) * 0.7f) : 0.44f); if (!(num8 > num11)) { float num12 = Math.Abs(num2 - num9); if (num12 < num10) { val5 = ((num12 > num10 - 0.018f || num8 > num11 - 0.018f) ? val2 : val3); } } } float num13 = num2 / 0.09f; float num14 = (num3 + 0f) / 0.075f; float num15 = num13 * num13 + num14 * num14; if (num15 < 1f) { val5 = ((num15 > 0.7f) ? val2 : val4); } array[i * n + j] = val5; } } return array; } } internal static class RibbonLook { internal sealed class Fit { internal Vector3 Center; internal float[] Outline; internal bool Measured; internal bool FromModel; internal float Top; internal MeshRenderer Bark; } private sealed class Bark { internal Vector3[] V; internal int[] T; } private static Material s_material; private static bool s_noMaterial; private static readonly Dictionary<Material, Material> s_sway = new Dictionary<Material, Material>(); private static readonly HashSet<string> s_swayLogged = new HashSet<string>(); private static readonly HashSet<string> s_fitLogged = new HashSet<string>(); private static int s_viewblock = -2; private static readonly Dictionary<Mesh, Bark> s_bark = new Dictionary<Mesh, Bark>(); private static readonly string[] s_notBark = new string[11] { "leaf", "leaves", "needle", "branch", "twig", "foliage", "card", "canopy", "bush", "moss", "vine" }; private static readonly List<MeshRenderer> s_visible = new List<MeshRenderer>(); private static readonly List<Vector2> s_lines = new List<Vector2>(); private static readonly List<Vector2> s_near = new List<Vector2>(); private static readonly List<int> s_lineFrom = new List<int>(); private static readonly List<int> s_nearFrom = new List<int>(); private static Vector3[] s_world = (Vector3[])(object)new Vector3[0]; internal static GameObject Make(GameObject tree, float knotDegrees, float height, bool anyway, bool preview, out Fit fit) { //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_0112: 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) //IL_0134: 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_0148: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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_016d: 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) fit = null; if ((Object)(object)tree == (Object)null) { return null; } fit = Measure(tree, height); if (!fit.Measured && !anyway) { return null; } Material val = null; Transform val2 = null; if ((TreeRibbonsPlugin.SwayWithTree == null || TreeRibbonsPlugin.SwayWithTree.Value) && fit.FromModel && (Object)(object)fit.Bark != (Object)null) { val = SwayMaterial(BarkMaterial(fit.Bark)); if ((Object)(object)val != (Object)null) { val2 = ((Component)fit.Bark).transform; } } Material val3 = val ?? Material(); if ((Object)(object)val3 == (Object)null) { return null; } RibbonShape shape = RibbonDesign.Build(fit.Outline, knotDegrees); if ((Object)(object)val2 != (Object)null) { Into(shape, fit.Center, val2); } Mesh val4 = ToMesh(shape); GameObject val5 = new GameObject(preview ? "anwo_tree_ribbon_preview" : "anwo_tree_ribbon"); if ((Object)(object)val2 != (Object)null) { val5.layer = ((Component)val2).gameObject.layer; val5.transform.SetParent(val2, false); val5.transform.localPosition = Vector3.zero; val5.transform.localRotation = Quaternion.identity; val5.transform.localScale = Vector3.one; Bounds bounds = val4.bounds; Vector3 lossyScale = val2.lossyScale; float num = Mathf.Max(0.0001f, (Mathf.Abs(lossyScale.x) + Mathf.Abs(lossyScale.y) + Mathf.Abs(lossyScale.z)) / 3f); ((Bounds)(ref bounds)).Expand(2f / num); val4.bounds = bounds; } else { val5.layer = tree.layer; val5.transform.SetPositionAndRotation(fit.Center, Quaternion.identity); val5.transform.localScale = Vector3.one; } val5.AddComponent<MeshFilter>().sharedMesh = val4; MeshRenderer obj = val5.AddComponent<MeshRenderer>(); ((Renderer)obj).sharedMaterial = val3; ((Renderer)obj).shadowCastingMode = (ShadowCastingMode)(!preview); ((Renderer)obj).receiveShadows = true; val5.AddComponent<OwnedMesh>().Mesh = val4; return val5; } private static void Into(RibbonShape shape, Vector3 center, Transform under) { //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_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_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_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: 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_0082: Unknown result type (might be due to invalid IL or missing references) Matrix4x4 worldToLocalMatrix = under.worldToLocalMatrix; Matrix4x4 localToWorldMatrix = under.localToWorldMatrix; Matrix4x4 transpose = ((Matrix4x4)(ref localToWorldMatrix)).transpose; for (int i = 0; i < shape.V.Count; i++) { shape.V[i] = ((Matrix4x4)(ref worldToLocalMatrix)).MultiplyPoint3x4(center + shape.V[i]); } for (int j = 0; j < shape.N.Count; j++) { Vector3 val = ((Matrix4x4)(ref transpose)).MultiplyVector(shape.N[j]); shape.N[j] = ((((Vector3)(ref val)).sqrMagnitude > 1E-12f) ? ((Vector3)(ref val)).normalized : Vector3.up); } } private static Material BarkMaterial(MeshRenderer r) { if ((Object)(object)r == (Object)null) { return null; } Material[] sharedMaterials = ((Renderer)r).sharedMaterials; foreach (Material val in sharedMaterials) { if ((Object)(object)val == (Object)null) { continue; } string text = ((Object)val).name.ToLowerInvariant(); bool flag = true; string[] array = s_notBark; foreach (string value in array) { if (text.Contains(value)) { flag = false; break; } } if (flag) { return val; } } return null; } internal static Material SwayMaterial(Material bark) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)bark == (Object)null || (Object)(object)bark.shader == (Object)null || !bark.HasProperty("_SwayDistance")) { return null; } if (s_sway.TryGetValue(bark, out var value)) { return value; } Material val = Material(); if ((Object)(object)val == (Object)null) { return null; } try { Material val2 = new Material(bark) { name = "anwo_tree_ribbon_cloth_sway" }; val2.mainTexture = val.mainTexture; val2.mainTextureScale = Vector2.one; val2.mainTextureOffset = Vector2.zero; if (val2.HasProperty("_Color")) { val2.color = Color.white; } string[] array = new string[3] { "_BumpMap", "_MetalTex", "_EmissiveTex" }; foreach (string text in array) { if (val2.HasProperty(text)) { val2.SetTexture(text, (Texture)null); } } if (val2.HasProperty("_MossAlpha")) { val2.SetFloat("_MossAlpha", 0f); } if (val2.HasProperty("_MossBlend")) { val2.SetFloat("_MossBlend", 0f); } if (val2.HasProperty("_EmissionColor")) { val2.SetColor("_EmissionColor", Color.black); } if (s_sway.Count > 64) { s_sway.Clear(); } s_sway[bark] = val2; if (s_swayLogged.Count < 16 && s_swayLogged.Add(((Object)bark).name)) { TreeRibbonsPlugin.Log.LogInfo((object)("Ribbons on " + ((Object)bark).name + " sway with it (" + ((Object)bark.shader).name + ").")); } return val2; } catch (Exception ex) { TreeRibbonsPlugin.Log.LogDebug((object)("A swaying ribbon cloth couldn't be made: " + ex.Message)); s_sway[bark] = null; return null; } } private static List<Collider> Solid(GameObject tree, out float top, out float reach) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: Unknown result type (might be due to invalid IL or missing references) List<Collider> list = new List<Collider>(); top = float.NegativeInfinity; reach = 0.5f; Collider[] componentsInChildren = tree.GetComponentsInChildren<Collider>(); foreach (Collider val in componentsInChildren) { if (!((Object)(object)val == (Object)null) && val.enabled && !val.isTrigger) { Bounds bounds = val.bounds; top = Mathf.Max(top, ((Bounds)(ref bounds)).max.y); if (!IsViewBlock(((Component)val).gameObject)) { list.Add(val); reach = Mathf.Max(reach, Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.z)); } } } if (list.Count == 0) { Renderer[] componentsInChildren2 = tree.GetComponentsInChildren<Renderer>(); foreach (Renderer val2 in componentsInChildren2) { if ((Object)(object)val2 != (Object)null && (val2 is MeshRenderer || val2 is SkinnedMeshRenderer)) { float num = top; Bounds bounds2 = val2.bounds; top = Mathf.Max(num, ((Bounds)(ref bounds2)).max.y); } } } return list; } internal static bool IsViewBlock(GameObject go) { if ((Object)(object)go == (Object)null) { return false; } if (s_viewblock == -2) { s_viewblock = LayerMask.NameToLayer("viewblock"); } if (s_viewblock < 0 || go.layer != s_viewblock) { return ((Object)go).name == "viewblock"; } return true; } internal static Fit Measure(GameObject tree, float height) { //IL_000